def create_fn_local(self): if not self.debug: sys.stdout = open(fnlc_config.configs["access_log"], "a+") sys.stderr = open(fnlc_config.configs["error_log"], "a+") account = fnlc_config.configs["account"] self.__session_id = proto_utils.gen_session_id(account["username"], account["password"]) self.__tun_fd = self.create_handler(-1, tundev.tunlc, self.__TUN_NAME) if fnlc_config.configs["virtual_dns"] == fnlc_config.configs["remote_dns"]: raise ValueError("virtual_dns and remote_dns are same") args = ( fnlc_config.configs["virtual_dns"], fnlc_config.configs["remote_dns"] ) self.__nameserver = socket.inet_aton(fnlc_config.configs["virtual_dns"]) self.__dns_fd = self.create_handler(-1, dns_proxy.dnslc_proxy, *args, debug=self.debug) self.__update_host_rules() signal.signal(signal.SIGUSR1, self.__update_host_rules) # 设置DNS路由 cmd = "route add -host %s dev %s" % (fnlc_config.configs["virtual_dns"], self.__TUN_NAME) os.system(cmd)
def gen_session_id(self, username, password): """生成用户session id :param username: :param password: :return: """ return proto_utils.gen_session_id(username, password)
def session_id(self): if not self.__session_id: connection = self.__configs["connection"] username = connection["username"] passwd = connection["password"] self.__session_id = proto_utils.gen_session_id(username, passwd) return self.__session_id
def __init__(self): super(fdslightgw, self).__init__() self.set_mode("gateway") self.__timer = timer.timer() self.__routers = {} account = fngw_config.configs["account"] self.__session_id = proto_utils.gen_session_id(account["username"], account["password"])
def init(self): self.__sessions = {} dirname = os.path.dirname(__file__) path = "%s/../../fdslight_etc/default_auth.json" % dirname with open(path, "r") as f: data = f.read() user_info = json.loads(data) for user in user_info: name = user["username"] passwd = user["password"] session_id = proto_utils.gen_session_id(name, passwd) self.__sessions[session_id] = None return
def init_func(self, creator_fd, session_id, dns_fd, raw_socket_fd, raw6_socket_fd, debug=False, is_ipv6=False): self.__server = fngw_config.configs["udp_server_address"] name = "freenet.lib.crypto.%s" % fngw_config.configs[ "udp_crypto_module"]["name"] __import__(name) m = sys.modules.get(name, None) crypto_config = fngw_config.configs["udp_crypto_module"]["configs"] self.__encrypt_m = m.encrypt() self.__decrypt_m = m.decrypt() self.__encrypt_m.config(crypto_config) self.__decrypt_m.config(crypto_config) self.__debug = debug self.__session_id = session_id self.__traffic_send_fd = raw_socket_fd self.__traffic6_send_fd = raw6_socket_fd self.__conn_timeout = int(fngw_config.configs["timeout"]) if is_ipv6: s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) else: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.set_socket(s) self.__dns_fd = dns_fd self.dispatcher.bind_session_id(self.__session_id, self.fileno, "udp") try: self.connect(self.__server) except socket.gaierror: self.close() return -1 ipaddr, _ = s.getpeername() self.__server_ipaddr = ipaddr self.__init() self.__conn_time = time.time() self.register(self.fileno) self.add_evt_read(self.fileno) account = fngw_config.configs["account"] self.__session_id = proto_utils.gen_session_id(account["username"], account["password"]) self.set_timeout(self.fileno, self.__LOOP_TIMEOUT) return self.fileno