Each server has its own creds!
pull/19/head
Aidaho12 2018-06-24 15:31:28 +06:00
parent 96ed5b6fda
commit 540e9acab1
16 changed files with 446 additions and 90 deletions

View File

@ -229,7 +229,7 @@ def update_db_v_2_4(**kwargs):
except sqltool.Error as e:
print(kwargs.get('silent'))
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: user_id':
if e.args[0] == 'duplicate column name: user_id' or e == "1060 (42S21): Duplicate column name 'user_id' ":
print('Updating... go to version 2.5.3')
else:
print("An error occurred:", e)
@ -284,7 +284,7 @@ def update_db_v_2_5_6(**kwargs):
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: exp' or e == "1060 (42S21): Duplicate column name 'exp' ":
if e.args[0] == 'duplicate column name: exp' or e == " 1060 (42S21): Duplicate column name 'exp' ":
print('Updating... go to version 2.5.6.1')
else:
print("An error occurred:", e)
@ -311,7 +311,7 @@ def update_db_v_2_5_6_1(**kwargs):
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: token' or e == "1060 (42S21): Duplicate column name 'token' ":
print('Already updated. No run more. Thx =^.^=')
print('Updating... go to version 2.6')
else:
print("An error occurred:", e)
return False
@ -321,7 +321,79 @@ def update_db_v_2_5_6_1(**kwargs):
cur.close()
con.close()
def update_all():
def update_db_v_2_6(**kwargs):
con, cur = get_cur()
sql = """ select id from cred limit 1 """
try:
cur.execute(sql)
except sqltool.Error as e:
if mysql_enable == '0':
sql = """ CREATE TABLE IF NOT EXISTS `cred_id` (
`id` integer primary key autoincrement,
`name` VARCHAR ( 64 ) UNIQUE,
`enable` INTEGER NOT NULL DEFAULT 1,
`username` VARCHAR ( 64 ) NOT NULL,
`password` VARCHAR ( 64 ) NOT NULL
);
INSERT INTO cred_id (enable, username, password) select enable, username, password from cred;
drop table cred;
ALTER TABLE cred_id RENAME to cred;
"""
try:
cur.executescript(sql)
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: name' or e == "1060 (42S21): Duplicate column name 'name' ":
pass
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.6<br />")
return True
else:
sql = [ "CREATE TABLE IF NOT EXISTS cred_id(`id` integer primary key AUTO_INCREMENT, `name` VARCHAR ( 64 ) UNIQUE, `enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL ); ",
"INSERT INTO cred_id (enable, username, password) select enable, username, password from cred;",
"drop table cred;",
"ALTER TABLE cred_id RENAME to cred;" ]
try:
for i in sql:
cur.execute(i)
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: id' or e == "1060 (42S21): Duplicate column name 'id' ":
print('DB was updated. No more run')
else:
print("An error occurred:", e)
return False
else:
pass
return True
cur.close()
con.close()
def update_db_v_2_61(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `servers` ADD COLUMN cred 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: cred' or e == "1060 (42S21): Duplicate column name 'cred' ":
print('DB was updated. No more run')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.6<br />")
return True
cur.close()
con.close()
def update_all():
update_db_v_2_0_1()
update_db_v_2_0_1_1()
update_db_v_2_0_5()
@ -329,6 +401,8 @@ def update_all():
update_db_v_2_5_3()
update_db_v_2_5_6()
update_db_v_2_5_6_1()
update_db_v_2_6()
update_db_v_2_61()
def update_all_silent():
update_db_v_2_0_1(silent=1)
@ -338,4 +412,6 @@ def update_all_silent():
update_db_v_2_5_3(silent=1)
update_db_v_2_5_6(silent=1)
update_db_v_2_5_6_1(silent=1)
update_db_v_2_6(silent=1)
update_db_v_2_61(silent=1)

View File

@ -126,17 +126,21 @@ def get_button(button, **kwargs):
def ssh_connect(serv, **kwargs):
import sql
ssh_enable = sql.ssh_enable()
ssh_user_name = sql.select_ssh_username()
fullpath = get_config_var('main', 'fullpath')
for sshs in sql.select_ssh(serv=serv):
ssh_enable = sshs[3]
ssh_user_name = sshs[4]
ssh_user_password = sshs[5]
ssh_key_name = fullpath+'/keys/%s.pem' % sshs[2]
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
if ssh_enable == 1:
k = paramiko.RSAKey.from_private_key_file(get_config_var('ssh', 'ssh_keys'))
k = paramiko.RSAKey.from_private_key_file(ssh_key_name)
ssh.connect(hostname = serv, username = ssh_user_name, pkey = k )
else:
ssh.connect(hostname = serv, username = ssh_user_name, password = sql.select_ssh_password())
ssh.connect(hostname = serv, username = ssh_user_name, password = ssh_user_password)
if kwargs.get('check'):
return True
else:
@ -446,7 +450,7 @@ def ssh_command(serv, commands, **kwargs):
elif kwargs.get("server_status") == "1":
server_status(stdout)
else:
print('<div style="margin: -10px;">'+stdout.read().decode(encoding='UTF-8')+'</div>')
print(stdout.read().decode(encoding='UTF-8'))
print(stderr.read().decode(encoding='UTF-8'))
try:

View File

@ -26,10 +26,6 @@ mysql_password = haproxy-wi
mysql_db = haproxywi
mysql_host = 127.0.0.1
[ssh]
#SSH keys to connect without password to HAproxy servers
ssh_keys = ${main:fullpath}/app/id_rsa.pem
[logs]
#Logs save locally, disable by default
local_path_logs = /var/log/haproxy.log

View File

@ -27,7 +27,9 @@ if form.getvalue('getcert') is not None and serv is not None:
print('<div class="alert alert-danger" style="margin:0">Can not connect to the server</div>')
if form.getvalue('ssh_cert'):
ssh_keys = funct.get_config_var('ssh', 'ssh_keys')
fullpath = funct.get_config_var('main', 'fullpath')
name = form.getvalue('name')
ssh_keys = fullpath+'/keys/'+name+'.pem'
try:
with open(ssh_keys, "w") as conf:

View File

@ -7,6 +7,9 @@ env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('ovw.html')
print('Content-type: text/html\n')
if create_db.check_db():
if create_db.create_table():
create_db.update_all()
create_db.update_all_silent()
funct.check_login()

View File

@ -42,9 +42,9 @@ def get_overviewServers():
commands1 = [ "top -u haproxy -b -n 1" ]
for server in sorted(listhap):
print('<tr><td class="overviewTr first-collumn"><a name="'+server[1]+'"></a><h3 title="IP ' + server[2] + '">' + server[1] + ':</h3></td>')
print('<td class="overviewTd"><pre style="font-size: 12px;">')
print('<td class="overviewTd" style="padding-top: 10px;"><pre style="font-size: 12px;">')
funct.ssh_command(server[2], commands)
print('</pre></td><td><pre style="font-size: 12px;">')
print('</pre></td><td style="padding-top: 10px;"><pre style="font-size: 12px;">')
funct.ssh_command(server[2], commands1)
print('</td><td style="padding: 10px;font-size: 13px;">')
funct.show_backends(server[2])

View File

@ -110,9 +110,9 @@ def update_group(name, descript, id):
cur.close()
con.close()
def add_server(hostname, ip, group, typeip, enable, master):
def add_server(hostname, ip, group, typeip, enable, master, cred):
con, cur = create_db.get_cur()
sql = """INSERT INTO servers (hostname, ip, groups, type_ip, enable, master) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')""" % (hostname, ip, group, typeip, enable, master)
sql = """INSERT INTO servers (hostname, ip, groups, type_ip, enable, master, cred) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')""" % (hostname, ip, group, typeip, enable, master, cred)
try:
cur.execute(sql)
con.commit()
@ -139,7 +139,7 @@ def delete_server(id):
cur.close()
con.close()
def update_server(hostname, ip, group, typeip, enable, master, id):
def update_server(hostname, ip, group, typeip, enable, master, id, cred):
con, cur = create_db.get_cur()
sql = """update servers set
hostname = '%s',
@ -147,8 +147,9 @@ def update_server(hostname, ip, group, typeip, enable, master, id):
groups = '%s',
type_ip = '%s',
enable = '%s',
master = '%s'
where id = '%s'""" % (hostname, ip, group, typeip, enable, master, id)
master = '%s',
cred = '%s'
where id = '%s'""" % (hostname, ip, group, typeip, enable, master, cred, id)
try:
cur.execute(sql)
con.commit()
@ -445,53 +446,61 @@ def is_master(ip, **kwargs):
return cur.fetchall()
cur.close()
con.close()
def ssh_enable():
def select_ssh(**kwargs):
con, cur = create_db.get_cur()
sql = """select enable from cred """
sql = """select * from cred """
if kwargs.get("name") is not None:
sql = """select * from cred where name = '%s' """ % kwargs.get("name")
if kwargs.get("id") is not None:
sql = """select * from cred where id = '%s' """ % kwargs.get("id")
if kwargs.get("serv") is not None:
sql = """select serv.cred, cred.* from servers as serv left join cred on cred.id = serv.cred where serv.ip = '%s' """ % kwargs.get("serv")
try:
cur.execute(sql)
except sqltool.Error as e:
print('<span class="alert alert-danger" id="error">An error occurred: ' + e + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
else:
for enable in cur.fetchone():
return enable
cur.close()
con.close()
def select_ssh_username():
con, cur = create_db.get_cur()
sql = """select username from cred """
try:
cur.execute(sql)
except sqltool.Error as e:
print('<span class="alert alert-danger" id="error">An error occurred: ' + e + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
else:
for username in cur.fetchone():
return username
return cur.fetchall()
cur.close()
con.close()
def select_ssh_password():
def insert_new_ssh(name, enable, username, password):
con, cur = create_db.get_cur()
sql = """select password from cred """
sql = """insert into cred(name, enable, username, password) values ('%s', '%s', '%s', '%s') """ % (name, enable, username, password)
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
print('<span class="alert alert-danger" id="error">An error occurred: ' + e + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
else:
for password in cur.fetchone():
return password
print('<span class="alert alert-danger" id="error">An error occurred: %s <a title="Close" id="errorMess"><b>X</b></a></span>' % e)
con.rollback()
else:
return True
cur.close()
con.close()
def delete_ssh(id):
con, cur = create_db.get_cur()
sql = """ delete from cred where id = %s """ % (id)
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
print('<span class="alert alert-danger" id="error">An error occurred: ' + e.args[0] + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
con.rollback()
else:
return True
cur.close()
con.close()
def update_ssh(enable, username, password):
def update_ssh(id, name, enable, username, password):
con, cur = create_db.get_cur()
sql = """
update cred set
name = '%s',
enable = '%s',
username = '%s',
password = '%s' """ % (enable, username, password)
password = '%s' where id = '%s' """ % (name, enable, username, password, id)
try:
cur.execute(sql)
con.commit()
@ -500,6 +509,16 @@ def update_ssh(enable, username, password):
con.rollback()
cur.close()
con.close()
def show_update_ssh(name):
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'))
template = env.get_template('/new_ssh.html')
print('Content-type: text/html\n')
output_from_parsed_template = template.render(sshs = select_ssh(name=name))
print(output_from_parsed_template)
def show_update_user(user):
from jinja2 import Environment, FileSystemLoader
@ -523,7 +542,8 @@ def show_update_server(server):
output_from_parsed_template = template.render(groups = select_groups(),
servers = select_servers(server=server),
roles = select_roles(),
masters = select_servers(get_master_servers=1))
masters = select_servers(get_master_servers=1),
sshs = select_ssh())
print(output_from_parsed_template)
def show_update_group(group):
@ -608,12 +628,13 @@ if form.getvalue('newserver') is not None:
typeip = form.getvalue('typeip')
enable = form.getvalue('enable')
master = form.getvalue('slave')
if ip is None or group is None:
cred = form.getvalue('cred')
if ip is None or group is None or cred is None:
print('Content-type: text/html\n')
print(error_mess)
else:
print('Content-type: text/html\n')
if add_server(hostname, ip, group, typeip, enable, master):
if add_server(hostname, ip, group, typeip, enable, master, cred):
show_update_server(ip)
if form.getvalue('serverdel') is not None:
@ -653,17 +674,20 @@ if form.getvalue('updateserver') is not None:
enable = form.getvalue('enable')
master = form.getvalue('slave')
id = form.getvalue('id')
cred = form.getvalue('cred')
if name is None or ip is None:
print('Content-type: text/html\n')
print(error_mess)
else:
print('Content-type: text/html\n')
if funct.ssh_connect(ip, check=1):
update_server(name, ip, group, typeip, enable, master, id)
else:
print('<span class="alert alert-danger" id="error"><a title="Close" id="errorMess"><b>X</b></a></span>')
#if funct.ssh_connect(ip, check=1):
update_server(name, ip, group, typeip, enable, master, id, cred)
#else:
# print('<span class="alert alert-danger" id="error"><a title="Close" id="errorMess"><b>X</b></a></span>')
if form.getvalue('updatessh'):
id = form.getvalue('id')
name = form.getvalue('name')
enable = form.getvalue('ssh_enable')
username = form.getvalue('ssh_user')
password = form.getvalue('ssh_pass')
@ -671,5 +695,49 @@ if form.getvalue('updatessh'):
print('Content-type: text/html\n')
print(error_mess)
else:
import funct
print('Content-type: text/html\n')
update_ssh(enable, username, password)
fullpath = funct.get_config_var('main', 'fullpath')
for sshs in select_ssh(id=id):
ssh_enable = sshs[2]
ssh_key_name = fullpath+'/keys/%s.pem' % sshs[1]
new_ssh_key_name = fullpath+'/keys/%s.pem' % name
if ssh_enable == 1:
cmd = 'mv %s %s' % (ssh_key_name, new_ssh_key_name)
try:
funct.subprocess_execute(cmd)
except:
pass
update_ssh(id, name, enable, username, password)
if form.getvalue('new_ssh'):
name = form.getvalue('new_ssh')
enable = form.getvalue('ssh_enable')
username = form.getvalue('ssh_user')
password = form.getvalue('ssh_pass')
if username is None:
print('Content-type: text/html\n')
print(error_mess)
else:
if insert_new_ssh(name, enable, username, password):
show_update_ssh(name)
if form.getvalue('sshdel') is not None:
import funct
print('Content-type: text/html\n')
fullpath = funct.get_config_var('main', 'fullpath')
for sshs in select_ssh(id=form.getvalue('sshdel')):
ssh_enable = sshs[2]
ssh_key_name = fullpath+'/keys/%s.pem' % sshs[1]
if ssh_enable == 1:
cmd = 'rm -f %s' % ssh_key_name
try:
funct.subprocess_execute(cmd)
except:
pass
if delete_ssh(form.getvalue('sshdel')):
print("Ok")

