Commit d77d161a authored by Franco Fichtner's avatar Franco Fichtner

plugins: import plugins_cron() with first caller

https://github.com/opnsense/core/issues/1483
parent aa5491c6
......@@ -74,6 +74,24 @@ function plugins_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()
{
$syslogs = array();
......@@ -165,8 +183,10 @@ function plugins_firewall($fw)
return $fw;
}
function plugins_configure($hook, $verbose = false)
function plugins_configure($hook, $verbose = false, $args = array())
{
array_unshift($args, $verbose);
foreach (plugins_scan() as $name => $path) {
require_once $path;
$func = sprintf('%s_configure', $name);
......@@ -175,7 +195,19 @@ function plugins_configure($hook, $verbose = false)
foreach ($workers as $when => $worker) {
if ($hook == $when && is_array($worker)) {
foreach ($worker as $task) {
$task($verbose);
/*
* An optional argument count parameter can be
* given by the plugin, which allows to securely
* pull more info from the configure call spot.
*/
list($argf, $argc) = explode(':', $task);
if (empty($argc) || !is_numeric($argc)) {
$argc = 1;
}
if ($argc > count($args)) {
$argc = count($args);
}
call_user_func_array($argf, array_slice($args, 0, $argc));
}
}
}
......
......@@ -2,7 +2,7 @@
/*
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.
Redistribution and use in source and binary forms, with or without
......@@ -38,8 +38,6 @@ function pf_services()
'description' => gettext('Packet Filter'),
'configd' => array(
'restart' => array('filter reload'),
'start' => array('filter reload'),
'stop' => array('filter reload'),
),
'nocheck' => true,
'name' => 'pf',
......@@ -49,6 +47,24 @@ function pf_services()
return $services;
}
function pf_cron()
{
global $config;
$jobs = 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()
{
global $config;
......
......@@ -1576,6 +1576,19 @@ function system_cron_configure($verbose = false)
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'])) {
$autocron[] = call_user_func_array('generate_cron_job', $cron_plugin['autocron']);
}
}
/* 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');
......@@ -1610,15 +1623,6 @@ function system_cron_configure($verbose = false)
$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 */
switch ($config['system']['bogons']['interval']) {
case 'daily':
......
......@@ -30,7 +30,7 @@
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("system.inc");
if (!isset($config['filter']['rule'])) {
$config['filter']['rule'] = array();
......@@ -49,6 +49,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = $pconfig['id'];
}
if (isset($pconfig['apply'])) {
system_cron_configure();
filter_configure();
clear_subsystem_dirty('filter');
$savemsg = sprintf(
......
......@@ -30,7 +30,6 @@
require_once("guiconfig.inc");
require_once("interfaces.inc");
require_once("system.inc");
require_once("filter.inc");
/* TCP flags */
......@@ -455,7 +454,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
// sort filter items per interface, not really necessary but leaves a bit nicer sorted config.xml behind.
filter_rules_sort();
system_cron_configure();
// write to config
write_config();
mark_subsystem_dirty('filter');
......
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