From 4879b215b7901992de52955c8f0a0b3b13333854 Mon Sep 17 00:00:00 2001 From: Aidaho Date: Sat, 4 Mar 2023 10:42:26 +0300 Subject: [PATCH] v6.3.7.0 Changelog: https://roxy-wi.org/changelog#6_3_7 --- app/create_db.py | 12 +++ app/modules/config/config.py | 6 +- app/modules/roxywi/user.py | 27 +---- app/options.py | 15 --- app/templates/ajax/compare.html | 5 +- app/templates/ajax/move_user_service.html | 19 ---- .../ajax/remove_user_group_and_role.html | 8 -- app/templates/ajax/show_compare_configs.html | 11 +- app/templates/base.html | 4 +- app/templates/languages/en.html | 6 ++ app/templates/languages/fr.html | 6 ++ app/templates/languages/ru.html | 6 ++ inc/users.js | 100 ++++++++++-------- 13 files changed, 105 insertions(+), 120 deletions(-) delete mode 100644 app/templates/ajax/move_user_service.html delete mode 100644 app/templates/ajax/remove_user_group_and_role.html diff --git a/app/create_db.py b/app/create_db.py index b8b7bf30..c11ba014 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -167,6 +167,18 @@ def default_values(): except Exception as e: print(str(e)) + data_source = [ + {'user_id': '1', 'user_group_id': '2', 'user_role_id': '1'}, + {'user_id': '2', 'user_group_id': '2', 'user_role_id': '2'}, + {'user_id': '3', 'user_group_id': '2', 'user_role_id': '4'} + ] + + try: + if create_users: + UserGroups.insert_many(data_source).on_conflict_ignore().execute() + except Exception as e: + print(str(e)) + data_source = [ {'name': 'superAdmin', 'description': 'Has the highest level of administrative permissions and controls the actions of all other users'}, {'name': 'admin', 'description': 'Has access everywhere except the Admin area'}, diff --git a/app/modules/config/config.py b/app/modules/config/config.py index 916c4e2f..0744d7e3 100644 --- a/app/modules/config/config.py +++ b/app/modules/config/config.py @@ -461,6 +461,7 @@ def show_compare_config(server_ip: str) -> None: left = form.getvalue('left') right = form.getvalue('right') service = form.getvalue('service') + lang = roxywi_common.get_user_lang() if service == 'nginx': return_files = roxywi_common.get_files(get_config_var.get_config_var('configs', 'nginx_save_configs_dir'), 'conf') @@ -471,7 +472,7 @@ def show_compare_config(server_ip: str) -> None: else: return_files = roxywi_common.get_files() - template = template.render(serv=server_ip, right=right, left=left, return_files=return_files) + template = template.render(serv=server_ip, right=right, left=left, return_files=return_files, lang=lang) print(template) @@ -480,6 +481,7 @@ def compare_config() -> None: left = common.checkAjaxInput(form.getvalue('left')) right = common.checkAjaxInput(form.getvalue('right')) + lang = roxywi_common.get_user_lang() if form.getvalue('service') == 'nginx': configs_dir = get_config_var.get_config_var('configs', 'nginx_save_configs_dir') @@ -496,7 +498,7 @@ def compare_config() -> None: template = env.get_template('ajax/compare.html') output, stderr = server_mod.subprocess_execute(cmd) - template = template.render(stdout=output) + template = template.render(stdout=output, lang=lang) print(template) print(stderr) diff --git a/app/modules/roxywi/user.py b/app/modules/roxywi/user.py index ecc486f9..2b10dfd3 100644 --- a/app/modules/roxywi/user.py +++ b/app/modules/roxywi/user.py @@ -20,9 +20,9 @@ def create_user(new_user: str, email: str, password: str, role: str, activeuser: sql.update_user_role(user_id, group, role) roxywi_common.logging(f'a new user {new_user}', ' has been created ', roxywi=1, login=1) try: - sql.update_user_role(user_id, group_id, role_id) + sql.update_user_role(user_id, group, role) except Exception as e: - print(str(e)) + print(f'error: cannot update user role {e}') try: if password == 'aduser': password = 'your domain password' @@ -121,18 +121,6 @@ def change_user_services() -> None: print(e) -def move_user_service(action) -> None: - service_id = common.checkAjaxInput(form.getvalue('service_id')) - service_name = common.checkAjaxInput(form.getvalue('service_name')) - length_tr = common.checkAjaxInput(form.getvalue('length_tr')) - lang = roxywi_common.get_user_lang() - env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) - template = env.get_template('ajax/move_user_service.html') - template = template.render(lang=lang, service_id=service_id, service_name=service_name, length_tr=length_tr, action=action) - print(template) - - - def change_user_active_group() -> None: group_id = common.checkAjaxInput(form.getvalue('changeUserCurrentGroupId')) user_uuid = common.checkAjaxInput(form.getvalue('changeUserGroupsUser')) @@ -180,17 +168,6 @@ def add_user_group_and_role() -> None: print(template) -def remove_user_group_and_role() -> None: - group_id = common.checkAjaxInput(form.getvalue('group_id')) - group_name = common.checkAjaxInput(form.getvalue('group_name')) - length_tr = common.checkAjaxInput(form.getvalue('length_tr')) - lang = roxywi_common.get_user_lang() - env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) - template = env.get_template('ajax/remove_user_group_and_role.html') - template = template.render(lang=lang, group_id=group_id, group_name=group_name, length_tr=length_tr) - print(template) - - def save_user_group_and_role() -> None: import json diff --git a/app/options.py b/app/options.py index df3c477f..5f77378b 100644 --- a/app/options.py +++ b/app/options.py @@ -1095,11 +1095,6 @@ if act == 'add_user_group_and_role': roxy_user.add_user_group_and_role() -if act == 'remove_user_group_and_role': - import modules.roxywi.user as roxy_user - - roxy_user.remove_user_group_and_role() - if act == 'save_user_group_and_role': import modules.roxywi.user as roxy_user @@ -1110,16 +1105,6 @@ if form.getvalue('changeUserServicesId') is not None: roxy_user.change_user_services() -if act == 'add_user_service': - import modules.roxywi.user as roxy_user - - roxy_user.move_user_service('add') - -if act == 'remove_user_service': - import modules.roxywi.user as roxy_user - - roxy_user.move_user_service('remove') - if form.getvalue('changeUserCurrentGroupId') is not None: import modules.roxywi.user as roxy_user diff --git a/app/templates/ajax/compare.html b/app/templates/ajax/compare.html index a255ff15..6f830cba 100644 --- a/app/templates/ajax/compare.html +++ b/app/templates/ajax/compare.html @@ -1,3 +1,4 @@ +{% import 'languages/'+lang|default('en')+'.html' as lang %}
{% set plus = [] %} @@ -23,7 +24,7 @@ {% set total_change = minus + plus %}
- Total change: {{ total_change|length }}, additions: {{ plus|length }} & deletions: {{ minus|length }} + {{lang.words.total|title()}} {{lang.words.changes}}: {{ total_change|length }}, {{lang.words.additions}}: {{ plus|length }} & {{lang.words.deletions}}: {{ minus|length }}
-
\ No newline at end of file + diff --git a/app/templates/ajax/move_user_service.html b/app/templates/ajax/move_user_service.html deleted file mode 100644 index b4d4ed68..00000000 --- a/app/templates/ajax/move_user_service.html +++ /dev/null @@ -1,19 +0,0 @@ -{% import 'languages/'+lang|default('en')+'.html' as lang %} -{% if length_tr|int() % 2 == 1 %} - {% set class = 'even' %} -{% endif %} -{% if action == 'add' %} - {% set tr_id = 'remove_service-' + service_id %} -{% else %} - {% set tr_id = 'add_service-' + service_id %} -{% endif %} - - {{service_name}} - - {% if action == 'add' %} - - - {% else %} - + - {% endif %} - - diff --git a/app/templates/ajax/remove_user_group_and_role.html b/app/templates/ajax/remove_user_group_and_role.html deleted file mode 100644 index 3d8c386b..00000000 --- a/app/templates/ajax/remove_user_group_and_role.html +++ /dev/null @@ -1,8 +0,0 @@ -{% import 'languages/'+lang|default('en')+'.html' as lang %} -{% if length_tr|int() % 2 == 1 %} -{% set class = 'even' %} -{% endif %} - - {{group_name}} - + - diff --git a/app/templates/ajax/show_compare_configs.html b/app/templates/ajax/show_compare_configs.html index 4bfed058..6e4f188e 100644 --- a/app/templates/ajax/show_compare_configs.html +++ b/app/templates/ajax/show_compare_configs.html @@ -1,10 +1,11 @@ {% from 'include/input_macros.html' import input %} +{% import 'languages/'+lang|default('en')+'.html' as lang %}
-

