diag_backup.php 30.9 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
	Copyright (C) 2014 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
	Copyright (C) 2004-2009 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

/* Allow additional execution time 0 = no limit. */
ini_set('max_execution_time', '0');
ini_set('max_input_time', '0');

/* omit no-cache headers because it confuses IE with file downloads */
$omit_nocacheheaders = true;
$nocsrf = true;
38 39

require_once("guiconfig.inc");
40
require_once("interfaces.inc");
41
require_once("filter.inc");
Ad Schellevis's avatar
Ad Schellevis committed
42
require_once("services.inc");
43
require_once("rrd.inc");
44
require_once("system.inc");
45
require_once("pfsense-utils.inc");
Ad Schellevis's avatar
Ad Schellevis committed
46

47 48 49 50 51 52 53 54 55 56 57 58 59
/**
 * check if cron exists
 */
function cron_job_exists($command) {
	global $config;
	foreach($config['cron']['item'] as $item) {
		if(strstr($item['command'], $command)) {
			return true;
		}
	}
	return false;
}

60 61
$rrddbpath = '/var/db/rrd';
$rrdtool = '/usr/local/bin/rrdtool';
Ad Schellevis's avatar
Ad Schellevis committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

function rrd_data_xml() {
	global $rrddbpath;
	global $rrdtool;

	$result = "\t<rrddata>\n";
	$rrd_files = glob("{$rrddbpath}/*.rrd");
	$xml_files = array();
	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}'");
		$xml_data = file_get_contents($xml_file);
		unlink($xml_file);
		if ($xml_data !== false) {
			$result .= "\t\t<rrddatafile>\n";
			$result .= "\t\t\t<filename>{$basename}</filename>\n";
			$result .= "\t\t\t<xmldata>" . base64_encode(gzdeflate($xml_data)) . "</xmldata>\n";
			$result .= "\t\t</rrddatafile>\n";
		}
	}
	$result .= "\t</rrddata>\n";
	return $result;
}

