[Box Backup] running bbackupquery in a browser
Jarkko Haapalainen
boxbackup@fluffy.co.uk
Thu, 28 Feb 2008 10:30:34 +0200
--Apple-Mail-4-394451532
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
Hi Dave,
I made quick version of mine for browsing and restoring files from
browser so look at the attached file. It only took ~1,5 hours so there
is probably bugs, but is working nicely for me in my mac ;)
Best regards, Jarkko
--Apple-Mail-4-394451532
Content-Disposition: attachment;
filename=test.php
Content-Type: text/php;
x-unix-mode=0644;
name="test.php"
Content-Transfer-Encoding: 7bit
<?php
$bquery = 'sudo /usr/local/bin/bbackupquery';
$chown = 'sudo /usr/sbin/chown _www';
$tmpdir = '/tmp';
function path_to_arr($bquery, $path = null) {
$cmd = sprintf('%s \'list -t "%s"\' quit', $bquery, rawurldecode($path));
$out = shell_exec($cmd);
preg_match_all('/^(\w{8})\s(\D{6})\s(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})\s([^\n]*)\n/m', $out, $matches, PREG_SET_ORDER);
return array('path' => $path, 'files' => $matches);
}
function arr_to_html($m) {
$html = '';
$path = $m['path'];
foreach ($m['files'] as $object) {
list ($line, $id, $flags, $datetime, $name) = $object;
if (strpos($flags, 'd') === 1) {
$link = sprintf('<a href="?cwd=%s">%s</a>', "$path/$name", $name);
} else {
$link = sprintf('<a href="?cwd=%s&get=%s&name=%s">%s</a>', "$path", $id, $name, $name);
}
$html .= "<tr><td>$id</td><td>$flags</td><td>$datetime</td><td>$link</td></tr>";
}
return $html;
}
function get_file($bquery, $chown, $tmpdir, $path, $file, $filename) {
$new = "$tmpdir/".md5($file);
$cmd = sprintf('%s \'cd "%s"\' \'get -i %s %s\' quit', $bquery, rawurldecode($path), rawurldecode($file), $new);
$out = shell_exec($cmd);
if (file_exists($new)) {
exec("$chown '$new'");
$fp = fopen($new, 'rb');
header("Pragma: public");
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header("Cache-Control: private",false);
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".rawurldecode(utf8_decode($filename))."\"");
header("Content-Length: " . filesize($new));
fpassthru($fp);
unlink($new);
exit;
} else {
echo "<pre>ERROR: file restore failed\n";
var_dump($cmd, $path, $file);
echo "</pre>";
}
}
if (!empty($_GET['get'])) {
get_file($bquery, $chown, $tmpdir, $_GET['cwd'], $_GET['get'], $_GET['name']);
exit;
}
?>
<html>
<head>
<title>bbackupquery wrapper</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style>
html, body {
font-family: verdana;
}
table.list thead td {
border-bottom: 1px solid #aaa;
}
table.list tbody td {
padding: 4px 6px 4px 6px;
border-right: 1px solid #aaa;
border-bottom: 1px solid #aaa;
}
</style>
</head>
<body>
<table class="list">
<thead>
<tr>
<td>id</td>
<td>flags</td>
<td>datetime</td>
<td>name</td>
</tr>
</thead>
<tbody>
<?= arr_to_html( path_to_arr($bquery, $_GET['cwd']) ); ?>
</tbody>
</table>
</body>
</html>
--Apple-Mail-4-394451532
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
Dave Bamford kirjoitti 27.2.2008 kello 22.00:
> I had a look at the Ruby on Rails at the time, but I don't think the
> source was available.
>
> I am looking for a quick and easy way of browsing and recovering files
> and I got stuck as to why I got the error. Its probably PHP related,
> perhaps
> I ought to try a PHP mailing list.
> I suspect I need some PHP code, maybe stream functions, to handle
> the file IO
> from bbackupquery, but it is way beyond me.
> Tried exec system and shell_exec. Had a look at the docs on popen
> but...
>
> Perhaps I need to set some environment variables.
>
> Dave Bamford
>
>
> _______________________________________________
> boxbackup mailing list
> boxbackup@fluffy.co.uk
> http://lists.warhead.org.uk/mailman/listinfo/boxbackup
>
--Apple-Mail-4-394451532--