mirror of https://github.com/Aidaho12/haproxy-wi
parent
fbdae839e4
commit
e373d0acee
|
@ -330,15 +330,38 @@ def update_db_v_3_4(**kwargs):
|
|||
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')
|
||||
print('Updating... go to version 3.4.1')
|
||||
else:
|
||||
print("An error occurred:", e)
|
||||
return False
|
||||
else:
|
||||
print("DB was update to 3.4<br />")
|
||||
print("Updating... go to version 3.4.1<br />")
|
||||
return True
|
||||
cur.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():
|
||||
update_db_v_31()
|
||||
|
@ -349,6 +372,7 @@ def update_all():
|
|||
update_db_v_3_3()
|
||||
update_db_v_3_31()
|
||||
update_db_v_3_4()
|
||||
update_db_v_3_4_1()
|
||||
|
||||
def update_all_silent():
|
||||
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_31(silent=1)
|
||||
update_db_v_3_4(silent=1)
|
||||
update_db_v_3_4_1(silent=1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_table()
|
||||
|
|
19
app/sql.py
19
app/sql.py
|
@ -20,12 +20,12 @@ def out_error(e):
|
|||
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>')
|
||||
|
||||
def add_user(user, email, password, role, group):
|
||||
def add_user(user, email, password, role, group, activeuser):
|
||||
con, cur = create_db.get_cur()
|
||||
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:
|
||||
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:
|
||||
cur.execute(sql)
|
||||
con.commit()
|
||||
|
@ -38,14 +38,15 @@ def add_user(user, email, password, role, group):
|
|||
cur.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()
|
||||
sql = """update user set username = '%s',
|
||||
email = '%s',
|
||||
password = '%s',
|
||||
role = '%s',
|
||||
groups = '%s'
|
||||
where id = '%s'""" % (user, email, password, role, group, id)
|
||||
groups = '%s',
|
||||
activeuser = '%s'
|
||||
where id = '%s'""" % (user, email, password, role, group, activeuser, id)
|
||||
try:
|
||||
cur.execute(sql)
|
||||
con.commit()
|
||||
|
@ -1161,11 +1162,12 @@ if form.getvalue('newuser') is not None:
|
|||
group = form.getvalue('newgroupuser')
|
||||
new_user = form.getvalue('newusername')
|
||||
page = form.getvalue('page')
|
||||
activeuser = form.getvalue('activeuser')
|
||||
print('Content-type: text/html\n')
|
||||
if password is None or role is None or group is None:
|
||||
print(error_mess)
|
||||
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)
|
||||
|
||||
if form.getvalue('updateuser') is not None:
|
||||
|
@ -1175,11 +1177,12 @@ if form.getvalue('updateuser') is not None:
|
|||
group = form.getvalue('usergroup')
|
||||
new_user = form.getvalue('updateuser')
|
||||
id = form.getvalue('id')
|
||||
activeuser = form.getvalue('activeuser')
|
||||
print('Content-type: text/html\n')
|
||||
if password is None or role is None or group is None:
|
||||
print(error_mess)
|
||||
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:
|
||||
print('Content-type: text/html\n')
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<tr class="overviewHead">
|
||||
<td class="padding10 first-collumn">Login name</td>
|
||||
<td>Password</td>
|
||||
<td>Active</td>
|
||||
<td>Email</td>
|
||||
<td>Role</td>
|
||||
<td>Group</td>
|
||||
|
@ -46,6 +47,13 @@
|
|||
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
||||
{% endif %}
|
||||
</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>
|
||||
{% if user.6 == 1%}
|
||||
<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">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding20">Active</td>
|
||||
<td>
|
||||
<label for="activeuser"></label><input type="checkbox" id="activeuser" checked>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding20">
|
||||
Email
|
||||
|
|
|
@ -10,6 +10,13 @@
|
|||
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
||||
{% endif %}
|
||||
</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>
|
||||
<input type="text" id="email-{{user.0}}" value="{{user.2}}" class="form-control">
|
||||
</td>
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
</ul>
|
||||
</nav>
|
||||
<div class="copyright-menu">
|
||||
HAproxy-WI v3.4
|
||||
HAproxy-WI v3.4.1
|
||||
<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>
|
||||
</div>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<tr class="overviewHead">
|
||||
<td class="padding10 first-collumn">Login name</td>
|
||||
<td>Password</td>
|
||||
<td>Active</td>
|
||||
<td>Email</td>
|
||||
<td>Role</td>
|
||||
<td></td>
|
||||
|
@ -47,6 +48,13 @@
|
|||
<input type="password" id="password-{{user.0}}" value="{{user.3}}" class="form-control">
|
||||
{% endif %}
|
||||
</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>
|
||||
{% if user.6 == 1%}
|
||||
<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">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding20">Active</td>
|
||||
<td>
|
||||
<label for="activeuser"></label><input type="checkbox" id="activeuser" checked>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding20">
|
||||
Email
|
||||
|
|
10
inc/users.js
10
inc/users.js
|
@ -426,6 +426,10 @@ function addUser() {
|
|||
allFields.removeClass( "ui-state-error" );
|
||||
valid = valid && checkLength( $('#new-username'), "user name", 1 );
|
||||
valid = valid && checkLength( $('#new-password'), "password", 1 );
|
||||
var activeuser = 0;
|
||||
if ($('#activeuser').is(':checked')) {
|
||||
activeuser = '1';
|
||||
}
|
||||
if (valid) {
|
||||
$.ajax( {
|
||||
url: "sql.py",
|
||||
|
@ -435,6 +439,7 @@ function addUser() {
|
|||
newpassword: $('#new-password').val(),
|
||||
newemail: $('#new-email').val(),
|
||||
newrole: $('#new-role').val(),
|
||||
activeuser: activeuser,
|
||||
page: cur_url[0],
|
||||
newgroupuser: $('#new-group').val()
|
||||
},
|
||||
|
@ -770,6 +775,10 @@ function updateUser(id) {
|
|||
} else {
|
||||
var usergroup = $('#usergroup-'+id ).val();
|
||||
}
|
||||
var activeuser = 0;
|
||||
if ($('#activeuser-'+id).is(':checked')) {
|
||||
activeuser = '1';
|
||||
}
|
||||
$.ajax( {
|
||||
url: "sql.py",
|
||||
data: {
|
||||
|
@ -778,6 +787,7 @@ function updateUser(id) {
|
|||
email: $('#email-'+id).val(),
|
||||
role: $('#role-'+id).val(),
|
||||
usergroup: usergroup,
|
||||
activeuser: activeuser,
|
||||
id: id
|
||||
},
|
||||
type: "GET",
|
||||
|
|
Loading…
Reference in New Issue