Pavel Loginov 2020-09-17 11:26:54 +06:00
parent 072daa52d1
commit cebf706ced
14 changed files with 82 additions and 34 deletions

View File

@ -17,7 +17,7 @@ if form.getvalue('add'):
print('Content-type: text/html\n') print('Content-type: text/html\n')
funct.check_login() funct.check_login()
funct.page_for_admin(level = 2) funct.page_for_admin(level=3)
try: try:
user, user_id, role, token, servers = funct.get_users_params() user, user_id, role, token, servers = funct.get_users_params()

View File

@ -46,7 +46,7 @@ if serv is not None:
cfg = configs_dir + serv + "-" + funct.get_data('config') + "."+format cfg = configs_dir + serv + "-" + funct.get_data('config') + "."+format
if serv is not None and form.getvalue('open') is not None : if serv is not None and form.getvalue('open') is not None :
funct.check_is_server_in_group(serv)
if service == 'keepalived': if service == 'keepalived':
error = funct.get_config(serv, cfg, keepalived=1) error = funct.get_config(serv, cfg, keepalived=1)
try: try:
@ -76,6 +76,7 @@ if serv is not None and form.getvalue('open') is not None :
os.system("/bin/mv %s %s.old" % (cfg, cfg)) os.system("/bin/mv %s %s.old" % (cfg, cfg))
if serv is not None and form.getvalue('config') is not None: if serv is not None and form.getvalue('config') is not None:
funct.check_is_server_in_group(serv)
try: try:
funct.logging(serv, "config.py edited config") funct.logging(serv, "config.py edited config")
except: except:

View File

