Esempio n. 1
0
 def __init__(self):
     self.log = logger.create_logger(self.__class__.__name__)
     self.default_gateways = []
     self.remove_old_format_backup()
     self._load_gateways()
     self.update_default_gateways()
     self._windows_seems_to_be_shutting_down = False
Esempio n. 2
0
 def __init__(self, pipe_dir, settings, conf_dir=None):
     self.log = logger.create_logger(self.__class__.__name__)
     self.tunnel = mtunnel.Tunnel(settings, conf_dir)
     self.tunnel.add_connection_listener(self.update_connection)
     self.tunnel.add_server_listener(self.update_server)
     self.tunnel.add_error_listener(self.update_error)
     self.request_pipe = open(os.path.join(pipe_dir, REQUEST_PIPE), 'r')
     self.reply_pipe = open(os.path.join(pipe_dir, REPLY_PIPE), 'w')
     self.update_pipe = open(os.path.join(pipe_dir, UPDATE_PIPE), 'w')
Esempio n. 3
0
 def __init__(self, server, keys=None,
              port=netcom.defaultPort, family=socket.AF_INET,
              timeout=10, connectTimeout=None):
     self.log = logger.create_logger(self.__class__.__name__)
     if keys is None:
         keys = ssl_keys.SSLKeys()
     self.ssl_keys = keys
     if connectTimeout is None:
         connectTimeout = timeout
     self.master = netcom.Client(
         server, port, family, timeout, connectTimeout)
Esempio n. 4
0
    def __init__(self):
        self.log = logger.create_logger(self.__class__.__name__)
        self.dns_pickle_path = _DEFAULT_DNS_PICKLE_PATH
        self.ipv4_re = '((\d{1,3}\.){3}\d{1,3})'
        self.ipv6_re = '(([0-9a-f]{0,4}:)+[0-9a-f]{1,4})(%\d+)?'

        self.ip_regex = {
            'ip': self.ipv4_re,
            'ipv4': self.ipv4_re,
            'ipv6': self.ipv6_re,
        }
Esempio n. 5
0
    def __init__(self, parser=None):
        """Create a new ReadOnlySettings.

        Args:
            parser: If given, this parser will be used to get values.
                    Will contain default values if not given.

        """
        self.log = logger.create_logger(self.__class__.__name__)
        if parser is None:
            self.parser = ReadOnlySettings._create_default_parser()
        else:
            self.parser = ReadOnlySettings._clone_parser(parser)
Esempio n. 6
0
    def __init__(self, directory=None):
        """Create a new Settings instance.

        Args:
            directory: Where to read/write settings.ini. If not given the path
                       module is used to determine location.
        """
        ReadOnlySettings.__init__(self)
        self.log = logger.create_logger(self.__class__.__name__)
        if directory is None:
            directory = paths.get_config_dir()
        self.path = os.path.join(directory, _SETTINGS_FILE)
        self.file_mtime = -1  # To keep track of on disk changes
        self._init_file()
Esempio n. 7
0
    def __init__(self, settings):
        self.log = logger.create_logger(self.__class__.__name__)
        self.settings = settings

        self.user_message = ''
        self.email_address = ''
        self.debug_log = self._remove_id_and_username(
            self._read_file(logger.get_debug_log_path()))
        self.debug_log_old = self._remove_id_and_username(
            self._read_file(logger.get_debug_log_backup_path()))
        self.openvpn_log = self._filtered_openvpn_log(
            logger.get_openvpn_path())
        self.openvpn_log_old = self._filtered_openvpn_log(
            logger.get_openvpn_backup_path())
        self.routes = self._get_routes()
        self.dns = self._get_dns()
Esempio n. 8
0
def main_args(args):
    if args.pipedir is not None:
        pipe_dir = args.pipedir
    else:
        print('--pipedir arg must be given', file=sys.stderr)
        sys.exit(1)

    logger.init(args.logdir)
    log = logger.create_logger('mtunnel_main')
    exceptioncatcher.activate(log)

    proc.kill_procs_by_name('mtunnel')  # Make sure we are alone.

    setup_file_paths()
    settings = config.Settings(directory=args.confdir)  # Using default if None
    tp = TunnelProcess(pipe_dir, settings, args.confdir)
    tp.run()