View File

@ -159,7 +159,7 @@
<td>Enable</td>
<td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td>
<td><span title="Actions with master config will automatically apply on slave">Slave for (?)</span></td>
<td></td>
<td>Credentials</td>
<td></td>
</tr>
@ -199,7 +199,7 @@
</td>
<td>
<select id="slavefor-{{server.0}}">
<option value="0" selected>Not slave</option>
<option disabled selected>Not slave</option>
{% for master in masters %}
{% if master.0 == server.6 %}
<option value="{{master.0}}" selected>{{master.1}}</option>
@ -209,6 +209,18 @@
{% endfor %}
</select>
</td>
<td>
<select id="credentials-{{server.0}}">
<option disabled selected>Choose credentials</option>
{% for ssh in sshs %}
{% if ssh.0 == server.7 %}
<option value="{{ssh.0}}" selected>{{ssh.1}}</option>
{% else %}
<option value="{{ssh.0}}">{{ssh.1}}</option>
{% endif %}
{% endfor %}
</select>
</td>
<td>
<a class="delete" onclick="confirmDeleteServer({{server.0}})" style="cursor: pointer;"></a>
</td>
@ -225,6 +237,7 @@
<td>Enable</td>
<td>Virt</td>
<td title="Actions with master config will automatically apply on slave">Slave for</td>
<td>Credentials</td>
<td></td>
</tr>
<tr>
@ -249,13 +262,21 @@
<label for="typeip"></label><input type="checkbox" id="typeip">
</td>
<td>
<select id="slavefor" value="0" selected>
<option>Not slave</option>
<select id="slavefor">
<option disabled selected>Not slave</option>
{% for master in masters %}
<option value="{{master.0}}">{{master.1}}</option>
{% endfor %}
</select>
</td>
<td>
<select id="credentials">
<option disabled selected>Choose credentials</option>
{% for ssh in sshs %}
<option value="{{ssh.0}}">{{ssh.1}}</option>
{% endfor %}
</select>
</td>
<td>
<a class="add-admin" id="add-server" style="cursor: pointer;"></a>
</td>
@ -281,27 +302,63 @@
</table>
</div>
<div id="ssh">
<table id="ssh_enable_table">
<table id="ssh_enable_table" class="overview">
<tr class="overviewHead" style="width: 50%;">
<td class="padding10 first-collumn" style="width: 25%;">SSH key</td>
<td class="padding10 first-collumn" style="width: 15%;">
<span title="It's just name alias. This alias will be userd in 'Servers' page for choose credentials">Name(?)</span>
</td>
<td class="padding10 first-collumn" style="width: 25%;">
<span title="If enabled, the key will be used, if turned off - the password. Do not forget to download the keys to all servers or install the sudo without a password">SSH key(?)</span>
</td>
<td>
<span title="Enter SSH user name. If SSH key disabled, enter password for ssh user">Credentials(?)</span>
</td>
<td></td>
</tr>
<tr style="width: 50%;">
<td class="first-collumn" valign="top" style="padding-top: 15px;">
{% if ssh_enable == 1 %}
<label for="ssh_enable">Enable SSH key</label><input type="checkbox" id="ssh_enable" checked>
{% else %}
<label for="ssh_enable">Enable SSH key</label><input type="checkbox" id="ssh_enable">
{% endif %}
<div class="tooltip tooltipTop">
<b>Note:</b> If enabled, the key will be used, if turned off - the password.
<br>Do not forget to download the keys to all servers or install the sudo without a password
{% for ssh in sshs %}
<tr style="width: 50%;" id="ssh-table-{{ssh.0}}">
<td class="first-collumn">
<input type="text" id="ssh_name-{{ssh.0}}" class="form-control" value="{{ssh.1}}" style="margin-bottom: 23px;">
</td>
<td class="first-collumn" valign="top" style="padding-top: 15px;">
{% if ssh.2 == 1 %}
<label for="ssh_enable-{{ssh.0}}">Enable SSH key</label><input type="checkbox" id="ssh_enable-{{ssh.0}}" checked>
{% else %}
<label for="ssh_enable-{{ssh.0}}">Enable SSH key</label><input type="checkbox" id="ssh_enable-{{ssh.0}}">
{% endif %}
</td>
<td style="padding-top: 15px;">
<p>
<input type="text" id="ssh_user-{{ssh.0}}" class="form-control" value="{{ssh.3}}">
</p>
{% if ssh.2 == 1 %}
<input type="password" id="ssh_pass-{{ssh.0}}" class="form-control" value="{{ssh.4}}" style="display: none;">
{% else %}
<input type="password" id="ssh_pass-{{ssh.0}}" class="form-control" value="{{ssh.4}}">
{% endif %}
<br>
<br>
</div>
</td>
<td>
<a class="delete" onclick="confirmDeleteSsh({{ssh.0}})" style="cursor: pointer;"></a>
</td>
</tr>
{% endfor %}
</table>
<br /><span class="add-button" title="Add ssh" id="add-ssh-button">+ Add</span>
<br /><br />
<table class="overview" id="ssh-add-table" style="display: none;">
<tr class="overviewHead">
<td class="padding10 first-collumn" style="width: 15%;">Name</td>
<td class="padding10 first-collumn" style="width: 25%;">SSH key</td>
<td>Credentials</td>
<td></td>
</tr>
<tr>
<td class="padding10 first-collumn">
<input type="text" name="new-ssh-add" id="new-ssh-add" class="form-control">
</td>
<td>
<label for="new-ssh_enable">Enable SSH key</label><input type="checkbox" id="new-ssh_enable" checked>
</td>
<td style="padding-top: 15px;">
<p>
@ -310,7 +367,9 @@
<input type="password" id="ssh_pass" class="form-control" value="{{ssh_pass}}" style="display: none;">
<br>
</td>
<td></td>
<td>
<a class="add-admin" id="add-ssh" style="cursor: pointer;"></a>
</td>
</tr>
</table>
<table id="ssh_key">
@ -323,7 +382,12 @@
</tr>
<tr style="width: 50%;">
<td class="first-collumn" valign="top" style="padding-top: 15px;">
<b>Note:</b> Paste pem file content here
<select id="ssh-key-name">
<option disabled selected>Choose credentials</option>
{% for ssh in sshs %}
<option value={{ssh.1}}>{{ssh.1}}</option>
{% endfor %}
</select>
</td>
<td style="padding-top: 15px;">
<textarea id="ssh_cert" cols="50" rows="5"></textarea><br /><br />

