From d640192e30f07dd55c40a1699dc835e7a453ccac Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sun, 21 May 2017 11:21:46 +0200 Subject: [PATCH] rc: root console tidy-up Adjust tabs to spaces, copyright headers and add missing one from restore script as per: https://github.com/pfsense/pfsense/commit/7d7ce752 --- src/etc/inc/console.inc | 798 ++++++++++++++++++------------------ src/etc/rc.initial.banner | 50 +-- src/etc/rc.initial.defaults | 48 +-- src/etc/rc.initial.halt | 50 +-- src/etc/rc.initial.password | 1 + src/etc/rc.initial.ping | 2 +- src/etc/rc.initial.reboot | 48 +-- src/etc/rc.initial.restore | 210 ++++++---- src/etc/rc.initial.setports | 48 +-- 9 files changed, 645 insertions(+), 610 deletions(-) diff --git a/src/etc/inc/console.inc b/src/etc/inc/console.inc index 73da7f735..9c54b1665 100644 --- a/src/etc/inc/console.inc +++ b/src/etc/inc/console.inc @@ -1,123 +1,123 @@ - Copyright (C) 2004-2010 Scott Ullrich - Copyright (C) 2003-2004 Manuel Kasper - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (C) 2015-2016 Franco Fichtner + * Copyright (C) 2004-2010 Scott Ullrich + * Copyright (C) 2003-2004 Manuel Kasper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ function timeout($timer = 5) { - while (!isset($key)) { - if ($timer >= 9) { echo chr(8) . chr(8) . ($timer==9 ? chr(32) : null) . "{$timer}"; } - else { echo chr(8). "{$timer}"; } - shell_exec('/bin/stty -icanon min 0 time 25'); - $key = shell_exec('/bin/dd count=1 status=none'); - shell_exec('/bin/stty icanon'); - if ($key == '') { - unset($key); - } - $timer--; - if ($timer == 0) { - break; - } - } + while (!isset($key)) { + if ($timer >= 9) { echo chr(8) . chr(8) . ($timer==9 ? chr(32) : null) . "{$timer}"; } + else { echo chr(8). "{$timer}"; } + shell_exec('/bin/stty -icanon min 0 time 25'); + $key = shell_exec('/bin/dd count=1 status=none'); + shell_exec('/bin/stty icanon'); + if ($key == '') { + unset($key); + } + $timer--; + if ($timer == 0) { + break; + } + } - return $key; + return $key; } function set_networking_interfaces_ports($probe = false) { - global $config; + global $config; - $fp = fopen('php://stdin', 'r'); - $yes_no_prompt = '[y/N]: '; - $interactive = true; - $key = null; + $fp = fopen('php://stdin', 'r'); + $yes_no_prompt = '[y/N]: '; + $interactive = true; + $key = null; - $iflist = get_interface_list(false, true); + $iflist = get_interface_list(false, true); - if ($probe) { - echo PHP_EOL . 'Press any key to start the manual interface assignment: '; + if ($probe) { + echo PHP_EOL . 'Press any key to start the manual interface assignment: '; - $key = timeout(); - if (!isset($key)) { - $interactive = false; - } + $key = timeout(); + if (!isset($key)) { + $interactive = false; + } - if ($key != "\n") { - echo PHP_EOL; - } - } + if ($key != "\n") { + echo PHP_EOL; + } + } - echo << $ifa) { - interfaces_bring_up($iface); - echo sprintf("%-16s %s %s\n", $iface, $ifa['mac'], $ifa['dmesg']); - } - } + if (!is_array($iflist)) { + echo "No interfaces found!\n"; + $iflist = array(); + } else { + foreach ($iflist as $iface => $ifa) { + interfaces_bring_up($iface); + echo sprintf("%-16s %s %s\n", $iface, $ifa['mac'], $ifa['dmesg']); + } + } - $ifnames = array_keys($iflist); + $ifnames = array_keys($iflist); - echo << 1 ? $ifnames[1] : ''; - echo $wanif . PHP_EOL; - } + if ($interactive) { + $wanif = chop(fgets($fp)); + } else { + /* more than one interface: put WAN as second one */ + $wanif = count($ifnames) > 1 ? $ifnames[1] : ''; + echo $wanif . PHP_EOL; + } - if ($wanif == '') { - break; - } + if ($wanif == '') { + break; + } - if ($wanif == 'a') { - $wanif = autodetect_interface('WAN', $fp); - if (!$wanif) { - continue; - } - } + if ($wanif == 'a') { + $wanif = autodetect_interface('WAN', $fp); + if (!$wanif) { + continue; + } + } - if (!array_key_exists($wanif, $iflist)) { - printf("\nInvalid interface name '%s'\n", $wanif); - unset($wanif); - } - } while (!$wanif); + if (!array_key_exists($wanif, $iflist)) { + printf("\nInvalid interface name '%s'\n", $wanif); + unset($wanif); + } + } while (!$wanif); - do { - echo "\nEnter the LAN interface name or 'a' for auto-detection\n" . - "NOTE: this enables full Firewalling/NAT mode.\n" . - "(or nothing if finished): "; + do { + echo "\nEnter the LAN interface name or 'a' for auto-detection\n" . + "NOTE: this enables full Firewalling/NAT mode.\n" . + "(or nothing if finished): "; - if ($interactive) { - $lanif = chop(fgets($fp)); - } else { - /* at least one interface: put LAN as first one */ - $lanif = count($ifnames) > 0 ? $ifnames[0] : ''; - echo $lanif . PHP_EOL; - } + if ($interactive) { + $lanif = chop(fgets($fp)); + } else { + /* at least one interface: put LAN as first one */ + $lanif = count($ifnames) > 0 ? $ifnames[0] : ''; + echo $lanif . PHP_EOL; + } - if ($lanif == '') { - break; - } + if ($lanif == '') { + break; + } - if ($lanif == 'a') { - $lanif = autodetect_interface('LAN', $fp); - if (!$lanif) { - continue; - } - } + if ($lanif == 'a') { + $lanif = autodetect_interface('LAN', $fp); + if (!$lanif) { + continue; + } + } - if (!array_key_exists($lanif, $iflist)) { - printf("\nInvalid interface name '%s'\n", $lanif); - unset($lanif); - } + if (!array_key_exists($lanif, $iflist)) { + printf("\nInvalid interface name '%s'\n", $lanif); + unset($lanif); + } - if ($wanif && $lanif == $wanif) { - unset($lanif); - echo << " . $wanif . "\n"; - } - if ($lanif != '') { - echo "LAN -> " . $lanif . "\n"; - } - for ($i = 0; $i < count($optif); $i++) { - echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n"; - } - } else { - echo "\nNo interfaces will be assigned!\n"; - } + if ($wanif != '') { + echo "WAN -> " . $wanif . "\n"; + } + if ($lanif != '') { + echo "LAN -> " . $lanif . "\n"; + } + for ($i = 0; $i < count($optif); $i++) { + echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n"; + } + } else { + echo "\nNo interfaces will be assigned!\n"; + } - echo << $ifa) { - if (!isset($iflist_prev[$ifn])) { - printf("Detected link-up: %s\n", $ifn); - return $ifn; - } - } - } + if (is_array($iflist)) { + foreach ($iflist as $ifn => $ifa) { + if (!isset($iflist_prev[$ifn])) { + printf("Detected link-up: %s\n", $ifn); + return $ifn; + } + } + } - echo "No link-up detected.\n"; + echo "No link-up detected.\n"; - return false; + return false; } function vlan_setup($iflist, $fp) { - global $config; + global $config; - $yes_no_prompt = '[y/N]: '; + $yes_no_prompt = '[y/N]: '; - if (isset($config['vlans']['vlan'])) { + if (isset($config['vlans']['vlan'])) { - echo << $ifa) { - if (is_jumbo_capable($iface)) { - echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'], - $ifa['up'] ? " (up)" : ""); - $vlan_capable++; - } - } - } + echo "\n\nVLAN-capable interfaces:\n\n"; + if(!is_array($iflist)) { + echo "No interfaces found!\n"; + } else { + $vlan_capable=0; + foreach ($iflist as $iface => $ifa) { + if (is_jumbo_capable($iface)) { + echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'], + $ifa['up'] ? " (up)" : ""); + $vlan_capable++; + } + } + } - if($vlan_capable == 0) { - echo "No VLAN-capable interfaces detected.\n"; - return; - } + if($vlan_capable == 0) { + echo "No VLAN-capable interfaces detected.\n"; + return; + } - echo "\nEnter the parent interface name for the new VLAN (or nothing if finished): "; - $vlan['if'] = chop(fgets($fp)); + echo "\nEnter the parent interface name for the new VLAN (or nothing if finished): "; + $vlan['if'] = chop(fgets($fp)); - if ($vlan['if']) { - if (!array_key_exists($vlan['if'], $iflist) or - !is_jumbo_capable($vlan['if'])) { - printf("\nInvalid interface name '%s'\n", $vlan['if']); - continue; - } - } else { - break; - } + if ($vlan['if']) { + if (!array_key_exists($vlan['if'], $iflist) or + !is_jumbo_capable($vlan['if'])) { + printf("\nInvalid interface name '%s'\n", $vlan['if']); + continue; + } + } else { + break; + } - echo 'Enter the VLAN tag (1-4094): '; - $vlan['tag'] = chop(fgets($fp)); - $vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}"; - if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) { - printf("\nInvalid VLAN tag '%s'\n", $vlan['tag']); - continue; - } + echo 'Enter the VLAN tag (1-4094): '; + $vlan['tag'] = chop(fgets($fp)); + $vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}"; + if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) { + printf("\nInvalid VLAN tag '%s'\n", $vlan['tag']); + continue; + } - $config['vlans']['vlan'][] = $vlan; - $vlanif++; - } + $config['vlans']['vlan'][] = $vlan; + $vlanif++; + } } diff --git a/src/etc/rc.initial.banner b/src/etc/rc.initial.banner index c64b93b7c..301303437 100755 --- a/src/etc/rc.initial.banner +++ b/src/etc/rc.initial.banner @@ -2,31 +2,31 @@ . - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (C) 2003-2004 Manuel Kasper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ require_once("util.inc"); require_once("config.inc"); diff --git a/src/etc/rc.initial.halt b/src/etc/rc.initial.halt index bafe023ce..ca634da3e 100755 --- a/src/etc/rc.initial.halt +++ b/src/etc/rc.initial.halt @@ -2,31 +2,31 @@ - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (C) 2004 Bachman Kharazmi + * Copyright (C) 2003-2004 Manuel Kasper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ require_once("util.inc"); require_once("config.inc"); diff --git a/src/etc/rc.initial.password b/src/etc/rc.initial.password index 8b7cb491d..d96a03252 100755 --- a/src/etc/rc.initial.password +++ b/src/etc/rc.initial.password @@ -2,6 +2,7 @@ * Copyright (C) 2003-2004 Manuel Kasper . * All rights reserved. * diff --git a/src/etc/rc.initial.ping b/src/etc/rc.initial.ping index f276766c7..c8ad875f0 100755 --- a/src/etc/rc.initial.ping +++ b/src/etc/rc.initial.ping @@ -25,7 +25,7 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. -*/ + */ require_once("config.inc"); require_once("util.inc"); diff --git a/src/etc/rc.initial.reboot b/src/etc/rc.initial.reboot index f4cf80a47..82831e389 100755 --- a/src/etc/rc.initial.reboot +++ b/src/etc/rc.initial.reboot @@ -2,30 +2,30 @@ - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (C) 2003-2004 Manuel Kasper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ require_once("util.inc"); require_once("config.inc"); diff --git a/src/etc/rc.initial.restore b/src/etc/rc.initial.restore index f4fc9fdc5..29e278c97 100755 --- a/src/etc/rc.initial.restore +++ b/src/etc/rc.initial.restore @@ -1,6 +1,32 @@ #!/usr/local/bin/php + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + require_once('config.inc'); $cnf = OPNsense\Core\Config::getInstance(); @@ -8,112 +34,120 @@ $confvers = $cnf->getBackups(true); $fp = fopen('php://stdin', 'r'); -function print_backup_info($backup_info, $number) { - if($backup_info['time'] != 0) - $date = date('n/j/y H:i:s', $backup_info['time']); - else - $date = 'Unknown'; +function print_backup_info($backup_info, $number) +{ + if ($backup_info['time'] != 0) { + $date = date('n/j/y H:i:s', $backup_info['time']); + } else { + $date = 'Unknown'; + } - list($page, $reason) = explode(": ", $backup_info['description'], 2); - if (empty($reason)) { - $reason = $page; - $page = 'Unknown Page'; - } + list($page, $reason) = explode(": ", $backup_info['description'], 2); + if (empty($reason)) { + $reason = $page; + $page = 'Unknown Page'; + } - echo sprintf("%02d", $number) . ". {$date}\tv{$backup_info['version']}\t{$page}\n"; - if ($reason) { - echo " {$reason}\n"; - } + echo sprintf("%02d", $number) . ". {$date}\tv{$backup_info['version']}\t{$page}\n"; + if ($reason) { + echo " {$reason}\n"; + } } -function list_backups($which="all") { - global $confvers; +function list_backups($which = 'all') +{ + global $confvers; - if (count($confvers) == 0) { - echo 'No backups found in the configuration history.'; - return; - } + if (count($confvers) == 0) { + echo 'No backups found in the configuration history.'; + return; + } - $c = 0 ; - foreach ($confvers as $filename => $bckinfo) { - $c++; - if (is_numeric($which) && ($c != $which)) - continue; - print_backup_info($bckinfo,$c); - } + $c = 0 ; + foreach ($confvers as $filename => $bckinfo) { + $c++; + if (is_numeric($which) && ($c != $which)) { + continue; + } + print_backup_info($bckinfo,$c); + } } -function choose_backup() { - global $fp, $confvers; - if (count($confvers) == 0) { - echo 'No backups found in the configuration history.'; - return -1; - } - echo "Which configuration would you like to restore?\n"; - echo " 1-" . count($confvers) . " : "; - $number = strtoupper(chop(fgets($fp))); - if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) { - return $number; - } else { - echo "That is not a valid backup number.\n"; - return -1; - } +function choose_backup() +{ + global $fp, $confvers; + + if (count($confvers) == 0) { + echo 'No backups found in the configuration history.'; + return -1; + } + + echo "Which configuration would you like to restore?\n"; + echo " 1-" . count($confvers) . " : "; + + $number = strtoupper(chop(fgets($fp))); + if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) { + return $number; + } + + echo "That is not a valid backup number.\n"; + return -1; } function restore_history_backup($number) { - global $fp, $confvers; + global $fp, $confvers; - if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) { - echo "\nIs this the backup you wish to restore?\n"; - list_backups($number); - $filename = array_keys($confvers)[$number-1]; - $thisbackup = $confvers[$filename]; - echo '[y/N]: '; - $confirm = strtoupper(chop(fgets($fp))); - if ($confirm == 'Y') { - $cnf = OPNsense\Core\Config::getInstance(); - if($cnf->restoreBackup($filename)){ - echo "\n"; - echo sprintf('Successfully reverted to timestamp %s with description "%s".', date('n/j/y H:i:s', $thisbackup['time']), $thisbackup['description']); - echo "\nYou may need to reboot the firewall or restart services before the restored configuration is fully active.\n\n"; - } else { - echo "Unable to revert to the selected configuration.\n"; - } - } else { - echo "Restore canceled.\n"; - } - } else { - echo "Restore canceled due to invalid input.\n"; - } + if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) { + echo "\nIs this the backup you wish to restore?\n"; + list_backups($number); + $filename = array_keys($confvers)[$number-1]; + $thisbackup = $confvers[$filename]; + echo '[y/N]: '; + $confirm = strtoupper(chop(fgets($fp))); + if ($confirm == 'Y') { + $cnf = OPNsense\Core\Config::getInstance(); + if ($cnf->restoreBackup($filename)){ + echo "\n"; + echo sprintf('Successfully reverted to timestamp %s with description "%s".', date('n/j/y H:i:s', $thisbackup['time']), $thisbackup['description']); + echo "\nYou may need to reboot the firewall or restart services before the restored configuration is fully active.\n\n"; + } else { + echo "Unable to revert to the selected configuration.\n"; + } + } else { + echo "Restore canceled.\n"; + } + } else { + echo "Restore canceled due to invalid input.\n"; + } } while (true) { - echo "\nRestore Backup from Configuration History\n\n"; - echo "1) List Backups\n"; - echo "2) Restore Backup\n"; - echo "q) Quit\n\n\n"; - echo "Please select an option to continue: "; + echo "\nRestore Backup from Configuration History\n\n"; + echo "1) List Backups\n"; + echo "2) Restore Backup\n"; + echo "q) Quit\n\n\n"; + echo "Please select an option to continue: "; - $command = strtolower(chop(fgets($fp))); + $command = strtolower(chop(fgets($fp))); - switch ($command) { - case "q": - case "quit": - echo "\n"; - fclose($fp); - die; - break; - case "1": - list_backups(); - break; - case "2": - $number = choose_backup(); - restore_history_backup($number); - fclose($fp); - die; - break; - } + switch ($command) { + case "q": + case "quit": + echo "\n"; + fclose($fp); + die; + break; + case "1": + list_backups(); + break; + case "2": + $number = choose_backup(); + restore_history_backup($number); + fclose($fp); + die; + break; + } } fclose($fp); diff --git a/src/etc/rc.initial.setports b/src/etc/rc.initial.setports index 2d809fe4f..c787d709e 100755 --- a/src/etc/rc.initial.setports +++ b/src/etc/rc.initial.setports @@ -2,30 +2,30 @@ . - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (C) 2003-2004 Manuel Kasper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ require_once("config.inc"); require_once("console.inc");