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()
global $config, $g;
/* 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');
......@@ -1874,7 +1874,7 @@ function system_login_configure()
{
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';
$serial_enabled = isset($config['system']['enableserial']);
......
......@@ -53,11 +53,11 @@ class ServiceController extends ApiControllerBase
$backend = new Backend();
// 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"));
if ($bckresult == "OK") {
// generate captive portal config
$bckresult = trim($backend->configdRun("template reload OPNsense.Captiveportal"));
$bckresult = trim($backend->configdRun('template reload OPNsense/Captiveportal'));
if ($bckresult == "OK") {
$mdlCP = new CaptivePortal();
if ($mdlCP->isEnabled()) {
......
......@@ -54,7 +54,7 @@ class ServiceController extends ApiControllerBase
$backend = new Backend();
// generate template
$backend->configdRun("template reload OPNsense.Cron");
$backend->configdRun('template reload OPNsense/Cron');
// (res)start daemon
$backend->configdRun("cron restart");
......
......@@ -125,7 +125,7 @@ class NetflowController extends ApiControllerBase
// reconfigure netflow
$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
// (which will only start if there are collectors configured)
$backend->configdRun("netflow stop");
......
......@@ -146,7 +146,7 @@ class ServiceController extends ApiControllerBase
}
$backend = new Backend();
$bckresult = trim($backend->configdRun("template reload OPNsense.IDS"));
$bckresult = trim($backend->configdRun('template reload OPNsense/IDS'));
if ($bckresult == "OK") {
if ((string)$mdlIDS->general->enabled == 1) {
......@@ -186,7 +186,7 @@ class ServiceController extends ApiControllerBase
// 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.
// (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 ($wait != null) {
......@@ -216,7 +216,7 @@ class ServiceController extends ApiControllerBase
$this->sessionClose();
$backend = new Backend();
// flush rule configuration
$bckresult = trim($backend->configdRun("template reload OPNsense.IDS"));
$bckresult = trim($backend->configdRun('template reload OPNsense/IDS'));
if ($bckresult == "OK") {
$status = $backend->configdRun("ids reload");
} else {
......
......@@ -145,7 +145,7 @@ class ServiceController extends ApiControllerBase
}
// generate template
$backend->configdRun("template reload OPNsense.Proxy");
$backend->configdRun('template reload OPNsense/Proxy');
// (res)start daemon
if ($mdlProxy->general->enabled->__toString() == 1) {
......@@ -172,7 +172,7 @@ class ServiceController extends ApiControllerBase
if ($this->request->isPost()) {
$backend = new Backend();
// generate template
$backend->configdRun("template reload OPNsense.Proxy");
$backend->configdRun('template reload OPNsense/Proxy');
// fetch files
$response = $backend->configdRun("proxy fetchacls");
......@@ -191,7 +191,7 @@ class ServiceController extends ApiControllerBase
if ($this->request->isPost()) {
$backend = new Backend();
// generate template
$backend->configdRun("template reload OPNsense.Proxy");
$backend->configdRun('template reload OPNsense/Proxy');
// download files
$response = $backend->configdRun("proxy downloadacls");
......
......@@ -48,7 +48,7 @@ class ServiceController extends ApiControllerBase
$this->sessionClose();
$backend = new Backend();
$backend->configdRun("template reload OPNsense.IPFW");
$backend->configdRun('template reload OPNsense/IPFW');
$bckresult = trim($backend->configdRun("ipfw reload"));
if ($bckresult == "OK") {
$status = "ok";
......
......@@ -5,3 +5,9 @@ type:inline
message:generate template %s
config:/conf/config.xml
root_dir:/
[list]
command:template.list
type:inline
message:list templates
root_dir:/
"""
Copyright (c) 2014 Ad Schellevis
All rights reserved.
Redistribution and use in source and binary forms, with or without
......@@ -28,15 +27,14 @@
package : configd
function: configd inline actions
"""
import syslog
import template
import config
__author__ = 'Ad Schellevis'
def execute(action, parameters):
""" wrapper for inline functions
......@@ -49,6 +47,8 @@ def execute(action, parameters):
tmpl = template.Template(action.root_dir)
conf = config.Config(action.config)
tmpl.set_config(conf.get())
# XXX backwards-compat for '.' syntax, remove post-17.1
parameters = parameters.replace('.', '/')
filenames = tmpl.generate(parameters)
del conf
......
......@@ -95,8 +95,8 @@ class Template(object):
"""
result = {}
for root, dirs, files in os.walk(self._template_dir):
if len(root) > len(self._template_dir):
module_name = '.'.join(root.replace(self._template_dir, '').split('/'))
if root.count('/') > self._template_dir.count('/'):
module_name = root.replace(self._template_dir, '')
if module_name not in result:
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