From 1cb6d444b48e7dd1ebc707fc5fe80acfa5e225dd Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sat, 16 Jan 2016 11:48:13 +0100 Subject: [PATCH] globals: thin out the file o is_install_media() was being misused. In the instance of dhcp6, the backup file did not even exist, I think someone did copy+paste the IPv4 code back in the day and the actual backup was never added. o match_wireless_interface() was moved to interfaces.inc where it belongs. --- src/etc/inc/globals.inc | 24 -------- src/etc/inc/interfaces.inc | 6 ++ src/etc/inc/pfsense-utils.inc | 108 +++++++++++++++++----------------- src/etc/inc/services.inc | 25 ++------ src/etc/rc.bootup | 17 ++++++ 5 files changed, 82 insertions(+), 98 deletions(-) diff --git a/src/etc/inc/globals.inc b/src/etc/inc/globals.inc index 28873565b..b806da1f1 100644 --- a/src/etc/inc/globals.inc +++ b/src/etc/inc/globals.inc @@ -46,27 +46,3 @@ $g = array( "product_copyright_url" => "https://www.deciso.com/", "latest_config" => "11.2", ); - -function is_install_media() -{ - /* - * Despite unionfs underneath, / is still not writeable, - * making the following the perfect test for install media. - */ - - $file = '/.probe.for.install.media'; - $fd = @fopen($file, 'w'); - if ($fd) { - fclose($fd); - unlink($file); - return false; - } - - return true; -} - -function match_wireless_interface($int) -{ - $wireless_regex = '/^(ndis|wi|ath|an|ral|ural|iwi|wlan|rum|run|bwn|zyd|mwl|bwi|ipw|iwn|malo|uath|upgt|urtw|wpi)/'; - return preg_match($wireless_regex, $int); -} diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index b2dfa7ea9..af5d1daf1 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -93,6 +93,12 @@ function convert_128bit_to_ipv6($ip6bin) return $ip6addr; } +function match_wireless_interface($int) +{ + $wireless_regex = '/^(ndis|wi|ath|an|ral|ural|iwi|wlan|rum|run|bwn|zyd|mwl|bwi|ipw|iwn|malo|uath|upgt|urtw|wpi)/'; + return preg_match($wireless_regex, $int); +} + function interfaces_bring_up($interface) { if (!$interface) { diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index 468008ad5..b8fcf29e5 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -277,65 +277,65 @@ function setup_serial_port($sync = true) $loader_conf_file = '/boot/loader.conf'; $boot_config_file = '/boot.config'; - if (!is_install_media()) { - /* serial console - write out /boot.config */ - if (file_exists($boot_config_file)) { - $boot_config = file_get_contents($boot_config_file); - } else { - $boot_config = ''; + /* serial console - write out /boot.config */ + if (file_exists($boot_config_file)) { + $boot_config = file_get_contents($boot_config_file); + } else { + $boot_config = ''; + } + + $boot_config_split = explode("\n", $boot_config); + $fd = fopen($boot_config_file,"w"); + if($fd) { + foreach($boot_config_split as $bcs) { + if(stristr($bcs, "-D") || stristr($bcs, "-h")) { + /* DONT WRITE OUT, WE'LL DO IT LATER */ + } else { + if($bcs <> "") + fwrite($fd, "{$bcs}\n"); + } + } + if ($serial_enabled) { + @fwrite($fd, "-S{$serialspeed} -D\n"); + } + fclose($fd); + } + + $boot_config = @file_get_contents($loader_conf_file); + $boot_config_split = explode("\n", $boot_config); + if(count($boot_config_split) > 0) { + $new_boot_config = array(); + // Loop through and only add lines that are not empty, and which + // do not contain a console directive. + foreach($boot_config_split as $bcs) { + if(!empty($bcs) + && (stripos($bcs, "console") === false) + && (stripos($bcs, "boot_multicons") === false) + && (stripos($bcs, "boot_serial") === false) + && (stripos($bcs, "hw.usb.no_pf") === false) + && (stripos($bcs, "autoboot_delay") === false)) { + $new_boot_config[] = $bcs; + } } - $boot_config_split = explode("\n", $boot_config); - $fd = fopen($boot_config_file,"w"); - if($fd) { - foreach($boot_config_split as $bcs) { - if(stristr($bcs, "-D") || stristr($bcs, "-h")) { - /* DONT WRITE OUT, WE'LL DO IT LATER */ - } else { - if($bcs <> "") - fwrite($fd, "{$bcs}\n"); - } + if ($serial_enabled) { + $new_boot_config[] = 'boot_multicons="YES"'; + $new_boot_config[] = 'boot_serial="YES"'; + $primaryconsole = $config['system']['primaryconsole']; + switch ($primaryconsole) { + case "video": + $new_boot_config[] = 'console="vidconsole,comconsole"'; + break; + case "serial": + default: + $new_boot_config[] = 'console="comconsole,vidconsole"'; } - if ($serial_enabled) { - fwrite($fd, "-S{$serialspeed} -D\n"); - } - fclose($fd); } + $new_boot_config[] = 'comconsole_speed="' . $serialspeed . '"'; + $new_boot_config[] = 'hw.usb.no_pf="1"'; + $new_boot_config[] = 'autoboot_delay="3"'; - $boot_config = @file_get_contents($loader_conf_file); - $boot_config_split = explode("\n", $boot_config); - if(count($boot_config_split) > 0) { - $new_boot_config = array(); - // Loop through and only add lines that are not empty, and which - // do not contain a console directive. - foreach($boot_config_split as $bcs) - if(!empty($bcs) - && (stripos($bcs, "console") === false) - && (stripos($bcs, "boot_multicons") === false) - && (stripos($bcs, "boot_serial") === false) - && (stripos($bcs, "hw.usb.no_pf") === false) - && (stripos($bcs, "autoboot_delay") === false)) - $new_boot_config[] = $bcs; - - if ($serial_enabled) { - $new_boot_config[] = 'boot_multicons="YES"'; - $new_boot_config[] = 'boot_serial="YES"'; - $primaryconsole = $config['system']['primaryconsole']; - switch ($primaryconsole) { - case "video": - $new_boot_config[] = 'console="vidconsole,comconsole"'; - break; - case "serial": - default: - $new_boot_config[] = 'console="comconsole,vidconsole"'; - } - } - $new_boot_config[] = 'comconsole_speed="' . $serialspeed . '"'; - $new_boot_config[] = 'hw.usb.no_pf="1"'; - $new_boot_config[] = 'autoboot_delay="3"'; - - file_put_contents($loader_conf_file, implode("\n", $new_boot_config) . "\n"); - } + @file_put_contents($loader_conf_file, implode("\n", $new_boot_config) . "\n"); } $ttys = file_get_contents("/etc/ttys"); diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index 10e1dbf41..4d701463c 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -1052,34 +1052,19 @@ function services_dhcpdv6_configure($blacklist = array()) return 0; } - if (file_exists("/var/run/booting")) { - if (is_install_media()) { - /* restore the leases, if we have them */ - if (file_exists('/conf/dhcp6leases.tgz')) { - $dhcprestore = ''; - $dhcpreturn = ''; - exec('cd /;LANG=C /usr/bin/tar -xzf /conf/dhcp6leases.tgz 2>&1', $dhcprestore, $dhcpreturn); - $dhcprestore = implode(' ', $dhcprestore); - if($dhcpreturn <> 0) { - log_error("DHCP leases v6 restore failed exited with $dhcpreturn, the error is: $dhcprestore\n"); - } - - } - } - } - $syscfg = $config['system']; - if (!isset($config['dhcpdv6']) || !is_array($config['dhcpdv6'])) + if (!isset($config['dhcpdv6']) || !is_array($config['dhcpdv6'])) { $config['dhcpdv6'] = array(); + } $dhcpdv6cfg = $config['dhcpdv6']; $Iflist = get_configured_interface_list(); $Iflist = array_merge($Iflist, get_configured_pppoe_server_interfaces()); - - if (file_exists("/var/run/booting")) + if (file_exists("/var/run/booting")) { echo "Starting DHCPv6 service..."; - else + } else { sleep(1); + } /* we add a fake entry for interfaces that are set to track6 another WAN */ foreach ($Iflist as $ifname) { diff --git a/src/etc/rc.bootup b/src/etc/rc.bootup index ca9b04f75..414c53a3a 100755 --- a/src/etc/rc.bootup +++ b/src/etc/rc.bootup @@ -29,6 +29,23 @@ POSSIBILITY OF SUCH DAMAGE. */ +function is_install_media() +{ + /* + * Despite unionfs underneath, / is still not writeable, + * making the following the perfect test for install media. + */ + + $file = '/.probe.for.install.media'; + $fd = @fopen($file, 'w'); + if ($fd) { + fclose($fd); + unlink($file); + return false; + } + + return true; +} function is_interface_mismatch() {