diff --git a/README.md b/README.md index 40db640f..28dc926b 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ For install just [dowload](https://github.com/Aidaho12/haproxy-wi/archive/master $ cd /var/www/ $ unzip master.zip $ mv haproxy-wi-master/ haproxy-wi +$ pip install -r haproxy-wi/requirements.txt $ cd haproxy-wi/cgi-bin $ chmod +x *.py $ ./create_db.py diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 9d8465ec..2b3a4fe5 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -188,7 +188,7 @@ def links(): '') print('' '' - '' + '' '') def show_login_links(): diff --git a/cgi-bin/haproxy-webintarface.config b/cgi-bin/haproxy-webintarface.config index 419742f3..1646f1dc 100644 --- a/cgi-bin/haproxy-webintarface.config +++ b/cgi-bin/haproxy-webintarface.config @@ -2,8 +2,6 @@ #Path to files destination fullpath = /var/www/haproxy-wi/ cgi_path = %(fullpath)s/cgi-bin/ -server_bind_ip = 0.0.0.0 -server_port = 8000 log_path = %(fullpath)s/log/ time_zone = UTC diff --git a/cgi-bin/sql.py b/cgi-bin/sql.py index b451f2ef..c771f717 100644 --- a/cgi-bin/sql.py +++ b/cgi-bin/sql.py @@ -58,11 +58,12 @@ def add_group(name, description): sql = """INSERT INTO groups (name, description) VALUES ('%s', '%s')""" % (name, description) try: with con: - cur.executescript(sql) + cur.execute(sql) except sqlite.Error as e: print('An error occurred: ' + e.args[0] + ' X') return False else: + print(cur.lastrowid) return True cur.close() con.close() @@ -318,7 +319,7 @@ def show_update_user(user): need_id_group = "usergroup-%s" % users[0] get_groups_select(need_id_group, selected=users[5]) print('') - print('' % users[0]) + #print('' % users[0]) print('' % users[0]) print('') @@ -338,7 +339,7 @@ def show_update_server(server): print('') get_type_ip_checkbox(server[0]) print('') - print('' % server[0]) + #print('' % server[0]) print('' % server[0]) print('') @@ -348,7 +349,7 @@ def show_update_group(group): print('' % group[0]) print('' % (group[0], group[1])) print('' % (group[0], group[2])) - print('') + print('' % group[0]) print('') print('') diff --git a/cgi-bin/users.py b/cgi-bin/users.py index 7b653b0c..06359272 100644 --- a/cgi-bin/users.py +++ b/cgi-bin/users.py @@ -51,7 +51,7 @@ for users in USERS: need_id_group = "usergroup-%s" % users[0] sql.get_groups_select(need_id_group, selected=users[5]) print('') - print('' % users[0]) + #print('' % users[0]) print('' % users[0]) print('') print('' @@ -90,7 +90,7 @@ for group in GROUPS: print('' % group[0]) print('' % (group[0], group[1])) print('' % (group[0], group[2])) - print('' % group[0]) + #print('' % group[0]) print('' % group[0]) print('') print('' @@ -135,7 +135,7 @@ for server in SERVERS: print('') sql.get_type_ip_checkbox(server[0]) print('') - print('' % server[0]) + #print('' % server[0]) print('' % server[0]) print('') print('' diff --git a/image/haproxy-wi-admin-area.jpeg b/image/haproxy-wi-admin-area.jpeg index 30ffffe8..4782ffc6 100644 Binary files a/image/haproxy-wi-admin-area.jpeg and b/image/haproxy-wi-admin-area.jpeg differ diff --git a/inc/script.js b/inc/script.js index e6ef6c61..e52968ef 100644 --- a/inc/script.js +++ b/inc/script.js @@ -253,7 +253,6 @@ $( function() { }); $( "input[type=submit], button" ).button(); $( "input[type=checkbox]" ).checkboxradio(); - $( "#number" ).spinner(); $( ".controlgroup" ).controlgroup(); function ajaxActionServers(action, id) { diff --git a/inc/style.css b/inc/style.css index 80913c4f..6d6febc8 100644 --- a/inc/style.css +++ b/inc/style.css @@ -266,7 +266,7 @@ pre { font-weight: bold; } .overview tr{ - border: 1px solid #ddd; + border-bottom: 1px solid #ddd; border-radius: 5px; } diff --git a/inc/users.js b/inc/users.js index 0969f4e0..1ab94cd3 100644 --- a/inc/users.js +++ b/inc/users.js @@ -1,6 +1,19 @@ var users = '/inc/usersdop.js' var awesome = "/inc/fontawesome.min.js" +jQuery.expr[':'].regex = function(elem, index, match) { + var matchParams = match[3].split(','), + validLabels = /^(data|css):/, + attr = { + method: matchParams[0].match(validLabels) ? + matchParams[0].split(':')[0] : 'attr', + property: matchParams.shift().replace(validLabels,'') + }, + regexFlags = 'ig', + regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags); + return regex.test(jQuery(elem)[attr.method](attr.property)); +} + $( function() { $('.alert-danger').remove(); @@ -41,9 +54,17 @@ $( function() { }, type: "GET", success: function( data ) { - $("#ajax-group").append(data); - $( "#ajax-group tr td" ).addClass( "update", 1000, callbackGroup ); - window.location.reload(); + if (data.indexOf('error') != '-1') { + $("#ajax-group").append(data); + $.getScript(users); + } else { + var getId = new RegExp('[0-9]+'); + var id = data.match(getId); + $("#ajax-group").append(data); + $( "#ajax-group tr td" ).addClass( "update", 1000, callbackGroup ); + $('select:regex(id, group)').append('').selectmenu("refresh"); + $.getScript(awesome); + } } } ); }); @@ -73,7 +94,7 @@ $( function() { $("#ajax-servers").append(data); $.getScript(users); } else { - $('.alert-danger').hide(); + $('.alert-danger').remove(); $("#ajax-servers").append(data); $( "#ajax-servers tr td" ).addClass( "update", 1000, callback ); $.getScript(url); @@ -117,6 +138,26 @@ $( function() { } }); + $( "#ajax-users input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateUser(id[1]) + }); + $( "#ajax-users select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateUser(id[1]) + }); + $( "#ajax-group input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateGroup(id[1]) + }); + $( "#ajax-servers input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateServer(id[1]) + }); + $( "#ajax-servers select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateServer(id[1]) + }); } ); function removeUser(id) { $("#user-"+id).css("background-color", "#f2dede"); @@ -162,11 +203,14 @@ function removeGroup(id) { data = data.replace(/\s+/g,' '); if(data == "Ok ") { $("#group-"+id).remove(); + $('select:regex(id, group) option[value='+id+']').remove(); + $('select:regex(id, group)').selectmenu("refresh"); } } } ); } function updateUser(id) { + $('.alert-danger').remove(); $.ajax( { url: "sql.py", data: { @@ -180,18 +224,21 @@ function updateUser(id) { type: "GET", success: function( data ) { data = data.replace(/\s+/g,' '); - if (data == "All fields must be completed ") { - alert(data); - } else { - $("#user-"+id).addClass( "update", 1000 ); - setTimeout(function() { - $( "#user-"+id ).removeClass( "update" ); - }, 2500 ); + if (data.indexOf('error') != '-1') { + $("#ajax-users").append(data); + $.getScript(users); + } else { + $('.alert-danger').remove(); + $("#user-"+id).addClass( "update", 1000 ); + setTimeout(function() { + $( "#user-"+id ).removeClass( "update" ); + }, 2500 ); } } } ); } function updateGroup(id) { + $('#error').remove(); $.ajax( { url: "sql.py", data: { @@ -202,18 +249,23 @@ function updateGroup(id) { type: "GET", success: function( data ) { data = data.replace(/\s+/g,' '); - if (data == "All fields must be completed ") { - alert(data); - } else { - $("#group-"+id).addClass( "update", 1000 ); - setTimeout(function() { - $( "#group-"+id ).removeClass( "update" ); - }, 2500 ); + if (data.indexOf('error') != '-1') { + $("#ajax-group").append(data); + $.getScript(users); + } else { + $('.alert-danger').remove(); + $("#group-"+id).addClass( "update", 1000 ); + setTimeout(function() { + $( "#group-"+id ).removeClass( "update" ); + }, 2500 ); + $('select:regex(id, group) option[value='+id+']').remove(); + $('select:regex(id, group)').append('').selectmenu("refresh"); } } } ); } function updateServer(id) { + $('.alert-danger').remove(); var typeip = 0; var enable = 0; if ($('#typeip-'+id).is(':checked')) { @@ -235,13 +287,15 @@ function updateServer(id) { type: "GET", success: function( data ) { data = data.replace(/\s+/g,' '); - if (data == "All fields must be completed ") { - alert(data); - } else { - $("#server-"+id).addClass( "update", 1000 ); - setTimeout(function() { - $( "#server-"+id ).removeClass( "update" ); - }, 2500 ); + if (data.indexOf('error') != '-1') { + $("#ajax-servers").append(data); + $.getScript(users); + } else { + $('.alert-danger').remove(); + $("#server-"+id).addClass( "update", 1000 ); + setTimeout(function() { + $( "#server-"+id ).removeClass( "update" ); + }, 2500 ); } } } );