mirror of https://github.com/Aidaho12/haproxy-wi
parent
fbdae839e4
commit
e373d0acee
|
@ -330,16 +330,39 @@ def update_db_v_3_4(**kwargs):
|
||||||
except sqltool.Error as e:
|
except sqltool.Error as e:
|
||||||
if kwargs.get('silent') != 1:
|
if kwargs.get('silent') != 1:
|
||||||
if e.args[0] == 'duplicate column name: active' or e == " 1060 (42S21): Duplicate column name 'active' ":
|
if e.args[0] == 'duplicate column name: active' or e == " 1060 (42S21): Duplicate column name 'active' ":
|
||||||
print('Updating... go to version 3.4')
|
print('Updating... go to version 3.4.1')
|
||||||
else:
|
else:
|
||||||
print("An error occurred:", e)
|
print("An error occurred:", e)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
print("DB was update to 3.4<br />")
|
print("Updating... go to version 3.4.1<br />")
|
||||||
return True
|
return True
|
||||||
cur.close()
|
cur.close()
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
|
|
||||||
|
def update_db_v_3_4_1(**kwargs):
|
||||||
|
con, cur = get_cur()
|
||||||
|
sql = """
|
||||||
|
ALTER TABLE `user` ADD COLUMN activeuser INTEGER NOT NULL DEFAULT 1;
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
cur.execute(sql)
|
||||||
|
con.commit()
|
||||||
|
except sqltool.Error as e:
|
||||||
|
if kwargs.get('silent') != 1:
|
||||||
|
if e.args[0] == 'duplicate column name: active' or e == " 1060 (42S21): Duplicate column name 'active' ":
|
||||||
|
print('Updating... go to version 3.4.1')
|
||||||
|
else:
|
||||||
|
print("An error occurred:", e)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print("DB was update to 3.4.1<br />")
|
||||||
|
return True
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
|
||||||
def update_all():
|
def update_all():
|
||||||
update_db_v_31()
|
update_db_v_31()
|
||||||
update_db_v_3_2()
|
update_db_v_3_2()
|
||||||
|
@ -349,6 +372,7 @@ def update_all():
|
||||||
update_db_v_3_3()
|
update_db_v_3_3()
|
||||||
update_db_v_3_31()
|
update_db_v_3_31()
|
||||||
update_db_v_3_4()
|
update_db_v_3_4()
|
||||||
|
update_db_v_3_4_1()
|
||||||
|
|
||||||
def update_all_silent():
|
def update_all_silent():
|
||||||
update_db_v_31(silent=1)
|
update_db_v_31(silent=1)
|
||||||
|
@ -359,6 +383,7 @@ def update_all_silent():
|
||||||
update_db_v_3_3(silent=1)
|
update_db_v_3_3(silent=1)
|
||||||
update_db_v_3_31(silent=1)
|
update_db_v_3_31(silent=1)
|
||||||
update_db_v_3_4(silent=1)
|
update_db_v_3_4(silent=1)
|
||||||
|
update_db_v_3_4_1(silent=1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
create_table()
|
create_table()
|
||||||
|
|
19
app/sql.py
19
app/sql.py
|
@ -20,12 +20,12 @@ def out_error(e):
|
||||||
error = e.args[0]
|
error = e.args[0]
|
||||||
print('<span class="alert alert-danger" id="error">An error occurred: ' + error + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
|
print('<span class="alert alert-danger" id="error">An error occurred: ' + error + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
|
||||||
|
|
||||||
def add_user(user, email, password, role, group):
|
def add_user(user, email, password, role, group, activeuser):
|
||||||
con, cur = create_db.get_cur()
|
con, cur = create_db.get_cur()
|
||||||
if password != 'aduser':
|
if password != 'aduser':
|
||||||
sql = """INSERT INTO user (username, email, password, role, groups) VALUES ('%s', '%s', '%s', '%s', '%s')""" % (user, email, password, role, group)
|
sql = """INSERT INTO user (username, email, password, role, groups, activeuser) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')""" % (user, email, password, role, group, activeuser)
|
||||||
else:
|
else:
|
||||||
sql = """INSERT INTO user (username, email, role, groups, ldap_user) VALUES ('%s', '%s', '%s', '%s', '1')""" % (user, email, role, group)
|
sql = """INSERT INTO user (username, email, role, groups, ldap_user, activeuser) VALUES ('%s', '%s', '%s', '%s', '1', '%s')""" % (user, email, role, group, activeuser)
|
||||||
try:
|
try:
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
con.commit()
|
con.commit()
|
||||||
|
@ -38,14 +38,15 @@ def add_user(user, email, password, role, group):
|
||||||
cur.close()
|
cur.close()
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
def update_user(user, email, password, role, group, id):
|
def update_user(user, email, password, role, group, id, activeuser):
|
||||||
con, cur = create_db.get_cur()
|
con, cur = create_db.get_cur()
|
||||||
sql = """update user set username = '%s',
|
sql = """update user set username = '%s',
|
||||||
email = '%s',
|
email = '%s',
|
||||||
password = '%s',
|
password = '%s',
|
||||||
role = '%s',
|
role = '%s',
|
||||||
groups = '%s'
|
groups = '%s',
|
||||||
where id = '%s'""" % (user, email, password, role, group, id)
|
activeuser = '%s'
|
||||||
|
where id = '%s'""" % (user, email, password, role, group, activeuser, id)
|
||||||
try:
|
try:
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
con.commit()
|
con.commit()
|
||||||
|
@ -1161,11 +1162,12 @@ if form.getvalue('newuser') is not None:
|
||||||
group = form.getvalue('newgroupuser')
|
group = form.getvalue('newgroupuser')
|
||||||
new_user = form.getvalue('newusername')
|
new_user = form.getvalue('newusername')
|
||||||
page = form.getvalue('page')
|
page = form.getvalue('page')
|
||||||
|
activeuser = form.getvalue('activeuser')
|
||||||
print('Content-type: text/html\n')
|
print('Content-type: text/html\n')
|
||||||
if password is None or role is None or group is None:
|
if password is None or role is None or group is None:
|
||||||
print(error_mess)
|
print(error_mess)
|
||||||
else:
|
else:
|
||||||
if add_user(new_user, email, password, role, group):
|
if add_user(new_user, email, password, role, group, activeuser):
|
||||||
show_update_user(new_user, page)
|
show_update_user(new_user, page)
|
||||||
|
|
||||||
if form.getvalue('updateuser') is not None:
|
if form.getvalue('updateuser') is not None:
|
||||||
|
@ -1175,11 +1177,12 @@ if form.getvalue('updateuser') is not None:
|
||||||
group = form.getvalue('usergroup')
|
group = form.getvalue('usergroup')
|
||||||
new_user = form.getvalue('updateuser')
|
new_user = form.getvalue('updateuser')
|
||||||
id = form.getvalue('id')
|
id = form.getvalue('id')
|
||||||
|
activeuser = form.getvalue('activeuser')
|
||||||
print('Content-type: text/html\n')
|
print('Content-type: text/html\n')
|
||||||
if password is None or role is None or group is None:
|
if password is None or role is None or group is None:
|
||||||
print(error_mess)
|
print(error_mess)
|
||||||
else:
|
else:
|
||||||
update_user(new_user, email, password, role, group, id)
|
update_user(new_user, email, password, role, group, id, activeuser)
|
||||||
|
|
||||||
if form.getvalue('userdel') is not None:
|
if form.getvalue('userdel') is not None:
|
||||||
print('Content-type: text/html\n')
|
print('Content-type: text/html\n')
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
<tr class="overviewHead">
|
<tr class="overviewHead">
|
||||||
<td class="padding10 first-collumn">Login name</td>
|
<td class="padding10 first-collumn">Login name</td>
|
||||||
<td>Password</td>
|
<td>Password</td>
|
||||||
|
<td>Active</td>
|
||||||
<td>Email</td>
|
<td>Email</td>
|
||||||
<td>Role</td>
|
<td>Role</td>
|
||||||
<td>Group</td>
|
<td>Group</td>
|
||||||
|
@ -46,6 +47,13 @@
|
||||||
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
<td class="checkbox">
|
||||||
|
{% if user.7 == 1 %}
|
||||||
|
<label for="activeuser-{{user.0}}"></label><input type="checkbox" id="activeuser-{{user.0}}" checked>
|
||||||
|
{% else %}
|
||||||
|
<label for="activeuser-{{user.0}}"></label><input type="checkbox" id="activeuser-{{user.0}}">
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if user.6 == 1%}
|
{% if user.6 == 1%}
|
||||||
<input type="text" id="email-{{user.0}}" value="{{user.2}}" class="form-control" readonly>
|
<input type="text" id="email-{{user.0}}" value="{{user.2}}" class="form-control" readonly>
|
||||||
|
@ -487,6 +495,12 @@
|
||||||
<input type="password" name="new-password" id="new-password" class="form-control">
|
<input type="password" name="new-password" id="new-password" class="form-control">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="padding20">Active</td>
|
||||||
|
<td>
|
||||||
|
<label for="activeuser"></label><input type="checkbox" id="activeuser" checked>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="padding20">
|
<td class="padding20">
|
||||||
Email
|
Email
|
||||||
|
|
|
@ -10,6 +10,13 @@
|
||||||
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
<td class="checkbox">
|
||||||
|
{% if user.7 == 1 %}
|
||||||
|
<label for="activeuser-{{user.0}}"></label><input type="checkbox" id="activeuser-{{user.0}}" checked>
|
||||||
|
{% else %}
|
||||||
|
<label for="activeuser-{{user.0}}"></label><input type="checkbox" id="activeuser-{{user.0}}">
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" id="email-{{user.0}}" value="{{user.2}}" class="form-control">
|
<input type="text" id="email-{{user.0}}" value="{{user.2}}" class="form-control">
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -99,7 +99,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="copyright-menu">
|
<div class="copyright-menu">
|
||||||
HAproxy-WI v3.4
|
HAproxy-WI v3.4.1
|
||||||
<br>
|
<br>
|
||||||
<a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 30px; color: red;" class="patreon"> Patreon</a>
|
<a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 30px; color: red;" class="patreon"> Patreon</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
<tr class="overviewHead">
|
<tr class="overviewHead">
|
||||||
<td class="padding10 first-collumn">Login name</td>
|
<td class="padding10 first-collumn">Login name</td>
|
||||||
<td>Password</td>
|
<td>Password</td>
|
||||||
|
<td>Active</td>
|
||||||
<td>Email</td>
|
<td>Email</td>
|
||||||
<td>Role</td>
|
<td>Role</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
@ -47,6 +48,13 @@
|
||||||
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
<td class="checkbox">
|
||||||
|
{% if user.7 == 1 %}
|
||||||
|
<label for="activeuser-{{user.0}}"></label><input type="checkbox" id="activeuser-{{user.0}}" checked>
|
||||||
|
{% else %}
|
||||||
|
<label for="activeuser-{{user.0}}"></label><input type="checkbox" id="activeuser-{{user.0}}">
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if user.6 == 1%}
|
{% if user.6 == 1%}
|
||||||
<input type="text" id="email-{{user.0}}" value="{{user.2}}" class="form-control" readonly>
|
<input type="text" id="email-{{user.0}}" value="{{user.2}}" class="form-control" readonly>
|
||||||
|
@ -378,6 +386,12 @@
|
||||||
<input type="password" name="new-password" id="new-password" class="form-control">
|
<input type="password" name="new-password" id="new-password" class="form-control">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="padding20">Active</td>
|
||||||
|
<td>
|
||||||
|
<label for="activeuser"></label><input type="checkbox" id="activeuser" checked>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="padding20">
|
<td class="padding20">
|
||||||
Email
|
Email
|
||||||
|
|
10
inc/users.js
10
inc/users.js
|
@ -426,6 +426,10 @@ function addUser() {
|
||||||
allFields.removeClass( "ui-state-error" );
|
allFields.removeClass( "ui-state-error" );
|
||||||
valid = valid && checkLength( $('#new-username'), "user name", 1 );
|
valid = valid && checkLength( $('#new-username'), "user name", 1 );
|
||||||
valid = valid && checkLength( $('#new-password'), "password", 1 );
|
valid = valid && checkLength( $('#new-password'), "password", 1 );
|
||||||
|
var activeuser = 0;
|
||||||
|
if ($('#activeuser').is(':checked')) {
|
||||||
|
activeuser = '1';
|
||||||
|
}
|
||||||
if (valid) {
|
if (valid) {
|
||||||
$.ajax( {
|
$.ajax( {
|
||||||
url: "sql.py",
|
url: "sql.py",
|
||||||
|
@ -435,6 +439,7 @@ function addUser() {
|
||||||
newpassword: $('#new-password').val(),
|
newpassword: $('#new-password').val(),
|
||||||
newemail: $('#new-email').val(),
|
newemail: $('#new-email').val(),
|
||||||
newrole: $('#new-role').val(),
|
newrole: $('#new-role').val(),
|
||||||
|
activeuser: activeuser,
|
||||||
page: cur_url[0],
|
page: cur_url[0],
|
||||||
newgroupuser: $('#new-group').val()
|
newgroupuser: $('#new-group').val()
|
||||||
},
|
},
|
||||||
|
@ -770,6 +775,10 @@ function updateUser(id) {
|
||||||
} else {
|
} else {
|
||||||
var usergroup = $('#usergroup-'+id ).val();
|
var usergroup = $('#usergroup-'+id ).val();
|
||||||
}
|
}
|
||||||
|
var activeuser = 0;
|
||||||
|
if ($('#activeuser-'+id).is(':checked')) {
|
||||||
|
activeuser = '1';
|
||||||
|
}
|
||||||
$.ajax( {
|
$.ajax( {
|
||||||
url: "sql.py",
|
url: "sql.py",
|
||||||
data: {
|
data: {
|
||||||
|
@ -778,6 +787,7 @@ function updateUser(id) {
|
||||||
email: $('#email-'+id).val(),
|
email: $('#email-'+id).val(),
|
||||||
role: $('#role-'+id).val(),
|
role: $('#role-'+id).val(),
|
||||||
usergroup: usergroup,
|
usergroup: usergroup,
|
||||||
|
activeuser: activeuser,
|
||||||
id: id
|
id: id
|
||||||
},
|
},
|
||||||
type: "GET",
|
type: "GET",
|
||||||
|
|
Loading…
Reference in New Issue