def iptables_delete(request): ff = IptablesForm() search_rules = Iptables.objects.filter(i_comment__contains="WEB_PORT_") if request.method == 'POST': if "delete" in request.POST: ruls_id = str(request.POST['delete']) delete_ruls = Iptables.objects.get(id=ruls_id) ipaddr = delete_ruls.i_source_ip remark = delete_ruls.i_remark comm = delete_ruls.i_comment delete_ruls.delete() task = "/etc/ansible/deleteip.yml" ansiblex(task, str(ipaddr), remark, comm) infos = "IP: %s 已经成功解除绑定" % str(ipaddr) #return HttpResponse(choice) return HttpResponseRedirect('/allow/welcome/') elif "searchcomment" in request.POST: ff = IptablesForm(request.POST) comment = request.POST.get('comment') search_rules = Iptables.objects.filter(i_comment__contains="%s" % comment) return render(request, "allow_list/iptables_delete.html", locals()) else: ip = request.POST.get('searchip') search_rules = Iptables.objects.filter(i_source_ip__contains="%s" % ip) return render(request, "allow_list/iptables_delete.html", locals()) return render(request, "allow_list/iptables_delete.html", locals())
def iptables_delete(request,id): data = Iptables.objects.get(pk=id) ipaddr = data.i_source_ip remark = data.i_remark comm = data.i_comment count_num = Iptables.objects.filter(i_source_ip=ipaddr) if len(count_num) > 1: data.delete() infos = "IP: %s Deleted! " % str(ipaddr) return JsonResponse({'res':"OK",'info':infos},safe=False) data.delete() task = "/etc/ansible/deleteip.yml" ansiblex(task,str(ipaddr),remark,comm) infos = "IP: %s Deleted!" % str(ipaddr) return JsonResponse({'res':"OK",'info':infos},safe=False)
def do_ansible(task, ip, remark, comment): current_task.update_state(state="PROGRESS") ansiblex(vars1=task, vars2=ip, vars3=remark, vars4=comment) return "12345" # @shared_task() # def do_ansible(task,ip,remark,comment): # task=task # ip=ip # remark=remark # comment=comment # current_task.update_state(state="PROGRESS") # ansiblex(task,ip,remark,comment) # return ip
def linechange(request): line_errors = [] flb_data = oldsite_line.objects.get(agent_name='flb').number chengxin_data = oldsite_line.objects.get(agent_name='chengxin').number yifa_data = oldsite_line.objects.get(agent_name='yifa').number bogou_data = oldsite_line.objects.get(agent_name='bogou').number shouxin_data = oldsite_line.objects.get(agent_name='shouxin').number amwnsr_data = oldsite_line.objects.get(agent_name='amwnsr').number meigaomei_data = oldsite_line.objects.get(agent_name='meigaomei').number kuke_data = oldsite_line.objects.get(agent_name='kuke').number dafa_data = oldsite_line.objects.get(agent_name='dafa').number yongli_data = oldsite_line.objects.get(agent_name='yongli').number if "change" in request.POST: if "choiceline" not in request.POST: line_errors.append("你没有选择需要切换的线路!") elif "choiceagent" not in request.POST: line_errors.append("你没有选择客户!") else: choiceagent = request.POST['choiceagent'] choiceline = request.POST['choiceline'] now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) if choiceline == u"line_one": changeip = '47.90.37.137' oldsite_line.objects.filter( agent_name__contains=choiceagent).update(date_time=now, status=True, number=1, line=changeip, comment=u"线路一") elif choiceline == u"line_two": changeip = '119.28.13.102' oldsite_line.objects.filter( agent_name__contains=choiceagent).update(date_time=now, status=True, number=2, line=changeip, comment=u"线路二") elif choiceline == u"line_three": changeip = '119.9.108.157' oldsite_line.objects.filter( agent_name__contains=choiceagent).update(date_time=now, status=True, number=3, line=changeip, comment=u"线路三") elif choiceline == u"line_four": changeip = '47.90.67.26' oldsite_line.objects.filter( agent_name__contains=choiceagent).update(date_time=now, status=True, number=4, line=changeip, comment=u"线路四") task = "/etc/ansible/changeline.yml" groupname = "changeline" # origin_wwwroot = "/data/docker-nginx/conf/nginx/conf/vhost" origin_wwwroot = "/tmp" ansiblex(task, groupname, choiceagent, changeip, origin_wwwroot) return HttpResponseRedirect('/allow/welcome/') search_lines = oldsite_line.objects.all() return render(request, "allow_list/linechange.html", locals())
def do_ansible(task, ip, remark, comment): current_task.update_state(state="PROGRESS") ansiblex(vars1=task, vars2=ip, vars3=remark, vars4=comment) return "12345"