From cebf706ceda8cb722b84b4d45525a53d6ef48795 Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Thu, 17 Sep 2020 11:26:54 +0600 Subject: [PATCH] v4.5.0.0 Changelog: https://haproxy-wi.org/changelog.py#4_5 --- app/add.py | 2 +- app/config.py | 3 +- app/create_db.py | 41 +++++++++++++++++++++-- app/funct.py | 4 +-- app/options.py | 6 ++-- app/smon.py | 2 +- app/templates/base.html | 6 ++-- app/templates/config.html | 6 ++-- app/templates/include/admin_users.html | 22 ++++++++---- app/templates/include/admins_dialogs.html | 2 +- app/templates/runtimeapi.html | 14 ++++---- app/templates/sections.html | 4 +-- app/users.py | 2 +- app/versions.py | 2 +- 14 files changed, 82 insertions(+), 34 deletions(-) diff --git a/app/add.py b/app/add.py index 971d469c..aef49ea9 100644 --- a/app/add.py +++ b/app/add.py @@ -17,7 +17,7 @@ if form.getvalue('add'): print('Content-type: text/html\n') funct.check_login() -funct.page_for_admin(level = 2) +funct.page_for_admin(level=3) try: user, user_id, role, token, servers = funct.get_users_params() diff --git a/app/config.py b/app/config.py index 6edabbaf..9324f107 100644 --- a/app/config.py +++ b/app/config.py @@ -46,7 +46,7 @@ if serv is not None: cfg = configs_dir + serv + "-" + funct.get_data('config') + "."+format if serv is not None and form.getvalue('open') is not None : - + funct.check_is_server_in_group(serv) if service == 'keepalived': error = funct.get_config(serv, cfg, keepalived=1) 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)) if serv is not None and form.getvalue('config') is not None: + funct.check_is_server_in_group(serv) try: funct.logging(serv, "config.py edited config") except: diff --git a/app/create_db.py b/app/create_db.py index 8410210d..2f1bc0e4 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -653,7 +653,7 @@ def update_db_v_4_3_2_1(**kwargs): except sqltool.Error as e: 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 ": - print('Updating... groups') + pass else: print("An error occurred:", e) else: @@ -679,14 +679,47 @@ def update_db_v_4_5(**kwargs): except sqltool.Error as e: if kwargs.get('silent') != 1: 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: - print("Updating... go to version to 4.5.1") + print("Updating... go to version to 4.5.0") return False else: return True cur.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): @@ -725,6 +758,7 @@ def update_all(): update_db_v_4_4_2_1() update_db_v_4_3_2_1() update_db_v_4_5() + update_db_v_4_5_1() update_ver() @@ -752,6 +786,7 @@ def update_all_silent(): update_db_v_4_4_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_1(silent=1) update_ver() diff --git a/app/funct.py b/app/funct.py index 01ce730b..8a9859db 100644 --- a/app/funct.py +++ b/app/funct.py @@ -174,7 +174,7 @@ def is_admin(**kwargs): try: role = sql.get_user_role_by_uuid(user_id.value) except: - role = 3 + role = 4 pass level = kwargs.get("level") @@ -710,7 +710,7 @@ def upload_and_restart(serv, cfg, **kwargs): else: haproxy_enterprise = sql.get_setting('haproxy_enterprise') - if haproxy_enterprise: + if haproxy_enterprise == '1': haproxy_service_name = "hapee-2.0-lb" else: haproxy_service_name = "haproxy" diff --git a/app/options.py b/app/options.py index 90d03b68..e0c1c4c0 100644 --- a/app/options.py +++ b/app/options.py @@ -397,7 +397,7 @@ if form.getvalue('action_hap') is not None and serv is not None: if funct.check_haproxy_config(serv): haproxy_enterprise = sql.get_setting('haproxy_enterprise') - if haproxy_enterprise: + if haproxy_enterprise == '1': haproxy_service_name = "hapee-2.0-lb" else: haproxy_service_name = "haproxy" @@ -931,7 +931,7 @@ if serv is not None and act == "configShow": template = template.render(conf=conf, serv=serv, configver=form.getvalue('configver'), - role=funct.is_admin(level=2), + role=funct.is_admin(level=3), service=form.getvalue('service')) print(template) @@ -1544,7 +1544,7 @@ if form.getvalue('bwlists_save'): pass haproxy_enterprise = sql.get_setting('haproxy_enterprise') - if haproxy_enterprise: + if haproxy_enterprise == '1': haproxy_service_name = "hapee-2.0-lb" else: haproxy_service_name = "haproxy" diff --git a/app/smon.py b/app/smon.py index 2324cb98..872644b8 100644 --- a/app/smon.py +++ b/app/smon.py @@ -23,7 +23,7 @@ except Exception as e: if 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" autorefresh = 0 else: diff --git a/app/templates/base.html b/app/templates/base.html index cad40846..9bf8b292 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -62,7 +62,7 @@
  • Stats
  • Runtime API
  • Metrics
  • - {% if role <= 2 %} + {% if role <= 3 %}
  • Add proxy
  • Versions
  • SSL
  • @@ -78,7 +78,7 @@
  • Overview
  • Configs
  • Stats
  • - {% if role <= 2 %} + {% if role <= 3 %}
  • Versions
  • SSL
  • {% endif %} @@ -98,7 +98,7 @@ SMON diff --git a/app/templates/config.html b/app/templates/config.html index d8dbd500..133e076e 100644 --- a/app/templates/config.html +++ b/app/templates/config.html @@ -32,11 +32,11 @@ {% endif %} {% if service != 'keepalived' %} Compare - {% if role <= 2 %} + {% if role <= 3 %} Versions {% endif %} {% else %} - {% if role <= 2 %} + {% if role <= 3 %} Versions {% endif %} @@ -50,7 +50,7 @@ {% endif %} {% endif %} {% if config %} - {% if role <= 2 %} + {% if role <= 3 %}

    Config from {{ serv }}

    diff --git a/app/templates/include/admin_users.html b/app/templates/include/admin_users.html index ec195227..6e307d5f 100644 --- a/app/templates/include/admin_users.html +++ b/app/templates/include/admin_users.html @@ -52,12 +52,22 @@ diff --git a/app/templates/include/admins_dialogs.html b/app/templates/include/admins_dialogs.html index 6ec9eec4..5092b994 100644 --- a/app/templates/include/admins_dialogs.html +++ b/app/templates/include/admins_dialogs.html @@ -63,7 +63,7 @@ - {% if role <= 2 %} + {% if role <= 3 %} @@ -46,11 +48,11 @@ {{ input('servbackend', value=servbackend, title='Frontend, backend/server, show: info, pools or help', required='required') }} + {% if role <= 3 %} - {% if role <= 2 %} - {{ checkbox('save', value='123') }} - {% endif %} + {{ checkbox('save', value='123') }} + {% endif %} @@ -72,7 +74,7 @@ You can read the description of all Run Time API here - {% if role <= 2 %} + {% if role <= 3 %}
    diff --git a/app/templates/sections.html b/app/templates/sections.html index f3099f65..a2319300 100644 --- a/app/templates/sections.html +++ b/app/templates/sections.html @@ -24,13 +24,13 @@ {% endfor %} - {% if role <= 2 %} + {% if role <= 3 %} {% endif %}

    {% if config %} - {% if role <= 2 %} + {% if role <= 3 %}

    You are editting "{{section}}" from server {{ serv }}

    diff --git a/app/users.py b/app/users.py index 5aa115cd..d4daf495 100644 --- a/app/users.py +++ b/app/users.py @@ -19,7 +19,7 @@ try: grafana, stderr = funct.subprocess_execute("service grafana-server status |grep Active |awk '{print $1}'") services = [] services_name = {"checker_haproxy":"Master backends checker service", - "keep_alive":"Auto start service", + "keep_alive":"Auto start service", "metrics_haproxy":"Master metrics service", "prometheus":"Prometheus service", "grafana-server":"Grafana service", diff --git a/app/versions.py b/app/versions.py index 473ce31b..55782609 100644 --- a/app/versions.py +++ b/app/versions.py @@ -7,7 +7,7 @@ template = env.get_template('delver.html') print('Content-type: text/html\n') funct.check_login() -funct.page_for_admin(level = 2) +funct.page_for_admin(level=3) form = funct.form serv = form.getvalue('serv')