Improved backup functionality. Thanks monotek, refs #186
This commit is contained in:
@@ -36,7 +36,9 @@ return array(
|
||||
'settinggroup' => 'system',
|
||||
'varname' => 'backup_dir',
|
||||
'type' => 'string',
|
||||
'default' => '#froxlor_backup',
|
||||
'string_type' => 'dir',
|
||||
'default' => '/var/customers/backups/',
|
||||
'string_regexp' => '/^/.*/$/',
|
||||
'save_method' => 'storeSettingField',
|
||||
),
|
||||
'backup_mysqldump_path' => array(
|
||||
|
||||
@@ -49,7 +49,7 @@ elseif($page == 'accounts')
|
||||
'homedir' => $lng['panel']['path']
|
||||
);
|
||||
$paging = new paging($userinfo, $db, TABLE_FTP_USERS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']);
|
||||
$result = $db->query("SELECT `id`, `username`, `homedir` FROM `" . TABLE_FTP_USERS . "` WHERE `customerid`='" . $userinfo['customerid'] . "' " . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit());
|
||||
$result = $db->query("SELECT `id`, `username`, `homedir` FROM `" . TABLE_FTP_USERS . "` WHERE `customerid`='" . $userinfo['customerid'] . "' AND `username` NOT LIKE '%_backup'" . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit());
|
||||
$paging->setEntries($db->num_rows($result));
|
||||
$sortcode = $paging->getHtmlSortCode($lng);
|
||||
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);
|
||||
@@ -312,6 +312,11 @@ elseif($page == 'accounts')
|
||||
{
|
||||
$log->logAction(USR_ACTION, LOG_INFO, "updated ftp-account password for '" . $result['username'] . "'");
|
||||
$db->query("UPDATE `" . TABLE_FTP_USERS . "` SET `password`=ENCRYPT('" . $db->escape($password) . "') WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
|
||||
|
||||
// also update customers backup user password if password of main ftp user is changed
|
||||
if(!preg_match('/' . $settings['customer']['ftpprefix'] . '/', $result['username'])){
|
||||
$db->query("UPDATE `" . TABLE_FTP_USERS . "` SET `password`=ENCRYPT('" . $db->escape($password) . "') WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `username`='" . $result['username'] . "_backup'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -622,7 +622,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('syste
|
||||
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('panel', 'default_theme', 'Froxlor');
|
||||
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'validate_domain', '1');
|
||||
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_enabled', '1');
|
||||
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_dir', '#froxlor_backup');
|
||||
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_dir', '/var/customers/backups/');
|
||||
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_mysqldump_path', '/usr/bin/mysqldump');
|
||||
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_count', '1');
|
||||
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'backup_bigfile', '1');
|
||||
|
||||
@@ -1634,3 +1634,14 @@ if(isFroxlorVersion('0.9.21'))
|
||||
|
||||
updateToVersion('0.9.22-svn1');
|
||||
}
|
||||
|
||||
if(isFroxlorVersion('0.9.21-svn1'))
|
||||
{
|
||||
showUpdateStep("Updating from 0.9.22-svn1 to 0.9.22-svn2");
|
||||
lastStepStatus(0);
|
||||
|
||||
/* add new settings for diskspacequota - support */
|
||||
$db->query("UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = '/var/customers/backups/' WHERE `varname` = 'backup_dir';");
|
||||
|
||||
updateToVersion('0.9.22-svn2');
|
||||
}
|
||||
@@ -1423,7 +1423,7 @@ $lng['serversettings']['mail_also_with_mxservers'] = 'Create mail-, imap-, pop3-
|
||||
$lng['aps']['nocontingent'] = 'Your APS contingent is insufficient. You cannot install any package.';
|
||||
$lng['aps']['packageneedsdb'] = 'This package needs a database but your contingent is used up';
|
||||
$lng['aps']['cannoteditordeleteapsdb'] = 'APS databases cannot be edited or removed here';
|
||||
$lng['admin']['webserver_user'] = 'Webserver user-name';
|
||||
$lng['admin']['webserver_Puser'] = 'Webserver user-name';
|
||||
$lng['admin']['webserver_group'] = 'Webserver group-name';
|
||||
|
||||
// ADDED IN FROXLOR 0.9.10
|
||||
@@ -1606,13 +1606,13 @@ $lng['error']['admin_domain_emailsystemhostname'] = 'Sorry, the system - hostnam
|
||||
$lng['backup'] = 'Backup';
|
||||
$lng['backup_allowed'] = 'Backup allowed';
|
||||
$lng['extras']['backup_create'] = 'Create Backup?';
|
||||
$lng['extras']['backup_info'] = 'Backup will be saved once daily in directory "' . $settings['system']['backup_dir'] . '".';
|
||||
$lng['extras']['backup_info'] = 'Backup will be saved once daily to a FTP directory. The FTP username is "'. $userinfo['loginname'] .'_backup". The FTP password is the same as for your main FTP account.';
|
||||
$lng['extras']['backup_info_sep'] = 'It contains compressed archives of your web-directory and databases.';
|
||||
$lng['extras']['backup_info_big'] = 'It contains a compressed archive of your web-directory and databases.';
|
||||
$lng['extras']['backup_count_info'] = '<br /><br />Please note that the backup will charge your webspace!';
|
||||
$lng['serversettings']['backup_count'] = 'Should backup size be subtracted from webspace size?';
|
||||
$lng['serversettings']['backup_enabled'] = 'Backup activated?';
|
||||
$lng['serversettings']['backupdir']['description'] = 'Which name should the customer\'s backup directory have?';
|
||||
$lng['serversettings']['backupdir']['description'] = 'Backup dir path?';
|
||||
$lng['serversettings']['mysqldump_path']['description'] = 'Path to mysqldump binary?';
|
||||
$lng['serversettings']['backup_bigfile'] = 'Save backup in 1 big file instead in separeted files for html and databases?';
|
||||
$lng['serversettings']['backup_ftp_enabled'] = 'FTP Upload activated?';
|
||||
|
||||
@@ -1586,9 +1586,9 @@ $lng['error']['admin_domain_emailsystemhostname'] = 'Der System - Hostname kann
|
||||
$lng['backup'] = 'Backup';
|
||||
$lng['backup_allowed'] = 'Backup erlaubt';
|
||||
$lng['extras']['backup_create'] = 'Backup erstellen?';
|
||||
$lng['extras']['backup_info'] = 'Das Backup wird täglich im Ordner "' . $settings['system']['backup_dir'] . '" abgelegt.';
|
||||
$lng['extras']['backup_info_sep'] = 'Es sind komprimierte Archive von Ihrem Webverzeichnis und Datenbanken enthalten.';
|
||||
$lng['extras']['backup_info_big'] = 'Es ist ein komprimiertes Archiv von Ihrem Webverzeichnis und Datenbanken enthalten.';
|
||||
$lng['extras']['backup_info'] = 'Das Backup wird täglich in einem FTP Verzeichnis abgelegt. Der FTP Username ist "' . $userinfo['loginname'] . '_backup". Das FTP Passwort ist das gleiche wie bei ihrem Haupt FTP Account.';
|
||||
$lng['extras']['backup_info_sep'] = 'Es sind komprimierte Archive von Ihrem Webverzeichnis und Ihren Datenbanken enthalten.';
|
||||
$lng['extras']['backup_info_big'] = 'Es ist ein komprimiertes Archiv von Ihrem Webverzeichnis und Ihren Datenbanken enthalten.';
|
||||
$lng['extras']['backup_count_info'] = '<br /><br />Beachten Sie bitte, dass das Backup den verfügbaren Speicherplatz belastet!';
|
||||
$lng['serversettings']['backup_count'] = 'Soll die Größe des Backups vom verfügbaren Webspace-Limit abgezogen werden?';
|
||||
$lng['serversettings']['backup_enabled'] = 'Backup aktivieren?';
|
||||
@@ -1596,7 +1596,7 @@ $lng['serversettings']['backup_ftp_enabled'] = 'FTP Upload aktivieren?';
|
||||
$lng['serversettings']['backup_ftp_server'] = 'FTP Server:';
|
||||
$lng['serversettings']['backup_ftp_user'] = 'FTP Benutzer:';
|
||||
$lng['serversettings']['backup_ftp_pass'] = 'FTP Passwort:';
|
||||
$lng['serversettings']['backupdir']['description'] = 'Welchen Namen soll das Backup Verzeichnis des Kunden haben?';
|
||||
$lng['serversettings']['backupdir']['description'] = 'Pfad des Backup Verzeichnises?';
|
||||
$lng['serversettings']['mysqldump_path']['description'] = 'Pfad zum mysqldump Programm:';
|
||||
$lng['serversettings']['backup_count'] = 'Soll die Größe des Backups vom verfügbaren Webspace abgezogen werden?';
|
||||
$lng['crondesc']['cron_backup'] = 'Backup Cronjob';
|
||||
|
||||
@@ -29,71 +29,43 @@ if($settings['system']['backup_enabled'] == '1'){
|
||||
|
||||
fwrite($debugHandler, 'backup customers started...' . "\n");
|
||||
|
||||
$result = $db->query("SELECT customerid, loginname, guid, documentroot, backup_allowed, backup_enabled FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC");
|
||||
$result = $db->query("SELECT customerid, loginname, guid, documentroot, backup_allowed, backup_enabled FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC;");
|
||||
while($row = $db->fetch_array($result)){
|
||||
fwrite($debugHandler, 'backup for ' . $row['loginname'] . ' started...' . "\n");
|
||||
|
||||
// create webserver backup directory access protection
|
||||
$backupprotectfile = $settings['system']['apacheconf_diroptions'] . '50_froxlor_diroption_' . md5($row['documentroot'] . $settings['system']['backup_dir']) . '.conf';
|
||||
$fh = fopen($backupprotectfile, 'w');
|
||||
if($settings['system']['webserver'] == 'apache2'){
|
||||
$filedata = '# ' . basename($backupprotectfile) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" .
|
||||
'# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n\n" .
|
||||
'<Directory "' . $row['documentroot'] . $settings['system']['backup_dir'] . '/">' . "\n" .
|
||||
' deny from all' . "\n" .
|
||||
'</Directory>' . "\n";
|
||||
}
|
||||
elseif($settings['system']['webserver'] == 'lighttpd'){
|
||||
$filedata = '# ' . basename($backupprotectfile) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" .
|
||||
'# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n\n" .
|
||||
'$PHYSICAL["path"] !~ "^' . $row['documentroot'] . $settings['system']['backup_dir'] . '/$" {' . "\n" .
|
||||
' access.deny-all = "enable"' . "\n" .
|
||||
'}' . "\n";
|
||||
}
|
||||
elseif($settings['system']['webserver'] == 'nginx'){
|
||||
$filedata = '# ' . basename($backupprotectfile) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" .
|
||||
'# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n\n" .
|
||||
'location ' . $row['documentroot'] . $settings['system']['backup_dir'] . ' {' . "\n" .
|
||||
' deny all;' . "\n" .
|
||||
' return 403;' . "\n" .
|
||||
'}' . "\n";
|
||||
}
|
||||
fwrite($fh, $filedata);
|
||||
fclose($fh);
|
||||
|
||||
// backup
|
||||
if($row['backup_allowed'] == '1' && $row['backup_enabled'] == '1'){
|
||||
// get uid & gid from ftp table
|
||||
$ftp_result = $db->query("SELECT uid, gid FROM `" . TABLE_FTP_USERS . "` WHERE `username` = '" . $db->escape($row['loginname']) . "'");
|
||||
$ftp_result = $db->query("SELECT uid, gid FROM `" . TABLE_FTP_USERS . "` WHERE `username` = '" . $db->escape($row['loginname']) . "';");
|
||||
$ftp_row = mysql_fetch_array($ftp_result);
|
||||
|
||||
// create backup dir an set rights
|
||||
if(!file_exists($row['documentroot'] . $settings['system']['backup_dir'])){
|
||||
safe_exec('install -d ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . ' -o ' . escapeshellarg($ftp_row['uid']) . ' -g ' . escapeshellarg($ftp_row['gid']) . ' -m ' . '0500');
|
||||
safe_exec('install -d ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . ' -o ' . escapeshellarg($ftp_row['uid']) . ' -g ' . escapeshellarg($ftp_row['gid']) . ' -m ' . '0500');
|
||||
}
|
||||
|
||||
// create customers html backup
|
||||
safe_exec('tar --exclude=' . escapeshellarg($settings['system']['backup_dir']) . ' -C ' . escapeshellarg($row['documentroot']) . ' -c -z -f ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/' . escapeshellarg($row['loginname']) . 'html.tar.gz .');
|
||||
safe_exec('tar -C ' . escapeshellarg($row['documentroot']) . ' -c -z -f ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/' . escapeshellarg($row['loginname']) . 'html.tar.gz .');
|
||||
|
||||
// get customer dbs
|
||||
$dbs_result = $db->query("SELECT databasename FROM `" . TABLE_PANEL_DATABASES . "` WHERE `customerid` = '" . $db->escape($row['customerid']) . "'");
|
||||
$dbs_result = $db->query("SELECT databasename FROM `" . TABLE_PANEL_DATABASES . "` WHERE `customerid` = '" . $db->escape($row['customerid']) . "';");
|
||||
while($dbs_row = $db->fetch_array($dbs_result)){
|
||||
// create customers sql backup
|
||||
safe_exec(escapeshellarg($settings['system']['backup_mysqldump_path']) . ' --opt --allow-keywords -u ' . $sql_root[0]['user'] . ' -p' . $sql_root[0]['password'] . ' -h ' . $sql_root[0]['host'] . ' ' . escapeshellarg($dbs_row['databasename']) . ' -r ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/' . escapeshellarg($dbs_row['databasename']) . '.sql' );
|
||||
safe_exec(escapeshellarg($settings['system']['backup_mysqldump_path']) . ' --opt --allow-keywords -u ' . $sql_root[0]['user'] . ' -p' . $sql_root[0]['password'] . ' -h ' . $sql_root[0]['host'] . ' ' . escapeshellarg($dbs_row['databasename']) . ' -r ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/' . escapeshellarg($dbs_row['databasename']) . '.sql' );
|
||||
// compress sql backup
|
||||
safe_exec('tar -C ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . ' -c -z -f ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/' . escapeshellarg($dbs_row['databasename']) . '.tar.gz ' . escapeshellarg($dbs_row['databasename']) . '.sql');
|
||||
safe_exec('tar -C ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . ' -c -z -f ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/' . escapeshellarg($dbs_row['databasename']) . '.tar.gz ' . escapeshellarg($dbs_row['databasename']) . '.sql');
|
||||
// remove uncompresed sql files
|
||||
safe_exec('rm ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/' . escapeshellarg($dbs_row['databasename']) . '.sql');
|
||||
safe_exec('rm ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/' . escapeshellarg($dbs_row['databasename']) . '.sql');
|
||||
}
|
||||
|
||||
// create 1 big file with html & db
|
||||
if($settings['system']['backup_bigfile'] == 1){
|
||||
safe_exec('tar -C ' . escapeshellarg($row['documentroot'] . $settings['system']['backup_dir']) . ' --exclude=' . escapeshellarg($row['loginname']) . '.tar.gz -c -z -f ' . escapeshellarg($row['documentroot'] . $settings['system']['backup_dir']) . '/' . escapeshellarg($row['loginname']) . '.tar.gz .');
|
||||
safe_exec('tar -C ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/' . ' --exclude=' . escapeshellarg($row['loginname']) . '.tar.gz -c -z -f ' . $settings['system']['backup_dir'] . $row['loginname'] . '/' . escapeshellarg($row['loginname']) . '.tar.gz .');
|
||||
// remove separated files
|
||||
$tmp_files = scandir($row['documentroot'] . $settings['system']['backup_dir']);
|
||||
$tmp_files = scandir($settings['system']['backup_dir'] . $row['loginname']);
|
||||
foreach ($tmp_files as $tmp_file){
|
||||
if(preg_match('/.*(html|sql|aps).*\.tar\.gz$/', $tmp_file) && !preg_match('/^' . $row['loginname'] . '\.tar\.gz$/', $tmp_file)){
|
||||
safe_exec('rm ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/' . $tmp_file . '');
|
||||
safe_exec('rm ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/' . $tmp_file . '');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,12 +81,17 @@ if($settings['system']['backup_enabled'] == '1'){
|
||||
}
|
||||
|
||||
// chown & chmod files to prevent manipulation
|
||||
safe_exec('chown ' . escapeshellarg($user) . ':' . escapeshellarg($group) . ' ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/' . '*');
|
||||
safe_exec('chmod 0400 ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/*');
|
||||
safe_exec('chown ' . escapeshellarg($user) . ':' . escapeshellarg($group) . ' ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/*');
|
||||
safe_exec('chmod 0400 ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/*');
|
||||
|
||||
// create ftp backup user
|
||||
$user_result = $db->query("SELECT username, password FROM `" . TABLE_FTP_USERS . "` WHERE `customerid` = '" . $db->escape($row['customerid']) . "' AND `username` = '" . $db->escape($row['loginname']) . "';");
|
||||
$user_row = mysql_fetch_array($user_result);
|
||||
$db->query("REPLACE INTO `" . TABLE_FTP_USERS . "` (`customerid`, `username`, `password`, `homedir`, `login_enabled`, `uid`, `gid`) VALUES ('" . $db->escape($row['customerid']) . "', '" . $db->escape($row['loginname']) . "_backup', '" . $db->escape($user_row['password']) . "', '" . $db->escape($settings['system']['backup_dir']) . $db->escape($row['loginname']) . "/', 'y', '" . $db->escape($row['guid']) . "', '" . $db->escape($row['guid']) . "')");
|
||||
|
||||
if($settings['system']['backup_ftp_enabled'] == '1'){
|
||||
// upload backup to customers ftp server
|
||||
$ftp_files = scandir($row['documentroot'] . $settings['system']['backup_dir']);
|
||||
$ftp_files = scandir($settings['system']['backup_dir'] . $row['loginname']);
|
||||
foreach ($ftp_files as $ftp_file){
|
||||
if(preg_match('/.*\.tar\.gz$/', $ftp_file)){
|
||||
$ftp_con = ftp_connect($settings['system']['backup_ftp_server']);
|
||||
@@ -130,28 +107,27 @@ if($settings['system']['backup_enabled'] == '1'){
|
||||
ftp_pasv($ftp_con, false);
|
||||
}
|
||||
|
||||
$ftp_upload = ftp_put($ftp_con, $ftp_file, $row['documentroot'] . $settings['system']['backup_dir'] . "/" . $ftp_file, FTP_BINARY);
|
||||
$ftp_upload = ftp_put($ftp_con, $ftp_file, $settings['system']['backup_dir'] . $row['loginname'] . "/" . $ftp_file, FTP_BINARY);
|
||||
}
|
||||
}
|
||||
}
|
||||
fwrite($debugHandler, 'backup for ' . $row['loginname'] . ' finished...' . "\n");
|
||||
}
|
||||
|
||||
|
||||
// delete old backup data (deletes backup if customer or admin disables backup)
|
||||
elseif($row['backup_allowed'] == '0' || $row['backup_enabled'] == '0'){
|
||||
if (file_exists($row['documentroot'] . $settings['system']['backup_dir'] . '/')){
|
||||
$files = scandir($row['documentroot'] . $settings['system']['backup_dir']);
|
||||
if (file_exists($settings['system']['backup_dir'] . $row['loginname'] . '/')){
|
||||
$files = scandir($settings['system']['backup_dir'] . $row['loginname'] . '/');
|
||||
foreach ($files as $file){
|
||||
if(preg_match('/.*\.tar\.gz$/', $file)){
|
||||
safe_exec('rm ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/' . $file . '');
|
||||
safe_exec('rm ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '/' . $file . '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fwrite($debugHandler, 'backup customers finished...' . "\n");
|
||||
|
||||
//reload webserver to enable directory protection
|
||||
safe_exec(escapeshellcmd($settings['system']['apachereload_command']));
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -296,6 +296,20 @@ while($row = $db->fetch_array($result_tasks))
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: rm -rf ' . escapeshellarg($homedir));
|
||||
safe_exec('rm -rf '.escapeshellarg($homedir));
|
||||
}
|
||||
|
||||
/*
|
||||
* remove backup dir
|
||||
*/
|
||||
$backupdir = makeCorrectDir($settings['system']['backup_dir'] . $row['data']['loginname']);
|
||||
|
||||
if($backupdir != '/'
|
||||
&& $backupdir != $settings['system']['backup_dir']
|
||||
&& substr($backupdir, 0, strlen($settings['system']['backup_dir'])) == $settings['system']['backup_dir'])
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: rm -rf ' . escapeshellarg($backupdir));
|
||||
safe_exec('rm -rf '.escapeshellarg($backupdir));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* remove maildir
|
||||
@@ -404,63 +418,6 @@ while($row = $db->fetch_array($result_tasks))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE=9 Create backup dir protection (no download of backups via webserver)
|
||||
*/
|
||||
elseif ($row['type'] == '9')
|
||||
{
|
||||
|
||||
fwrite($debugHandler, ' cron_tasks: Task9 started - creating backup dir protection' . "\n");
|
||||
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task9 started - creating backup dir protection');
|
||||
|
||||
$result = $db->query("SELECT documentroot, backup_allowed, backup_enabled FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE 1");
|
||||
while($row = $db->fetch_array($result)){
|
||||
|
||||
if ($row['backup_allowed'] == '1' && $row['backup_enabled'] == '1'){
|
||||
|
||||
$backupprotectfile = $settings['system']['apacheconf_diroptions'] . '50_froxlor_diroption_' . md5($row['documentroot'] . $settings['system']['backup_dir']) . '.conf';
|
||||
$fh = fopen($backupprotectfile, 'w');
|
||||
|
||||
if($settings['system']['webserver'] == 'apache2'){
|
||||
$filedata = '# ' . basename($backupprotectfile) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" .
|
||||
'# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n\n" .
|
||||
'<Directory "' . $row['documentroot'] . $settings['system']['backup_dir'] . '/">' . "\n" .
|
||||
' deny from all' . "\n" .
|
||||
'</Directory>' . "\n";
|
||||
}
|
||||
elseif($settings['system']['webserver'] == 'lighttpd'){
|
||||
$filedata = '# ' . basename($backupprotectfile) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" .
|
||||
'# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n\n" .
|
||||
'$PHYSICAL["path"] !~ "^' . $row['documentroot'] . $settings['system']['backup_dir'] . '/$" {' . "\n" .
|
||||
' access.deny-all = "enable"' . "\n" .
|
||||
'}' . "\n";
|
||||
}
|
||||
elseif($settings['system']['webserver'] == 'nginx'){
|
||||
$filedata = '# ' . basename($backupprotectfile) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" .
|
||||
'# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n\n" .
|
||||
'location ' . $row['documentroot'] . $settings['system']['backup_dir'] . ' {' . "\n" .
|
||||
' deny all;' . "\n" .
|
||||
' return 403;' . "\n" .
|
||||
'}' . "\n";
|
||||
}
|
||||
fwrite($fh, $filedata);
|
||||
fclose($fh);
|
||||
}
|
||||
else{
|
||||
// deletes backup if customer or admin disables backup because backup protection is not set
|
||||
if (file_exists($row['documentroot'] . $settings['system']['backup_dir'] . '/')){
|
||||
$files = scandir($row['documentroot'] . $settings['system']['backup_dir']);
|
||||
foreach ($files as $file){
|
||||
if(preg_match('/.*\.tar\.gz$/', $file)){
|
||||
safe_exec('rm ' . escapeshellarg($row['documentroot']) . escapeshellarg($settings['system']['backup_dir']) . '/' . $file . '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE=10 Set the filesystem - quota
|
||||
*/
|
||||
|
||||
@@ -380,8 +380,8 @@ while($row = $db->fetch_array($result))
|
||||
*/
|
||||
|
||||
$diskusage = floatval($webspaceusage + $emailusage + $mysqlusage);
|
||||
if($settings['system']['backup_count'] == 0 && file_exists($row['documentroot'] . $settings['system']['backup_dir'])){
|
||||
$backupsize = exec('du -s ' . escapeshellarg($row['documentroot'] . $settings['system']['backup_dir']) . '');
|
||||
if($settings['system']['backup_count'] == 0 && file_exists($settings['system']['backup_dir'] . $row['loginname'])){
|
||||
$backupsize = exec('du -s ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . '');
|
||||
$diskusage = floatval($webspaceusage + $emailusage + $mysqlusage - $backupsize);
|
||||
}
|
||||
else{
|
||||
|
||||
Reference in New Issue
Block a user