Beispiel #1
0
    def create_fn_gw(self):
        os.chdir("driver")
        if not os.path.isfile("fdslight.ko"):
            print("you must install this software")
            sys.exit(-1)

        path = "/dev/%s" % fdsl_ctl.FDSL_DEV_NAME
        if os.path.exists(path): os.system("rmmod fdslight")

        # 开启ip forward
        os.system("echo 1 > /proc/sys/net/ipv4/ip_forward")
        # 禁止接收ICMP redirect 包,防止客户端机器选择最佳路由
        os.system(
            "echo 0 | tee /proc/sys/net/ipv4/conf/*/send_redirects > /dev/null"
        )
        os.system("insmod fdslight.ko")
        os.chdir("../")

        if not self.debug:
            sys.stdout = open(fngw_config.configs["access_log"], "a+")
            sys.stderr = open(fngw_config.configs["error_log"], "a+")

        host_rules = file_parser.parse_host_file("fdslight_etc/host_rules.txt")

        self.__tun_fd = self.create_handler(-1, tundev.tungw, self.__TUN_NAME)
        self.__dns_fd = self.create_handler(-1,
                                            dns_proxy.dnsgw_proxy,
                                            self.__session_id,
                                            host_rules,
                                            debug=self.debug)
        self.get_handler(self.__dns_fd).set_dns_id_max(
            int(fngw_config.configs["max_dns_request"]))

        signal.signal(signal.SIGUSR1, self.__update_host_rules)
Beispiel #2
0
    def __create_fn_client(self):
        if not self.__debug: create_pid_file(FDSL_PID_FILE, os.getpid())
        self.create_poll()

        os.chdir("driver")
        if not os.path.isfile("fdslight.ko"):
            print("you must install this software")
            sys.exit(-1)

        path = "/dev/%s" % fdsl_ctl.FDSL_DEV_NAME
        if os.path.exists(path): os.system("rmmod fdslight")

        # 开启ip forward
        os.system("echo 1 > /proc/sys/net/ipv4/ip_forward")
        # 禁止接收icmo redirect 包,防止客户端机器选择最佳路由
        os.system("echo 0 | tee /proc/sys/net/ipv4/conf/*/send_redirects")
        os.system("insmod fdslight.ko")
        os.chdir("../")

        whitelist = file_parser.parse_ip_subnet_file("fdslight_etc/whitelist.txt")
        blacklist = file_parser.parse_host_file("fdslight_etc/blacklist.txt")

        self.__dnsc_fd = self.create_handler(-1, dns_proxy.dns_proxy, blacklist, debug=self.__debug)

        name_tcp = "freenet.tunnelc.%s" % fnc_config.configs["tcp_tunnel"]
        name_udp = "freenet.tunnelc.%s" % fnc_config.configs["udp_tunnel"]

        if fnc_config.configs["tunnel_type"].lower() == "udp":
            name = name_udp
        else:
            name = name_tcp

        __import__(name)
        self.__tunnelc = sys.modules[name]
        self.create_handler(-1, self.__tunnelc.tunnel, self.__dnsc_fd, whitelist, debug=self.__debug)
Beispiel #3
0
    def __create_fn_client(self):
        if not self.__debug: create_pid_file(FDSL_PID_FILE, os.getpid())
        self.create_poll()

        os.chdir("driver")
        if not os.path.isfile("fdslight.ko"):
            print("you must install this software")
            sys.exit(-1)

        path = "/dev/%s" % fdsl_ctl.FDSL_DEV_NAME
        if os.path.exists(path):
            os.system("rmmod fdslight")

        os.system("insmod fdslight.ko")

        os.chdir("../")

        whitelist = file_parser.parse_ip_subnet_file("fdslight_etc/whitelist.txt")
        blacklist = file_parser.parse_host_file("fdslight_etc/blacklist.txt")

        self.__dnsc_fd = self.create_handler(-1, dns_proxy.dns_proxy, blacklist, debug=self.__debug)

        name_tcp = "freenet.tunnelc.%s" % fnc_config.configs["tcp_tunnel"]
        name_udp = "freenet.tunnelc.%s" % fnc_config.configs["udp_tunnel"]

        if fnc_config.configs["tunnel_type"].lower() == "udp":
            name = name_udp
        else:
            name = name_tcp

        __import__(name)
        self.__tunnelc = sys.modules[name]
        self.create_handler(-1, self.__tunnelc.tunnel, self.__dnsc_fd, whitelist, debug=self.__debug)
