HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
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)