2020-07-14 00:59:16 +00:00
|
|
|
import configparser
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
2020-08-09 20:30:44 +00:00
|
|
|
CONFDIR = '/home/phablet/.config/pantalaimon/'
|
|
|
|
CONFFILE = 'pantalaimon.conf'
|
2020-07-14 00:59:16 +00:00
|
|
|
|
|
|
|
def load():
|
|
|
|
entries = []
|
|
|
|
|
2020-08-09 20:30:44 +00:00
|
|
|
if os.path.exists(CONFDIR + CONFFILE):
|
2020-07-14 00:59:16 +00:00
|
|
|
config = configparser.ConfigParser()
|
2020-08-09 20:30:44 +00:00
|
|
|
config.read_file(open(CONFDIR + CONFFILE))
|
2020-07-14 00:59:16 +00:00
|
|
|
|
|
|
|
for instance in config.sections():
|
|
|
|
item = {'name': instance}
|
|
|
|
item['homeserver'] = config[instance].get('homeserver')
|
|
|
|
item['listenaddress'] = config[instance].get('listenaddress')
|
|
|
|
item['listenport'] = config[instance].get('listenport')
|
|
|
|
item['ignoreverification'] = config[instance].get('ignoreverification')
|
|
|
|
item['usekeyring'] = config[instance].get('usekeyring')
|
|
|
|
|
|
|
|
entries.append(item)
|
|
|
|
|
|
|
|
return entries
|
|
|
|
|
|
|
|
def save(data):
|
|
|
|
logging.debug("save config")
|
|
|
|
dataobj = json.loads(data)
|
|
|
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
|
|
|
for item in dataobj:
|
|
|
|
config[item['name']] = {}
|
|
|
|
config[item['name']]['homeserver'] = item['homeserver']
|
|
|
|
config[item['name']]['listenaddress'] = "127.0.0.1"
|
|
|
|
config[item['name']]['listenport'] = item['listenport']
|
|
|
|
config[item['name']]['ignoreverification'] = "true"
|
|
|
|
config[item['name']]['usekeyring'] = "false"
|
|
|
|
|
2020-08-09 20:30:44 +00:00
|
|
|
if not os.path.exists(CONFDIR):
|
|
|
|
os.makedirs(CONFDIR)
|
|
|
|
|
|
|
|
with open(CONFDIR + CONFFILE,'w') as configfile:
|
2020-07-14 00:59:16 +00:00
|
|
|
config.write(configfile)
|
|
|
|
|