summaryrefslogtreecommitdiffstats
path: root/usr/local/www/diag_backup.php
diff options
context:
space:
mode:
authorDarren Embry <dse@webonastick.com>2012-05-17 15:16:12 -0400
committerDarren Embry <dse@webonastick.com>2012-05-17 15:16:12 -0400
commit0887774669e272c1a0825af4548ac7edb445e40a (patch)
treec25f9aa21ec0418e6c5e294fd809356e2a6746fd /usr/local/www/diag_backup.php
parent7a865f0344009b3b5b675d7e8ea7e277a1550a0f (diff)
downloadpfsense-0887774669e272c1a0825af4548ac7edb445e40a.zip
pfsense-0887774669e272c1a0825af4548ac7edb445e40a.tar.gz
restore_rrddata() adds log_error calls and uses -f
Diffstat (limited to 'usr/local/www/diag_backup.php')
-rwxr-xr-xusr/local/www/diag_backup.php39
1 files changed, 27 insertions, 12 deletions
diff --git a/usr/local/www/diag_backup.php b/usr/local/www/diag_backup.php
index efb6a58..9f08117 100755
--- a/usr/local/www/diag_backup.php
+++ b/usr/local/www/diag_backup.php
@@ -84,35 +84,50 @@ function rrd_data_xml() {
function restore_rrddata() {
global $config, $g, $rrdtool, $input_errors;
-
- log_error("restore_rrddata has been called.");
foreach($config['rrddata']['rrddatafile'] as $rrd) {
if ($rrd['xmldata']) {
- log_error("rrd contains xmldata.");
$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
- log_error("\$xml_file = \"$xml_file\"");
- log_error("\$rrd_file = \"$rrd_file\"");
- file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata'])));
- exec("$rrdtool restore '{$xml_file}' '{$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 failed returning $status");
+ continue;
+ }
unlink($xml_file);
}
else if ($rrd['data']) {
- log_error("rrd contains (non-xml) data.");
$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
- log_error("\$rrd_file = \"$rrd_file\"");
$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 */
- fwrite($rrd_fd, $dcomp);
+ 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 */
- fwrite($rrd_fd, $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;
}
- fclose($rrd_fd);
}
}
}
OpenPOWER on IntegriCloud