Esempio n. 9
0
 def __init__(self):
     self.log = logger.create_logger(self.__class__.__name__)
     self.has_ipv6 = self._has_ipv6()
     # Give the instance its own copies of the class variables to avoid
     # modifying the shared instance when adding the wait flag
     self.iptables = list(self.iptables)
     self.ip6tables = list(self.ip6tables)
     self.allowed_ip = None
     self.block_traffic_state = False
     self.block_ipv6_state = False
     try:
         self._check_commands()
         if self._supports_wait_flag():
             self.iptables.append(self.iptables_wait_flag)
             self.ip6tables.append(self.iptables_wait_flag)
         self._setup_chain()
     except OSError as e:
         raise FirewallError(e)
Esempio n. 10
0
 def __init__(self, pipe_dir):
     super(TunnelController, self).__init__()
     self.log = logger.create_logger(self.__class__.__name__)
     self.call_lock = threading.Lock()
     self.running = True
     self.connection_listeners = []
     self.server_listeners = []
     self.error_listeners = []
     self.tp = proc.open(
         ['pkexec', 'mtunnel',
          '--logdir', paths.get_log_dir(),
          '--confdir', paths.get_config_dir(),
          '--pipedir', pipe_dir],
         stream_target=None)
     self.request_pipe = open(os.path.join(pipe_dir, REQUEST_PIPE), 'w')
     self.reply_pipe = open(os.path.join(pipe_dir, REPLY_PIPE), 'r')
     self.update_pipe = open(os.path.join(pipe_dir, UPDATE_PIPE), 'r')
     self.start()
Esempio n. 11
0
    def __init__(self, key_base, sub_key):
        """Windows registry manipulating class.

        Args:
            key_base: A base key of the windows registry, for example:
                      _winreg.HKEY_CURRENT_USER
            sub_key: A string that is the key location, for example:
                     'Software\Microsoft\Windows\CurrentVersion\Run'
        """
        self.log = logger.create_logger(self.__class__.__name__)
        self.key_base = key_base
        self.sub_key = sub_key
        try:
            self.key_handle = _winreg.OpenKey(
                key_base, sub_key, 0,
                _winreg.KEY_QUERY_VALUE |
                _winreg.KEY_SET_VALUE |
                _winreg.KEY_ENUMERATE_SUB_KEYS)
        except WindowsError as e:
            err = unicode(str(e), errors='replace')
            self.log.error('Unable to open registry key %s, because: %s',
                           self, err)
            raise e
Esempio n. 12
0
 def __init__(self):
     self.log = logger.create_logger(self.__class__.__name__)
     self.saved_resolv_link_path = _DEFAULT_SAVED_RESOLV_LINK_PATH
     self.resolv_conf_path = _DEFAULT_RESOLV_CONF_PATH
Esempio n. 13
0
 def __init__(self):
     self.log = logger.create_logger(self.__class__.__name__)
     self.dns_pickle_path = _DEFAULT_DNS_PICKLE_PATH
Esempio n. 14
0
 def __init__(self):
     self.log = logger.create_logger(self.__class__.__name__)
     self.encode_encoding = self._get_encode_encoding()
     self.decode_encoding = self._get_decode_encoding()
     self.log.debug('Encoding with %s, decoding with %s',
                    self.encode_encoding, self.decode_encoding)
Esempio n. 15
0
 def __init__(self, gateway=None):
     self.log = logger.create_logger(self.__class__.__name__)
     if gateway is None:
         self.gw = _find_default_gateway()
     else:
         self.gw = gateway
Esempio n. 16
0
 def __init__(self):
     self.log = logger.create_logger(self.__class__.__name__)
Esempio n. 17
0
 def __init__(self, conf_dir=None):
     self.log = logger.create_logger(self.__class__.__name__)
     if conf_dir is None:
         conf_dir = paths.get_config_dir()
     self.ssl_dir = os.path.join(conf_dir, _SSL_KEY_DIR)
     paths.create_dir(self.ssl_dir)