function restore_rrddata() {
	global $config, $g, $rrdtool, $input_errors;
	foreach($config['rrddata']['rrddatafile'] as $rrd) {
		if ($rrd['xmldata']) {
91
			$rrd_file = "/var/db/rrd/{$rrd['filename']}";
Ad Schellevis's avatar
Ad Schellevis committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
			$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
			if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
				log_error("Cannot write $xml_file");
				continue;
			}
			$output = array();
			$status = null;
			exec("$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']) {
107
			$rrd_file = "/var/db/rrd/{$rrd['filename']}";
Ad Schellevis's avatar
Ad Schellevis committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
			$rrd_fd = fopen($rrd_file, "w");
			if (!$rrd_fd) {
				log_error("Cannot write $rrd_file");
				continue;
			}
			$data = base64_decode($rrd['data']);
			/* Try to decompress the data. */
			$dcomp = @gzinflate($data);
			if ($dcomp) {
				/* If the decompression worked, write the decompressed data */
				if (fwrite($rrd_fd, $dcomp) === false) {
					log_error("fwrite $rrd_file failed");
					continue;
				}
			} else {
				/* 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;
			}
		}
	}
}


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"),
		       "dnsmasq" => gettext("DNS Forwarder"),
		       "dhcpd" => gettext("DHCP Server"),
		       "dhcpdv6" => gettext("DHCPv6 Server"),
		       "filter" => gettext("Firewall Rules"),
		       "interfaces" => gettext("Interfaces"),
		       "ipsec" => gettext("IPSEC"),
		       "nat" => gettext("NAT"),
		       "openvpn" => gettext("OpenVPN"),
		       "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"),
		       "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)
			$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 ($_POST) {
	unset($input_errors);
	if (stristr($_POST['Submit'], gettext("Restore configuration")))
		$mode = "restore";
	else if (stristr($_POST['Submit'], gettext("Download")))
		$mode = "download";
	else if (stristr($_POST['Submit'], gettext("Restore version")))
		$mode = "restore_ver";
221 222
        else if (stristr($_POST['Submit'], gettext("Setup/Test Google Drive")))
                $mode = "setup_gdrive";
Ad Schellevis's avatar
Ad Schellevis committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

	if ($_POST["ver"] <> "")
		$ver2restore = $_POST["ver"];

	if ($mode) {

		if ($mode == "download") {

			if ($_POST['encrypt']) {
				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'])
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
			}

			if (!$input_errors) {

				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
				$name = "config-{$host}-".date("YmdHis").".xml";
				$data = "";

244 245 246 247 248 249
				if(!$_POST['backuparea']) {
					/* backup entire configuration */
					$data = file_get_contents('/conf/config.xml');
				} else if ($_POST['backuparea'] === "rrddata") {
					$data = rrd_data_xml();
					$name = "{$_POST['backuparea']}-{$name}";
Ad Schellevis's avatar
Ad Schellevis committed
250
				} else {
251 252 253
					/* backup specific area of configuration */
					$data = backup_config_section($_POST['backuparea']);
					$name = "{$_POST['backuparea']}-{$name}";
Ad Schellevis's avatar
Ad Schellevis committed
254 255 256 257 258 259 260
				}

				/*
				 *  Backup RRD Data
				 */
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
					$rrd_data_xml = rrd_data_xml();
261
					$closing_tag = "</opnsense>";
Ad Schellevis's avatar
Ad Schellevis committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
				}

				if ($_POST['encrypt']) {
					$data = encrypt_data($data, $_POST['encrypt_password']);
					tagfile_reformat($data, $data, "config.xml");
				}

				$size = strlen($data);
				header("Content-Type: application/octet-stream");
				header("Content-Disposition: attachment; filename={$name}");
				header("Content-Length: $size");
				if (isset($_SERVER['HTTPS'])) {
					header('Pragma: ');
					header('Cache-Control: ');
				} else {
					header("Pragma: private");
					header("Cache-Control: private, must-revalidate");
				}
				echo $data;

				exit;
			}
285
		}elseif ($mode == "restore") {
Ad Schellevis's avatar
Ad Schellevis committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

			if ($_POST['decrypt']) {
				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'])
					$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) {
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
						return 1;
					}

					if ($_POST['decrypt']) {
						if (!tagfile_deformat($data, $data, "config.xml")) {
307
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted OPNsense configuration.");
Ad Schellevis's avatar
Ad Schellevis committed
308 309 310 311 312
						}
						$data = decrypt_data($data, $_POST['decrypt_password']);
					}

					if(stristr($data, "<m0n0wall>")) {
313
						log_error(gettext("Upgrading m0n0wall configuration to OPNsense."));
Ad Schellevis's avatar
Ad Schellevis committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
						/* 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 (!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']) {
									restore_rrddata();
									unset($config['rrddata']);
									write_config();
									convert_config();
								}
								filter_configure();
								$savemsg = gettext("The configuration area has been restored.  You may need to reboot the firewall.");
							}
						}
					} else {
337
						if(!$input_errors) {
Ad Schellevis's avatar
Ad Schellevis committed
338
							/* restore the entire configuration */
339 340
							$filename = $_FILES['conffile']['tmp_name'];
							file_put_contents($filename, $data);
Ad Schellevis's avatar
Ad Schellevis committed
341 342
							$cnf = OPNsense\Core\Config::getInstance();
							if ($cnf->restoreBackup($filename)) {
Ad Schellevis's avatar
Ad Schellevis committed
343 344
								/* this will be picked up by /index.php */
								mark_subsystem_dirty("restore");
345

346
								$config = parse_config();
347

Ad Schellevis's avatar
Ad Schellevis committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
								/* extract out rrd items, unset from $config when done */
								if($config['rrddata']) {
									restore_rrddata();
									unset($config['rrddata']);
									write_config();
									convert_config();
								}
								if($m0n0wall_upgrade == true) {
									if($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) {
											if(is_alias($config['interfaces'][$iface]['descr'])) {
												// Firewall rules
												$origname = $config['interfaces'][$iface]['descr'];
												$newname  = $config['interfaces'][$iface]['descr'] . "Alias";
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
												// NAT Rules
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
												// Alias in an alias
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
											}
										}
									}
									// Reset configuration version to something low
									// in order to force the config upgrade code to
									// run through with all steps that are required.
									$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)
											$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")
											$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;
											}
										}
									}
									$config['diag']['ipv6nat'] = true;
									write_config();
									convert_config();
