diff --git a/app/create_db.py b/app/create_db.py index fac37946..9c7257c7 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -755,7 +755,7 @@ def update_db_v_7_2_3(): def update_ver(): try: - Version.update(version='7.2.5.0').execute() + Version.update(version='7.2.6.0').execute() except Exception: print('Cannot update version') diff --git a/app/modules/db/user.py b/app/modules/db/user.py index 3e84fc75..954accb5 100644 --- a/app/modules/db/user.py +++ b/app/modules/db/user.py @@ -245,16 +245,13 @@ def get_user_id_by_username(username: str): def get_user_role_by_uuid(uuid, group_id): - query = ( - UserGroups.select(UserGroups.user_role_id).join(UUID, on=(UserGroups.user_id == UUID.user_id) + try: + query_res = UserGroups.select(UserGroups.user_role_id).join( + UUID, on=(UserGroups.user_id == UUID.user_id) ).where( (UUID.uuid == uuid) & (UserGroups.user_group_id == group_id) - ) - ) - - try: - query_res = query.execute() + ).execute() except Exception as e: out_error(e) else: @@ -262,6 +259,20 @@ def get_user_role_by_uuid(uuid, group_id): return int(user_id.user_role_id) +def get_user_current_group_by_uuid(uuid): + try: + query_res = User.select(User.groups).join( + UUID, on=(User.user_id == UUID.user_id) + ).where( + (UUID.uuid == uuid) + ).execute() + except Exception as e: + out_error(e) + else: + for user_id in query_res: + return int(user_id.groups) + + def write_user_uuid(login, user_uuid): session_ttl = get_setting('session_ttl') user_id = get_user_id_by_username(login) diff --git a/app/modules/roxywi/common.py b/app/modules/roxywi/common.py index 4398cead..2835bd20 100644 --- a/app/modules/roxywi/common.py +++ b/app/modules/roxywi/common.py @@ -209,10 +209,18 @@ def get_users_params(**kwargs): raise Exception('error: Cannot get user UUID') try: - group_id = int(request.cookies.get('group')) + group_id = user_sql.get_user_current_group_by_uuid(user_uuid) except Exception as e: raise Exception(f'error: Cannot get user group: {e}') + try: + group_id_from_cookies = int(request.cookies.get('group')) + except Exception as e: + raise Exception(f'error: Cannot get group id from cookies: {e}') + + if group_id_from_cookies != group_id: + raise Exception('error: Wrong current group') + try: role = user_sql.get_user_role_by_uuid(user_uuid, group_id) except Exception: diff --git a/app/modules/roxywi/roxy.py b/app/modules/roxywi/roxy.py index 9de77f4a..5d1b2fb4 100644 --- a/app/modules/roxywi/roxy.py +++ b/app/modules/roxywi/roxy.py @@ -60,9 +60,9 @@ def check_new_version(service): proxy_dict = common.return_proxy_dict() try: - response = requests.get(f'https://roxy-wi.org/version/get/{service}', timeout=1, proxies=proxy_dict) + response = requests.get(f'https://roxy-wi.org/version/get/{service}', timeout=5, proxies=proxy_dict) if service == 'roxy-wi': - requests.get(f'https://roxy-wi.org/version/send/{current_ver}', timeout=1, proxies=proxy_dict) + requests.get(f'https://roxy-wi.org/version/send/{current_ver}', timeout=5, proxies=proxy_dict) res = response.content.decode(encoding='UTF-8') except requests.exceptions.RequestException as e: @@ -82,7 +82,7 @@ def update_user_status() -> None: adapter = HTTPAdapter(max_retries=retry_strategy) roxy_wi_get_plan = requests.Session() roxy_wi_get_plan.mount("https://", adapter) - roxy_wi_get_plan = requests.get(f'https://roxy-wi.org/user-name/{user_name}', timeout=1, proxies=proxy_dict) + roxy_wi_get_plan = requests.get(f'https://roxy-wi.org/user-name/{user_name}', timeout=5, proxies=proxy_dict) try: status = roxy_wi_get_plan.content.decode(encoding='UTF-8') status = status.split(' ') diff --git a/app/modules/service/installation.py b/app/modules/service/installation.py index fb6686d5..a06e84a9 100644 --- a/app/modules/service/installation.py +++ b/app/modules/service/installation.py @@ -2,7 +2,6 @@ import os import json from packaging import version -from flask import render_template import ansible import ansible_runner @@ -35,81 +34,28 @@ def show_installation_output(error: str, output: list, service: str, rc=0): return True -def show_success_installation(service): - lang = roxywi_common.get_user_lang_for_flask() - return render_template('include/show_success_installation.html', service=service, lang=lang) +def generate_geoip_inv(server_ip: str, installed_service: str, geoip_update: int) -> object: + inv = {"server": {"hosts": {}}} + server_ips = [] + + inv['server']['hosts'][server_ip] = { + 'service_dir': common.return_nice_path(sql.get_setting(f'{installed_service}_dir')), + 'maxmind_key': sql.get_setting('maxmind_key'), + 'UPDATE': geoip_update + + } + server_ips.append(server_ip) + + return inv, server_ips -def geoip_installation(serv, geoip_update, service): - proxy = sql.get_setting('proxy') - maxmind_key = sql.get_setting('maxmind_key') - proxy_serv = '' - ssh_settings = return_ssh_keys_path(serv) - full_path = '/var/www/haproxy-wi/app' +def generate_grafana_inv() -> object: + inv = {"server": {"hosts": {}}} + server_ips = [] + inv['server']['hosts']['localhost'] = {} + server_ips.append('localhost') - if service in ('haproxy', 'nginx'): - service_dir = common.return_nice_path(sql.get_setting(f'{service}_dir')) - script = f'install_{service}_geoip.sh' - else: - raise Exception('warning: select a server and service first') - - if proxy is not None and proxy != '' and proxy != 'None': - proxy_serv = proxy - - try: - os.system(f"cp {full_path}/scripts/{script} {full_path}/{script}") - except Exception as e: - raise Exception(f'error: {e}') - - commands = [ - f"chmod +x {full_path}/{script} && {full_path}/{script} PROXY={proxy_serv} SSH_PORT={ssh_settings['port']} UPDATE={geoip_update} " - f"maxmind_key={maxmind_key} service_dir={service_dir} HOST={serv} USER={ssh_settings['user']} " - f"PASS={ssh_settings['password']} KEY={ssh_settings['key']}" - ] - - return_out = server_mod.subprocess_execute_with_rc(commands[0]) - - try: - show_installation_output(return_out['error'], return_out['output'], 'GeoLite2 Database', rc=return_out['rc']) - except Exception as e: - raise Exception(e) - - os.remove(f'{full_path}/{script}') - - return show_success_installation('GeoLite2 Database') - - -def grafana_install(): - script = "install_grafana.sh" - proxy = sql.get_setting('proxy') - proxy_serv = '' - host = os.environ.get('HTTP_HOST', '') - full_path = '/var/www/haproxy-wi/app' - - try: - os.system(f"cp {full_path}/scripts/{script} {full_path}/{script}") - except Exception as e: - raise Exception(f'error: {e}') - - if proxy is not None and proxy != '' and proxy != 'None': - proxy_serv = proxy - - cmd = f"chmod +x {full_path}/{script} && {full_path}/{script} PROXY={proxy_serv}" - output, error = server_mod.subprocess_execute(cmd) - - if error: - roxywi_common.logging('Roxy-WI server', error, roxywi=1) - else: - for line in output: - if any(s in line for s in ("Traceback", "FAILED")): - try: - return line - except Exception: - return output - - os.remove(f'{full_path}/{script}') - - return f'success: Grafana and Prometheus servers were installed. You can find Grafana on http://{host}:3000
' + return inv, server_ips def generate_kp_inv(json_data: json, installed_service) -> object: @@ -155,13 +101,9 @@ def generate_kp_inv(json_data: json, installed_service) -> object: def generate_waf_inv(server_ip: str, installed_service: str) -> object: inv = {"server": {"hosts": {}}} server_ips = [] - if installed_service == "waf": - service_dir = sql.get_setting('haproxy_dir') - else: - service_dir = sql.get_setting('nginx_dir') inv['server']['hosts'][server_ip] = { - 'SERVICE_PATH': service_dir + 'SERVICE_PATH': common.return_nice_path(sql.get_setting(f'{installed_service}_dir')) } server_ips.append(server_ip) @@ -404,7 +346,7 @@ def install_service(service: str, json_data: str) -> object: def _install_ansible_collections(): old_ansible_server = '' - collections = ('community.general', 'ansible.posix', 'community.docker') + collections = ('community.general', 'ansible.posix', 'community.docker', 'community.grafana') trouble_link = 'Read troubleshooting' for collection in collections: if not os.path.isdir(f'/usr/share/httpd/.ansible/collections/ansible_collections/{collection.replace(".", "/")}'): diff --git a/app/routes/install/routes.py b/app/routes/install/routes.py index 56095851..10127947 100644 --- a/app/routes/install/routes.py +++ b/app/routes/install/routes.py @@ -77,7 +77,8 @@ def get_exporter_version(exporter, server_ip): @bp.route('/grafana') def install_grafana(): try: - return service_mod.grafana_install() + inv, server_ips = service_mod.generate_grafana_inv() + return service_mod.run_ansible(inv, server_ips, 'grafana'), 201 except Exception as e: return f'{e}' @@ -121,9 +122,10 @@ def install_geoip(): service = request.form.get('service') try: - return service_mod.geoip_installation(server_ip, geoip_update, service) + inv, server_ips = service_mod.generate_geoip_inv(server_ip, service, geoip_update) + return service_mod.run_ansible(inv, server_ips, f'{service}_geoip'), 201 except Exception as e: - return str(e) + return f'{e}' @bp.route('/geoip//') diff --git a/app/scripts/ansible/roles/geoip.sh.j2 b/app/scripts/ansible/roles/geoip.sh.j2 index 2e1a3b43..86ac4982 100644 --- a/app/scripts/ansible/roles/geoip.sh.j2 +++ b/app/scripts/ansible/roles/geoip.sh.j2 @@ -4,7 +4,7 @@ set -e -o pipefail country_location="GeoLite2-Country-CSV_*/GeoLite2-Country-Locations-en.csv" country_ip="GeoLite2-Country-CSV_*/GeoLite2-Country-Blocks-IPv4.csv" -haproxy_dir="{{haproxy_dir}}" +service_dir="{{service_dir}}" MAXMIND_LICENSE="{{maxmind_key}}" PROXY="{{PROXY}}" @@ -45,10 +45,10 @@ while read line; do done < $country_location -if [[ ! -d "$haproxy_dir"/geoip ]]; then - mkdir "$haproxy_dir"/geoip +if [[ ! -d "$service_dir"/geoip ]]; then + mkdir "$service_dir"/geoip fi -cp subnets/* "$haproxy_dir"/geoip +cp subnets/* "$service_dir"/geoip systemctl reload haproxy \ No newline at end of file diff --git a/app/scripts/ansible/roles/geoip.yml b/app/scripts/ansible/roles/haproxy_geoip.yml similarity index 65% rename from app/scripts/ansible/roles/geoip.yml rename to app/scripts/ansible/roles/haproxy_geoip.yml index b4ec7687..ef9dfd52 100644 --- a/app/scripts/ansible/roles/geoip.yml +++ b/app/scripts/ansible/roles/haproxy_geoip.yml @@ -1,19 +1,15 @@ -- hosts: "{{ variable_host }}" +- hosts: all become: yes become_method: sudo tasks: - - name: Set SSH port - set_fact: - ansible_port: "{{SSH_PORT}}" - - name: Creates directory file: - path: "{{haproxy_dir}}/geoip" + path: "{{service_dir}}/geoip" state: directory - name: Creates directory file: - path: "{{haproxy_dir}}/scripts" + path: "{{service_dir}}/scripts" state: directory - name: Install wget @@ -30,16 +26,16 @@ - name: Copy GeoIP script in place. template: src: /var/www/haproxy-wi/app/scripts/ansible/roles/geoip.sh.j2 - dest: "{{haproxy_dir}}/scripts/geoip.sh" + dest: "{{service_dir}}/scripts/geoip.sh" mode: 0777 - name: Execute the script - command: "{{haproxy_dir}}/scripts/geoip.sh" + command: "{{service_dir}}/scripts/geoip.sh" - name: Update geoip every Wednesday cron: - name: "Update geoip" + name: "Update HAProxy geoip" minute: "0" hour: "01" weekday: "3" - job: "{{haproxy_dir}}/scripts/geoip.sh" \ No newline at end of file + job: "{{service_dir}}/scripts/geoip.sh" \ No newline at end of file diff --git a/app/scripts/ansible/roles/keepalived/tasks/main.yml b/app/scripts/ansible/roles/keepalived/tasks/main.yml index a421e13c..87628289 100644 --- a/app/scripts/ansible/roles/keepalived/tasks/main.yml +++ b/app/scripts/ansible/roles/keepalived/tasks/main.yml @@ -69,7 +69,7 @@ when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') -- name: Disble SELINUX in config +- name: Disable SELINUX in config template: src: ../../haproxy/templates/selinux.j2 dest: /etc/selinux/config @@ -79,7 +79,7 @@ - '"Enforcing" in sestatus.stdout' -- name: Disble SELINUX in env +- name: Disable SELINUX in env shell: setenforce 0 2> /dev/null ignore_errors: yes debugger: never diff --git a/app/scripts/ansible/roles/nginx_geoip.yml b/app/scripts/ansible/roles/nginx_geoip.yml index 3bd57106..bc4760d9 100644 --- a/app/scripts/ansible/roles/nginx_geoip.yml +++ b/app/scripts/ansible/roles/nginx_geoip.yml @@ -1,6 +1,6 @@ --- - name: Install NGINX GeoIP - hosts: "{{ variable_host }}" + hosts: all become: yes become_method: sudo gather_facts: yes diff --git a/app/scripts/ansible/roles/nginx_geoip/tasks/main.yml b/app/scripts/ansible/roles/nginx_geoip/tasks/main.yml index 57b2fe8d..4ac08ffc 100644 --- a/app/scripts/ansible/roles/nginx_geoip/tasks/main.yml +++ b/app/scripts/ansible/roles/nginx_geoip/tasks/main.yml @@ -1,16 +1,12 @@ --- -- name: Set SSH port - set_fact: - ansible_port: "{{SSH_PORT}}" - - name: Creates directory file: - path: "{{nginx_dir}}/geoip" + path: "{{service_dir}}/geoip" state: directory - name: Creates directory file: - path: "{{nginx_dir}}/scripts" + path: "{{service_dir}}/scripts" state: directory - name: Install wget @@ -27,17 +23,17 @@ - name: Copy GeoIP script in place. template: src: geoip.sh.j2 - dest: "{{nginx_dir}}/scripts/geoip.sh" + dest: "{{service_dir}}/scripts/geoip.sh" mode: 0777 - name: Execute the script - command: "{{nginx_dir}}/scripts/geoip.sh" + command: "{{service_dir}}/scripts/geoip.sh" - name: Update geoip every Wednesday cron: - name: "Update geoip" + name: "Update NGINX geoip" minute: "0" hour: "01" weekday: "3" - job: "{{nginx_dir}}/scripts/geoip.sh" + job: "{{service_dir}}/scripts/geoip.sh" when: UPDATE == "1" diff --git a/app/scripts/ansible/roles/nginx_geoip/templates/geoip.sh.j2 b/app/scripts/ansible/roles/nginx_geoip/templates/geoip.sh.j2 index 1061c64e..48f0b38f 100644 --- a/app/scripts/ansible/roles/nginx_geoip/templates/geoip.sh.j2 +++ b/app/scripts/ansible/roles/nginx_geoip/templates/geoip.sh.j2 @@ -1,9 +1,9 @@ #!/bin/bash -cd {{nginx_dir}}/scripts +cd {{service_dir}}/scripts git clone https://github.com/sherpya/geolite2legacy.git || true cd geolite2legacy wget "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key={{maxmind_key}}&suffix=zip" -qO geoip2Country.zip python3 geolite2legacy.py -i geoip2Country.zip -o GeoIP.dat -mv GeoIP.dat {{nginx_dir}}/geoip/ +mv GeoIP.dat {{service_dir}}/geoip/ diff --git a/app/scripts/install_grafana.sh b/app/scripts/install_grafana.sh deleted file mode 100644 index 6083a1c9..00000000 --- a/app/scripts/install_grafana.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -for ARGUMENT in "$@" -do - KEY=$(echo $ARGUMENT | cut -f1 -d=) - VALUE=$(echo $ARGUMENT | cut -f2 -d=) - - case "$KEY" in - PROXY) PROXY=${VALUE} ;; - *) - esac -done - -if [ ! -d "/var/www/haproxy-wi/app/scripts/ansible/roles/cloudalchemy.grafana" ]; then - if [ ! -z $PROXY ];then - export https_proxy="$PROXY" - export http_proxy="$PROXY" - fi - ansible-galaxy install cloudalchemy.grafana --roles-path /var/www/haproxy-wi/app/scripts/ansible/roles/ -fi - -if [ ! -d "/var/www/haproxy-wi/app/scripts/ansible/roles/cloudalchemy.prometheus" ]; then - if [ ! -z $PROXY ];then - export https_proxy="$PROXY" - export http_proxy="$PROXY" - fi - ansible-galaxy install cloudalchemy.prometheus --roles-path /var/www/haproxy-wi/app/scripts/ansible/roles/ -fi - -export ANSIBLE_HOST_KEY_CHECKING=False -export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False -export ACTION_WARNINGS=False -export LOCALHOST_WARNING=False -export COMMAND_WARNINGS=False - -PWD=/var/www/haproxy-wi/app/scripts/ansible/ - -ansible-playbook $PWD/roles/grafana.yml -e "PROXY=$PROXY" - -if [ $? -gt 0 ] -then - echo "error: Can't install Grafana and Prometheus services

