def dropConnection(request): name = request.POST['device_name'] conns = request.POST.getlist('interface_id') inter_id = {} inter_id_print = {} not_empty_sign = 0 if conns == []: results = {'msg': '删除设备连接成功'} return JsonResponse(results) for iid in range(1, INTERFACE_NUM + 1): iid = str(iid) inf = 'interface' + iid ip = DeviceTopology.objects.get( device_name=name).serializable_value(inf) if iid in conns: inter_id[inf] = None inter_id_print[inf] = ip elif ip != None: not_empty_sign = 1 if not not_empty_sign: DeviceTopology.objects.get(device_name=name).delete() else: DeviceTopology.objects.filter(device_name=name).update(**inter_id) results = {'msg': '删除设备连接成功', 'detail': inter_id_print} if not DeviceTopology.objects.all().exists(): reset.reset_auto_increment('attack_demo_devicetopology') return JsonResponse(results)
def deleteScript(request): s_id = request.POST['id'] obj = AttackScript.objects.filter(pk=int(s_id)) info = obj.values()[0] obj.delete() results = {'msg': '删除脚本成功', 'detail': info} if not AttackScript.objects.all().exists(): reset.reset_auto_increment('attack_demo_attackscript') return JsonResponse(results)
def scriptsInit(request): AttackScript.objects.all().delete() reset.reset_auto_increment('attack_demo_attackscript') f = open(DIR + '/initscripts.json', encoding='utf-8') results = json.loads(f.read()) info = copy.deepcopy(results) for script in info.values(): AttackScript.objects.create(**script) return JsonResponse(results)
def deleteHistory(request): hs = request.POST.getlist('record_id') results = {} for h in hs: info = AttackHistory.objects.filter(pk=int(h)).values()[0] results['record' + h] = info AttackHistory.objects.get(pk=int(h)).delete() if not AttackHistory.objects.all().exists(): reset.reset_auto_increment('attack_demo_attackhistory') return JsonResponse(results)
def dropDevice(request): name = request.POST['device_name'] dev = Device.objects.filter(device_name=name) if not dev.exists(): results = {'msg': '设备不存在'} else: dev.delete() results = {'msg': '删除设备成功', 'device_name': name} if not Device.objects.all().exists(): reset.reset_auto_increment('attack_demo_device') return JsonResponse(results)
def toolsInit(request): AttackTool.objects.all().delete() AttackArg.objects.all().delete() reset.reset_auto_increment('attack_demo_attacktool') reset.reset_auto_increment('attack_demo_attackarg') f = open(DIR + '/inittools.json', encoding='utf-8') results = json.loads(f.read()) info = copy.deepcopy(results) args = [] for tool in info.values(): args = tool.pop('attack_arg') t = AttackTool.objects.create(**tool) for a in args: t.attackarg_set.create(attack_arg=a) args = [] return JsonResponse(results)
def demoInit(request): # results = read_dev_and_topo() Device.objects.all().delete() DeviceTopology.objects.all().delete() reset.reset_auto_increment('attack_demo_device') f = open(DIR + '/initdata.json', encoding='utf-8') results = json.loads(f.read()) info = copy.deepcopy(results) conns = {} for v in info.values(): # v.pop('device_id') v.pop('device_createtime') conns = v.pop('device_conns') obj = Device.objects.create(**v) DeviceTopology.objects.create(device_name=obj, **conns) return JsonResponse(results)
def dropAllDevice(request): Device.objects.all().delete() results = {'msg': '删除所有设备成功'} if not Device.objects.all().exists(): reset.reset_auto_increment('attack_demo_device') return JsonResponse(results)
def emptyHistory(request): AttackHistory.objects.all().delete() reset.reset_auto_increment('attack_demo_attackhistory') results = {'msg': '清空历史纪录成功'} return JsonResponse(results)