Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
6bb1b51d
Commit
6bb1b51d
authored
Mar 20, 2019
by
Дмитрий Никулин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle template syntax errors
parent
8b03916a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
11 deletions
+24
-11
fmod_maild.py
plugins/functions/fmod_maild.py
+10
-4
fmod_postfix.py
plugins/functions/fmod_postfix.py
+14
-7
No files found.
plugins/functions/fmod_maild.py
View file @
6bb1b51d
...
...
@@ -15,6 +15,7 @@ from settingsd.tools.process import execProcess
import
settingsd.tools.editors
from
os
import
path
from
jinja2
import
Template
from
jinja2.exceptions
import
TemplateSyntaxError
##### Private constants #####
SERVICE_NAME
=
"maild"
...
...
@@ -22,16 +23,21 @@ MAILD_METHODS_NAMESPACE = "maild"
MAILD_DRWEB_INI
=
"/etc/opt/drweb.com/drweb.ini"
MAILD_MILTER_HOOK
=
"/etc/opt/drweb.com/milterhook.lua"
##### Private classes #####
class
MailD
(
service
.
FunctionObject
)
:
### DBus methods ###
@service.functionMethod
(
MAILD_METHODS_NAMESPACE
,
in_signature
=
"sss"
)
@service.functionMethod
(
MAILD_METHODS_NAMESPACE
,
in_signature
=
"sss"
,
out_signature
=
"s"
)
def
regenerateDrwebIni
(
self
,
config_filename
,
drweb_ini_templates_dir
,
lua_templates_dir
):
with
open
(
config_filename
,
'r'
)
as
maild_config
:
config
=
safe_load
(
maild_config
.
read
())
self
.
renderTemplate
(
config
[
'template'
],
drweb_ini_templates_dir
,
config
[
'settings'
],
MAILD_DRWEB_INI
)
self
.
renderTemplate
(
config
[
'template'
],
lua_templates_dir
,
config
[
'settings'
],
MAILD_MILTER_HOOK
)
try
:
self
.
renderTemplate
(
config
[
'template'
],
drweb_ini_templates_dir
,
config
[
'settings'
],
MAILD_DRWEB_INI
)
self
.
renderTemplate
(
config
[
'template'
],
lua_templates_dir
,
config
[
'settings'
],
MAILD_MILTER_HOOK
)
return
''
except
TemplateSyntaxError
as
exc
:
return
str
(
exc
)
def
renderTemplate
(
self
,
template
,
templates_dir
,
settings
,
output_filename
):
template_filename
=
path
.
join
(
templates_dir
,
template
+
'.tpl'
)
...
...
plugins/functions/fmod_postfix.py
View file @
6bb1b51d
...
...
@@ -15,6 +15,7 @@ from settingsd.tools.process import execProcess
import
settingsd.tools.editors
from
os
import
path
from
jinja2
import
Template
from
jinja2.exceptions
import
TemplateSyntaxError
##### Private constants #####
SERVICE_NAME
=
"postfix"
...
...
@@ -24,17 +25,23 @@ POSTFIX_MAIN_CF = "/etc/postfix/main.cf"
##### Private classes #####
class
Postfix
(
service
.
FunctionObject
)
:
### DBus methods ###
@service.functionMethod
(
POSTFIX_METHODS_NAMESPACE
,
in_signature
=
"ss"
)
@service.functionMethod
(
POSTFIX_METHODS_NAMESPACE
,
in_signature
=
"ss"
,
out_signature
=
"s"
)
def
regenerateMainCf
(
self
,
config_filename
,
templates_dir
):
with
open
(
config_filename
,
'r'
)
as
postfix_config
:
config
=
safe_load
(
postfix_config
.
read
())
template_filename
=
path
.
join
(
templates_dir
,
config
[
'template'
]
+
'.tpl'
)
with
open
(
template_filename
,
'r'
)
as
template_text
:
template
=
Template
(
template_text
.
read
())
config_text
=
template
.
render
(
settings
=
config
[
'settings'
])
with
open
(
POSTFIX_MAIN_CF
,
'w+'
)
as
main_cf
:
main_cf
.
write
(
config_text
)
try
:
template_filename
=
path
.
join
(
templates_dir
,
config
[
'template'
]
+
'.tpl'
)
with
open
(
template_filename
,
'r'
)
as
template_text
:
template
=
Template
(
template_text
.
read
())
config_text
=
template
.
render
(
settings
=
config
[
'settings'
])
with
open
(
POSTFIX_MAIN_CF
,
'w+'
)
as
main_cf
:
main_cf
.
write
(
config_text
)
return
''
except
TemplateSyntaxError
as
exc
:
return
str
(
exc
)
##### Public classes #####
...
...
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