446
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to OPNsense.");
Ad Schellevis's avatar
Ad Schellevis committed
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
									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 {
								$input_errors[] = gettext("The configuration could not be restored.");
							}
						}
					}
				} else {
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
				}
			}
468
		} elseif ($mode == "restore_ver") {
Ad Schellevis's avatar
Ad Schellevis committed
469 470
			$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
			if ($ver2restore <> "") {
471
				$conf_file = '/conf/backup/config-' . strtotime($ver2restore) . '.xml';
Ad Schellevis's avatar
Ad Schellevis committed
472 473
				$cnf = OPNsense\Core\Config::getInstance();
				if ($cnf->restoreBackup($conf_file)) {
Ad Schellevis's avatar
Ad Schellevis committed
474 475 476 477 478 479 480
					mark_subsystem_dirty("restore");
				} else {
					$input_errors[] = gettext("The configuration could not be restored.");
				}
			} else {
				$input_errors[] = gettext("No version selected.");
			}
481 482 483 484 485 486 487 488 489 490
		} elseif ( $mode == "setup_gdrive" ){
		      global $config;
		      if (!isset($config['system']['remotebackup'])) {
		        $config['system']['remotebackup'] = array() ;
		      }
		      $config['system']['remotebackup']['GDriveEnabled'] = $_POST['GDriveEnabled'];
		      $config['system']['remotebackup']['GDriveEmail'] = $_POST['GDriveEmail'] ;
		      $config['system']['remotebackup']['GDriveFolderID'] = $_POST['GDriveFolderID'];
		      $config['system']['remotebackup']['GDrivePassword'] = $_POST['GDrivePassword'];
		      if (is_numeric($_POST['GDriveBackupCount'])) {
491
		        $config['system']['remotebackup']['GDriveBackupCount'] = $_POST['GDriveBackupCount'];
492 493 494
                      } else {
                        $config['system']['remotebackup']['GDriveBackupCount'] = 30;
                      }
495

496 497 498 499
		      if ( $_POST['GDrivePasswordConfirm'] != $_POST['GDrivePassword'] ) {
		        // log error, but continue
		        $input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
		      }
500 501

		      if (is_uploaded_file($_FILES['GDriveP12file']['tmp_name'])) {
502 503 504 505 506
                          $data = file_get_contents($_FILES['GDriveP12file']['tmp_name']);
                          $config['system']['remotebackup']['GDriveP12key'] = base64_encode($data);
                      } elseif ($config['system']['remotebackup']['GDriveEnabled'] != "on") {
                          unset($config['system']['remotebackup']['GDriveP12key']);
                      }
507

508
                      write_config();
509
                      // test / perform backup
510 511
                      try {
                         $filesInBackup = backup_to_google_drive() ;
Ad Schellevis's avatar
Ad Schellevis committed
512 513 514 515 516
                         $cron_job = "/usr/local/opnsense/scripts/remote_backup.php";
                         if (!cron_job_exists($cron_job)) {
                           // initial cron job install
                           install_cron_job($cron_job,true,0,1);
                         }
517
                      } catch (Exception $e) {
518 519
                         $filesInBackup = array() ;
                      }
520

521 522 523 524
                      if (count($filesInBackup) == 0) {
                         $input_errors[] = gettext("Google Drive communication failure");
                      } else {
                         $input_messages = gettext("Backup succesfull, current filelist:");
Ad Schellevis's avatar
Ad Schellevis committed
525
                      foreach ($filesInBackup as $filename => $file) {
526
                         $input_messages = $input_messages . "<br>" . $filename ;
Ad Schellevis's avatar
Ad Schellevis committed
527 528
                      }
                  }
Ad Schellevis's avatar
Ad Schellevis committed
529 530 531 532 533 534 535 536 537 538
		}
	}
}

$id = rand() . '.' . time();

