Skip to content

Commit

Permalink
Fixed service name display issue. Added usemail option for PHP mail()…
Browse files Browse the repository at this point in the history
… support. Fixed block display in restore shell. Added stats shell command. Improved stats display.
  • Loading branch information
cubiclesoft committed Mar 30, 2016
1 parent 4067ff6 commit ebe37e4
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 25 deletions.
3 changes: 3 additions & 0 deletions backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
$incrementals = $result["incrementals"];
$lastbackupid = $result["summary"]["lastbackupid"];

$services = CB_GetBackupServices();
if (isset($services[$servicename])) $servicename = $services[$servicename];

// Merge down incrementals.
while (count($incrementals) > $config["numincrementals"] + 1)
{
Expand Down
34 changes: 24 additions & 10 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,35 @@ function SetupPaths($configkey, $pathsstr, $checkpaths = true)
$from = trim(fgets(STDIN));
echo "Subject line (e.g. [Backup] Some computer name): ";
$subject = trim(fgets(STDIN));
echo "SMTP server (without port): ";
$server = trim(fgets(STDIN));
echo "SMTP port (usually 25, 465, or 587): ";
$port = (int)trim(fgets(STDIN));
echo "SMTP over SSL/TLS (Y/N): ";
$secure = (substr(strtoupper(trim(fgets(STDIN))), 0, 1) == "Y");
echo "SMTP username (optional): ";
$username = trim(fgets(STDIN));
echo "SMTP password (optional): ";
$password = trim(fgets(STDIN));
echo "PHP mail() command (Y/N): ";
$usemail = (substr(strtoupper(trim(fgets(STDIN))), 0, 1) == "Y");
if ($usemail)
{
$server = "";
$port = 25;
$secure = false;
$username = "";
$password = "";
}
else
{
echo "SMTP server (without port): ";
$server = trim(fgets(STDIN));
echo "SMTP port (usually 25, 465, or 587): ";
$port = (int)trim(fgets(STDIN));
echo "SMTP over SSL/TLS (Y/N): ";
$secure = (substr(strtoupper(trim(fgets(STDIN))), 0, 1) == "Y");
echo "SMTP username (optional): ";
$username = trim(fgets(STDIN));
echo "SMTP password (optional): ";
$password = trim(fgets(STDIN));
}

$data = array(
"filter" => $filter,
"from" => $from,
"subject" => $subject,
"usemail" => $usemail,
"server" => $server,
"port" => $port,
"secure" => $secure,
Expand Down
3 changes: 3 additions & 0 deletions restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
$incrementaltimes = $result["summary"]["incrementaltimes"];
$lastbackupid = $result["summary"]["lastbackupid"];

$services = CB_GetBackupServices();
if (isset($services[$servicename])) $servicename = $services[$servicename];

function CleanupCache()
{
global $rootpath;
Expand Down
69 changes: 55 additions & 14 deletions restore_shell_exts/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function shell_cmd_ls($line)
else $attr .= "-";

// Output: Attributes Owner Group Created Filesize[ Blocknum]
echo $attr . " " . sprintf("%-" . $maxowner . "s", $info["owner"]) . " " . sprintf("%-" . $maxgroup . "s", $info["group"]) . " " . sprintf("%" . $maxfullsize . "s", number_format($info["filesize"], 0)) . ($blocks ? " " . $info["blocknum"] : "") . " " . date("Y-M-d h:i A", $info["created"]) . " ";
echo $attr . " " . sprintf("%-" . $maxowner . "s", $info["owner"]) . " " . sprintf("%-" . $maxgroup . "s", $info["group"]) . " " . sprintf("%" . $maxfullsize . "s", number_format($info["filesize"], 0)) . ($blocks ? " " . sprintf("%" . $maxblocknumsize . "s", $info["blocknum"]) : "") . " " . date("Y-M-d h:i A", $info["created"]) . " ";
}

echo $name;
Expand Down Expand Up @@ -268,24 +268,65 @@ function shell_cmd_chdir($line)
shell_cmd_cd($line);
}

function shell_cmd_restore($line)
function shell_cmd_stats($line)
{
global $rootpath, $blocklist, $servicehelper, $config, $cb_messages;
global $db;

if (is_array($line)) $args = $line;
else
$options = array(
"shortmap" => array(
"?" => "help"
),
"rules" => array(
"help" => array("arg" => false)
)
);
$args = ParseCommandLine($options, $line);

if (count($args["params"]) > 0 || isset($args["opts"]["help"]))
{
$options = array(
"shortmap" => array(
"?" => "help"
),
"rules" => array(
"help" => array("arg" => false)
)
);
$args = ParseCommandLine($options, $line);
echo $args["file"] . " - Stats command\n";
echo "Purpose: Display database-wide statistics.\n";
echo "\n";
echo "Syntax: " . $args["file"] . " [options]\n";
echo "Options:\n";
echo "\t-? This help documentation.\n";
echo "\n";
echo "Example: " . $args["file"] . " /\n";

return;
}

$numfiles = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum > 0 AND sharedblock = 0"), "files");
$numsharedfiles = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum > 0 AND sharedblock = 1"), "files");
$numsharedblocks = (int)$db->GetOne("SELECT", array("COUNT(DISTINCT blocknum)", "FROM" => "?", "WHERE" => "blocknum > 0 AND sharedblock = 1"), "files");
$numemptyfiles = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum = 0 AND sharedblock = 1"), "files");
$numsymlinks = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum = 0 AND sharedblock = 0 AND symlink <> ''"), "files");
$numdirs = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum = 0 AND sharedblock = 0 AND symlink = ''"), "files");

echo "Symlinks: " . number_format($numsymlinks, 0) . "\n";
echo "Folders: " . number_format($numdirs, 0) . "\n";
echo "Files:\n";
echo "\t" . number_format($numsharedfiles, 0) . " shared (" . number_format($numsharedblocks, 0) . " blocks)\n";
echo "\t" . number_format($numfiles, 0) . " non-shared\n";
echo "\t" . number_format($numemptyfiles, 0) . " empty\n";
echo "\t" . number_format($numsharedfiles + $numfiles + $numemptyfiles, 0) . " total (" . number_format($numsharedblocks + $numfiles, 0) . " blocks)\n";
echo "\n";
}

function shell_cmd_restore($line)
{
global $rootpath, $blocklist, $servicehelper, $config, $cb_messages;

$options = array(
"shortmap" => array(
"?" => "help"
),
"rules" => array(
"help" => array("arg" => false)
)
);
$args = ParseCommandLine($options, $line);

if (count($args["params"]) > 1 || isset($args["opts"]["help"]))
{
echo $args["file"] . " - Restore command\n";
Expand Down
1 change: 1 addition & 0 deletions support/cb_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function CB_SendNotificationEmail($notificationinfo, $htmlmsg, $textmsg)
"headers" => $headers,
"htmlmessage" => $htmlmsg,
"textmessage" => $textmsg,
"usemail" => $notificationinfo["usemail"],
"server" => $notificationinfo["server"],
"port" => $notificationinfo["port"],
"secure" => $notificationinfo["secure"],
Expand Down
3 changes: 3 additions & 0 deletions test_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
$servicename = $result["servicename"];
$service = $result["service"];

$services = CB_GetBackupServices();
if (isset($services[$servicename])) $servicename = $services[$servicename];

echo "Testing " . $servicename . "...\n";
$service->Test();

Expand Down
7 changes: 6 additions & 1 deletion verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,18 @@ function CleanupCache()
echo "\tRetrieving files database statistics...\n";
$numfiles = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum > 0 AND sharedblock = 0"), "files");
$numsharedfiles = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum > 0 AND sharedblock = 1"), "files");
$numsharedblocks = (int)$db->GetOne("SELECT", array("COUNT(DISTINCT blocknum)", "FROM" => "?", "WHERE" => "blocknum > 0 AND sharedblock = 1"), "files");
$numemptyfiles = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum = 0 AND sharedblock = 1"), "files");
$numsymlinks = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum = 0 AND sharedblock = 0 AND symlink <> ''"), "files");
$numdirs = (int)$db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "blocknum = 0 AND sharedblock = 0 AND symlink = ''"), "files");

echo "\tSymlinks: " . number_format($numsymlinks, 0) . "\n";
echo "\tFolders: " . number_format($numdirs, 0) . "\n";
echo "\tFiles: " . number_format($numsharedfiles, 0) . " shared, " . number_format($numfiles, 0) . " non-shared, " . number_format($numemptyfiles, 0) . " empty, " . number_format($numsharedfiles + $numfiles + $numemptyfiles, 0) . " total\n";
echo "\tFiles:\n";
echo "\t\t" . number_format($numsharedfiles, 0) . " shared (" . number_format($numsharedblocks, 0) . " blocks)\n";
echo "\t\t" . number_format($numfiles, 0) . " non-shared\n";
echo "\t\t" . number_format($numemptyfiles, 0) . " empty\n";
echo "\t\t" . number_format($numsharedfiles + $numfiles + $numemptyfiles, 0) . " total (" . number_format($numsharedblocks + $numfiles, 0) . " blocks)\n";

// Verify that all blocks in the database are in the block list.
echo "\tRetrieving all unique blocks in the database...\n";
Expand Down

0 comments on commit ebe37e4

Please sign in to comment.