summaryrefslogtreecommitdiffstats
path: root/usr/local/www/diag_backup.php
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2015-04-19 18:00:00 +0545
committerPhil Davis <phil.davis@inf.org>2015-04-19 18:00:00 +0545
commit5f6010605ba8e3ab2fbc27080ec2db80dbd0e32e (patch)
treecd25c71caf551eb882f460ac6e1c32c8220fe58f /usr/local/www/diag_backup.php
parent0608bd3c354ea76eb6df9ed9322e2ef8686f15e7 (diff)
downloadpfsense-5f6010605ba8e3ab2fbc27080ec2db80dbd0e32e.zip
pfsense-5f6010605ba8e3ab2fbc27080ec2db80dbd0e32e.tar.gz
Code style usr-local-www diag
Diffstat (limited to 'usr/local/www/diag_backup.php')
-rw-r--r--usr/local/www/diag_backup.php271
1 files changed, 143 insertions, 128 deletions
diff --git a/usr/local/www/diag_backup.php b/usr/local/www/diag_backup.php
index a83bdab..6c25f02 100644
--- a/usr/local/www/diag_backup.php
+++ b/usr/local/www/diag_backup.php
@@ -85,7 +85,7 @@ function rrd_data_xml() {
function restore_rrddata() {
global $config, $g, $rrdtool, $input_errors;
- foreach($config['rrddata']['rrddatafile'] as $rrd) {
+ foreach ($config['rrddata']['rrddatafile'] as $rrd) {
if ($rrd['xmldata']) {
$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
@@ -101,8 +101,7 @@ function restore_rrddata() {
continue;
}
unlink($xml_file);
- }
- else if ($rrd['data']) {
+ } else if ($rrd['data']) {
$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
$rrd_fd = fopen($rrd_file, "w");
if (!$rrd_fd) {
@@ -137,18 +136,21 @@ function add_base_packages_menu_items() {
global $g, $config;
$base_packages = explode(",", $g['base_packages']);
$modified_config = false;
- foreach($base_packages as $bp) {
+ foreach ($base_packages as $bp) {
$basepkg_path = "/usr/local/pkg/{$bp}";
$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
- if($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
+ if ($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
- if($pkg_config['menu'] != "") {
- if(is_array($pkg_config['menu'])) {
- foreach($pkg_config['menu'] as $menu) {
- if(is_array($config['installedpackages']['menu']))
- foreach($config['installedpackages']['menu'] as $amenu)
- if($amenu['name'] == $menu['name'])
+ if ($pkg_config['menu'] != "") {
+ if (is_array($pkg_config['menu'])) {
+ foreach ($pkg_config['menu'] as $menu) {
+ if (is_array($config['installedpackages']['menu'])) {
+ foreach ($config['installedpackages']['menu'] as $amenu) {
+ if ($amenu['name'] == $menu['name']) {
continue;
+ }
+ }
+ }
$config['installedpackages']['menu'][] = $menu;
$modified_config = true;
}
@@ -158,7 +160,7 @@ function add_base_packages_menu_items() {
}
}
}
- if($modified_config) {
+ if ($modified_config) {
write_config(gettext("Restored base_package menus after configuration restore."));
$config = parse_config(true);
}
@@ -170,8 +172,9 @@ function remove_bad_chars($string) {
function check_and_returnif_section_exists($section) {
global $config;
- if(is_array($config[$section]))
+ if (is_array($config[$section])) {
return true;
+ }
return false;
}
@@ -179,41 +182,45 @@ function spit_out_select_items($name, $showall) {
global $config;
$areas = array("aliases" => gettext("Aliases"),
- "captiveportal" => gettext("Captive Portal"),
- "voucher" => gettext("Captive Portal Vouchers"),
- "dnsmasq" => gettext("DNS Forwarder"),
- "unbound" => gettext("DNS Resolver"),
- "dhcpd" => gettext("DHCP Server"),
- "dhcpdv6" => gettext("DHCPv6 Server"),
- "filter" => gettext("Firewall Rules"),
- "interfaces" => gettext("Interfaces"),
- "ipsec" => gettext("IPSEC"),
- "nat" => gettext("NAT"),
- "openvpn" => gettext("OpenVPN"),
- "installedpackages" => gettext("Package Manager"),
- "pptpd" => gettext("PPTP Server"),
- "rrddata" => gettext("RRD Data"),
- "cron" => gettext("Scheduled Tasks"),
- "syslog" => gettext("Syslog"),
- "system" => gettext("System"),
- "staticroutes" => gettext("Static routes"),
- "sysctl" => gettext("System tunables"),
- "snmpd" => gettext("SNMP Server"),
- "shaper" => gettext("Traffic Shaper"),
- "vlans" => gettext("VLANS"),
- "wol" => gettext("Wake on LAN")
+ "captiveportal" => gettext("Captive Portal"),
+ "voucher" => gettext("Captive Portal Vouchers"),
+ "dnsmasq" => gettext("DNS Forwarder"),
+ "unbound" => gettext("DNS Resolver"),
+ "dhcpd" => gettext("DHCP Server"),
+ "dhcpdv6" => gettext("DHCPv6 Server"),
+ "filter" => gettext("Firewall Rules"),
+ "interfaces" => gettext("Interfaces"),
+ "ipsec" => gettext("IPSEC"),
+ "nat" => gettext("NAT"),
+ "openvpn" => gettext("OpenVPN"),
+ "installedpackages" => gettext("Package Manager"),
+ "pptpd" => gettext("PPTP Server"),
+ "rrddata" => gettext("RRD Data"),
+ "cron" => gettext("Scheduled Tasks"),
+ "syslog" => gettext("Syslog"),
+ "system" => gettext("System"),
+ "staticroutes" => gettext("Static routes"),
+ "sysctl" => gettext("System tunables"),
+ "snmpd" => gettext("SNMP Server"),
+ "shaper" => gettext("Traffic Shaper"),
+ "vlans" => gettext("VLANS"),
+ "wol" => gettext("Wake on LAN")
);
$select = "<select name=\"{$name}\" id=\"{$name}\">";
$select .= "<option value=\"\">" . gettext("ALL") . "</option>";
- if($showall == true)
- foreach($areas as $area => $areaname)
+ if ($showall == true) {
+ foreach ($areas as $area => $areaname) {
$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
- else
- foreach($areas as $area => $areaname)
- if($area === "rrddata" || check_and_returnif_section_exists($area) == true)
+ }
+ } else {
+ foreach ($areas as $area => $areaname) {
+ if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
+ }
+ }
+ }
$select .= "</select>\n";
@@ -246,32 +253,32 @@ if ($_POST['apply']) {
if ($_POST) {
unset($input_errors);
- if (stristr($_POST['Submit'], gettext("Restore configuration")))
+ if (stristr($_POST['Submit'], gettext("Restore configuration"))) {
$mode = "restore";
- else if (stristr($_POST['Submit'], gettext("Reinstall")))
+ } else if (stristr($_POST['Submit'], gettext("Reinstall"))) {
$mode = "reinstallpackages";
- else if (stristr($_POST['Submit'], gettext("Clear Package Lock")))
+ } else if (stristr($_POST['Submit'], gettext("Clear Package Lock"))) {
$mode = "clearpackagelock";
- else if (stristr($_POST['Submit'], gettext("Download")))
+ } else if (stristr($_POST['Submit'], gettext("Download"))) {
$mode = "download";
- else if (stristr($_POST['Submit'], gettext("Restore version")))
+ } else if (stristr($_POST['Submit'], gettext("Restore version"))) {
$mode = "restore_ver";
-
- if ($_POST["nopackages"] <> "")
+ }
+ if ($_POST["nopackages"] <> "") {
$options = "nopackages";
-
- if ($_POST["ver"] <> "")
+ }
+ if ($_POST["ver"] <> "") {
$ver2restore = $_POST["ver"];
-
+ }
if ($mode) {
-
if ($mode == "download") {
-
if ($_POST['encrypt']) {
- if(!$_POST['encrypt_password'] || !$_POST['encrypt_passconf'])
+ if (!$_POST['encrypt_password'] || !$_POST['encrypt_passconf']) {
$input_errors[] = gettext("You must supply and confirm the password for encryption.");
- if($_POST['encrypt_password'] != $_POST['encrypt_passconf'])
+ }
+ if ($_POST['encrypt_password'] != $_POST['encrypt_passconf']) {
$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
+ }
}
if (!$input_errors) {
@@ -282,8 +289,8 @@ if ($_POST) {
$name = "config-{$host}-".date("YmdHis").".xml";
$data = "";
- if($options == "nopackages") {
- if(!$_POST['backuparea']) {
+ if ($options == "nopackages") {
+ if (!$_POST['backuparea']) {
/* backup entire configuration */
$data = file_get_contents("{$g['conf_path']}/config.xml");
} else {
@@ -296,7 +303,7 @@ if ($_POST) {
exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
$data = file_get_contents($sfn . "-new");
} else {
- if(!$_POST['backuparea']) {
+ if (!$_POST['backuparea']) {
/* backup entire configuration */
$data = file_get_contents("{$g['conf_path']}/config.xml");
} else if ($_POST['backuparea'] === "rrddata") {
@@ -343,21 +350,21 @@ if ($_POST) {
}
if ($mode == "restore") {
-
if ($_POST['decrypt']) {
- if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
+ if (!$_POST['decrypt_password'] || !$_POST['decrypt_passconf']) {
$input_errors[] = gettext("You must supply and confirm the password for decryption.");
- if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
+ }
+ if ($_POST['decrypt_password'] != $_POST['decrypt_passconf']) {
$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
+ }
}
if (!$input_errors) {
-
if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
/* read the file contents */
$data = file_get_contents($_FILES['conffile']['tmp_name']);
- if(!$data) {
+ if (!$data) {
log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
return 1;
}
@@ -370,15 +377,15 @@ if ($_POST) {
$data = decrypt_data($data, $_POST['decrypt_password']);
}
- if(stristr($data, "<m0n0wall>")) {
+ if (stristr($data, "<m0n0wall>")) {
log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
/* m0n0wall was found in config. convert it. */
$data = str_replace("m0n0wall", "pfsense", $data);
$m0n0wall_upgrade = true;
}
- if($_POST['restorearea']) {
+ if ($_POST['restorearea']) {
/* restore a specific area of the configuration */
- if(!stristr($data, "<" . $_POST['restorearea'] . ">")) {
+ if (!stristr($data, "<" . $_POST['restorearea'] . ">")) {
$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
} else {
if (!restore_config_section($_POST['restorearea'], $data)) {
@@ -398,7 +405,7 @@ if ($_POST) {
}
}
} else {
- if(!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
+ if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
$input_errors[] = sprintf(gettext("You have selected to restore the full configuration but we could not locate a %s tag."), $g['xml_rootobj']);
} else {
/* restore the entire configuration */
@@ -409,8 +416,9 @@ if ($_POST) {
mark_subsystem_dirty("restore");
touch("/conf/needs_package_sync");
/* remove cache, we will force a config reboot */
- if(file_exists("{$g['tmp_path']}/config.cache"))
+ if (file_exists("{$g['tmp_path']}/config.cache")) {
unlink("{$g['tmp_path']}/config.cache");
+ }
$config = parse_config(true);
if (file_exists("/boot/loader.conf")) {
$loaderconf = file_get_contents("/boot/loader.conf");
@@ -421,7 +429,7 @@ if ($_POST) {
unset($loaderconf);
}
/* extract out rrd items, unset from $config when done */
- if($config['rrddata']) {
+ if ($config['rrddata']) {
restore_rrddata();
unset($config['rrddata']);
unlink_if_exists("{$g['tmp_path']}/config.cache");
@@ -430,20 +438,23 @@ if ($_POST) {
convert_config();
conf_mount_ro();
}
- if($m0n0wall_upgrade == true) {
- if($config['system']['gateway'] <> "")
+ if ($m0n0wall_upgrade == true) {
+ if ($config['system']['gateway'] <> "") {
$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
+ }
unset($config['shaper']);
/* optional if list */
$ifdescrs = get_configured_interface_list(true, true);
/* remove special characters from interface descriptions */
- if(is_array($ifdescrs))
- foreach($ifdescrs as $iface)
+ if (is_array($ifdescrs)) {
+ foreach ($ifdescrs as $iface) {
$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
+ }
+ }
/* check for interface names with an alias */
- if(is_array($ifdescrs)) {
- foreach($ifdescrs as $iface) {
- if(is_alias($config['interfaces'][$iface]['descr'])) {
+ if (is_array($ifdescrs)) {
+ foreach ($ifdescrs as $iface) {
+ if (is_alias($config['interfaces'][$iface]['descr'])) {
// Firewall rules
$origname = $config['interfaces'][$iface]['descr'];
$newname = $config['interfaces'][$iface]['descr'] . "Alias";
@@ -465,58 +476,60 @@ if ($_POST) {
$config['system']['version'] = "1.0";
// Deal with descriptions longer than 63 characters
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
- if(count($config['filter']['rule'][$i]['descr']) > 63)
+ if (count($config['filter']['rule'][$i]['descr']) > 63) {
$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
+ }
}
// Move interface from ipsec to enc0
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
- if($config['filter']['rule'][$i]['interface'] == "ipsec")
+ if ($config['filter']['rule'][$i]['interface'] == "ipsec") {
$config['filter']['rule'][$i]['interface'] = "enc0";
+ }
}
// Convert icmp types
// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
- if($config["filter"]["rule"][$i]['icmptype']) {
- switch($config["filter"]["rule"][$i]['icmptype']) {
- case "echo":
- $config["filter"]["rule"][$i]['icmptype'] = "echoreq";
- break;
- case "unreach":
- $config["filter"]["rule"][$i]['icmptype'] = "unreach";
- break;
- case "echorep":
- $config["filter"]["rule"][$i]['icmptype'] = "echorep";
- break;
- case "squench":
- $config["filter"]["rule"][$i]['icmptype'] = "squench";
- break;
- case "redir":
- $config["filter"]["rule"][$i]['icmptype'] = "redir";
- break;
- case "timex":
- $config["filter"]["rule"][$i]['icmptype'] = "timex";
- break;
- case "paramprob":
- $config["filter"]["rule"][$i]['icmptype'] = "paramprob";
- break;
- case "timest":
- $config["filter"]["rule"][$i]['icmptype'] = "timereq";
- break;
- case "timestrep":
- $config["filter"]["rule"][$i]['icmptype'] = "timerep";
- break;
- case "inforeq":
- $config["filter"]["rule"][$i]['icmptype'] = "inforeq";
- break;
- case "inforep":
- $config["filter"]["rule"][$i]['icmptype'] = "inforep";
- break;
- case "maskreq":
- $config["filter"]["rule"][$i]['icmptype'] = "maskreq";
- break;
- case "maskrep":
- $config["filter"]["rule"][$i]['icmptype'] = "maskrep";
- break;
+ if ($config["filter"]["rule"][$i]['icmptype']) {
+ switch ($config["filter"]["rule"][$i]['icmptype']) {
+ case "echo":
+ $config["filter"]["rule"][$i]['icmptype'] = "echoreq";
+ break;
+ case "unreach":
+ $config["filter"]["rule"][$i]['icmptype'] = "unreach";
+ break;
+ case "echorep":
+ $config["filter"]["rule"][$i]['icmptype'] = "echorep";
+ break;
+ case "squench":
+ $config["filter"]["rule"][$i]['icmptype'] = "squench";
+ break;
+ case "redir":
+ $config["filter"]["rule"][$i]['icmptype'] = "redir";
+ break;
+ case "timex":
+ $config["filter"]["rule"][$i]['icmptype'] = "timex";
+ break;
+ case "paramprob":
+ $config["filter"]["rule"][$i]['icmptype'] = "paramprob";
+ break;
+ case "timest":
+ $config["filter"]["rule"][$i]['icmptype'] = "timereq";
+ break;
+ case "timestrep":
+ $config["filter"]["rule"][$i]['icmptype'] = "timerep";
+ break;
+ case "inforeq":
+ $config["filter"]["rule"][$i]['icmptype'] = "inforeq";
+ break;
+ case "inforep":
+ $config["filter"]["rule"][$i]['icmptype'] = "inforep";
+ break;
+ case "maskreq":
+ $config["filter"]["rule"][$i]['icmptype'] = "maskreq";
+ break;
+ case "maskrep":
+ $config["filter"]["rule"][$i]['icmptype'] = "maskrep";
+ break;
}
}
}
@@ -528,8 +541,8 @@ if ($_POST) {
$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
mark_subsystem_dirty("restore");
}
- if(is_array($config['captiveportal'])) {
- foreach($config['captiveportal'] as $cp) {
+ if (is_array($config['captiveportal'])) {
+ foreach ($config['captiveportal'] as $cp) {
if (isset($cp['enable'])) {
/* for some reason ipfw doesn't init correctly except on bootup sequence */
mark_subsystem_dirty("restore");
@@ -538,7 +551,7 @@ if ($_POST) {
}
}
setup_serial_port();
- if(is_interface_mismatch() == true) {
+ if (is_interface_mismatch() == true) {
touch("/var/run/interface_mismatch_reboot_needed");
clear_subsystem_dirty("restore");
convert_config();
@@ -564,7 +577,6 @@ if ($_POST) {
}
if ($mode == "reinstallpackages") {
-
header("Location: pkg_mgr_install.php?mode=reinstallall");
exit;
} else if ($mode == "clearpackagelock") {
@@ -603,18 +615,20 @@ include("head.inc");
function encrypt_change() {
- if (!document.iform.encrypt.checked)
+ if (!document.iform.encrypt.checked) {
document.getElementById("encrypt_opts").style.display="none";
- else
+ } else {
document.getElementById("encrypt_opts").style.display="";
+ }
}
function decrypt_change() {
- if (!document.iform.decrypt.checked)
+ if (!document.iform.decrypt.checked) {
document.getElementById("decrypt_opts").style.display="none";
- else
+ } else {
document.getElementById("decrypt_opts").style.display="";
+ }
}
function backuparea_change(obj) {
@@ -797,7 +811,8 @@ decrypt_change();
</html>
<?php
-if (is_subsystem_dirty('restore'))
+if (is_subsystem_dirty('restore')) {
system_reboot();
+}
?>
OpenPOWER on IntegriCloud