diff --git a/app/create_db.py b/app/create_db.py index 8489e037..c727881c 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -670,7 +670,7 @@ def update_db_v_5_2_0(**kwargs): def update_db_v_5_2_4(**kwargs): cursor = conn.cursor() - sql = """ALTER TABLE `user` ADD COLUMN user_services varchar(20) DEFAULT '1 2 3';""" + sql = """ALTER TABLE `user` ADD COLUMN user_services varchar(20) DEFAULT '1 2 3 4';""" try: cursor.execute(sql) except Exception as e: @@ -892,7 +892,7 @@ def update_db_v_5_4_02(**kwargs): def update_ver(): - query = Version.update(version='5.4.0.0') + query = Version.update(version='5.4.1.0') try: query.execute() except: diff --git a/app/funct.py b/app/funct.py index 86b46f88..8f9c4f0b 100644 --- a/app/funct.py +++ b/app/funct.py @@ -157,10 +157,7 @@ def logging(server_ip, action, **kwargs): except Exception: pass - if kwargs.get('alerting') == 1: - mess = get_data('date_in_log') + action + "\n" - log = open(log_path + "/checker-"+get_data('logs')+".log", "a") - elif kwargs.get('metrics') == 1: + if kwargs.get('metrics') == 1: mess = get_data('date_in_log') + action + "\n" log = open(log_path + "/metrics-"+get_data('logs')+".log", "a") elif kwargs.get('keep_alive') == 1: @@ -908,10 +905,32 @@ def upload_and_restart(server_ip, cfg, **kwargs): if kwargs.get("nginx"): service = 'nginx' + # config_path = sql.get_setting('nginx_config_path') + config_path = kwargs.get('config_file_name') + tmp_file = sql.get_setting('tmp_config_path') + "/" + get_data('config') + ".conf" elif kwargs.get("keepalived"): service = 'keepalived' + config_path = "/etc/keepalived/keepalived.conf" + tmp_file = sql.get_setting('tmp_config_path') + "/" + get_data('config') + ".cfg" else: service = 'haproxy' + config_path = sql.get_setting('haproxy_config_path') + tmp_file = sql.get_setting('tmp_config_path') + "/" + get_data('config') + ".cfg" + + is_docker = sql.select_service_setting(server_id, service, 'dockerized') + if is_docker == '1': + service_cont_name = service + '_container_name' + container_name = sql.get_setting(service_cont_name) + reload_command = " && sudo docker kill -s HUP " + container_name + restart_command = " && sudo docker restart " + container_name + else: + service_name = service + if service == 'haproxy': + haproxy_enterprise = sql.select_service_setting(server_id, 'haproxy', 'haproxy_enterprise') + if haproxy_enterprise == '1': + service_name = "hapee-2.0-lb" + reload_command = " && sudo systemctl reload " + service_name + restart_command = " && sudo systemctl restart " + service_name if kwargs.get("just_save") == 'save': action = 'save' @@ -927,17 +946,6 @@ def upload_and_restart(server_ip, cfg, **kwargs): else: login = 1 - if service == "nginx": - # config_path = sql.get_setting('nginx_config_path') - config_path = kwargs.get('config_file_name') - tmp_file = sql.get_setting('tmp_config_path') + "/" + get_data('config') + ".conf" - elif service == "keepalived": - config_path = "/etc/keepalived/keepalived.conf" - tmp_file = sql.get_setting('tmp_config_path') + "/" + get_data('config') + ".cfg" - else: - config_path = sql.get_setting('haproxy_config_path') - tmp_file = sql.get_setting('tmp_config_path') + "/" + get_data('config') + ".cfg" - try: os.system("dos2unix "+cfg) except OSError: @@ -948,48 +956,30 @@ def upload_and_restart(server_ip, cfg, **kwargs): if action == "save": commands = [move_config] elif action == "reload": - commands = [ - move_config + " && sudo systemctl reload keepalived"] + commands = [move_config + reload_command] else: - commands = [move_config + " && sudo systemctl restart keepalived"] + commands = [move_config + restart_command] elif service == "nginx": - is_docker = sql.select_service_setting(server_id, 'nginx', 'dockerized') if is_docker == '1': - container_name = sql.get_setting('nginx_container_name') check_config = "sudo docker exec -it exec " + container_name + " nginx -t -q " else: check_config = "sudo nginx -t -q -p " + tmp_file - check_and_move = "sudo mv -f " + tmp_file + " " + config_path + " && sudo nginx -t -q" + check_and_move = "sudo mv -f " + tmp_file + " " + config_path + " && " + check_config if action == "test": commands = [check_config + " && sudo rm -f " + tmp_file] elif action == "save": commands = [check_and_move] elif action == "reload": - if is_docker == '1': - commands = [ check_and_move + " && sudo docker kill -s HUP "+container_name ] - else: - commands = [ check_and_move + " && sudo systemctl reload nginx" ] + commands = [ check_and_move + reload_command ] else: - if is_docker == '1': - commands = [check_and_move + " && sudo docker restart " + container_name] - else: - commands = [check_and_move + " && sudo systemctl restart nginx"] + commands = [check_and_move + restart_command] if sql.return_firewall(server_ip): commands[0] += open_port_firewalld(cfg, server_ip=server_ip, service='nginx') else: - is_docker = sql.select_service_setting(server_id, 'haproxy', 'dockerized') - haproxy_service_name = "haproxy" - if is_docker == '1': - container_name = sql.get_setting('haproxy_container_name') check_config = "sudo docker exec -it " + container_name + " haproxy -q -c -f " + tmp_file else: - haproxy_enterprise = sql.select_service_setting(server_id, 'haproxy', 'haproxy_enterprise') - - if haproxy_enterprise == '1': - haproxy_service_name = "hapee-2.0-lb" - - check_config = "sudo " + haproxy_service_name + " -q -c -f " + tmp_file + check_config = "sudo " + service_name + " -q -c -f " + tmp_file move_config = " && sudo mv -f " + tmp_file + " " + config_path if action == "test": @@ -997,15 +987,9 @@ def upload_and_restart(server_ip, cfg, **kwargs): elif action == "save": commands = [check_config + move_config] elif action == "reload": - if is_docker == '1': - commands = [check_config + move_config + " && sudo docker kill -s HUP "+container_name ] - else: - commands = [check_config + move_config + " && sudo systemctl reload "+haproxy_service_name ] + commands = [check_config + move_config + reload_command ] else: - if is_docker == '1': - commands = [check_config + move_config + " && sudo docker restart "+container_name ] - else: - commands = [check_config + move_config + " && sudo systemctl restart "+haproxy_service_name ] + commands = [check_config + move_config + restart_command ] if sql.return_firewall(server_ip): commands[0] += open_port_firewalld(cfg, server_ip=server_ip) @@ -1533,21 +1517,25 @@ def check_user_group(**kwargs): if kwargs.get('token') is not None: return True - import http.cookies - import os import sql - cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) - user_uuid = cookie.get('uuid') - group = cookie.get('group') - group_id = group.value - user_id = sql.get_user_id_by_uuid(user_uuid.value) + if kwargs.get('user_uuid'): + group_id = kwargs.get('user_group_id') + user_uuid = kwargs.get('user_uuid') + user_id = sql.get_user_id_by_uuid(user_uuid) + else: + import http.cookies + import os + cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) + user_uuid = cookie.get('uuid') + group = cookie.get('group') + group_id = group.value + user_id = sql.get_user_id_by_uuid(user_uuid.value) if sql.check_user_group(user_id, group_id): return True else: logging('localhost', ' has tried to actions in not his group ', haproxywi=1, login=1) print('Atata!') - sys.exit() def check_is_server_in_group(server_ip): diff --git a/app/options.py b/app/options.py index ca9b1d9d..df10494a 100644 --- a/app/options.py +++ b/app/options.py @@ -1207,6 +1207,7 @@ if form.getvalue('master'): IP = form.getvalue('vrrpip') syn_flood = form.getvalue('syn_flood') virt_server = form.getvalue('virt_server') + return_to_master = form.getvalue('return_to_master') haproxy = form.getvalue('hap') nginx = form.getvalue('nginx') script = "install_keepalived.sh" @@ -1229,7 +1230,8 @@ if form.getvalue('master'): os.system("cp scripts/%s ." % script) commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port + - " ETH=" + ETH + " IP=" + str(IP) + " MASTER=MASTER" + " SYN_FLOOD=" + syn_flood + " HOST=" + str(master) + + " ETH=" + ETH + " IP=" + str(IP) + " MASTER=MASTER" + " RETURN_TO_MASTER=" + return_to_master + + " SYN_FLOOD=" + syn_flood + " HOST=" + str(master) + " USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)] output, error = funct.subprocess_execute(commands[0]) @@ -1286,6 +1288,7 @@ if form.getvalue('masteradd'): ETH = form.getvalue('interfaceadd') IP = form.getvalue('vrrpipadd') kp = form.getvalue('kp') + return_to_master = form.getvalue('return_to_master') script = "install_keepalived.sh" proxy = sql.get_setting('proxy') ssh_port = 22 @@ -1306,7 +1309,7 @@ if form.getvalue('masteradd'): ssh_port = str(server[10]) commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + - " SSH_PORT=" + ssh_port + " ETH=" + ETH + + " SSH_PORT=" + ssh_port + " ETH=" + ETH + " RETURN_TO_MASTER=" + return_to_master + " IP=" + str(IP) + " MASTER=MASTER" + " RESTART=" + kp + " ADD_VRRP=1 HOST=" + str(master) + " USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)] diff --git a/app/templates/ajax/config_show.html b/app/templates/ajax/config_show.html index 419ee591..3ba1f9d1 100644 --- a/app/templates/ajax/config_show.html +++ b/app/templates/ajax/config_show.html @@ -4,6 +4,11 @@ {% if role <= 3 %} {% if not is_serv_protected or role <= 2 %} Edit + {% if service == 'haproxy' %} + Add + {% elif service == 'keepalived' %} + Add + {% endif %} {% endif %} {% endif %} Expand all @@ -111,6 +116,14 @@
Current installation | Master | +Current installation | Slave | Interface | VRRP IP | -HAProxy | - -Nginx | -Add VIRT | -SYN-flood protection | |
+ | {{ input('interface', size='7', title='Interface for VRRP address') }} | {{ input('vrrp-ip', size='14') }} | -{{ checkbox('hap', title='Roxy-WI will try to install HAProxy') }} | +{{ checkbox('virt_server', title='Roxy-WI will add VRRP address as a separated server', checked='checked') }} | +||||||
+ | + | Return to Master state | +SYN-flood protection | +HAProxy | + +Nginx | + ++ | + | |||
+ | + | {{ checkbox('return_to_master', checked='checked') }} | +{{ checkbox('syn_flood') }} | +{{ checkbox('hap', title='Roxy-WI will try to install HAProxy') }} | {{ checkbox('nginx', title='Roxy-WI will try to install Nginx') }} | -{{ checkbox('virt_server', title='Roxy-WI will add VRRP address as a separated server', checked='checked') }} | -{{ checkbox('syn_flood') }} | - + | +
Current installation | Master | +Current installation | Slave | Interface | VRRP IP | Restart | -- | - | - | + | Return to Master state | ||
+ | {{ input('interface-add', size='7', title='Interface for VRRP address') }} | {{ input('vrrp-ip-add', size='14') }} | -{{ checkbox('kp', title='If checked Roxy-WI will restart Keepalived') }} | -- | - | - | + | {{ checkbox('kp', title='If checked Roxy-WI will restart Keepalived') }} | +{{ checkbox('add_return_to_master', checked='checked') }} | - + |
'+data+'
', '#creating-master', progress_value, '#creating-progress', '#created-mess', '#wait-mess'); + $( "#master" ).trigger( "selectmenuchange" ); if (hap === '1') { create_keep_alived_hap(nginx, 'master', haproxy_docker); } @@ -237,6 +344,7 @@ function create_slave_keepalived(hap, nginx, syn_flood) { showProvisioningWarning(step_id, 'slave Keepalived', '#creating-warning', '#wait_mess'); } else if (data.indexOf('success') != '-1' ){ showProvisioningProccess(''+data+'
', '#creating-slave', progress_value, '#creating-progress', '#created-mess', '#wait-mess'); + $( "#slave" ).trigger( "selectmenuchange" ); } else { toastr.clear(); toastr.info(data);