View File

@ -44,6 +44,18 @@
{% endfor %}
</select>
</td>
<td>
<select id="credentials-{{server.0}}">
<option value="0" selected>Choose credentials</option>
{% for ssh in sshs %}
{% if ssh.0 == server.7 %}
<option value="{{ssh.0}}" selected>{{ssh.1}}</option>
{% else %}
<option value="{{ssh.0}}">{{ssh.1}}</option>
{% endif %}
{% endfor %}
</select>
</td>
<td>
<a class="delete" onclick="removeServer({{server.0}})" style="cursor: pointer;"></a>
</td>

View File

@ -0,0 +1,28 @@
{% for ssh in sshs %}
<tr style="width: 50%;" id="ssh-table-{{ssh.0}}">
<td class="first-collumn">
<input type="text" id="ssh_name-{{ssh.0}}" class="form-control" value="{{ssh.1}}" style="margin-bottom: 23px;">
</td>
<td class="first-collumn" valign="top" style="padding-top: 15px;">
{% if ssh.2 == 1 %}
<label for="ssh_enable-{{ssh.0}}">Enable SSH key</label><input type="checkbox" id="ssh_enable-{{ssh.0}}" checked>
{% else %}
<label for="ssh_enable-{{ssh.0}}">Enable SSH key</label><input type="checkbox" id="ssh_enable-{{ssh.0}}">
{% endif %}
</td>
<td style="padding-top: 15px;">
<p>
<input type="text" id="ssh_user-{{ssh.0}}" class="form-control" value="{{ssh.3}}">
</p>
{% if ssh.2 == 1 %}
<input type="password" id="ssh_pass-{{ssh.0}}" class="form-control" value="{{ssh.4}}" style="display: none;">
{% else %}
<input type="password" id="ssh_pass-{{ssh.0}}" class="form-control" value="{{ssh.4}}">
{% endif %}
<br>
</td>
<td>
<a class="delete" onclick="confirmDeleteSsh({{ssh.0}})" style="cursor: pointer;"></a>
</td>
</tr>
{% endfor %}

