$backupjobs = json_decode(file_get_contents($config['path'] . '/db/db-backupjobs.json'), true); $backupservers = json_decode(file_get_contents($config['path'] . '/db/db-backupservers.json'), true); function GetBackupDetails($backupdata) { global $backups; foreach ($backups as $backup) { if ($backup['file'] == $backupdata) { return $backup; } } return false; } $backupdetail = GetBackupDetails($_GET['id']); function GetJobDetails($jobid) { global $backupjobs; foreach ($backupjobs as $backupjob) { if ($backupjob['id'] == $jobid) { return $backupjob; } } return false; } $jobdetail = GetJobDetails($backupdetail['id']); $smarty->assign('backupservers', $backupservers); $smarty->assign('backupdetail', $backupdetail); $smarty->assign('jobdetail', $jobdetail); $smarty->display($config['path'] . '/templates/header.tpl'); $smarty->display($config['path'] . '/templates/backuprestore.tpl'); $smarty->display($config['path'] . '/templates/footer.tpl'); }
return $backupjob; } } return false; } function GetServerDetails($host) { global $backupservers; foreach ($backupservers as $backupserver) { if ($backupserver['host'] == $host) { return $backupserver; } } return false; } $backupjob = GetJobDetails($argv[1]); if (!$backupjob) { $log .= 'Job ID does not exist' . PHP_EOL; exitcron(); } $backupserver = GetServerDetails($backupjob['source']); if (!$backupserver) { $log .= 'Server does not exist' . PHP_EOL; exitcron(); } if ($backupjob['type'] == 'full' || $backupjob['type'] == 'incremental') { $log .= 'Starting file backup' . PHP_EOL; set_include_path($config['path'] . '/libs/phpseclib'); include 'Net/SSH2.php'; include 'Net/SFTP.php'; include 'Crypt/RSA.php';
} } return false; } function GetJobDetails($jobid) { global $backupjobs; foreach ($backupjobs as $backupjob) { if ($backupjob['id'] == $jobid) { return $backupjob; } } return false; } $backup = GetBackupDetails($_REQUEST['id']); $backupjob = GetJobDetails($backup['id']); header('Content-Disposition: attachment; filename="' . basename($_REQUEST['id']) . '"'); set_include_path($config['path'] . '/libs/phpseclib'); include 'Crypt/AES.php'; $cipher = new Crypt_AES(CRYPT_AES_MODE_ECB); $cipher->setKey($backupjob['encryptionkey']); echo $cipher->decrypt(file_get_contents($config['path'] . '/files/' . $_REQUEST['id'])); logevent('User ' . $_SESSION['user'] . ' downloaded decrypted backup ' . $_REQUEST['id'], 'activity'); } else { echo 'File not found'; } } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'backupdelete' && isset($_REQUEST['id'])) { checkacl('deleteb'); if (file_exists($config['path'] . '/files/' . $_REQUEST['id'])) { if (unlink($config['path'] . '/files/' . $_REQUEST['id'])) { $backups = json_decode(file_get_contents($config['path'] . '/db/db-backups.json'), true);
$backups = json_decode(file_get_contents($config['path'] . '/db/db-backups.json'), true); $backups = array_reverse($backups); //reverse the array to make newest backups at the top $backupjobs = json_decode(file_get_contents($config['path'] . '/db/db-backupjobs.json'), true); $backupservers = json_decode(file_get_contents($config['path'] . '/db/db-backupservers.json'), true); function GetJobDetails($jobid) { global $backupjobs; foreach ($backupjobs as $backupjob) { if ($backupjob['id'] == $jobid) { return $backupjob; } } return false; } $backupjob = GetJobDetails($_GET['id']); $smarty->display($config['path'] . '/templates/header.tpl'); echo '<div class="container"><h2>View Backups</h2>'; if ($backupjob['encryption'] == 'AES-256') { echo '<div class="alert alert-info">It may take a little longer to download decrypted files, please be patient!</div>'; } echo '<table class="table table-striped table-bordered">'; echo '<tr><th>File</th><th>Size</th><th>Time</th><th>Actions</th>'; foreach ($backups as $backup) { if (isset($_GET['id']) && $_GET['id'] == $backup['id']) { echo '<tr><td>' . $backup['file'] . '</td>'; echo '<td>' . formatBytes($backup['size']) . '</td>'; echo '<td>' . date("Y-m-d H:i:s", $backup['time']) . '</td>'; echo '<td><a href="index.php?action=backupdownload&id=' . $backup['file'] . '" class="btn btn-success">Download</a> '; if ($backupjob['encryption'] == 'AES-256') { echo '<a href="index.php?action=backupdownloaddecrypt&id=' . $backup['file'] . '" class="btn btn-success">Download (Decrypted)</a> ';