Commit 2c944e73 authored by Franco Fichtner's avatar Franco Fichtner

configd: small improvements loosely related to #1238

o Don't look for templates in manufacturer directory
o Allow to use "/" component separator, it's safe
o Hook up the "template list" command

(cherry picked from commit a4b9c029)
(cherry picked from commit 477fba11)
parent 534e2526
...@@ -760,7 +760,7 @@ function system_syslogd_start() ...@@ -760,7 +760,7 @@ function system_syslogd_start()
global $config, $g; global $config, $g;
/* XXX temporary hook for newsyslog.conf regeneration */ /* XXX temporary hook for newsyslog.conf regeneration */
configd_run('template reload OPNsense.Syslog'); configd_run('template reload OPNsense/Syslog');
mwexec('/etc/rc.d/hostid start'); mwexec('/etc/rc.d/hostid start');
...@@ -1874,7 +1874,7 @@ function system_login_configure() ...@@ -1874,7 +1874,7 @@ function system_login_configure()
{ {
global $config; global $config;
configd_run('template reload OPNsense.Auth'); configd_run('template reload OPNsense/Auth');
$serialspeed = (!empty($config['system']['serialspeed']) && is_numeric($config['system']['serialspeed'])) ? $config['system']['serialspeed'] : '115200'; $serialspeed = (!empty($config['system']['serialspeed']) && is_numeric($config['system']['serialspeed'])) ? $config['system']['serialspeed'] : '115200';
$serial_enabled = isset($config['system']['enableserial']); $serial_enabled = isset($config['system']['enableserial']);
......
...@@ -53,11 +53,11 @@ class ServiceController extends ApiControllerBase ...@@ -53,11 +53,11 @@ class ServiceController extends ApiControllerBase
$backend = new Backend(); $backend = new Backend();
// the ipfw rules need to know about all the zones, so we need to reload ipfw for the portal to work // the ipfw rules need to know about all the zones, so we need to reload ipfw for the portal to work
$backend->configdRun("template reload OPNsense.IPFW"); $backend->configdRun('template reload OPNsense/IPFW');
$bckresult = trim($backend->configdRun("ipfw reload")); $bckresult = trim($backend->configdRun("ipfw reload"));
if ($bckresult == "OK") { if ($bckresult == "OK") {
// generate captive portal config // generate captive portal config
$bckresult = trim($backend->configdRun("template reload OPNsense.Captiveportal")); $bckresult = trim($backend->configdRun('template reload OPNsense/Captiveportal'));
if ($bckresult == "OK") { if ($bckresult == "OK") {
$mdlCP = new CaptivePortal(); $mdlCP = new CaptivePortal();
if ($mdlCP->isEnabled()) { if ($mdlCP->isEnabled()) {
......
...@@ -54,7 +54,7 @@ class ServiceController extends ApiControllerBase ...@@ -54,7 +54,7 @@ class ServiceController extends ApiControllerBase
$backend = new Backend(); $backend = new Backend();
// generate template // generate template
$backend->configdRun("template reload OPNsense.Cron"); $backend->configdRun('template reload OPNsense/Cron');
// (res)start daemon // (res)start daemon
$backend->configdRun("cron restart"); $backend->configdRun("cron restart");
......
...@@ -125,7 +125,7 @@ class NetflowController extends ApiControllerBase ...@@ -125,7 +125,7 @@ class NetflowController extends ApiControllerBase
// reconfigure netflow // reconfigure netflow
$backend = new Backend(); $backend = new Backend();
$backend->configdRun("template reload OPNsense.Netflow"); $backend->configdRun('template reload OPNsense/Netflow');
// restart netflow, by calling stop (which will always stop the collectors) and start // restart netflow, by calling stop (which will always stop the collectors) and start
// (which will only start if there are collectors configured) // (which will only start if there are collectors configured)
$backend->configdRun("netflow stop"); $backend->configdRun("netflow stop");
......
...@@ -146,7 +146,7 @@ class ServiceController extends ApiControllerBase ...@@ -146,7 +146,7 @@ class ServiceController extends ApiControllerBase
} }
$backend = new Backend(); $backend = new Backend();
$bckresult = trim($backend->configdRun("template reload OPNsense.IDS")); $bckresult = trim($backend->configdRun('template reload OPNsense/IDS'));
if ($bckresult == "OK") { if ($bckresult == "OK") {
if ((string)$mdlIDS->general->enabled == 1) { if ((string)$mdlIDS->general->enabled == 1) {
...@@ -186,7 +186,7 @@ class ServiceController extends ApiControllerBase ...@@ -186,7 +186,7 @@ class ServiceController extends ApiControllerBase
// we have to trigger a template reload to be sure we have the right download configuration // we have to trigger a template reload to be sure we have the right download configuration
// ideally we should only regenerate the download config, but that's not supported at the moment. // ideally we should only regenerate the download config, but that's not supported at the moment.
// (not sure if it should be supported) // (not sure if it should be supported)
$bckresult = trim($backend->configdRun("template reload OPNsense.IDS")); $bckresult = trim($backend->configdRun('template reload OPNsense/IDS'));
if ($bckresult == "OK") { if ($bckresult == "OK") {
if ($wait != null) { if ($wait != null) {
...@@ -216,7 +216,7 @@ class ServiceController extends ApiControllerBase ...@@ -216,7 +216,7 @@ class ServiceController extends ApiControllerBase
$this->sessionClose(); $this->sessionClose();
$backend = new Backend(); $backend = new Backend();
// flush rule configuration // flush rule configuration
$bckresult = trim($backend->configdRun("template reload OPNsense.IDS")); $bckresult = trim($backend->configdRun('template reload OPNsense/IDS'));
if ($bckresult == "OK") { if ($bckresult == "OK") {
$status = $backend->configdRun("ids reload"); $status = $backend->configdRun("ids reload");
} else { } else {
......
...@@ -145,7 +145,7 @@ class ServiceController extends ApiControllerBase ...@@ -145,7 +145,7 @@ class ServiceController extends ApiControllerBase
} }
// generate template // generate template
$backend->configdRun("template reload OPNsense.Proxy"); $backend->configdRun('template reload OPNsense/Proxy');
// (res)start daemon // (res)start daemon
if ($mdlProxy->general->enabled->__toString() == 1) { if ($mdlProxy->general->enabled->__toString() == 1) {
...@@ -172,7 +172,7 @@ class ServiceController extends ApiControllerBase ...@@ -172,7 +172,7 @@ class ServiceController extends ApiControllerBase
if ($this->request->isPost()) { if ($this->request->isPost()) {
$backend = new Backend(); $backend = new Backend();
// generate template // generate template
$backend->configdRun("template reload OPNsense.Proxy"); $backend->configdRun('template reload OPNsense/Proxy');
// fetch files // fetch files
$response = $backend->configdRun("proxy fetchacls"); $response = $backend->configdRun("proxy fetchacls");
...@@ -191,7 +191,7 @@ class ServiceController extends ApiControllerBase ...@@ -191,7 +191,7 @@ class ServiceController extends ApiControllerBase
if ($this->request->isPost()) { if ($this->request->isPost()) {
$backend = new Backend(); $backend = new Backend();
// generate template // generate template
$backend->configdRun("template reload OPNsense.Proxy"); $backend->configdRun('template reload OPNsense/Proxy');
// download files // download files
$response = $backend->configdRun("proxy downloadacls"); $response = $backend->configdRun("proxy downloadacls");
......
...@@ -48,7 +48,7 @@ class ServiceController extends ApiControllerBase ...@@ -48,7 +48,7 @@ class ServiceController extends ApiControllerBase
$this->sessionClose(); $this->sessionClose();
$backend = new Backend(); $backend = new Backend();
$backend->configdRun("template reload OPNsense.IPFW"); $backend->configdRun('template reload OPNsense/IPFW');
$bckresult = trim($backend->configdRun("ipfw reload")); $bckresult = trim($backend->configdRun("ipfw reload"));
if ($bckresult == "OK") { if ($bckresult == "OK") {
$status = "ok"; $status = "ok";
......
...@@ -5,3 +5,9 @@ type:inline ...@@ -5,3 +5,9 @@ type:inline
message:generate template %s message:generate template %s
config:/conf/config.xml config:/conf/config.xml
root_dir:/ root_dir:/
[list]
command:template.list
type:inline
message:list templates
root_dir:/
""" """
Copyright (c) 2014 Ad Schellevis Copyright (c) 2014 Ad Schellevis
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
...@@ -28,15 +27,14 @@ ...@@ -28,15 +27,14 @@
package : configd package : configd
function: configd inline actions function: configd inline actions
""" """
import syslog import syslog
import template import template
import config import config
__author__ = 'Ad Schellevis' __author__ = 'Ad Schellevis'
def execute(action, parameters): def execute(action, parameters):
""" wrapper for inline functions """ wrapper for inline functions
...@@ -49,6 +47,8 @@ def execute(action, parameters): ...@@ -49,6 +47,8 @@ def execute(action, parameters):
tmpl = template.Template(action.root_dir) tmpl = template.Template(action.root_dir)
conf = config.Config(action.config) conf = config.Config(action.config)
tmpl.set_config(conf.get()) tmpl.set_config(conf.get())
# XXX backwards-compat for '.' syntax, remove post-17.1
parameters = parameters.replace('.', '/')
filenames = tmpl.generate(parameters) filenames = tmpl.generate(parameters)
del conf del conf
......
...@@ -95,8 +95,8 @@ class Template(object): ...@@ -95,8 +95,8 @@ class Template(object):
""" """
result = {} result = {}
for root, dirs, files in os.walk(self._template_dir): for root, dirs, files in os.walk(self._template_dir):
if len(root) > len(self._template_dir): if root.count('/') > self._template_dir.count('/'):
module_name = '.'.join(root.replace(self._template_dir, '').split('/')) module_name = root.replace(self._template_dir, '')
if module_name not in result: if module_name not in result:
result[module_name] = self.list_module(module_name) result[module_name] = self.list_module(module_name)
......
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