diff --git a/app/__init__.py b/app/__init__.py index cb244acd..e8f545d1 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -28,6 +28,7 @@ from app.routes.metric import bp as metric_bp from app.routes.waf import bp as waf_bp from app.routes.runtime import bp as runtime_bp from app.routes.smon import bp as smon_bp +from app.routes.channel import bp as channel_bp from app.routes.checker import bp as checker_bp from app.routes.portscanner import bp as portscanner_bp from app.routes.install import bp as install_bp @@ -47,6 +48,7 @@ app.register_blueprint(waf_bp, url_prefix='/waf') app.register_blueprint(runtime_bp, url_prefix='/runtimeapi') app.register_blueprint(smon_bp, url_prefix='/smon') app.register_blueprint(checker_bp, url_prefix='/checker') +app.register_blueprint(channel_bp, url_prefix='/channel') app.register_blueprint(portscanner_bp, url_prefix='/portscanner') app.register_blueprint(install_bp, url_prefix='/install') app.register_blueprint(user_bp, url_prefix='/user') diff --git a/app/modules/server/server.py b/app/modules/server/server.py index 318bb27d..74b6ced2 100644 --- a/app/modules/server/server.py +++ b/app/modules/server/server.py @@ -59,7 +59,6 @@ def subprocess_execute(cmd): p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True) stdout, stderr = p.communicate() output = stdout.splitlines() - return output, stderr diff --git a/app/modules/service/installation.py b/app/modules/service/installation.py index 0c0893af..0f2f8317 100644 --- a/app/modules/service/installation.py +++ b/app/modules/service/installation.py @@ -1,7 +1,9 @@ import os import json +from packaging import version from flask import render_template +import ansible import ansible_runner import app.modules.db.sql as sql @@ -374,6 +376,7 @@ def run_ansible(inv: dict, server_ips: str, ansible_role: str) -> object: 'AWX_DISPLAY': False, 'SSH_AUTH_PID': agent_pid['pid'], 'SSH_AUTH_SOCK': agent_pid['socket'], + 'ANSIBLE_PYTHON_INTERPRETER': '/usr/bin/python3' } kwargs = { 'private_data_dir': '/var/www/haproxy-wi/app/scripts/ansible/', @@ -461,12 +464,15 @@ def install_service(service: str, json_data: str) -> object: def _install_ansible_collections(): + old_ansible_server = '' collections = ('community.general', 'ansible.posix', 'community.docker') trouble_link = 'Read troubleshooting' for collection in collections: if not os.path.isdir(f'/usr/share/httpd/.ansible/collections/ansible_collections/{collection.replace(".", "/")}'): try: - exit_code = os.system(f'ansible-galaxy collection install {collection}') + if version.parse(ansible.__version__) < version.parse('2.13.9'): + old_ansible_server = '--server https://old-galaxy.ansible.com/' + exit_code = os.system(f'ansible-galaxy collection install {collection} {old_ansible_server}') except Exception as e: roxywi_common.handle_exceptions(e, 'Roxy-WI server', diff --git a/app/modules/tools/alerting.py b/app/modules/tools/alerting.py index 25cc63eb..a7ee6ef2 100644 --- a/app/modules/tools/alerting.py +++ b/app/modules/tools/alerting.py @@ -1,7 +1,7 @@ import json import pika -from flask import render_template, request +from flask import render_template, request, abort import app.modules.db.sql as sql import app.modules.db.user as user_sql @@ -433,3 +433,34 @@ def check_receiver(channel_id: int, receiver_name: str) -> str: return functions[receiver_name](mess, level, channel_id=channel_id) except Exception as e: return f'error: Cannot send message: {e}' + + +def load_channels(): + try: + user_subscription = roxywi_common.return_user_status() + except Exception as e: + user_subscription = roxywi_common.return_unsubscribed_user_status() + roxywi_common.logging('Roxy-WI server', f'Cannot get a user plan: {e}', roxywi=1) + + try: + user_params = roxywi_common.get_users_params() + except Exception: + abort(403) + + kwargs = { + 'user_subscription': user_subscription, + 'user_params': user_params, + 'lang': user_params['lang'] + } + + if user_subscription['user_status']: + user_group = roxywi_common.get_user_group(id=1) + kwargs.setdefault('telegrams', channel_sql.get_user_telegram_by_group(user_group)) + kwargs.setdefault('pds', channel_sql.get_user_pd_by_group(user_group)) + kwargs.setdefault('groups', group_sql.select_groups()) + kwargs.setdefault('slacks', channel_sql.get_user_slack_by_group(user_group)) + kwargs.setdefault('user_subscription', user_subscription) + kwargs.setdefault('user_params', user_params) + kwargs.setdefault('lang', user_params['lang']) + + return render_template('ajax/channels.html', **kwargs) diff --git a/app/routes/admin/routes.py b/app/routes/admin/routes.py index 8150826e..5b4d2f56 100644 --- a/app/routes/admin/routes.py +++ b/app/routes/admin/routes.py @@ -11,7 +11,6 @@ import app.modules.db.sql as sql import app.modules.db.cred as cred_sql import app.modules.db.user as user_sql import app.modules.db.group as group_sql -import app.modules.db.backup as backup_sql import app.modules.db.server as server_sql import app.modules.db.service as service_sql from app.middleware import get_user_params @@ -34,10 +33,6 @@ def before_request(): @get_user_params() def admin(): roxywi_auth.page_for_admin() - grafana = 0 - - if not roxy.is_docker(): - grafana = tools_common.is_tool_active('grafana-server') kwargs = { 'lang': g.user_params['lang'], @@ -50,12 +45,7 @@ def admin(): 'settings': sql.get_setting('', all=1), 'ldap_enable': sql.get_setting('ldap_enable'), 'services': service_sql.select_services(), - 'gits': backup_sql.select_gits(), 'masters': server_sql.select_servers(get_master_servers=1), - 'is_needed_tool': common.is_tool('ansible'), - 'grafana': grafana, - 'backups': backup_sql.select_backups(), - 's3_backups': backup_sql.select_s3_backups(), 'guide_me': 1, 'user_subscription': roxywi_common.return_user_subscription() } diff --git a/app/routes/channel/__init__.py b/app/routes/channel/__init__.py new file mode 100644 index 00000000..189d7011 --- /dev/null +++ b/app/routes/channel/__init__.py @@ -0,0 +1,5 @@ +from flask import Blueprint + +bp = Blueprint('channel', __name__) + +from app.routes.channel import routes diff --git a/app/routes/channel/routes.py b/app/routes/channel/routes.py new file mode 100644 index 00000000..e805e56f --- /dev/null +++ b/app/routes/channel/routes.py @@ -0,0 +1,73 @@ +from flask import request, render_template +from flask_login import login_required + +from app.routes.channel import bp +from app.middleware import get_user_params +import app.modules.common.common as common +import app.modules.tools.alerting as alerting +import app.modules.roxywi.common as roxywi_common + + +@bp.before_request +@login_required +def before_request(): + """ Protect all the admin endpoints. """ + pass + + +@bp.route('') +@get_user_params() +def channels(): + roxywi_common.check_user_group_for_flask() + + return render_template('channel.html') + + +@bp.route('/load') +@get_user_params() +def load_channels(): + try: + return alerting.load_channels() + except Exception as e: + return f'{e}' + + +@bp.route('/check//') +def check_receiver(channel_id, receiver_name): + channel_id = common.checkAjaxInput(channel_id) + receiver_name = common.checkAjaxInput(receiver_name) + + return alerting.check_receiver(channel_id, receiver_name) + + +@bp.route('/check/rabbit') +def check_rabbit(): + return alerting.check_rabbit_alert() + + +@bp.route('/check/email') +def check_email(): + return alerting.check_email_alert() + + +@bp.route('/receiver/', methods=['PUT', 'POST', 'DELETE']) +def receiver(receiver_name): + if request.method == 'POST': + token = common.checkAjaxInput(request.form.get('receiver')) + channel = common.checkAjaxInput(request.form.get('channel')) + group = common.checkAjaxInput(request.form.get('group')) + page = common.checkAjaxInput(request.form.get('page')) + page = page.split("#")[0] + + return alerting.add_receiver_channel(receiver_name, token, channel, group, page) + elif request.method == 'PUT': + token = common.checkAjaxInput(request.form.get('receiver_token')) + channel = common.checkAjaxInput(request.form.get('channel')) + group = common.checkAjaxInput(request.form.get('group')) + user_id = common.checkAjaxInput(request.form.get('id')) + + return alerting.update_receiver_channel(receiver_name, token, channel, group, user_id) + elif request.method == 'DELETE': + channel_id = common.checkAjaxInput(request.form.get('channel_id')) + + return alerting.delete_receiver_channel(channel_id, receiver_name) diff --git a/app/routes/checker/routes.py b/app/routes/checker/routes.py index c261feb5..ce343049 100644 --- a/app/routes/checker/routes.py +++ b/app/routes/checker/routes.py @@ -3,11 +3,8 @@ from flask_login import login_required from app.routes.checker import bp from app.middleware import get_user_params -import app.modules.db.sql as sql import app.modules.db.history as history_sql -import app.modules.common.common as common import app.modules.roxywi.common as roxywi_common -import app.modules.tools.alerting as alerting import app.modules.tools.checker as checker_mod @@ -67,44 +64,3 @@ def checker_history(): } return render_template('smon/checker_history.html', **kwargs) - - -@bp.route('/check//') -def check_receiver(channel_id, receiver_name): - channel_id = common.checkAjaxInput(channel_id) - receiver_name = common.checkAjaxInput(receiver_name) - - return alerting.check_receiver(channel_id, receiver_name) - - -@bp.route('/check/rabbit') -def check_rabbit(): - return alerting.check_rabbit_alert() - - -@bp.route('/check/email') -def check_email(): - return alerting.check_email_alert() - - -@bp.route('/receiver/', methods=['PUT', 'POST', 'DELETE']) -def receiver(receiver_name): - if request.method == 'POST': - token = common.checkAjaxInput(request.form.get('receiver')) - channel = common.checkAjaxInput(request.form.get('channel')) - group = common.checkAjaxInput(request.form.get('group')) - page = common.checkAjaxInput(request.form.get('page')) - page = page.split("#")[0] - - return alerting.add_receiver_channel(receiver_name, token, channel, group, page) - elif request.method == 'PUT': - token = common.checkAjaxInput(request.form.get('receiver_token')) - channel = common.checkAjaxInput(request.form.get('channel')) - group = common.checkAjaxInput(request.form.get('group')) - user_id = common.checkAjaxInput(request.form.get('id')) - - return alerting.update_receiver_channel(receiver_name, token, channel, group, user_id) - elif request.method == 'DELETE': - channel_id = common.checkAjaxInput(request.form.get('channel_id')) - - return alerting.delete_receiver_channel(channel_id, receiver_name) diff --git a/app/routes/main/routes.py b/app/routes/main/routes.py index bf7282da..6ce22a12 100644 --- a/app/routes/main/routes.py +++ b/app/routes/main/routes.py @@ -13,7 +13,6 @@ import app.modules.db.sql as sql import app.modules.db.cred as cred_sql import app.modules.db.user as user_sql import app.modules.db.group as group_sql -import app.modules.db.backup as backup_sql import app.modules.db.server as server_sql import app.modules.db.service as service_sql import app.modules.db.history as history_sql @@ -188,12 +187,8 @@ def servers(): 'timezones': pytz.all_timezones, 'guide_me': 1, 'settings': sql.get_setting('', all=1), - 'backups': backup_sql.select_backups(), - 's3_backups': backup_sql.select_s3_backups(), 'page': 'servers.py', 'ldap_enable': sql.get_setting('ldap_enable'), - 'gits': backup_sql.select_gits(), - 'is_needed_tool': common.is_tool('ansible'), 'user_roles': user_sql.select_user_roles_by_group(user_group), 'user_subscription': roxywi_common.return_user_subscription(), 'lang': g.user_params['lang'] diff --git a/app/routes/server/routes.py b/app/routes/server/routes.py index f52b5c31..0d1a7dc7 100644 --- a/app/routes/server/routes.py +++ b/app/routes/server/routes.py @@ -1,12 +1,13 @@ import json -from flask import render_template, request +from flask import render_template, request, g from flask_login import login_required from app.routes.server import bp import app.modules.db.cred as cred_sql import app.modules.db.group as group_sql import app.modules.db.server as server_sql +import app.modules.db.backup as backup_sql import app.modules.common.common as common import app.modules.roxywi.group as group_mod import app.modules.roxywi.auth as roxywi_auth @@ -15,6 +16,7 @@ import app.modules.server.ssh as ssh_mod import app.modules.server.server as server_mod import app.modules.tools.smon as smon_mod import app.modules.service.backup as backup_mod +from app.middleware import get_user_params error_mess = roxywi_common.return_error_message() @@ -271,6 +273,22 @@ def show_firewall(server_ip): return server_mod.show_firewalld_rules(server_ip) +@bp.route('/backup') +@get_user_params() +def load_backup(): + user_group = g.user_params['group_id'] + kwargs = { + 'sshs': cred_sql.select_ssh(group=user_group), + 'servers': roxywi_common.get_dick_permit(virt=1, disable=0, only_group=1), + 'backups': backup_sql.select_backups(), + 's3_backups': backup_sql.select_s3_backups(), + 'gits': backup_sql.select_gits(), + 'lang': g.user_params['lang'], + 'is_needed_tool': common.is_tool('ansible'), + 'user_subscription': roxywi_common.return_user_subscription(), + } + return render_template('include/admin_backup.html', **kwargs) + @bp.post('/backup/create') @bp.post('/backup/delete') @bp.post('/backup/update') diff --git a/app/routes/smon/routes.py b/app/routes/smon/routes.py index 56fc3c70..8220224d 100644 --- a/app/routes/smon/routes.py +++ b/app/routes/smon/routes.py @@ -347,6 +347,8 @@ def smon_host_history(server_ip): roxywi_common.check_user_group_for_flask() needed_host = common.checkAjaxInput(server_ip) + if ' ' in needed_host: + needed_host = f"'{needed_host}'" smon_status = tools_common.is_tool_active('roxy-wi-smon') smon = history_sql.alerts_history('SMON', g.user_params['group_id'], host=needed_host) user_subscription = roxywi_common.return_user_subscription() diff --git a/app/static/css/awesome-6.3.9.css b/app/static/css/awesome-6.3.9.css index e14f5780..afa6f3a8 100644 --- a/app/static/css/awesome-6.3.9.css +++ b/app/static/css/awesome-6.3.9.css @@ -466,3 +466,8 @@ margin: 8px 5px 10px var(--indent); font-size: 15px; } +.channel::before { + display: none; + font-family: "Font Awesome 5 Regular"; + content: "\f086"; +} diff --git a/app/static/js/backup.js b/app/static/js/backup.js new file mode 100644 index 00000000..a6740cfb --- /dev/null +++ b/app/static/js/backup.js @@ -0,0 +1,441 @@ +$( function() { + $("#backup_tabs").tabs(); + $('#add-backup-button').click(function() { + addBackupDialog.dialog('open'); + }); + var backup_tabel_title = $( "#backup-add-table-overview" ).attr('title'); + var addBackupDialog = $( "#backup-add-table" ).dialog({ + autoOpen: false, + resizable: false, + height: "auto", + width: 600, + modal: true, + title: backup_tabel_title, + show: { + effect: "fade", + duration: 200 + }, + hide: { + effect: "fade", + duration: 200 + }, + buttons: { + "Add": function () { + addBackup(this); + }, + Cancel: function () { + $(this).dialog("close"); + clearTips(); + } + } + }); + $('#add-backup-s3-button').click(function() { + addS3BackupDialog.dialog('open'); + }); + var s3_backup_tabel_title = $( "#s3-backup-add-table-overview" ).attr('title'); + var addS3BackupDialog = $( "#s3-backup-add-table" ).dialog({ + autoOpen: false, + resizable: false, + height: "auto", + width: 600, + modal: true, + title: s3_backup_tabel_title, + show: { + effect: "fade", + duration: 200 + }, + hide: { + effect: "fade", + duration: 200 + }, + buttons: { + "Add": function () { + addS3Backup(this); + }, + Cancel: function () { + $(this).dialog("close"); + clearTips(); + } + } + }); + $('#add-git-button').click(function() { + addGitDialog.dialog('open'); + }); + var git_tabel_title = $( "#git-add-table-overview" ).attr('title'); + var addGitDialog = $( "#git-add-table" ).dialog({ + autoOpen: false, + resizable: false, + height: "auto", + width: 600, + modal: true, + title: git_tabel_title, + show: { + effect: "fade", + duration: 200 + }, + hide: { + effect: "fade", + duration: 200 + }, + buttons: { + "Add": function () { + addGit(this); + }, + Cancel: function () { + $(this).dialog("close"); + clearTips(); + } + } + }); + $('#git-init').click(function() { + if ($('#git-init').is(':checked')) { + $('.git-init-params').show(); + } else { + $('.git-init-params').hide(); + } + }); + $( "#ajax-backup-table input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateBackup(id[2]) + }); + $( "#ajax-backup-table select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateBackup(id[2]) + }); + $("#backup_tabs ul li").click(function() { + $('.menu li ul li').each(function () { + $(this).find('a').css('border-left', '0px solid var(--right-menu-blue-rolor)'); + $(this).find('a').css('padding-left', '20px') + $(this).children(".backup").css('padding-left', '30px'); + $(this).children(".backup").css('border-left', '4px solid var(--right-menu-blue-rolor)'); + }); + }); +}); +function loadBackup() { + $.ajax({ + url: "/app/server/backup", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('danger') != '-1' || data.indexOf('unique') != '-1' || data.indexOf('error:') != '-1') { + toastr.error(data); + } else { + $('#backup').html(data); + $.getScript('/app/static/js/backup.js'); + $("select").selectmenu(); + $.getScript(awesome); + } + } + }); +} +function addBackup(dialog_id) { + var valid = true; + toastr.clear(); + let allFields = $([]).add($('#backup-server')).add($('#rserver')).add($('#rpath')).add($('#backup-time')).add($('#backup-credentials')); + allFields.removeClass("ui-state-error"); + valid = valid && checkLength($('#backup-server'), "backup server ", 1); + valid = valid && checkLength($('#rserver'), "remote server", 1); + valid = valid && checkLength($('#rpath'), "remote path", 1); + valid = valid && checkLength($('#backup-time'), "backup time", 1); + valid = valid && checkLength($('#backup-credentials'), "backup credentials", 1); + if (valid) { + $.ajax({ + url: "/app/server/backup/create", + data: { + server: $('#backup-server').val(), + rserver: $('#rserver').val(), + rpath: $('#rpath').val(), + type: $('#backup-type').val(), + time: $('#backup-time').val(), + cred: $('#backup-credentials').val(), + description: $('#backup-description').val(), + token: $('#token').val() + }, + type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('error:') != '-1') { + toastr.error(data); + } else if (data.indexOf('info: ') != '-1') { + toastr.clear(); + toastr.info(data); + } else if (data.indexOf('warning: ') != '-1') { + toastr.clear(); + toastr.warning(data); + } else { + common_ajax_action_after_success(dialog_id, 'newbackup', 'ajax-backup-table', data); + $("select").selectmenu(); + } + } + }); + } +} +function addS3Backup(dialog_id) { + var valid = true; + toastr.clear(); + allFields = $([]).add($('#s3-backup-server')).add($('#s3_server')).add($('#s3_bucket')).add($('#s3_secret_key')).add($('#s3_access_key')) + allFields.removeClass("ui-state-error"); + valid = valid && checkLength($('#s3-backup-server'), "backup server ", 1); + valid = valid && checkLength($('#s3_server'), "S3 server", 1); + valid = valid && checkLength($('#s3_bucket'), "S3 bucket", 1); + valid = valid && checkLength($('#s3_secret_key'), "S3 secret key", 1); + valid = valid && checkLength($('#s3_access_key'), "S3 access key", 1); + if (valid) { + $.ajax({ + url: "/app/server/s3backup/create", + data: { + s3_backup_server: $('#s3-backup-server').val(), + s3_server: $('#s3_server').val(), + s3_bucket: $('#s3_bucket').val(), + s3_secret_key: $('#s3_secret_key').val(), + s3_access_key: $('#s3_access_key').val(), + time: $('#s3-backup-time').val(), + description: $('#s3-backup-description').val(), + token: $('#token').val() + }, + type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('error:') != '-1') { + toastr.error(data); + } else if (data.indexOf('info: ') != '-1') { + toastr.clear(); + toastr.info(data); + } else if (data.indexOf('warning: ') != '-1') { + toastr.clear(); + toastr.warning(data); + } else if (data.indexOf('error: ') != '-1') { + toastr.clear(); + toastr.error(data); + } else { + common_ajax_action_after_success(dialog_id, 'newbackup', 'ajax-backup-s3-table', data); + $("select").selectmenu(); + } + } + }); + } +} +function addGit(dialog_id) { + var valid = true; + toastr.clear(); + allFields = $([]).add($('#git-server')).add($('#git-service')).add($('#git-time')).add($('#git-credentials')).add($('#git-branch')) + allFields.removeClass("ui-state-error"); + valid = valid && checkLength($('#git-server'), "Server ", 1); + valid = valid && checkLength($('#git-service'), "Service", 1); + valid = valid && checkLength($('#git-credentials'), "Credentials", 1); + valid = valid && checkLength($('#git-branch'), "Branch name", 1); + var git_init = 0; + if ($('#git-init').is(':checked')) { + git_init = '1'; + } + if (valid) { + $.ajax({ + url: "/app/server/git/create", + data: { + server: $('#git-server').val(), + git_service: $('#git-service').val(), + git_init: git_init, + git_repo: $('#git-repo').val(), + git_branch: $('#git-branch').val(), + time: $('#git-time').val(), + cred: $('#git-credentials').val(), + description: $('#git-description').val(), + git_deljob: 0, + token: $('#token').val() + }, + type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('error:') != '-1') { + toastr.error(data); + } else if (data.indexOf('success: ') != '-1') { + common_ajax_action_after_success(dialog_id, 'newgit', 'ajax-git-table', data); + $("select").selectmenu(); + } else if (data.indexOf('info: ') != '-1') { + toastr.clear(); + toastr.info(data); + } else if (data.indexOf('warning: ') != '-1') { + toastr.clear(); + toastr.warning(data); + } + } + }); + } +} +function confirmDeleteBackup(id) { + $("#dialog-confirm").dialog({ + resizable: false, + height: "auto", + width: 400, + modal: true, + title: delete_word + " " + $('#backup-server-' + id).val() + "?", + buttons: [{ + text: delete_word, + click: function () { + $(this).dialog("close"); + removeBackup(id); + } + }, { + text: cancel_word, + click: function () { + $(this).dialog("close"); + } + }] + }); +} +function confirmDeleteS3Backup(id) { + $("#dialog-confirm").dialog({ + resizable: false, + height: "auto", + width: 400, + modal: true, + title: delete_word + " " + $('#backup-s3-server-' + id).val() + "?", + buttons: [{ + text: delete_word, + click: function () { + $(this).dialog("close"); + removeS3Backup(id); + } + }, { + text: cancel_word, + click: function () { + $(this).dialog("close"); + } + }] + }); +} +function confirmDeleteGit(id) { + $("#dialog-confirm").dialog({ + resizable: false, + height: "auto", + width: 400, + modal: true, + title: delete_word + " " + $('#git-server-' + id).text() + "?", + buttons: [{ + text: delete_word, + click: function () { + $(this).dialog("close"); + removeGit(id); + } + }, { + text: cancel_word, + click: function () { + $(this).dialog("close"); + } + }] + }); +} +function cloneBackup(id) { + $( "#add-backup-button" ).trigger( "click" ); + $('#rserver').val($('#backup-rserver-'+id).val()) + $('#rpath').val($('#backup-rpath-'+id).val()) + $('#backup-type').val($('#backup-type-'+id+' option:selected').val()).change() + $('#backup-type').selectmenu("refresh"); + $('#backup-time').val($('#backup-time-'+id+' option:selected').val()).change() + $('#backup-time').selectmenu("refresh"); + $('#backup-credentials').val($('#backup-credentials-'+id+' option:selected').val()).change() + $('#backup-credentials').selectmenu("refresh"); +} +function removeBackup(id) { + $("#backup-table-" + id).css("background-color", "#f2dede"); + $.ajax({ + url: "/app/server/backup/delete", + data: { + deljob: id, + cred: $('#backup-credentials-' + id).val(), + server: $('#backup-server-' + id).text(), + rserver: $('#backup-rserver-' + id).val(), + token: $('#token').val() + }, + type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('ok') != '-1') { + $("#backup-table-" + id).remove(); + } else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { + toastr.error(data); + } + } + }); +} +function removeS3Backup(id) { + $("#backup-table-s3-" + id).css("background-color", "#f2dede"); + $.ajax({ + url: "/app/server/s3backup/delete", + data: { + dels3job: id, + s3_bucket: $('#bucket-' + id).text(), + s3_backup_server: $('#backup-s3-server-' + id).text(), + token: $('#token').val() + }, + type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('ok') != '-1') { + $("#s3-backup-table-" + id).remove(); + } else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { + toastr.error(data); + } + } + }); +} +function removeGit(id) { + $("#git-table-" + id).css("background-color", "#f2dede"); + $.ajax({ + url: "/app/server/git/delete", + data: { + git_backup: id, + git_deljob: 1, + git_init: 0, + repo: 0, + branch: 0, + time: 0, + cred: $('#git-credentials-id-' + id).text(), + server: $('#git-server-id-' + id).text(), + git_service: $('#git-service-id-' + id).text(), + token: $('#token').val() + }, + type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('ok') != '-1') { + $("#git-table-" + id).remove(); + } else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { + toastr.error(data); + } + } + }); +} +function updateBackup(id) { + toastr.clear(); + if ($("#backup-type-" + id + " option:selected").val() == "-------" || $('#backup-rserver-' + id).val() == '' || $('#backup-rpath-' + id).val() == '') { + toastr.error('All fields must be completed'); + } else { + $.ajax({ + url: "/app/server/backup/update", + data: { + backupupdate: id, + server: $('#backup-server-' + id).text(), + rserver: $('#backup-rserver-' + id).val(), + rpath: $('#backup-rpath-' + id).val(), + type: $('#backup-type-' + id).val(), + time: $('#backup-time-' + id).val(), + cred: $('#backup-credentials-' + id).val(), + description: $('#backup-description-' + id).val(), + token: $('#token').val() + }, + type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { + toastr.error(data); + } else { + toastr.clear(); + $("#backup-table-" + id).addClass("update", 1000); + setTimeout(function () { + $("#backup-table-" + id).removeClass("update"); + }, 2500); + } + } + }); + } +} diff --git a/app/static/js/channel.js b/app/static/js/channel.js new file mode 100644 index 00000000..36b8b5e3 --- /dev/null +++ b/app/static/js/channel.js @@ -0,0 +1,310 @@ +var awesome = "/inc/fontawesome.min.js"; +var add_word = $('#translate').attr('data-add'); +var delete_word = $('#translate').attr('data-delete'); +var cancel_word = $('#translate').attr('data-cancel'); +var cur_url = window.location.href.split('/app/').pop(); +cur_url = cur_url.split('/'); +$( function() { + $('#add-telegram-button').click(function() { + addTelegramDialog.dialog('open'); + }); + $('#add-slack-button').click(function() { + addSlackDialog.dialog('open'); + }); + $('#add-pd-button').click(function() { + addPDDialog.dialog('open'); + }); + var telegram_tabel_title = $( "#telegram-add-table-overview" ).attr('title'); + var addTelegramDialog = $( "#telegram-add-table" ).dialog({ + autoOpen: false, + resizable: false, + height: "auto", + width: 600, + modal: true, + title: telegram_tabel_title, + show: { + effect: "fade", + duration: 200 + }, + hide: { + effect: "fade", + duration: 200 + }, + buttons: [{ + text: add_word, + click: function () { + addRecevier(this, 'telegram'); + } + }, { + text: cancel_word, + click: function () { + $(this).dialog("close"); + clearTips(); + } + }] + }); + var slack_tabel_title = $( "#slack-add-table-overview" ).attr('title'); + var addSlackDialog = $( "#slack-add-table" ).dialog({ + autoOpen: false, + resizable: false, + height: "auto", + width: 600, + modal: true, + title: slack_tabel_title, + show: { + effect: "fade", + duration: 200 + }, + hide: { + effect: "fade", + duration: 200 + }, + buttons: [{ + text: add_word, + click: function () { + addRecevier(this, 'slack'); + } + }, { + text: cancel_word, + click: function () { + $(this).dialog("close"); + clearTips(); + } + }] + }); + var pd_tabel_title = $( "#pd-add-table-overview" ).attr('title'); + var addPDDialog = $( "#pd-add-table" ).dialog({ + autoOpen: false, + resizable: false, + height: "auto", + width: 600, + modal: true, + title: pd_tabel_title, + show: { + effect: "fade", + duration: 200 + }, + hide: { + effect: "fade", + duration: 200 + }, + buttons: [{ + text: add_word, + click: function () { + addRecevier(this, 'pd'); + } + }, { + text: cancel_word, + click: function () { + $(this).dialog("close"); + clearTips(); + } + }] + }); + $( "#checker_telegram_table input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateReceiver(id[2], 'telegram') + }); + $( "#checker_telegram_table select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateReceiver(id[1], 'telegram') + }); + $( "#checker_slack_table input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateReceiver(id[2], 'slack') + }); + $( "#checker_slack_table select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateReceiver(id[1], 'slack') + }); + $( "#checker_pd_table input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateReceiver(id[2], 'pd') + }); + $( "#checker_pd_table select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateReceiver(id[1], 'pd') + }); +}); +function loadChannel() { + $.ajax({ + url: "/app/channel/load", + type: "GET", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('group_error') == '-1' && data.indexOf('error:') != '-1') { + toastr.error(data); + } else { + $('#checker').html(data); + $( "select" ).selectmenu(); + $("button").button(); + $( "input[type=checkbox]" ).checkboxradio(); + $.getScript('/app/static/js/channel.js'); + $.getScript(awesome); + } + } + } ); +} +function updateReceiver(id, receiver_name) { + if (cur_url[0].indexOf('servers') != '-1') { + var group = $('#new-group').val(); + } else { + var group = $('#' + receiver_name + 'group-' + id).val(); + } + toastr.clear(); + $.ajax({ + url: "/app/channel/receiver/" + receiver_name, + data: { + receiver_token: $('#' + receiver_name + '-token-' + id).val(), + channel: $('#' + receiver_name + '-chanel-' + id).val(), + group: group, + id: id, + token: $('#token').val() + }, + type: "PUT", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { + toastr.error(data); + } else { + toastr.clear(); + $("#" + receiver_name + "-table-" + id).addClass("update", 1000); + setTimeout(function () { + $("#" + receiver_name + "-table-" + id).removeClass("update"); + }, 2500); + } + } + }); +} +function checkReceiver(channel_id, receiver_name) { + $.ajax({ + url: "/app/channel/check/" + channel_id + "/" + receiver_name, + // data: { + // token: $('#token').val() + // }, + // type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('error:') != '-1' || data.indexOf('error_code') != '-1') { + toastr.error(data); + } else { + toastr.success('Test message has been sent'); + } + } + }); +} +function addRecevier(dialog_id, receiver_name) { + var valid = true; + toastr.clear(); + let allFields = $([]).add($('#' + receiver_name + '-token-add')).add($('#' + receiver_name + '-chanel-add')); + allFields.removeClass("ui-state-error"); + valid = valid && checkLength($('#' + receiver_name + '-token-add'), "token", 1); + valid = valid && checkLength($('#' + receiver_name + '-chanel-add'), "channel name", 1); + if (valid) { + toastr.clear(); + $.ajax({ + url: "/app/channel/receiver/" + receiver_name, + data: { + receiver: $('#' + receiver_name + '-token-add').val(), + channel: $('#' + receiver_name + '-chanel-add').val(), + group: $('#new-' + receiver_name + '-group-add').val(), + page: cur_url[0].split('#')[0], + token: $('#token').val() + }, + type: "POST", + success: function (data) { + if (data.indexOf('error:') != '-1') { + toastr.error(data); + } else { + var getId = new RegExp(receiver_name + '-table-[0-9]+'); + var id = data.match(getId) + ''; + id = id.split('-').pop(); + $('select:regex(id, ' + receiver_name + '_channel)').append('').selectmenu("refresh"); + common_ajax_action_after_success(dialog_id, 'newgroup', 'checker_' + receiver_name + '_table', data); + $("input[type=submit], button").button(); + $("input[type=checkbox]").checkboxradio(); + $("select").selectmenu(); + } + } + }); + } +} +function confirmDeleteReceiver(id, receiver_name) { + $( "#dialog-confirm-services" ).dialog({ + resizable: false, + height: "auto", + width: 400, + modal: true, + title: delete_word + " " + $('#' + receiver_name + '-chanel-' + id).val() + "?", + buttons: [{ + text: delete_word, + click: function () { + $(this).dialog("close"); + removeReceiver(receiver_name, id); + } + }, { + text: cancel_word, + click: function () { + $(this).dialog("close"); + } + }] + }); +} +function cloneReceiver(id, receiver_name) { + $('#add-'+receiver_name+'-button').trigger( "click" ); + $('#'+receiver_name+'-token-add').val($('#'+receiver_name+'-token-'+id).val()); + $('#'+receiver_name+'-chanel-add').val($('#'+receiver_name+'-chanel-'+id).val()); +} +function removeReceiver(receiver_name, receiver_id) { + $("#" + receiver_name + "-table-" + receiver_id).css("background-color", "#f2dede"); + $.ajax({ + url: "/app/channel/receiver/" + receiver_name, + data: { + channel_id: receiver_id, + token: $('#token').val() + }, + type: "DELETE", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data == "ok") { + $("#" + receiver_name + "-table-" + receiver_id).remove(); + } else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { + toastr.error(data); + } + } + }); +} +function checkWebPanel() { + $.ajax({ + url: "/app/channel/check/rabbit", + // data: { + // token: $('#token').val() + // }, + // type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('error:') != '-1' || data.indexOf('error_code') != '-1') { + toastr.error(data); + } else { + toastr.success('Test message has been sent'); + } + } + }); +} +function checkEmail() { + $.ajax({ + url: "/app/channel/check/email", + // data: { + // token: $('#token').val() + // }, + // type: "POST", + success: function (data) { + data = data.replace(/\s+/g, ' '); + if (data.indexOf('error:') != '-1' || data.indexOf('error_code') != '-1') { + toastr.error(data); + } else { + toastr.success('Test message has been sent'); + } + } + }); +} diff --git a/app/static/js/install.js b/app/static/js/install.js new file mode 100644 index 00000000..5ed2ba9d --- /dev/null +++ b/app/static/js/install.js @@ -0,0 +1,310 @@ +$( 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(); + } + }); + $( "#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); + $.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", + success: function (data) { + data = data.replace(/^\s+|\s+$/g, ''); + $("#ajax-geoip").html('') + if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-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); + $("#geoip_service").trigger("selectmenuchange"); + } else if (data.indexOf('Info') != '-1') { + toastr.clear(); + toastr.info(data); + } else { + toastr.clear(); + toastr.info(data); + } + } + }); + }); +}); +function checkGeoipInstallation() { + $.ajax( { + url: "/app/install/geoip/" + $('#geoip_service option:selected').val() + "/" + $('#geoipserv option:selected').val(), + // data: { + // token: $('#token').val() + // }, + // type: "POST", + success: function( data ) { + data = data.replace(/^\s+|\s+$/g,''); + if(data.indexOf('No such file or directory') != '-1' || data.indexOf('cannot access') != '-1') { + $('#cur_geoip').html('GeoIPLite is not installed'); + $('#geoip_install').show(); + } else { + $('#cur_geoip').html('GeoIPLite is installed'); + $('#geoip_install').hide(); + } + } + } ); +} +function installService(service) { + $("#ajax").html('') + var syn_flood = 0; + var docker = 0; + var select_id = '#' + service + 'addserv'; + var nice_names = {'haproxy': 'HAProxy', 'nginx': 'NGINX', 'apache': 'Apache'}; + if ($('#' + service + '_syn_flood').is(':checked')) { + syn_flood = '1'; + } + if ($('#' + service + '_docker').is(':checked')) { + docker = '1'; + } + if ($(select_id).val() == '------' || $(select_id).val() === null) { + var select_server = $('#translate').attr('data-select_server'); + toastr.warning(select_server); + return false + } + var jsonData = {}; + jsonData['servers'] = {'0': {}} + jsonData['services'] = {}; + jsonData['services'][service] = {}; + jsonData['syn_flood'] = syn_flood; + jsonData['servers']['0']['ip'] = $(select_id).val(); + jsonData['servers']['0']['master'] = '0'; + jsonData['servers']['0']['name'] = $(select_id + ' option:selected').text(); + if (service == 'haproxy') { + jsonData['servers']['0']['version'] = $('#hapver option:selected').val(); + } + jsonData['services'][service]['enabled'] = 1; + jsonData['services'][service]['docker'] = docker; + $("#ajax").html(wait_mess); + $.ajax({ + url: "/app/install/" + service, + 500: function () { + showErrorStatus(nice_names[service], $(select_id + ' option:selected').text()); + }, + 504: function () { + showErrorStatus(nice_names[service], $(select_id + ' option:selected').text()); + }, + data: { + jsonData: JSON.stringify(jsonData), + token: $('#token').val() + }, + type: "POST", + success: function (data) { + try { + if (data.indexOf('error:') != '-1') { + toastr.error(data); + } + } catch (e) { + parseAnsibleJsonOutput(data, nice_names[service], select_id); + $(select_id).trigger("selectmenuchange"); + } + } + }); +} +function installExporter(exporter) { + $("#ajaxmon").html(''); + $("#ajaxmon").html(wait_mess); + var exporter_id = '#' + exporter + '_exp_addserv'; + var ext_prom = 0; + if ($('#' + exporter + '_ext_prom').is(':checked')) { + ext_prom = '1'; + } + var nice_names = {'haproxy': 'HAProxy exporter', 'nginx': 'NGINX exporter', 'apache': 'Apache exporter', 'node': 'Node exporter', 'keepalived': 'Keepalived exporter'}; + $("#ajax").html(wait_mess); + $.ajax({ + url: "/app/install/exporter/" + exporter, + 500: function () { + showErrorStatus(nice_names[exporter], $(exporter_id + ' option:selected').text()); + }, + 504: function () { + showErrorStatus(nice_names[exporter], $(exporter_id + ' option:selected').text()); + }, + data: { + server_ip: $(exporter_id).val(), + exporter_v: $('#' + exporter + 'expver').val(), + ext_prom: ext_prom, + token: $('#token').val() + }, + type: "POST", + success: function (data) { + try { + if (data.indexOf('error:') != '-1') { + toastr.error(data); + } + } catch (e) { + parseAnsibleJsonOutput(data, nice_names[exporter], exporter_id); + $(exporter_id).trigger("selectmenuchange"); + } + } + }); +} +function showExporterVersion(exporter) { + var nice_names = {'haproxy': 'HAProxy', 'nginx': 'NGINX', 'apache': 'Apache', 'node': 'Node', 'keepalived': 'Keepalived'}; + $.ajax({ + url: "/app/install/exporter/"+ exporter +"/version/" + $('#' + exporter + '_exp_addserv option:selected').val(), + // data: { + // token: $('#token').val() + // }, + // type: "POST", + success: function (data) { + data = data.replace(/^\s+|\s+$/g, ''); + if (data.indexOf('error:') != '-1') { + toastr.clear(); + toastr.error(data); + } else if (data == 'no' || data.indexOf('command') != '-1' || data.indexOf('_exporter:') != '-1' || data == '') { + $('#cur_'+ exporter +'_exp_ver').text(nice_names[exporter]+' exporter has not been installed'); + } else { + $('#cur_'+ exporter +'_exp_ver').text(data); + } + } + }); +} +function showServiceVersion(service) { + $.ajax({ + url: "/app/install/" + service + "/version/" + $('#' + service + 'addserv option:selected').val(), + // data: { + // token: $('#token').val() + // }, + // type: "POST", + success: function (data) { + data = data.replace(/^\s+|\s+$/g, ''); + if (data.indexOf('error: ') != '-1') { + toastr.warning(data); + $('#cur_' + service + '_ver').text(''); + } else if(data.indexOf('bash') != '-1' || data.indexOf('such') != '-1' || data.indexOf('command not found') != '-1' || data.indexOf('from') != '-1') { + $('#cur_' + service + '_ver').text(service + ' has not installed'); + $('#' + service + '_install').text('Install'); + $('#' + service + '_install').attr('title', 'Install'); + } else if (data.indexOf('warning: ') != '-1') { + toastr.warning(data); + } else if (data == '') { + $('#cur_' + service + '_ver').text(service + ' has not installed'); + $('#' + service + '_install').text('Install'); + $('#' + service + '_install').attr('title', 'Install'); + } else { + $('#cur_' + service + '_ver').text(data); + $('#cur_' + service + '_ver').css('font-weight', 'bold'); + $('#' + service + '_install').text('Update'); + $('#' + service + '_install').attr('title', 'Update'); + } + } + }); +} +function showErrorStatus(service_name, server) { + var something_wrong = $('#translate').attr('data-something_wrong'); + toastr.error(something_wrong + ' ' + service_name + ' ' + server); +} +function parseAnsibleJsonOutput(output, service_name, select_id) { + output = JSON.parse(JSON.stringify(output)); + var check_apache_log = $('#translate').attr('data-check_apache_log'); + var was_installed = $('#translate').attr('data-was_installed'); + for (var k in output['ok']) { + var server_name = $(select_id + ' option[value="'+k+'"]').text(); + toastr.success(service_name + ' ' + was_installed +' ' + server_name); + } + for (var k in output['failures']) { + var server_name = $(select_id + ' option[value="'+k+'"]').text(); + showErrorStatus(service_name, server_name); + } + for (var k in output['dark']) { + var server_name = $(select_id + ' option[value="'+k+'"]').text(); + showErrorStatus(service_name, server_name); + } +} diff --git a/app/templates/admin.html b/app/templates/admin.html index 1e286ddf..5fd42122 100644 --- a/app/templates/admin.html +++ b/app/templates/admin.html @@ -4,6 +4,7 @@ {% block content %} {% from 'include/input_macros.html' import input, select, copy_to_clipboard, checkbox %} + {% include 'include/del_confirm.html' %}
@@ -131,9 +132,7 @@
-
- {% include 'include/admin_backup.html' %} -
+
{% include 'include/admins_dialogs.html' %} + +
+ +{% endblock %} diff --git a/app/templates/include/admin_backup.html b/app/templates/include/admin_backup.html index 64a44fd5..81b8cfc3 100644 --- a/app/templates/include/admin_backup.html +++ b/app/templates/include/admin_backup.html @@ -1,3 +1,5 @@ +{% import 'languages/'+lang|default('en')+'.html' as lang %} +{% from 'include/input_macros.html' import input, select, copy_to_clipboard, checkbox %} {% if not is_needed_tool %}

{{lang.admin_page.desc.no_ansible}} Ansible

. diff --git a/app/templates/include/admins_dialogs.html b/app/templates/include/admins_dialogs.html index 5d756cbc..d0e8d5bc 100644 --- a/app/templates/include/admins_dialogs.html +++ b/app/templates/include/admins_dialogs.html @@ -174,7 +174,7 @@ {{ input('telegram-chanel-add') }} - {% if page != "servers.py" %} + {% if g.user_params['role'] == 1 %} {{lang.words.group|title()}} @@ -210,7 +210,7 @@ {{ input('slack-chanel-add') }} - {% if page != "servers.py" %} + {% if g.user_params['role'] == 1 %} {{lang.words.group|title()}} @@ -246,7 +246,7 @@ {{ input('pd-chanel-add') }} - {% if page != "servers.py" %} + {% if g.user_params['role'] == 1 %} {{lang.words.group|title()}} diff --git a/app/templates/include/main_menu.html b/app/templates/include/main_menu.html index 6c6f0d5f..96256079 100644 --- a/app/templates/include/main_menu.html +++ b/app/templates/include/main_menu.html @@ -90,6 +90,7 @@
  • {{lang.menu_links.monitoring.smon.history}}
  • {% if g.user_params['role'] <= 3 %}
  • {{lang.menu_links.monitoring.smon.agent}}
  • +
  • {{lang.words.channels|title}}
  • Checker: {{lang.words.settings|title()}}
  • {% endif %}
  • {{lang.menu_links.monitoring.checker_history}}
  • diff --git a/app/templates/include/smon/smon_history.html b/app/templates/include/smon/smon_history.html index b39feb2e..445f0e73 100644 --- a/app/templates/include/smon/smon_history.html +++ b/app/templates/include/smon/smon_history.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% from 'include/input_macros.html' import select %} -{% block title %}{{ lang.menu_links.history.title }} {{ smon_name }}{% endblock %} -{% block h2 %}{{ lang.menu_links.history.title }} {{ smon_name }}{% endblock %} +{% block title %}{{ lang.menu_links.history.title }} {{ smon_name|replace("'","") }}{% endblock %} +{% block h2 %}{{ lang.menu_links.history.title }} {{ smon_name|replace("'","") }}{% endblock %} {% block content %} {% set checking_types = {'1': 'TCP/UDP', '2': 'HTTP', '4': 'Ping', '5': 'DNS'} %} {% if user_subscription['user_status'] == 0 or user_subscription['user_plan'] == 'user' %} diff --git a/app/templates/install.html b/app/templates/install.html index 1789504d..8dd7505e 100644 --- a/app/templates/install.html +++ b/app/templates/install.html @@ -3,7 +3,7 @@ {% block h2 %}{{lang.words.admin_area|title()}}{% endblock %} {% block content %} {% from 'include/input_macros.html' import select, checkbox %} - +
      @@ -39,8 +39,8 @@ {% set values = dict() %} - {% set values = {'2.4.23-1':'2.4.23-1','2.5.14-1':'2.5.14-1', '2.6.14-1':'2.6.14-1','2.7.9-1':'2.7.9-1','2.8.1-1':'2.8.1-1'} %} - {{ select('hapver', values=values, selected='2.8.1-1', required='required') }} + {% set values = {'2.4.23-1':'2.4.23-1','2.5.14-1':'2.5.14-1', '2.6.14-1':'2.6.14-1','2.7.9-1':'2.7.9-1','2.8.1-1':'2.8.1-1','2.9.5-1':'2.9.5-1'} %} + {{ select('hapver', values=values, selected='2.9.5-1', required='required') }} @@ -35,9 +36,7 @@ {% include 'include/admin_settings.html' %}
    -
    - {% include 'include/admin_backup.html' %} -
    +
    {% include 'include/admins_dialogs.html' %} diff --git a/inc/script.js b/inc/script.js index d1b00c5c..cf206589 100644 --- a/inc/script.js +++ b/inc/script.js @@ -1106,29 +1106,7 @@ $( function() { $(this).children(".settings").css('border-left', '4px solid var(--right-menu-blue-rolor)'); $(this).children(".settings").css('background-color', 'var(--right-menu-blue-rolor)'); }); - $("#tabs").tabs("option", "active", 4); - }); - $(".installproxy").on("click", function () { - $('.menu li ul li').each(function () { - $(this).find('a').css('padding-left', '20px'); - $(this).find('a').css('border-left', '0px solid var(--right-menu-blue-rolor)'); - $(this).find('a').css('background-color', '#48505A'); - $(this).children(".installproxy").css('padding-left', '30px'); - $(this).children(".installproxy").css('border-left', '4px solid var(--right-menu-blue-rolor)'); - $(this).children(".installproxy").css('background-color', 'var(--right-menu-blue-rolor)'); - }); - $("#tabs").tabs("option", "active", 5); - }); - $(".installmon").on("click", function () { - $('.menu li ul li').each(function () { - $(this).find('a').css('padding-left', '20px'); - $(this).find('a').css('border-left', '0px solid var(--right-menu-blue-rolor)'); - $(this).find('a').css('background-color', '#48505A'); - $(this).children(".installmon").css('padding-left', '30px'); - $(this).children(".installmon").css('border-left', '4px solid var(--right-menu-blue-rolor)'); - $(this).children(".installmon").css('background-color', 'var(--right-menu-blue-rolor)'); - }); - $("#tabs").tabs("option", "active", 6); + $("#tabs").tabs("option", "active", 3); }); $(".backup").on("click", function () { $('.menu li ul li').each(function () { @@ -1139,7 +1117,8 @@ $( function() { $(this).children(".backup").css('border-left', '4px solid var(--right-menu-blue-rolor)'); $(this).children(".backup").css('background-color', 'var(--right-menu-blue-rolor)'); }); - $("#tabs").tabs("option", "active", 7); + $("#tabs").tabs("option", "active", 4); + loadBackup(); }); } } diff --git a/inc/smon.js b/inc/smon.js index 8f97161a..e15150a1 100644 --- a/inc/smon.js +++ b/inc/smon.js @@ -225,7 +225,7 @@ function getCheckSettings(smon_id, check_type) { async: false, dataType: "json", success: function( data ) { - $('#new-smon-name').val(data['name']); + $('#new-smon-name').val(data['name'].replaceAll("'", "")); $('#new-smon-ip').val(data['server_ip']); $('#new-smon-port').val(data['port']); $('#new-smon-resolver-server').val(data['resolver']); diff --git a/inc/users.js b/inc/users.js index 9083e290..6df1c868 100644 --- a/inc/users.js +++ b/inc/users.js @@ -1,88 +1,10 @@ var awesome = "/inc/fontawesome.min.js" var cur_url = window.location.href.split('/app/').pop(); cur_url = cur_url.split('/'); +var add_word = $('#translate').attr('data-add'); +var delete_word = $('#translate').attr('data-delete'); +var cancel_word = $('#translate').attr('data-cancel'); $( function() { - var add_word = $('#translate').attr('data-add'); - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); - $( "#backup_tabs" ).tabs(); - $('#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'); - }); $('#add-group-button').click(function() { addGroupDialog.dialog('open'); }); @@ -116,8 +38,6 @@ $( function() { addUserDialog.dialog('open'); }); var user_tabel_title = $( "#user-add-table-overview" ).attr('title'); - var add_word = $('#translate').attr('data-add'); - var canerl_word = $('#translate').attr('data-cancel'); var addUserDialog = $( "#user-add-table" ).dialog({ autoOpen: false, resizable: false, @@ -210,196 +130,6 @@ $( function() { } }] }); - $('#add-telegram-button').click(function() { - addTelegramDialog.dialog('open'); - }); - $('#add-slack-button').click(function() { - addSlackDialog.dialog('open'); - }); - $('#add-pd-button').click(function() { - addPDDialog.dialog('open'); - }); - var telegram_tabel_title = $( "#telegram-add-table-overview" ).attr('title'); - var addTelegramDialog = $( "#telegram-add-table" ).dialog({ - autoOpen: false, - resizable: false, - height: "auto", - width: 600, - modal: true, - title: telegram_tabel_title, - show: { - effect: "fade", - duration: 200 - }, - hide: { - effect: "fade", - duration: 200 - }, - buttons: [{ - text: add_word, - click: function () { - addRecevier(this, 'telegram'); - } - }, { - text: cancel_word, - click: function () { - $(this).dialog("close"); - clearTips(); - } - }] - }); - var slack_tabel_title = $( "#slack-add-table-overview" ).attr('title'); - var addSlackDialog = $( "#slack-add-table" ).dialog({ - autoOpen: false, - resizable: false, - height: "auto", - width: 600, - modal: true, - title: slack_tabel_title, - show: { - effect: "fade", - duration: 200 - }, - hide: { - effect: "fade", - duration: 200 - }, - buttons: [{ - text: add_word, - click: function () { - addRecevier(this, 'slack'); - } - }, { - text: cancel_word, - click: function () { - $(this).dialog("close"); - clearTips(); - } - }] - }); - var pd_tabel_title = $( "#pd-add-table-overview" ).attr('title'); - var addPDDialog = $( "#pd-add-table" ).dialog({ - autoOpen: false, - resizable: false, - height: "auto", - width: 600, - modal: true, - title: pd_tabel_title, - show: { - effect: "fade", - duration: 200 - }, - hide: { - effect: "fade", - duration: 200 - }, - buttons: [{ - text: add_word, - click: function () { - addRecevier(this, 'pd'); - } - }, { - text: cancel_word, - click: function () { - $(this).dialog("close"); - clearTips(); - } - }] - }); - $('#add-backup-button').click(function() { - addBackupDialog.dialog('open'); - }); - var backup_tabel_title = $( "#backup-add-table-overview" ).attr('title'); - var addBackupDialog = $( "#backup-add-table" ).dialog({ - autoOpen: false, - resizable: false, - height: "auto", - width: 600, - modal: true, - title: backup_tabel_title, - show: { - effect: "fade", - duration: 200 - }, - hide: { - effect: "fade", - duration: 200 - }, - buttons: { - "Add": function () { - addBackup(this); - }, - Cancel: function () { - $(this).dialog("close"); - clearTips(); - } - } - }); - $('#add-backup-s3-button').click(function() { - addS3BackupDialog.dialog('open'); - }); - var s3_backup_tabel_title = $( "#s3-backup-add-table-overview" ).attr('title'); - var addS3BackupDialog = $( "#s3-backup-add-table" ).dialog({ - autoOpen: false, - resizable: false, - height: "auto", - width: 600, - modal: true, - title: s3_backup_tabel_title, - show: { - effect: "fade", - duration: 200 - }, - hide: { - effect: "fade", - duration: 200 - }, - buttons: { - "Add": function () { - addS3Backup(this); - }, - Cancel: function () { - $(this).dialog("close"); - clearTips(); - } - } - }); - $('#add-git-button').click(function() { - addGitDialog.dialog('open'); - }); - var git_tabel_title = $( "#git-add-table-overview" ).attr('title'); - var addGitDialog = $( "#git-add-table" ).dialog({ - autoOpen: false, - resizable: false, - height: "auto", - width: 600, - modal: true, - title: git_tabel_title, - show: { - effect: "fade", - duration: 200 - }, - hide: { - effect: "fade", - duration: 200 - }, - buttons: { - "Add": function () { - addGit(this); - }, - Cancel: function () { - $(this).dialog("close"); - clearTips(); - } - } - }); - $('#git-init').click(function() { - if ($('#git-init').is(':checked')) { - $('.git-init-params').show(); - } else { - $('.git-init-params').hide(); - } - }); $( "#ajax-users input" ).change(function() { var id = $(this).attr('id').split('-'); updateUser(id[1]) @@ -442,38 +172,6 @@ $( function() { } else { $('#ssh_pass').css('display', 'block'); } - $( "#checker_telegram_table input" ).change(function() { - var id = $(this).attr('id').split('-'); - updateReceiver(id[2], 'telegram') - }); - $( "#checker_telegram_table select" ).on('selectmenuchange',function() { - var id = $(this).attr('id').split('-'); - updateReceiver(id[1], 'telegram') - }); - $( "#checker_slack_table input" ).change(function() { - var id = $(this).attr('id').split('-'); - updateReceiver(id[2], 'slack') - }); - $( "#checker_slack_table select" ).on('selectmenuchange',function() { - var id = $(this).attr('id').split('-'); - updateReceiver(id[1], 'slack') - }); - $( "#checker_pd_table input" ).change(function() { - var id = $(this).attr('id').split('-'); - updateReceiver(id[2], 'pd') - }); - $( "#checker_pd_table select" ).on('selectmenuchange',function() { - var id = $(this).attr('id').split('-'); - updateReceiver(id[1], 'pd') - }); - $( "#ajax-backup-table input" ).change(function() { - var id = $(this).attr('id').split('-'); - updateBackup(id[2]) - }); - $( "#ajax-backup-table select" ).on('selectmenuchange',function() { - var id = $(this).attr('id').split('-'); - updateBackup(id[2]) - }); $( "#scan_server" ).change(function() { if ($('#scan_server').is(':checked')) { $('.services_for_scan').hide(); @@ -549,53 +247,6 @@ $( function() { clearTips(); } }); - $( "#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); - $.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", - success: function (data) { - data = data.replace(/^\s+|\s+$/g, ''); - $("#ajax-geoip").html('') - if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-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); - $("#geoip_service").trigger("selectmenuchange"); - } else if (data.indexOf('Info') != '-1') { - toastr.clear(); - toastr.info(data); - } else { - toastr.clear(); - toastr.info(data); - } - } - }); - }); $("#tabs ul li").click(function() { var activeTab = $(this).find("a").attr("href"); var activeTabClass = activeTab.replace('#', ''); @@ -613,16 +264,10 @@ $( function() { loadupdatehapwi(); } else if (activeTab == '#openvpn'){ loadopenvpn(); + } else if (activeTab == '#backup'){ + loadBackup(); } }); - $("#backup_tabs ul li").click(function() { - $('.menu li ul li').each(function () { - $(this).find('a').css('border-left', '0px solid var(--right-menu-blue-rolor)'); - $(this).find('a').css('padding-left', '20px') - $(this).children(".backup").css('padding-left', '30px'); - $(this).children(".backup").css('border-left', '4px solid var(--right-menu-blue-rolor)'); - }); - }); } ); window.onload = function() { $('#tabs').tabs(); @@ -632,9 +277,15 @@ window.onload = function() { loadServices(); } else if (activeTabIdx == 7) { loadupdatehapwi(); + } else if (activeTabIdx == 8) { + loadBackup(); } else if (activeTabIdx == 4) { loadopenvpn(); } + } else if (cur_url[0].split('#')[0] == 'servers') { + if (activeTabIdx == 4) { + loadBackup(); + } } } function common_ajax_action_after_success(dialog_id, new_group, ajax_append_id, data) { @@ -901,176 +552,6 @@ function getGroupNameById(group_id) { }); return group_name; } -function addRecevier(dialog_id, receiver_name) { - var valid = true; - toastr.clear(); - let allFields = $([]).add($('#' + receiver_name + '-token-add')).add($('#' + receiver_name + '-chanel-add')); - allFields.removeClass("ui-state-error"); - valid = valid && checkLength($('#' + receiver_name + '-token-add'), "token", 1); - valid = valid && checkLength($('#' + receiver_name + '-chanel-add'), "channel name", 1); - if (valid) { - toastr.clear(); - $.ajax({ - url: "/app/checker/receiver/" + receiver_name, - data: { - receiver: $('#' + receiver_name + '-token-add').val(), - channel: $('#' + receiver_name + '-chanel-add').val(), - group: $('#new-' + receiver_name + '-group-add').val(), - page: cur_url[0].split('#')[0], - token: $('#token').val() - }, - type: "POST", - success: function (data) { - if (data.indexOf('error:') != '-1') { - toastr.error(data); - } else { - var getId = new RegExp(receiver_name + '-table-[0-9]+'); - var id = data.match(getId) + ''; - id = id.split('-').pop(); - $('select:regex(id, ' + receiver_name + '_channel)').append('').selectmenu("refresh"); - common_ajax_action_after_success(dialog_id, 'newgroup', 'checker_' + receiver_name + '_table', data); - $("input[type=submit], button").button(); - $("input[type=checkbox]").checkboxradio(); - $("select").selectmenu(); - } - } - }); - } -} -function addBackup(dialog_id) { - var valid = true; - toastr.clear(); - let allFields = $([]).add($('#backup-server')).add($('#rserver')).add($('#rpath')).add($('#backup-time')).add($('#backup-credentials')); - allFields.removeClass("ui-state-error"); - valid = valid && checkLength($('#backup-server'), "backup server ", 1); - valid = valid && checkLength($('#rserver'), "remote server", 1); - valid = valid && checkLength($('#rpath'), "remote path", 1); - valid = valid && checkLength($('#backup-time'), "backup time", 1); - valid = valid && checkLength($('#backup-credentials'), "backup credentials", 1); - if (valid) { - $.ajax({ - url: "/app/server/backup/create", - data: { - server: $('#backup-server').val(), - rserver: $('#rserver').val(), - rpath: $('#rpath').val(), - type: $('#backup-type').val(), - time: $('#backup-time').val(), - cred: $('#backup-credentials').val(), - description: $('#backup-description').val(), - token: $('#token').val() - }, - type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('error:') != '-1') { - toastr.error(data); - } else if (data.indexOf('info: ') != '-1') { - toastr.clear(); - toastr.info(data); - } else if (data.indexOf('warning: ') != '-1') { - toastr.clear(); - toastr.warning(data); - } else { - common_ajax_action_after_success(dialog_id, 'newbackup', 'ajax-backup-table', data); - $("select").selectmenu(); - } - } - }); - } -} -function addS3Backup(dialog_id) { - var valid = true; - toastr.clear(); - allFields = $([]).add($('#s3-backup-server')).add($('#s3_server')).add($('#s3_bucket')).add($('#s3_secret_key')).add($('#s3_access_key')) - allFields.removeClass("ui-state-error"); - valid = valid && checkLength($('#s3-backup-server'), "backup server ", 1); - valid = valid && checkLength($('#s3_server'), "S3 server", 1); - valid = valid && checkLength($('#s3_bucket'), "S3 bucket", 1); - valid = valid && checkLength($('#s3_secret_key'), "S3 secret key", 1); - valid = valid && checkLength($('#s3_access_key'), "S3 access key", 1); - if (valid) { - $.ajax({ - url: "/app/server/s3backup/create", - data: { - s3_backup_server: $('#s3-backup-server').val(), - s3_server: $('#s3_server').val(), - s3_bucket: $('#s3_bucket').val(), - s3_secret_key: $('#s3_secret_key').val(), - s3_access_key: $('#s3_access_key').val(), - time: $('#s3-backup-time').val(), - description: $('#s3-backup-description').val(), - token: $('#token').val() - }, - type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('error:') != '-1') { - toastr.error(data); - } else if (data.indexOf('info: ') != '-1') { - toastr.clear(); - toastr.info(data); - } else if (data.indexOf('warning: ') != '-1') { - toastr.clear(); - toastr.warning(data); - } else if (data.indexOf('error: ') != '-1') { - toastr.clear(); - toastr.error(data); - } else { - common_ajax_action_after_success(dialog_id, 'newbackup', 'ajax-backup-s3-table', data); - $("select").selectmenu(); - } - } - }); - } -} -function addGit(dialog_id) { - var valid = true; - toastr.clear(); - allFields = $([]).add($('#git-server')).add($('#git-service')).add($('#git-time')).add($('#git-credentials')).add($('#git-branch')) - allFields.removeClass("ui-state-error"); - valid = valid && checkLength($('#git-server'), "Server ", 1); - valid = valid && checkLength($('#git-service'), "Service", 1); - valid = valid && checkLength($('#git-credentials'), "Credentials", 1); - valid = valid && checkLength($('#git-branch'), "Branch name", 1); - var git_init = 0; - if ($('#git-init').is(':checked')) { - git_init = '1'; - } - if (valid) { - $.ajax({ - url: "/app/server/git/create", - data: { - server: $('#git-server').val(), - git_service: $('#git-service').val(), - git_init: git_init, - git_repo: $('#git-repo').val(), - git_branch: $('#git-branch').val(), - time: $('#git-time').val(), - cred: $('#git-credentials').val(), - description: $('#git-description').val(), - git_deljob: 0, - token: $('#token').val() - }, - type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('error:') != '-1') { - toastr.error(data); - } else if (data.indexOf('success: ') != '-1') { - common_ajax_action_after_success(dialog_id, 'newgit', 'ajax-git-table', data); - $("select").selectmenu(); - } else if (data.indexOf('info: ') != '-1') { - toastr.clear(); - toastr.info(data); - } else if (data.indexOf('warning: ') != '-1') { - toastr.clear(); - toastr.warning(data); - } - } - }); - } -} function sshKeyEnableShow(id) { $('#ssh_enable-'+id).click(function() { if ($('#ssh_enable-'+id).is(':checked')) { @@ -1087,8 +568,6 @@ function sshKeyEnableShow(id) { } function confirmDeleteUser(id) { - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); $( "#dialog-confirm" ).dialog({ resizable: false, height: "auto", @@ -1110,8 +589,6 @@ function confirmDeleteUser(id) { }); } function confirmDeleteGroup(id) { - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); $( "#dialog-confirm" ).dialog({ resizable: false, height: "auto", @@ -1133,8 +610,6 @@ function confirmDeleteGroup(id) { }); } function confirmDeleteServer(id) { - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); $( "#dialog-confirm" ).dialog({ resizable: false, height: "auto", @@ -1156,8 +631,6 @@ function confirmDeleteServer(id) { }); } function confirmDeleteSsh(id) { - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); $( "#dialog-confirm" ).dialog({ resizable: false, height: "auto", @@ -1178,98 +651,6 @@ function confirmDeleteSsh(id) { }] }); } -function confirmDeleteReceiver(id, reciever_name) { - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); - $( "#dialog-confirm-services" ).dialog({ - resizable: false, - height: "auto", - width: 400, - modal: true, - title: delete_word + " " + $('#' + reciever_name + '-chanel-' + id).val() + "?", - buttons: [{ - text: delete_word, - click: function () { - $(this).dialog("close"); - removeReciver(reciever_name, id); - } - }, { - text: cancel_word, - click: function () { - $(this).dialog("close"); - } - }] - }); -} -function confirmDeleteBackup(id) { - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); - $( "#dialog-confirm" ).dialog({ - resizable: false, - height: "auto", - width: 400, - modal: true, - title: delete_word + " " +$('#backup-server-'+id).val() + "?", - buttons: [{ - text: delete_word, - click: function () { - $(this).dialog("close"); - removeBackup(id); - } - }, { - text: cancel_word, - click: function () { - $(this).dialog("close"); - } - }] - }); -} -function confirmDeleteS3Backup(id) { - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); - $( "#dialog-confirm" ).dialog({ - resizable: false, - height: "auto", - width: 400, - modal: true, - title: delete_word + " " +$('#backup-s3-server-'+id).val() + "?", - buttons: [{ - text: delete_word, - click: function () { - $(this).dialog("close"); - removeS3Backup(id); - } - }, { - text: cancel_word, - click: function () { - $(this).dialog("close"); - } - }] - }); -} -function confirmDeleteGit(id) { - var delete_word = $('#translate').attr('data-delete'); - var cancel_word = $('#translate').attr('data-cancel'); - $( "#dialog-confirm" ).dialog({ - resizable: false, - height: "auto", - width: 400, - modal: true, - title: delete_word + " " +$('#git-server-'+id).text() + "?", - buttons: [{ - text: delete_word, - click: function () { - $(this).dialog("close"); - removeGit(id); - } - },{ - text: cancel_word, - click: function () { - $(this).dialog("close"); - } - }] - }); -} function cloneServer(id) { $( "#add-server-button" ).trigger( "click" ); if ($('#enable-'+id).is(':checked')) { @@ -1309,22 +690,6 @@ function cloneServer(id) { $('#new-server-group-add').selectmenu("refresh"); } } -function cloneReceiver(id, reciever_name) { - $('#add-'+reciever_name+'-button').trigger( "click" ); - $('#'+reciever_name+'-token-add').val($('#'+reciever_name+'-token-'+id).val()); - $('#'+reciever_name+'-chanel-add').val($('#'+reciever_name+'-chanel-'+id).val()); -} -function cloneBackup(id) { - $( "#add-backup-button" ).trigger( "click" ); - $('#rserver').val($('#backup-rserver-'+id).val()) - $('#rpath').val($('#backup-rpath-'+id).val()) - $('#backup-type').val($('#backup-type-'+id+' option:selected').val()).change() - $('#backup-type').selectmenu("refresh"); - $('#backup-time').val($('#backup-time-'+id+' option:selected').val()).change() - $('#backup-time').selectmenu("refresh"); - $('#backup-credentials').val($('#backup-credentials-'+id+' option:selected').val()).change() - $('#backup-credentials').selectmenu("refresh"); -} function removeUser(id) { $("#user-" + id).css("background-color", "#f2dede"); $.ajax({ @@ -1404,95 +769,6 @@ function removeSsh(id) { } } ); } -function removeReciver(receiver_name, receiver_id) { - $("#" + receiver_name + "-table-" + receiver_id).css("background-color", "#f2dede"); - $.ajax({ - url: "/app/checker/receiver/" + receiver_name, - data: { - channel_id: receiver_id, - token: $('#token').val() - }, - type: "DELETE", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data == "ok") { - $("#" + receiver_name + "-table-" + receiver_id).remove(); - } else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { - toastr.error(data); - } - } - }); -} -function removeBackup(id) { - $("#backup-table-" + id).css("background-color", "#f2dede"); - $.ajax({ - url: "/app/server/backup/delete", - data: { - deljob: id, - cred: $('#backup-credentials-' + id).val(), - server: $('#backup-server-' + id).text(), - rserver: $('#backup-rserver-' + id).val(), - token: $('#token').val() - }, - type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('ok') != '-1') { - $("#backup-table-" + id).remove(); - } else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { - toastr.error(data); - } - } - }); -} -function removeS3Backup(id) { - $("#backup-table-s3-" + id).css("background-color", "#f2dede"); - $.ajax({ - url: "/app/server/s3backup/delete", - data: { - dels3job: id, - s3_bucket: $('#bucket-' + id).text(), - s3_backup_server: $('#backup-s3-server-' + id).text(), - token: $('#token').val() - }, - type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('ok') != '-1') { - $("#s3-backup-table-" + id).remove(); - } else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { - toastr.error(data); - } - } - }); -} -function removeGit(id) { - $("#git-table-" + id).css("background-color", "#f2dede"); - $.ajax({ - url: "/app/server/git/delete", - data: { - git_backup: id, - git_deljob: 1, - git_init: 0, - repo: 0, - branch: 0, - time: 0, - cred: $('#git-credentials-id-' + id).text(), - server: $('#git-server-id-' + id).text(), - git_service: $('#git-service-id-' + id).text(), - token: $('#token').val() - }, - type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('ok') != '-1') { - $("#git-table-" + id).remove(); - } else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { - toastr.error(data); - } - } - }); -} function updateUser(id) { toastr.remove(); cur_url[0] = cur_url[0].split('#')[0] @@ -1681,71 +957,6 @@ function updateSSH(id) { } }); } -function updateReceiver(id, receiver_name) { - if (cur_url[0].indexOf('servers') != '-1') { - var group = $('#new-group').val(); - } else { - var group = $('#' + receiver_name + 'group-' + id).val(); - } - toastr.clear(); - $.ajax({ - url: "/app/checker/receiver/" + receiver_name, - data: { - receiver_token: $('#' + receiver_name + '-token-' + id).val(), - channel: $('#' + receiver_name + '-chanel-' + id).val(), - group: group, - id: id, - token: $('#token').val() - }, - type: "PUT", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { - toastr.error(data); - } else { - toastr.clear(); - $("#" + receiver_name + "-table-" + id).addClass("update", 1000); - setTimeout(function () { - $("#" + receiver_name + "-table-" + id).removeClass("update"); - }, 2500); - } - } - }); -} -function updateBackup(id) { - toastr.clear(); - if ($("#backup-type-" + id + " option:selected").val() == "-------" || $('#backup-rserver-' + id).val() == '' || $('#backup-rpath-' + id).val() == '') { - toastr.error('All fields must be completed'); - } else { - $.ajax({ - url: "/app/server/backup/update", - data: { - backupupdate: id, - server: $('#backup-server-' + id).text(), - rserver: $('#backup-rserver-' + id).val(), - rpath: $('#backup-rpath-' + id).val(), - type: $('#backup-type-' + id).val(), - time: $('#backup-time-' + id).val(), - cred: $('#backup-credentials-' + id).val(), - description: $('#backup-description-' + id).val(), - token: $('#token').val() - }, - type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { - toastr.error(data); - } else { - toastr.clear(); - $("#backup-table-" + id).addClass("update", 1000); - setTimeout(function () { - $("#backup-table-" + id).removeClass("update"); - }, 2500); - } - } - }); - } -} function showApacheLog(serv) { var rows = $('#rows').val(); var grep = $('#grep').val(); @@ -1945,7 +1156,6 @@ function changeUserServices(user_id) { } function addServiceToUser(service_id) { var service_name = $('#add_service-'+service_id).attr('data-service_name'); - var delete_word = $('#translate').attr('data-delete'); var service_word = $('#translate').attr('data-service'); var length_tr = $('#checked_services tbody tr').length; var tr_class = 'odd'; @@ -1960,7 +1170,6 @@ function addServiceToUser(service_id) { } 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'; @@ -2278,23 +1487,6 @@ function loadopenvpn() { } } ); } -function checkReceiver(channel_id, receiver_name) { - $.ajax({ - url: "/app/checker/check/" + channel_id + "/" + receiver_name, - // data: { - // token: $('#token').val() - // }, - // type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('error:') != '-1' || data.indexOf('error_code') != '-1') { - toastr.error(data); - } else { - toastr.success('Test message has been sent'); - } - } - }); -} function updateServerInfo(ip, id) { $.ajax({ url: "/app/server/system_info/update/" + ip + "/" + id, @@ -2474,204 +1666,6 @@ function updateServiceCheckerSettings(id, service_name) { } }); } -function checkWebPanel() { - $.ajax({ - url: "/app/checker/check/rabbit", - // data: { - // token: $('#token').val() - // }, - // type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('error:') != '-1' || data.indexOf('error_code') != '-1') { - toastr.error(data); - } else { - toastr.success('Test message has been sent'); - } - } - }); -} -function checkEmail() { - $.ajax({ - url: "/app/checker/check/email", - // data: { - // token: $('#token').val() - // }, - // type: "POST", - success: function (data) { - data = data.replace(/\s+/g, ' '); - if (data.indexOf('error:') != '-1' || data.indexOf('error_code') != '-1') { - toastr.error(data); - } else { - toastr.success('Test message has been sent'); - } - } - }); -} -function checkGeoipInstallation() { - $.ajax( { - url: "/app/install/geoip/" + $('#geoip_service option:selected').val() + "/" + $('#geoipserv option:selected').val(), - // data: { - // token: $('#token').val() - // }, - // type: "POST", - success: function( data ) { - data = data.replace(/^\s+|\s+$/g,''); - if(data.indexOf('No such file or directory') != '-1' || data.indexOf('cannot access') != '-1') { - $('#cur_geoip').html('GeoIPLite is not installed'); - $('#geoip_install').show(); - } else { - $('#cur_geoip').html('GeoIPLite is installed'); - $('#geoip_install').hide(); - } - } - } ); -} -function installService(service) { - $("#ajax").html('') - var syn_flood = 0; - var docker = 0; - var select_id = '#' + service + 'addserv'; - var nice_names = {'haproxy': 'HAProxy', 'nginx': 'NGINX', 'apache': 'Apache'}; - if ($('#' + service + '_syn_flood').is(':checked')) { - syn_flood = '1'; - } - if ($('#' + service + '_docker').is(':checked')) { - docker = '1'; - } - if ($(select_id).val() == '------' || $(select_id).val() === null) { - var select_server = $('#translate').attr('data-select_server'); - toastr.warning(select_server); - return false - } - var jsonData = {}; - jsonData['servers'] = {'0': {}} - jsonData['services'] = {}; - jsonData['services'][service] = {}; - jsonData['syn_flood'] = syn_flood; - jsonData['servers']['0']['ip'] = $(select_id).val(); - jsonData['servers']['0']['master'] = '0'; - jsonData['servers']['0']['name'] = $(select_id + ' option:selected').text(); - if (service == 'haproxy') { - jsonData['servers']['0']['version'] = $('#hapver option:selected').val(); - } - jsonData['services'][service]['enabled'] = 1; - jsonData['services'][service]['docker'] = docker; - $("#ajax").html(wait_mess); - $.ajax({ - url: "/app/install/" + service, - 500: function () { - showErrorStatus(nice_names[service], $(select_id + ' option:selected').text()); - }, - 504: function () { - showErrorStatus(nice_names[service], $(select_id + ' option:selected').text()); - }, - data: { - jsonData: JSON.stringify(jsonData), - token: $('#token').val() - }, - type: "POST", - success: function (data) { - try { - if (data.indexOf('error:') != '-1') { - toastr.error(data); - } - } catch (e) { - parseAnsibleJsonOutput(data, nice_names[service], select_id); - $(select_id).trigger("selectmenuchange"); - } - } - }); -} -function installExporter(exporter) { - $("#ajaxmon").html(''); - $("#ajaxmon").html(wait_mess); - var exporter_id = '#' + exporter + '_exp_addserv'; - var ext_prom = 0; - if ($('#' + exporter + '_ext_prom').is(':checked')) { - ext_prom = '1'; - } - var nice_names = {'haproxy': 'HAProxy exporter', 'nginx': 'NGINX exporter', 'apache': 'Apache exporter', 'node': 'Node exporter', 'keepalived': 'Keepalived exporter'}; - $("#ajax").html(wait_mess); - $.ajax({ - url: "/app/install/exporter/" + exporter, - 500: function () { - showErrorStatus(nice_names[exporter], $(exporter_id + ' option:selected').text()); - }, - 504: function () { - showErrorStatus(nice_names[exporter], $(exporter_id + ' option:selected').text()); - }, - data: { - server_ip: $(exporter_id).val(), - exporter_v: $('#' + exporter + 'expver').val(), - ext_prom: ext_prom, - token: $('#token').val() - }, - type: "POST", - success: function (data) { - try { - if (data.indexOf('error:') != '-1') { - toastr.error(data); - } - } catch (e) { - parseAnsibleJsonOutput(data, nice_names[exporter], exporter_id); - $(exporter_id).trigger("selectmenuchange"); - } - } - }); -} -function showExporterVersion(exporter) { - var nice_names = {'haproxy': 'HAProxy', 'nginx': 'NGINX', 'apache': 'Apache', 'node': 'Node', 'keepalived': 'Keepalived'}; - $.ajax({ - url: "/app/install/exporter/"+ exporter +"/version/" + $('#' + exporter + '_exp_addserv option:selected').val(), - // data: { - // token: $('#token').val() - // }, - // type: "POST", - success: function (data) { - data = data.replace(/^\s+|\s+$/g, ''); - if (data.indexOf('error:') != '-1') { - toastr.clear(); - toastr.error(data); - } else if (data == 'no' || data.indexOf('command') != '-1' || data.indexOf('_exporter:') != '-1' || data == '') { - $('#cur_'+ exporter +'_exp_ver').text(nice_names[exporter]+' exporter has not been installed'); - } else { - $('#cur_'+ exporter +'_exp_ver').text(data); - } - } - }); -} -function showServiceVersion(service) { - $.ajax({ - url: "/app/install/" + service + "/version/" + $('#' + service + 'addserv option:selected').val(), - // data: { - // token: $('#token').val() - // }, - // type: "POST", - success: function (data) { - data = data.replace(/^\s+|\s+$/g, ''); - if (data.indexOf('error: ') != '-1') { - toastr.warning(data); - $('#cur_' + service + '_ver').text(''); - } else if(data.indexOf('bash') != '-1' || data.indexOf('such') != '-1' || data.indexOf('command not found') != '-1' || data.indexOf('from') != '-1') { - $('#cur_' + service + '_ver').text(service + ' has not installed'); - $('#' + service + '_install').text('Install'); - $('#' + service + '_install').attr('title', 'Install'); - } else if (data.indexOf('warning: ') != '-1') { - toastr.warning(data); - } else if (data == '') { - $('#cur_' + service + '_ver').text(service + ' has not installed'); - $('#' + service + '_install').text('Install'); - $('#' + service + '_install').attr('title', 'Install'); - } else { - $('#cur_' + service + '_ver').text(data); - $('#cur_' + service + '_ver').css('font-weight', 'bold'); - $('#' + service + '_install').text('Update'); - $('#' + service + '_install').attr('title', 'Update'); - } - } - }); -} function serverIsUp(server_ip, server_id) { var cur_url = window.location.href.split('/').pop(); if (cur_url.split('#')[1] == 'servers') { @@ -2740,7 +1734,6 @@ function confirmChangeGroupsAndRoles(user_id) { } function addGroupToUser(group_id) { var group_name = $('#add_group-'+group_id).attr('data-group_name'); - var delete_word = $('#translate').attr('data-delete'); var group2_word = $('#translate').attr('data-group2'); var length_tr = $('#all_groups tbody tr').length; const roles = {1: 'superAdmin', 2: 'amdin', 3: 'user', 4: 'guest'}; @@ -2847,7 +1840,6 @@ function openChangeServerServiceDialog(server_id) { } function addServiceToServer(service_id) { var service_name = $('#add_service-'+service_id).attr('data-service_name'); - var delete_word = $('#translate').attr('data-delete'); var service_word = $('#translate').attr('data-service'); var length_tr = $('#checked_services tbody tr').length; var tr_class = 'odd'; @@ -2862,7 +1854,6 @@ function addServiceToServer(service_id) { } function removeServiceFromServer(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'; @@ -2905,24 +1896,3 @@ function changeServerServices(server_id) { } }); } -function showErrorStatus(service_name, server) { - var something_wrong = $('#translate').attr('data-something_wrong'); - toastr.error(something_wrong + ' ' + service_name + ' ' + server); -} -function parseAnsibleJsonOutput(output, service_name, select_id) { - output = JSON.parse(JSON.stringify(output)); - var check_apache_log = $('#translate').attr('data-check_apache_log'); - var was_installed = $('#translate').attr('data-was_installed'); - for (var k in output['ok']) { - var server_name = $(select_id + ' option[value="'+k+'"]').text(); - toastr.success(service_name + ' ' + was_installed +' ' + server_name); - } - for (var k in output['failures']) { - var server_name = $(select_id + ' option[value="'+k+'"]').text(); - showErrorStatus(service_name, server_name); - } - for (var k in output['dark']) { - var server_name = $(select_id + ' option[value="'+k+'"]').text(); - showErrorStatus(service_name, server_name); - } -}