Commit b4a0c4bc authored by Franco Fichtner's avatar Franco Fichtner

rc.initial: apply PSR2 style

parent e1eca26e
...@@ -44,80 +44,82 @@ print "\n*** Welcome to {$product} {$version} ({$machine}/${flavour}) on {$hostn ...@@ -44,80 +44,82 @@ print "\n*** Welcome to {$product} {$version} ({$machine}/${flavour}) on {$hostn
$iflist = get_configured_interface_with_descr(false, true); $iflist = get_configured_interface_with_descr(false, true);
if (empty($iflist)) { if (empty($iflist)) {
printf("\n\tNo network interfaces are assigned.\n"); printf("\n\tNo network interfaces are assigned.\n");
return; return;
} }
foreach($iflist as $ifname => $friendly) { foreach ($iflist as $ifname => $friendly) {
/* point to this interface's config */ /* point to this interface's config */
$ifconf = $config['interfaces'][$ifname]; $ifconf = $config['interfaces'][$ifname];
/* look for 'special cases' */ /* look for 'special cases' */
$class = ""; $class = "";
if (isset($ifconf['ipaddr'])) { if (isset($ifconf['ipaddr'])) {
switch($ifconf['ipaddr']) { switch ($ifconf['ipaddr']) {
case "dhcp": case "dhcp":
$class = "/DHCP4"; $class = "/DHCP4";
break; break;
case "pppoe": case "pppoe":
$class = "/PPPoE"; $class = "/PPPoE";
break; break;
case "pptp": case "pptp":
$class = "/PPTP"; $class = "/PPTP";
break; break;
case "l2tp": case "l2tp":
$class = "/L2TP"; $class = "/L2TP";
break; break;
} }
} }
$class6 = null; $class6 = null;
if (isset($ifconf['ipaddrv6'])) { if (isset($ifconf['ipaddrv6'])) {
switch($ifconf['ipaddrv6']) { switch ($ifconf['ipaddrv6']) {
case "dhcp6": case "dhcp6":
$class6 = "/DHCP6"; $class6 = "/DHCP6";
break; break;
case "slaac": case "slaac":
$class6 = "/SLAAC"; $class6 = "/SLAAC";
break; break;
case "6rd": case "6rd":
$class6 = "/6RD"; $class6 = "/6RD";
break; break;
case "6to4": case "6to4":
$class6 = "/6to4"; $class6 = "/6to4";
break; break;
case "track6": case "track6":
$class6 = "/t6"; $class6 = "/t6";
break; break;
} }
} }
$ipaddr = get_interface_ip($ifname); $ipaddr = get_interface_ip($ifname);
$subnet = get_interface_subnet($ifname); $subnet = get_interface_subnet($ifname);
$ipaddr6 = get_interface_ipv6($ifname); $ipaddr6 = get_interface_ipv6($ifname);
$subnet6 = get_interface_subnetv6($ifname); $subnet6 = get_interface_subnetv6($ifname);
$realif = get_real_interface($ifname); $realif = get_real_interface($ifname);
$tobanner = "{$friendly} ({$realif})"; $tobanner = "{$friendly} ({$realif})";
printf("\n %-15s -> ", $tobanner); printf("\n %-15s -> ", $tobanner);
$v6first = false; $v6first = false;
if (!empty($ipaddr) && !empty($subnet)) { if (!empty($ipaddr) && !empty($subnet)) {
printf("v4%s: %s/%s", printf(
$class, "v4%s: %s/%s",
$ipaddr, $class,
$subnet $ipaddr,
); $subnet
} else { );
$v6first = true; } else {
} $v6first = true;
if (!empty($ipaddr6) && !empty($subnet6)) { }
if (!$v6first) { if (!empty($ipaddr6) && !empty($subnet6)) {
printf("\n%s", str_repeat(" ", 20)); if (!$v6first) {
} printf("\n%s", str_repeat(" ", 20));
printf("v6%s: %s/%s", }
$class6, printf(
$ipaddr6, "v6%s: %s/%s",
$subnet6 $class6,
); $ipaddr6,
} $subnet6
);
}
} }
printf("\n"); printf("\n");
...@@ -43,7 +43,7 @@ Do you want to proceed {$yes_no_prompt} ...@@ -43,7 +43,7 @@ Do you want to proceed {$yes_no_prompt}
EOD; EOD;
if (strcasecmp(chop(fgets($fp)), 'y') == 0) { if (strcasecmp(chop(fgets($fp)), 'y') == 0) {
reset_factory_defaults(); reset_factory_defaults();
} }
fclose($fp); fclose($fp);
...@@ -38,7 +38,7 @@ echo "This may take a minute, depending on your hardware.\n"; ...@@ -38,7 +38,7 @@ echo "This may take a minute, depending on your hardware.\n";
echo "\nDo you want to proceed [y|n]? "; echo "\nDo you want to proceed [y|n]? ";
if (strcasecmp(chop(fgets($fp)), 'y') == 0) { if (strcasecmp(chop(fgets($fp)), 'y') == 0) {
system_halt(true); system_halt(true);
} }
fclose($fp); fclose($fp);
...@@ -33,49 +33,50 @@ require_once('auth.inc'); ...@@ -33,49 +33,50 @@ require_once('auth.inc');
$fp = fopen('php://stdin', 'r'); $fp = fopen('php://stdin', 'r');
printf( printf(
gettext('The %s password will be reset to the factory default of `%s\'.'), gettext('The %s password will be reset to the factory default of `%s\'.'),
$g['factory_shipped_username'], $g['factory_shipped_username'],
$g['factory_shipped_password'] $g['factory_shipped_password']
); );
printf("\n\n"); printf("\n\n");
printf(gettext('Do you want to proceed [y|n]? ')); printf(gettext('Do you want to proceed [y|n]? '));
if (strcasecmp(chop(fgets($fp)), 'y') == 0) { if (strcasecmp(chop(fgets($fp)), 'y') == 0) {
if (isset($config['system']['webgui']['authmode']) && if (isset($config['system']['webgui']['authmode']) &&
$config['system']['webgui']['authmode'] != 'Local Database') { $config['system']['webgui']['authmode'] != 'Local Database') {
printf("\n\n"); printf("\n\n");
printf(gettext('The User manager authentication server is set to "%s".'), $config['system']['webgui']['authmode']); printf(gettext('The User manager authentication server is set to "%s".'), $config['system']['webgui']['authmode']);
printf("\n"); printf("\n");
printf(gettext('Do you want to set it back to Local Database [y|n]? ')); printf(gettext('Do you want to set it back to Local Database [y|n]? '));
if (strcasecmp(chop(fgets($fp)), 'y') == 0) { if (strcasecmp(chop(fgets($fp)), 'y') == 0) {
$config['system']['webgui']['authmode'] = 'Local Database'; $config['system']['webgui']['authmode'] = 'Local Database';
} }
} }
$admin_user =& getUserEntryByUID(0); $admin_user =& getUserEntryByUID(0);
if (!$admin_user) { if (!$admin_user) {
echo "Failed to locate the admin user account! Attempting to restore access.\n"; echo "Failed to locate the admin user account! Attempting to restore access.\n";
$admin_user = array(); $admin_user = array();
$admin_user['uid'] = 0; $admin_user['uid'] = 0;
if (!isset($config['system']['user'])) if (!isset($config['system']['user'])) {
$config['system']['user'] = array(); $config['system']['user'] = array();
$config['system']['user'][] = $admin_user; }
} $config['system']['user'][] = $admin_user;
}
$admin_user['name'] = $g['factory_shipped_username']; $admin_user['name'] = $g['factory_shipped_username'];
$admin_user['priv'] = array('user-shell-access'); $admin_user['priv'] = array('user-shell-access');
$admin_user['scope'] = 'system'; $admin_user['scope'] = 'system';
if (isset($admin_user['disabled'])) { if (isset($admin_user['disabled'])) {
unset($admin_user['disabled']); unset($admin_user['disabled']);
} }
local_user_set_password($admin_user, $g['factory_shipped_password']); local_user_set_password($admin_user, $g['factory_shipped_password']);
local_user_set($admin_user); local_user_set($admin_user);
write_config($config, gettext("password changed from console menu")); write_config($config, gettext("password changed from console menu"));
printf("\n\n"); printf("\n\n");
printf(gettext("The password has been reset.")); printf(gettext("The password has been reset."));
printf("\n"); printf("\n");
printf(gettext("Please change the password as soon as you log in!")); printf(gettext("Please change the password as soon as you log in!"));
printf("\n\n"); printf("\n\n");
} }
...@@ -37,15 +37,15 @@ echo "\nEnter a host name or IP address: "; ...@@ -37,15 +37,15 @@ echo "\nEnter a host name or IP address: ";
$pinghost = chop(fgets($fp)); $pinghost = chop(fgets($fp));
if (is_ipaddrv4($pinghost) || is_hostname($pinghost)) { if (is_ipaddrv4($pinghost) || is_hostname($pinghost)) {
$command = "ping"; $command = "ping";
} elseif (is_ipaddrv6($pinghost)) { } elseif (is_ipaddrv6($pinghost)) {
$command = "ping6"; $command = "ping6";
} }
if ($command) { if ($command) {
echo "\n"; echo "\n";
passthru("/sbin/{$command} -c 3 -n " . escapeshellarg($pinghost)); passthru("/sbin/{$command} -c 3 -n " . escapeshellarg($pinghost));
echo "\nPress ENTER to continue.\n"; echo "\nPress ENTER to continue.\n";
fgets($fp); fgets($fp);
} }
fclose($fp); fclose($fp);
...@@ -38,7 +38,7 @@ echo "This may take a minute, depending on your hardware.\n"; ...@@ -38,7 +38,7 @@ echo "This may take a minute, depending on your hardware.\n";
echo "\nDo you want to proceed [y|n]? "; echo "\nDo you want to proceed [y|n]? ";
if (strcasecmp(chop(fgets($fp)), 'y') == 0) { if (strcasecmp(chop(fgets($fp)), 'y') == 0) {
system_reboot(true); system_reboot(true);
} }
fclose($fp); fclose($fp);
...@@ -43,100 +43,106 @@ require_once("unbound.inc"); ...@@ -43,100 +43,106 @@ require_once("unbound.inc");
$options = getopt("hn", array("dry-run", "help")); $options = getopt("hn", array("dry-run", "help"));
if (isset($options["h"]) || isset($options["help"])) { if (isset($options["h"]) || isset($options["help"])) {
echo "usage: rc.initial.setlanip [option ...]\n"; echo "usage: rc.initial.setlanip [option ...]\n";
echo " -h, --help show this message\n"; echo " -h, --help show this message\n";
echo " -n, --dry-run do not make any configuration changes\n"; echo " -n, --dry-run do not make any configuration changes\n";
exit(0); exit(0);
} }
$dry_run = isset($options["n"]) || isset($options["dry-run"]); $dry_run = isset($options["n"]) || isset($options["dry-run"]);
if ($dry_run) { if ($dry_run) {
echo "DRY RUN MODE IS ON\n"; echo "DRY RUN MODE IS ON\n";
} }
function console_prompt_for_yn ($prompt_text) { function console_prompt_for_yn($prompt_text)
global $fp; {
global $fp;
$good_answer = false;
$good_answer = false;
do {
echo "\n" . $prompt_text . " (y/n) "; do {
$yn = strtolower(chop(fgets($fp))); echo "\n" . $prompt_text . " (y/n) ";
if (($yn == "y") || ($yn == "yes")) { $yn = strtolower(chop(fgets($fp)));
$boolean_answer = true; if (($yn == "y") || ($yn == "yes")) {
$good_answer = true; $boolean_answer = true;
} $good_answer = true;
if (($yn == "n") || ($yn == "no")) { }
$boolean_answer = false; if (($yn == "n") || ($yn == "no")) {
$good_answer = true; $boolean_answer = false;
} $good_answer = true;
} while (!$good_answer); }
} while (!$good_answer);
return $boolean_answer;
return $boolean_answer;
} }
function console_get_interface_from_ppp($realif) function console_get_interface_from_ppp($realif)
{ {
global $config; global $config;
if (isset($config['ppps']['ppp'])) { if (isset($config['ppps']['ppp'])) {
foreach ($config['ppps']['ppp'] as $pppid => $ppp) { foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
if ($realif == $ppp['if']) { if ($realif == $ppp['if']) {
$ifaces = explode(',', $ppp['ports']); $ifaces = explode(',', $ppp['ports']);
return $ifaces[0]; return $ifaces[0];
} }
} }
} }
return ''; return '';
} }
function prompt_for_enable_dhcp_server($version = 4) { function prompt_for_enable_dhcp_server($version = 4)
global $config, $fp, $interface; {
if($interface == "wan") { global $config, $fp, $interface;
if($config['interfaces']['lan']) if ($interface == "wan") {
return false; if ($config['interfaces']['lan']) {
} return false;
/* only allow DHCP server to be enabled when static IP is }
}
/* only allow DHCP server to be enabled when static IP is
configured on this interface */ configured on this interface */
if ($version === 6) { if ($version === 6) {
$is_ipaddr = is_ipaddrv6($config['interfaces'][$interface]['ipaddrv6']); $is_ipaddr = is_ipaddrv6($config['interfaces'][$interface]['ipaddrv6']);
} else { } else {
$is_ipaddr = is_ipaddrv4($config['interfaces'][$interface]['ipaddr']); $is_ipaddr = is_ipaddrv4($config['interfaces'][$interface]['ipaddr']);
} }
if (!($is_ipaddr)) { if (!($is_ipaddr)) {
return false; return false;
} }
$label_DHCP = ($version === 6) ? "DHCP6" : "DHCP"; $label_DHCP = ($version === 6) ? "DHCP6" : "DHCP";
$upperifname = strtoupper($interface); $upperifname = strtoupper($interface);
return console_prompt_for_yn (sprintf(gettext("Do you want to enable the %s server on %s?"), $label_DHCP, $upperifname)); return console_prompt_for_yn(sprintf(gettext("Do you want to enable the %s server on %s?"), $label_DHCP, $upperifname));
} }
function get_interface_config_description($iface) { function get_interface_config_description($iface)
global $config; {
$c = $config['interfaces'][$iface]; global $config;
if (!$c) { return null; } $c = $config['interfaces'][$iface];
$if = $c['if']; if (!$c) {
$result = $if; return null;
$result2 = array(); }
$ipaddr = $c['ipaddr']; $if = $c['if'];
$ipaddrv6 = $c['ipaddrv6']; $result = $if;
if (is_ipaddr($ipaddr)) { $result2 = array();
$result2[] = "static"; $ipaddr = $c['ipaddr'];
} else if ($ipaddr == "dhcp") { $ipaddrv6 = $c['ipaddrv6'];
$result2[] = "dhcp"; if (is_ipaddr($ipaddr)) {
} $result2[] = "static";
if (is_ipaddr($ipaddrv6)) { } elseif ($ipaddr == "dhcp") {
$result2[] = "staticv6"; $result2[] = "dhcp";
} else if ($ipaddrv6 == "dhcp6") { }
$result2[] = "dhcp6"; if (is_ipaddr($ipaddrv6)) {
} $result2[] = "staticv6";
if (count($result2)) { } elseif ($ipaddrv6 == "dhcp6") {
$result .= " - " . implode(", ", $result2); $result2[] = "dhcp6";
} }
return $result; if (count($result2)) {
$result .= " - " . implode(", ", $result2);
}
return $result;
} }
$fp = fopen('php://stdin', 'r'); $fp = fopen('php://stdin', 'r');
...@@ -148,211 +154,233 @@ $count = count($ifdescrs); ...@@ -148,211 +154,233 @@ $count = count($ifdescrs);
/* grab interface that we will operate on, unless there is only one /* grab interface that we will operate on, unless there is only one
interface */ interface */
if ($count > 1) { if ($count > 1) {
echo "Available interfaces:\n\n"; echo "Available interfaces:\n\n";
$x=1; $x=1;
foreach($ifdescrs as $iface => $ifdescr) { foreach ($ifdescrs as $iface => $ifdescr) {
$config_descr = get_interface_config_description($iface); $config_descr = get_interface_config_description($iface);
echo "{$x} - {$ifdescr} ({$config_descr})\n"; echo "{$x} - {$ifdescr} ({$config_descr})\n";
$x++; $x++;
} }
echo "\nEnter the number of the interface you wish to configure: "; echo "\nEnter the number of the interface you wish to configure: ";
$intnum = chop(fgets($fp)); $intnum = chop(fgets($fp));
} else { } else {
$intnum = $count; $intnum = $count;
} }
if($intnum < 1) if ($intnum < 1) {
exit; exit;
if($intnum > $count) }
exit; if ($intnum > $count) {
exit;
}
$index = 1; $index = 1;
foreach ($ifdescrs as $ifname => $ifdesc) { foreach ($ifdescrs as $ifname => $ifdesc) {
if ($intnum == $index) { if ($intnum == $index) {
$interface = $ifname; $interface = $ifname;
break; break;
} else { } else {
$index++; $index++;
} }
} }
if(!$interface) { if (!$interface) {
echo "Invalid interface!\n"; echo "Invalid interface!\n";
exit; exit;
} }
$ifaceassigned = ""; $ifaceassigned = "";
function next_unused_gateway_name($interface) { function next_unused_gateway_name($interface)
global $g, $config; {
$new_name = "GW_" . strtoupper($interface); global $g, $config;
$new_name = "GW_" . strtoupper($interface);
if (!is_array($config['gateways']['gateway_item'])) { return $new_name; }
$count = 1; if (!is_array($config['gateways']['gateway_item'])) {
do { return $new_name;
$existing = false; }
foreach ($config['gateways']['gateway_item'] as $item) { $count = 1;
if ($item['name'] === $new_name) { do {
$existing = true; $existing = false;
break; foreach ($config['gateways']['gateway_item'] as $item) {
} if ($item['name'] === $new_name) {
} $existing = true;
if ($existing) { break;
$count += 1; }
$new_name = "GW_" . strtoupper($interface) . "_" . $count; }
} if ($existing) {
} while ($existing); $count += 1;
return $new_name; $new_name = "GW_" . strtoupper($interface) . "_" . $count;
}
} while ($existing);
return $new_name;
} }
function add_gateway_to_config($interface, $gatewayip, $inet_type) { function add_gateway_to_config($interface, $gatewayip, $inet_type)
global $g, $config, $dry_run; {
if (!is_array($config['gateways']['gateway_item'])) { global $g, $config, $dry_run;
$config['gateways']['gateway_item'] = array(); if (!is_array($config['gateways']['gateway_item'])) {
} $config['gateways']['gateway_item'] = array();
$a_gateways = &$config['gateways']['gateway_item']; }
if ($dry_run) { $a_gateways = &$config['gateways']['gateway_item'];
print_r($a_gateways); if ($dry_run) {
} print_r($a_gateways);
$new_name = ''; }
$is_default = true; $new_name = '';
foreach ($a_gateways as $item) { $is_default = true;
if ($item['ipprotocol'] === $inet_type) { foreach ($a_gateways as $item) {
if (isset($item['defaultgw'])) if ($item['ipprotocol'] === $inet_type) {
$is_default = false; if (isset($item['defaultgw'])) {
if (($item['interface'] === $interface) && ($item['gateway'] === $gatewayip)) $is_default = false;
$new_name = $item['name']; }
} if (($item['interface'] === $interface) && ($item['gateway'] === $gatewayip)) {
} $new_name = $item['name'];
if ($new_name == '') { }
$new_name = next_unused_gateway_name($interface); }
$item = array( }
"interface" => $interface, if ($new_name == '') {
"gateway" => $gatewayip, $new_name = next_unused_gateway_name($interface);
"name" => $new_name, $item = array(
"weight" => 1, "interface" => $interface,
"ipprotocol" => $inet_type, "gateway" => $gatewayip,
"interval" => true, "name" => $new_name,
"descr" => "Interface $interface Gateway", "weight" => 1,
"defaultgw" => $is_default "ipprotocol" => $inet_type,
); "interval" => true,
if ($dry_run) { "descr" => "Interface $interface Gateway",
print_r($item); "defaultgw" => $is_default
} );
$a_gateways[] = $item; if ($dry_run) {
} print_r($item);
}
return $new_name; $a_gateways[] = $item;
}
return $new_name;
} }
function console_configure_ip_address($version) { function console_configure_ip_address($version)
global $g, $config, $interface, $restart_dhcpd, $ifaceassigned, $fp; {
global $g, $config, $interface, $restart_dhcpd, $ifaceassigned, $fp;
$label_IPvX = ($version === 6) ? "IPv6" : "IPv4";
$maxbits = ($version === 6) ? 127 : 31; $label_IPvX = ($version === 6) ? "IPv6" : "IPv4";
$label_DHCP = ($version === 6) ? "DHCP6" : "DHCP"; $maxbits = ($version === 6) ? 127 : 31;
$label_DHCP = ($version === 6) ? "DHCP6" : "DHCP";
$upperifname = strtoupper($interface);
$upperifname = strtoupper($interface);
if($interface == "wan") {
if (console_prompt_for_yn (sprintf(gettext("Configure %s address %s interface via %s?"), $label_IPvX, $upperifname, $label_DHCP))) { if ($interface == "wan") {
$ifppp = console_get_interface_from_ppp(get_real_interface("wan")); if (console_prompt_for_yn(sprintf(gettext("Configure %s address %s interface via %s?"), $label_IPvX, $upperifname, $label_DHCP))) {
if (!empty($ifppp)) $ifppp = console_get_interface_from_ppp(get_real_interface("wan"));
$ifaceassigned = $ifppp; if (!empty($ifppp)) {
$intip = ($version === 6) ? "dhcp6" : "dhcp"; $ifaceassigned = $ifppp;
$intbits = ""; }
$isintdhcp = true; $intip = ($version === 6) ? "dhcp6" : "dhcp";
$restart_dhcpd = true; $intbits = "";
} $isintdhcp = true;
} $restart_dhcpd = true;
}
if($isintdhcp == false or $interface <> "wan") { }
while(true) {
do { if ($isintdhcp == false or $interface <> "wan") {
echo "\n" . sprintf(gettext("Enter the new %s %s address. Press <ENTER> for none:"), while (true) {
$upperifname, $label_IPvX) . "\n> "; do {
$intip = chop(fgets($fp)); echo "\n" . sprintf(
$is_ipaddr = ($version === 6) ? is_ipaddrv6($intip) : is_ipaddrv4($intip); gettext("Enter the new %s %s address. Press <ENTER> for none:"),
if ($is_ipaddr && is_ipaddr_configured($intip, $interface, true)) { $upperifname,
$ip_conflict = true; $label_IPvX
echo gettext("This IP address conflicts with another interface or a VIP") . "\n"; ) . "\n> ";
} else $intip = chop(fgets($fp));
$ip_conflict = false; $is_ipaddr = ($version === 6) ? is_ipaddrv6($intip) : is_ipaddrv4($intip);
} while (($ip_conflict === true) || !($is_ipaddr || $intip == '')); if ($is_ipaddr && is_ipaddr_configured($intip, $interface, true)) {
if ($intip != '') { $ip_conflict = true;
echo "\n" . sprintf(gettext("Subnet masks are entered as bit counts (as in CIDR notation) in %s."), echo gettext("This IP address conflicts with another interface or a VIP") . "\n";
$g['product_name']) . "\n"; } else {
if ($version === 6) { $ip_conflict = false;
echo "e.g. ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00 = 120\n"; }
echo " ffff:ffff:ffff:ffff:ffff:ffff:ffff:0 = 112\n"; } while (($ip_conflict === true) || !($is_ipaddr || $intip == ''));
echo " ffff:ffff:ffff:ffff:ffff:ffff:0:0 = 96\n"; if ($intip != '') {
echo " ffff:ffff:ffff:ffff:ffff:0:0:0 = 80\n"; echo "\n" . sprintf(
echo " ffff:ffff:ffff:ffff:0:0:0:0 = 64\n"; gettext("Subnet masks are entered as bit counts (as in CIDR notation) in %s."),
} else { $g['product_name']
echo "e.g. 255.255.255.0 = 24\n"; ) . "\n";
echo " 255.255.0.0 = 16\n"; if ($version === 6) {
echo " 255.0.0.0 = 8\n"; echo "e.g. ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00 = 120\n";
} echo " ffff:ffff:ffff:ffff:ffff:ffff:ffff:0 = 112\n";
do { echo " ffff:ffff:ffff:ffff:ffff:ffff:0:0 = 96\n";
$upperifname = strtoupper($interface); echo " ffff:ffff:ffff:ffff:ffff:0:0:0 = 80\n";
echo "\n" . sprintf(gettext("Enter the new %s %s subnet bit count (1 to %s):"), echo " ffff:ffff:ffff:ffff:0:0:0:0 = 64\n";
$upperifname, $label_IPvX, $maxbits) . "\n> "; } else {
$intbits = chop(fgets($fp)); echo "e.g. 255.255.255.0 = 24\n";
$intbits_ok = is_numeric($intbits) && (($intbits >= 1) && ($intbits <= $maxbits)); echo " 255.255.0.0 = 16\n";
$restart_dhcpd = true; echo " 255.0.0.0 = 8\n";
}
if ($version === 4 && $intbits < $maxbits) { do {
if ($intip == gen_subnet($intip, $intbits)) { $upperifname = strtoupper($interface);
echo gettext("You cannot set network address to an interface"); echo "\n" . sprintf(
continue 2; gettext("Enter the new %s %s subnet bit count (1 to %s):"),
$intbits_ok = false; $upperifname,
} else if ($intip == gen_subnet_max($intip, $intbits)) { $label_IPvX,
echo gettext("You cannot set broadcast address to an interface"); $maxbits
continue 2; ) . "\n> ";
$intbits_ok = false; $intbits = chop(fgets($fp));
} $intbits_ok = is_numeric($intbits) && (($intbits >= 1) && ($intbits <= $maxbits));
} $restart_dhcpd = true;
} while (!$intbits_ok);
if ($version === 4 && $intbits < $maxbits) {
if ($version === 6) { if ($intip == gen_subnet($intip, $intbits)) {
$subnet = gen_subnetv6($intip, $intbits); echo gettext("You cannot set network address to an interface");
} else { continue 2;
$subnet = gen_subnet($intip, $intbits); $intbits_ok = false;
} } elseif ($intip == gen_subnet_max($intip, $intbits)) {
do { echo gettext("You cannot set broadcast address to an interface");
echo "\n" . sprintf(gettext("For a WAN, enter the new %s %s upstream gateway address."), $upperifname, $label_IPvX) . "\n" . continue 2;
gettext("For a LAN, press <ENTER> for none:") . "\n> "; $intbits_ok = false;
$gwip = chop(fgets($fp)); }
$is_ipaddr = ($version === 6) ? is_ipaddrv6($gwip) : is_ipaddrv4($gwip); }
$is_in_subnet = $is_ipaddr && ip_in_subnet($gwip, $subnet . "/" . $intbits); } while (!$intbits_ok);
if ($gwip != '') {
if (!$is_ipaddr) { if ($version === 6) {
echo sprintf(gettext("not an %s IP address!"), $label_IPvX) . "\n"; $subnet = gen_subnetv6($intip, $intbits);
} else if (!$is_in_subnet) { } else {
echo gettext("not in subnet!") . "\n"; $subnet = gen_subnet($intip, $intbits);
} }
} do {
} while (!($gwip == '' || ($is_ipaddr && $is_in_subnet))); echo "\n" . sprintf(gettext("For a WAN, enter the new %s %s upstream gateway address."), $upperifname, $label_IPvX) . "\n" .
gettext("For a LAN, press <ENTER> for none:") . "\n> ";
if ($gwip != '') { $gwip = chop(fgets($fp));
$inet_type = ($version === 6) ? "inet6" : "inet"; $is_ipaddr = ($version === 6) ? is_ipaddrv6($gwip) : is_ipaddrv4($gwip);
$gwname = add_gateway_to_config($interface, $gwip, $inet_type); $is_in_subnet = $is_ipaddr && ip_in_subnet($gwip, $subnet . "/" . $intbits);
} if ($gwip != '') {
} if (!$is_ipaddr) {
$ifppp = console_get_interface_from_ppp(get_real_interface($interface)); echo sprintf(gettext("not an %s IP address!"), $label_IPvX) . "\n";
if (!empty($ifppp)) } elseif (!$is_in_subnet) {
$ifaceassigned = $ifppp; echo gettext("not in subnet!") . "\n";
break; }
} }
} } while (!($gwip == '' || ($is_ipaddr && $is_in_subnet)));
return array($intip, $intbits, $gwname); if ($gwip != '') {
$inet_type = ($version === 6) ? "inet6" : "inet";
$gwname = add_gateway_to_config($interface, $gwip, $inet_type);
}
}
$ifppp = console_get_interface_from_ppp(get_real_interface($interface));
if (!empty($ifppp)) {
$ifaceassigned = $ifppp;
}
break;
}
}
return array($intip, $intbits, $gwname);
} }
list($intip, $intbits, $gwname) = console_configure_ip_address(4); list($intip, $intbits, $gwname) = console_configure_ip_address(4);
list($intip6, $intbits6, $gwname6) = console_configure_ip_address(6); list($intip6, $intbits6, $gwname6) = console_configure_ip_address(6);
if (!empty($ifaceassigned)) if (!empty($ifaceassigned)) {
$config['interfaces'][$interface]['if'] = $ifaceassigned; $config['interfaces'][$interface]['if'] = $ifaceassigned;
}
$config['interfaces'][$interface]['ipaddr'] = $intip; $config['interfaces'][$interface]['ipaddr'] = $intip;
$config['interfaces'][$interface]['subnet'] = $intbits; $config['interfaces'][$interface]['subnet'] = $intbits;
$config['interfaces'][$interface]['gateway'] = $gwname; $config['interfaces'][$interface]['gateway'] = $gwname;
...@@ -361,57 +389,60 @@ $config['interfaces'][$interface]['subnetv6'] = $intbits6; ...@@ -361,57 +389,60 @@ $config['interfaces'][$interface]['subnetv6'] = $intbits6;
$config['interfaces'][$interface]['gatewayv6'] = $gwname6; $config['interfaces'][$interface]['gatewayv6'] = $gwname6;
$config['interfaces'][$interface]['enable'] = true; $config['interfaces'][$interface]['enable'] = true;
function console_configure_dhcpd($version = 4) { function console_configure_dhcpd($version = 4)
global $g, $config, $restart_dhcpd, $fp, $interface, $dry_run, $intip, $intbits, $intip6, $intbits6; {
global $g, $config, $restart_dhcpd, $fp, $interface, $dry_run, $intip, $intbits, $intip6, $intbits6;
$label_IPvX = ($version === 6) ? "IPv6" : "IPv4";
$dhcpd = ($version === 6) ? "dhcpdv6" : "dhcpd"; $label_IPvX = ($version === 6) ? "IPv6" : "IPv4";
$dhcpd = ($version === 6) ? "dhcpdv6" : "dhcpd";
if (prompt_for_enable_dhcp_server($version)) {
$subnet_start = ($version === 6) ? gen_subnetv6($intip6, $intbits6) : gen_subnet($intip, $intbits); if (prompt_for_enable_dhcp_server($version)) {
$subnet_end = ($version === 6) ? gen_subnetv6_max($intip6, $intbits6) : gen_subnet_max($intip, $intbits); $subnet_start = ($version === 6) ? gen_subnetv6($intip6, $intbits6) : gen_subnet($intip, $intbits);
do { $subnet_end = ($version === 6) ? gen_subnetv6_max($intip6, $intbits6) : gen_subnet_max($intip, $intbits);
do { do {
echo sprintf(gettext("Enter the start address of the %s client address range:"), $label_IPvX) . " "; do {
$dhcpstartip = chop(fgets($fp)); echo sprintf(gettext("Enter the start address of the %s client address range:"), $label_IPvX) . " ";
if ($dhcpstartip === "") { $dhcpstartip = chop(fgets($fp));
fclose($fp); if ($dhcpstartip === "") {
exit(0); fclose($fp);
} exit(0);
$is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpstartip) : is_ipaddrv4($dhcpstartip); }
$is_inrange = is_inrange($dhcpstartip, $subnet_start, $subnet_end); $is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpstartip) : is_ipaddrv4($dhcpstartip);
if (!$is_inrange) $is_inrange = is_inrange($dhcpstartip, $subnet_start, $subnet_end);
echo gettext("This IP address must be in the interface's subnet") . "\n"; if (!$is_inrange) {
} while (!$is_ipaddr || !$is_inrange); echo gettext("This IP address must be in the interface's subnet") . "\n";
}
do { } while (!$is_ipaddr || !$is_inrange);
echo sprintf(gettext("Enter the end address of the %s client address range:"), $label_IPvX) . " ";
$dhcpendip = chop(fgets($fp)); do {
if ($dhcpendip === "") { echo sprintf(gettext("Enter the end address of the %s client address range:"), $label_IPvX) . " ";
fclose($fp); $dhcpendip = chop(fgets($fp));
exit(0); if ($dhcpendip === "") {
} fclose($fp);
$is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpendip) : is_ipaddrv4($dhcpendip); exit(0);
$is_inrange = is_inrange($dhcpendip, $subnet_start, $subnet_end); }
if (!$is_inrange) $is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpendip) : is_ipaddrv4($dhcpendip);
echo gettext("This IP address must be in the interface's subnet") . "\n"; $is_inrange = is_inrange($dhcpendip, $subnet_start, $subnet_end);
$not_inorder = ($version === 6) ? (inet_pton($dhcpendip) < inet_pton($dhcpstartip)) : ip_less_than($dhcpendip, $dhcpstartip); if (!$is_inrange) {
if ($not_inorder) { echo gettext("This IP address must be in the interface's subnet") . "\n";
echo gettext("The end address of the DHCP range must be >= the start address") . "\n"; }
} $not_inorder = ($version === 6) ? (inet_pton($dhcpendip) < inet_pton($dhcpstartip)) : ip_less_than($dhcpendip, $dhcpstartip);
} while (!$is_ipaddr || !$is_inrange); if ($not_inorder) {
} while ($not_inorder); echo gettext("The end address of the DHCP range must be >= the start address") . "\n";
$restart_dhcpd = true; }
$config[$dhcpd][$interface]['enable'] = true; } while (!$is_ipaddr || !$is_inrange);
$config[$dhcpd][$interface]['range']['from'] = $dhcpstartip; } while ($not_inorder);
$config[$dhcpd][$interface]['range']['to'] = $dhcpendip; $restart_dhcpd = true;
} else { $config[$dhcpd][$interface]['enable'] = true;
if(isset($config[$dhcpd][$interface]['enable'])) { $config[$dhcpd][$interface]['range']['from'] = $dhcpstartip;
unset($config[$dhcpd][$interface]['enable']); $config[$dhcpd][$interface]['range']['to'] = $dhcpendip;
printf(gettext("Disabling %s DHCPD..."), $label_IPvX); } else {
$restart_dhcpd = true; if (isset($config[$dhcpd][$interface]['enable'])) {
} unset($config[$dhcpd][$interface]['enable']);
} printf(gettext("Disabling %s DHCPD..."), $label_IPvX);
$restart_dhcpd = true;
}
}
} }
console_configure_dhcpd(4); console_configure_dhcpd(4);
...@@ -420,103 +451,120 @@ console_configure_dhcpd(6); ...@@ -420,103 +451,120 @@ console_configure_dhcpd(6);
//***************************************************************************** //*****************************************************************************
if ($config['system']['webgui']['protocol'] == "https") { if ($config['system']['webgui']['protocol'] == "https") {
if (console_prompt_for_yn(gettext("Do you want to revert to HTTP as the webConfigurator protocol?"))) {
if (console_prompt_for_yn (gettext("Do you want to revert to HTTP as the webConfigurator protocol?"))) { $config['system']['webgui']['protocol'] = "http";
$config['system']['webgui']['protocol'] = "http"; $restart_webgui = true;
$restart_webgui = true; }
}
} }
if (isset($config['system']['webgui']['noantilockout'])) { if (isset($config['system']['webgui']['noantilockout'])) {
echo "\n" . sprintf(gettext("Note: the anti-lockout rule on %s has been re-enabled."), $interface) . "\n"; echo "\n" . sprintf(gettext("Note: the anti-lockout rule on %s has been re-enabled."), $interface) . "\n";
unset($config['system']['webgui']['noantilockout']); unset($config['system']['webgui']['noantilockout']);
} }
if($config['interfaces']['lan']) { if ($config['interfaces']['lan']) {
if($config['dhcpd']) if ($config['dhcpd']) {
if($config['dhcpd']['wan']) if ($config['dhcpd']['wan']) {
unset($config['dhcpd']['wan']); unset($config['dhcpd']['wan']);
if($config['dhcpdv6']) }
if($config['dhcpdv6']['wan']) }
unset($config['dhcpdv6']['wan']); if ($config['dhcpdv6']) {
if ($config['dhcpdv6']['wan']) {
unset($config['dhcpdv6']['wan']);
}
}
} }
if(!$config['interfaces']['lan']) { if (!$config['interfaces']['lan']) {
unset($config['interfaces']['lan']); unset($config['interfaces']['lan']);
if($config['dhcpd']['lan']) if ($config['dhcpd']['lan']) {
unset($config['dhcpd']['lan']); unset($config['dhcpd']['lan']);
if($config['dhcpdv6']['lan']) }
unset($config['dhcpdv6']['lan']); if ($config['dhcpdv6']['lan']) {
unset($config['nat']); unset($config['dhcpdv6']['lan']);
if (!$dry_run) { }
system("rm /var/dhcpd/var/db/* >/dev/null 2>/dev/null"); unset($config['nat']);
$restart_dhcpd = true; if (!$dry_run) {
} system("rm /var/dhcpd/var/db/* >/dev/null 2>/dev/null");
$restart_dhcpd = true;
}
} }
$upperifname = strtoupper($interface); $upperifname = strtoupper($interface);
if (!$dry_run) { if (!$dry_run) {
echo "\nPlease wait while the changes are saved to {$upperifname}..."; echo "\nPlease wait while the changes are saved to {$upperifname}...";
write_config(sprintf(gettext("%s IP configuration from console menu"), $interface)); write_config(sprintf(gettext("%s IP configuration from console menu"), $interface));
interface_reconfigure(strtolower($upperifname)); interface_reconfigure(strtolower($upperifname));
echo "\n Reloading filter..."; echo "\n Reloading filter...";
filter_configure_sync(); filter_configure_sync();
if($restart_dhcpd) { if ($restart_dhcpd) {
echo "\n DHCPD..."; echo "\n DHCPD...";
services_dhcpd_configure(); services_dhcpd_configure();
} }
if ($restart_webgui) { if ($restart_webgui) {
mwexec('/usr/local/etc/rc.restart_webgui'); mwexec('/usr/local/etc/rc.restart_webgui');
} }
} }
if ($intip != '') { if ($intip != '') {
if (is_ipaddr($intip)) { if (is_ipaddr($intip)) {
echo "\n\n" . sprintf(gettext("The IPv4 %s address has been set to %s"), echo "\n\n" . sprintf(
$upperifname, "{$intip}/{$intbits}") . "\n"; gettext("The IPv4 %s address has been set to %s"),
} else { $upperifname,
echo "\n\n" . sprintf(gettext("The IPv4 %s address has been set to %s"), "{$intip}/{$intbits}"
$upperifname, $intip) . "\n"; ) . "\n";
} } else {
echo "\n\n" . sprintf(
gettext("The IPv4 %s address has been set to %s"),
$upperifname,
$intip
) . "\n";
}
} }
if ($intip6 != '') { if ($intip6 != '') {
if (is_ipaddr($intip6)) { if (is_ipaddr($intip6)) {
echo "\n\n" . sprintf(gettext("The IPv6 %s address has been set to %s"), echo "\n\n" . sprintf(
$upperifname, "${intip6}/${intbits6}") . "\n"; gettext("The IPv6 %s address has been set to %s"),
} else { $upperifname,
echo "\n\n" . sprintf(gettext("The IPv6 %s address has been set to %s"), "${intip6}/${intbits6}"
$upperifname, $intip6) . "\n"; ) . "\n";
} } else {
echo "\n\n" . sprintf(
gettext("The IPv6 %s address has been set to %s"),
$upperifname,
$intip6
) . "\n";
}
} }
if ($intip != '' || $intip6 != '') { if ($intip != '' || $intip6 != '') {
if (count($ifdescrs) == "1" or $interface == "lan") { if (count($ifdescrs) == "1" or $interface == "lan") {
echo gettext('You can now access the webConfigurator by opening the following URL in your web browser:') . "\n"; echo gettext('You can now access the webConfigurator by opening the following URL in your web browser:') . "\n";
if(!empty($config['system']['webgui']['port'])) { if (!empty($config['system']['webgui']['port'])) {
$webuiport = $config['system']['webgui']['port']; $webuiport = $config['system']['webgui']['port'];
if ($intip != '') { if ($intip != '') {
echo " {$config['system']['webgui']['protocol']}://{$intip}:{$webuiport}/\n"; echo " {$config['system']['webgui']['protocol']}://{$intip}:{$webuiport}/\n";
} }
if ($intip6 != '') { if ($intip6 != '') {
if (is_ipaddr($intip6)) { if (is_ipaddr($intip6)) {
echo " {$config['system']['webgui']['protocol']}://[{$intip6}]:{$webuiport}/\n"; echo " {$config['system']['webgui']['protocol']}://[{$intip6}]:{$webuiport}/\n";
} else { } else {
echo " {$config['system']['webgui']['protocol']}://{$intip6}:{$webuiport}/\n"; echo " {$config['system']['webgui']['protocol']}://{$intip6}:{$webuiport}/\n";
} }
} }
} else { } else {
if ($intip != '') { if ($intip != '') {
echo " {$config['system']['webgui']['protocol']}://{$intip}/\n"; echo " {$config['system']['webgui']['protocol']}://{$intip}/\n";
} }
if ($intip6 != '') { if ($intip6 != '') {
if (is_ipaddr($intip6)) { if (is_ipaddr($intip6)) {
echo " {$config['system']['webgui']['protocol']}://[{$intip6}]/\n"; echo " {$config['system']['webgui']['protocol']}://[{$intip6}]/\n";
} else { } else {
echo " {$config['system']['webgui']['protocol']}://{$intip6}/\n"; echo " {$config['system']['webgui']['protocol']}://{$intip6}/\n";
} }
} }
} }
} }
} }
echo "\n" . gettext('Press <ENTER> to continue.'); echo "\n" . gettext('Press <ENTER> to continue.');
......
...@@ -42,11 +42,11 @@ require_once("pfsense-utils.inc"); ...@@ -42,11 +42,11 @@ require_once("pfsense-utils.inc");
require_once("unbound.inc"); require_once("unbound.inc");
if (set_networking_interfaces_ports()) { if (set_networking_interfaces_ports()) {
echo "Reloading interfaces..."; echo "Reloading interfaces...";
global $config; global $config;
$config = parse_config(); $config = parse_config();
system_routing_enable(); system_routing_enable();
interfaces_configure(); interfaces_configure();
echo "done.\n"; echo "done.\n";
enable_rrd_graphing(); enable_rrd_graphing();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment