Commit ec679740 authored by Franco Fichtner's avatar Franco Fichtner

system: move system_cron_configure() to new home

parent b508d4d9
......@@ -2043,107 +2043,6 @@ EOD;
return 0;
}
function system_cron_configure($verbose = false)
{
global $config;
function generate_cron_job($command, $minute = '0', $hour = '*', $monthday = '*', $month = '*', $weekday = '*')
{
$cron_item = array();
$cron_item['minute'] = $minute;
$cron_item['hour'] = $hour;
$cron_item['mday'] = $monthday;
$cron_item['month'] = $month;
$cron_item['wday'] = $weekday;
$cron_item['command'] = $command;
return $cron_item;
}
$autocron = array();
if ($verbose) {
echo 'Configuring CRON...';
flush();
}
/* hourly */
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 webConfiguratorlockout', '1');
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 sshlockout', '2');
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 virusprot', '3');
$autocron[] = generate_cron_job('/usr/local/etc/rc.expireaccounts', '5');
/* daily */
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_alias_url_data', '1', '1');
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_urltables', '5', '1');
$autocron[] = generate_cron_job('/usr/local/etc/rc.dyndns.update', '11', '1');
/* every now and then */
$autocron[] = generate_cron_job('/usr/local/sbin/ping_hosts.sh', '*/4');
if (!empty($config['system']['rrdbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_rrd', '0', '*/' . $config['system']['rrdbackup']);
}
if (!empty($config['system']['dhcpbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_dhcpleases', '0', '*/' . $config['system']['dhcpbackup']);
}
if (!empty($config['system']['netflowbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_netflow', '0', '*/' . $config['system']['netflowbackup']);
}
if (!empty($config['system']['remotebackup']['GDriveEnabled'])) {
$autocron[] = generate_cron_job('/usr/local/opnsense/scripts/remote_backup.php', 0, 1);
}
if (isset($config['filter']['rule'])) {
foreach ($config['filter']['rule'] as $rule) {
if (!empty($rule['sched'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.filter_configure_sync', '0,15,30,45');
break;
}
}
}
/* bogons fetch always set in default config.xml */
switch ($config['system']['bogons']['interval']) {
case 'daily':
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_bogons cron', '1', '3', '*', '*', '*');
break;
case 'weekly':
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_bogons cron', '1', '3', '*', '*', '0');
break;
case 'monthly':
default:
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_bogons cron', '1', '3', '1', '*', '*');
break;
}
$crontab_contents = "# DO NOT EDIT THIS FILE -- OPNsense auto-generated file\n";
$crontab_contents .= "# Please use /etc/crontab for your overrides instead.\n";
$crontab_contents .= "SHELL=/bin/sh\n";
$crontab_contents .= "PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\n";
$crontab_contents .= "#minute\thour\tmday\tmonth\twday\tcommand\n";
foreach ($autocron as $item) {
$crontab_contents .= "{$item['minute']}\t";
$crontab_contents .= "{$item['hour']}\t";
$crontab_contents .= "{$item['mday']}\t";
$crontab_contents .= "{$item['month']}\t";
$crontab_contents .= "{$item['wday']}\t";
$crontab_contents .= "{$item['command']}\n";
}
file_put_contents('/var/cron/tabs/root', $crontab_contents);
killbypid('/var/run/cron.pid', 'HUP');
if ($verbose) {
echo "done.\n";
}
}
function is_apinger_enabled()
{
global $config;
......
......@@ -1820,6 +1820,107 @@ function load_thermal_module()
}
}
function system_cron_configure($verbose = false)
{
global $config;
function generate_cron_job($command, $minute = '0', $hour = '*', $monthday = '*', $month = '*', $weekday = '*')
{
$cron_item = array();
$cron_item['minute'] = $minute;
$cron_item['hour'] = $hour;
$cron_item['mday'] = $monthday;
$cron_item['month'] = $month;
$cron_item['wday'] = $weekday;
$cron_item['command'] = $command;
return $cron_item;
}
$autocron = array();
if ($verbose) {
echo 'Configuring CRON...';
flush();
}
/* hourly */
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 webConfiguratorlockout', '1');
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 sshlockout', '2');
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 virusprot', '3');
$autocron[] = generate_cron_job('/usr/local/etc/rc.expireaccounts', '5');
/* daily */
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_alias_url_data', '1', '1');
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_urltables', '5', '1');
$autocron[] = generate_cron_job('/usr/local/etc/rc.dyndns.update', '11', '1');
/* every now and then */
$autocron[] = generate_cron_job('/usr/local/sbin/ping_hosts.sh', '*/4');
if (!empty($config['system']['rrdbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_rrd', '0', '*/' . $config['system']['rrdbackup']);
}
if (!empty($config['system']['dhcpbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_dhcpleases', '0', '*/' . $config['system']['dhcpbackup']);
}
if (!empty($config['system']['netflowbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_netflow', '0', '*/' . $config['system']['netflowbackup']);
}
if (!empty($config['system']['remotebackup']['GDriveEnabled'])) {
$autocron[] = generate_cron_job('/usr/local/opnsense/scripts/remote_backup.php', 0, 1);
}
if (isset($config['filter']['rule'])) {
foreach ($config['filter']['rule'] as $rule) {
if (!empty($rule['sched'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.filter_configure_sync', '0,15,30,45');
break;
}
}
}
/* bogons fetch always set in default config.xml */
switch ($config['system']['bogons']['interval']) {
case 'daily':
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_bogons cron', '1', '3', '*', '*', '*');
break;
case 'weekly':
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_bogons cron', '1', '3', '*', '*', '0');
break;
case 'monthly':
default:
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_bogons cron', '1', '3', '1', '*', '*');
break;
}
$crontab_contents = "# DO NOT EDIT THIS FILE -- OPNsense auto-generated file\n";
$crontab_contents .= "# Please use /etc/crontab for your overrides instead.\n";
$crontab_contents .= "SHELL=/bin/sh\n";
$crontab_contents .= "PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\n";
$crontab_contents .= "#minute\thour\tmday\tmonth\twday\tcommand\n";
foreach ($autocron as $item) {
$crontab_contents .= "{$item['minute']}\t";
$crontab_contents .= "{$item['hour']}\t";
$crontab_contents .= "{$item['mday']}\t";
$crontab_contents .= "{$item['month']}\t";
$crontab_contents .= "{$item['wday']}\t";
$crontab_contents .= "{$item['command']}\n";
}
file_put_contents('/var/cron/tabs/root', $crontab_contents);
killbypid('/var/run/cron.pid', 'HUP');
if ($verbose) {
echo "done.\n";
}
}
function system_console_types()
{
return array(
......
......@@ -30,7 +30,7 @@
require_once("guiconfig.inc");
require_once("interfaces.inc");
require_once("services.inc");
require_once("system.inc");
require_once("filter.inc");
/* TCP flags */
......
......@@ -31,7 +31,6 @@
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("services.inc");
require_once("system.inc");
function default_table_entries_size()
......
......@@ -33,7 +33,6 @@ require_once("guiconfig.inc");
require_once("filter.inc");
require_once("ipsec.inc");
require_once("system.inc");
require_once("services.inc");
require_once("interfaces.inc");
function crypto_modules()
......
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