Commit 29490c8d authored by Franco Fichtner's avatar Franco Fichtner

plugins: add plugins_cron() for autocron usage; closes #1483

parent 983134be
...@@ -74,6 +74,24 @@ function plugins_services() ...@@ -74,6 +74,24 @@ function plugins_services()
return $services; return $services;
} }
function plugins_cron()
{
$jobs = array();
foreach (plugins_scan() as $name => $path) {
require_once $path;
$func = sprintf('%s_cron', $name);
if (function_exists($func)) {
$workers = $func();
foreach ($workers as $work) {
$jobs[] = $work;
}
}
}
return $jobs;
}
function plugins_syslog() function plugins_syslog()
{ {
$syslogs = array(); $syslogs = array();
......
...@@ -41,6 +41,15 @@ function dyndns_configure() ...@@ -41,6 +41,15 @@ function dyndns_configure()
); );
} }
function dyndns_cron()
{
$jobs = array('autocron' => array());
$jobs['autocron'][] = array('/usr/local/etc/rc.dyndns.update', '11', '1');
return $jobs;
}
function dyndns_list() function dyndns_list()
{ {
return array( return array(
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* /*
Copyright (C) 2016 Deciso B.V. Copyright (C) 2016 Deciso B.V.
Copyright (C) 2016 Franco Fichtner <franco@opnsense.org> Copyright (C) 2016-2017 Franco Fichtner <franco@opnsense.org>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
...@@ -49,6 +49,24 @@ function pf_services() ...@@ -49,6 +49,24 @@ function pf_services()
return $services; return $services;
} }
function pf_cron()
{
global $config;
$jobs = array('autocron' => array());
if (isset($config['filter']['rule'])) {
foreach ($config['filter']['rule'] as $rule) {
if (!empty($rule['sched'])) {
$jobs['autocron'][] = array('/usr/local/etc/rc.filter_configure', '0,15,30,45');
break;
}
}
}
return $jobs;
}
function pf_interfaces() function pf_interfaces()
{ {
global $config; global $config;
......
...@@ -38,6 +38,15 @@ function rfc2136_configure() ...@@ -38,6 +38,15 @@ function rfc2136_configure()
); );
} }
function rfc2136_cron()
{
$jobs = array('autocron' => array());
$jobs['autocron'][] = array('/usr/local/etc/rc.rfc2136.update', '16', '1');
return $jobs;
}
function rfc2136_configure_do($verbose = false, $int = '', $updatehost = '', $forced = false) function rfc2136_configure_do($verbose = false, $int = '', $updatehost = '', $forced = false)
{ {
global $config; global $config;
......
...@@ -1580,6 +1580,21 @@ function system_cron_configure($verbose = false) ...@@ -1580,6 +1580,21 @@ function system_cron_configure($verbose = false)
flush(); flush();
} }
foreach (plugins_cron() as $cron_plugin) {
/*
* We are stuffing jobs inside 'autocron' to be able to
* depreceate this at a later time. Ideally all of the
* services should use a single cron-model, which this is
* not. At least this plugin function helps us to divide
* and conquer the code bits... :)
*/
if (!empty($cron_plugin['autocron'])) {
foreach ($cron_plugin['autocron'] as $cron_job) {
$autocron[] = call_user_func_array('generate_cron_job', $cron_job);
}
}
}
/* hourly */ /* 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 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 sshlockout', '2');
...@@ -1589,8 +1604,6 @@ function system_cron_configure($verbose = false) ...@@ -1589,8 +1604,6 @@ function system_cron_configure($verbose = false)
/* daily */ /* daily */
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_alias_url_data', '1', '1'); $autocron[] = generate_cron_job('/usr/local/etc/rc.update_alias_url_data', '1', '1');
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_urltables', '6', '1'); $autocron[] = generate_cron_job('/usr/local/etc/rc.update_urltables', '6', '1');
$autocron[] = generate_cron_job('/usr/local/etc/rc.dyndns.update', '11', '1');
$autocron[] = generate_cron_job('/usr/local/etc/rc.rfc2136.update', '16', '1');
/* every now and then */ /* every now and then */
$autocron[] = generate_cron_job('/usr/local/sbin/ping_hosts.sh', '*/4'); $autocron[] = generate_cron_job('/usr/local/sbin/ping_hosts.sh', '*/4');
...@@ -1615,15 +1628,6 @@ function system_cron_configure($verbose = false) ...@@ -1615,15 +1628,6 @@ function system_cron_configure($verbose = false)
$autocron[] = generate_cron_job('/usr/local/opnsense/scripts/remote_backup.php', 0, 1); $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', '0,15,30,45');
break;
}
}
}
/* 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':
......
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