@ -653,7 +653,7 @@ def update_db_v_4_3_2_1(**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] == 'columns param, group are not unique' or e == " 1060 (42S21): columns param, group are not unique ": if e.args[0] == 'columns param, group are not unique' or e == " 1060 (42S21): columns param, group are not unique ":
print('Updating... groups') pass
else: else:
print("An error occurred:", e) print("An error occurred:", e)
else: else:
@ -679,14 +679,47 @@ def update_db_v_4_5(**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: version' or e == "1060 (42S21): Duplicate column name 'version' ": if e.args[0] == 'duplicate column name: version' or e == "1060 (42S21): Duplicate column name 'version' ":
print('Updating... go to version 4.5.1') print('Updating... go to version 4.5.0')
else: else:
print("Updating... go to version to 4.5.1") print("Updating... go to version to 4.5.0")
return False return False
else: else:
return True return True
cur.close() cur.close()
con.close() con.close()
def update_db_v_4_5_1(**kwargs):
con, cur = get_cur()
sql = """ select name from role where name = 'superAdmin';"""
try:
cur.execute(sql)
except sqltool.Error as e:
funct.out_error(e)
else:
role = cur.fetchall()
if not role:
sql = list()
sql.append("update role set name = 'superAdmin' where id = '1';")
sql.append("update role set name = 'admin' `description` = 'Has access everywhere except the Admin area' where id = '2';")
sql.append("update role set id = '4' where id = '3';")
sql.append("INSERT INTO role (id, name, `description`) values('3', 'editor', 'Has the same as the admin except the Servers page');")
sql.append("update user set role = 's uperAdmin' where role = 'admin';")
sql.append("update user set role = 'admin' where role = 'editor';")
for i in sql:
try:
cur.execute(i)
con.commit()
except sqltool.Error as e:
pass
else:
if kwargs.get('silent') != 1:
print('DB was update to 4.5.0')
return True
cur.close()
con.close()
def update_ver(**kwargs): def update_ver(**kwargs):
@ -725,6 +758,7 @@ def update_all():
update_db_v_4_4_2_1() update_db_v_4_4_2_1()
update_db_v_4_3_2_1() update_db_v_4_3_2_1()
update_db_v_4_5() update_db_v_4_5()
update_db_v_4_5_1()
update_ver() update_ver()
@ -752,6 +786,7 @@ def update_all_silent():
update_db_v_4_4_2_1(silent=1) update_db_v_4_4_2_1(silent=1)
update_db_v_4_3_2_1(silent=1) update_db_v_4_3_2_1(silent=1)
update_db_v_4_5(silent=1) update_db_v_4_5(silent=1)
update_db_v_4_5_1(silent=1)
update_ver() update_ver()

View File

@ -174,7 +174,7 @@ def is_admin(**kwargs):
try: try:
role = sql.get_user_role_by_uuid(user_id.value) role = sql.get_user_role_by_uuid(user_id.value)
except: except:
role = 3 role = 4
pass pass
level = kwargs.get("level") level = kwargs.get("level")
@ -710,7 +710,7 @@ def upload_and_restart(serv, cfg, **kwargs):
else: else:
haproxy_enterprise = sql.get_setting('haproxy_enterprise') haproxy_enterprise = sql.get_setting('haproxy_enterprise')
if haproxy_enterprise: if haproxy_enterprise == '1':
haproxy_service_name = "hapee-2.0-lb" haproxy_service_name = "hapee-2.0-lb"
else: else:
haproxy_service_name = "haproxy" haproxy_service_name = "haproxy"

View File

@ -397,7 +397,7 @@ if form.getvalue('action_hap') is not None and serv is not None:
if funct.check_haproxy_config(serv): if funct.check_haproxy_config(serv):
haproxy_enterprise = sql.get_setting('haproxy_enterprise') haproxy_enterprise = sql.get_setting('haproxy_enterprise')
if haproxy_enterprise: if haproxy_enterprise == '1':
haproxy_service_name = "hapee-2.0-lb" haproxy_service_name = "hapee-2.0-lb"
else: else:
haproxy_service_name = "haproxy" haproxy_service_name = "haproxy"
@ -931,7 +931,7 @@ if serv is not None and act == "configShow":
template = template.render(conf=conf, template = template.render(conf=conf,
serv=serv, serv=serv,
configver=form.getvalue('configver'), configver=form.getvalue('configver'),
role=funct.is_admin(level=2), role=funct.is_admin(level=3),
service=form.getvalue('service')) service=form.getvalue('service'))
print(template) print(template)
@ -1544,7 +1544,7 @@ if form.getvalue('bwlists_save'):
pass pass
haproxy_enterprise = sql.get_setting('haproxy_enterprise') haproxy_enterprise = sql.get_setting('haproxy_enterprise')
if haproxy_enterprise: if haproxy_enterprise == '1':
haproxy_service_name = "hapee-2.0-lb" haproxy_service_name = "hapee-2.0-lb"
else: else:
haproxy_service_name = "haproxy" haproxy_service_name = "haproxy"

View File

@ -23,7 +23,7 @@ except Exception as e:
if action == 'add': if action == 'add':
smon = sql.select_smon(user_group,action='add') smon = sql.select_smon(user_group,action='add')
funct.page_for_admin(level=2) funct.page_for_admin(level=3)
title = "SMON Admin" title = "SMON Admin"
autorefresh = 0 autorefresh = 0
else: else:

View File

@ -62,7 +62,7 @@
<li><a href="/app/viewsttats.py" title="HAProxy statistics " class="stats head-submenu">Stats</a></li> <li><a href="/app/viewsttats.py" title="HAProxy statistics " class="stats head-submenu">Stats</a></li>
<li><a href="/app/runtimeapi.py" title="Runtime API - HAProxy-WI" class="runtime head-submenu">Runtime API</a></li> <li><a href="/app/runtimeapi.py" title="Runtime API - HAProxy-WI" class="runtime head-submenu">Runtime API</a></li>
<li><a href="/app/metrics.py" title="Metrics" class="metrics head-submenu">Metrics</a></li> <li><a href="/app/metrics.py" title="Metrics" class="metrics head-submenu">Metrics</a></li>
{% if role <= 2 %} {% if role <= 3 %}
<li><a href="/app/add.py#proxy" title="Add proxy: Create proxy - HAProxy-WI" class="add head-submenu" id="add1">Add proxy</a></li> <li><a href="/app/add.py#proxy" title="Add proxy: Create proxy - HAProxy-WI" class="add head-submenu" id="add1">Add proxy</a></li>
<li><a href="/app/versions.py" title="Working with versions HAProxy configs" class="version head-submenu">Versions</a></li> <li><a href="/app/versions.py" title="Working with versions HAProxy configs" class="version head-submenu">Versions</a></li>
<li><a href="/app/add.py#ssl" title="Add proxy: Upload SSL certificates - HAProxy-WI" class="cert head-submenu" id="add3">SSL</a></li> <li><a href="/app/add.py#ssl" title="Add proxy: Upload SSL certificates - HAProxy-WI" class="cert head-submenu" id="add3">SSL</a></li>
@ -78,7 +78,7 @@
<li><a href="/app/hapservers.py?service=nginx" title="Overview Nginx servers" class="overview-link head-submenu">Overview</a> </li> <li><a href="/app/hapservers.py?service=nginx" title="Overview Nginx servers" class="overview-link head-submenu">Overview</a> </li>
<li><a href="/app/config.py?service=nginx" title="Working with Nginx configs" class="edit head-submenu">Configs</a></li> <li><a href="/app/config.py?service=nginx" title="Working with Nginx configs" class="edit head-submenu">Configs</a></li>
<li><a href="/app/viewsttats.py?service=nginx" title="Nginx statistics" class="stats head-submenu">Stats</a></li> <li><a href="/app/viewsttats.py?service=nginx" title="Nginx statistics" class="stats head-submenu">Stats</a></li>
{% if role <= 2 %} {% if role <= 3 %}
<li><a href="/app/versions.py?service=nginx" title="Working with versions Nginx configs" class="version head-submenu">Versions</a></li> <li><a href="/app/versions.py?service=nginx" title="Working with versions Nginx configs" class="version head-submenu">Versions</a></li>
<li><a href="/app/add.py?service=nginx#ssl" title="Add proxy: Upload SSL certificates - HAProxy-WI" class="cert head-submenu" id="add3">SSL</a></li> <li><a href="/app/add.py?service=nginx#ssl" title="Add proxy: Upload SSL certificates - HAProxy-WI" class="cert head-submenu" id="add3">SSL</a></li>
{% endif %} {% endif %}
@ -98,7 +98,7 @@
<a title="Simple monitoring network ports" class="stats">SMON</a> <a title="Simple monitoring network ports" class="stats">SMON</a>
<ul class="v_menu"> <ul class="v_menu">
<li><a href="/app/smon.py?action=view" title="SMON Dashboard" class="overview-link head-submenu">Dashboard</a></li> <li><a href="/app/smon.py?action=view" title="SMON Dashboard" class="overview-link head-submenu">Dashboard</a></li>
{% if role <= 2 %} {% if role <= 3 %}
<li><a href="/app/smon.py?action=add" title="SMON admin panel" class="edit head-submenu">Admin panel</a></li> <li><a href="/app/smon.py?action=add" title="SMON admin panel" class="edit head-submenu">Admin panel</a></li>
{% endif %} {% endif %}
</ul> </ul>

View File

@ -32,11 +32,11 @@
{% endif %} {% endif %}
{% if service != 'keepalived' %} {% if service != 'keepalived' %}
<a class="ui-button ui-widget ui-corner-all" title="Compare configs" onclick="showCompareConfigs()">Compare</a> <a class="ui-button ui-widget ui-corner-all" title="Compare configs" onclick="showCompareConfigs()">Compare</a>
{% if role <= 2 %} {% if role <= 3 %}
<a class="ui-button ui-widget ui-corner-all" title="Show versions" onclick="openVersions()">Versions</a> <a class="ui-button ui-widget ui-corner-all" title="Show versions" onclick="openVersions()">Versions</a>
{% endif %} {% endif %}
{% else %} {% else %}
{% if role <= 2 %} {% if role <= 3 %}
<button type="submit" value="open" name="open" class="btn btn-default" title="Edit running config">Edit</button> <button type="submit" value="open" name="open" class="btn btn-default" title="Edit running config">Edit</button>
<a class="ui-button ui-widget ui-corner-all" title="Show versions" onclick="openVersions()">Versions</a> <a class="ui-button ui-widget ui-corner-all" title="Show versions" onclick="openVersions()">Versions</a>
{% endif %} {% endif %}
@ -50,7 +50,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if config %} {% if config %}
{% if role <= 2 %} {% if role <= 3 %}
<h4>Config from {{ serv }}</h4> <h4>Config from {{ serv }}</h4>
</center> </center>
<form action="{{ action }}" name="saveconfig" id="saveconfig" method="post"> <form action="{{ action }}" name="saveconfig" id="saveconfig" method="post">

