Esempio n. 1
0
def editservers(request):
    
    if request.method == 'POST':
        form = ServicesForm(request.POST,user=request.user)
        sub_form = CommandForm(request.POST)
        
        if form.is_valid() and sub_form.is_valid():
            name = str(form.cleaned_data['contener'])
            ram = sub_form.cleaned_data['ram']
            quote = sub_form.cleaned_data['quote']
            com_services = 'python3.5 /root/services_skrypt.py'+ ' '+ name + ' ' + sql + ' ' + http + ' ' + php +'  > wyniki_services.txt'
            edit_servers = form.save()
            query = Commands.objects.get(name=name)
            idl = edit_servers.pk
            query.edit_id = idl
            query.save()
            try:
                ssh = paramiko.SSHClient()
                ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                ssh.connect('89.206.7.46', username='******', password='******')
                # Tworzenie serwisów
                #stdin, stdout, stderr = ssh.exec_command(com_services)
                ssh.close()
            except paramiko.ssh_exception.NoValidConnectionsError as e:
                print ('Error %s' %e)
                return HttpResponseRedirect('editservers/')
            return HttpResponseRedirect('editservers/')
            
    else:
        form = ServicesForm()
        sub_form = CommandForm()
    return render(request, 'psw/editservers.html', {'form': form, 'sub_form': sub_form})
Esempio n. 2
0
def servers(request):
    if request.method == "POST":
        form = CommandForm(request.POST)

        if form.is_valid():
            form.instance.user = request.user
            ip = ip_adding()
            form.instance.ip = ip
            name = form.cleaned_data["name"]
            # ip = form.cleaned_data['ip']
            system = form.cleaned_data["system"]
            ram = form.cleaned_data["ram"]
            quote = form.cleaned_data["quote"]
            password1 = form.cleaned_data["password1"]
            username = str(request.user.get_username())
            commandlog = (
                "python3.5 /root/log_skrypt.py"
                + " "
                + ip
                + " "
                + system
                + " "
                + ram
                + " "
                + quote
                + " "
                + username
                + " "
                + name
                + " "
                + password1
                + " >> PSW_log.log"
            )
            # command = 'python3.5 /root/main_skrypt_podip.py'+ ' '+ ip + ' ' + system + ' ' + ram + ' ' + quote + ' ' + username + ' ' + name +'  > wyniki_testy.txt'
            form.save()

            # Tworzenie ze skryptu.py Python 3.5
            try:
                ssh = paramiko.SSHClient()
                ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                ssh.connect("89.206.7.46", username="******", password="******")
                # Tworzenie Log
                stdin, stdout, stderr = ssh.exec_command(commandlog)
                # Tworzenie kontenerow
                # stdin, stdout, stderr = ssh.exec_command(command)
                ssh.close()
            except paramiko.ssh_exception.NoValidConnectionsError as e:
                print("Error %s" % e)
                return HttpResponseRedirect("servers/")
            return HttpResponseRedirect("/")
    else:
        form = CommandForm()
    return render(request, "psw/servers.html", {"form": form})
Esempio n. 3
0
def servers(request):
    if request.method == 'POST':
        form = CommandForm(request.POST)
        if form.is_valid():

            form.save()
            return HttpResponseRedirect('/psw')
    else:
        form = CommandForm()

    return render(request, 'psw/servers.html', {'form': form})
Esempio n. 4
0
def servers(request):
    if request.method == 'POST':
        form = CommandForm(request.POST)
        if form.is_valid():
            ip = form.cleaned_data['ip']
            system = form.cleaned_data['system']
            ram = form.cleaned_data['ram']
            quote = form.cleaned_data['quote']
            commandlog = 'python3.5 /root/log_skrypt.py'+ ' '+ ip + ' ' + system + ' ' + ram + ' ' + quote + ' >> PSW_log.log'

            command = 'python3.5 /root/main_skrypt.py'+ ' '+ ip + ' ' + system + ' ' + ram + ' ' + quote + '  > wyniki_testy.txt'
            
            #form.save()

#Tworzenie ze skryptu.py Python 3.5 
            try:
                ssh = paramiko.SSHClient()
                ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                ssh.connect('89.206.7.46', username='******', password='******')
                # Tworzenie Log
                stdin, stdout, stderr = ssh.exec_command(commandlog)
                # Tworzenie kontenerow
                stdin, stdout, stderr = ssh.exec_command(command)
                ssh.close()
            except paramiko.ssh_exception.NoValidConnectionsError as e:
                print ('Error %s' %e)
                return HttpResponseRedirect('/psw/servers/')
                      
            return HttpResponseRedirect('/psw/')
        
    else:
         form = CommandForm()
         
           
            
           
    return render(request, 'psw/servers.html', {'form': form})
Esempio n. 5
0
def servers(request):
    if request.method == 'POST':
        form = CommandForm(request.POST)
        if form.is_valid():
            
            form.save()
            try:
                ssh = paramiko.SSHClient()
                ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                ssh.connect('89.206.7.46', username='******', password='******')
                stdin, stdout, stderr = ssh.exec_command('/bin/bash /root/skrypt.sh')
                ssh.close()
            except paramiko.ssh_exception.NoValidConnectionsError as e:
                print ('Error %s' %e)
                return HttpResponseRedirect('/psw/servers/')
                      
            return HttpResponseRedirect('/psw')
    else:
         form = CommandForm()
         
           
            
           
    return render(request, 'psw/servers.html', {'form': form})
Esempio n. 6
0
def servers(request):
    if request.method == 'POST':
        form = CommandForm(request.POST)
        if form.is_valid():

            form.save()
            try:
                ssh = paramiko.SSHClient()
                ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                ssh.connect('89.206.7.46',
                            username='******',
                            password='******')
                stdin, stdout, stderr = ssh.exec_command(
                    '/bin/bash /root/skrypt.sh')
                ssh.close()
            except paramiko.ssh_exception.NoValidConnectionsError as e:
                print('Error %s' % e)
                return HttpResponseRedirect('/psw/servers/')

            return HttpResponseRedirect('/psw')
    else:
        form = CommandForm()

    return render(request, 'psw/servers.html', {'form': form})