Commit 5a10f56a authored by Franco Fichtner's avatar Franco Fichtner

cron: remove install_cron_job() usage; #911

parent 98485c39
...@@ -2350,6 +2350,8 @@ function configure_cron() ...@@ -2350,6 +2350,8 @@ function configure_cron()
'/usr/local/etc/rc.backup_netflow', '/usr/local/etc/rc.backup_netflow',
'/usr/local/etc/rc.backup_rrd', '/usr/local/etc/rc.backup_rrd',
'/usr/local/etc/rc.update_bogons', '/usr/local/etc/rc.update_bogons',
'/usr/local/opnsense/scripts/remote_backup.php',
'newsyslog', /* old config migration for extra care */
); );
foreach ($obsoletes as $obsolete) { foreach ($obsoletes as $obsolete) {
...@@ -2374,6 +2376,10 @@ function configure_cron() ...@@ -2374,6 +2376,10 @@ function configure_cron()
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_netflow', $minute = '0', '*/' . $config['system']['netflowbackup']); $autocron[] = generate_cron_job('/usr/local/etc/rc.backup_netflow', $minute = '0', '*/' . $config['system']['netflowbackup']);
} }
if (!empty($config['system']['remotebackup']['GDriveEnabled'])) {
$autocron[] = generate_cron_job('/usr/local/opnsense/scripts/remote_backup.php', 0, 1);
}
/* bogons fetch always set in default config.xml */ /* bogons fetch always set in default config.xml */
switch ($config['system']['bogons']['interval']) { switch ($config['system']['bogons']['interval']) {
case 'daily': case 'daily':
......
...@@ -3119,12 +3119,6 @@ function upgrade_098_to_099() { ...@@ -3119,12 +3119,6 @@ function upgrade_098_to_099() {
} }
} }
function upgrade_099_to_100()
{
install_cron_job("newsyslog", false);
configure_cron();
}
function upgrade_100_to_101() function upgrade_100_to_101()
{ {
global $config; global $config;
......
...@@ -44,20 +44,6 @@ require_once("rrd.inc"); ...@@ -44,20 +44,6 @@ require_once("rrd.inc");
require_once("system.inc"); require_once("system.inc");
require_once("pfsense-utils.inc"); require_once("pfsense-utils.inc");
/**
* check if cron exists
*/
function cron_job_exists($command) {
global $config;
foreach($config['cron']['item'] as $item) {
if(strstr($item['command'], $command)) {
return true;
}
}
return false;
}
function rrd_data_xml() { function rrd_data_xml() {
$rrddbpath = '/var/db/rrd'; $rrddbpath = '/var/db/rrd';
...@@ -426,7 +412,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -426,7 +412,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (is_numeric($_POST['GDriveBackupCount'])) { if (is_numeric($_POST['GDriveBackupCount'])) {
$config['system']['remotebackup']['GDriveBackupCount'] = $_POST['GDriveBackupCount']; $config['system']['remotebackup']['GDriveBackupCount'] = $_POST['GDriveBackupCount'];
} else { } else {
$config['system']['remotebackup']['GDriveBackupCount'] = 30; $config['system']['remotebackup']['GDriveBackupCount'] = 60;
} }
if ( $_POST['GDrivePasswordConfirm'] != $_POST['GDrivePassword'] ) { if ( $_POST['GDrivePasswordConfirm'] != $_POST['GDrivePassword'] ) {
...@@ -434,6 +420,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -434,6 +420,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match."); $input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
} }
if (count($input_errors) == 0) {
if (is_uploaded_file($_FILES['GDriveP12file']['tmp_name'])) { if (is_uploaded_file($_FILES['GDriveP12file']['tmp_name'])) {
$data = file_get_contents($_FILES['GDriveP12file']['tmp_name']); $data = file_get_contents($_FILES['GDriveP12file']['tmp_name']);
$config['system']['remotebackup']['GDriveP12key'] = base64_encode($data); $config['system']['remotebackup']['GDriveP12key'] = base64_encode($data);
...@@ -441,27 +428,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -441,27 +428,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
unset($config['system']['remotebackup']['GDriveP12key']); unset($config['system']['remotebackup']['GDriveP12key']);
} }
$savemsg = gettext("Google Drive backup settings have been saved.");
write_config(); write_config();
// test / perform backup configure_cron();
try { try {
$filesInBackup = backup_to_google_drive(); $filesInBackup = backup_to_google_drive();
$cron_job = "/usr/local/opnsense/scripts/remote_backup.php";
if (!cron_job_exists($cron_job)) {
install_cron_job($cron_job, true, 0, 1);
configure_cron();
}
} catch (Exception $e) { } catch (Exception $e) {
$filesInBackup = array() ; $filesInBackup = array();
} }
if (count($filesInBackup) == 0) { if (empty($config['system']['remotebackup']['GDriveEnabled'])) {
/* unused */
} elseif (count($filesInBackup) == 0) {
$input_errors[] = gettext("Google Drive communication failure"); $input_errors[] = gettext("Google Drive communication failure");
} else { } else {
$input_messages = gettext("Backup succesfull, current filelist:"); $input_messages = gettext("Backup successful, current file list:") . "<br>";
foreach ($filesInBackup as $filename => $file) { foreach ($filesInBackup as $filename => $file) {
$input_messages = $input_messages . "<br>" . $filename ; $input_messages = $input_messages . "<br>" . $filename;
}
} }
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment