Beispiel #1
0
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})
Beispiel #2
0
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})
Beispiel #3
0
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})
Beispiel #4
0
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})
Beispiel #5
0
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})
Beispiel #6
0
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))
Beispiel #7
0
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))
Beispiel #8
0
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)})
Beispiel #9
0
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()})
Beispiel #10
0
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)})
Beispiel #11
0
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()})
Beispiel #12
0
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)})
Beispiel #13
0
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)})
Beispiel #14
0
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})
Beispiel #15
0
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})
Beispiel #16
0
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
    })
Beispiel #17
0
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))
Beispiel #18
0
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))