From 082467ce500ba633eac4e27f3c9d37c457b814bf Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Mon, 1 Oct 2018 22:51:37 +0600 Subject: [PATCH] v3.2.11 Was added SSH check connect --- app/funct.py | 12 +++++++++--- app/options.py | 13 +++++++++---- app/templates/admin.html | 1 + app/templates/ajax/new_server.html | 1 + app/templates/base.html | 10 +++++----- app/templates/servers.html | 2 ++ inc/users.js | 23 +++++++++++++++++++++++ 7 files changed, 50 insertions(+), 12 deletions(-) diff --git a/app/funct.py b/app/funct.py index b30d7bf7..89bb4bf6 100644 --- a/app/funct.py +++ b/app/funct.py @@ -144,11 +144,17 @@ def ssh_connect(serv, **kwargs): from paramiko import SSHClient import sql fullpath = get_config_var('main', 'fullpath') + ssh_enable = '' + ssh_port = '' + ssh_user_name = '' + ssh_user_password = '' + for sshs in sql.select_ssh(serv=serv): ssh_enable = sshs[3] ssh_user_name = sshs[4] ssh_user_password = sshs[5] ssh_key_name = fullpath+'/keys/%s.pem' % sshs[2] + servers = sql.select_servers(server=serv) for server in servers: ssh_port = server[10] @@ -407,7 +413,7 @@ def ssh_command(serv, commands, **kwargs): for command in commands: try: - stdin, stdout, stderr = ssh.exec_command(command,get_pty=True) + stdin, stdout, stderr = ssh.exec_command(command, get_pty=True) except: continue @@ -431,7 +437,7 @@ def ssh_command(serv, commands, **kwargs): try: ssh.close() except: - print("
"+str(ssh)+"
") + print("
"+str(ssh)+"X
") pass def escape_html(text): @@ -485,4 +491,4 @@ def get_files(dir = get_config_var('configs', 'haproxy_save_configs_dir'), forma return files def get_key(item): - return item[0] + return item[0] \ No newline at end of file diff --git a/app/options.py b/app/options.py index 45fd86bd..1aba94b6 100644 --- a/app/options.py +++ b/app/options.py @@ -32,6 +32,12 @@ if form.getvalue('getcerts') is not None and serv is not None: funct.ssh_command(serv, commands, ip="1") except: print('
Can not connect to the server
') + +if form.getvalue('checkSshConnect') is not None and serv is not None: + try: + funct.ssh_command(serv, ["ls -1t"]) + except: + print('
Can not connect to the server
') if form.getvalue('getcert') is not None and serv is not None: id = form.getvalue('getcert') @@ -486,8 +492,7 @@ if form.getvalue('metrics'): for key, value in p.items(): plots.append(value) - plots_sorted = sorted(plots, key=funct.get_key) - grid = gridplot(plots_sorted, ncols=2, plot_width=800, plot_height=250, toolbar_location = "left", toolbar_options=dict(logo=None)) + grid = gridplot(plots, ncols=2, plot_width=800, plot_height=250, toolbar_location = "left", toolbar_options=dict(logo=None)) show(grid) if form.getvalue('waf_metrics'): @@ -556,8 +561,8 @@ if form.getvalue('waf_metrics'): plots = [] for key, value in p.items(): plots.append(value) - plots_sorted = sorted(plots, key=funct.get_key) - grid = gridplot(plots_sorted, ncols=2, plot_width=800, plot_height=250, toolbar_location = "left", toolbar_options=dict(logo=None)) + + grid = gridplot(plots, ncols=2, plot_width=800, plot_height=250, toolbar_location = "left", toolbar_options=dict(logo=None)) show(grid) if form.getvalue('get_hap_v'): diff --git a/app/templates/admin.html b/app/templates/admin.html index def064c4..8ed7a074 100644 --- a/app/templates/admin.html +++ b/app/templates/admin.html @@ -250,6 +250,7 @@ {% endif %} {% endfor %} + {% if server.11 != "None" %} diff --git a/app/templates/ajax/new_server.html b/app/templates/ajax/new_server.html index 7ae74915..cac636cf 100644 --- a/app/templates/ajax/new_server.html +++ b/app/templates/ajax/new_server.html @@ -76,6 +76,7 @@ {% endif %} {% endfor %} + {% if server.11 != "None" %} diff --git a/app/templates/base.html b/app/templates/base.html index 9db92fea..1eb51853 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -56,10 +56,10 @@ {% if user %}
  • Configs
  • {% if role <= 2 %} -
  • Add listen
  • -
  • Add frontend
  • -
  • Add backend
  • -
  • SSL
  • +
  • Add listen
  • +
  • Add frontend
  • +
  • Add backend
  • +
  • SSL
  • Lists
  • WAF
  • Installation
  • @@ -99,7 +99,7 @@ diff --git a/app/templates/servers.html b/app/templates/servers.html index 1ee7e040..ed6ffe49 100644 --- a/app/templates/servers.html +++ b/app/templates/servers.html @@ -175,6 +175,7 @@ {% endif %} {% endfor %} + {% if server.11 != "None" %} @@ -431,6 +432,7 @@ setTimeout(function() { $("input[type=checkbox]").checkboxradio( "disable" ); $("select").selectmenu( "disable" ); + $("button").button( "disable" ); $("input").attr( "readonly", "readonly" ); $('.delete').remove() }, 500 ); diff --git a/inc/users.js b/inc/users.js index e1b74eee..fd1b0efd 100644 --- a/inc/users.js +++ b/inc/users.js @@ -880,4 +880,27 @@ function showApacheLog(serv) { window.history.pushState("Logs", "Logs", cur_url[0]+"?serv="+$("#serv").val()+"&rows1="+$('#rows').val()+"&grep="+$("#grep").val()); } } ); +} +function checkSshConnect(ip) { + $.ajax( { + url: "options.py", + data: { + checkSshConnect: 1, + serv: ip, + token: $('#token').val() + }, + type: "GET", + success: function( data ) { + if (data.indexOf('danger') != '-1') { + $("#ajax").html(data); + } else { + $("#ajax").html("
    Connect acceptX
    "); + } + $('#errorMess').click(function() { + $('#error').remove(); + $('.alert-danger').remove(); + $('.alert-success').remove(); + }); + } + } ); } \ No newline at end of file