Exemplo n.º 1
0
 def load_defaults(self):
     """Load default config options.
     """
     # Settings
     self.settings = {}
     self.settings['name'] = None
     self.settings['geoip_data'] = None
     self.settings['datetime_format'] = '%d/%m/%Y %H:%M:%S'
     # VPN(s)
     self.vpns = []
     vpn = VPN(host='localhost', port=5555)
     vpn.name = 'Default VPN'
     vpn.allow_disconnect = True
     self.vpns.append(vpn)
Exemplo n.º 2
0
 def _parse_file(self, filename):
     config = configparser.RawConfigParser()
     logger.info('Parsing config file: %s', filename)
     contents = config.read(filename)
     if not contents:
         raise InvalidConfigError(
             'Unable to read config file: {}'.format(filename))
     if 'Monitor' not in config.sections():
         raise InvalidConfigError(
             "'Monitor' section required, but not found in config")
     # Parse 'Monitor' section
     monitor = config['Monitor']
     self.settings['name'] = monitor.get('name')
     self.settings['geoip_data'] = monitor.get('geoip_data')
     self.settings['datetime_format'] = monitor.get('datetime_format',
                                                    '%d/%m/%Y %H:%M:%S')
     # Parse other (VPN) sections
     for s in [s for s in config.sections() if s != 'Monitor']:
         section = config[s]
         # Compulsory
         host = section.get('host')
         try:
             port = section.getint('port')
         except ValueError:
             port = None
         socket = section.get('socket')
         if (socket and host) or (socket
                                  and port) or (not socket and not host
                                                and not port):
             raise InvalidConfigError(
                 'Must specify either socket or host and port')
         if socket:
             vpn = VPN(socket=socket)
         else:
             vpn = VPN(host=host, port=port)
         vpn.name = s
         # Optional
         try:
             vpn.allow_disconnect = section.getboolean(
                 'allow_disconnect', True)
         except configparser.NoOptionError:
             pass
         # Add VPN
         self.vpns.append(vpn)