File: /volume1/@appstore/HyperBackup/bin/backupconf.py
#!/usr/bin/env python
import sys
import json
import re
from collections import OrderedDict
conf_file = "/usr/syno/etc/synobackup.conf"
sensitive_key = ['remote_pass', 'remote_secret', 'remote_access_token', 'remote_refresh_token']
with open(conf_file) as conf:
session = None
total_dict = OrderedDict()
sess_dict = OrderedDict()
for line in conf.readlines():
line = line.rstrip()
if re.match('\[.*\]', line):
if session:
total_dict[session] = sess_dict.copy()
sess_dict.clear()
session = line.strip('[]')
else:
try:
key, value = line.split('=', 1)
except ValueError:
continue
if key and value and key not in sensitive_key:
sess_dict[key] = json.loads(value)
if session:
total_dict[session] = sess_dict.copy()
print json.dumps(total_dict)