$mth = ini_get('upload_progress_meter.store_method');
$dir = ini_get('upload_progress_meter.file.filename_template');

$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
539

Ad Schellevis's avatar
Ad Schellevis committed
540 541 542 543
include("head.inc");

?>

544
<body>
Ad Schellevis's avatar
Ad Schellevis committed
545
<?php include("fbegin.inc"); ?>
546

Ad Schellevis's avatar
Ad Schellevis committed
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
<script type="text/javascript">
//<![CDATA[

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="";
}

function backuparea_change(obj) {
	if (obj.value == "rrddata") {
		document.getElementById("dotnotbackuprrd").disabled = true;
	} else {
		document.getElementById("dotnotbackuprrd").disabled = false;
	}
}
//]]>
</script>

576

577
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
Ad Schellevis's avatar
Ad Schellevis committed
578 579 580 581 582 583
<?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; ?>
584 585


Ad Schellevis's avatar
Ad Schellevis committed
586
<form action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
587
	<section class="page-content-main">
588
		<div class="container-fluid">
589
			<div class="row">
Ad Schellevis's avatar
Ad Schellevis committed
590
			        <?php if ($input_messages) print_info_box($input_messages); ?>
591
				<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
592

593
			    <section class="col-xs-12">
594 595 596


					<?php
597 598 599 600 601 602
								$tab_array = array();
								$tab_array[0] = array(gettext("Config History"), false, "diag_confbak.php");
								$tab_array[1] = array(gettext("Backup/Restore"), true, "diag_backup.php");
								display_top_tabs($tab_array);
						?>

603

604
						<div class="tab-content content-box col-xs-12">
605 606 607 608

					    <div class="container-fluid tab-content">

							<div class="tab-pane active" id="system">
609

Ad Schellevis's avatar
Ad Schellevis committed
610
									<section class="__mb">
611 612
				                        <div class="content-box">

Ad Schellevis's avatar
Ad Schellevis committed
613
				                            <header class="content-box-head container-fluid">
614 615 616 617 618 619 620 621 622 623 624 625 626 627
									        <h3>Backup configuration</h3>
									    </header>

									    <div class="content-box-main ">
									    <div class="table-responsive">

									        <table class="table table-striped __nomb">
										        <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>
628 629 630
																	</table>
																	<table>
																		<tr>
Ad Schellevis's avatar
Ad Schellevis committed
631
																			<td width="25">
632
																				<input name="encrypt" type="checkbox" class="formcheckbox" id="encryptconf" onclick="encrypt_change()" />
633 634 635 636 637 638
																			</td>
																			<td>
																				<span class="vexpl"><?=gettext("Encrypt this configuration file."); ?></span>
																			</td>
																		</tr>
																		<tr>
Ad Schellevis's avatar
Ad Schellevis committed
639
																			<td width="25">
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
																				<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">
																		<tr>
																			<td>
																				<span class="vexpl"><?=gettext("Password:"); ?> </span>
																			</td>
																			<td>
																				<input name="encrypt_password" type="password" class="formfld pwd" size="20" 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>
																		</tr>
																	</table>
665

Ad Schellevis's avatar
Ad Schellevis committed
666
																	<input name="Submit" type="submit" class="btn btn-default __mt" id="download" value="<?=gettext("Download configuration"); ?>" />
667 668 669 670 671 672 673 674 675 676 677 678 679


										          </td>
										        </tr>
										        </tbody>
										    </table>
									    </div>

									    </div>

									</div>
								</section>

680
								<section class="__mb">
681 682
				                        <div class="content-box">

Ad Schellevis's avatar
Ad Schellevis committed
683
				                            <header class="content-box-head container-fluid">
684 685 686 687 688 689 690 691 692
									        <h3><?=gettext("Restore configuration"); ?></h3>
									    </header>

									    <div class="content-box-main ">
									    <div class="table-responsive">
									        <table class="table table-striped __nomb">
										        <tbody>
										        <tr>
										          <td><p><?=gettext("Open a"); ?> <?=$g['[product_name']?> <?=gettext("configuration XML file and click the button below to restore the configuration."); ?>
