def __init__(self): super(Stateful_thread, self).__init__() self.os_type = common.get_os_type() self.checks = checks.Checks() self.controlchannel = controlchannel.ControlChannel() # control message handlers self.cmh_struct = { # num : [string to look for, function, server(1) or client(0), return on success, return on failure] # return value meanings: True - module continues # False - module thread terminates # in case of Stateless modules, the whole module terminates if the return value is False 0 : [common.CONTROL_CHECK, self.controlchannel.cmh_check_query, 1, True, False], 1 : [common.CONTROL_CHECK_RESULT, self.controlchannel.cmh_check_check, 0, True, False], 2 : [common.CONTROL_AUTH, self.controlchannel.cmh_auth, 1, True, False], 3 : [common.CONTROL_AUTH_OK, self.controlchannel.cmh_auth_ok, 0, True, False], 4 : [common.CONTROL_AUTH_NOTOK, self.controlchannel.cmh_auth_not_ok, 0, True, False], 5 : [common.CONTROL_LOGOFF, self.controlchannel.cmh_logoff, 1, False, False] } self.packet_writer = self.packet_writer_default self.packet_reader = self.packet_reader_default self.communication = self.communication_unix if self.os_type == common.OS_WINDOWS: self.packet_writer = self.packet_writer_win self.communication = self.communication_win self.packet_reader = None if self.os_type == common.OS_MACOSX: self.packet_writer = self.packet_writer_mac self.packet_reader = self.packet_reader_mac return
def __init__(self, tunnel): threading.Thread.__init__(self) self.timeout = 1.0 # seems to be a good value for timeout self.clients = [] self.tunnel = tunnel self._stop = False self.os_type = common.get_os_type() if self.os_type == common.OS_WINDOWS: self.run_ps_mainloop = self.run_windows else: self.run_ps_mainloop = self.run_unix
def __init__(self): super(Stateful_thread, self).__init__() self.os_type = common.get_os_type() self.checks = checks.Checks() self.controlchannel = controlchannel.ControlChannel() # control message handlers self.cmh_struct = { # num : [string to look for, function, server(1) or client(0), return on success, return on failure] # return value meanings: True - module continues # False - module thread terminates # in case of Stateless modules, the whole module terminates if the return value is False 0: [ common.CONTROL_CHECK, self.controlchannel.cmh_check_query, 1, True, False ], 1: [ common.CONTROL_CHECK_RESULT, self.controlchannel.cmh_check_check, 0, True, False ], 2: [ common.CONTROL_INIT, self.controlchannel.cmh_init, 1, True, False ], 3: [ common.CONTROL_INIT_DONE, self.controlchannel.cmh_init_done, 0, True, False ], 4: [ common.CONTROL_LOGOFF, self.controlchannel.cmh_logoff, 1, False, False ], } # reading/writing packets can be different based on the OS self.packet_writer = self.packet_writer_default self.packet_reader = self.packet_reader_default # different communication function for Unix and Windows self.communication = self.communication_unix # setting up for Windows if self.os_type == common.OS_WINDOWS: self.packet_writer = self.packet_writer_win self.communication = self.communication_win self.packet_reader = None # setting up for MacOS(X) if self.os_type == common.OS_MACOSX: self.packet_writer = self.packet_writer_mac self.packet_reader = self.packet_reader_mac return
def get_nameserver(self): if common.get_os_type() == common.OS_LINUX: f = open("/etc/resolv.conf", "r") content = f.read() f.close() for line in content.split("\n"): if line.replace(" ", "").replace("\t", "")[0:1] == "#": continue if line.find("nameserver") != -1: break nameserver = line[line.find("nameserver")+len("nameserver "):len(line)+line.find("nameserver")] if common.is_ipv4(nameserver) or common.is_ipv6(nameserver): return nameserver else: return None
def __init__(self): self._stop = False self.os_type = common.get_os_type() return
def __init__(self): OSFP_table = { # OS type : [__init__(), tun_alloc(), set_ip_address(), # set_mtu(), close_tunnel(), check_default_route(), # set_default_route(), set_intermediate_route(), restore_routes()] common.OS_LINUX: [ self.lin_init, self.lin_tun_alloc, self.lin_set_ip_address, self.lin_set_mtu, self.lin_close_tunnel, self.lin_check_default_route, self.lin_set_default_route, self.lin_set_intermediate_route, self.lin_restore_routes, self.lin_set_split_route, self.lin_del_split_route ], common.OS_MACOSX: [ self.mac_init, self.mac_tun_alloc, self.mac_set_ip_address, self.mac_set_mtu, self.mac_close_tunnel, self.mac_check_default_route, self.mac_set_default_route, self.mac_set_intermediate_route, self.mac_restore_routes, self.mac_set_split_route, self.mac_del_split_route ], common.OS_WINDOWS: [ self.win_init, self.win_tun_alloc, self.win_set_ip_address, self.win_set_mtu, self.win_close_tunnel, self.win_check_default_route, self.win_set_default_route, self.win_set_intermediate_route, self.win_restore_routes, self.win_set_split_route, self.win_del_split_route ], } os_type = common.get_os_type() if not (os_type in OSFP_table): common.internal_print( "Your operating system is not supported yet. (interface.py)", -1) sys.exit(-1) # calling OS specific __init__() OSFP_table[os_type][0]() # replacing placeholders with OS specific calls # allocating tunnel, clonde device and name it self.tun_alloc = OSFP_table[os_type][1] # setting IP address + netmask on the interface self.set_ip_address = OSFP_table[os_type][2] # setting MTU on the interface self.set_mtu = OSFP_table[os_type][3] # closing tunnel file descriptor self.close_tunnel = OSFP_table[os_type][4] # check if more than one or no default route is present self.check_default_route = OSFP_table[os_type][5] # automatic routing set up. # check for multiple default routes, if there are then print error message # - save default route address # - delete default route # - add default route, route all packets into the XFLTReaT interface # - last route: server IP address routed over the original default route self.set_default_route = OSFP_table[os_type][6] # setting up intermediate route # when the module needs an intermediate hop (DNS server, Proxy server) # then all encapsulated packet should be sent to the intermediate server # instead of the XFLTReaT server self.set_intermediate_route = OSFP_table[os_type][7] # restoring default route self.restore_routes = OSFP_table[os_type][8] # set split routes self.set_split_route = OSFP_table[os_type][9] # del split routes self.del_split_route = OSFP_table[os_type][10]