def list(loadpath=None): all_modules_config = Xcache.list_moduleconfigs() if all_modules_config is None: PostModuleConfig.load_all_modules_config() all_modules_config = Xcache.list_moduleconfigs() # 删除内部模块 for one in all_modules_config[:]: if one.get('MODULETYPE') == TAG2CH.internal: all_modules_config.remove(one) if loadpath is None: for one in all_modules_config: one['OPTIONS'] = [] context = list_data_return(200, CODE_MSG.get(200), all_modules_config) return context else: for one_module_config in all_modules_config: if one_module_config.get('loadpath') == loadpath: # 动态处理handler和凭证选项 new_module_config = PostModuleConfig._deal_dynamic_option( one_module_config=one_module_config) context = dict_data_return(200, CODE_MSG.get(200), new_module_config) return context # 没有找到模块 context = dict_data_return(200, CODE_MSG.get(200), {}) return context
def destory(id): try: model = WebsiteCDNModel.objects.get(id=id) model.delete() CODE = 204 context = dict_data_return(CODE, CODE_MESSAGE.get(CODE), {}) except Exception as E: CODE = 404 context = dict_data_return(CODE, CODE_MESSAGE.get(CODE), {}) return context
def destory(id): try: model = IPaddressModel.objects.get(id=id) model.delete() Port.destory_by_ipid(id) CODE = 204 context = dict_data_return(CODE, CODE_MESSAGE.get(CODE), {}) except Exception as E: CODE = 404 context = dict_data_return(CODE, CODE_MESSAGE.get(CODE), {}) return context
def create_bot(ipportlist=None, custom_param=None, loadpath=None): module_config = Xcache.get_moduleconfig(loadpath) # 获取模块配置 if module_config is None: context = dict_data_return(305, PostModuleActuator_MSG.get(305), {}) return context # 处理模块参数 try: custom_param = json.loads(custom_param) except Exception as E: logger.warning(E) custom_param = {} # 获取模块实例 group_uuid = str(uuid.uuid1()).replace('-', "") class_intent = importlib.import_module(loadpath) for ipport in ipportlist: post_module_intent = class_intent.PostModule( ip=ipport.get("ip"), port=ipport.get("port"), protocol=ipport.get("protocol"), custom_param=custom_param) # 模块前序检查,调用check函数 try: flag, msg = post_module_intent.check() if flag is not True: # 如果检查未通过,返回未通过原因(msg) Notices.send_warning( f"模块:{post_module_intent.NAME} IP:{ipport.get('ip')} 检查未通过,原因:{msg}" ) continue except Exception as E: logger.warning(E) Notices.send_warning( f"模块:{post_module_intent.NAME} IP:{ipport.get('ip')} 检查函数执行异常" ) continue tmp_self_uuid = str(uuid.uuid1()) req = { 'uuid': tmp_self_uuid, 'group_uuid': group_uuid, 'broker': post_module_intent.MODULE_BROKER, 'module': post_module_intent, 'time': int(time.time()), } Xcache.putin_bot_wait(req) context = dict_data_return(201, PostModuleActuator_MSG.get(201), {}) return context
def destory(id): try: model = WebsiteModel.objects.get(id=id) model.delete() # 删除关联表 WebsiteTech.destory_by_wid(id) WebsiteWaf.destory_by_wid(id) WebsiteCDN.destory_by_wid(id) CODE = 204 context = dict_data_return(CODE, CODE_MESSAGE.get(CODE), {}) except Exception as E: CODE = 404 context = dict_data_return(CODE, CODE_MESSAGE.get(CODE), {}) return context
def list(hid=None, loadpath=None): host = Host.get_by_hid(hid) result = Xcache.get_module_result(ipaddress=host.get("ipaddress"), loadpath=loadpath) result_dict = { "hid": hid, "loadpath": loadpath, "update_time": result.get("update_time"), "result": result.get("result") } context = dict_data_return(200, CODE_MSG.get(200), result_dict) return context
def destory(): Xcache.del_module_result_history() context = dict_data_return(204, PostModuleResultHistory_MSG.get(204), {}) return context
def create_post(loadpath=None, sessionid=None, hid=None, custom_param=None): module_config = Xcache.get_moduleconfig(loadpath) # 获取模块配置 if module_config is None: context = dict_data_return(305, PostModuleActuator_MSG.get(305), {}) return context # 处理模块参数 try: custom_param = json.loads(custom_param) except Exception as E: logger.warning(E) custom_param = {} # 获取模块实例 class_intent = importlib.import_module(loadpath) post_module_intent = class_intent.PostModule(sessionid, hid, custom_param) # 模块前序检查,调用check函数 try: flag, msg = post_module_intent.check() if flag is not True: # 如果检查未通过,返回未通过原因(msg) context = dict_data_return(405, msg, {}) return context except Exception as E: logger.warning(E) context = dict_data_return(301, PostModuleActuator_MSG.get(301), {}) return context try: broker = post_module_intent.MODULE_BROKER except Exception as E: logger.warning(E) context = dict_data_return(305, PostModuleActuator_MSG.get(305), {}) return context if broker == BROKER.post_python_job: # 放入多模块队列 if aps_module.putin_post_python_module_queue(post_module_intent): context = dict_data_return(201, PostModuleActuator_MSG.get(201), {}) return context else: context = dict_data_return(306, PostModuleActuator_MSG.get(306), {}) return context elif broker == BROKER.post_msf_job: # 放入后台运行队列 if MSFModule.putin_post_msf_module_queue(post_module_intent): context = dict_data_return(201, PostModuleActuator_MSG.get(201), {}) return context else: context = dict_data_return(306, PostModuleActuator_MSG.get(306), {}) return context else: logger.warning("错误的broker")