View File

@ -52,12 +52,22 @@
<td> <td>
<select id="role-{{user.0}}" name="role-{{user.0}}"> <select id="role-{{user.0}}" name="role-{{user.0}}">
<option disabled selected>Choose role</option> <option disabled selected>Choose role</option>
{% for role in roles %} {% for r in roles %}
{% if user.4 == role.1 %} {% if page == "servers.py" %}
<option value="{{ role.1 }}" selected>{{ role.1 }}</option> {% if r.1 != "superAdmin" %}
{% else %} {% if user.4 == r.1 %}
<option value="{{ role.1 }}">{{ role.1 }}</option> <option value="{{ r.1 }}" selected>{{ r.1 }}</option>
{% endif %} {% else %}
<option value="{{ r.1 }}">{{ r.1 }}</option>
{% endif %}
{% endif %}
{% else %}
{% if user.4 == r.1 %}
<option value="{{ r.1 }}" selected>{{ r.1 }}</option>
{% else %}
<option value="{{ r.1 }}">{{ r.1 }}</option>
{% endif %}
{% endif %}
{% endfor %} {% endfor %}
</select> </select>
</td> </td>

View File

@ -63,7 +63,7 @@
<select id="new-role" name="new-role"> <select id="new-role" name="new-role">
<option disabled selected>Choose role</option> <option disabled selected>Choose role</option>
{% for role in roles %} {% for role in roles %}
{% if role.1 != "admin" %} {% if role.1 != "superAdmin" %}
<option value="{{ role.1 }}">{{ role.1 }}</option> <option value="{{ role.1 }}">{{ role.1 }}</option>
{% endif %} {% endif %}
{% endfor %} {% endfor %}

