smeserver-openvpn-bridge/root/etc/e-smith/db/configuration/migrate/50openvpn-bridge-range

37 lines
1.2 KiB
Plaintext
Raw Normal View History

{
my $openvpn = $DB->get('openvpn-bridge') || $DB->new_record('openvpn-bridge', {type => 'service'});
my $start = $openvpn->prop('startPool') || '';
my $end = $openvpn->prop('endPool') || '';
# If start and end are define, we return an empty string
return "" if ($start ne '' and $end ne '');
# Else, we compute valid address
$start = '0.0.0.10';
$end = '0.0.0.30';
$start = esmith::util::IPquadToAddr($start);
$end = esmith::util::IPquadToAddr($end);
my $netmask = esmith::util::IPquadToAddr($LocalNetmask);
my $localnet = esmith::util::IPquadToAddr($LocalIP) & $netmask;
# AND-out the host bits from the start and end ips.
# And, OR our local network with our start and end host values.
$start = $localnet | ($start & ~$netmask);
$end = $localnet | ($end & ~$netmask);
# Make sure that $start is less than $end (might not be if netmask has changed)
if ($start > $end)
{
my $temp = $start;
$start = $end;
$end = $temp;
}
$openvpn->merge_props(startPool => esmith::util::IPaddrToQuad($start),
endPool => esmith::util::IPaddrToQuad($end));
}