From 278bf1a90b6fb617133d6a951216f6887e37a06d Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Tue, 17 Apr 2018 09:46:57 +0600 Subject: [PATCH] v2.0.0.1 Bugs fixed --- README.md | 2 +- cgi-bin/funct.py | 3 +-- cgi-bin/sql.py | 67 ++++++++++++++++++++++++++++++------------------ cgi-bin/users.py | 6 ++--- inc/awesome.css | 2 +- inc/script.js | 3 +-- inc/style.css | 25 ++++++++++++++++-- inc/users.js | 24 +++++++++++------ inc/usersdop.js | 5 ++++ 9 files changed, 93 insertions(+), 44 deletions(-) create mode 100644 inc/usersdop.js diff --git a/README.md b/README.md index 458a1ec..f631753 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Meet Haproxy-wi 2.0! Now with DB and Admin web interface! Life has become easier, life has become more cheerful! +# Meet Haproxy-wi 2.0! Now with DB and Admin web interface! Life has become easier, life has become more cheerful! # Haproxy web interface A simple web interface(user-frendly web GUI) for managing Haproxy servers. Leave your [feedback](https://github.com/Aidaho12/haproxy-wi/issues) diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index ec91ec8..0edb048 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -161,7 +161,6 @@ def links(): '' @@ -198,7 +197,7 @@ def links(): '') print('' '' - '' + '' '') def show_login_links(): diff --git a/cgi-bin/sql.py b/cgi-bin/sql.py index d230e4c..a51dc03 100644 --- a/cgi-bin/sql.py +++ b/cgi-bin/sql.py @@ -15,7 +15,10 @@ def add_user(user, email, password, role, group): with con: cur.executescript(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') + return False + else: + return True cur.close() con.close() @@ -31,7 +34,10 @@ def update_user(user, email, password, role, group, id): with con: cur.executescript(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') + return False + else: + return True cur.close() con.close() @@ -54,7 +60,10 @@ def add_group(name, description): with con: cur.executescript(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') + return False + else: + return True cur.close() con.close() @@ -65,7 +74,7 @@ def delete_group(id): with con: cur.executescript(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') else: return True cur.close() @@ -82,7 +91,10 @@ def update_group(name, descript, id): with con: cur.executescript(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') + return False + else: + return True cur.close() con.close() @@ -93,7 +105,10 @@ def add_server(hostname, ip, group): with con: cur.executescript(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') + return False + else: + return True cur.close() con.close() @@ -104,7 +119,7 @@ def delete_server(id): with con: cur.executescript(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') else: return True cur.close() @@ -121,7 +136,7 @@ def update_server(hostname, ip, group, id): with con: cur.executescript(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') cur.close() con.close() @@ -147,7 +162,7 @@ def select_groups(**kwargs): try: cur.execute(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') else: return cur.fetchall() cur.close() @@ -159,7 +174,7 @@ def select_user_name_group(id): try: cur.execute(sql) except sqlite.Error as e: - print("An error occurred:", e.args[0]) + print('
An error occurred: ' + e.args[0] + '') else: return cur.fetchone() cur.close() @@ -232,7 +247,7 @@ def show_update_servers(): '') for server in SERVERS: print('' % server[0]) - print('' % (server[0], server[1], server[0])) + print('' % (server[0], server[1])) print('' % (server[0], server[2])) print('') get_groups_select("123", selected=server[3]) @@ -244,7 +259,7 @@ def show_update_user(user): USERS = select_users(user=user) for users in USERS: print('' % users[0]) - print('' % (users[0], users[1])) + print('' % (users[0], users[1])) print('' % (users[0], users[3])) print('' % (users[0], users[2])) print('') @@ -263,12 +278,12 @@ def show_update_server(server): SERVERS = select_servers(server=server) for server in SERVERS: print('' % server[0]) - print('' % (server[0], server[1], server[0])) + print('' % (server[0], server[1])) print('' % (server[0], server[2])) print('') get_groups_select("123", selected=server[3]) print('') - print('' % users[0]) + print('' % server[0]) print('' % server[0]) print('') @@ -323,7 +338,9 @@ def get_roles_select(id, **kwargs): selected = "" print('' % (role[1], selected, role[1])) print('') + form = cgi.FieldStorage() +error_mess = '
All fields must be completed X' if form.getvalue('newusername') is not None: email = form.getvalue('newemail') @@ -333,11 +350,11 @@ if form.getvalue('newusername') is not None: new_user = form.getvalue('newusername') if password is None or role is None or group is None: print('Content-type: text/html\n') - print("All fields must be completed") + print(error_mess) else: print('Content-type: text/html\n') - add_user(new_user, email, password, role, group) - show_update_user(new_user) + if add_user(new_user, email, password, role, group): + show_update_user(new_user) if form.getvalue('updateuser') is not None: email = form.getvalue('email') @@ -348,7 +365,7 @@ if form.getvalue('updateuser') is not None: id = form.getvalue('id') if password is None or role is None or group is None: print('Content-type: text/html\n') - print("All fields must be completed") + print(error_mess) else: print('Content-type: text/html\n') update_user(new_user, email, password, role, group, id) @@ -364,11 +381,11 @@ if form.getvalue('newserver') is not None: group = form.getvalue('newservergroup') if ip is None or group is None: print('Content-type: text/html\n') - print("All fields must be completed") + print(error_mess) else: print('Content-type: text/html\n') - add_server(hostname, ip, group) - show_update_server(hostname) + if add_server(hostname, ip, group): + show_update_server(hostname) if form.getvalue('serverdel') is not None: print('Content-type: text/html\n') @@ -379,8 +396,8 @@ if form.getvalue('newgroup') is not None: newgroup = form.getvalue('newgroup') desc = form.getvalue('newdesc') print('Content-type: text/html\n') - add_group(newgroup, desc) - show_update_group(newgroup) + if add_group(newgroup, desc): + show_update_group(newgroup) if form.getvalue('groupdel') is not None: print('Content-type: text/html\n') @@ -393,7 +410,7 @@ if form.getvalue('updategroup') is not None: id = form.getvalue('id') if name is None: print('Content-type: text/html\n') - print("All fields must be completed") + print(error_mess) else: print('Content-type: text/html\n') update_group(name, descript, id) @@ -405,7 +422,7 @@ if form.getvalue('updateserver') is not None: id = form.getvalue('id') if name is None or ip is None: print('Content-type: text/html\n') - print("All fields must be completed") + print(error_mess) else: print('Content-type: text/html\n') update_server(name, ip, group, id) diff --git a/cgi-bin/users.py b/cgi-bin/users.py index 214c623..1a86661 100644 --- a/cgi-bin/users.py +++ b/cgi-bin/users.py @@ -74,7 +74,7 @@ sql.get_roles_select("new-role") print('') sql.get_groups_select("new-group") print('' - '' + '' '') print('') @@ -105,7 +105,7 @@ print('

