コード例 #1
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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})
コード例 #2
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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})
コード例 #3
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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})
コード例 #4
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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})
コード例 #5
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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})
コード例 #6
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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))
コード例 #7
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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))
コード例 #8
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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)})
コード例 #9
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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()})
コード例 #10
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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)})
コード例 #11
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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()})
コード例 #12
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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)})
コード例 #13
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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)})
コード例 #14
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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})
コード例 #15
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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})
コード例 #16
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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
    })
コード例 #17
0
ファイル: views.py プロジェクト: cvvnx1/sliceVA
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))
コード例 #18
0
ファイル: views.py プロジェクト: wanyinglong/sliceVA
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))