def scan(request): if auth_match(request): return HttpResponseRedirect(reverse(login)) username = request.COOKIES["user"] password = User.objects.filter(username=username)[0].password list = Device.objects.all() hosts = [] for device in list: device.status = False hosts.append(device.host) if 'submitcode' in request.POST: code = request.POST.get('submitcode').replace('\r', '').split('\n') commands = [x for x in code if x != ''] work = run_config(commands) result = Assignment(work, username, password, hosts, 20) for device in list: device.status = result[device.host] if 'checkcode' in request.POST: code = request.POST.get('checkcode').replace('\r', '').split('\n') commands = [x for x in code if x != ''] work = search_config(commands) result = Assignment(work, username, password, hosts, 20) for device in list: device.status = result[device.host] return render_to_response('scan.html', {'list': list})
def listuser(request): if auth_match(request): return HttpResponseRedirect(reverse(login)) if admin_match(request): return HttpResponseRedirect(reverse(listdevice)) list = User.objects.all() return render_to_response('listuser.html', {'list': list})
def listuser(request): if auth_match(request): return HttpResponseRedirect(reverse(login)) if admin_match(request): return HttpResponseRedirect(reverse(listdevice)) list = User.objects.all() return render_to_response('listuser.html', {'list': list})
def scan(request): if auth_match(request): return HttpResponseRedirect(reverse(login)) username = request.COOKIES["user"] password = User.objects.filter(username=username)[0].password list = Device.objects.all() hosts = [] for device in list: device.status = False hosts.append(device.host) if 'submitcode' in request.POST: code = request.POST.get('submitcode').replace('\r', '').split('\n') commands = [x for x in code if x != ''] work = run_config(commands) result = Assignment(work, username, password, hosts, 20) for device in list: device.status = result[device.host] if 'checkcode' in request.POST: code = request.POST.get('checkcode').replace('\r', '').split('\n') commands = [x for x in code if x != ''] work = search_config(commands) result = Assignment(work, username, password, hosts, 20) for device in list: device.status = result[device.host] return render_to_response('scan.html', {'list': list})
def device(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) device = get_object_or_404(Device, pk=int(id)) username = request.COOKIES["user"] password = User.objects.filter(username=username)[0].password status_bar = [] if 'submitcode' in request.POST: code = request.POST.get('submitcode').replace('\r', '').split('\n') commands = [x for x in code if x != ''] work = run_config(commands) result = work.run(hostname=device.host, username=username, password=password) if result: status_bar = ['Commands sent...'] else: status_bar = ['Commands sent failed...'] if 'checkcode' in request.POST: code = request.POST.get('checkcode').replace('\r', '').split('\n') commands = [x for x in code if x != ''] work = search_config(commands) result = work.run(hostname=device.host, username=username, password=password) if result: status_bar = ['Config matched...'] else: status_bar = ['Config not matched...'] work = show_running() running_config = work.run(hostname=device.host, username=username, password=password) if not running_config: running_config = [] status_bar = "Host %s can not connect..." % device.host return render_to_response('device.html', {'running_config': running_config, 'status_bar': status_bar})
def deleteuser(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) if admin_match(request): return HttpResponseRedirect(reverse(listdevice)) user = get_object_or_404(User, pk=int(id)) user.delete() return HttpResponseRedirect(reverse(listuser))
def deleteuser(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) if admin_match(request): return HttpResponseRedirect(reverse(listdevice)) user = get_object_or_404(User, pk=int(id)) user.delete() return HttpResponseRedirect(reverse(listuser))
def updatedevice(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) device = get_object_or_404(Device, pk=int(id)) if request.method == "POST": form = DeviceForm(request.POST, instance=device) if form.is_valid(): form.save() return HttpResponseRedirect(reverse(listdevice)) return render_to_response('adddevice.html', {'form': DeviceForm(instance=device)})
def adddevice(request): if auth_match(request): return HttpResponseRedirect(reverse(login)) if request.method == "POST": form = DeviceForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse(listdevice)) else: return render_to_response('adddevice.html', {'form': form}) return render_to_response('adddevice.html', {'form': DeviceForm()})
def updatedevice(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) device = get_object_or_404(Device, pk=int(id)) if request.method == "POST": form = DeviceForm(request.POST, instance=device) if form.is_valid(): form.save() return HttpResponseRedirect(reverse(listdevice)) return render_to_response('adddevice.html', {'form': DeviceForm(instance=device)})
def adddevice(request): if auth_match(request): return HttpResponseRedirect(reverse(login)) if request.method == "POST": form = DeviceForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse(listdevice)) else: return render_to_response('adddevice.html', {'form': form}) return render_to_response('adddevice.html', {'form': DeviceForm()})
def updateuser(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) if admin_match(request): return HttpResponseRedirect(reverse(listdevice)) user = get_object_or_404(User, pk=int(id)) if request.method == "POST": form = UserForm(request.POST, instance=user) if form.is_valid(): form.save() return HttpResponseRedirect(reverse(listuser)) return render_to_response('adduser.html', {'form': UserForm(instance=user)})
def updateuser(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) if admin_match(request): return HttpResponseRedirect(reverse(listdevice)) user = get_object_or_404(User, pk=int(id)) if request.method == "POST": form = UserForm(request.POST, instance=user) if form.is_valid(): form.save() return HttpResponseRedirect(reverse(listuser)) return render_to_response('adduser.html', {'form': UserForm(instance=user)})
def listdevice(request): if auth_match(request): return HttpResponseRedirect(reverse(login)) username = request.COOKIES["user"] password = User.objects.filter(username=username)[0].password list = Device.objects.all().extra(order_by = ['host']) hosts = [] for device in list: hosts.append(device.host) # work = alive() # result = Assignment(work, username, password, hosts, 20) for device in list: # device.status = result[device.host] device.status = False return render_to_response('listdevice.html', {'list': list})
def listdevice(request): if auth_match(request): return HttpResponseRedirect(reverse(login)) username = request.COOKIES["user"] password = User.objects.filter(username=username)[0].password list = Device.objects.all().extra(order_by=['host']) hosts = [] for device in list: hosts.append(device.host) # work = alive() # result = Assignment(work, username, password, hosts, 20) for device in list: # device.status = result[device.host] device.status = False return render_to_response('listdevice.html', {'list': list})
def device(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) device = get_object_or_404(Device, pk=int(id)) username = request.COOKIES["user"] password = User.objects.filter(username=username)[0].password status_bar = [] if 'submitcode' in request.POST: code = request.POST.get('submitcode').replace('\r', '').split('\n') commands = [x for x in code if x != ''] work = run_config(commands) result = work.run(hostname=device.host, username=username, password=password) if result: status_bar = ['Commands sent...'] else: status_bar = ['Commands sent failed...'] if 'checkcode' in request.POST: code = request.POST.get('checkcode').replace('\r', '').split('\n') commands = [x for x in code if x != ''] work = search_config(commands) result = work.run(hostname=device.host, username=username, password=password) if result: status_bar = ['Config matched...'] else: status_bar = ['Config not matched...'] work = show_running() running_config = work.run(hostname=device.host, username=username, password=password) if not running_config: running_config = [] status_bar = "Host %s can not connect..." % device.host return render_to_response('device.html', { 'running_config': running_config, 'status_bar': status_bar })
def deletedevice(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) device = get_object_or_404(Device, pk=int(id)) device.delete() return HttpResponseRedirect(reverse(listdevice))
def deletedevice(request, id): if auth_match(request): return HttpResponseRedirect(reverse(login)) device = get_object_or_404(Device, pk=int(id)) device.delete() return HttpResponseRedirect(reverse(listdevice))