Commit e23a462e authored by Franco Fichtner's avatar Franco Fichtner

plugins: make plugins.inc side-effect free

The rules are simple:

* plugins_configure() requires all available plugins, probes their
  configure functions and then calls the advertised functions.

* All GUI pages must directly include their includes in plugins.inc.d
  to not overly pollute their loading phase.

(cherry picked from commit cbd9ffb5)
parent 62c1f8ec
...@@ -26,14 +26,39 @@ ...@@ -26,14 +26,39 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
foreach (glob('/usr/local/etc/inc/plugins.inc.d/*.inc') as $plugin) { function plugin_scan()
require_once $plugin; {
$path = '/usr/local/etc/inc/plugins.inc.d/';
$ext = '.inc';
$ret = array();
$plugins = glob($path . '*' . $ext);
if (!is_array($plugins)) {
return $ret;
}
sort($plugins);
foreach ($plugins as $plugin) {
$name = preg_replace('/' . preg_quote($path, '/') . '/', '', $plugin);
$name = preg_replace('/' . preg_quote($ext, '/') . '/', '', $name);
$ret[$name] = $plugin;
}
return $ret;
} }
/* XXX must be reworked to work dynamically, not by name */ function plugins_configure()
function plugins_hook_xxx($name)
{ {
if (function_exists($name)) { foreach (plugin_scan() as $name => $path) {
return $name(); require_once $path;
$func = sprintf('%s_configure', $name);
if (function_exists($func)) {
$workers = $func();
foreach ($workers as $worker) {
$worker();
}
}
} }
} }
...@@ -29,6 +29,15 @@ ...@@ -29,6 +29,15 @@
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
function vpn_configure()
{
return array(
'vpn_pptpd_configure',
'vpn_pppoes_configure',
'vpn_l2tp_configure'
);
}
function vpn_netgraph_support() { function vpn_netgraph_support() {
$iflist = get_configured_interface_list(); $iflist = get_configured_interface_list();
foreach ($iflist as $iface) { foreach ($iflist as $iface) {
......
...@@ -315,14 +315,8 @@ configd_run("dyndns reload"); ...@@ -315,14 +315,8 @@ configd_run("dyndns reload");
/* Run a filter configure now that most all services have started */ /* Run a filter configure now that most all services have started */
filter_configure_sync(); filter_configure_sync();
/* start pptpd */ /* Run all registered plugins */
plugins_hook_xxx('vpn_pptpd_configure'); plugins_configure();
/* start pppoe server */
plugins_hook_xxx('vpn_pppoes_configure');
/* setup l2tp */
plugins_hook_xxx('vpn_l2tp_configure');
/* start IPsec tunnels */ /* start IPsec tunnels */
$ipsec_dynamic_hosts = ipsec_configure(); $ipsec_dynamic_hosts = ipsec_configure();
......
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