From 620dd68d51de163f221aa31a4760a6f6c147cfeb Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Sun, 3 Jul 2022 19:37:15 +0300 Subject: [PATCH] v6.1.1.0 Change log: https://roxy-wi.org/changelog.py#6_1_1 --- app/add.py | 7 ++-- app/db_model.py | 2 +- app/funct.py | 6 +-- app/options.py | 40 +++++++++++-------- app/overview.py | 2 +- app/roxy-wi.cfg | 11 ++--- app/scripts/ansible/roles/backup.yml | 14 +++---- .../keepalived/templates/keepalived.conf.j2 | 2 +- 8 files changed, 46 insertions(+), 38 deletions(-) diff --git a/app/add.py b/app/add.py index 0587bd7b..ce258ef2 100644 --- a/app/add.py +++ b/app/add.py @@ -27,9 +27,10 @@ if all(v is None for v in [ except Exception as e: print(str(e)) - dir = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') - white_dir = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + user_group + "/white" - black_dir = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + user_group + "/black" + lib_path = funct.get_config_var('main', 'lib_path') + dir = lib_path + "/" + sql.get_setting('lists_path') + white_dir = lib_path + "/" + sql.get_setting('lists_path') + "/" + user_group + "/white" + black_dir = lib_path + "/" + sql.get_setting('lists_path') + "/" + user_group + "/black" if not os.path.exists(dir): os.makedirs(dir) diff --git a/app/db_model.py b/app/db_model.py index 42856f91..fa06e37e 100644 --- a/app/db_model.py +++ b/app/db_model.py @@ -12,7 +12,7 @@ if mysql_enable == '1': mysql_port = get_config_var('mysql', 'mysql_port') conn = MySQLDatabase(mysql_db, user=mysql_user, password=mysql_password, host=mysql_host, port=int(mysql_port)) else: - db = "/var/www/haproxy-wi/app/roxy-wi.db" + db = "/var/lib/roxy-wi/app/roxy-wi.db" conn = SqliteDatabase(db, pragmas={'timeout': 1000, 'foreign_keys': 1}) diff --git a/app/funct.py b/app/funct.py index 652f2f94..18c896a9 100644 --- a/app/funct.py +++ b/app/funct.py @@ -360,7 +360,7 @@ def page_for_admin(**kwargs): def return_ssh_keys_path(server_ip, **kwargs): import sql - full_path = get_config_var('main', 'fullpath') + lib_path = get_config_var('main', 'lib_path') ssh_enable = '' ssh_user_name = '' ssh_user_password = '' @@ -371,13 +371,13 @@ def return_ssh_keys_path(server_ip, **kwargs): ssh_enable = sshs.enable ssh_user_name = sshs.username ssh_user_password = sshs.password - ssh_key_name = full_path + '/keys/%s.pem' % sshs.name + ssh_key_name = lib_path + '/keys/%s.pem' % sshs.name else: for sshs in sql.select_ssh(serv=server_ip): ssh_enable = sshs.enable ssh_user_name = sshs.username ssh_user_password = sshs.password - ssh_key_name = full_path + '/keys/%s.pem' % sshs.name + ssh_key_name = lib_path + '/keys/%s.pem' % sshs.name return ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name diff --git a/app/options.py b/app/options.py index 2330b8f2..90624865 100644 --- a/app/options.py +++ b/app/options.py @@ -305,15 +305,15 @@ if form.getvalue('list_select_id') is not None: if form.getvalue('list_id_for_delete') is not None: haproxy_sock_port = sql.get_setting('haproxy_sock_port') lists_path = sql.get_setting('lists_path') - full_path = funct.get_config_var('main', 'fullpath') + lib_path = funct.get_config_var('main', 'lib_path') ip_id = form.getvalue('list_ip_id_for_delete') ip = form.getvalue('list_ip_for_delete') list_id = form.getvalue('list_id_for_delete') list_name = form.getvalue('list_name') user_group = funct.get_user_group(id=1) - cmd = "sed -i 's!%s$!!' %s/%s/%s/%s" % (ip, full_path, lists_path, user_group, list_name) - cmd1 = "sed -i '/^$/d' %s/%s/%s/%s" % (full_path, lists_path, user_group, list_name) + cmd = "sed -i 's!%s$!!' %s/%s/%s/%s" % (ip, lib_path, lists_path, user_group, list_name) + cmd1 = "sed -i '/^$/d' %s/%s/%s/%s" % (lib_path, lists_path, user_group, list_name) output, stderr = funct.subprocess_execute(cmd) output1, stderr1 = funct.subprocess_execute(cmd1) if output: @@ -338,7 +338,7 @@ if form.getvalue('list_id_for_delete') is not None: if form.getvalue('list_ip_for_add') is not None: haproxy_sock_port = sql.get_setting('haproxy_sock_port') lists_path = sql.get_setting('lists_path') - full_path = funct.get_config_var('main', 'fullpath') + lib_path = funct.get_config_var('main', 'lib_path') ip = form.getvalue('list_ip_for_add') ip = ip.strip() ip = funct.is_ip_or_dns(ip) @@ -354,7 +354,7 @@ if form.getvalue('list_ip_for_add') is not None: print('error: ' + stderr[0]) if 'is not a valid IPv4 or IPv6 address' not in output[0]: - cmd = 'echo "%s" >> %s/%s/%s/%s' % (ip, full_path, lists_path, user_group, list_name) + cmd = 'echo "%s" >> %s/%s/%s/%s' % (ip, lib_path, lists_path, user_group, list_name) output, stderr = funct.subprocess_execute(cmd) if output: print('error: ' + str(output)) @@ -1990,7 +1990,8 @@ if form.getvalue('get_exporter_v'): print(funct.get_service_version(serv, form.getvalue('get_exporter_v'))) if form.getvalue('bwlists'): - list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue('color') + "/" + form.getvalue('bwlists') + lib_path = funct.get_config_var('main', 'lib_path') + list_path = lib_path + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue('color') + "/" + form.getvalue('bwlists') try: file = open(list_path, "r") file_read = file.read() @@ -2002,8 +2003,9 @@ if form.getvalue('bwlists'): if form.getvalue('bwlists_create'): color = form.getvalue('color') list_name = form.getvalue('bwlists_create').split('.')[0] + lib_path = funct.get_config_var('main', 'lib_path') list_name += '.lst' - list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + list_name + list_path = lib_path + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + list_name try: open(list_path, 'a').close() print('success: ') @@ -2017,7 +2019,8 @@ if form.getvalue('bwlists_create'): if form.getvalue('bwlists_save'): color = form.getvalue('color') bwlists_save = form.getvalue('bwlists_save') - list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + bwlists_save + lib_path = funct.get_config_var('main', 'lib_path') + list_path = lib_path + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + bwlists_save try: with open(list_path, "w") as file: file.write(form.getvalue('bwlists_content')) @@ -2068,7 +2071,8 @@ if form.getvalue('bwlists_save'): if form.getvalue('bwlists_delete'): color = form.getvalue('color') bwlists_delete = form.getvalue('bwlists_delete') - list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + bwlists_delete + lib_path = funct.get_config_var('main', 'lib_path') + list_path = lib_path + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + bwlists_delete try: os.remove(list_path) except IOError as e: @@ -2102,7 +2106,8 @@ if form.getvalue('bwlists_delete'): pass if form.getvalue('get_lists'): - list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue('color') + lib_path = funct.get_config_var('main', 'lib_path') + list_path = lib_path + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue('color') lists = funct.get_files(dir=list_path, format="lst") for list in lists: print(list) @@ -2430,13 +2435,13 @@ if form.getvalue('new_ssh'): funct.logging('localhost', 'A new SSH credentials ' + name + ' has created', haproxywi=1, login=1) if form.getvalue('sshdel') is not None: - fullpath = funct.get_config_var('main', 'fullpath') + lib_path = funct.get_config_var('main', 'lib_path') sshdel = form.getvalue('sshdel') for sshs in sql.select_ssh(id=sshdel): ssh_enable = sshs.enable name = sshs.name - ssh_key_name = fullpath + '/keys/%s.pem' % sshs.name + ssh_key_name = lib_path + '/keys/%s.pem' % sshs.name if ssh_enable == 1: cmd = 'rm -f %s' % ssh_key_name @@ -2459,12 +2464,12 @@ if form.getvalue('updatessh'): if username is None: print(error_mess) else: - fullpath = funct.get_config_var('main', 'fullpath') + lib_path = funct.get_config_var('main', 'lib_path') for sshs in sql.select_ssh(id=ssh_id): ssh_enable = sshs.enable - ssh_key_name = fullpath + '/keys/%s.pem' % sshs.name - new_ssh_key_name = fullpath + '/keys/%s.pem' % name + ssh_key_name = lib_path + '/keys/%s.pem' % sshs.name + new_ssh_key_name = lib_path + '/keys/%s.pem' % name if ssh_enable == 1: cmd = 'mv %s %s' % (ssh_key_name, new_ssh_key_name) @@ -2487,8 +2492,9 @@ if form.getvalue('ssh_cert'): except Exception as e: print('error: Cannot save SSH key file: ', str(e)) - full_dir = '/var/www/haproxy-wi/keys/' - ssh_keys = full_dir + name + '.pem' + lib_path = funct.get_config_var('main', 'lib_path') + full_dir = lib_path + '/keys/' + ssh_keys = name + '.pem' try: split_name = name.split('_')[1] diff --git a/app/overview.py b/app/overview.py index 892c436f..fcf08c91 100644 --- a/app/overview.py +++ b/app/overview.py @@ -106,7 +106,7 @@ rendered_template = template.render( metrics_master=''.join(metrics_master), metrics_worker=''.join(metrics_worker), checker_master=''.join(checker_master), checker_worker=''.join(checker_worker), keep_alive=''.join(keep_alive), smon=''.join(smon), port_scanner=''.join(port_scanner), grafana=''.join(grafana), socket=''.join(socket), - haproxy_wi_log_id=funct.haproxy_wi_log(log_id=1, file="roxy-wi-", with_date=1), + roxy_wi_log_id=funct.haproxy_wi_log(log_id=1, file="roxy-wi-", with_date=1), metrics_log_id=funct.haproxy_wi_log(log_id=1, file="metrics", with_date=1), checker_log_id=funct.haproxy_wi_log(log_id=1, file="checker", with_date=1), keep_alive_log_id=funct.haproxy_wi_log(log_id=1, file="keep_alive"), diff --git a/app/roxy-wi.cfg b/app/roxy-wi.cfg index 3cebad2b..05c3f55c 100644 --- a/app/roxy-wi.cfg +++ b/app/roxy-wi.cfg @@ -1,14 +1,15 @@ [main] # Path to the files destination fullpath = /var/www/haproxy-wi -log_path = ${fullpath}/log/ +log_path = ${fullpath}/log/ +lib_path = /var/lib/roxy-wi [configs] # Folders for configs -haproxy_save_configs_dir = ${main:fullpath}/configs/hap_config/ -kp_save_configs_dir = ${main:fullpath}/configs/kp_config/ -nginx_save_configs_dir = ${main:fullpath}/configs/nginx_config/ -apache_save_configs_dir = ${main:fullpath}/configs/apache_config/ +haproxy_save_configs_dir = ${main:lib_path}/configs/hap_config/ +kp_save_configs_dir = ${main:lib_path}/configs/kp_config/ +nginx_save_configs_dir = ${main:lib_path}/configs/nginx_config/ +apache_save_configs_dir = ${main:lib_path}/configs/apache_config/ [mysql] # By default Sqlite DB is used diff --git a/app/scripts/ansible/roles/backup.yml b/app/scripts/ansible/roles/backup.yml index ee9aa8fb..6a98cafd 100644 --- a/app/scripts/ansible/roles/backup.yml +++ b/app/scripts/ansible/roles/backup.yml @@ -6,38 +6,38 @@ - name: Set SSH port set_fact: ansible_port: "{{SSH_PORT}}" - + - name: Creates directory file: path: "{{ RPATH }}/roxy-wi-configs-backup/configs" state: directory owner: "{{ ansible_user }}" when: DELJOB|length == 0 - + - hosts: haproxy_wi become: yes become_method: sudo gather_facts: no tasks: - + - name: Creates backup jobs cron: name: "Roxy-WI Backup configs for server {{ SERVER }} {{ item }}" special_time: "{{ TIME }}" - job: "rsync -arv {{ TYPE }} /var/www/haproxy-wi/configs/{{ item }}/{{ SERVER }}* {{ ansible_user }}@{{ HOST }}:{{ RPATH }}/roxy-wi-configs-backup/configs/{{ item }} -e 'ssh -i {{ KEY }} -o StrictHostKeyChecking=no' --log-file=/var/www/haproxy-wi/log/backup.log" + job: "rsync -arv {{ TYPE }} /var/lib/roxy-wi/configs/{{ item }}/{{ SERVER }}* {{ ansible_user }}@{{ HOST }}:{{ RPATH }}/roxy-wi-configs-backup/configs/{{ item }} -e 'ssh -i {{ KEY }} -o StrictHostKeyChecking=no' --log-file=/var/www/haproxy-wi/log/backup.log" when: DELJOB|length == 0 - with_items: + with_items: - kp_config - hap_config - nginx_config - apache_config - + - name: Removes backup jobs cron: name: "Roxy-WI Backup configs for server {{ SERVER }} {{ item }}" state: absent when: DELJOB|length > 0 - with_items: + with_items: - kp_config - hap_config - nginx_config diff --git a/app/scripts/ansible/roles/keepalived/templates/keepalived.conf.j2 b/app/scripts/ansible/roles/keepalived/templates/keepalived.conf.j2 index c373937b..ab61f73c 100644 --- a/app/scripts/ansible/roles/keepalived/templates/keepalived.conf.j2 +++ b/app/scripts/ansible/roles/keepalived/templates/keepalived.conf.j2 @@ -3,7 +3,7 @@ global_defs { } #health-check for keepalive vrrp_script chk_haproxy { - script "killall -0 haproxy" + script "/usr/bin/killall -0 haproxy" interval 2 weight 3 }