(self, status = False)
禁止BT设置
禁止BT设置
禁止BT设置
def write_ban_bittorrent(self, status = False):
        '''
        禁止BT设置
        '''
        conf_rules = self.config["routing"]["rules"]
        if status:
            for group in self.group_list:
                if "sniffing" not in self.config["inbounds"][group.index]:
                    self.config["inbounds"][group.index].update({
                        "sniffing": {
                            "enabled": True,
                            "destOverride": ["http", "tls"]
                        }
                    })
            has_rule = False
            for rule in conf_rules:
                if "protocol" in rule and "bittorrent" in rule["protocol"]:
                    has_rule = True
                    break
            if not has_rule:
                self.config["routing"]["rules"].append(
                    {
                        "type": "field",
                        "outboundTag": "blocked",
                        "protocol": [
                            "bittorrent"
                        ]
                    }
                )
        else:
            for group in self.group_list:
                if "sniffing" in self.config["inbounds"][group.index]:
                    del self.config["inbounds"][group.index]["sniffing"]

            for index, rule in enumerate(conf_rules):
                if "protocol" in rule and "bittorrent" in rule["protocol"]:
                    del self.config["routing"]["rules"][index]

        self.save()
def write_ban_bittorrent ( self , status = False ) : conf_rules = self . config [ "routing" ] [ "rules" ] if status : for group in self . group_list : if "sniffing" not in self . config [ "inbounds" ] [ group . index ] : self . config [ "inbounds" ] [ group . index ] . update ( { "sniffing" : { "enabled" : True , "destOverride" : [ "http" , "tls" ] } } ) has_rule = False for rule in conf_rules : if "protocol" in rule and "bittorrent" in rule [ "protocol" ] : has_rule = True break if not has_rule : self . config [ "routing" ] [ "rules" ] . append ( { "type" : "field" , "outboundTag" : "blocked" , "protocol" : [ "bittorrent" ] } ) else : for group in self . group_list : if "sniffing" in self . config [ "inbounds" ] [ group . index ] : del self . config [ "inbounds" ] [ group . index ] [ "sniffing" ] for index , rule in enumerate ( conf_rules ) : if "protocol" in rule and "bittorrent" in rule [ "protocol" ] : del self . config [ "routing" ] [ "rules" ] [ index ] self . save ( )