Commit d640192e authored by Franco Fichtner's avatar Franco Fichtner

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
parent d63d59af
<?php <?php
/* /*
Copyright (C) 2015-2016 Franco Fichtner <franco@opnsense.org> * Copyright (C) 2015-2016 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com> * Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net> * Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
All rights reserved. * All rights reserved.
*
Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
*
1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
*
2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
*
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
function timeout($timer = 5) function timeout($timer = 5)
{ {
while (!isset($key)) { while (!isset($key)) {
if ($timer >= 9) { echo chr(8) . chr(8) . ($timer==9 ? chr(32) : null) . "{$timer}"; } if ($timer >= 9) { echo chr(8) . chr(8) . ($timer==9 ? chr(32) : null) . "{$timer}"; }
else { echo chr(8). "{$timer}"; } else { echo chr(8). "{$timer}"; }
shell_exec('/bin/stty -icanon min 0 time 25'); shell_exec('/bin/stty -icanon min 0 time 25');
$key = shell_exec('/bin/dd count=1 status=none'); $key = shell_exec('/bin/dd count=1 status=none');
shell_exec('/bin/stty icanon'); shell_exec('/bin/stty icanon');
if ($key == '') { if ($key == '') {
unset($key); unset($key);
} }
$timer--; $timer--;
if ($timer == 0) { if ($timer == 0) {
break; break;
} }
} }
return $key; return $key;
} }
function set_networking_interfaces_ports($probe = false) function set_networking_interfaces_ports($probe = false)
{ {
global $config; global $config;
$fp = fopen('php://stdin', 'r'); $fp = fopen('php://stdin', 'r');
$yes_no_prompt = '[y/N]: '; $yes_no_prompt = '[y/N]: ';
$interactive = true; $interactive = true;
$key = null; $key = null;
$iflist = get_interface_list(false, true); $iflist = get_interface_list(false, true);
if ($probe) { if ($probe) {
echo PHP_EOL . 'Press any key to start the manual interface assignment: '; echo PHP_EOL . 'Press any key to start the manual interface assignment: ';
$key = timeout(); $key = timeout();
if (!isset($key)) { if (!isset($key)) {
$interactive = false; $interactive = false;
} }
if ($key != "\n") { if ($key != "\n") {
echo PHP_EOL; echo PHP_EOL;
} }
} }
echo <<<EOD echo <<<EOD
Valid interfaces are: Valid interfaces are:
EOD; EOD;
if (!is_array($iflist)) { if (!is_array($iflist)) {
echo "No interfaces found!\n"; echo "No interfaces found!\n";
$iflist = array(); $iflist = array();
} else { } else {
foreach ($iflist as $iface => $ifa) { foreach ($iflist as $iface => $ifa) {
interfaces_bring_up($iface); interfaces_bring_up($iface);
echo sprintf("%-16s %s %s\n", $iface, $ifa['mac'], $ifa['dmesg']); echo sprintf("%-16s %s %s\n", $iface, $ifa['mac'], $ifa['dmesg']);
} }
} }
$ifnames = array_keys($iflist); $ifnames = array_keys($iflist);
echo <<<EOD echo <<<EOD
You now have the opportunity to configure VLANs. If you don't require VLANs You now have the opportunity to configure VLANs. If you don't require VLANs
for initial connectivity, say no here and use the GUI to configure VLANs later. for initial connectivity, say no here and use the GUI to configure VLANs later.
Do you want to set up VLANs now? ${yes_no_prompt} Do you want to set up VLANs now? ${yes_no_prompt}
EOD; EOD;
if ($interactive) { if ($interactive) {
$key = chop(fgets($fp)); $key = chop(fgets($fp));
} else { } else {
$key = 'n'; $key = 'n';
echo $key . PHP_EOL; echo $key . PHP_EOL;
} }
if (in_array($key, array('y', 'Y'))) { if (in_array($key, array('y', 'Y'))) {
vlan_setup($iflist, $fp); vlan_setup($iflist, $fp);
} }
if (isset($config['vlans']['vlan'])) { if (isset($config['vlans']['vlan'])) {
echo "\n\nVLAN interfaces:\n\n"; echo "\n\nVLAN interfaces:\n\n";
foreach ($config['vlans']['vlan'] as $vlan) { foreach ($config['vlans']['vlan'] as $vlan) {
echo sprintf("% -16s%s\n", "{$vlan['if']}_vlan{$vlan['tag']}", echo sprintf("% -16s%s\n", "{$vlan['if']}_vlan{$vlan['tag']}",
"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}"); "VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
$iflist[$vlan['if'] . '_vlan' . $vlan['tag']] = array(); $iflist[$vlan['if'] . '_vlan' . $vlan['tag']] = array();
} }
} }
echo <<<EOD echo <<<EOD
If you do not know the names of your interfaces, you may choose to use If you do not know the names of your interfaces, you may choose to use
auto-detection. In that case, disconnect all interfaces now before auto-detection. In that case, disconnect all interfaces now before
...@@ -125,404 +125,404 @@ hitting 'a' to initiate auto detection. ...@@ -125,404 +125,404 @@ hitting 'a' to initiate auto detection.
EOD; EOD;
do { do {
echo "\nEnter the WAN interface name or 'a' for auto-detection: "; echo "\nEnter the WAN interface name or 'a' for auto-detection: ";
if ($interactive) { if ($interactive) {
$wanif = chop(fgets($fp)); $wanif = chop(fgets($fp));
} else { } else {
/* more than one interface: put WAN as second one */ /* more than one interface: put WAN as second one */
$wanif = count($ifnames) > 1 ? $ifnames[1] : ''; $wanif = count($ifnames) > 1 ? $ifnames[1] : '';
echo $wanif . PHP_EOL; echo $wanif . PHP_EOL;
} }
if ($wanif == '') { if ($wanif == '') {
break; break;
} }
if ($wanif == 'a') { if ($wanif == 'a') {
$wanif = autodetect_interface('WAN', $fp); $wanif = autodetect_interface('WAN', $fp);
if (!$wanif) { if (!$wanif) {
continue; continue;
} }
} }
if (!array_key_exists($wanif, $iflist)) { if (!array_key_exists($wanif, $iflist)) {
printf("\nInvalid interface name '%s'\n", $wanif); printf("\nInvalid interface name '%s'\n", $wanif);
unset($wanif); unset($wanif);
} }
} while (!$wanif); } while (!$wanif);
do { do {
echo "\nEnter the LAN interface name or 'a' for auto-detection\n" . echo "\nEnter the LAN interface name or 'a' for auto-detection\n" .
"NOTE: this enables full Firewalling/NAT mode.\n" . "NOTE: this enables full Firewalling/NAT mode.\n" .
"(or nothing if finished): "; "(or nothing if finished): ";
if ($interactive) { if ($interactive) {
$lanif = chop(fgets($fp)); $lanif = chop(fgets($fp));
} else { } else {
/* at least one interface: put LAN as first one */ /* at least one interface: put LAN as first one */
$lanif = count($ifnames) > 0 ? $ifnames[0] : ''; $lanif = count($ifnames) > 0 ? $ifnames[0] : '';
echo $lanif . PHP_EOL; echo $lanif . PHP_EOL;
} }
if ($lanif == '') { if ($lanif == '') {
break; break;
} }
if ($lanif == 'a') { if ($lanif == 'a') {
$lanif = autodetect_interface('LAN', $fp); $lanif = autodetect_interface('LAN', $fp);
if (!$lanif) { if (!$lanif) {
continue; continue;
} }
} }
if (!array_key_exists($lanif, $iflist)) { if (!array_key_exists($lanif, $iflist)) {
printf("\nInvalid interface name '%s'\n", $lanif); printf("\nInvalid interface name '%s'\n", $lanif);
unset($lanif); unset($lanif);
} }
if ($wanif && $lanif == $wanif) { if ($wanif && $lanif == $wanif) {
unset($lanif); unset($lanif);
echo <<<EOD echo <<<EOD
Error: you cannot assign the same interface name twice! Error: you cannot assign the same interface name twice!
EOD; EOD;
} }
} while (!$lanif); } while (!$lanif);
$done = !$lanif; /* only if lan was set */ $done = !$lanif; /* only if lan was set */
while (!$done) { while (!$done) {
/* optional interfaces */ /* optional interfaces */
$optif = array(); $optif = array();
$i = 0; $i = 0;
while (1) { while (1) {
if ($optif[$i]) { if ($optif[$i]) {
$i++; $i++;
} }
$io = $i + 1; $io = $i + 1;
if ($config['interfaces']['opt' . $io]['descr']) { if ($config['interfaces']['opt' . $io]['descr']) {
printf("\nOptional interface %s description found: %s", $io, $config['interfaces']['opt' . $io]['descr']); printf("\nOptional interface %s description found: %s", $io, $config['interfaces']['opt' . $io]['descr']);
} }
printf("\nEnter the Optional %s interface name or 'a' for auto-detection\n" . printf("\nEnter the Optional %s interface name or 'a' for auto-detection\n" .
"(or nothing if finished): ", $io); "(or nothing if finished): ", $io);
if ($interactive) { if ($interactive) {
$optif[$i] = chop(fgets($fp)); $optif[$i] = chop(fgets($fp));
} else { } else {
/* never configure OPT in automatic assign */ /* never configure OPT in automatic assign */
$optif[$i] = ''; $optif[$i] = '';
echo $optif[$i] . PHP_EOL; echo $optif[$i] . PHP_EOL;
} }
if ($optif[$i] == '') { if ($optif[$i] == '') {
unset($optif[$i]); unset($optif[$i]);
$done = true; $done = true;
break; break;
} }
if ($optif[$i] == 'a') { if ($optif[$i] == 'a') {
$ad = autodetect_interface('OPT' . $io, $fp); $ad = autodetect_interface('OPT' . $io, $fp);
if (!$ad) { if (!$ad) {
unset($optif[$i]); unset($optif[$i]);
continue; continue;
} }
$optif[$i] = $ad; $optif[$i] = $ad;
} }
if (!array_key_exists($optif[$i], $iflist)) { if (!array_key_exists($optif[$i], $iflist)) {
printf("\nInvalid interface name '%s'\n", $optif[$i]); printf("\nInvalid interface name '%s'\n", $optif[$i]);
unset($optif[$i]); unset($optif[$i]);
continue; continue;
} }
/* check for double assignments */ /* check for double assignments */
$ifarr = array_merge(array($lanif, $wanif), $optif); $ifarr = array_merge(array($lanif, $wanif), $optif);
$again = false; $again = false;
for ($k = 0; $k < (count($ifarr)-1); $k++) { for ($k = 0; $k < (count($ifarr)-1); $k++) {
for ($j = ($k+1); $j < count($ifarr); $j++) { for ($j = ($k+1); $j < count($ifarr); $j++) {
if ($ifarr[$k] == $ifarr[$j]) { if ($ifarr[$k] == $ifarr[$j]) {
$again = true; $again = true;
echo <<<EOD echo <<<EOD
Error: you cannot assign the same interface name twice! Error: you cannot assign the same interface name twice!
EOD; EOD;
} }
} }
} }
if ($again) { if ($again) {
unset($optif[$i]); unset($optif[$i]);
} }
} }
} }
if ($wanif != '' || $lanif != '' || count($optif)) { if ($wanif != '' || $lanif != '' || count($optif)) {
echo "\nThe interfaces will be assigned as follows:\n\n"; echo "\nThe interfaces will be assigned as follows:\n\n";
if ($wanif != '') { if ($wanif != '') {
echo "WAN -> " . $wanif . "\n"; echo "WAN -> " . $wanif . "\n";
} }
if ($lanif != '') { if ($lanif != '') {
echo "LAN -> " . $lanif . "\n"; echo "LAN -> " . $lanif . "\n";
} }
for ($i = 0; $i < count($optif); $i++) { for ($i = 0; $i < count($optif); $i++) {
echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n"; echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n";
} }
} else { } else {
echo "\nNo interfaces will be assigned!\n"; echo "\nNo interfaces will be assigned!\n";
} }
echo <<<EOD echo <<<EOD
Do you want to proceed? ${yes_no_prompt} Do you want to proceed? ${yes_no_prompt}
EOD; EOD;
if ($interactive) { if ($interactive) {
$key = chop(fgets($fp)); $key = chop(fgets($fp));
} else { } else {
$key = 'y'; $key = 'y';
echo $key . PHP_EOL; echo $key . PHP_EOL;
} }
if (!in_array($key, array('y', 'Y'))) { if (!in_array($key, array('y', 'Y'))) {
fclose($fp); fclose($fp);
return false; return false;
} }
/* /*
* XXX Ideally, at this point we'd import the default settings here, * XXX Ideally, at this point we'd import the default settings here,
* not hardcode them. It was this way before, so fixing for now. * not hardcode them. It was this way before, so fixing for now.
*/ */
if ($lanif) { if ($lanif) {
$new = false; $new = false;
if (!is_array($config['interfaces']['lan'])) { if (!is_array($config['interfaces']['lan'])) {
$config['interfaces']['lan'] = array(); $config['interfaces']['lan'] = array();
$new = true; $new = true;
} }
$config['interfaces']['lan']['if'] = $lanif; $config['interfaces']['lan']['if'] = $lanif;
$config['interfaces']['lan']['enable'] = true; $config['interfaces']['lan']['enable'] = true;
if ($new) { if ($new) {
$config['interfaces']['lan']['ipaddr'] = '192.168.1.1'; $config['interfaces']['lan']['ipaddr'] = '192.168.1.1';
$config['interfaces']['lan']['subnet'] = '24'; $config['interfaces']['lan']['subnet'] = '24';
if ($wanif) { if ($wanif) {
$config['interfaces']['lan']['track6-interface'] = 'wan'; $config['interfaces']['lan']['track6-interface'] = 'wan';
$config['interfaces']['lan']['track6-prefix-id'] = '0'; $config['interfaces']['lan']['track6-prefix-id'] = '0';
$config['interfaces']['lan']['ipaddrv6'] = 'track6'; $config['interfaces']['lan']['ipaddrv6'] = 'track6';
$config['interfaces']['lan']['subnetv6'] = '64'; $config['interfaces']['lan']['subnetv6'] = '64';
} }
if (!isset($config['dhcpd']['lan'])) { if (!isset($config['dhcpd']['lan'])) {
$config['dhcpd']['lan'] = array(); $config['dhcpd']['lan'] = array();
$config['dhcpd']['lan']['range'] = array(); $config['dhcpd']['lan']['range'] = array();
} }
$config['dhcpd']['lan']['enable'] = true; $config['dhcpd']['lan']['enable'] = true;
$config['dhcpd']['lan']['range']['from'] = '192.168.1.100'; $config['dhcpd']['lan']['range']['from'] = '192.168.1.100';
$config['dhcpd']['lan']['range']['to'] = '192.168.1.199'; $config['dhcpd']['lan']['range']['to'] = '192.168.1.199';
if (!is_array($config['nat'])) { if (!is_array($config['nat'])) {
$config['nat'] = array(); $config['nat'] = array();
} }
if (!is_array($config['nat']['outbound'])) { if (!is_array($config['nat']['outbound'])) {
$config['nat']['outbound'] = array(); $config['nat']['outbound'] = array();
} }
$config['nat']['outbound']['mode'] = 'automatic'; $config['nat']['outbound']['mode'] = 'automatic';
} }
if (match_wireless_interface($lanif)) { if (match_wireless_interface($lanif)) {
if (is_array($config['interfaces']['lan']) && if (is_array($config['interfaces']['lan']) &&
(!is_array($config['interfaces']['lan']['wireless']))) { (!is_array($config['interfaces']['lan']['wireless']))) {
$config['interfaces']['lan']['wireless'] = array(); $config['interfaces']['lan']['wireless'] = array();
} }
} else { } else {
if (isset($config['interfaces']['lan'])) { if (isset($config['interfaces']['lan'])) {
unset($config['interfaces']['lan']['wireless']); unset($config['interfaces']['lan']['wireless']);
} }
} }
} else { } else {
if (isset($config['interfaces']['lan']['if'])) { if (isset($config['interfaces']['lan']['if'])) {
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete"); mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
} }
if (isset($config['interfaces']['lan'])) { if (isset($config['interfaces']['lan'])) {
unset($config['interfaces']['lan']); unset($config['interfaces']['lan']);
} }
if (isset($config['dhcpd']['lan'])) { if (isset($config['dhcpd']['lan'])) {
unset($config['dhcpd']['lan']); unset($config['dhcpd']['lan']);
} }
if (isset($config['interfaces']['wan']['blockpriv'])) { if (isset($config['interfaces']['wan']['blockpriv'])) {
unset($config['interfaces']['wan']['blockpriv']); unset($config['interfaces']['wan']['blockpriv']);
} }
if (isset($config['nat'])) { if (isset($config['nat'])) {
unset($config['nat']); unset($config['nat']);
} }
} }
if ($wanif) { if ($wanif) {
if (!is_array($config['interfaces']['wan'])) { if (!is_array($config['interfaces']['wan'])) {
$config['interfaces']['wan'] = array(); $config['interfaces']['wan'] = array();
} }
$config['interfaces']['wan']['if'] = $wanif; $config['interfaces']['wan']['if'] = $wanif;
$config['interfaces']['wan']['enable'] = true; $config['interfaces']['wan']['enable'] = true;
$config['interfaces']['wan']['ipaddr'] = 'dhcp'; $config['interfaces']['wan']['ipaddr'] = 'dhcp';
$config['interfaces']['wan']['ipaddrv6'] = 'dhcp6'; $config['interfaces']['wan']['ipaddrv6'] = 'dhcp6';
$config['interfaces']['wan']['blockbogons'] = true; $config['interfaces']['wan']['blockbogons'] = true;
if ($lanif) { if ($lanif) {
$config['interfaces']['wan']['blockpriv'] = true; $config['interfaces']['wan']['blockpriv'] = true;
} }
if (match_wireless_interface($wanif)) { if (match_wireless_interface($wanif)) {
if (is_array($config['interfaces']['wan']) && if (is_array($config['interfaces']['wan']) &&
(!is_array($config['interfaces']['wan']['wireless']))) { (!is_array($config['interfaces']['wan']['wireless']))) {
$config['interfaces']['wan']['wireless'] = array(); $config['interfaces']['wan']['wireless'] = array();
} }
} else { } else {
if (isset($config['interfaces']['wan'])) { if (isset($config['interfaces']['wan'])) {
unset($config['interfaces']['wan']['wireless']); unset($config['interfaces']['wan']['wireless']);
} }
} }
} else { } else {
if (isset($config['interfaces']['wan'])) { if (isset($config['interfaces']['wan'])) {
unset($config['interfaces']['wan']); unset($config['interfaces']['wan']);
} }
} }
for ($i = 0; $i < count($optif); $i++) { for ($i = 0; $i < count($optif); $i++) {
if (!is_array($config['interfaces']['opt' . ($i+1)])) if (!is_array($config['interfaces']['opt' . ($i+1)]))
$config['interfaces']['opt' . ($i+1)] = array(); $config['interfaces']['opt' . ($i+1)] = array();
$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i]; $config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
if (match_wireless_interface($optif[$i])) { if (match_wireless_interface($optif[$i])) {
if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless'])) if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless']))
$config['interfaces']['opt' . ($i+1)]['wireless'] = array(); $config['interfaces']['opt' . ($i+1)]['wireless'] = array();
} else { } else {
unset($config['interfaces']['opt' . ($i+1)]['wireless']); unset($config['interfaces']['opt' . ($i+1)]['wireless']);
} }
if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) { if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
$config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1); $config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
unset($config['interfaces']['opt' . ($i+1)]['enable']); unset($config['interfaces']['opt' . ($i+1)]['enable']);
} }
} }
/* remove all other (old) optional interfaces */ /* remove all other (old) optional interfaces */
for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) { for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
unset($config['interfaces']['opt' . ($i+1)]); unset($config['interfaces']['opt' . ($i+1)]);
} }
echo "\nWriting configuration..."; echo "\nWriting configuration...";
flush(); flush();
write_config("Console assignment of interfaces"); write_config("Console assignment of interfaces");
echo "done.\n"; echo "done.\n";
fclose($fp); fclose($fp);
return true; return true;
} }
function autodetect_interface($name, $fp) function autodetect_interface($name, $fp)
{ {
$iflist_prev = get_interface_list(true); $iflist_prev = get_interface_list(true);
echo <<<EOD echo <<<EOD
Connect the {$name} interface now and make sure that the link is up. Connect the {$name} interface now and make sure that the link is up.
Then press ENTER to continue. Then press ENTER to continue.
EOD; EOD;
fgets($fp); fgets($fp);
$iflist = get_interface_list(true); $iflist = get_interface_list(true);
if (is_array($iflist)) { if (is_array($iflist)) {
foreach ($iflist as $ifn => $ifa) { foreach ($iflist as $ifn => $ifa) {
if (!isset($iflist_prev[$ifn])) { if (!isset($iflist_prev[$ifn])) {
printf("Detected link-up: %s\n", $ifn); printf("Detected link-up: %s\n", $ifn);
return $ifn; return $ifn;
} }
} }
} }
echo "No link-up detected.\n"; echo "No link-up detected.\n";
return false; return false;
} }
function vlan_setup($iflist, $fp) 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 <<<EOD echo <<<EOD
WARNING: all existing VLANs will be cleared if you proceed! WARNING: all existing VLANs will be cleared if you proceed!
Do you want to proceed? ${yes_no_prompt} Do you want to proceed? ${yes_no_prompt}
EOD; EOD;
if (strcasecmp(chop(fgets($fp)), "y") != 0) { if (strcasecmp(chop(fgets($fp)), "y") != 0) {
return; return;
} }
} }
$config['vlans']['vlan'] = array(); $config['vlans']['vlan'] = array();
echo "\n"; echo "\n";
$vlanif = 0; $vlanif = 0;
while (1) { while (1) {
$vlan = array(); $vlan = array();
echo "\n\nVLAN-capable interfaces:\n\n"; echo "\n\nVLAN-capable interfaces:\n\n";
if(!is_array($iflist)) { if(!is_array($iflist)) {
echo "No interfaces found!\n"; echo "No interfaces found!\n";
} else { } else {
$vlan_capable=0; $vlan_capable=0;
foreach ($iflist as $iface => $ifa) { foreach ($iflist as $iface => $ifa) {
if (is_jumbo_capable($iface)) { if (is_jumbo_capable($iface)) {
echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'], echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'],
$ifa['up'] ? " (up)" : ""); $ifa['up'] ? " (up)" : "");
$vlan_capable++; $vlan_capable++;
} }
} }
} }
if($vlan_capable == 0) { if($vlan_capable == 0) {
echo "No VLAN-capable interfaces detected.\n"; echo "No VLAN-capable interfaces detected.\n";
return; return;
} }
echo "\nEnter the parent interface name for the new VLAN (or nothing if finished): "; echo "\nEnter the parent interface name for the new VLAN (or nothing if finished): ";
$vlan['if'] = chop(fgets($fp)); $vlan['if'] = chop(fgets($fp));
if ($vlan['if']) { if ($vlan['if']) {
if (!array_key_exists($vlan['if'], $iflist) or if (!array_key_exists($vlan['if'], $iflist) or
!is_jumbo_capable($vlan['if'])) { !is_jumbo_capable($vlan['if'])) {
printf("\nInvalid interface name '%s'\n", $vlan['if']); printf("\nInvalid interface name '%s'\n", $vlan['if']);
continue; continue;
} }
} else { } else {
break; break;
} }
echo 'Enter the VLAN tag (1-4094): '; echo 'Enter the VLAN tag (1-4094): ';
$vlan['tag'] = chop(fgets($fp)); $vlan['tag'] = chop(fgets($fp));
$vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}"; $vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}";
if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) { if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) {
printf("\nInvalid VLAN tag '%s'\n", $vlan['tag']); printf("\nInvalid VLAN tag '%s'\n", $vlan['tag']);
continue; continue;
} }
$config['vlans']['vlan'][] = $vlan; $config['vlans']['vlan'][] = $vlan;
$vlanif++; $vlanif++;
} }
} }
...@@ -2,31 +2,31 @@ ...@@ -2,31 +2,31 @@
<?php <?php
/* /*
Copyright (C) 2005 Scott Ullrich and Colin Smith * Copyright (C) 2005 Scott Ullrich and Colin Smith
Copyright (C) 2009 Ermal Lui * Copyright (C) 2009 Ermal Lui
All rights reserved * All rights reserved
*
Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
*
1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
*
2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
*
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("config.inc"); require_once("config.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
......
...@@ -2,30 +2,30 @@ ...@@ -2,30 +2,30 @@
<?php <?php
/* /*
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. * Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
All rights reserved. * All rights reserved.
*
Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
*
1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
*
2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
*
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("util.inc"); require_once("util.inc");
require_once("config.inc"); require_once("config.inc");
......
...@@ -2,31 +2,31 @@ ...@@ -2,31 +2,31 @@
<?php <?php
/* /*
Copyright (C) 2004 Bachman Kharazmi * Copyright (C) 2004 Bachman Kharazmi
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net> * Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
All rights reserved. * All rights reserved.
*
Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
*
1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
*
2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
*
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("util.inc"); require_once("util.inc");
require_once("config.inc"); require_once("config.inc");
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<?php <?php
/* /*
* Copyright (C) 2017 Franco Fichter <franco@opnsense.org>
* Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. * Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
* All rights reserved. * All rights reserved.
* *
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("config.inc"); require_once("config.inc");
require_once("util.inc"); require_once("util.inc");
......
...@@ -2,30 +2,30 @@ ...@@ -2,30 +2,30 @@
<?php <?php
/* /*
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net> * Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
All rights reserved. * All rights reserved.
*
Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
*
1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
*
2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
*
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("util.inc"); require_once("util.inc");
require_once("config.inc"); require_once("config.inc");
......
#!/usr/local/bin/php #!/usr/local/bin/php
<?php <?php
/*
* Copyright (C) 2011 Jim Pingle <jimp@pfsense.org>
* 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('config.inc');
$cnf = OPNsense\Core\Config::getInstance(); $cnf = OPNsense\Core\Config::getInstance();
...@@ -8,112 +34,120 @@ $confvers = $cnf->getBackups(true); ...@@ -8,112 +34,120 @@ $confvers = $cnf->getBackups(true);
$fp = fopen('php://stdin', 'r'); $fp = fopen('php://stdin', 'r');
function print_backup_info($backup_info, $number) { function print_backup_info($backup_info, $number)
if($backup_info['time'] != 0) {
$date = date('n/j/y H:i:s', $backup_info['time']); if ($backup_info['time'] != 0) {
else $date = date('n/j/y H:i:s', $backup_info['time']);
$date = 'Unknown'; } else {
$date = 'Unknown';
list($page, $reason) = explode(": ", $backup_info['description'], 2); }
if (empty($reason)) {
$reason = $page; list($page, $reason) = explode(": ", $backup_info['description'], 2);
$page = 'Unknown Page'; 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") { function list_backups($which = 'all')
global $confvers; {
global $confvers;
if (count($confvers) == 0) {
echo 'No backups found in the configuration history.'; if (count($confvers) == 0) {
return; echo 'No backups found in the configuration history.';
} return;
}
$c = 0 ;
foreach ($confvers as $filename => $bckinfo) { $c = 0 ;
$c++; foreach ($confvers as $filename => $bckinfo) {
if (is_numeric($which) && ($c != $which)) $c++;
continue; if (is_numeric($which) && ($c != $which)) {
print_backup_info($bckinfo,$c); continue;
} }
print_backup_info($bckinfo,$c);
}
} }
function choose_backup() { function choose_backup()
global $fp, $confvers; {
if (count($confvers) == 0) { global $fp, $confvers;
echo 'No backups found in the configuration history.';
return -1; if (count($confvers) == 0) {
} echo 'No backups found in the configuration history.';
echo "Which configuration would you like to restore?\n"; return -1;
echo " 1-" . count($confvers) . " : "; }
$number = strtoupper(chop(fgets($fp)));
if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) { echo "Which configuration would you like to restore?\n";
return $number; echo " 1-" . count($confvers) . " : ";
} else {
echo "That is not a valid backup number.\n"; $number = strtoupper(chop(fgets($fp)));
return -1; 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) function restore_history_backup($number)
{ {
global $fp, $confvers; global $fp, $confvers;
if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) { if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) {
echo "\nIs this the backup you wish to restore?\n"; echo "\nIs this the backup you wish to restore?\n";
list_backups($number); list_backups($number);
$filename = array_keys($confvers)[$number-1]; $filename = array_keys($confvers)[$number-1];
$thisbackup = $confvers[$filename]; $thisbackup = $confvers[$filename];
echo '[y/N]: '; echo '[y/N]: ';
$confirm = strtoupper(chop(fgets($fp))); $confirm = strtoupper(chop(fgets($fp)));
if ($confirm == 'Y') { if ($confirm == 'Y') {
$cnf = OPNsense\Core\Config::getInstance(); $cnf = OPNsense\Core\Config::getInstance();
if($cnf->restoreBackup($filename)){ if ($cnf->restoreBackup($filename)){
echo "\n"; echo "\n";
echo sprintf('Successfully reverted to timestamp %s with description "%s".', date('n/j/y H:i:s', $thisbackup['time']), $thisbackup['description']); 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"; echo "\nYou may need to reboot the firewall or restart services before the restored configuration is fully active.\n\n";
} else { } else {
echo "Unable to revert to the selected configuration.\n"; echo "Unable to revert to the selected configuration.\n";
} }
} else { } else {
echo "Restore canceled.\n"; echo "Restore canceled.\n";
} }
} else { } else {
echo "Restore canceled due to invalid input.\n"; echo "Restore canceled due to invalid input.\n";
} }
} }
while (true) { while (true) {
echo "\nRestore Backup from Configuration History\n\n"; echo "\nRestore Backup from Configuration History\n\n";
echo "1) List Backups\n"; echo "1) List Backups\n";
echo "2) Restore Backup\n"; echo "2) Restore Backup\n";
echo "q) Quit\n\n\n"; echo "q) Quit\n\n\n";
echo "Please select an option to continue: "; echo "Please select an option to continue: ";
$command = strtolower(chop(fgets($fp))); $command = strtolower(chop(fgets($fp)));
switch ($command) { switch ($command) {
case "q": case "q":
case "quit": case "quit":
echo "\n"; echo "\n";
fclose($fp); fclose($fp);
die; die;
break; break;
case "1": case "1":
list_backups(); list_backups();
break; break;
case "2": case "2":
$number = choose_backup(); $number = choose_backup();
restore_history_backup($number); restore_history_backup($number);
fclose($fp); fclose($fp);
die; die;
break; break;
} }
} }
fclose($fp); fclose($fp);
...@@ -2,30 +2,30 @@ ...@@ -2,30 +2,30 @@
<?php <?php
/* /*
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. * Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
All rights reserved. * All rights reserved.
*
Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
*
1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
*
2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
*
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("config.inc"); require_once("config.inc");
require_once("console.inc"); require_once("console.inc");
......
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