You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.7 KiB
50 lines
1.7 KiB
#request工具类,来处理curl、http、https的页面访问等处理逻辑,后期考虑wget等
|
|
import requests
|
|
from tools.ToolBase import ToolBase
|
|
|
|
class RequestTool(ToolBase):
|
|
def validate_instruction(self, instruction_old):
|
|
#指令过滤
|
|
|
|
return instruction_old
|
|
|
|
def execute_instruction(self, instruction_old):
|
|
'''
|
|
执行指令:验证合法性 -> 执行 -> 分析结果
|
|
:param instruction_old:
|
|
:return:
|
|
bool:true-正常返回给大模型,false-结果不返回给大模型
|
|
str:执行的指令
|
|
str:执行指令的结果
|
|
'''
|
|
ext_params = self.create_extparams()
|
|
# 第一步:验证指令合法性
|
|
instruction,time_out = self.validate_instruction(instruction_old)
|
|
if not instruction:
|
|
return False,instruction_old,"该指令暂不执行!","",ext_params
|
|
# 第二步:执行指令
|
|
if instruction_old.startswith("curl"):
|
|
parts = instruction_old.split()
|
|
for i, part in enumerate(parts):
|
|
if part == "-H" and i + 1 < len(parts):
|
|
target = parts[i + 1]
|
|
elif instruction_old.startswith("http"):
|
|
pass
|
|
else:
|
|
print(f"{instruction_old}暂不支持")
|
|
return False, instruction_old, "该指令暂不执行!","",ext_params
|
|
|
|
# 第三步:分析执行结果
|
|
analysis = self.analyze_result(output,instruction)
|
|
#指令和结果入数据库
|
|
#?
|
|
return True,instruction, analysis,"",ext_params
|
|
|
|
|
|
def analyze_result(self, result,instruction):
|
|
#指令结果分析
|
|
|
|
return result
|
|
|
|
if __name__ == "__main__":
|
|
RT = RequestTool()
|
|
|