/,/<\/installedpackages>/d' /conf/config.xml > {$sfn}");
$data = file_get_contents($sfn);
} else {
if(!$_POST['backuparea']) {
/* backup entire configuration */
$data = file_get_contents("{$g['conf_path']}/config.xml");
} else {
/* backup specific area of configuration */
$data = backup_config_section($_POST['backuparea']);
$name = "{$_POST['backuparea']}-{$name}";
}
}
if ($_POST['encrypt']) {
$data = encrypt_data($data, $_POST['encrypt_password']);
tagfile_reformat($data, $data, "config.xml");
}
/*
* Backup RRD Data
*/
if(!$_POST['donotbackuprrd']) {
$data = str_replace("", "\t", $data);
$rrd_files_var_db_rrd = split("\n",`cd /var/db/rrd && ls *.rrd`);
foreach($rrd_files_var_db_rrd as $rrd) {
if($rrd) {
$rrd_data = file_get_contents("{$g['vardb_path']}/rrd/{$rrd}");
if($rrd_data) {
$data .= "\t\t\n";
$data .= "\t\t\t{$rrd}\n";
$data .= "\t\t\t" . base64_encode($rrd_data) . "\n";
$data .= "\t\t\n";
}
}
}
$data .= "\t\n";
$data .= "\n";
}
$size = strlen($data);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$name}");
header("Content-Length: $size");
echo $data;
unlock($lockbckp);
exit;
}
}
if ($mode == "restore") {
if ($_POST['decrypt']) {
if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
$input_errors[] = "You must supply and confirm the password for decryption.";
if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
$input_errors[] = "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) {
log_error("Warning, could not read file " . $_FILES['conffile']['tmp_name']);
return 1;
}
if ($_POST['decrypt']) {
if (!tagfile_deformat($data, $data, "config.xml")) {
$input_errors[] = "The uploaded file does not appear to contain an encrypted pfsense configuration.";
return 1;
}
$data = decrypt_data($data, $_POST['decrypt_password']);
}
if(stristr($data, "m0n0wall")) {
log_error("Upgrading m0n0wall configuration to pfsense.");
/* 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[] = "You have selected to restore a area but we could not locate the correct xml tag.";
} else {
restore_config_section($_POST['restorearea'], $data);
filter_configure();
$savemsg = "The configuration area has been restored. You may need to reboot the firewall.";
}
} else {
if(!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
$input_errors[] = "You have selected to restore the full configuration but we could not locate a " . $g['xml_rootobj'] . " tag.";
} else {
/* restore the entire configuration */
file_put_contents($_FILES['conffile']['tmp_name'], $data);
if (config_install($_FILES['conffile']['tmp_name']) == 0) {
/* this will be picked up by /index.php */
conf_mount_rw();
if($g['platform'] <> "cdrom")
touch("/needs_package_sync");
$reboot_needed = true;
$savemsg = "The configuration has been restored. The firewall is now rebooting.";
/* remove cache, we will force a config reboot */
if(file_exists("/tmp/config.cache"))
unlink("/tmp/config.cache");
$config = parse_config(true);
/* extract out rrd items, unset from $confgi when done */
if($config['rrddata']) {
foreach($config['rrddata']['rrddatafile'] as $rrd) {
$rrd_fd = fopen("{$g['vardb_path']}/rrd/{$rrd['filename']}", "w");
fwrite($rrd_fd, base64_decode($rrd['data']));
fclose($rrd_fd);
}
unset($config['rrddata']);
unlink_if_exists("/tmp/config.cache");
write_config();
add_base_packages_menu_items();
convert_config();
conf_mount_ro();
}
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)
$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
unlink_if_exists("/tmp/config.cache");
write_config();
add_base_packages_menu_items();
convert_config();
conf_mount_ro();
$savemsg = "The m0n0wall configuration has been restored and upgraded to pfSense.The firewall is now rebooting.";
$reboot_needed = true;
}
if(isset($config['captiveportal']['enable'])) {
/* for some reason ipfw doesn't init correctly except on bootup sequence */
$savemsg = "The configuration has been restored.
The firewall is now rebooting.";
$reboot_needed = true;
}
setup_serial_port();
if(is_interface_mismatch() == true) {
touch("/var/run/interface_mismatch_reboot_needed");
$reboot_needed = false;
header("Location: interfaces_assign.php");
exit;
}
} else {
$input_errors[] = "The configuration could not be restored.";
}
}
}
} else {
$input_errors[] = "The configuration could not be restored (file upload error).";
}
}
}
if ($mode == "reinstallpackages") {
header("Location: pkg_mgr_install.php?mode=reinstallall");
exit;
} else if ($mode == "restore_ver") {
$input_errors[] = "XXX - this feature may hose your config (do NOT backrev configs!) - billm";
if ($ver2restore <> "") {
$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
if (config_install($conf_file) == 0) {
$reboot_needed = true;
$savemsg = "The configuration has been restored. The firewall is now rebooting.";
} else {
$input_errors[] = "The configuration could not be restored.";
}
} else {
$input_errors[] = "No version selected.";
}
}
}
}
$id = rand() . '.' . time();
$mth = ini_get('upload_progress_meter.store_method');
$dir = ini_get('upload_progress_meter.file.filename_template');
$pgtitle = array("Diagnostics","Backup/restore");
include("head.inc");
?>