diff --git a/app/create_db.py b/app/create_db.py index 0591dc66..e023208d 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -473,7 +473,7 @@ def update_db_v_4_3(**kwargs): con.close() -def update_db_v_4_3_1(**kwargs): +def update_db_v_4_3_0(**kwargs): con, cur = get_cur() sql = """ insert OR IGNORE into user_groups(user_id, user_group_id) select id, groups from user; @@ -484,7 +484,7 @@ def update_db_v_4_3_1(**kwargs): except sqltool.Error as e: if kwargs.get('silent') != 1: if e.args[0] == 'duplicate column name: haproxy' or e == " 1060 (42S21): Duplicate column name 'haproxy' ": - print('DB was update to 4.3.0') + print('Updating... go to version 4.3.1') else: print("An error occurred:", e) return False @@ -494,9 +494,31 @@ def update_db_v_4_3_1(**kwargs): con.close() +def update_db_v_4_3_1(**kwargs): + con, cur = get_cur() + sql = """ + ALTER TABLE `servers` ADD COLUMN pos INTEGER NOT NULL DEFAULT 0; + """ + try: + cur.execute(sql) + con.commit() + except sqltool.Error as e: + if kwargs.get('silent') != 1: + if e.args[0] == 'duplicate column name: pos' or e == " 1060 (42S21): Duplicate column name 'pos' ": + print('DB was update to 4.3.1') + else: + print("An error occurred:", e) + return False + else: + print("DB was update to 4.3.1") + return True + cur.close() + con.close() + + def update_ver(**kwargs): con, cur = get_cur() - sql = """update version set version = '4.3.0.0'; """ + sql = """update version set version = '4.3.1.0'; """ try: cur.execute(sql) con.commit() @@ -522,6 +544,7 @@ def update_all(): update_db_v_42() update_db_v_4_2_3() update_db_v_4_3() + update_db_v_4_3_0() update_db_v_4_3_1() update_ver() @@ -542,6 +565,7 @@ def update_all_silent(): update_db_v_42(silent=1) update_db_v_4_2_3(silent=1) update_db_v_4_3(silent=1) + update_db_v_4_3_0(silent=1) update_db_v_4_3_1(silent=1) update_ver() diff --git a/app/options.py b/app/options.py index 96c6fe7e..4192898d 100644 --- a/app/options.py +++ b/app/options.py @@ -90,8 +90,14 @@ if form.getvalue('backend') is not None: funct.show_backends(serv) +if form.getvalue('change_pos') is not None: + import sql + pos = form.getvalue('change_pos') + sql.update_server_pos(pos, serv) + + if form.getvalue('ip') is not None and serv is not None: - commands = [ "sudo ip a |grep inet |egrep -v '::1' |awk '{ print $2 }' |awk -F'/' '{ print $1 }'" ] + commands = [ "sudo ip a |grep inet |egrep -v '::1' |awk '{ print $2 }' |awk -F'/' '{ print $1 }'" ] funct.ssh_command(serv, commands, ip="1") @@ -143,6 +149,7 @@ if form.getvalue('action_service') is not None: output, stderr = funct.subprocess_execute(cmd) funct.logging('localhost', ' The service '+serv+ 'was '+action+'ed', haproxywi=1, login=1) + if act == "overviewHapserverBackends": from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True) @@ -598,7 +605,7 @@ if form.getvalue('servaction') is not None: haproxy_sock = sql.get_setting('haproxy_sock') enable = form.getvalue('servaction') backend = form.getvalue('servbackend') - cmd='echo "%s %s" |sudo socat stdio %s | cut -d "," -f 1-2,5-10,18,34-36 | column -s, -t' % (enable, backend, haproxy_sock) + cmd='echo "%s %s" |sudo socat stdio %s' % (enable, backend, haproxy_sock) if form.getvalue('save') == "on": save_command = 'echo "show servers state" | sudo socat %s stdio > %s' % (haproxy_sock, server_state_file) diff --git a/app/sql.py b/app/sql.py index 23670d66..d1813317 100644 --- a/app/sql.py +++ b/app/sql.py @@ -654,9 +654,9 @@ def get_dick_permit(**kwargs): if select_user_groups(user, check_id=grp): con, cur = get_cur() if grp == '1': - sql = """ select * from servers where enable = 1 %s %s %s """ % (disable, type_ip, nginx) + sql = """ select * from servers where enable = 1 %s %s %s order by pos""" % (disable, type_ip, nginx) else: - sql = """ select * from servers where groups = '{group}' and (enable = 1 {disable}) {type_ip} {ip} {haproxy} {nginx} {keepalived} + sql = """ select * from servers where groups = '{group}' and (enable = 1 {disable}) {type_ip} {ip} {haproxy} {nginx} {keepalived} order by pos """.format(group=grp, disable=disable, type_ip=type_ip, ip=ip, haproxy=haproxy, nginx=nginx, keepalived=keepalived) try: @@ -1670,6 +1670,21 @@ def update_haproxy(serv): con.close() +def update_server_pos(pos, id): + con, cur = get_cur() + sql = """ update servers set + pos = '%s' + where id = '%s'""" % (pos, id) + try: + cur.execute(sql) + con.commit() + except sqltool.Error as e: + funct.out_error(e) + con.rollback() + cur.close() + con.close() + + def check_token_exists(token): try: import http.cookies diff --git a/app/templates/base.html b/app/templates/base.html index 1e80a815..6ca82196 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -94,7 +94,8 @@
  • Users
  • Servers
  • SSH credentials
  • -
  • Installation
  • +
  • Installation Proxy
  • +
  • Installation Monitoring
  • Backups
  • diff --git a/app/templates/hapservers.html b/app/templates/hapservers.html index 8a9f2234..de9a540d 100644 --- a/app/templates/hapservers.html +++ b/app/templates/hapservers.html @@ -30,6 +30,24 @@ host = host.replace(/\./g, '\\.'); hostnamea.push(host) {% endfor %} + $( function() { + $( ".sortable" ).sortable({ + revert: true, + placeholder: "ui-state-highlight" + }); + $( ".sortable" ).disableSelection(); + + $( ".sortable" ).sortable({ + stop: function(event, ui) { + var itemOrder = $('.sortable').sortable("toArray"); + for (var i = 0; i < itemOrder.length; i++) { + var pos = i; + var id = itemOrder[i].split('-')[2] + change_pos(pos, id); + } + } + }); + });
    {% if servers|length == 0 %} diff --git a/app/templates/metrics.html b/app/templates/metrics.html index 82d9081c..762eb36b 100644 --- a/app/templates/metrics.html +++ b/app/templates/metrics.html @@ -28,27 +28,19 @@ th, tr, td {
    {% endfor %} - + {% endif %} {% endblock %} diff --git a/app/templates/runtimeapi.html b/app/templates/runtimeapi.html index 77cb739a..be988285 100644 --- a/app/templates/runtimeapi.html +++ b/app/templates/runtimeapi.html @@ -1,59 +1,167 @@ {% extends "base.html" %} {% block content %} {% from 'include/input_macros.html' import input, checkbox %} - - - - - - - - - - - + + + +
    ServerDisable/Enable server or output any informationCommandSave change
    -
    - {% include 'include/select.html' %} -
    - + + + + + + + + + + + + - - - - - -
    ServerDisable/Enable server or output any informationCommandSave change
    + + {% include 'include/select.html' %} + + + + {{ input('servbackend', value=servbackend, title='Frontend, backend/server, show: info, pools or help', required='required') }} + {% if role <= 2 %} - - - + {{ checkbox('save', value='123') }} {% endif %} - - - - {{ input('servbackend', value=servbackend, title='Frontend, backend/server, show: info, pools or help', required='required') }} - - {% if role <= 2 %} - {{ checkbox('save', value='123') }} - {% endif %} - - -
    - -
    -
    - You can read the description of all Run Time API here +
    + +
    + +
    +
    + You can read the description of all Run Time API here +
    +
    + + + + + + + + + + + + + + +
    ServerChoose FrontendMaxconn
    +
    + +
    + + + {{ input('maxconnint', title='Enter maxconn', type="number", required='required') }} + + +
    +
    +
    + You can read how it works here +
    +
    + +
    + + + + + + + + + + + + + + + + + + +
    ServerChoose BackendChoose ServerNew IPNew Port
    +
    + +
    + + + + + {{ input('backend_ip', title='Set new server IP', required='required', size='16') }} + + {{ input('backend_port', title='Set new server Port', type="number", required='required', size='6') }} + + +
    +
    +
    + You can read how it works here +
    +
    + + {% endblock %} \ No newline at end of file diff --git a/app/templates/servers.html b/app/templates/servers.html index 66829d87..5e4c2695 100644 --- a/app/templates/servers.html +++ b/app/templates/servers.html @@ -17,7 +17,8 @@
  • Servers
  • SSH credentials
  • Checker
  • -
  • Installation
  • +
  • Installation Proxy
  • +
  • Installation Monitoring
  • Backup
  • {% include 'include/login.html' %} @@ -276,7 +277,7 @@ You can read the description of all parameters here -
    +
    @@ -341,6 +342,10 @@

    Install HAProxy

    +
    +
    + +
    @@ -434,7 +439,7 @@

    Install Grafana and Prometheus servers

    -
    +
    diff --git a/inc/awesome.css b/inc/awesome.css index 78cf1625..5681bbee 100644 --- a/inc/awesome.css +++ b/inc/awesome.css @@ -92,6 +92,11 @@ font-family: "Font Awesome 5 Solid"; content: "\f074"; } +.hap1::before { + display: none; + font-family: "Font Awesome 5 Solid"; + content: "\f074"; +} .backup::before { display: none; font-family: "Font Awesome 5 Solid"; diff --git a/inc/overview.js b/inc/overview.js index 6e930bbd..e43b9803 100644 --- a/inc/overview.js +++ b/inc/overview.js @@ -134,53 +134,53 @@ function ajaxActionServers(action, id) { } ); } function ajaxActionNginxServers(action, id) { - var bad_ans = 'Bad config, check please'; - $.ajax( { - url: "options.py", - data: { - action_nginx: action, - serv: id, - token: $('#token').val() - }, - success: function( data ) { - data = data.replace(/\s+/g,' '); - if( data == 'Bad config, check please ' ) { - alert(data); - } else { - if (cur_url[0] == "hapservers.py") { - location.reload() - } else { - setTimeout(showOverview(ip, hostnamea), 2000) - } - } - }, - error: function(){ - alert(w.data_error); - } - } ); - } + var bad_ans = 'Bad config, check please'; + $.ajax( { + url: "options.py", + data: { + action_nginx: action, + serv: id, + token: $('#token').val() + }, + success: function( data ) { + data = data.replace(/\s+/g,' '); + if( data == 'Bad config, check please ' ) { + alert(data); + } else { + if (cur_url[0] == "hapservers.py") { + location.reload() + } else { + setTimeout(showOverview(ip, hostnamea), 2000) + } + } + }, + error: function(){ + alert(w.data_error); + } + } ); +} function ajaxActionWafServers(action, id) { - var bad_ans = 'Bad config, check please'; - $.ajax( { - url: "options.py", - data: { - action_waf: action, - serv: id, - token: $('#token').val() - }, - success: function( data ) { - data = data.replace(/\s+/g,' '); - if( data == 'Bad config, check please ' ) { - alert(data); - } else { - setTimeout(showOverviewWaf(ip, hostnamea), 2000) - } - }, - error: function(){ - alert(w.data_error); - } - } ); - } + var bad_ans = 'Bad config, check please'; + $.ajax( { + url: "options.py", + data: { + action_waf: action, + serv: id, + token: $('#token').val() + }, + success: function( data ) { + data = data.replace(/\s+/g,' '); + if( data == 'Bad config, check please ' ) { + alert(data); + } else { + setTimeout(showOverviewWaf(ip, hostnamea), 2000) + } + }, + error: function(){ + alert(w.data_error); + } + } ); +} $( function() { $( "#show-all-users" ).click( function() { $( ".show-users" ).show("fast"); @@ -304,4 +304,17 @@ function updateHapWIServer(id) { } } } ); +} +function change_pos(pos, id) { + $.ajax( { + url: "options.py", + data: { + change_pos: pos, + serv: id, + token: $('#token').val() + }, + error: function(){ + console.log(w.data_error); + } + } ); } \ No newline at end of file diff --git a/inc/runtimeapi.js b/inc/runtimeapi.js new file mode 100644 index 00000000..61becb7a --- /dev/null +++ b/inc/runtimeapi.js @@ -0,0 +1,189 @@ +function showRuntime() { + if($('#save').prop('checked')) { + saveCheck = "on"; + } else { + saveCheck = ""; + } + $.ajax( { + url: "options.py", + data: { + servaction: $('#servaction').val(), + serv: $("#serv").val(), + servbackend: $("#servbackend").val(), + save: saveCheck, + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + $("#ajaxruntime").html(data); + } + } ); +} +$( function() { + $('#runtimeapiform').submit(function() { + showRuntime(); + return false; + }); + $( "#maxconn_select" ).on('selectmenuchange',function() { + $.ajax( { + url: "options.py", + data: { + maxconn_select: $('#maxconn_select').val(), + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + data = data.replace(/\s+/g,' '); + if (data.indexOf('error') != '-1') { + alert(data) + } else { + var value = data.split('
    ') + $('#maxconnfront').find('option').remove(); + $('#maxconnfront').append($("").attr("value","disabled").text("Choose Frontend")); + $('#maxconnfront').append($("").attr("value","global").text("global")); + + for(let i = 0; i < data.split('
    ').length; i++){ + if(value[i] != '') { + $('#maxconnfront').append($("") + .attr("value",value[i]) + .text(value[i])); + } + } + $('#maxconnfront').selectmenu("refresh"); + } + } + } ); + }); + $('#maxconnform').submit(function() { + $.ajax( { + url: "options.py", + data: { + serv: $('#maxconn_select').val(), + maxconn_frontend: $('#maxconnfront').val(), + maxconn_int: $('#maxconnint').val(), + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + data = data.replace(/\s+/g,' '); + if (data.indexOf('error') != '-1') { + $("#ajaxmaxconn").html('
    '+data+'
    '); + } else { + $("#ajaxmaxconn").html('
    '+data+'
    '); + } + } + } ); + return false; + }); + $( "#ip_select" ).on('selectmenuchange',function() { + $.ajax( { + url: "options.py", + data: { + ip_select: $('#ip_select').val(), + serv: $('#ip_select').val(), + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + data = data.replace(/\s+/g,' '); + if (data.indexOf('error') != '-1') { + alert(data) + } else { + var value = data.split('
    ') + $('#ipbackend').find('option').remove(); + $('#ipbackend').append($("").attr("value","disabled").text("Choose Backend")); + + for(let i = 0; i < data.split('
    ').length; i++){ + if(value[i] != '') { + $('#ipbackend').append($("") + .attr("value",value[i]) + .text(value[i])); + } + } + $('#ipbackend').selectmenu("refresh"); + } + } + } ); + }); + $( "#ipbackend" ).on('selectmenuchange',function() { + $.ajax( { + url: "options.py", + data: { + serv: $('#ip_select').val(), + ipbackend: $('#ipbackend').val(), + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + data = data.replace(/\s+/g,' '); + if (data.indexOf('error') != '-1') { + alert(data) + } else { + var value = data.split('
    ') + $('#backend_server').find('option').remove(); + $('#backend_server').append($("").attr("value","disabled").text("Choose Server")); + + for(let i = 0; i < data.split('
    ').length; i++){ + if(value[i] != ' ') { + value[i] = value[i].replace(/\s+/g,''); + $('#backend_server').append($("") + .attr("value",value[i]) + .text(value[i])); + } + } + $('#backend_server').selectmenu("refresh"); + } + } + } ); + }); + $( "#backend_server" ).on('selectmenuchange',function() { + $('#backend_ip').val(); + $('#backend_port').val(); + $.ajax( { + url: "options.py", + data: { + serv: $('#ip_select').val(), + ipbackend: $('#ipbackend').val(), + backend_server: $('#backend_server').val(), + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + data = data.replace(/\s+/g,' '); + if (data.indexOf('error') != '-1') { + alert(data) + } else { + var server = data.split(':')[0] + var port = data.split(':')[1] + port = port.replace(/\s+/g,''); + server = server.replace(/\s+/g,''); + $('#backend_port').val(port); + $('#backend_ip').val(server); + } + } + } ); + }); + $('#runtimeapiip').submit(function() { + $.ajax( { + url: "options.py", + data: { + serv: $('#ip_select').val(), + backend_backend: $('#ipbackend').val(), + backend_server: $('#backend_server').val(), + backend_ip: $('#backend_ip').val(), + backend_port: $('#backend_port').val(), + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + data = data.replace(/\s+/g,' '); + if (data.indexOf('error') != '-1') { + $("#ajaxip").html('
    '+data+'
    '); + } else { + $("#ajaxip").html('
    '+data+'
    '); + } + } + } ); + return false; + }); +}); diff --git a/inc/script.js b/inc/script.js index 1265f91a..87ca7206 100644 --- a/inc/script.js +++ b/inc/script.js @@ -854,6 +854,15 @@ $( function() { }); $( "#tabs" ).tabs( "option", "active", 4 ); } ); + $( ".hap1" ).on( "click", function() { + $('.menu li ul li').each(function () { + $(this).find('a').css('padding-left', '20px') + $(this).find('a').css('border-left', '0px solid #5D9CEB'); + $(this).children(".hap1").css('padding-left', '30px'); + $(this).children(".hap1").css('border-left', '4px solid #5D9CEB'); + }); + $( "#tabs" ).tabs( "option", "active", 5 ); + } ); $( ".backup" ).on( "click", function() { $('.menu li ul li').each(function () { $(this).find('a').css('padding-left', '20px') @@ -861,7 +870,7 @@ $( function() { $(this).children(".backup").css('padding-left', '30px'); $(this).children(".backup").css('border-left', '4px solid #5D9CEB'); }); - $( "#tabs" ).tabs( "option", "active", 5 ); + $( "#tabs" ).tabs( "option", "active", 6 ); } ); } } @@ -950,4 +959,4 @@ function changeCurrentGroupF(){ Cookies.remove('group'); Cookies.set('group', $('#newCurrentGroup').val(), { path: '/app', sameSite: 'Strict', Secure: 'True' }); location.reload(); -} +} \ No newline at end of file diff --git a/inc/users.js b/inc/users.js index bf5aaddb..0f0c4d86 100644 --- a/inc/users.js +++ b/inc/users.js @@ -220,8 +220,8 @@ $( function() { } ); }); $('#grafna_install').click(function() { - $("#ajax").html('') - $("#ajax").html(wait_mess); + $("#ajaxmon").html('') + $("#ajaxmon").html(wait_mess); $.ajax( { url: "options.py", data: { @@ -232,26 +232,26 @@ $( function() { success: function( data ) { data = data.replace(/\s+/g,' '); if (data.indexOf('FAILED') != '-1') { - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } else if (data.indexOf('success') != '-1' ){ $('.alert-danger').remove(); $('.alert-warning').remove(); - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } else if (data.indexOf('Info') != '-1' ){ $('.alert-danger').remove(); $('.alert-warning').remove(); - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } else { $('.alert-danger').remove(); $('.alert-warning').remove(); - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } } } ); }); $('#haproxy_exp_install').click(function() { - $("#ajax").html('') - $("#ajax").html(wait_mess); + $("#ajaxmon").html('') + $("#ajaxmon").html(wait_mess); $.ajax( { url: "options.py", data: { @@ -262,17 +262,17 @@ $( function() { success: function( data ) { data = data.replace(/\s+/g,' '); if (data.indexOf('error') != '-1' || data.indexOf('FAILED') != '-1') { - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } else if (data.indexOf('success') != '-1' ){ $('.alert-danger').remove(); $('.alert-warning').remove(); - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); $('#cur_haproxy_exp_ver').text('HAProxy expoter is installed'); $('#haproxy_exp_install').text('Update'); } else if (data.indexOf('Info') != '-1' ){ $('.alert-danger').remove(); $('.alert-warning').remove(); - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } else { $('.alert-danger').remove(); $('.alert-warning').remove(); @@ -282,8 +282,8 @@ $( function() { } ); }); $('#nginx_exp_install').click(function() { - $("#ajax").html('') - $("#ajax").html(wait_mess); + $("#ajaxmon").html('') + $("#ajaxmon").html(wait_mess); $.ajax( { url: "options.py", data: { @@ -294,21 +294,21 @@ $( function() { success: function( data ) { data = data.replace(/\s+/g,' '); if (data.indexOf('error') != '-1' || data.indexOf('FAILED') != '-1') { - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } else if (data.indexOf('success') != '-1' ){ $('.alert-danger').remove(); $('.alert-warning').remove(); - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); $('#cur_nginx_exp_ver').text('Nginx expoter is installed'); $('#nginx_exp_install').text('Update'); } else if (data.indexOf('Info') != '-1' ){ $('.alert-danger').remove(); $('.alert-warning').remove(); - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } else { $('.alert-danger').remove(); $('.alert-warning').remove(); - $("#ajax").html('
    '+data+'
    '); + $("#ajaxmon").html('
    '+data+'
    '); } } } );