Ad Schellevis's avatar
Ad Schellevis committed
693
						<br /><br />
694
						<?=gettext("Restore area:"); ?> <?php spit_out_select_items("restorearea", true); ?></p></td>
695 696 697 698
										        </tr>
										        <tr>
										          <td>

699 700 701
																<p><input name="conffile" type="file" class="formbtn" id="conffile" size="40" /></p>
																<table>
																	<tr>
Ad Schellevis's avatar
Ad Schellevis committed
702
																		<td width="25">
703
																			<input name="decrypt" type="checkbox" class="formcheckbox" id="encryptconf" onclick="decrypt_change()" />
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
																		</td>
																		<td>
																			<span class="vexpl"><?=gettext("Configuration file is encrypted."); ?></span>
																		</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>
																	</tr>
																	<tr>
																		<td>
																			<span class="vexpl"><?=gettext("confirm :"); ?></span>
																		</td>
																		<td>
																			<input name="decrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
																		</td>
																	</tr>
																</table>
Ad Schellevis's avatar
Ad Schellevis committed
728
																<p><input name="Submit" type="submit" class="btn btn-default" id="restore" value="<?=gettext("Restore configuration"); ?>" /></p>
729
																<p><strong><span class="red"><?=gettext("Note:"); ?></span></strong><br /><?=gettext("The firewall will reboot after restoring the configuration."); ?><br /></p>
730 731 732 733 734 735 736 737 738 739 740 741


										          </td>
										        </tr>
										        </tbody>
										    </table>
									    </div>

									    </div>

									</div>
								</section>
742

743
                                                                <section class="__mb">
744 745
						                        <div class="content-box">
						                            <header class="content-box-head container-fluid">
746 747
									        <h3><?=gettext("Remote backup (using Google drive)"); ?></h3>
									    </header>
748 749

									    <div class="content-box-main ">
750
                                                                              <div class="table-responsive">
751
                                                                                    <table class="table table-striped __nomb">
752 753 754 755 756 757 758 759 760
                                                                                          <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" <? 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="<? echo $config['system']['remotebackup']['GDriveEmail'];?>" type="text"> </td> </tr>
                                                                                             <tr><td><?=gettext("P12 key"); ?> <? 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="<? echo $config['system']['remotebackup']['GDriveFolderID'];?>" size="40" type="text"></td> </tr>
761
                                                                                             <tr><td><?=gettext("Backup Count"); ?> </td><td> <input name="GDriveBackupCount" class="formbtn" id="GDriveBackupCount" value="<? echo $config['system']['remotebackup']['GDriveBackupCount'];?>" size="40" type="text"></td> </tr>
762 763 764 765 766 767 768
                                                                                             <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="<? echo $config['system']['remotebackup']['GDrivePassword'] ;?>" /> </td></tr>
                                                                                             <tr><td><?=gettext("Confirm :"); ?></td> <td> <input name="GDrivePasswordConfirm" type="password" class="formfld pwd" size="20" value="<? echo $config['system']['remotebackup']['GDrivePassword'] ;?>" /> </td></tr>
                                                                                             <tr><td><input name="Submit" class="btn btn-default" id="Gdrive" value="<?=gettext("Setup/Test Google Drive");?>" type="submit"></td><td></td></tr>
                                                                                          </tbody>
                                                                                    </table>
                                                                              </div>
769
                                                                            </div>
770 771
									</div>
                                                                </section>
772 773


774 775 776 777 778 779
						</div>
						</div>

					</div>


780 781 782



783 784
				</section>

Ad Schellevis's avatar
Ad Schellevis committed
785
			</div>
786 787 788 789
		</div>
	</section>


Ad Schellevis's avatar
Ad Schellevis committed
790 791 792 793 794 795 796 797 798
</form>

<script type="text/javascript">
//<![CDATA[
encrypt_change();
decrypt_change();
//]]>
</script>

799 800
<?php include("foot.inc"); ?>

Ad Schellevis's avatar
Ad Schellevis committed
801 802 803 804 805 806
<?php

if (is_subsystem_dirty('restore'))
	system_reboot();

?>