Commit 487a9a69 authored by Ad Schellevis's avatar Ad Schellevis

(ids) write yaml file for installed rules

parent 0cd3480d
...@@ -38,6 +38,7 @@ RuleCache = rulecache.RuleCache() ...@@ -38,6 +38,7 @@ RuleCache = rulecache.RuleCache()
rule_config_fn = ('%s../rules.config'%RuleCache.rule_source_dir) rule_config_fn = ('%s../rules.config'%RuleCache.rule_source_dir)
rule_target_dir = ('%s../opnsense.rules'%RuleCache.rule_source_dir) rule_target_dir = ('%s../opnsense.rules'%RuleCache.rule_source_dir)
rule_yaml_list = ('%s../installed_rules.yaml'%RuleCache.rule_source_dir)
# parse OPNsense rule config # parse OPNsense rule config
rule_updates = {} rule_updates = {}
...@@ -56,6 +57,7 @@ if not os.path.exists(rule_target_dir): ...@@ -56,6 +57,7 @@ if not os.path.exists(rule_target_dir):
os.mkdir(rule_target_dir, 0o755) os.mkdir(rule_target_dir, 0o755)
# install ruleset # install ruleset
all_installed_files = []
for filename in RuleCache.listLocal(): for filename in RuleCache.listLocal():
output_data = [] output_data = []
for rule_info_record in RuleCache.listRules(filename=filename): for rule_info_record in RuleCache.listRules(filename=filename):
...@@ -79,4 +81,13 @@ for filename in RuleCache.listLocal(): ...@@ -79,4 +81,13 @@ for filename in RuleCache.listLocal():
output_data.append(rule) output_data.append(rule)
# write data to file # write data to file
all_installed_files.append(filename.split('/')[-1])
open('%s/%s'%(rule_target_dir, filename.split('/')[-1]), 'wb').write('\n'.join(output_data)) open('%s/%s'%(rule_target_dir, filename.split('/')[-1]), 'wb').write('\n'.join(output_data))
# flush all written rule filenames into yaml file
with open(rule_yaml_list,'wb') as f_out:
f_out.write('%YAML 1.1\n')
f_out.write('---\n')
f_out.write('rule-files:\n')
for installed_file in all_installed_files:
f_out.write(' - %s\n'%installed_file)
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