Add access table generation for postfix

parent 6bb1b51d
...@@ -25,6 +25,21 @@ POSTFIX_MAIN_CF = "/etc/postfix/main.cf" ...@@ -25,6 +25,21 @@ POSTFIX_MAIN_CF = "/etc/postfix/main.cf"
##### Private classes ##### ##### Private classes #####
class Postfix(service.FunctionObject) : class Postfix(service.FunctionObject) :
### DBus methods ### ### DBus methods ###
@service.functionMethod(POSTFIX_METHODS_NAMESPACE, in_signature="ss")
def generateAccessTable(self, filters_file_path, access_file_path):
with open(filters_file_path, 'r') as filters_file:
lists = safe_load(filters_file.read())
entries = []
for item in lists['whitelist']:
entries.append([item['key'], 'OK'])
for item in lists['blacklist']:
entries.append([item['key'], item['action'].upper()])
with open(access_file_path, 'w+') as access_file:
access_file.write('\n'.join([ ' '.join(pair) for pair in entries ]))
@service.functionMethod(POSTFIX_METHODS_NAMESPACE, in_signature="ss", out_signature="s") @service.functionMethod(POSTFIX_METHODS_NAMESPACE, in_signature="ss", out_signature="s")
def regenerateMainCf(self, config_filename, templates_dir): def regenerateMainCf(self, config_filename, templates_dir):
with open(config_filename, 'r') as postfix_config: with open(config_filename, 'r') as postfix_config:
......
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