Ejemplo n.º 1
0
    try:
        with open(list, "w") as file:
            file.write(form.getvalue('bwlists_content'))
    except IOError as e:
        print('<div class="alert alert-danger" style="margin:0">Cat\'n save ' +
              form.getvalue('color') + ' list. %s </div>' % e)

    servers = sql.get_dick_permit()
    path = sql.get_setting('haproxy_dir') + "/" + form.getvalue('color')

    for server in servers:
        commands = ["sudo mkdir " + path]
        funct.ssh_command(server[2], commands)

        try:
            ssh = funct.ssh_connect(server[2])
        except Exception as e:
            print('<div class="alert alert-danger">Connect fail: %s</div>' % e)

        try:
            sftp = ssh.open_sftp()
            file = sftp.put(list, path + "/" + form.getvalue('bwlists_save'))
            sftp.close()
            ssh.close()
            print(
                '<div class="alert alert-success" style="margin:10px">Edited '
                + form.getvalue('color') + ' list was uploaded to ' +
                server[1] + '</div>')
        except Exception as e:
            print('<div class="alert alert-danger">Upload fail: %s</div>' % e)
Ejemplo n.º 2
0
if form.getvalue('updateserver') is not None:
    import funct
    name = form.getvalue('updateserver')
    ip = form.getvalue('ip')
    group = form.getvalue('servergroup')
    typeip = form.getvalue('typeip')
    enable = form.getvalue('enable')
    master = form.getvalue('slave')
    id = form.getvalue('id')
    if name is None or ip is None:
        print('Content-type: text/html\n')
        print(error_mess)
    else:
        print('Content-type: text/html\n')
        if funct.ssh_connect(ip, check=1):
            update_server(name, ip, group, typeip, enable, master, id)
        else:
            print(
                '<span class="alert alert-danger" id="error"><a title="Close" id="errorMess"><b>X</b></a></span>'
            )

if form.getvalue('updatessh'):
    enable = form.getvalue('ssh_enable')
    username = form.getvalue('ssh_user')
    password = form.getvalue('ssh_pass')
    if username is None:
        print('Content-type: text/html\n')
        print(error_mess)
    else:
        print('Content-type: text/html\n')