' '' - '' + '' '' '
' '' @@ -144,7 +144,7 @@ print('' '') sql.get_groups_select("new-server-group-add") print('' - '' + '' '') print('') diff --git a/inc/awesome.css b/inc/awesome.css index fd54f6c..8c9b7f7 100644 --- a/inc/awesome.css +++ b/inc/awesome.css @@ -101,7 +101,7 @@ font-family: "Font Awesome 5 Solid"; content: "\f2b9"; } -.add:before { +.add-admin:before { display: none; font-family: "Font Awesome 5 Solid"; content: "\f00c"; diff --git a/inc/script.js b/inc/script.js index dfb8ea4..8c6ad76 100644 --- a/inc/script.js +++ b/inc/script.js @@ -108,7 +108,6 @@ function showStats() { type: "GET", success: function( data ) { $("#ajax").html(data); - $.getScript(url); window.history.pushState("Stats", "Stats", cur_url[0]+"?serv="+$("#serv").val()); } } ); @@ -296,7 +295,7 @@ $( function() { var cur_url = '/cgi-bin/' + location.split('/').pop(); cur_url = cur_url.split('?'); - $('.menu ').each(function () { + $('.menu li').each(function () { var link = $(this).find('a').attr('href'); if (cur_url[0] == link) diff --git a/inc/style.css b/inc/style.css index 70de651..8bedcdf 100644 --- a/inc/style.css +++ b/inc/style.css @@ -37,6 +37,7 @@ pre { .icon { max-width: 20px; margin-left: 2px; + cursor: pointer; } .top-menu { position: fixed; @@ -385,7 +386,9 @@ pre { } .ui-state-active { background-color: #5D9CEB !important; + border: none !important; border-color: #5D9CEB !important; + font-weight: bold !important; } .ui-button { padding-left: 10px !important; @@ -400,6 +403,9 @@ pre { .ui-tabs-nav { padding-left: 20px !important; } + .ui-widget-header { + background: #5d9ceb !important; + } a { background-color: transparent; } @@ -503,9 +509,24 @@ a:focus { margin-left: -15px; } .update { - background-color: rgb(0,168,107) !important; + background-color: #dff0d8 !important; +} +.alert { + padding:15px; + margin-bottom:20px; + border:1px solid transparent; + border-radius:4px +} +.alert a { + cursor: pointer; + font-weight: bold; + padding-left: 10px; +} +.alert-danger { + color:#a94442; + background-color:#f2dede; + border-color:#ebccd1 } - label { display: inline-block; max-width: 100%; diff --git a/inc/users.js b/inc/users.js index 3c74f18..964341a 100644 --- a/inc/users.js +++ b/inc/users.js @@ -1,5 +1,9 @@ +var users = '/inc/usersdop.js' $( function() { + $('#error').hide(); + $('#add-user').click(function() { + $('#error').hide(); $.ajax( { url: "sql.py", data: { @@ -11,12 +15,14 @@ $( function() { }, type: "GET", success: function( data ) { - if (data == "All fields must be completed ") { - alert(data); + data = data.replace(/\s+/g,' '); + if (data == '
All fields must be completed X ') { + $("#ajax-users").append(data); + $.getScript(users); } else { $("#ajax-users").append(data); $( "#ajax-users tr td" ).addClass( "update", 1000, callbackUser ); - $.getScript(url); + $.getScript(url); } } } ); @@ -37,6 +43,7 @@ $( function() { } ); }); $('#add-server').click(function() { + $('#error').hide(); $.ajax( { url: "sql.py", data: { @@ -47,8 +54,9 @@ $( function() { type: "GET", success: function( data ) { data = data.replace(/\s+/g,' '); - if (data == "All fields must be completed ") { - alert(data); + if (data == '
All fields must be completed X ') { + $("#ajax-servers").append(data); + $.getScript(users); } else { $("#ajax-servers").append(data); $( "#ajax-servers tr td" ).addClass( "update", 1000, callback ); @@ -93,7 +101,7 @@ $( function() { } ); function removeUser(id) { - $("#user-"+id).css("background-color", "#f36223"); + $("#user-"+id).css("background-color", "#f2dede"); $.ajax( { url: "sql.py", data: { @@ -109,7 +117,7 @@ function removeUser(id) { } ); } function removeServer(id) { - $("#server-"+id).css("background-color", "#f36223"); + $("#server-"+id).css("background-color", "#f2dede"); $.ajax( { url: "sql.py", data: { @@ -125,7 +133,7 @@ function removeServer(id) { } ); } function removeGroup(id) { - $("#group-"+id).css("background-color", "#f36223"); + $("#group-"+id).css("background-color", "#f2dede"); $.ajax( { url: "sql.py", data: { diff --git a/inc/usersdop.js b/inc/usersdop.js new file mode 100644 index 0000000..5d04e22 --- /dev/null +++ b/inc/usersdop.js @@ -0,0 +1,5 @@ +$( function() { + $('#errorMess').click(function() { + $('#error').hide(); + }); +}); \ No newline at end of file