Update gen.py

This commit is contained in:
House of Vanity
2021-05-18 15:16:31 -07:00
committed by GitHub
parent 8262832c6b
commit fa7f5a5e2f

22
gen.py
View File

@ -1,3 +1,7 @@
#!/usr/bin/env python3
# Author: 'UltraDesu <ab@hexor.ru>'
# Home: https://github.com/house-of-vanity/Wireguard-Peer-Manager
import wgconfig # default iniparser cannot read WG configs. import wgconfig # default iniparser cannot read WG configs.
import logging import logging
import json import json
@ -23,7 +27,7 @@ my_parser = argparse.ArgumentParser()
my_parser.add_argument('--update', action='store_true', default=False) my_parser.add_argument('--update', action='store_true', default=False)
my_parser.add_argument('--peer', action='store', type=str) my_parser.add_argument('--peer', action='store', type=str)
my_parser.add_argument('--delete', action='store', type=str) my_parser.add_argument('--delete', action='store', type=str)
my_parser.add_argument('--config', action='store', type=str) my_parser.add_argument('--config', action='store', default='wg0', type=str)
## Reading config ## Reading config
# Execute the parse_args() method # Execute the parse_args() method
@ -32,14 +36,20 @@ peer_name = args.peer
del_name = args.delete del_name = args.delete
is_update = args.update is_update = args.update
wpm_config = configparser.ConfigParser() wpm_config = configparser.ConfigParser()
wpm_config.read('wpm.conf') if wpm_config.read('wpm.conf'):
ips = wpm_config['Interface'].get('allowed_ips', '0.0.0.0/0') ips = wpm_config['Interface'].get('allowed_ips', '0.0.0.0/0')
dns = wpm_config['Interface'].get('dns', '8.8.8.8/32') dns = wpm_config['Interface'].get('dns', '8.8.8.8/32')
hostname = wpm_config['Interface'].get('hostname', getfqdn()) hostname = wpm_config['Interface'].get('hostname', getfqdn())
config = args.config if args.config else (wpm_config['Interface'].get('config', 'wg0')) config = args.config if args.config else (wpm_config['Interface'].get('config', 'wg0'))
else:
ips = '0.0.0.0/0'
dns = '8.8.8.8/32'
hostname = getfqdn()
config = args.config
log.info('Using %s WG config file.', config) log.info('Using %s WG config file.', config)
class Peer: class Peer:
def __init__(self, peer=None, allowed_ips=None, comment='None'): def __init__(self, peer=None, allowed_ips=None, comment='None'):
self.comment = comment self.comment = comment