mirror of https://github.com/Aidaho12/haproxy-wi
v3.2.4
parent
ca1d564294
commit
1d39d5de16
57
app/funct.py
57
app/funct.py
|
@ -172,54 +172,27 @@ def ssh_connect(serv, **kwargs):
|
|||
ssh.connect(hostname = serv, port = ssh_port, username = ssh_user_name, pkey = k)
|
||||
else:
|
||||
ssh.connect(hostname = serv, port = ssh_port, username = ssh_user_name, password = ssh_user_password)
|
||||
if kwargs.get('check'):
|
||||
return True
|
||||
else:
|
||||
return ssh
|
||||
return ssh
|
||||
except paramiko.AuthenticationException:
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">Authentication failed, please verify your credentials</div>')
|
||||
return False
|
||||
else:
|
||||
return 'Authentication failed, please verify your credentials'
|
||||
pass
|
||||
return 'Authentication failed, please verify your credentials'
|
||||
pass
|
||||
except paramiko.SSHException as sshException:
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">Unable to establish SSH connection: %s </div>' % sshException)
|
||||
return False
|
||||
else:
|
||||
return 'Unable to establish SSH connection: %s ' % sshException
|
||||
pass
|
||||
return 'Unable to establish SSH connection: %s ' % sshException
|
||||
pass
|
||||
except paramiko.BadHostKeyException as badHostKeyException:
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">Unable to verify server\'s host key: %s </div>' % badHostKeyException)
|
||||
return False
|
||||
else:
|
||||
return 'Unable to verify server\'s host key: %s ' % badHostKeyException
|
||||
pass
|
||||
return 'Unable to verify server\'s host key: %s ' % badHostKeyException
|
||||
pass
|
||||
except Exception as e:
|
||||
if e == "No such file or directory":
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">%s. Check ssh key</div>') % e
|
||||
else:
|
||||
return '%s. Check ssh key' % e
|
||||
pass
|
||||
return '%s. Check ssh key' % e
|
||||
pass
|
||||
elif e == "Invalid argument":
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">Check the IP of the new server</div>')
|
||||
else:
|
||||
error = 'Check the IP of the new server'
|
||||
pass
|
||||
error = 'Check the IP of the server'
|
||||
pass
|
||||
else:
|
||||
if kwargs.get('check'):
|
||||
print('<div class="alert alert-danger">%s</div>') % e
|
||||
else:
|
||||
error = e
|
||||
pass
|
||||
if kwargs.get('check'):
|
||||
return False
|
||||
else:
|
||||
return error
|
||||
error = e
|
||||
pass
|
||||
return str(error)
|
||||
|
||||
def get_config(serv, cfg, **kwargs):
|
||||
import sql
|
||||
|
@ -470,7 +443,7 @@ def ssh_command(serv, commands, **kwargs):
|
|||
ssh.close()
|
||||
except:
|
||||
ssh = str(ssh)
|
||||
print("<div class='alert alert-danger'>"+ssh+"</div>")
|
||||
print("<div class='alert alert-danger' style='margin: 0;'>"+ssh+"</div>")
|
||||
pass
|
||||
|
||||
def escape_html(text):
|
||||
|
|
18
app/sql.py
18
app/sql.py
|
@ -110,13 +110,13 @@ def update_group(name, descript, id):
|
|||
cur.close()
|
||||
con.close()
|
||||
|
||||
def add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics):
|
||||
def add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics, port):
|
||||
con, cur = create_db.get_cur()
|
||||
sql = """
|
||||
INSERT INTO servers
|
||||
(hostname, ip, groups, type_ip, enable, master, cred, alert, metrics)
|
||||
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
|
||||
""" % (hostname, ip, group, typeip, enable, master, cred, alert, metrics)
|
||||
(hostname, ip, groups, type_ip, enable, master, cred, alert, metrics, port)
|
||||
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
|
||||
""" % (hostname, ip, group, typeip, enable, master, cred, alert, metrics, port)
|
||||
try:
|
||||
cur.execute(sql)
|
||||
con.commit()
|
||||
|
@ -1150,11 +1150,12 @@ if form.getvalue('newserver') is not None:
|
|||
metrics = form.getvalue('metrics')
|
||||
page = form.getvalue('page')
|
||||
page = page.split("#")[0]
|
||||
port = form.getvalue('port')
|
||||
print('Content-type: text/html\n')
|
||||
if ip is None or group is None or cred is None:
|
||||
if ip is None or group is None or cred is None or port is None:
|
||||
print(error_mess)
|
||||
else:
|
||||
if add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics):
|
||||
if add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics, port):
|
||||
show_update_server(ip, page)
|
||||
|
||||
if form.getvalue('serverdel') is not None:
|
||||
|
@ -1202,13 +1203,10 @@ if form.getvalue('updateserver') is not None:
|
|||
metrics = form.getvalue('metrics')
|
||||
port = form.getvalue('port')
|
||||
print('Content-type: text/html\n')
|
||||
if name is None or ip is None:
|
||||
if name is None or ip is None or port is None:
|
||||
print(error_mess)
|
||||
else:
|
||||
#if funct.ssh_connect(ip, check=1):
|
||||
update_server(name, ip, group, typeip, enable, master, id, cred, alert, metrics, port)
|
||||
#else:
|
||||
# print('<span class="alert alert-danger" id="error"><a title="Close" id="errorMess"><b>X</b></a></span>')
|
||||
|
||||
if form.getvalue('updatessh'):
|
||||
id = form.getvalue('id')
|
||||
|
|
Loading…
Reference in New Issue