Commit 2c03711a authored by Ad Schellevis's avatar Ad Schellevis

fix config restore / remove package code from backup/restore

parent 308122b3
#!/bin/sh #!/bin/sh
vi /conf/config.xml vi /conf/config.xml
rm /tmp/config.cache
...@@ -34,7 +34,7 @@ require_once("script/load_phalcon.php"); ...@@ -34,7 +34,7 @@ require_once("script/load_phalcon.php");
/****f* config/parse_config /****f* config/parse_config
* NAME * NAME
* parse_config - Read in config.cache or config.xml if needed and return $config array * parse_config - Read in config.xml if needed and return $config array
* RESULT * RESULT
* $config - array containing all configuration variables * $config - array containing all configuration variables
******/ ******/
...@@ -272,7 +272,6 @@ function reset_factory_defaults($lock = false) ...@@ -272,7 +272,6 @@ function reset_factory_defaults($lock = false)
} }
} }
closedir($dh); closedir($dh);
unlink_if_exists('/tmp/config.cache');
/* copy default configuration */ /* copy default configuration */
copy('/usr/local/etc/config.xml', '/conf/config.xml'); copy('/usr/local/etc/config.xml', '/conf/config.xml');
......
...@@ -44,7 +44,6 @@ $g = array( ...@@ -44,7 +44,6 @@ $g = array(
"vardb_path" => "/var/db", "vardb_path" => "/var/db",
"varlog_path" => "/var/log", "varlog_path" => "/var/log",
"tmp_path" => "/tmp", "tmp_path" => "/tmp",
"xml_rootobj" => "pfsense",
"admin_group" => "admins", "admin_group" => "admins",
"product_name" => "OPNsense", "product_name" => "OPNsense",
"product_copyright" => "Deciso B.V.", "product_copyright" => "Deciso B.V.",
......
...@@ -495,7 +495,6 @@ function restore_config_section($section_name, $new_contents) ...@@ -495,7 +495,6 @@ function restore_config_section($section_name, $new_contents)
} }
$config[$section_name] = &$section_xml; $config[$section_name] = &$section_xml;
@unlink('/tmp/config.cache');
write_config(sprintf(gettext("Restored %s of config file (maybe from CARP partner)"), $section_name)); write_config(sprintf(gettext("Restored %s of config file (maybe from CARP partner)"), $section_name));
disable_security_checks(); disable_security_checks();
......
...@@ -372,9 +372,6 @@ fi ...@@ -372,9 +372,6 @@ fi
/usr/local/bin/beep.sh start 2>&1 >/dev/null /usr/local/bin/beep.sh start 2>&1 >/dev/null
# Reset the cache. read-only requires this.
/bin/rm -f /tmp/config.cache
/usr/local/etc/rc.initial.banner /usr/local/etc/rc.initial.banner
exit 0 exit 0
...@@ -119,36 +119,6 @@ function restore_rrddata() { ...@@ -119,36 +119,6 @@ function restore_rrddata() {
} }
} }
function add_base_packages_menu_items() {
global $g, $config;
$base_packages = explode(",", $g['base_packages']);
$modified_config = false;
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)) {
$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'])
continue;
$config['installedpackages']['menu'][] = $menu;
$modified_config = true;
}
}
$static_output .= "done.\n";
update_output_window($static_output);
}
}
}
if($modified_config) {
write_config(gettext("Restored base_package menus after configuration restore."));
$config = parse_config();
}
}
function remove_bad_chars($string) { function remove_bad_chars($string) {
return preg_replace('/[^a-z_0-9]/i','',$string); return preg_replace('/[^a-z_0-9]/i','',$string);
...@@ -175,7 +145,6 @@ function spit_out_select_items($name, $showall) { ...@@ -175,7 +145,6 @@ function spit_out_select_items($name, $showall) {
"ipsec" => gettext("IPSEC"), "ipsec" => gettext("IPSEC"),
"nat" => gettext("NAT"), "nat" => gettext("NAT"),
"openvpn" => gettext("OpenVPN"), "openvpn" => gettext("OpenVPN"),
"installedpackages" => gettext("Package Manager"),
"pptpd" => gettext("PPTP Server"), "pptpd" => gettext("PPTP Server"),
"rrddata" => gettext("RRD Data"), "rrddata" => gettext("RRD Data"),
"cron" => gettext("Scheduled Tasks"), "cron" => gettext("Scheduled Tasks"),
...@@ -231,18 +200,11 @@ if ($_POST) { ...@@ -231,18 +200,11 @@ if ($_POST) {
unset($input_errors); unset($input_errors);
if (stristr($_POST['Submit'], gettext("Restore configuration"))) if (stristr($_POST['Submit'], gettext("Restore configuration")))
$mode = "restore"; $mode = "restore";
else if (stristr($_POST['Submit'], gettext("Reinstall")))
$mode = "reinstallpackages";
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"; $mode = "download";
else if (stristr($_POST['Submit'], gettext("Restore version"))) else if (stristr($_POST['Submit'], gettext("Restore version")))
$mode = "restore_ver"; $mode = "restore_ver";
if ($_POST["nopackages"] <> "")
$options = "nopackages";
if ($_POST["ver"] <> "") if ($_POST["ver"] <> "")
$ver2restore = $_POST["ver"]; $ver2restore = $_POST["ver"];
...@@ -259,26 +221,10 @@ if ($_POST) { ...@@ -259,26 +221,10 @@ if ($_POST) {
if (!$input_errors) { if (!$input_errors) {
//$lockbckp = lock('config');
$host = "{$config['system']['hostname']}.{$config['system']['domain']}"; $host = "{$config['system']['hostname']}.{$config['system']['domain']}";
$name = "config-{$host}-".date("YmdHis").".xml"; $name = "config-{$host}-".date("YmdHis").".xml";
$data = ""; $data = "";
if($options == "nopackages") {
if(!$_POST['backuparea']) {
/* backup entire configuration */
$data = file_get_contents('/conf/config.xml');
} else {
/* backup specific area of configuration */
$data = backup_config_section($_POST['backuparea']);
$name = "{$_POST['backuparea']}-{$name}";
}
$sfn = '/tmp/config.xml.nopkg';
file_put_contents($sfn, $data);
exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
$data = file_get_contents($sfn . "-new");
} else {
if(!$_POST['backuparea']) { if(!$_POST['backuparea']) {
/* backup entire configuration */ /* backup entire configuration */
$data = file_get_contents('/conf/config.xml'); $data = file_get_contents('/conf/config.xml');
...@@ -290,16 +236,13 @@ if ($_POST) { ...@@ -290,16 +236,13 @@ if ($_POST) {
$data = backup_config_section($_POST['backuparea']); $data = backup_config_section($_POST['backuparea']);
$name = "{$_POST['backuparea']}-{$name}"; $name = "{$_POST['backuparea']}-{$name}";
} }
}
//unlock($lockbckp);
/* /*
* Backup RRD Data * Backup RRD Data
*/ */
if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) { if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
$rrd_data_xml = rrd_data_xml(); $rrd_data_xml = rrd_data_xml();
$closing_tag = "</" . $g['xml_rootobj'] . ">"; $closing_tag = "</opnsense>";
$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data); $data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
} }
...@@ -370,9 +313,7 @@ if ($_POST) { ...@@ -370,9 +313,7 @@ if ($_POST) {
if ($config['rrddata']) { if ($config['rrddata']) {
restore_rrddata(); restore_rrddata();
unset($config['rrddata']); unset($config['rrddata']);
@unlink('/tmp/config.cache');
write_config(); write_config();
add_base_packages_menu_items();
convert_config(); convert_config();
} }
filter_configure(); filter_configure();
...@@ -380,26 +321,20 @@ if ($_POST) { ...@@ -380,26 +321,20 @@ if ($_POST) {
} }
} }
} else { } else {
if(!stristr($data, "<" . $g['xml_rootobj'] . ">")) { if(true) {
$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 */ /* restore the entire configuration */
file_put_contents($_FILES['conffile']['tmp_name'], $data); $filename = $_FILES['conffile']['tmp_name'];
file_put_contents($filename, $data);
$cnf = OPNsense\Core\Config::getInstance(); $cnf = OPNsense\Core\Config::getInstance();
if ($cnf->restoreBackup($filename)) { if ($cnf->restoreBackup($filename)) {
/* this will be picked up by /index.php */ /* this will be picked up by /index.php */
mark_subsystem_dirty("restore"); mark_subsystem_dirty("restore");
touch("/conf/needs_package_sync");
/* remove cache, we will force a config reboot */
@unlink('/tmp/config.cache');
$config = parse_config(); $config = parse_config();
/* extract out rrd items, unset from $config when done */ /* extract out rrd items, unset from $config when done */
if($config['rrddata']) { if($config['rrddata']) {
restore_rrddata(); restore_rrddata();
unset($config['rrddata']); unset($config['rrddata']);
@unlink('/tmp/config.cache');
write_config(); write_config();
add_base_packages_menu_items();
convert_config(); convert_config();
} }
if($m0n0wall_upgrade == true) { if($m0n0wall_upgrade == true) {
...@@ -430,7 +365,6 @@ if ($_POST) { ...@@ -430,7 +365,6 @@ if ($_POST) {
} }
} }
} }
@unlink('/tmp/config.cache');
// Reset configuration version to something low // Reset configuration version to something low
// in order to force the config upgrade code to // in order to force the config upgrade code to
// run through with all steps that are required. // run through with all steps that are required.
...@@ -494,7 +428,6 @@ if ($_POST) { ...@@ -494,7 +428,6 @@ if ($_POST) {
} }
$config['diag']['ipv6nat'] = true; $config['diag']['ipv6nat'] = true;
write_config(); write_config();
add_base_packages_menu_items();
convert_config(); convert_config();
$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to OPNsense."); $savemsg = gettext("The m0n0wall configuration has been restored and upgraded to OPNsense.");
mark_subsystem_dirty("restore"); mark_subsystem_dirty("restore");
...@@ -534,14 +467,7 @@ if ($_POST) { ...@@ -534,14 +467,7 @@ if ($_POST) {
} }
} }
if ($mode == "reinstallpackages") { if ($mode == "restore_ver") {
header("Location: pkg_mgr_install.php?mode=reinstallall");
exit;
} else if ($mode == "clearpackagelock") {
clear_subsystem_dirty('packagelock');
$savemsg = "Package Lock Cleared";
} else if ($mode == "restore_ver") {
$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm"); $input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
if ($ver2restore <> "") { if ($ver2restore <> "") {
$conf_file = '/conf/backup/config-' . strtotime($ver2restore) . '.xml'; $conf_file = '/conf/backup/config-' . strtotime($ver2restore) . '.xml';
...@@ -593,10 +519,8 @@ function decrypt_change() { ...@@ -593,10 +519,8 @@ function decrypt_change() {
function backuparea_change(obj) { function backuparea_change(obj) {
if (obj.value == "rrddata") { if (obj.value == "rrddata") {
document.getElementById("nopackages").disabled = true;
document.getElementById("dotnotbackuprrd").disabled = true; document.getElementById("dotnotbackuprrd").disabled = true;
} else { } else {
document.getElementById("nopackages").disabled = false;
document.getElementById("dotnotbackuprrd").disabled = false; document.getElementById("dotnotbackuprrd").disabled = false;
} }
} }
...@@ -655,19 +579,11 @@ function backuparea_change(obj) { ...@@ -655,19 +579,11 @@ function backuparea_change(obj) {
<tr> <tr>
<td> <td>
<table> <table>
<tr>
<td width="25">
<input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages" />
</td>
<td>
<span class="vexpl"><?=gettext("Do not backup package information."); ?></span>
</td>
</tr>
</table> </table>
<table> <table>
<tr> <tr>
<td width="25"> <td width="25">
<input name="encrypt" type="checkbox" class="formcheckbox" id="nopackages" onclick="encrypt_change()" /> <input name="encrypt" type="checkbox" class="formcheckbox" id="encryptconf" onclick="encrypt_change()" />
</td> </td>
<td> <td>
<span class="vexpl"><?=gettext("Encrypt this configuration file."); ?></span> <span class="vexpl"><?=gettext("Encrypt this configuration file."); ?></span>
...@@ -738,7 +654,7 @@ function backuparea_change(obj) { ...@@ -738,7 +654,7 @@ function backuparea_change(obj) {
<table> <table>
<tr> <tr>
<td width="25"> <td width="25">
<input name="decrypt" type="checkbox" class="formcheckbox" id="nopackages" onclick="decrypt_change()" /> <input name="decrypt" type="checkbox" class="formcheckbox" id="encryptconf" onclick="decrypt_change()" />
</td> </td>
<td> <td>
<span class="vexpl"><?=gettext("Configuration file is encrypted."); ?></span> <span class="vexpl"><?=gettext("Configuration file is encrypted."); ?></span>
...@@ -778,46 +694,6 @@ function backuparea_change(obj) { ...@@ -778,46 +694,6 @@ function backuparea_change(obj) {
</div> </div>
</section> </section>
<?php if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) { ?>
<section>
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext("Package Functions"); ?></h3>
</header>
<div class="content-box-main col-xs-12">
<div class="table-responsive">
<table class="table table-striped">
<tbody>
<tr>
<td>
<?php if ($config['installedpackages']['package'] != "") { ?>
<p><?=gettext("Click this button to reinstall all system packages. This may take a while."); ?> <br /><br />
<input name="Submit" type="submit" class="formbtn" id="reinstallpackages" value="<?=gettext("Reinstall packages"); ?>" />
<br />
<br />
<?php } ?>
<?php if (is_subsystem_dirty("packagelock")) { ?>
<p><?=gettext("Click this button to clear the package lock if a package fails to reinstall properly after an upgrade."); ?> <br /><br />
<input name="Submit" type="submit" class="formbtn" id="clearpackagelock" value="<?=gettext("Clear Package Lock"); ?>" />
<?php } ?>
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<? } ?>
</div> </div>
</div> </div>
......
...@@ -55,7 +55,6 @@ if ($_POST) { ...@@ -55,7 +55,6 @@ if ($_POST) {
$retval = 0; $retval = 0;
unlink_if_exists("/tmp/config.cache");
$retval |= filter_configure(); $retval |= filter_configure();
$savemsg = get_std_save_message($retval); $savemsg = get_std_save_message($retval);
......
...@@ -399,7 +399,6 @@ if ($_POST['apply']) { ...@@ -399,7 +399,6 @@ if ($_POST['apply']) {
if (!is_subsystem_dirty('interfaces')) if (!is_subsystem_dirty('interfaces'))
$intput_errors[] = gettext("You have already applied your settings!"); $intput_errors[] = gettext("You have already applied your settings!");
else { else {
unlink_if_exists("{$g['tmp_path']}/config.cache");
clear_subsystem_dirty('interfaces'); clear_subsystem_dirty('interfaces');
if (file_exists("{$g['tmp_path']}/.interfaces.apply")) { if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
......
...@@ -212,9 +212,6 @@ if (isset($_POST['add_x']) && isset($_POST['if_add'])) { ...@@ -212,9 +212,6 @@ if (isset($_POST['add_x']) && isset($_POST['if_add'])) {
uksort($config['interfaces'], "compare_interface_friendly_names"); uksort($config['interfaces'], "compare_interface_friendly_names");
/* XXX: Do not remove this. */
unlink_if_exists("{$g['tmp_path']}/config.cache");
write_config(); write_config();
$savemsg = gettext("Interface has been added."); $savemsg = gettext("Interface has been added.");
......
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