Commit cbd9ffb5 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.
parent c9b70766
......@@ -26,14 +26,39 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
foreach (glob('/usr/local/etc/inc/plugins.inc.d/*.inc') as $plugin) {
require_once $plugin;
function plugin_scan()
{
$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_hook_xxx($name)
function plugins_configure()
{
if (function_exists($name)) {
return $name();
foreach (plugin_scan() as $name => $path) {
require_once $path;
$func = sprintf('%s_configure', $name);
if (function_exists($func)) {
$workers = $func();
foreach ($workers as $worker) {
$worker();
}
}
}
}
......@@ -29,6 +29,15 @@
POSSIBILITY OF SUCH DAMAGE.
*/
function vpn_configure()
{
return array(
'vpn_pptpd_configure',
'vpn_pppoes_configure',
'vpn_l2tp_configure'
);
}
function vpn_netgraph_support() {
$iflist = get_configured_interface_list();
foreach ($iflist as $iface) {
......
......@@ -315,14 +315,8 @@ configd_run("dyndns reload");
/* Run a filter configure now that most all services have started */
filter_configure_sync();
/* start pptpd */
plugins_hook_xxx('vpn_pptpd_configure');
/* start pppoe server */
plugins_hook_xxx('vpn_pppoes_configure');
/* setup l2tp */
plugins_hook_xxx('vpn_l2tp_configure');
/* Run all registered plugins */
plugins_configure();
/* start IPsec tunnels */
$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