system_firmware_restorefullbackup.php 6.56 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-2015 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
	Copyright (C) 2011 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');

35
require_once("functions.inc");
Ad Schellevis's avatar
Ad Schellevis committed
36 37 38 39 40 41 42 43
require("guiconfig.inc");
require_once("filter.inc");
require_once("shaper.inc");

if($_POST['overwriteconfigxml'])
	touch("/tmp/do_not_restore_config.xml");

if($_GET['backupnow'])
44
	mwexec_bg("/usr/local/etc/rc.create_full_backup");
Ad Schellevis's avatar
Ad Schellevis committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

if($_GET['downloadbackup']) {
	$filename = basename($_GET['downloadbackup']);
	$path = "/root/{$filename}";
	if(file_exists($path)) {
		session_write_close();
		ob_end_clean();
		session_cache_limiter('public');
		//$fd = fopen("/root/{$filename}", "rb");
		$filesize = filesize("/root/{$filename}");
		header("Cache-Control: ");
		header("Pragma: ");
		header("Content-Type: application/octet-stream");
		header("Content-Length: " .(string)(filesize($path)) );
		header('Content-Disposition: attachment; filename="'.$filename.'"');
		header("Content-Transfer-Encoding: binary\n");
		if($file = fopen("/root/{$filename}", 'rb')){
			while( (!feof($file)) && (connection_status()==0) ){
				print(fread($file, 1024*8));
				flush();
			}
			fclose($file);
		}

		exit;
	}
}

if ($_GET['deletefile']) {
	$filename = $_GET['deletefile'];
	if(file_exists("/root/{$filename}")) {
		unlink("/root/" . $filename);
		$savemsg = gettext("$filename has been deleted.");
	}
}

if ($_POST['restorefile']) {
	$filename = $_POST['restorefile'];
	if(file_exists("/root/{$filename}")) {
84
		mwexec_bg("/usr/local/etc/rc.restore_full_backup /root/" . escapeshellcmd($filename));
Ad Schellevis's avatar
Ad Schellevis committed
85 86 87 88 89 90 91 92 93
		$savemsg = gettext("The firewall is currently restoring $filename");
	}
}

$pgtitle = array(gettext("Diagnostics"),gettext("Restore full backup"));
include("head.inc");

?>

94
<body>
Ad Schellevis's avatar
Ad Schellevis committed
95
<?php include("fbegin.inc"); ?>
96 97 98 99

<!-- row -->
<section class="page-content-main">
	<div class="container-fluid">
100

101 102
        <div class="row">
            <?php
103 104
		if ($input_errors) print_input_errors($input_errors);
		if ($savemsg) print_info_box($savemsg);
105 106
            ?>
            <section class="col-xs-12">
107 108 109

                <? include('system_firmware_tabs.php'); ?>

110 111 112
                <div class="content-box tab-content">

                    <?php if (is_subsystem_dirty('restore')): ?><p>
113

114 115 116 117
                    <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>
118

119
                    <?php endif; ?>
120

121
                    <form action="system_firmware_restorefullbackup.php" method="post">
122 123 124 125 126 127 128 129 130 131 132

				<table class="table table-striped __nomb" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">

					<thead>
						<tr>
							<th colspan="1" class="listtopic"><?=gettext("Filename"); ?></th>
							<th colspan="1" class="listtopic"><?=gettext("Date"); ?></th>
							<th colspan="2" class="listtopic"><?=gettext("Size"); ?></th>
						</tr>
					</thead>

133
                            <tbody>
134

135
                                <?php
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
						chdir("/root");
						$available_restore_files = glob("pfSense-full-backup-*");
						$counter = 0;
						foreach($available_restore_files as $arf) {
							$counter++;
							$size = exec("gzip -l /root/$arf | grep -v compressed | awk '{ print $2 }'");
							echo "<tr>";
							echo "<td  class='listlr' width='50%' colspan='1'>";
							echo "<input type='radio' name='restorefile' value='$arf' /> $arf";
							echo "</td>";
							echo "<td  class='listr' width='30%' colspan='1'>";
							echo date ("F d Y H:i:s", filemtime($arf));
							echo "</td>";
							echo "<td  class='listr' width='40%' colspan='1'>";
							echo format_bytes($size);
							echo "</td>";
							echo "<td  class='listr nowrap' width='20%' colspan='1'>";
							echo "<a onclick=\"return confirm('" . gettext("Do you really want to delete this backup?") . "')\" href='system_firmware_restorefullbackup.php?deletefile=" . htmlspecialchars($arf) . "'>";
							echo gettext("Delete");
							echo "</a> | ";
							echo "<a href='system_firmware_restorefullbackup.php?downloadbackup=" . htmlspecialchars($arf) . "'>";
							echo gettext("Download");
							echo "</a>";
							echo "</td>";
							echo "</tr>";
						}
						if($counter == 0) {
							echo "<tr>";
							echo "<td  class='listlr' width='100%' colspan='4' align='center'>";
							echo gettext("Could not locate any previous backups.");
							echo "</td>";
							echo "</tr>";
						}
169
                                ?>
170 171 172 173 174 175 176 177 178
						<tr>
							<td width="78%" colspan="3">
								&nbsp;<br />
								<input type="checkbox" name="overwriteconfigxml" id="overwriteconfigxml" checked="checked" /> <?=gettext("do not restore config.xml."); ?>
								<br />
								<input name="Restore" type="submit" class="btn btn-primary" id="restore" value="<?=gettext("Restore"); ?>" />
							</td>
						</tr>

179
                            </tbody>
180 181

				</table>
182 183 184 185 186 187 188
                    </form>

                </div>
            </section>
        </div>
	</div>
</section>
Ad Schellevis's avatar
Ad Schellevis committed
189 190 191 192 193 194 195 196

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

197
<?php include("foot.inc"); ?>
Ad Schellevis's avatar
Ad Schellevis committed
198

199
<?php
Ad Schellevis's avatar
Ad Schellevis committed
200 201 202
if (is_subsystem_dirty('restore'))
	system_reboot();
?>