Commit dc9e633d authored by Franco Fichtner's avatar Franco Fichtner

src: merge config manager rework from master

parent e58dcdd7
......@@ -57,12 +57,9 @@ function cron_job_exists($command) {
return false;
}
$rrddbpath = '/var/db/rrd';
$rrdtool = '/usr/local/bin/rrdtool';
function rrd_data_xml() {
global $rrddbpath;
global $rrdtool;
$rrddbpath = '/var/db/rrd';
$result = "\t<rrddata>\n";
$rrd_files = glob("{$rrddbpath}/*.rrd");
......@@ -70,7 +67,7 @@ function rrd_data_xml() {
foreach ($rrd_files as $rrd_file) {
$basename = basename($rrd_file);
$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
exec("$rrdtool dump '{$rrd_file}' '{$xml_file}'");
exec("/usr/local/bin/rrdtool dump '{$rrd_file}' '{$xml_file}'");
$xml_data = @file_get_contents($xml_file);
@unlink($xml_file);
if ($xml_data !== false) {
......@@ -84,10 +81,11 @@ function rrd_data_xml() {
return $result;
}
function restore_rrddata() {
global $config, $g, $rrdtool, $input_errors;
global $config;
foreach($config['rrddata']['rrddatafile'] as $rrd) {
if ($rrd['xmldata']) {
if (!empty($rrd['xmldata'])) {
$rrd_file = "/var/db/rrd/{$rrd['filename']}";
$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
......@@ -96,14 +94,14 @@ function restore_rrddata() {
}
$output = array();
$status = null;
exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
exec("/usr/local/bin/rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
if ($status) {
log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
continue;
}
unlink($xml_file);
}
else if ($rrd['data']) {
} elseif (!empty($rrd['data'])) {
// pfSense 2.0 rrd backup format
$rrd_file = "/var/db/rrd/{$rrd['filename']}";
$rrd_fd = fopen($rrd_file, "w");
if (!$rrd_fd) {
......@@ -119,13 +117,11 @@ function restore_rrddata() {
log_error("fwrite $rrd_file failed");
continue;
}
} else {
} elseif (fwrite($rrd_fd, $data) === false) {
/* If the decompression failed, it wasn't compressed, so write raw data */
if (fwrite($rrd_fd, $data) === false) {
log_error("fwrite $rrd_file failed");
continue;
}
}
if (fclose($rrd_fd) === false) {
log_error("fclose $rrd_file failed");
continue;
......@@ -134,24 +130,7 @@ function restore_rrddata() {
}
}
function remove_bad_chars($string) {
return preg_replace('/[^a-z_0-9]/i','',$string);
}
function check_and_returnif_section_exists($section) {
global $config;
if(is_array($config[$section]))
return true;
return false;
}
function spit_out_select_items($name, $showall) {
global $config;
$areas = array("aliases" => gettext("Aliases"),
"captiveportal" => gettext("Captive Portal"),
"voucher" => gettext("Captive Portal Vouchers"),
$areas = array("aliases" => gettext("Aliases"),
"dnsmasq" => gettext("DNS Forwarder"),
"dhcpd" => gettext("DHCP Server"),
"dhcpdv6" => gettext("DHCPv6 Server"),
......@@ -172,74 +151,44 @@ function spit_out_select_items($name, $showall) {
"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)
$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
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";
if ($name === "backuparea") {
$select .= <<<END_SCRIPT_BLOCK
<script type="text/javascript">
//<![CDATA[
jQuery(function (\$) {
$("#{$name}").change(function () {
backuparea_change(this);
}).trigger("change");
});
//]]>
</script>
END_SCRIPT_BLOCK;
}
echo $select;
}
if ($_POST['apply']) {
ob_flush();
flush();
clear_subsystem_dirty("restore");
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
$pconfig['GDriveEnabled'] = isset($config['system']['remotebackup']['GDriveEnabled']) ? $config['system']['remotebackup']['GDriveEnabled'] : null;
$pconfig['GDriveEmail'] = isset($config['system']['remotebackup']['GDriveEmail']) ? $config['system']['remotebackup']['GDriveEmail'] : null;
$pconfig['GDriveP12key'] = isset($config['system']['remotebackup']['GDriveP12key']) ? $config['system']['remotebackup']['GDriveP12key'] : null;
$pconfig['GDriveFolderID'] = isset($config['system']['remotebackup']['GDriveFolderID']) ? $config['system']['remotebackup']['GDriveFolderID'] : null;
$pconfig['GDriveBackupCount'] = isset($config['system']['remotebackup']['GDriveBackupCount']) ? $config['system']['remotebackup']['GDriveBackupCount'] : null;
$pconfig['GDrivePassword'] = isset($config['system']['remotebackup']['GDrivePassword']) ? $config['system']['remotebackup']['GDrivePassword'] : null;
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input_errors = array();
$pconfig = $_POST;
if ($_POST) {
unset($input_errors);
if (stristr($_POST['Submit'], gettext("Restore configuration")))
if (!empty($_POST['restore'])) {
$mode = "restore";
else if (stristr($_POST['Submit'], gettext("Download")))
} elseif (!empty($_POST['download'])) {
$mode = "download";
else if (stristr($_POST['Submit'], gettext("Setup/Test Google Drive")))
} elseif (!empty($_POST['setup_gdrive'])) {
$mode = "setup_gdrive";
if ($mode) {
} else {
$mode = false;
}
if ($mode == "download") {
if ($_POST['encrypt']) {
if(!$_POST['encrypt_password'] || !$_POST['encrypt_passconf'])
if (!empty($_POST['encrypt']) && (empty($_POST['encrypt_password']) || empty($_POST['encrypt_passconf']))) {
$input_errors[] = gettext("You must supply and confirm the password for encryption.");
if($_POST['encrypt_password'] != $_POST['encrypt_passconf'])
} elseif (!empty($_POST['encrypt']) && $_POST['encrypt_password'] != $_POST['encrypt_passconf']) {
$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
}
if (!$input_errors) {
if (count($input_errors) == 0) {
$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
$name = "config-{$host}-".date("YmdHis").".xml";
$data = "";
if(!$_POST['backuparea']) {
if(empty($_POST['backuparea'])) {
/* backup entire configuration */
$data = file_get_contents('/conf/config.xml');
} else if ($_POST['backuparea'] === "rrddata") {
} elseif ($_POST['backuparea'] === "rrddata") {
$data = rrd_data_xml();
$name = "{$_POST['backuparea']}-{$name}";
} else {
......@@ -251,13 +200,13 @@ if ($_POST) {
/*
* Backup RRD Data
*/
if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
if ($_POST['backuparea'] !== "rrddata" && empty($_POST['donotbackuprrd'])) {
$rrd_data_xml = rrd_data_xml();
$closing_tag = "</opnsense>";
$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
}
if ($_POST['encrypt']) {
if (!empty($_POST['encrypt'])) {
$data = encrypt_data($data, $_POST['encrypt_password']);
tagfile_reformat($data, $data, "config.xml");
}
......@@ -274,51 +223,51 @@ if ($_POST) {
header("Cache-Control: private, must-revalidate");
}
echo $data;
exit;
}
}elseif ($mode == "restore") {
if ($_POST['decrypt']) {
if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
} elseif ($mode == "restore") {
// unpack data and perform validation
$data = null;
if (!empty($_POST['decrypt']) && (empty($_POST['decrypt_password']) || empty($_POST['decrypt_passconf']))) {
$input_errors[] = gettext("You must supply and confirm the password for decryption.");
if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
} elseif (!empty($_POST['decrypt']) && $_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 */
if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
$data = file_get_contents($_FILES['conffile']['tmp_name']);
if(!$data) {
if(empty($data)) {
log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
return 1;
$input_errors[] = sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']);
}
} else {
$input_errors[] = gettext("The configuration could not be restored (file upload error).");
}
if ($_POST['decrypt']) {
if (!empty($_POST['decrypt'])) {
if (!tagfile_deformat($data, $data, "config.xml")) {
$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted OPNsense configuration.");
}
$data = decrypt_data($data, $_POST['decrypt_password']);
}
if(!empty($_POST['restorearea']) && !stristr($data, "<" . $_POST['restorearea'] . ">")) {
/* restore a specific area of the configuration */
$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
}
if (count($input_errors) == 0) {
if(stristr($data, "<m0n0wall>")) {
log_error(gettext("Upgrading m0n0wall configuration to OPNsense."));
/* m0n0wall was found in config. convert it. */
$data = str_replace("m0n0wall", "pfsense", $data);
$m0n0wall_upgrade = true;
}
if($_POST['restorearea']) {
/* restore a specific area of the configuration */
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 (!empty($_POST['restorearea'])) {
if (!restore_config_section($_POST['restorearea'], $data)) {
$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
} else {
if ($config['rrddata']) {
if (!empty($config['rrddata'])) {
restore_rrddata();
unset($config['rrddata']);
write_config();
......@@ -327,9 +276,7 @@ if ($_POST) {
filter_configure();
$savemsg = gettext("The configuration area has been restored. You may need to reboot the firewall.");
}
}
} else {
if(!$input_errors) {
/* restore the entire configuration */
$filename = $_FILES['conffile']['tmp_name'];
file_put_contents($filename, $data);
......@@ -337,9 +284,7 @@ if ($_POST) {
if ($cnf->restoreBackup($filename)) {
/* this will be picked up by /index.php */
mark_subsystem_dirty("restore");
$config = parse_config();
/* extract out rrd items, unset from $config when done */
if($config['rrddata']) {
restore_rrddata();
......@@ -347,17 +292,18 @@ if ($_POST) {
write_config();
convert_config();
}
if($m0n0wall_upgrade == true) {
if($config['system']['gateway'] <> "")
if($m0n0wall_upgrade) {
if(!empty($config['system']['gateway'])) {
$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
}
/* optional if list */
$ifdescrs = get_configured_interface_list(true, true);
/* remove special characters from interface descriptions */
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) {
$config['interfaces'][$iface]['descr'] = preg_replace('/[^a-z_0-9]/i','',$config['interfaces'][$iface]['descr']);
}
/* check for interface names with an alias */
foreach($ifdescrs as $iface) {
if(is_alias($config['interfaces'][$iface]['descr'])) {
// Firewall rules
......@@ -380,14 +326,16 @@ 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++) {
......@@ -438,16 +386,6 @@ if ($_POST) {
write_config();
convert_config();
$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to OPNsense.");
mark_subsystem_dirty("restore");
}
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");
break;
}
}
}
setup_serial_port();
} else {
......@@ -455,12 +393,7 @@ if ($_POST) {
}
}
}
} else {
$input_errors[] = gettext("The configuration could not be restored (file upload error).");
}
}
} elseif ( $mode == "setup_gdrive" ){
global $config;
if (!isset($config['system']['remotebackup'])) {
$config['system']['remotebackup'] = array() ;
}
......@@ -508,16 +441,9 @@ if ($_POST) {
}
}
}
}
}
$id = rand() . '.' . time();
$mth = ini_get('upload_progress_meter.store_method');
$dir = ini_get('upload_progress_meter.file.filename_template');
include("head.inc");
?>
<body>
......@@ -525,235 +451,238 @@ include("head.inc");
<script type="text/javascript">
//<![CDATA[
$( document ).ready(function() {
// show encryption password
$("#encryptconf").change(function(event){
event.preventDefault();
if ($("#encryptconf").prop('checked')) {
$("#encrypt_opts").removeClass("hidden");
} else {
$("#encrypt_opts").addClass("hidden");
}
});
function encrypt_change() {
if (!document.iform.encrypt.checked)
document.getElementById("encrypt_opts").style.display="none";
else
document.getElementById("encrypt_opts").style.display="";
}
function decrypt_change() {
if (!document.iform.decrypt.checked)
document.getElementById("decrypt_opts").style.display="none";
else
document.getElementById("decrypt_opts").style.display="";
}
// show decryption password
$("#decryptconf").change(function(event){
event.preventDefault();
if ($("#decryptconf").prop('checked')) {
$("#decrypt_opts").removeClass("hidden");
} else {
$("#decrypt_opts").addClass("hidden");
}
});
function backuparea_change(obj) {
if (obj.value == "rrddata") {
document.getElementById("dotnotbackuprrd").disabled = true;
$("#backuparea").change(function(event){
if ($("#backuparea").val() == "rrddata") {
$("#dotnotbackuprrd").prop('disabled', true);
} else {
document.getElementById("dotnotbackuprrd").disabled = false;
$("#dotnotbackuprrd").prop('disabled', false);
}
}
});
});
//]]>
</script>
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('restore')): ?><br/>
<form action="reboot.php" method="post">
<input name="Submit" type="hidden" value="Yes" />
<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting."));?><br />
</form>
<?php endif; ?>
<form action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
<form action="diag_backup.php" method="post">
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('restore')): ?><br/>
<form action="reboot.php" method="post">
<input name="Submit" type="hidden" value="Yes" />
<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting."));?><br />
</form>
<?php endif; ?>
<?php if ($input_messages) print_info_box($input_messages); ?>
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<section class="col-xs-12">
<section class="__mb">
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext('Download')?></h3>
</header>
<div class="content-box-main">
<div class="table-responsive">
<table class="table table-striped __nomb">
<table class="table table-striped">
<tbody>
<tr>
<td><p><?=gettext("Click this button to download the system configuration in XML format."); ?><br /><br /> <?=gettext("Backup area:"); ?> <?php spit_out_select_items("backuparea", false); ?></p></td>
</tr>
<tr>
<td>
<table>
</table>
<table>
<tr>
<td width="25">
<input name="encrypt" type="checkbox" class="formcheckbox" id="encryptconf" onclick="encrypt_change()" />
</td>
<td>
<span class="vexpl"><?=gettext("Encrypt this configuration file."); ?></span>
</td>
<?=gettext("Click this button to download the system configuration in XML format."); ?><br /><br />
<?=gettext("Backup area:");?>
<select name="backuparea" id="backuparea">
<option value=""><?=gettext("ALL");?></option>
<?php
foreach($areas as $area => $areaname):
if($area !== "rrddata" && (!isset($config[$area]) || !is_array($config[$area]))) {
continue;
};?>
<option value="<?=$area;?>"><?=$areaname;?></option>
<?php
endforeach;?>
</select>
</tr>
<tr>
<td width="25">
<input name="donotbackuprrd" type="checkbox" class="formcheckbox" id="dotnotbackuprrd" checked="checked" />
</td>
<td>
<span class="vexpl"><?=gettext("Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)"); ?></span>
</td>
</tr>
</table>
<table id="encrypt_opts">
<input name="encrypt" type="checkbox" id="encryptconf" />
<?=gettext("Encrypt this configuration file."); ?><br/>
<input name="donotbackuprrd" type="checkbox" id="dotnotbackuprrd" checked="checked" />
<?=gettext("Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)"); ?>
<div class="hidden table-responsive" id="encrypt_opts">
<table class="table table-condensed">
<tr>
<td>
<span class="vexpl"><?=gettext("Password:"); ?> </span>
</td>
<td>
<input name="encrypt_password" type="password" class="formfld pwd" size="20" value="" />
</td>
<td><?=gettext("Password:"); ?></td>
<td><input name="encrypt_password" type="password" value="" /></td>
</tr>
<tr>
<td>
<span class="vexpl"><?=gettext("confirm:"); ?> </span>
</td>
<td>
<input name="encrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
</td>
<td><?=gettext("confirm:"); ?></td>
<td><input name="encrypt_passconf" type="password" value="" /> </td>
</tr>
</table>
<input name="Submit" type="submit" class="btn btn-primary __mt" id="download" value="<?=gettext("Download configuration"); ?>" />
</div>
<hr/>
<input name="download" type="submit" class="btn btn-primary __mt" value="<?=gettext("Download configuration"); ?>" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section class="__mb">
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext("Restore"); ?></h3>
</header>
<div class="content-box-main ">
<div class="table-responsive">
<table class="table table-striped __nomb">
<table class="table table-striped">
<tbody>
<tr>
<td><p><?=gettext("Open a"); ?> <?=$g['[product_name']?> <?=gettext("configuration XML file and click the button below to restore the configuration."); ?>
<br /><br />
<?=gettext("Restore area:"); ?> <?php spit_out_select_items("restorearea", true); ?></p></td>
</tr>
<tr>
<td>
<p><input name="conffile" type="file" class="formbtn" id="conffile" size="40" /></p>
<table>
<tr>
<td width="25">
<input name="decrypt" type="checkbox" class="formcheckbox" id="encryptconf" onclick="decrypt_change()" />
</td>
<td>
<span class="vexpl"><?=gettext("Configuration file is encrypted."); ?></span>
<?=gettext("Open a"); ?> <?=$g['[product_name']?> <?=gettext("configuration XML file and click the button below to restore the configuration."); ?>
<br /><br />
<?=gettext("Restore area:"); ?>
<select name="restorearea" id="restorearea">
<option value=""><?=gettext("ALL");?></option>
<?php
foreach($areas as $area => $areaname):?>
<option value="<?=$area;?>"><?=$areaname;?></option>
<?php
endforeach;?>
</select>
</td>
</tr>
</table>
<table id="decrypt_opts">
<tr>
<td>
<span class="vexpl"><?=gettext("Password :"); ?></span>
</td>
<td>
<input name="decrypt_password" type="password" class="formfld pwd" size="20" value="" />
</td>
<input name="conffile" type="file" id="conffile" />
<input name="decrypt" type="checkbox" id="decryptconf"/>
<?=gettext("Configuration file is encrypted."); ?>
<div class="hidden table-responsive" id="decrypt_opts">
<table class="table table-condensed">
<tr>
<td><?=gettext("Password:"); ?></td>
<td><input name="decrypt_password" type="password" value="" /></td>
</tr>
<tr>
<td>
<span class="vexpl"><?=gettext("confirm :"); ?></span>
</td>
<td>
<input name="decrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
</td>
<td><?=gettext("confirm:"); ?></td>
<td><input name="decrypt_passconf" type="password" value="" /> </td>
</tr>
</table>
<p><input name="Submit" type="submit" class="btn btn-primary" id="restore" value="<?=gettext("Restore configuration"); ?>" /></p>
</div>
<hr/>
<input name="restore" type="submit" class="btn btn-primary" id="restore" value="<?=gettext("Restore configuration"); ?>" />
<hr/>
<p><strong><span class="text-danger"><?=gettext("Note:"); ?> <?=gettext("The firewall will reboot after restoring the configuration."); ?></span></strong></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section class="__mb">
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext("Google Drive"); ?></h3>
</header>
<div class="content-box-main ">
<div class="table-responsive">
<table class="table table-striped __nomb">
<table class="table table-striped ">
<thead>
<th class="col-sm-1"></th>
<th class="col-sm-3"></th>
</thead>
<tbody>
<tr><td><?=gettext("Enable"); ?> </td> <td><input name="GDriveEnabled" class="formcheckbox" id="GDriveEnabled" type="checkbox" <?php if( $config['system']['remotebackup']['GDriveEnabled'] == "on" ) echo "checked";?> > </td></tr>
<tr><td><?=gettext("Email Address"); ?> </td><td><input name="GDriveEmail" class="formfld" size="20" value="<?= $config['system']['remotebackup']['GDriveEmail'] ?>" type="text"> </td> </tr>
<tr><td><?=gettext("P12 key"); ?> <?php if (isset($config['system']['remotebackup']['GDriveP12key'])) echo gettext("(replace)"); else echo gettext("(not loaded)"); ?> </td><td> <input name="GDriveP12file" class="formbtn" id="P12file" size="40" type="file"></td> </tr>
<tr><td><?=gettext("Folder ID"); ?> </td><td> <input name="GDriveFolderID" class="formbtn" id="GDriveFolderID" value="<?= $config['system']['remotebackup']['GDriveFolderID'] ?>" size="40" type="text"></td> </tr>
<tr><td><?=gettext("Backup Count"); ?> </td><td> <input name="GDriveBackupCount" class="formbtn" id="GDriveBackupCount" value="<?= $config['system']['remotebackup']['GDriveBackupCount'] ?>" size="40" type="text"></td> </tr>
<tr><td colspan=2><?=gettext("Password protect your data"); ?> :</td></tr>
<tr><td><?=gettext("Password :"); ?></td> <td> <input name="GDrivePassword" type="password" class="formfld pwd" size="20" value="<?= $config['system']['remotebackup']['GDrivePassword'] ?>" /> </td></tr>
<tr><td><?=gettext("Confirm :"); ?></td> <td> <input name="GDrivePasswordConfirm" type="password" class="formfld pwd" size="20" value="<?= $config['system']['remotebackup']['GDrivePassword'] ?>" /> </td></tr>
<tr><td><input name="Submit" class="btn btn-primary" id="Gdrive" value="<?=gettext("Setup/Test Google Drive");?>" type="submit"></td><td></td></tr>
<tr>
<td><?=gettext("Enable"); ?> </td>
<td>
<input name="GDriveEnabled" type="checkbox" <?=!empty($pconfig['GDriveEnabled']) ? "checked" : "";?> >
</td>
</tr>
<tr>
<td><?=gettext("Email Address"); ?> </td>
<td>
<input name="GDriveEmail" value="<?=$pconfig['GDriveEmail'];?>" type="text">
</td>
</tr>
<tr>
<td><?=gettext("P12 key"); ?> <?=!empty($pconfig['GDriveP12key']) ? gettext("(replace)") : gettext("(not loaded)"); ?> </td>
<td>
<input name="GDriveP12file" type="file">
</td>
</tr>
<tr>
<td><?=gettext("Folder ID"); ?> </td>
<td>
<input name="GDriveFolderID" value="<?=$pconfig['GDriveFolderID'];?>" type="text">
</td>
</tr>
<tr>
<td><?=gettext("Backup Count"); ?> </td>
<td>
<input name="GDriveBackupCount" value="<?=$pconfig['GDriveBackupCount'];?>" type="text">
</td>
</tr>
<tr>
<td colspan=2><?=gettext("Password protect your data"); ?> :</td>
</tr>
<tr>
<td><?=gettext("Password :"); ?></td>
<td>
<input name="GDrivePassword" type="password" value="<?=$pconfig['GDrivePassword'];?>" />
</td>
</tr>
<tr>
<td><?=gettext("Confirm :"); ?></td>
<td>
<input name="GDrivePasswordConfirm" type="password" value="<?=$pconfig['GDrivePassword'];?>" />
</td>
</tr>
<tr>
<td>
<input name="setup_gdrive" class="btn btn-primary" id="Gdrive" value="<?=gettext("Setup/Test Google Drive");?>" type="submit">
</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
</section>
</div>
</div>
</section>
</section>
</form>
<script type="text/javascript">
//<![CDATA[
encrypt_change();
decrypt_change();
//]]>
</script>
<?php include("foot.inc"); ?>
<?php
if (is_subsystem_dirty('restore')) {
system_reboot();
}
......@@ -30,47 +30,10 @@
require_once("guiconfig.inc");
$cnf = OPNsense\Core\Config::getInstance();
$confvers = $cnf->getBackups(true);
if (isset($_POST['backupcount'])) {
if (is_numeric($_POST['backupcount']) && ($_POST['backupcount'] >= 0)) {
$config['system']['backupcount'] = $_POST['backupcount'];
} else {
unset($config['system']['backupcount']);
}
write_config(gettext('Changed backup revision count.'));
} elseif (isset($_POST['newver']) && $_POST['newver'] != '') {
foreach ($confvers as $filename => $revision) {
if (isset($revision['time']) && $revision['time'] == $_POST['newver']) {
if (config_restore($filename)== 0) {
$savemsg = sprintf(gettext('Successfully reverted to timestamp %s with description "%s".'), date(gettext("n/j/y H:i:s"), $_POST['newver']), $revision['description']);
} else {
$savemsg = gettext("Unable to revert to the selected configuration.");
}
break;
}
}
} elseif (isset($_POST['rmver']) && $_POST['rmver'] != '') {
foreach ($confvers as $filename => $revision) {
if (isset($revision['time']) && $revision['time'] == $_POST['rmver']) {
if (file_exists($filename)) {
@unlink($filename);
$savemsg = sprintf(gettext('Deleted backup with timestamp %s and description "%s".'), date(gettext("n/j/y H:i:s"), $_POST['rmver']),$revision['description']);
} else {
$savemsg = gettext("Unable to delete the selected configuration.");
}
break;
}
}
}
if (isset($_POST)) {
/* things might have changed */
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$cnf = OPNsense\Core\Config::getInstance();
$confvers = $cnf->getBackups(true);
}
if (isset($_GET['getcfg']) && $_GET['getcfg'] != '') {
if (!empty($_GET['getcfg'])) {
foreach ($confvers as $filename => $revision) {
if ($revision['time'] == $_GET['getcfg']) {
$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
......@@ -84,17 +47,7 @@ if (isset($_GET['getcfg']) && $_GET['getcfg'] != '') {
exit;
}
}
}
$newcheck = 'current';
$oldcheck = '';
foreach ($confvers as $revision) {
/* grab first entry if any */
$oldcheck = $revision['time'];
break;
}
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime'])
} elseif (!empty($_GET['diff']) && isset($_GET['oldtime']) && isset($_GET['newtime'])
&& is_numeric($_GET['oldtime']) && (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
$oldfile = '';
$newfile = '';
......@@ -116,7 +69,6 @@ if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime
if ($_GET['newtime'] == 'current') {
$newfile = '/conf/config.xml';
$newtime = $config['revision']['time'];
$newcheck = 'current';
} else {
$newtime = $_GET['newtime'];
$newcheck = $newtime;
......@@ -125,12 +77,102 @@ if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime
if (file_exists($oldfile) && file_exists($newfile)) {
exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$cnf = OPNsense\Core\Config::getInstance();
$confvers = $cnf->getBackups(true);
if (!empty($_POST['save'])) {
if (is_numeric($_POST['backupcount']) && ($_POST['backupcount'] >= 0)) {
$config['system']['backupcount'] = $_POST['backupcount'];
} elseif (isset($config['system']['backupcount'])) {
unset($config['system']['backupcount']);
}
write_config(gettext('Changed backup revision count.'));
} elseif (!empty($_POST['act']) && $_POST['act'] == "revert") {
foreach ($confvers as $filename => $revision) {
if (isset($revision['time']) && $revision['time'] == $_POST['time']) {
if (config_restore($filename) == 0) {
$savemsg = sprintf(gettext('Successfully reverted to timestamp %s with description "%s".'), date(gettext("n/j/y H:i:s"), $_POST['id']), $revision['description']);
} else {
$savemsg = gettext("Unable to revert to the selected configuration.");
}
break;
}
}
} elseif (!empty($_POST['act']) && $_POST['act'] == "delete") {
foreach ($confvers as $filename => $revision) {
if (isset($revision['time']) && $revision['time'] == $_POST['time']) {
if (file_exists($filename)) {
@unlink($filename);
$savemsg = sprintf(gettext('Deleted backup with timestamp %s and description "%s".'), date(gettext("n/j/y H:i:s"), $revision['time']),$revision['description']);
} else {
$savemsg = gettext("Unable to delete the selected configuration.");
}
unset($confvers[$filename]);
break;
}
}
}
}
include("head.inc");
include("head.inc");
?>
<script type="text/javascript">
//<![CDATA[
$( document ).ready(function() {
// revert config dialog
$(".act_revert").click(function(){
var id = $(this).data('id');
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Action");?>",
message: "<?=gettext("Restore from Configuration Backup");?> <br/> <?=gettext('Version');?>: " + id,
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#time").val(id);
$("#action").val("revert");
$("#iform").submit()
}
}]
});
});
// delete backup dialog
$(".act_delete").click(function(){
var id = $(this).data('id');
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Action");?>",
message: "<?=gettext("Remove Configuration Backup");?> <br/> <?=gettext('Version');?>: " + id,
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#time").val(id);
$("#action").val("delete");
$("#iform").submit()
}
}]
});
});
});
//]]>
</script>
<body>
<?php
include("fbegin.inc");
......@@ -141,66 +183,35 @@ include("head.inc");
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<section class="col-xs-12">
<div class="container-fluid tab-content">
<div class="tab-pane active" id="system">
<?php if ($_GET["newver"] || $_GET["rmver"]): ?>
<form action="<?=explode("?", $_SERVER['REQUEST_URI'])[0];?>" method="post">
<section>
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?= gettext('Confirm Action') ?></h3>
</header>
<div class="content-box-main col-xs-12">
<strong><?= gettext('Please confirm the selected action') ?></strong>:
<br />
<br /><strong><?= gettext('Action') ?>:</strong>
<?php if (!empty($_GET["newver"])) {
echo gettext("Restore from Configuration Backup");
$target_config = $_GET["newver"]; ?>
<input type="hidden" name="newver" value="<?= htmlspecialchars($_GET['newver']) ?>" />
<?php } elseif (!empty($_GET["rmver"])) {
echo gettext("Remove Configuration Backup");
$target_config = $_GET["rmver"]; ?>
<input type="hidden" name="rmver" value="<?= htmlspecialchars($_GET['rmver']) ?>" />
<?php } ?>
<br /><strong><?= gettext('Target Configuration') ?>:</strong>
<?= sprintf(gettext('Timestamp %s'), date(gettext('n/j/y H:i:s'), $target_config)) ?>
<br /><input type="submit" name="confirm" class="btn btn-primary" value="<?= gettext('Confirm') ?>" />
</div>
</div>
</section>
</form>
<?php else: ?>
<form action="<?=$_SERVER['REQUEST_URI'];?>" method="post">
<div class="container-fluid">
<form method="post" id="iform">
<input type="hidden" id="time" name="time" value="" />
<input type="hidden" id="action" name="act" value="" />
<section style="margin-bottom:15px;">
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext('Settings');?></h3>
</header>
<div class="content-box-main">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th><?=gettext("Backup Count");?></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><?=gettext("Backup Count");?></td>
<td><input name="backupcount" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($config['system']['backupcount']);?>"/></td>
<td><?= gettext("Enter the number of older configurations to keep in the local backup cache. By default this is 30."); ?></td>
<td><input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" /></td>
</tr>
<tr>
<td>
<input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
</td>
</tr>
</tbody>
</table>
<hr/>
<div class="container-fluid">
<?= gettext("NOTE: Be aware of how much space is consumed by backups before adjusting this value. Current space used by backups: "); ?> <?= exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'") ?>
</div>
......@@ -209,21 +220,18 @@ include("head.inc");
</div>
</section>
</form>
<?php if ($diff): ?>
<section style="margin-bottom:15px;">
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext("Configuration diff from");?> <?php echo date(gettext("n/j/y H:i:s"), $oldtime); ?> <?=gettext("to");?> <?php echo date(gettext("n/j/y H:i:s"), $newtime); ?></h3>
<h3><?=gettext("Configuration diff from");?> <?= date(gettext("n/j/y H:i:s"), $oldtime); ?> <?=gettext("to");?> <?=date(gettext("n/j/y H:i:s"), $newtime); ?></h3>
</header>
<div class="content-box-main">
<div class="container-fluid __mb">
<div class="table-responsive">
<table summary="Differences">
<tr><td></td></tr>
<?php foreach ($diff as $line) {
<div class="table-responsive" style="overflow: scroll;">
<table class="table table-condensed table-striped">
<?php
foreach ($diff as $line):
switch (substr($line, 0, 1)) {
case '+':
$color = '#3bbb33';
......@@ -239,9 +247,10 @@ include("head.inc");
}
?>
<tr>
<td valign="middle" style="color: <?=$color;?>; white-space: pre-wrap; font-family: monospace;"><?php echo htmlentities($line);?></td>
<td style="color: <?=$color;?>; white-space: pre-wrap; font-family: monospace;"><?=htmlentities($line);?></td>
</tr>
<?php } ?>
<?php
endforeach;?>
</table>
</div>
</div>
......@@ -249,87 +258,88 @@ include("head.inc");
</div>
</section>
<?php endif; ?>
<?php if (is_array($confvers)): ?>
<form action="<?=$_SERVER['REQUEST_URI'];?>" method="get">
<form method="get">
<section>
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext('History');?></h3>
</header>
<div class="content-box-main">
<div class="container-fluid __mb">
<button type="submit" name="diff" class="btn btn-primary pull-left" style="margin-right: 8px;" value="Diff"><?=gettext('View differences');?></button>
<table class="table table-condensed">
<tr>
<td>
<button type="submit" name="diff" class="btn btn-primary pull-left" value="Diff">
<?=gettext('View differences');?>
</button>
</td>
<td>
<?= gettext("To view the differences between an older configuration and a newer configuration, select the older configuration using the left column of radio options and select the newer configuration in the right column, then press the button."); ?>
</td>
</tr>
</table>
</div>
<table class="table table-striped table-sort" summary="difference">
<table class="table table-striped">
<thead>
<tr>
<td colspan="2" valign="middle" class="list nowrap"><?=gettext("Diff");?></td>
<td class="listhdrr"><?=gettext("Date");?></td>
<td class="listhdrr"><?=gettext("Version");?></td>
<td class="listhdrr"><?=gettext("Size");?></td>
<td class="listhdrr"><?=gettext("Configuration Change");?></td>
<td class="list">&nbsp;</td>
<th colspan="2"><?=gettext("Diff");?></th>
<th><?=gettext("Date");?></th>
<th><?=gettext("Version");?></th>
<th><?=gettext("Size");?></th>
<th><?=gettext("Configuration Change");?></th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td valign="middle" class="list nowrap"></td>
<td class="list">
<input type="radio" name="newtime" value="current" <?= $newcheck == 'current' ? 'checked="checked"' : '' ?>/>
<tr>
<td></td>
<td>
<input type="radio" name="newtime" value="current" <?= !isset($newcheck) || $newcheck == 'current' ? 'checked="checked"' : '' ?>/>
</td>
<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
<td class="listr"> <?= $config['version'] ?></td>
<td class="listr"> <?= format_bytes(filesize("/conf/config.xml")) ?></td>
<td class="listr"> <?= "{$config['revision']['username']}: {$config['revision']['description']}" ?></td>
<td valign="middle" class="list nowrap"><b><?=gettext("Current");?></b></td>
<td> <?=date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
<td> <?=$config['version'] ?></td>
<td> <?=format_bytes(filesize("/conf/config.xml")) ?></td>
<td> <?="{$config['revision']['username']}: {$config['revision']['description']}" ?></td>
<td><b><?=gettext("Current");?></b></td>
</tr>
<?php
$c = 0;
foreach($confvers as $version):
?>
<tr valign="top">
<td class="list">
<input type="radio" name="oldtime" value="<?php echo $version['time'];?>" <?= $oldcheck == $version['time'] ? 'checked="checked"' : '' ?>/>
<?php
$i = 0;
foreach($confvers as $version):?>
<tr>
<td>
<input type="radio" name="oldtime" value="<?=$version['time'];?>" <?= (!isset($oldcheck) && $i == 0) || (isset($oldcheck) && $oldcheck == $version['time']) ? 'checked="checked"' : '' ?>/>
</td>
<td class="list">
<?php if ($c < (count($confvers) - 1)) { ?>
<input type="radio" name="newtime" value="<?php echo $version['time'];?>" <?= $newcheck == $version['time'] ? 'checked="checked"' : ''?>/>
<?php } else { ?>
&nbsp;
<?php }
$c++; ?>
<td>
<input type="radio" name="newtime" value="<?=$version['time'];?>" <?= isset($newcheck) && $newcheck == $version['time'] ? 'checked="checked"' : ''?>/>
</td>
<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $version['time']) ?></td>
<td class="listr"> <?= $version['version'] ?></td>
<td class="listr"> <?= format_bytes($version['filesize']) ?></td>
<td class="listr"> <?= "{$version['username']}: {$version['description']}" ?></td>
<td class="btn-group-table">
<a href="diag_confbak.php?newver=<?=$version['time'];?>" class="btn btn-default btn-xs" title="<?=gettext("Revert to this configuration");?>"><span class="glyphicon glyphicon-log-in"></span></a>
<a href="diag_confbak.php?rmver=<?=$version['time'];?>" class="btn btn-default btn-xs" title="<?=gettext("Remove this backup");?>" ><span class="glyphicon glyphicon-remove"></span></a>
<a href="diag_confbak.php?getcfg=<?=$version['time'];?>" class="btn btn-default btn-xs" title="<?=gettext("Download this backup");?>"><span class="glyphicon glyphicon-download"></span></a>
<td> <?= date(gettext("n/j/y H:i:s"), $version['time']) ?></td>
<td> <?= $version['version'] ?></td>
<td> <?= format_bytes($version['filesize']) ?></td>
<td> <?= "{$version['username']}: {$version['description']}" ?></td>
<td>
<a data-id="<?=$version['time'];?>" href="#" class="act_revert btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("Revert to this configuration");?>">
<span class="glyphicon glyphicon-log-in"></span>
</a>
<a data-id="<?=$version['time'];?>" href="#" class="act_delete btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("Remove this backup");?>" >
<span class="glyphicon glyphicon-remove"></span>
</a>
<a href="diag_confbak.php?getcfg=<?=$version['time'];?>" class="btn btn-default btn-xs" title="<?=gettext("Download this backup");?>">
<span class="glyphicon glyphicon-download"></span>
</a>
</td>
</tr>
<?php endforeach; ?>
<?php
$i++;
endforeach;?>
</tbody>
</table>
</div>
</div>
</section>
</form>
<?php endif; endif; ?>
</div>
</section>
</div>
</div>
</section>
</section>
<?php include("foot.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