" - exit 1 -fi -if ! sudo grep -Fxq " - job_name: proxy" /etc/prometheus/prometheus.yml; then - sudo echo " - job_name: proxy" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null - sudo echo " metrics_path: /metrics" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null - sudo echo " static_configs:" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null - sudo echo " - targets:" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null -fi diff --git a/app/scripts/install_haproxy_geoip.sh b/app/scripts/install_haproxy_geoip.sh deleted file mode 100644 index c9b066a0..00000000 --- a/app/scripts/install_haproxy_geoip.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -for ARGUMENT in "$@" -do - KEY=$(echo "$ARGUMENT" | cut -f1 -d=) - VALUE=$(echo "$ARGUMENT" | cut -f2 -d=) - - case "$KEY" in - PROXY) PROXY=${VALUE} ;; - UPDATE) UPDATE=${VALUE} ;; - maxmind_key) maxmind_key=${VALUE} ;; - service_dir) service_dir=${VALUE} ;; - HOST) HOST=${VALUE} ;; - USER) USER=${VALUE} ;; - PASS) PASS=${VALUE} ;; - KEY) KEY=${VALUE} ;; - SSH_PORT) SSH_PORT=${VALUE} ;; - *) - esac -done - -export ANSIBLE_HOST_KEY_CHECKING=False -export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False -export ACTION_WARNINGS=False -export LOCALHOST_WARNING=False -export COMMAND_WARNINGS=False - -PWD=/var/www/haproxy-wi/app/scripts/ansible/ -echo "$HOST ansible_port=$SSH_PORT" > $PWD/$HOST - -if [[ $maxmind_key == "" ]]; then - echo "error: the Maxmind key cannot be empty" - rm -f $PWD/$HOST - exit 1 -fi - -if [[ $KEY == "" ]]; then - ansible-playbook $PWD/roles/geoip.yml -e "ansible_user=$USER ansible_ssh_pass='$PASS' variable_host=$HOST PROXY=$PROXY UPDATE=$UPDATE haproxy_dir=$service_dir maxmind_key=$maxmind_key SSH_PORT=$SSH_PORT" -i $PWD/$HOST -else - ansible-playbook $PWD/roles/geoip.yml --key-file $KEY -e "ansible_user=$USER variable_host=$HOST PROXY=$PROXY UPDATE=$UPDATE haproxy_dir=$service_dir maxmind_key=$maxmind_key SSH_PORT=$SSH_PORT" -i $PWD/$HOST -fi - -if [ $? -gt 0 ] -then - echo "error: Cannot download GeoLite2 database" - rm -f $PWD/$HOST - exit 1 -fi -rm -f $PWD/$HOST diff --git a/app/scripts/install_nginx_geoip.sh b/app/scripts/install_nginx_geoip.sh deleted file mode 100644 index fbb0a05f..00000000 --- a/app/scripts/install_nginx_geoip.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -for ARGUMENT in "$@" -do - KEY=$(echo "$ARGUMENT" | cut -f1 -d=) - VALUE=$(echo "$ARGUMENT" | cut -f2 -d=) - - case "$KEY" in - PROXY) PROXY=${VALUE} ;; - UPDATE) UPDATE=${VALUE} ;; - maxmind_key) maxmind_key=${VALUE} ;; - service_dir) service_dir=${VALUE} ;; - HOST) HOST=${VALUE} ;; - USER) USER=${VALUE} ;; - PASS) PASS=${VALUE} ;; - KEY) KEY=${VALUE} ;; - SSH_PORT) SSH_PORT=${VALUE} ;; - *) - esac -done - -export ANSIBLE_HOST_KEY_CHECKING=False -export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False -export ACTION_WARNINGS=False -export LOCALHOST_WARNING=False -export COMMAND_WARNINGS=False - -PWD=/var/www/haproxy-wi/app/scripts/ansible/ -echo "$HOST ansible_port=$SSH_PORT" > $PWD/$HOST - -if [[ $maxmind_key == "" ]]; then - echo "error: the Maxmind key cannot be empty" - rm -f $PWD/$HOST - exit 1 -fi - -if [[ $KEY == "" ]]; then - ansible-playbook $PWD/roles/nginx_geoip.yml -e "ansible_user=$USER ansible_ssh_pass='$PASS' variable_host=$HOST PROXY=$PROXY UPDATE=$UPDATE nginx_dir=$service_dir maxmind_key=$maxmind_key SSH_PORT=$SSH_PORT" -i $PWD/$HOST -else - ansible-playbook $PWD/roles/nginx_geoip.yml --key-file $KEY -e "ansible_user=$USER variable_host=$HOST PROXY=$PROXY UPDATE=$UPDATE nginx_dir=$service_dir maxmind_key=$maxmind_key SSH_PORT=$SSH_PORT" -i $PWD/$HOST -fi - -if [ $? -gt 0 ] -then - echo "error: Cannot download GeoLite2 database" - rm -f $PWD/$HOST - exit 1 -fi -rm -f $PWD/$HOST diff --git a/app/static/js/install.js b/app/static/js/install.js index 9503e3f0..439083ab 100644 --- a/app/static/js/install.js +++ b/app/static/js/install.js @@ -1,117 +1,32 @@ $( function() { - $('#install').click(function () { - installService('haproxy') - }); - $('#nginx_install').click(function () { - installService('nginx'); - }); - $('#apache_install').click(function () { - installService('apache'); - }); - $('#grafana_install').click(function () { - $("#ajaxmon").html(''); - $("#ajaxmon").html(wait_mess); - $.ajax({ - url: "/app/install/grafana", - // data: { - // token: $('#token').val() - // }, - // type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - $("#ajaxmon").html(''); - if (data.indexOf('FAILED') != '-1' || data.indexOf('UNREACHABLE') != '-1' || data.indexOf('ERROR') != '-1') { - toastr.clear(); - var p_err = show_pretty_ansible_error(data); - toastr.error(p_err); - } else if (data.indexOf('success') != '-1') { - toastr.clear(); - toastr.success(data); - } else if (data.indexOf('Info') != '-1') { - toastr.clear(); - toastr.info(data); - } else { - toastr.clear(); - toastr.info(data); - } - } - }); - }); - $('#haproxy_exp_install').click(function () { - installExporter('haproxy'); - }); - $('#nginx_exp_install').click(function () { - installExporter('nginx'); - }); - $('#apache_exp_install').click(function () { - installExporter('apache'); - }); - $('#keepalived_exp_install').click(function () { - installExporter('keepalived'); - }); - $('#node_exp_install').click(function () { - installExporter('node'); - }); - $("#haproxyaddserv").on('selectmenuchange', function () { - showServiceVersion('haproxy'); - }); - $("#nginxaddserv").on('selectmenuchange', function () { - showServiceVersion('nginx'); - }); - $("#apacheaddserv").on('selectmenuchange', function () { - showServiceVersion('apache'); - }); - $("#haproxy_exp_addserv").on('selectmenuchange', function () { - showExporterVersion('haproxy'); - }); - $("#nginx_exp_addserv").on('selectmenuchange', function () { - showExporterVersion('nginx'); - }); - $("#apache_exp_addserv").on('selectmenuchange', function () { - showExporterVersion('apache'); - }); - $("#keepalived_exp_addserv").on('selectmenuchange', function () { - showExporterVersion('keepalived'); - }); - $("#node_exp_addserv").on('selectmenuchange', function () { - showExporterVersion('node'); - }); - $( "#geoipserv" ).on('selectmenuchange',function() { - if($('#geoip_service option:selected').val() != '------') { - checkGeoipInstallation(); - } + $('#install').click(function () { + installService('haproxy') }); - $( "#geoip_service" ).on('selectmenuchange',function() { - if($('#geoipserv option:selected').val() != '------') { - checkGeoipInstallation(); - } + $('#nginx_install').click(function () { + installService('nginx'); }); - $( "#geoip_install" ).click(function() { - var updating_geoip = 0; - if ($('#updating_geoip').is(':checked')) { - updating_geoip = '1'; - } - $("#ajax-geoip").html(wait_mess); + $('#apache_install').click(function () { + installService('apache'); + }); + $('#grafana_install').click(function () { + $("#ajaxmon").html(''); + $("#ajaxmon").html(wait_mess); $.ajax({ - url: "/app/install/geoip", - data: { - server_ip: $('#geoipserv option:selected').val(), - service: $('#geoip_service option:selected').val(), - update: updating_geoip, - token: $('#token').val() - }, - type: "POST", + url: "/app/install/grafana", + // data: { + // token: $('#token').val() + // }, + // type: "POST", success: function (data) { - data = data.replace(/^\s+|\s+$/g, ''); - $("#ajax-geoip").html('') - if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') { + data = data.replace(/\s+/g, ' '); + $("#ajaxmon").html(''); + if (data.indexOf('FAILED') != '-1' || data.indexOf('UNREACHABLE') != '-1' || data.indexOf('ERROR') != '-1') { toastr.clear(); var p_err = show_pretty_ansible_error(data); toastr.error(p_err); - } else if (data.indexOf('success:') != '-1') { + } else if (data.indexOf('success') != '-1') { toastr.clear(); toastr.success(data); - $("#geoip_service").trigger("selectmenuchange"); } else if (data.indexOf('Info') != '-1') { toastr.clear(); toastr.info(data); @@ -122,6 +37,84 @@ $( function() { } }); }); + $('#haproxy_exp_install').click(function () { + installExporter('haproxy'); + }); + $('#nginx_exp_install').click(function () { + installExporter('nginx'); + }); + $('#apache_exp_install').click(function () { + installExporter('apache'); + }); + $('#keepalived_exp_install').click(function () { + installExporter('keepalived'); + }); + $('#node_exp_install').click(function () { + installExporter('node'); + }); + $("#haproxyaddserv").on('selectmenuchange', function () { + showServiceVersion('haproxy'); + }); + $("#nginxaddserv").on('selectmenuchange', function () { + showServiceVersion('nginx'); + }); + $("#apacheaddserv").on('selectmenuchange', function () { + showServiceVersion('apache'); + }); + $("#haproxy_exp_addserv").on('selectmenuchange', function () { + showExporterVersion('haproxy'); + }); + $("#nginx_exp_addserv").on('selectmenuchange', function () { + showExporterVersion('nginx'); + }); + $("#apache_exp_addserv").on('selectmenuchange', function () { + showExporterVersion('apache'); + }); + $("#keepalived_exp_addserv").on('selectmenuchange', function () { + showExporterVersion('keepalived'); + }); + $("#node_exp_addserv").on('selectmenuchange', function () { + showExporterVersion('node'); + }); + $("#geoipserv").on('selectmenuchange', function () { + if ($('#geoip_service option:selected').val() != '------') { + checkGeoipInstallation(); + } + }); + $("#geoip_service").on('selectmenuchange', function () { + if ($('#geoipserv option:selected').val() != '------') { + checkGeoipInstallation(); + } + }); + $("#geoip_install").click(function () { + var updating_geoip = 0; + if ($('#updating_geoip').is(':checked')) { + updating_geoip = '1'; + } + $("#ajax-geoip").html(wait_mess); + let service = $('#geoip_service option:selected').val(); + $.ajax({ + url: "/app/install/geoip", + data: { + server_ip: $('#geoipserv option:selected').val(), + service: service, + update: updating_geoip, + token: $('#token').val() + }, + type: "POST", + success: function (data) { + $("#ajax-geoip").html(''); + try { + if (data.indexOf('error:') != '-1') { + toastr.error(data); + } + } catch (e) { + parseAnsibleJsonOutput(data, service + ' GeoIP', '#geoip_service'); + $("#geoip_service").trigger("selectmenuchange"); + } + } + }); + }); }); function checkGeoipInstallation() { $.ajax( {