add possibility to enable/disable backup function

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2016-04-28 15:27:59 +02:00
parent 9bfd5eb17e
commit b1446d366e
8 changed files with 93 additions and 58 deletions

View File

@@ -186,6 +186,15 @@ return array(
)
),
),
'system_backupenabled' => array(
'label' => $lng['serversettings']['backupenabled'],
'settinggroup' => 'system',
'varname' => 'backupenabled',
'type' => 'bool',
'default' => false,
'cronmodule' => 'froxlor/backup',
'save_method' => 'storeSettingField'
),
),
),
);

View File

@@ -519,65 +519,73 @@ if ($page == 'overview') {
}
}
} elseif ($page == 'backup') {
if ($action == '') {
$log->logAction(USR_ACTION, LOG_NOTICE, "viewed customer_extras::backup");
if (isset($_POST['send']) && $_POST['send'] == 'send') {
if (Settings::Get('system.backupenabled') == 1)
{
if ($action == '') {
$log->logAction(USR_ACTION, LOG_NOTICE, "viewed customer_extras::backup");
if (! $_POST['path']) {
standard_error('invalidpath');
}
if (isset($_POST['send']) && $_POST['send'] == 'send') {
$path = makeCorrectDir(validate($_POST['path'], 'path'));
$path = makeCorrectDir($userinfo['documentroot'] . '/' . $path);
$backup_dbs = isset($_POST['backup_dbs']) ? intval($_POST['backup_dbs']) : 0;
$backup_mail = isset($_POST['backup_mail']) ? intval($_POST['backup_mail']) : 0;
$backup_web = isset($_POST['backup_web']) ? intval($_POST['backup_web']) : 0;
if ($backup_dbs != '1') {
$backup_dbs = '0';
}
if ($backup_mail != '1') {
$backup_mail = '0';
}
if ($backup_web != '1') {
$backup_web = '0';
}
$task_data = array(
'customerid' => $userinfo['customerid'],
'uid' => $userinfo['guid'],
'gid' => $userinfo['guid'],
'loginname' => $userinfo['loginname'],
'destdir' => $path,
'backup_dbs' => $backup_dbs,
'backup_mail' => $backup_mail,
'backup_web' => $backup_web
);
inserttask('20', $task_data);
standard_success('backupscheduled');
} else {
// check whether there is a backup-job for this customer
$sel_stmt = Database::prepare("SELECT * FROM `".TABLE_PANEL_TASKS."` WHERE `type` = '20'");
Database::pexecute($sel_stmt);
while ($entry = $sel_stmt->fetch())
{
$data = unserialize($entry['data']);
if ($data['customerid'] == $userinfo['customerid']) {
standard_error('customerhasongoingbackupjob');
if (! $_POST['path']) {
standard_error('invalidpath');
}
$path = makeCorrectDir(validate($_POST['path'], 'path'));
$path = makeCorrectDir($userinfo['documentroot'] . '/' . $path);
$backup_dbs = isset($_POST['backup_dbs']) ? intval($_POST['backup_dbs']) : 0;
$backup_mail = isset($_POST['backup_mail']) ? intval($_POST['backup_mail']) : 0;
$backup_web = isset($_POST['backup_web']) ? intval($_POST['backup_web']) : 0;
if ($backup_dbs != '1') {
$backup_dbs = '0';
}
if ($backup_mail != '1') {
$backup_mail = '0';
}
if ($backup_web != '1') {
$backup_web = '0';
}
$task_data = array(
'customerid' => $userinfo['customerid'],
'uid' => $userinfo['guid'],
'gid' => $userinfo['guid'],
'loginname' => $userinfo['loginname'],
'destdir' => $path,
'backup_dbs' => $backup_dbs,
'backup_mail' => $backup_mail,
'backup_web' => $backup_web
);
inserttask('20', $task_data);
standard_success('backupscheduled');
} else {
// check whether there is a backup-job for this customer
$sel_stmt = Database::prepare("SELECT * FROM `".TABLE_PANEL_TASKS."` WHERE `type` = '20'");
Database::pexecute($sel_stmt);
while ($entry = $sel_stmt->fetch())
{
$data = unserialize($entry['data']);
if ($data['customerid'] == $userinfo['customerid']) {
standard_error('customerhasongoingbackupjob');
}
}
$pathSelect = makePathfield($userinfo['documentroot'], $userinfo['guid'], $userinfo['guid']);
$backup_data = include_once dirname(__FILE__) . '/lib/formfields/customer/extras/formfield.backup.php';
$backup_form = htmlform::genHTMLForm($backup_data);
$title = $backup_data['backup']['title'];
$image = $backup_data['backup']['image'];
eval("echo \"" . getTemplate("extras/backup") . "\";");
}
$pathSelect = makePathfield($userinfo['documentroot'], $userinfo['guid'], $userinfo['guid']);
$backup_data = include_once dirname(__FILE__) . '/lib/formfields/customer/extras/formfield.backup.php';
$backup_form = htmlform::genHTMLForm($backup_data);
$title = $backup_data['backup']['title'];
$image = $backup_data['backup']['image'];
eval("echo \"" . getTemplate("extras/backup") . "\";");
}
}
}
else
{
standard_error('backupfunctionnotenabled');
}
}

View File

@@ -525,6 +525,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES
('system', 'letsencryptkeysize', '4096'),
('system', 'letsencryptreuseold', 0),
('system', 'leenabled', '0'),
('system', 'backupenabled', '0'),
('panel', 'decimal_places', '4'),
('panel', 'adminmail', 'admin@SERVERNAME'),
('panel', 'phpmyadmin_url', ''),

View File

@@ -3295,7 +3295,9 @@ if (isFroxlorVersion('0.9.35')) {
if (isFroxlorVersion('0.9.35.1') && isDatabaseVersion('201603150')) {
showUpdateStep("Adding new backup-cron entry");
showUpdateStep("Adding new backup settings and cron");
$enable_backup = isset($_POST['enable_backup']) ? (int) $_POST['enable_backup'] : "0";
Settings::AddNew("system.backupenabled", $enable_backup);
$stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_CRONRUNS . "` SET
`module` = 'froxlor/backup',
@@ -3303,9 +3305,9 @@ if (isFroxlorVersion('0.9.35.1') && isDatabaseVersion('201603150')) {
`interval` = '1 DAY',
`desc_lng_key` = 'cron_backup',
`lastrun` = 0,
`isactive` = 0"
`isactive` = :isactive"
);
Database::pexecute($stmt);
Database::pexecute($stmt, array('isactive' => $enable_backup));
lastStepStatus(0);
updateToDbVersion('201604270');

View File

@@ -708,4 +708,12 @@ function parseAndOutputPreconfig(&$has_preconfig, &$return, $current_version, $c
$question.= makeyesno('enable_letsencrypt', '1', '0', '1').'<br />';
eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
}
if (versionInUpdate($current_db_version, '201604270')) {
$has_preconfig = true;
$description = 'You can chose whether you want to enable or disable our backup function.<br /><br />';
$question = '<strong>Do you want to enable Backup? (default: no):</strong>&nbsp;';
$question.= makeyesno('enable_backup', '1', '0', '0').'<br />';
eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
}
}

View File

@@ -132,6 +132,7 @@ return array (
array (
'url' => 'customer_extras.php?page=backup',
'label' => $lng['menue']['extras']['backup'],
'show_element' => ( Settings::Get('system.backupenabled') == true ),
),
),
),

View File

@@ -1983,3 +1983,6 @@ $lng['extras']['backup_dbs'] = 'Backup databases';
$lng['error']['customerhasongoingbackupjob'] = 'There is already a backup job waiting to be processed, please be patient.';
$lng['success']['backupscheduled'] = 'Your backup job has been scheduled. Please wait for it to be processed';
$lng['crondesc']['cron_backup'] = 'Process backup jobs';
$lng['error']['backupfunctionnotenabled'] = 'The backup function is not enabled';
$lng['serversettings']['backupenabled']['title'] = "Enable backup for customers";
$lng['serversettings']['backupenabled']['description'] = "If activated, the customer will be able to schedule backup jobs (cron-backup) which generates an archive within his docroot (subdirectory chosable by customer)";

View File

@@ -1636,3 +1636,6 @@ $lng['extras']['backup_dbs'] = 'Datenbanken sichern';
$lng['error']['customerhasongoingbackupjob'] = 'Es gibt noch einen austehenden Backup-Job. Bitte haben Sie etwas Geduld.';
$lng['success']['backupscheduled'] = 'Ihre Sicherung wurde erfolgreich geplant. Bitte warten Sie nun, bis diese abgearbeitet wurde.';
$lng['crondesc']['cron_backup'] = 'Ausstehende Sicherungen erstellen';
$lng['error']['backupfunctionnotenabled'] = 'Die Sicherungs-Funktion is nicht aktiviert';
$lng['serversettings']['backupenabled']['title'] = "Backup für Kunden aktivieren";
$lng['serversettings']['backupenabled']['description'] = "Wenn dies aktiviert ist, kann der Kunde Sicherungen planen (cron-backup) welche ein Archiv in sein Heimatverzeichnis ablegt (Unterordner vom Kunden wählbar)";