Comparing config files

+

{{ lang.phrases.comparing_config }}

{{ input('serv', type='hidden', value=serv) }} {{ input('open', type='hidden', value='open') }} - Compare + {{ lang.words.compare|title() }}

-
\ No newline at end of file + diff --git a/app/templates/base.html b/app/templates/base.html index 117eeb1a..8af75301 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -9,9 +9,9 @@ ' + + ''+service_name+'' + + '+'; + $('#add_service-'+service_id).remove(); + $("#checked_services tbody").append(html_tag); +} +function removeServiceFromUser(service_id) { + var service_name = $('#remove_service-'+service_id).attr('data-service_name'); + var add_word = $('#translate').attr('data-add'); + var service_word = $('#translate').attr('data-service'); + var length_tr = $('#all_services tbody tr').length; + var tr_class = 'odd'; + if (length_tr % 2 != 0) { + tr_class = 'even'; + } + var html_tag = '' + + ''+service_name+'' + + '+'; + $('#remove_service-'+service_id).remove(); + $("#all_services tbody").append(html_tag); } function confirmAjaxServiceAction(action, service) { var cancel_word = $('#translate').attr('data-cancel'); @@ -3090,6 +3107,7 @@ function confirmChangeGroupsAndRoles(user_id) { var cancel_word = $('#translate').attr('data-cancel'); var action_word = $('#translate').attr('data-save'); var user_groups_word = $('#translate').attr('data-user_groups'); + var username = $('#login-'+user_id).val(); $.ajax({ url: "options.py", data: { @@ -3105,7 +3123,7 @@ function confirmChangeGroupsAndRoles(user_id) { height: "auto", width: 700, modal: true, - title: user_groups_word, + title: user_groups_word + ' ' + username, buttons: [{ text: action_word, click: function () { @@ -3142,21 +3160,19 @@ function addGroupToUser(group_id) { } function removeGroupFromUser(group_id) { var group_name = $('#remove_group-'+group_id).attr('data-group_name'); - $.ajax({ - url: "options.py", - data: { - act: 'remove_user_group_and_role', - group_id: group_id, - group_name: group_name, - length_tr: $('#all_groups tbody tr').length, - token: $('#token').val() - }, - type: "POST", - success: function (data) { - $('#remove_group-'+group_id).remove(); - $("#all_groups tbody").append(data); - } - }); + var add_word = $('#translate').attr('data-add'); + var group2_word = $('#translate').attr('data-group2'); + var length_tr = $('#all_groups tbody tr').length; + var tr_class = 'odd'; + if (length_tr % 2 != 0) { + tr_class = 'even'; + } + var html_tag = '\n' + + ' '+group_name+'\n' + + ' +\n' + + '' + $('#remove_group-'+group_id).remove(); + $("#all_groups tbody").append(html_tag); } function saveGroupsAndRoles(user_id) { var length_tr = $('#checked_groups tbody tr').length; @@ -3167,11 +3183,11 @@ function saveGroupsAndRoles(user_id) { var role_id = $('#add_role-'+this_id).val(); jsonData[user_id][this_id] = {'role_id': role_id}; }); - console.log(jsonData); $.ajax({ url: "options.py", data: { act: 'save_user_group_and_role', + changeUserGroupsUser: $('#login-'+user_id).val(), jsonDatas: JSON.stringify(jsonData), token: $('#token').val() },