View File

@ -7,7 +7,7 @@
<div id="tabs"> <div id="tabs">
<ul> <ul>
<li><a href="#runtimeapi" title="Runtime API - HAProxy-WI">Runtime API</a></li> <li><a href="#runtimeapi" title="Runtime API - HAProxy-WI">Runtime API</a></li>
{% if role <= 2 %} {% if role <= 3 %}
<li><a href="#maxconn" title="Runtime API: Changing Maxconn - HAProxy-WI">Change Maxconn</a></li> <li><a href="#maxconn" title="Runtime API: Changing Maxconn - HAProxy-WI">Change Maxconn</a></li>
<li><a href="#ip" title="Runtime API: Changing IP and Port for backend servers - HAProxy-WI">Change IP and Port</a></li> <li><a href="#ip" title="Runtime API: Changing IP and Port for backend servers - HAProxy-WI">Change IP and Port</a></li>
<li><a href="#table" title="Runtime API: Stick Table - HAProxy-WI">Stick Table</a></li> <li><a href="#table" title="Runtime API: Stick Table - HAProxy-WI">Stick Table</a></li>
@ -23,7 +23,9 @@
<td class="padding10 first-collumn">Server</td> <td class="padding10 first-collumn">Server</td>
<td>Disable/Enable server or output any information</td> <td>Disable/Enable server or output any information</td>
<td>Command</td> <td>Command</td>
{% if role <= 3 %}
<td class="checkbox-head">Save change</td> <td class="checkbox-head">Save change</td>
{% endif %}
<td></td> <td></td>
</tr> </tr>
<tr> <tr>
@ -34,7 +36,7 @@
<td style="width: 30%;"> <td style="width: 30%;">
<select required name="servaction" id="servaction"> <select required name="servaction" id="servaction">
<option disabled>Choose action</option> <option disabled>Choose action</option>
{% if role <= 2 %} {% if role <= 3 %}
<option value="disable">Disable</option> <option value="disable">Disable</option>
<option value="shutdown">Shutdown</option> <option value="shutdown">Shutdown</option>
<option value="enable">Enable</option> <option value="enable">Enable</option>
@ -46,11 +48,11 @@
<td> <td>
{{ input('servbackend', value=servbackend, title='Frontend, backend/server, show: info, pools or help', required='required') }} {{ input('servbackend', value=servbackend, title='Frontend, backend/server, show: info, pools or help', required='required') }}
</td> </td>
{% if role <= 3 %}
<td class="checkbox"> <td class="checkbox">
{% if role <= 2 %} {{ checkbox('save', value='123') }}
{{ checkbox('save', value='123') }}
{% endif %}
</td> </td>
{% endif %}
<td> <td>
<button type="submit" name="Enter" value="Enter" id="enter">Enter</button> <button type="submit" name="Enter" value="Enter" id="enter">Enter</button>
</td> </td>
@ -72,7 +74,7 @@
You can read the description of all Run Time API <a href="https://haproxy-wi.org/description.py?description=runtimeapi#commands" title="Run Time API description" target="_blank">here</a> You can read the description of all Run Time API <a href="https://haproxy-wi.org/description.py?description=runtimeapi#commands" title="Run Time API description" target="_blank">here</a>
</div> </div>
</div> </div>
{% if role <= 2 %} {% if role <= 3 %}
<div id="maxconn"> <div id="maxconn">
<table class="overview"> <table class="overview">
<tr class="overviewHead"> <tr class="overviewHead">