Beispiel #4
0
    def __update_rules(self, signum, frame):
        """更新白名单规则
        :param signum:
        :param frame:
        :return:
        """
        host_rules = file_parser.parse_host_file(self.__host_rules_path)
        ip_rules = file_parser.parse_ip_subnet_file(self.__ip_rules_path)
        udp_src_rules = file_parser.parse_ip_subnet_file(
            self.__udp_src_proxy_path)

        for rule in host_rules:
            self.__domain_match.add_rule(rule)
        for subnet, prefix in ip_rules:
            rs = self.__ip_match.add_rule(subnet, prefix)
            if not rs:
                sys.stderr.write("wrong ip format at %s/%s from %s" %
                                 (subnet, prefix, self.__ip_rules_path))
                sys.stderr.flush()
            ''''''
        for subnet, prefix in udp_src_rules:
            rs = self.__udp_src_match.add_rule(subnet, prefix)
            if not rs:
                sys.stderr.write("wrong ip format at %s/%s from %s" %
                                 (subnet, prefix, self.__udp_src_proxy_path))
                sys.stderr.flush()
            ''''''
        return
Beispiel #5
0
    def __set_host_rules(self, signum, frame):
        fpath = "%s/fdslight_etc/host_rules.txt" % BASE_DIR

        if not os.path.isfile(fpath):
            print("cannot found host_rules.txt")
            self.__exit(signum, frame)

        rules = file_parser.parse_host_file(fpath)
        self.get_handler(self.__dns_fileno).set_host_rules(rules)
Beispiel #6
0
    def __set_host_rules(self, signum, frame):
        fpath = "%s/fdslight_etc/host_rules.txt" % BASE_DIR

        if not os.path.isfile(fpath):
            print("cannot found host_rules.txt")
            self.__exit(signum, frame)

        rules = file_parser.parse_host_file(fpath)
        self.get_handler(self.__dns_fileno).set_host_rules(rules)
Beispiel #7
0
    def __set_host_rules(self, signum, frame):
        fpath = "%s/fdslight_etc/host_rules.txt" % BASE_DIR

        if not os.path.isfile(fpath):
            print("cannot found host_rules.txt")
            self.__exit(signum, frame)

        rules = file_parser.parse_host_file(fpath)
        for rule in rules:
            self.__host_match.add_rule(rule)
Beispiel #8
0
    def __set_rules(self, signum, frame):
        fpaths = [
            "%s/fdslight_etc/host_rules.txt" % BASE_DIR,
            "%s/fdslight_etc/ip_rules.txt" % BASE_DIR,
            "%s/fdslight_etc/pre_load_ip_rules.txt" % BASE_DIR
        ]

        for fpath in fpaths:
            if not os.path.isfile(fpath):
                sys.stderr.write("cannot found %s\r\n" % fpath)
                return
        try:
            rules = file_parser.parse_host_file(fpaths[0])
            self.get_handler(self.__dns_fileno).set_host_rules(rules)

            rules = file_parser.parse_ip_subnet_file(fpaths[1])
            self.get_handler(self.__dns_fileno).set_ip_rules(rules)

            rules = file_parser.parse_ip_subnet_file(fpaths[2])
            self.__set_static_ip_rules(rules)

        except file_parser.FilefmtErr:
            logging.print_error()
Beispiel #9
0
    def __create_fn_client(self):
        if not self.__debug: create_pid_file(FDSL_PID_FILE, os.getpid())
        self.create_poll()

        os.chdir("driver")
        if not os.path.isfile("fdslight.ko"):
            print("you must install this software")
            sys.exit(-1)

        path = "/dev/%s" % fdsl_ctl.FDSL_DEV_NAME
        if os.path.exists(path): os.system("rmmod fdslight")

        # 开启ip forward
        os.system("echo 1 > /proc/sys/net/ipv4/ip_forward")
        # 禁止接收ICMP redirect 包,防止客户端机器选择最佳路由
        os.system("echo 0 | tee /proc/sys/net/ipv4/conf/*/send_redirects")
        os.system("insmod fdslight.ko")
        os.chdir("../")

        whitelist = file_parser.parse_ip_subnet_file("fdslight_etc/whitelist.txt")
        blacklist = file_parser.parse_host_file("fdslight_etc/blacklist.txt")

        self.__dnsc_fd = self.create_handler(-1, dns_proxy.dns_proxy, blacklist, debug=self.__debug)
        self.__raw_socket_fd = self.create_handler(-1, traffic_pass.traffic_send)

        name_tcp = "freenet.tunnelc.%s" % fnc_config.configs["tcp_tunnel"]
        name_udp = "freenet.tunnelc.%s" % fnc_config.configs["udp_tunnel"]

        if fnc_config.configs["tunnel_type"].lower() == "udp":
            name = name_udp
        else:
            name = name_tcp

        __import__(name)
        self.__tunnelc = sys.modules[name]
        self.create_handler(-1, self.__tunnelc.tunnel, self.__dnsc_fd, self.__raw_socket_fd,
                            whitelist, debug=self.__debug)
Beispiel #10
0
 def __update_host_rules(self, signum, frame):
     host_rules = file_parser.parse_host_file("fdslight_etc/host_rules.txt")
     self.get_handler(self.__dns_fd).update_host_rules(host_rules)