View File

@ -100,7 +100,7 @@
</ul>
</nav>
<div class="copyright-menu">
HAproxy-WI v2.5.6.2
HAproxy-WI v2.6
<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>

View File

@ -18,6 +18,7 @@ try:
user_id = cookie.get('uuid')
user = sql.get_user_name_by_uuid(user_id.value)
servers = sql.get_dick_permit()
token = sql.get_token(user_id.value)
except:
pass
@ -29,7 +30,6 @@ output_from_parsed_template = template.render(title = "Admin area: users manage"
servers = sql.select_servers(full=1),
roles = sql.select_roles(),
masters = sql.select_servers(get_master_servers=1),
ssh_enable = sql.ssh_enable(),
ssh_user = sql.select_ssh_username(),
ssh_pass = sql.select_ssh_password())
sshs = sql.select_ssh(),
token = token)
print(output_from_parsed_template)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 298 KiB

After

Width:  |  Height:  |  Size: 343 KiB

View File

@ -184,7 +184,8 @@ $( function() {
newservergroup: $('#new-server-group-add').val(),
typeip: typeip,
enable: enable,
slave: $('#slavefor option:selected' ).val()
slave: $('#slavefor' ).val(),
cred: $('#credentials').val(),
},
type: "GET",
success: function( data ) {
@ -203,6 +204,40 @@ $( function() {
} );
});
$('#add-ssh').click(function() {
$('#error').remove();
$('.alert-danger').remove();
var ssh_enable = 0;
if ($('#new-ssh_enable').is(':checked')) {
ssh_enable = '1';
}
$.ajax( {
url: "sql.py",
data: {
new_ssh: $('#new-ssh-add').val(),
ssh_user: $('#ssh_user').val(),
ssh_pass: $('#ssh_pass').val(),
ssh_enable: ssh_enable,
},
type: "GET",
success: function( data ) {
if (data.indexOf('error') != '-1') {
$("#ajax-ssh").append(data);
$.getScript(users);
} else {
var getId = new RegExp('[0-9]+');
var id = data.match(getId);
$("#ssh_enable_table").append(data);
$( ".newgroup" ).addClass( "update", 1000, callbackGroup );
$('select:regex(id, credentials)').append('<option value='+id+'>'+$('#new-ssh-add').val()+'</option>').selectmenu("refresh");
$('select:regex(id, ssh-key-name)').append('<option value='+$('#new-ssh-add').val()+'>'+$('#new-ssh-add').val()+'</option>').selectmenu("refresh");
$.getScript(awesome);
$.getScript(url);
}
}
} );
});
function callbackUser() {
setTimeout(function() {
$( ".newuser" ).removeClass( "update" );
@ -234,6 +269,11 @@ $( function() {
$('#server-add-table').show("blind", "fast");
}
});
$('#add-ssh-button').click(function() {
if ($('#ssh-add-table').css('display', 'none')) {
$('#ssh-add-table').show("blind", "fast");
}
});
$( "#ajax-users input" ).change(function() {
var id = $(this).attr('id').split('-');
@ -256,22 +296,39 @@ $( function() {
updateServer(id[1])
});
$( "#ssh_enable_table input" ).change(function() {
updateSSH()
var id = $(this).attr('id').split('-');
updateSSH(id[1])
sshKeyEnableShow(id[1])
});
$('#ssh_enable').click(function() {
if ($('#ssh_enable').is(':checked')) {
$('#new-ssh_enable').click(function() {
if ($('#new-ssh_enable').is(':checked')) {
$('#ssh_pass').css('display', 'none');
} else {
$('#ssh_pass').css('display', 'block');
}
});
if ($('#ssh_enable').is(':checked')) {
if ($('#new-ssh_enable').is(':checked')) {
$('#ssh_pass').css('display', 'none');
} else {
$('#ssh_pass').css('display', 'block');
}
} );
function sshKeyEnableShow(id) {
$('#ssh_enable-'+id).click(function() {
if ($('#ssh_enable-'+id).is(':checked')) {
$('#ssh_pass-'+id).css('display', 'none');
} else {
$('#ssh_pass-'+id).css('display', 'block');
}
});
if ($('#ssh_enable-'+id).is(':checked')) {
$('#ssh_pass-'+id).css('display', 'none');
} else {
$('#ssh_pass-'+id).css('display', 'block');
}
}
function confirmDeleteUser(id) {
$( "#dialog-confirm" ).dialog({
resizable: false,
@ -326,6 +383,24 @@ function confirmDeleteServer(id) {
}
});
}
function confirmDeleteSsh(id) {
$( "#dialog-confirm" ).dialog({
resizable: false,
height: "auto",
width: 400,
modal: true,
title: "Are you sure you want to delete " +$('#ssh_name-'+id).val() + "?",
buttons: {
"Delete": function() {
$( this ).dialog( "close" );
removeSsh(id);
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
}
function removeUser(id) {
$("#user-"+id).css("background-color", "#f2dede");
$.ajax( {
@ -376,6 +451,24 @@ function removeGroup(id) {
}
} );
}
function removeSsh(id) {
$("#ssh-table-"+id).css("background-color", "#f2dede");
$.ajax( {
url: "sql.py",
data: {
sshdel: id,
},
type: "GET",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if(data == "Ok ") {
$("#ssh-table-"+id).remove();
$('select:regex(id, credentials) option[value='+id+']').remove();
$('select:regex(id, credentials)').selectmenu("refresh");
}
}
} );
}
function updateUser(id) {
$('.alert-danger').remove();
$.ajax( {
@ -450,6 +543,7 @@ function updateServer(id) {
typeip: typeip,
enable: enable,
slave: $('#slavefor-'+id+' option:selected' ).val(),
cred: $('#credentials-'+id+' option:selected').val(),
id: id
},
type: "GET",
@ -474,6 +568,7 @@ function uploadSsh() {
url: "options.py",
data: {
ssh_cert: $('#ssh_cert').val(),
name: $('#ssh-key-name').val(),
token: $('#token').val()
},
type: "GET",
@ -494,19 +589,21 @@ function uploadSsh() {
}
} );
}
function updateSSH() {
function updateSSH(id) {
$('#error').remove();
var ssh_enable = 0;
if ($('#ssh_enable').is(':checked')) {
if ($('#ssh_enable-'+id).is(':checked')) {
ssh_enable = '1';
}
$.ajax( {
url: "sql.py",
data: {
updatessh: 1,
name: $('#ssh_name-'+id).val(),
ssh_enable: ssh_enable,
ssh_user: $('#ssh_user').val(),
ssh_pass: $('#ssh_pass').val(),
ssh_user: $('#ssh_user-'+id).val(),
ssh_pass: $('#ssh_pass-'+id).val(),
id: id
},
type: "GET",
success: function( data ) {
@ -516,10 +613,14 @@ function updateSSH() {
$.getScript(users);
} else {
$('.alert-danger').remove();
$("#ssh_enable_table").addClass( "update", 1000 );
$("#ssh-table-"+id).addClass( "update", 1000 );
setTimeout(function() {
$( "#ssh_enable_table" ).removeClass( "update" );
$( "#ssh-table-"+id ).removeClass( "update" );
}, 2500 );
$('select:regex(id, credentials) option[value='+id+']').remove();
$('select:regex(id, ssh-key-name) option[value='+$('#ssh_name-'+id).val()+']').remove();
$('select:regex(id, credentials)').append('<option value='+id+'>'+$('#ssh_name-'+id).val()+'</option>').selectmenu("refresh");
$('select:regex(id, ssh-key-name)').append('<option value='+$('#ssh_name-'+id).val()+'>'+$('#ssh_name-'+id).val()+'</option>').selectmenu("refresh");
}
}
} );

View File

@ -319,6 +319,7 @@ echo ""
echo "################################"
mkdir /var/www/$HOME_HAPROXY_WI/app/certs
mkdir /var/www/$HOME_HAPROXY_WI/keys
chmod +x /var/www/$HOME_HAPROXY_WI/app/*.py
rm -f /var/www/$HOME_HAPROXY_WI/log/config_edit.log
cd /var/www/$HOME_HAPROXY_WI/app

View File

@ -5,6 +5,7 @@ cp app/haproxy-webintarface.config /tmp/
git reset --hard
git pull https://github.com/Aidaho12/haproxy-wi.git
mkdir keys
mkdir app/certs
chmod +x app/*py
chown -R apache:apache *