View File

@ -24,13 +24,13 @@
{% endfor %} {% endfor %}
</select> </select>
<input type="hidden" value="{{ serv }}" name="serv"> <input type="hidden" value="{{ serv }}" name="serv">
{% if role <= 2 %} {% if role <= 3 %}
<button type="submit" value="open" name="open" class="btn btn-default" title="Edit running config">Edit</button> <button type="submit" value="open" name="open" class="btn btn-default" title="Edit running config">Edit</button>
{% endif %} {% endif %}
</form> </form>
</p> </p>
{% if config %} {% if config %}
{% if role <= 2 %} {% if role <= 3 %}
<div id="config"> <div id="config">
<h4>You are editting "{{section}}" from server {{ serv }}</h4> <h4>You are editting "{{section}}" from server {{ serv }}</h4>
</center> </center>

View File

@ -19,7 +19,7 @@ try:
grafana, stderr = funct.subprocess_execute("service grafana-server status |grep Active |awk '{print $1}'") grafana, stderr = funct.subprocess_execute("service grafana-server status |grep Active |awk '{print $1}'")
services = [] services = []
services_name = {"checker_haproxy":"Master backends checker service", services_name = {"checker_haproxy":"Master backends checker service",
"keep_alive":"Auto start service", "keep_alive":"Auto start service",
"metrics_haproxy":"Master metrics service", "metrics_haproxy":"Master metrics service",
"prometheus":"Prometheus service", "prometheus":"Prometheus service",
"grafana-server":"Grafana service", "grafana-server":"Grafana service",

View File

@ -7,7 +7,7 @@ template = env.get_template('delver.html')
print('Content-type: text/html\n') print('Content-type: text/html\n')
funct.check_login() funct.check_login()
funct.page_for_admin(level = 2) funct.page_for_admin(level=3)
form = funct.form form = funct.form
serv = form.getvalue('serv') serv = form.getvalue('serv')