费了半天劲,总算调试通了,以下两个函数,显示系统防火墙白名单ip列表,给白名单里增加新ip
- __BT_PANEL = 'https://*.*.*.*:34415'
- def get_firewall_rules(self):
- # 修改为使用新的IP规则列表接口
- url = self.__BT_PANEL + '/firewall/com/ip_rules_list'
- p_data = self.__get_key_data()
- p_data['chain'] = "ALL"
- p_data['p'] = 1 # 添加分页参数
- p_data['row'] = 30 # 获取足够多的规则
- result = self.__http_post_cookie(url, p_data)
- return json.loads(result) if result else {"data": []}
- def add_firewall_rule(self, ip):
- # 修改为使用新的设置IP规则接口
- url = self.__BT_PANEL + '/firewall/com/set_ip_rule'
- p_data = self.__get_key_data()
- # 构建符合新接口要求的参数
- p_data['types'] = 'accept'
- p_data['brief'] = 'API_ADD_HOME'
- p_data['address'] = ip
- p_data['chain'] = 'INPUT'
- p_data['family'] = 'ipv4'
- p_data['zone'] = 'public'
- p_data['operation'] = 'add'
- p_data['strategy'] = 'accept'
- result = self.__http_post_cookie(url, p_data)
- try:
- return json.loads(result)
- except:
- return {"status": False, "msg": result}
复制代码
|
|