Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
d77d161a
Commit
d77d161a
authored
Mar 21, 2017
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugins: import plugins_cron() with first caller
https://github.com/opnsense/core/issues/1483
parent
aa5491c6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
17 deletions
+68
-17
plugins.inc
src/etc/inc/plugins.inc
+34
-2
pf.inc
src/etc/inc/plugins.inc.d/pf.inc
+19
-3
system.inc
src/etc/inc/system.inc
+13
-9
firewall_rules.php
src/www/firewall_rules.php
+2
-1
firewall_rules_edit.php
src/www/firewall_rules_edit.php
+0
-2
No files found.
src/etc/inc/plugins.inc
View file @
d77d161a
...
...
@@ -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
));
}
}
}
...
...
src/etc/inc/plugins.inc.d/pf.inc
View file @
d77d161a
...
...
@@ -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
;
...
...
src/etc/inc/system.inc
View file @
d77d161a
...
...
@@ -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'
:
...
...
src/www/firewall_rules.php
View file @
d77d161a
...
...
@@ -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
(
...
...
src/www/firewall_rules_edit.php
View file @
d77d161a
...
...
@@ -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'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment