Revision da17d77e
Added by Ermal Luçi almost 16 years ago
- In config_install validate the file that will be installed not the already present config!
- Convert most hardcoded /tmp to the global variable
- Do not reboot the firewall under the hood without confirmation from the user after restoring. Just ask the user to do it.
- Fix various things in restore/backup code.
usr/local/www/diag_backup.php | ||
---|---|---|
52 | 52 |
$base_packages = split($g['base_packages'], ","); |
53 | 53 |
$modified_config = false; |
54 | 54 |
foreach($base_packages as $bp) { |
55 |
$basepkg_path = "/usr/local/pkg/"; |
|
56 |
if(file_exists($basepkg_path . $configfile)) { |
|
57 |
$pkg_config = parse_xml_config_pkg($basepkg_path . $bp, "packagegui"); |
|
55 |
$basepkg_path = "/usr/local/pkg/{$bp}"; |
|
56 |
$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION); |
|
57 |
if($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) { |
|
58 |
$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui"); |
|
58 | 59 |
if($pkg_config['menu'] != "") { |
59 | 60 |
if(is_array($pkg_config['menu'])) { |
60 | 61 |
foreach($pkg_config['menu'] as $menu) { |
... | ... | |
130 | 131 |
|
131 | 132 |
} |
132 | 133 |
|
134 |
if ($_POST['apply']) { |
|
135 |
ob_flush(); |
|
136 |
flush(); |
|
137 |
sleep(5); |
|
138 |
conf_mount_rw(); |
|
139 |
clear_subsystem_dirty("restore"); |
|
140 |
conf_mount_ro(); |
|
141 |
mwexec("/sbin/shutdown -r now"); |
|
142 |
exit; |
|
143 |
} |
|
144 |
|
|
133 | 145 |
if ($_POST) { |
134 | 146 |
unset($input_errors); |
135 | 147 |
if (stristr($_POST['Submit'], "Restore configuration")) |
... | ... | |
167 | 179 |
$data = ""; |
168 | 180 |
|
169 | 181 |
if($options == "nopackages") { |
170 |
$sfn = "/tmp/config.xml.nopkg";
|
|
182 |
$sfn = "{$g['tmp_path']}/config.xml.nopkg";
|
|
171 | 183 |
exec("sed '/<installedpackages>/,/<\/installedpackages>/d' /conf/config.xml > {$sfn}"); |
172 | 184 |
$data = file_get_contents($sfn); |
173 | 185 |
} else { |
... | ... | |
181 | 193 |
} |
182 | 194 |
} |
183 | 195 |
|
196 |
unlock($lockbckp); |
|
197 |
|
|
184 | 198 |
if ($_POST['encrypt']) { |
185 | 199 |
$data = encrypt_data($data, $_POST['encrypt_password']); |
186 | 200 |
tagfile_reformat($data, $data, "config.xml"); |
... | ... | |
213 | 227 |
header("Content-Length: $size"); |
214 | 228 |
echo $data; |
215 | 229 |
|
216 |
unlock($lockbckp); |
|
217 | 230 |
exit; |
218 | 231 |
} |
219 | 232 |
} |
... | ... | |
271 | 284 |
if (config_install($_FILES['conffile']['tmp_name']) == 0) { |
272 | 285 |
/* this will be picked up by /index.php */ |
273 | 286 |
conf_mount_rw(); |
274 |
if($g['platform'] <> "cdrom") |
|
275 |
touch("/needs_package_sync"); |
|
276 |
$reboot_needed = true; |
|
277 |
$savemsg = "The configuration has been restored. The firewall is now rebooting."; |
|
287 |
mark_subsystem_dirty("restore"); |
|
288 |
$savemsg = "The configuration has been restored. You need to reboot your firewall."; |
|
278 | 289 |
touch("/conf/needs_package_sync"); |
279 | 290 |
/* remove cache, we will force a config reboot */ |
280 |
if(file_exists("/tmp/config.cache"))
|
|
281 |
unlink("/tmp/config.cache");
|
|
291 |
if(file_exists("{$g['tmp_path']}/config.cache"))
|
|
292 |
unlink("{$g['tmp_path']}/config.cache");
|
|
282 | 293 |
$config = parse_config(true); |
283 | 294 |
/* extract out rrd items, unset from $confgi when done */ |
284 | 295 |
if($config['rrddata']) { |
... | ... | |
288 | 299 |
fclose($rrd_fd); |
289 | 300 |
} |
290 | 301 |
unset($config['rrddata']); |
291 |
unlink_if_exists("/tmp/config.cache");
|
|
302 |
unlink_if_exists("{$g['tmp_path']}/config.cache");
|
|
292 | 303 |
write_config(); |
293 | 304 |
add_base_packages_menu_items(); |
294 | 305 |
convert_config(); |
... | ... | |
304 | 315 |
if(is_array($ifdescrs)) |
305 | 316 |
foreach($ifdescrs as $iface) |
306 | 317 |
$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']); |
307 |
unlink_if_exists("/tmp/config.cache");
|
|
318 |
unlink_if_exists("{$g['tmp_path']}/config.cache");
|
|
308 | 319 |
write_config(); |
309 | 320 |
add_base_packages_menu_items(); |
310 | 321 |
convert_config(); |
311 | 322 |
conf_mount_ro(); |
312 |
$savemsg = "The m0n0wall configuration has been restored and upgraded to pfSense.<p>The firewall is now rebooting.";
|
|
313 |
$reboot_needed = true;
|
|
323 |
$savemsg = "The m0n0wall configuration has been restored and upgraded to pfSense. You need to reboot your firewall.";
|
|
324 |
mark_subsystem_dirty("restore");
|
|
314 | 325 |
} |
315 | 326 |
if(isset($config['captiveportal']['enable'])) { |
316 | 327 |
/* for some reason ipfw doesn't init correctly except on bootup sequence */ |
317 |
$savemsg = "The configuration has been restored.<p>The firewall is now rebooting.";
|
|
318 |
$reboot_needed = true;
|
|
328 |
$savemsg = "The configuration has been restored. You need to reboot your firewall.";
|
|
329 |
mark_subsystem_dirty("restore");
|
|
319 | 330 |
} |
320 | 331 |
setup_serial_port(); |
321 | 332 |
if(is_interface_mismatch() == true) { |
322 | 333 |
touch("/var/run/interface_mismatch_reboot_needed"); |
323 |
$reboot_needed = false;
|
|
334 |
clear_subsystem_dirty("restore");
|
|
324 | 335 |
header("Location: interfaces_assign.php"); |
325 | 336 |
exit; |
326 | 337 |
} |
... | ... | |
344 | 355 |
if ($ver2restore <> "") { |
345 | 356 |
$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml"; |
346 | 357 |
if (config_install($conf_file) == 0) { |
347 |
$reboot_needed = true;
|
|
348 |
$savemsg = "The configuration has been restored. The firewall is now rebooting.";
|
|
358 |
mark_subsystem_dirty("restore");
|
|
359 |
$savemsg = "The configuration has been restored. You need to reboot your firewall.";
|
|
349 | 360 |
} else { |
350 | 361 |
$input_errors[] = "The configuration could not be restored."; |
351 | 362 |
} |
... | ... | |
392 | 403 |
<form action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data"> |
393 | 404 |
<?php if ($input_errors) print_input_errors($input_errors); ?> |
394 | 405 |
<?php if ($savemsg) print_info_box($savemsg); ?> |
406 |
<?php if (is_subsystem_dirty('restore')): ?><p> |
|
407 |
<?php print_info_box_np("The firewall configuration has been changed.<br>You must click the apply button to restart the firewall in order for it to take effect.");?><br> |
|
408 |
<?php endif; ?> |
|
395 | 409 |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> |
396 | 410 |
<tr> |
397 | 411 |
<td> |
... | ... | |
538 | 552 |
<?php include("fend.inc"); ?> |
539 | 553 |
</body> |
540 | 554 |
</html> |
541 |
|
|
542 |
<?php |
|
543 |
|
|
544 |
if($reboot_needed == true) { |
|
545 |
ob_flush(); |
|
546 |
flush(); |
|
547 |
sleep(5); |
|
548 |
while(file_exists("{$g['varrun_path']}/config.lock")) |
|
549 |
sleep(3); |
|
550 |
mwexec("/sbin/shutdown -r now"); |
|
551 |
exit; |
|
552 |
} |
|
553 |
|
|
554 |
?> |
Also available in: Unified diff