mirror of https://github.com/Aidaho12/haproxy-wi
parent
811255ba0b
commit
61dc21c822
|
@ -662,7 +662,7 @@ def update_db_v_7_3_1():
|
||||||
|
|
||||||
def update_ver():
|
def update_ver():
|
||||||
try:
|
try:
|
||||||
Version.update(version='7.3.1.0').execute()
|
Version.update(version='7.3.2.0').execute()
|
||||||
except Exception:
|
except Exception:
|
||||||
print('Cannot update version')
|
print('Cannot update version')
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ def delete_s3_backups(backup_id: int) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def insert_new_git(server_id, service_id, repo, branch, period, cred, description):
|
def insert_new_git(server_id, service_id, repo, branch, period, cred, description) -> None:
|
||||||
try:
|
try:
|
||||||
GitSetting.insert(
|
GitSetting.insert(
|
||||||
server_id=server_id, service_id=service_id, repo=repo, branch=branch, period=period,
|
server_id=server_id, service_id=service_id, repo=repo, branch=branch, period=period,
|
||||||
|
@ -72,9 +72,6 @@ def insert_new_git(server_id, service_id, repo, branch, period, cred, descriptio
|
||||||
).execute()
|
).execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def delete_git(git_id):
|
def delete_git(git_id):
|
||||||
|
|
|
@ -51,7 +51,7 @@ def return_ssh_keys_path(server_ip: str, **kwargs) -> dict:
|
||||||
ssh_port = [str(server[10]) for server in server_sql.select_servers(server=server_ip)]
|
ssh_port = [str(server[10]) for server in server_sql.select_servers(server=server_ip)]
|
||||||
ssh_settings.setdefault('port', ssh_port[0])
|
ssh_settings.setdefault('port', ssh_port[0])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f'error: Cannot get SSH settings: {e}')
|
raise Exception(f'error: Cannot get SSH port: {e}')
|
||||||
|
|
||||||
return ssh_settings
|
return ssh_settings
|
||||||
|
|
||||||
|
|
|
@ -9,64 +9,79 @@ import app.modules.db.server as server_sql
|
||||||
import app.modules.db.service as service_sql
|
import app.modules.db.service as service_sql
|
||||||
import app.modules.server.ssh as ssh_mod
|
import app.modules.server.ssh as ssh_mod
|
||||||
import app.modules.server.server as server_mod
|
import app.modules.server.server as server_mod
|
||||||
|
import app.modules.common.common as common
|
||||||
import app.modules.roxywi.common as roxywi_common
|
import app.modules.roxywi.common as roxywi_common
|
||||||
import app.modules.service.installation as installation_mod
|
import app.modules.service.installation as installation_mod
|
||||||
|
|
||||||
|
|
||||||
def backup(serv, rpath, time, backup_type, rserver, cred, deljob, update, description) -> str:
|
def delete_backup(serv: str, backup_id: int) -> None:
|
||||||
script = 'backup.sh'
|
if backup_sql.check_exists_backup(serv):
|
||||||
ssh_settings = ssh_mod.return_ssh_keys_path(rserver, id=cred)
|
raise Exception(f'Backup job for {serv} already exists')
|
||||||
full_path = '/var/www/haproxy-wi/app'
|
|
||||||
|
|
||||||
if deljob:
|
backup_sql.delete_backups(backup_id)
|
||||||
|
roxywi_common.logging('backup ', f' a backup job for server {serv} has been deleted', roxywi=1, login=1)
|
||||||
|
|
||||||
|
|
||||||
|
def backup(json_data) -> str:
|
||||||
|
cred = int(json_data['cred'])
|
||||||
|
server = common.is_ip_or_dns(json_data['server'])
|
||||||
|
rserver = common.is_ip_or_dns(json_data['rserver'])
|
||||||
|
ssh_settings = ssh_mod.return_ssh_keys_path(rserver, id=cred)
|
||||||
|
update_id = ''
|
||||||
|
description = ''
|
||||||
|
if 'del_id' in json_data:
|
||||||
time = ''
|
time = ''
|
||||||
rpath = ''
|
rpath = ''
|
||||||
backup_type = ''
|
backup_type = ''
|
||||||
elif update:
|
del_id = int(json_data['del_id'])
|
||||||
deljob = ''
|
|
||||||
else:
|
else:
|
||||||
deljob = ''
|
del_id = ''
|
||||||
if backup_sql.check_exists_backup(serv):
|
rpath = common.checkAjaxInput(json_data['rpath'])
|
||||||
return f'warning: Backup job for {serv} already exists'
|
backup_type = common.checkAjaxInput(json_data['type'])
|
||||||
|
time = common.checkAjaxInput(json_data['time'])
|
||||||
|
description = common.checkAjaxInput(json_data['description'])
|
||||||
|
if backup_sql.check_exists_backup(server):
|
||||||
|
return f'warning: Backup job for {server} already exists'
|
||||||
|
|
||||||
os.system(f"cp {full_path}/scripts/{script} {full_path}/{script}")
|
if 'update_id' in json_data:
|
||||||
|
update_id = int(json_data['update_id'])
|
||||||
|
|
||||||
commands = [
|
inv = {"server": {"hosts": {}}}
|
||||||
f"chmod +x {full_path}/{script} && {full_path}/{script} HOST={rserver} SERVER={serv} TYPE={backup_type} SSH_PORT={ssh_settings['port']} "
|
server_ips = []
|
||||||
f"TIME={time} RPATH={rpath} DELJOB={deljob} USER={ssh_settings['user']} KEY={ssh_settings['key']}"
|
inv['server']['hosts'][server] = {
|
||||||
]
|
'HOST': rserver,
|
||||||
|
"SERVER": server,
|
||||||
output, error = server_mod.subprocess_execute(commands[0])
|
"TYPE": backup_type,
|
||||||
|
"TIME": time,
|
||||||
|
"RPATH": rpath,
|
||||||
|
"DELJOB": del_id,
|
||||||
|
"USER": ssh_settings['user'],
|
||||||
|
"KEY": ssh_settings['key']
|
||||||
|
}
|
||||||
|
server_ips.append(server)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(f'{full_path}/{script}')
|
installation_mod.run_ansible(inv, server_ips, 'backup')
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
raise Exception(f'error: {e}')
|
||||||
|
|
||||||
for line in output:
|
if not del_id and not update_id:
|
||||||
if any(s in line for s in ("Traceback", "FAILED")):
|
if backup_sql.insert_backup_job(server, rserver, rpath, backup_type, time, cred, description):
|
||||||
try:
|
roxywi_common.logging('backup ', f' a new backup job for server {server} has been created', roxywi=1,
|
||||||
return f'error: {line}'
|
|
||||||
except Exception:
|
|
||||||
return f'error: {output}'
|
|
||||||
else:
|
|
||||||
if not deljob and not update:
|
|
||||||
if backup_sql.insert_backup_job(serv, rserver, rpath, backup_type, time, cred, description):
|
|
||||||
roxywi_common.logging('backup ', f' a new backup job for server {serv} has been created', roxywi=1,
|
|
||||||
login=1)
|
login=1)
|
||||||
return render_template(
|
return render_template(
|
||||||
'ajax/new_backup.html', backups=backup_sql.select_backups(server=serv, rserver=rserver), sshs=cred_sql.select_ssh()
|
'ajax/new_backup.html', backups=backup_sql.select_backups(server=server, rserver=rserver), sshs=cred_sql.select_ssh()
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception('error: Cannot add the job into DB')
|
raise Exception('Cannot add the job into DB')
|
||||||
elif deljob:
|
elif del_id:
|
||||||
backup_sql.delete_backups(deljob)
|
backup_sql.delete_backups(del_id)
|
||||||
roxywi_common.logging('backup ', f' a backup job for server {serv} has been deleted', roxywi=1, login=1)
|
roxywi_common.logging('backup ', f' a backup job for server {server} has been deleted', roxywi=1, login=1)
|
||||||
return 'ok'
|
return 'ok'
|
||||||
elif update:
|
elif update_id:
|
||||||
backup_sql.update_backup(serv, rserver, rpath, backup_type, time, cred, description, update)
|
backup_sql.update_backup(server, rserver, rpath, backup_type, time, cred, description, update_id)
|
||||||
roxywi_common.logging('backup ', f' a backup job for server {serv} has been updated', roxywi=1, login=1)
|
roxywi_common.logging('backup ', f' a backup job for server {server} has been updated', roxywi=1, login=1)
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,62 +125,46 @@ def s3_backup(server, s3_server, bucket, secret_key, access_key, time, deljob, d
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
||||||
|
|
||||||
def git_backup(server_id, service_id, git_init, repo, branch, period, cred, deljob, description, backup_id) -> str:
|
def git_backup(server_id, service_id, git_init, repo, branch, period, cred, del_job, description, backup_id) -> str:
|
||||||
servers = roxywi_common.get_dick_permit()
|
|
||||||
proxy = sql.get_setting('proxy')
|
|
||||||
services = service_sql.select_services()
|
|
||||||
server_ip = server_sql.select_server_ip_by_id(server_id)
|
server_ip = server_sql.select_server_ip_by_id(server_id)
|
||||||
service_name = service_sql.select_service_name_by_id(service_id).lower()
|
service_name = service_sql.select_service_name_by_id(service_id).lower()
|
||||||
service_config_dir = sql.get_setting(service_name + '_dir')
|
service_config_dir = sql.get_setting(service_name + '_dir')
|
||||||
script = 'git_backup.sh'
|
ssh_settings = ssh_mod.return_ssh_keys_path(server_ip, id=cred)
|
||||||
proxy_serv = ''
|
|
||||||
ssh_settings = ssh_mod.return_ssh_keys_path('localhost', id=int(cred))
|
|
||||||
full_path = '/var/www/haproxy-wi/app'
|
|
||||||
|
|
||||||
os.system(f"cp {full_path}/scripts/{script} {full_path}/{script}")
|
|
||||||
|
|
||||||
if proxy is not None and proxy != '' and proxy != 'None':
|
|
||||||
proxy_serv = proxy
|
|
||||||
|
|
||||||
if repo is None or git_init == '0':
|
if repo is None or git_init == '0':
|
||||||
repo = ''
|
repo = ''
|
||||||
if branch is None or branch == '0':
|
if branch is None or branch == '0':
|
||||||
branch = 'main'
|
branch = 'main'
|
||||||
|
|
||||||
commands = [
|
inv = {"server": {"hosts": {}}}
|
||||||
f"chmod +x {full_path}/{script} && {full_path}/{script} HOST={server_ip} DELJOB={deljob} SERVICE={service_name} INIT={git_init} "
|
inv["server"]["hosts"][server_ip] = {
|
||||||
f"SSH_PORT={ssh_settings['port']} PERIOD={period} REPO={repo} BRANCH={branch} CONFIG_DIR={service_config_dir} "
|
"REPO": repo,
|
||||||
f"PROXY={proxy_serv} USER={ssh_settings['user']} KEY={ssh_settings['key']}"
|
"CONFIG_DIR": service_config_dir,
|
||||||
]
|
"PERIOD": period,
|
||||||
|
"INIT": git_init,
|
||||||
output, error = server_mod.subprocess_execute(commands[0])
|
"BRANCH": branch,
|
||||||
|
"SERVICE": service_name,
|
||||||
|
"DELJOB": del_job,
|
||||||
|
"KEY": ssh_settings['key']
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(f'{full_path}/{script}')
|
installation_mod.run_ansible(inv, [server_ip], 'git_backup')
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
raise Exception(f'error: {e}')
|
||||||
|
|
||||||
for line in output:
|
if not del_job:
|
||||||
if any(s in line for s in ("Traceback", "FAILED")):
|
backup_sql.insert_new_git(server_id=server_id, service_id=service_id, repo=repo, branch=branch, period=period, cred=cred, description=description)
|
||||||
try:
|
kwargs = {
|
||||||
return 'error: ' + line
|
"gits": backup_sql.select_gits(server_id=server_id, service_id=service_id),
|
||||||
except Exception:
|
"sshs": cred_sql.select_ssh(),
|
||||||
return 'error: ' + output
|
"servers": roxywi_common.get_dick_permit(),
|
||||||
else:
|
"services": service_sql.select_services(),
|
||||||
if deljob == '0':
|
"new_add": 1,
|
||||||
if backup_sql.insert_new_git(
|
"lang": roxywi_common.get_user_lang_for_flask()
|
||||||
server_id=server_id, service_id=service_id, repo=repo, branch=branch,
|
}
|
||||||
period=period, cred=cred, description=description
|
roxywi_common.logging(server_ip, 'A new git job has been created', roxywi=1, login=1, keep_history=1, service=service_name)
|
||||||
):
|
return render_template('ajax/new_git.html', **kwargs)
|
||||||
gits = backup_sql.select_gits(server_id=server_id, service_id=service_id)
|
|
||||||
sshs = cred_sql.select_ssh()
|
|
||||||
|
|
||||||
lang = roxywi_common.get_user_lang_for_flask()
|
|
||||||
roxywi_common.logging(
|
|
||||||
server_ip, ' A new git job has been created', roxywi=1, login=1, keep_history=1,
|
|
||||||
service=service_name
|
|
||||||
)
|
|
||||||
return render_template('ajax/new_git.html', gits=gits, sshs=sshs, servers=servers, services=services, new_add=1, lang=lang)
|
|
||||||
else:
|
else:
|
||||||
if backup_sql.delete_git(backup_id):
|
if backup_sql.delete_git(backup_id):
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
|
@ -204,7 +204,7 @@ def generate_service_inv(json_data: json, installed_service: str) -> object:
|
||||||
return inv, server_ips
|
return inv, server_ips
|
||||||
|
|
||||||
|
|
||||||
def run_ansible(inv: dict, server_ips: str, ansible_role: str) -> object:
|
def run_ansible(inv: dict, server_ips: list, ansible_role: str) -> object:
|
||||||
inventory_path = '/var/www/haproxy-wi/app/scripts/ansible/inventory'
|
inventory_path = '/var/www/haproxy-wi/app/scripts/ansible/inventory'
|
||||||
inventory = f'{inventory_path}/{ansible_role}.json'
|
inventory = f'{inventory_path}/{ansible_role}.json'
|
||||||
proxy = sql.get_setting('proxy')
|
proxy = sql.get_setting('proxy')
|
||||||
|
|
|
@ -107,22 +107,33 @@ def get_slaves_for_udp_listener(cluster_id: int, vip: str) -> list:
|
||||||
return servers
|
return servers
|
||||||
|
|
||||||
|
|
||||||
def listener_actions(listener_id: int, action: str, group_id: int) -> str:
|
def _return_listener_servers(listener_id: int, group_id=None):
|
||||||
if action not in ('start', 'stop', 'restart'):
|
|
||||||
raise ValueError("error: Invalid action")
|
|
||||||
servers = []
|
servers = []
|
||||||
listener = udp_sql.get_listener(listener_id)
|
listener = udp_sql.get_listener(listener_id)
|
||||||
if int(listener.group_id.group_id) != group_id:
|
if group_id is not None and int(listener.group_id.group_id) != group_id:
|
||||||
raise ValueError("error: Invalid group")
|
raise ValueError("error: Invalid group")
|
||||||
if listener.cluster_id:
|
if listener.cluster_id:
|
||||||
get_slaves_for_udp_listener(listener.cluster_id, listener.vip)
|
servers = get_slaves_for_udp_listener(listener.cluster_id, listener.vip)
|
||||||
elif listener.server_id:
|
elif listener.server_id:
|
||||||
server = server_sql.get_server_by_id(listener.server_id)
|
server = server_sql.get_server_by_id(listener.server_id)
|
||||||
servers.append(server.ip)
|
servers.append(server.ip)
|
||||||
if len(servers) < 1:
|
if len(servers) < 1:
|
||||||
raise ValueError("error: Cannot find server")
|
raise ValueError("error: Cannot find server")
|
||||||
|
|
||||||
|
return servers, listener
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def listener_actions(listener_id: int, action: str, group_id: int) -> str:
|
||||||
|
if action not in ('start', 'stop', 'restart'):
|
||||||
|
raise ValueError("error: Invalid action")
|
||||||
|
|
||||||
cmd = f'sudo systemctl {action} keepalived-udp-{listener_id}.service'
|
cmd = f'sudo systemctl {action} keepalived-udp-{listener_id}.service'
|
||||||
print(cmd)
|
try:
|
||||||
|
servers, listener = _return_listener_servers(listener_id, group_id)
|
||||||
|
except Exception as e:
|
||||||
|
raise e
|
||||||
|
|
||||||
for server_ip in servers:
|
for server_ip in servers:
|
||||||
try:
|
try:
|
||||||
server_mod.ssh_command(server_ip, cmd)
|
server_mod.ssh_command(server_ip, cmd)
|
||||||
|
@ -130,3 +141,20 @@ def listener_actions(listener_id: int, action: str, group_id: int) -> str:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot {action} for UDP balancer {listener.name}', roxywi=1)
|
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot {action} for UDP balancer {listener.name}', roxywi=1)
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
||||||
|
|
||||||
|
def check_is_listener_active(listener_id: int) -> str:
|
||||||
|
try:
|
||||||
|
servers, listener = _return_listener_servers(listener_id)
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(e)
|
||||||
|
statuses = []
|
||||||
|
cmd = f'systemctl is-active keepalived-udp-{listener_id}.service'
|
||||||
|
for server_ip in servers:
|
||||||
|
status = server_mod.ssh_command(server_ip, cmd)
|
||||||
|
statuses.append(status.replace('\n', '').replace('\r', ''))
|
||||||
|
if 'inactive' in statuses and 'active' in statuses:
|
||||||
|
return 'warning'
|
||||||
|
elif 'inactive' in statuses and 'active' not in statuses:
|
||||||
|
return 'error'
|
||||||
|
return 'ok'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import request, render_template, jsonify
|
from flask import request, render_template, g, jsonify
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
from app.routes.channel import bp
|
from app.routes.channel import bp
|
||||||
|
@ -19,8 +19,9 @@ def before_request():
|
||||||
@get_user_params()
|
@get_user_params()
|
||||||
def channels():
|
def channels():
|
||||||
roxywi_common.check_user_group_for_flask()
|
roxywi_common.check_user_group_for_flask()
|
||||||
|
lang = g.user_params['lang']
|
||||||
|
|
||||||
return render_template('channel.html')
|
return render_template('channel.html', lang=lang)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/load')
|
@bp.route('/load')
|
||||||
|
|
|
@ -296,9 +296,10 @@ def show_firewall(server_ip):
|
||||||
return server_mod.show_firewalld_rules(server_ip)
|
return server_mod.show_firewalld_rules(server_ip)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/backup')
|
@bp.route('/backup', methods=['GET', 'POST', 'PUT', 'DELETE'])
|
||||||
@get_user_params()
|
@get_user_params()
|
||||||
def load_backup():
|
def load_backup():
|
||||||
|
if request.method == 'GET':
|
||||||
user_group = g.user_params['group_id']
|
user_group = g.user_params['group_id']
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'sshs': cred_sql.select_ssh(group=user_group),
|
'sshs': cred_sql.select_ssh(group=user_group),
|
||||||
|
@ -311,25 +312,13 @@ def load_backup():
|
||||||
'user_subscription': roxywi_common.return_user_subscription(),
|
'user_subscription': roxywi_common.return_user_subscription(),
|
||||||
}
|
}
|
||||||
return render_template('include/admin_backup.html', **kwargs)
|
return render_template('include/admin_backup.html', **kwargs)
|
||||||
|
elif request.method in ('POST', 'PUT', 'DELETE'):
|
||||||
@bp.post('/backup/create')
|
json_data = request.get_json()
|
||||||
@bp.post('/backup/delete')
|
|
||||||
@bp.post('/backup/update')
|
|
||||||
def create_backup():
|
|
||||||
server = common.is_ip_or_dns(request.form.get('server'))
|
|
||||||
rpath = common.checkAjaxInput(request.form.get('rpath'))
|
|
||||||
time = common.checkAjaxInput(request.form.get('time'))
|
|
||||||
backup_type = common.checkAjaxInput(request.form.get('type'))
|
|
||||||
rserver = common.checkAjaxInput(request.form.get('rserver'))
|
|
||||||
cred = int(request.form.get('cred'))
|
|
||||||
deljob = common.checkAjaxInput(request.form.get('deljob'))
|
|
||||||
update = common.checkAjaxInput(request.form.get('backupupdate'))
|
|
||||||
description = common.checkAjaxInput(request.form.get('description'))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return backup_mod.backup(server, rpath, time, backup_type, rserver, cred, deljob, update, description)
|
data = backup_mod.backup(json_data)
|
||||||
|
return jsonify({'status': 'ok', 'data': data})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return str(e)
|
return roxywi_common.handle_json_exceptions(e, f'Cannot {request.method} backup')
|
||||||
|
|
||||||
|
|
||||||
@bp.post('/s3backup/create')
|
@bp.post('/s3backup/create')
|
||||||
|
@ -350,18 +339,24 @@ def create_s3_backup():
|
||||||
return str(e)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
@bp.post('/git/create')
|
@bp.route('/git', methods=['DELETE', 'POST'])
|
||||||
@bp.post('/git/delete')
|
|
||||||
def create_git_backup():
|
def create_git_backup():
|
||||||
server_id = request.form.get('server')
|
json_data = request.get_json()
|
||||||
service_id = request.form.get('git_service')
|
server_id = int(json_data['server'])
|
||||||
git_init = request.form.get('git_init')
|
service_id = int(json_data['service'])
|
||||||
repo = request.form.get('git_repo')
|
git_init = int(json_data['init'])
|
||||||
branch = request.form.get('git_branch')
|
repo = common.checkAjaxInput(json_data['repo'])
|
||||||
period = request.form.get('time')
|
branch = common.checkAjaxInput(json_data['branch'])
|
||||||
cred = request.form.get('cred')
|
period = common.checkAjaxInput(json_data['time'])
|
||||||
deljob = request.form.get('git_deljob')
|
cred = int(json_data['cred'])
|
||||||
description = request.form.get('description')
|
del_job = int(json_data['del_job'])
|
||||||
backup_id = request.form.get('git_backup')
|
description = common.checkAjaxInput(json_data['desc'])
|
||||||
|
backup_id = ''
|
||||||
|
if request.method == 'DELETE':
|
||||||
|
backup_id = json_data['backup_id']
|
||||||
|
|
||||||
return backup_mod.git_backup(server_id, service_id, git_init, repo, branch, period, cred, deljob, description, backup_id)
|
try:
|
||||||
|
data = backup_mod.git_backup(server_id, service_id, git_init, repo, branch, period, cred, del_job, description, backup_id)
|
||||||
|
return jsonify({'status': 'ok', 'data': data})
|
||||||
|
except Exception as e:
|
||||||
|
return roxywi_common.handle_json_exceptions(e, f'Cannot {request.method} git backup')
|
||||||
|
|
|
@ -110,3 +110,13 @@ def action_with_listener(service, listener_id, action):
|
||||||
return jsonify({'status': 'done'})
|
return jsonify({'status': 'done'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return roxywi_common.handle_json_exceptions(e,f'Cannot {action} listener')
|
return roxywi_common.handle_json_exceptions(e,f'Cannot {action} listener')
|
||||||
|
|
||||||
|
|
||||||
|
@bp.get('/<service>/listener/<int:listener_id>/check')
|
||||||
|
@check_services
|
||||||
|
def check_listener(service, listener_id):
|
||||||
|
try:
|
||||||
|
status = udp_mod.check_is_listener_active(listener_id)
|
||||||
|
return jsonify({'status': status})
|
||||||
|
except Exception as e:
|
||||||
|
return roxywi_common.handle_json_exceptions(e,f'Cannot get status')
|
||||||
|
|
|
@ -69,8 +69,6 @@ def create_user():
|
||||||
return jsonify({'status': 'deleted'})
|
return jsonify({'status': 'deleted'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return roxywi_common.handle_json_exceptions(e, f'Cannot delete the user {user_id}')
|
return roxywi_common.handle_json_exceptions(e, f'Cannot delete the user {user_id}')
|
||||||
else:
|
|
||||||
abort(405)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/ldap/<username>')
|
@bp.route('/ldap/<username>')
|
||||||
|
|
|
@ -1,31 +1,26 @@
|
||||||
- hosts: backup
|
- hosts: all
|
||||||
become: yes
|
become: yes
|
||||||
become_method: sudo
|
become_method: sudo
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
tasks:
|
tasks:
|
||||||
- name: Set SSH port
|
|
||||||
set_fact:
|
|
||||||
ansible_port: "{{SSH_PORT}}"
|
|
||||||
|
|
||||||
- name: Creates directory
|
- name: Creates directory
|
||||||
file:
|
file:
|
||||||
path: "{{ RPATH }}/roxy-wi-configs-backup/configs"
|
path: "{{ RPATH }}/roxy-wi-configs-backup/configs"
|
||||||
state: directory
|
state: directory
|
||||||
owner: "{{ ansible_user }}"
|
owner: "{{ ansible_user }}"
|
||||||
when: DELJOB|length == 0
|
when: not DELJOB
|
||||||
|
|
||||||
- hosts: haproxy_wi
|
- hosts: localhost
|
||||||
become: yes
|
become: yes
|
||||||
become_method: sudo
|
become_method: sudo
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
- name: Creates backup jobs
|
- name: Creates backup jobs
|
||||||
cron:
|
cron:
|
||||||
name: "Roxy-WI Backup configs for server {{ SERVER }} {{ item }}"
|
name: "Roxy-WI Backup configs for server {{ SERVER }} {{ item }}"
|
||||||
special_time: "{{ TIME }}"
|
special_time: "{{ TIME }}"
|
||||||
job: "rsync -arv {{ TYPE }} /var/lib/roxy-wi/configs/{{ item }}/{{ SERVER }}* {{ ansible_user }}@{{ HOST }}:{{ RPATH }}/roxy-wi-configs-backup/configs/{{ item }} -e 'ssh -i {{ KEY }} -o StrictHostKeyChecking=no' --log-file=/var/www/haproxy-wi/log/backup.log"
|
job: "rsync -arv {{ TYPE }} /var/lib/roxy-wi/configs/{{ item }}/{{ SERVER }}* {{ ansible_user }}@{{ HOST }}:{{ RPATH }}/roxy-wi-configs-backup/configs/{{ item }} -e 'ssh -i {{ KEY }} -o StrictHostKeyChecking=no' --log-file=/var/www/haproxy-wi/log/backup.log"
|
||||||
when: DELJOB|length == 0
|
when: not DELJOB
|
||||||
with_items:
|
with_items:
|
||||||
- kp_config
|
- kp_config
|
||||||
- hap_config
|
- hap_config
|
||||||
|
@ -36,7 +31,7 @@
|
||||||
cron:
|
cron:
|
||||||
name: "Roxy-WI Backup configs for server {{ SERVER }} {{ item }}"
|
name: "Roxy-WI Backup configs for server {{ SERVER }} {{ item }}"
|
||||||
state: absent
|
state: absent
|
||||||
when: DELJOB|length > 0
|
when: DELJOB
|
||||||
with_items:
|
with_items:
|
||||||
- kp_config
|
- kp_config
|
||||||
- hap_config
|
- hap_config
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
- hosts: "{{ variable_host }}"
|
- hosts: all
|
||||||
become: yes
|
become: yes
|
||||||
become_method: sudo
|
become_method: sudo
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
- name: Check if .git exists
|
- name: Check if .git exists
|
||||||
stat:
|
stat:
|
||||||
path: "{{ CONFIG_DIR }}/.git"
|
path: "{{ CONFIG_DIR }}/.git"
|
||||||
|
@ -12,7 +11,7 @@
|
||||||
- name: Fail if has been installed
|
- name: Fail if has been installed
|
||||||
fail:
|
fail:
|
||||||
msg="Git configuration not found. Initialize git at the beginning"
|
msg="Git configuration not found. Initialize git at the beginning"
|
||||||
when: not register_name.stat.exists and INIT == '0' and DELJOB == '0'
|
when: not register_name.stat.exists and not INIT and DELJOB
|
||||||
|
|
||||||
- name: Install git
|
- name: Install git
|
||||||
package:
|
package:
|
||||||
|
@ -21,7 +20,7 @@
|
||||||
environment:
|
environment:
|
||||||
http_proxy: "{{PROXY}}"
|
http_proxy: "{{PROXY}}"
|
||||||
https_proxy: "{{PROXY}}"
|
https_proxy: "{{PROXY}}"
|
||||||
when: INIT == '1'
|
when: INIT
|
||||||
|
|
||||||
- name: Create home dir
|
- name: Create home dir
|
||||||
file:
|
file:
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
mode: 0700
|
mode: 0700
|
||||||
group: '{{ ansible_user }}'
|
group: '{{ ansible_user }}'
|
||||||
owner: '{{ ansible_user }}'
|
owner: '{{ ansible_user }}'
|
||||||
when: INIT == '1'
|
when: INIT
|
||||||
|
|
||||||
- name: Copy ssh file
|
- name: Copy ssh file
|
||||||
copy:
|
copy:
|
||||||
|
@ -40,14 +39,14 @@
|
||||||
group: '{{ ansible_user }}'
|
group: '{{ ansible_user }}'
|
||||||
owner: '{{ ansible_user }}'
|
owner: '{{ ansible_user }}'
|
||||||
force: no
|
force: no
|
||||||
when: INIT == '1'
|
when: INIT
|
||||||
|
|
||||||
- name: Add write permisions
|
- name: Add write permissions
|
||||||
shell: "chmod o+wr -R {{ CONFIG_DIR }}"
|
shell: "chmod o+wr -R {{ CONFIG_DIR }}"
|
||||||
|
|
||||||
- name: Git init
|
- name: Git init
|
||||||
shell: 'cd {{ CONFIG_DIR }} && git init'
|
shell: 'cd {{ CONFIG_DIR }} && git init'
|
||||||
when: INIT == '1'
|
when: INIT
|
||||||
become: no
|
become: no
|
||||||
|
|
||||||
- name: Git configure
|
- name: Git configure
|
||||||
|
@ -57,16 +56,16 @@
|
||||||
[user]
|
[user]
|
||||||
name = Roxy-WI
|
name = Roxy-WI
|
||||||
email = roxy-wi@.com
|
email = roxy-wi@.com
|
||||||
when: INIT == '1'
|
when: INIT
|
||||||
|
|
||||||
- name: Git add remote
|
- name: Git add remote
|
||||||
shell: 'cd {{ CONFIG_DIR }} && git add --all . && git commit -m "Roxy-WI init repo" && git branch -M {{ BRANCH }} && git remote add origin {{ REPO }}'
|
shell: 'cd {{ CONFIG_DIR }} && git add --all . && git commit -m "Roxy-WI init repo" && git branch -M {{ BRANCH }} && git remote add origin {{ REPO }}'
|
||||||
when: INIT == '1'
|
when: INIT
|
||||||
become: no
|
become: no
|
||||||
|
|
||||||
- name: Git add push
|
- name: Git add push
|
||||||
shell: 'cd {{ CONFIG_DIR }} && GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" git push -u origin {{ BRANCH }}'
|
shell: 'cd {{ CONFIG_DIR }} && GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" git push -u origin {{ BRANCH }}'
|
||||||
when: INIT == '1'
|
when: INIT
|
||||||
become: no
|
become: no
|
||||||
|
|
||||||
- name: Creates git job
|
- name: Creates git job
|
||||||
|
@ -74,12 +73,12 @@
|
||||||
name: "Git backup {{ SERVICE }} configs"
|
name: "Git backup {{ SERVICE }} configs"
|
||||||
special_time: "{{ PERIOD }}"
|
special_time: "{{ PERIOD }}"
|
||||||
job: 'cd {{ CONFIG_DIR }} && git add --all . && git commit -m "Roxy-WI backup job at $(date)" && git push --set-upstream origin {{ BRANCH }}'
|
job: 'cd {{ CONFIG_DIR }} && git add --all . && git commit -m "Roxy-WI backup job at $(date)" && git push --set-upstream origin {{ BRANCH }}'
|
||||||
when: DELJOB == '0'
|
when: not DELJOB
|
||||||
become: no
|
become: no
|
||||||
|
|
||||||
- name: Removes git backup job
|
- name: Removes git backup job
|
||||||
cron:
|
cron:
|
||||||
name: "Git backup {{ SERVICE }} configs"
|
name: "Git backup {{ SERVICE }} configs"
|
||||||
state: absent
|
state: absent
|
||||||
when: DELJOB == '1'
|
when: DELJOB
|
||||||
become: no
|
become: no
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
for ARGUMENT in "$@"
|
|
||||||
do
|
|
||||||
KEY=$(echo $ARGUMENT | cut -f1 -d=)
|
|
||||||
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
|
|
||||||
|
|
||||||
case "$KEY" in
|
|
||||||
RPATH) RPATH=${VALUE} ;;
|
|
||||||
TIME) TIME=${VALUE} ;;
|
|
||||||
TYPE) TYPE=${VALUE} ;;
|
|
||||||
HOST) HOST=${VALUE} ;;
|
|
||||||
SERVER) SERVER=${VALUE} ;;
|
|
||||||
USER) USER=${VALUE} ;;
|
|
||||||
KEY) KEY=${VALUE} ;;
|
|
||||||
DELJOB) DELJOB=${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 '[backup]' > $PWD/$HOST
|
|
||||||
echo "$HOST ansible_port=$SSH_PORT" >> $PWD/$HOST
|
|
||||||
echo '[haproxy_wi]' >> $PWD/$HOST
|
|
||||||
echo 'localhost' >> $PWD/$HOST
|
|
||||||
|
|
||||||
if [[ $TYPE == 'synchronization' ]]; then
|
|
||||||
TYPE='--delete'
|
|
||||||
else
|
|
||||||
TYPE=''
|
|
||||||
fi
|
|
||||||
|
|
||||||
ansible-playbook $PWD/roles/backup.yml --key-file $KEY -e "ansible_user=$USER variable_host=$HOST RPATH=$RPATH TYPE=$TYPE TIME=$TIME HOST=$HOST SERVER=$SERVER KEY=$KEY DELJOB=$DELJOB SSH_PORT=$SSH_PORT" -i $PWD/$HOST
|
|
||||||
|
|
||||||
if [ $? -gt 0 ]
|
|
||||||
then
|
|
||||||
echo "error: Can't create backup job"
|
|
||||||
rm -f $PWD/$HOST
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
rm -f $PWD/$HOST
|
|
|
@ -1,39 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
for ARGUMENT in "$@"
|
|
||||||
do
|
|
||||||
KEY=$(echo $ARGUMENT | cut -f1 -d=)
|
|
||||||
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
|
|
||||||
|
|
||||||
case "$KEY" in
|
|
||||||
HOST) HOST=${VALUE} ;;
|
|
||||||
DELJOB) DELJOB=${VALUE} ;;
|
|
||||||
SERVICE) SERVICE=${VALUE} ;;
|
|
||||||
INIT) INIT=${VALUE} ;;
|
|
||||||
REPO) REPO=${VALUE} ;;
|
|
||||||
BRANCH) BRANCH=${VALUE} ;;
|
|
||||||
PERIOD) PERIOD=${VALUE} ;;
|
|
||||||
CONFIG_DIR) CONFIG_DIR=${VALUE} ;;
|
|
||||||
USER) USER=${VALUE} ;;
|
|
||||||
KEY) KEY=${VALUE} ;;
|
|
||||||
SSH_PORT) SSH_PORT=${VALUE} ;;
|
|
||||||
PROXY) PROXY=${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
|
|
||||||
|
|
||||||
ansible-playbook $PWD/roles/git_backup.yml --key-file $KEY -e "ansible_user=$USER variable_host=$HOST DELJOB=$DELJOB SERVICE=$SERVICE INIT=$INIT REPO=$REPO BRANCH=$BRANCH PERIOD=$PERIOD CONFIG_DIR=$CONFIG_DIR PROXY=$PROXY KEY=$KEY" -i $PWD/$HOST
|
|
||||||
|
|
||||||
if [ $? -gt 0 ]
|
|
||||||
then
|
|
||||||
echo "error: Cannot create a git job"
|
|
||||||
fi
|
|
||||||
rm -f $PWD/$HOST
|
|
|
@ -31,17 +31,17 @@ $( function() {
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
$( "#ssh_enable_table input" ).change(function() {
|
$("#ssh_enable_table input").change(function () {
|
||||||
let id = $(this).attr('id').split('-');
|
let id = $(this).attr('id').split('-');
|
||||||
updateSSH(id[1])
|
updateSSH(id[1])
|
||||||
sshKeyEnableShow(id[1])
|
sshKeyEnableShow(id[1])
|
||||||
});
|
});
|
||||||
$( "#ssh_enable_table select" ).on('selectmenuchange',function() {
|
$("#ssh_enable_table select").on('selectmenuchange', function () {
|
||||||
let id = $(this).attr('id').split('-');
|
let id = $(this).attr('id').split('-');
|
||||||
updateSSH(id[1])
|
updateSSH(id[1])
|
||||||
sshKeyEnableShow(id[1])
|
sshKeyEnableShow(id[1])
|
||||||
});
|
});
|
||||||
$('#new-ssh_enable').click(function() {
|
$('#new-ssh_enable').click(function () {
|
||||||
if ($('#new-ssh_enable').is(':checked')) {
|
if ($('#new-ssh_enable').is(':checked')) {
|
||||||
$('#ssh_pass').css('display', 'none');
|
$('#ssh_pass').css('display', 'none');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -89,6 +89,10 @@ function addUser(dialog_id) {
|
||||||
if ($('#activeuser').is(':checked')) {
|
if ($('#activeuser').is(':checked')) {
|
||||||
enabled = '1';
|
enabled = '1';
|
||||||
}
|
}
|
||||||
|
let user_group = $('#new-group').val();
|
||||||
|
if (user_group === undefined || user_group === null) {
|
||||||
|
user_group = $('#new-sshgroup').val();
|
||||||
|
}
|
||||||
if (valid) {
|
if (valid) {
|
||||||
let jsonData = {
|
let jsonData = {
|
||||||
"username": new_username_div.val(),
|
"username": new_username_div.val(),
|
||||||
|
@ -96,7 +100,7 @@ function addUser(dialog_id) {
|
||||||
"email": email_div.val(),
|
"email": email_div.val(),
|
||||||
"role": $('#new-role').val(),
|
"role": $('#new-role').val(),
|
||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
"user_group": $('#new-group').val(),
|
"user_group": user_group,
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/user",
|
url: "/app/user",
|
||||||
|
@ -157,7 +161,6 @@ function updateUser(id) {
|
||||||
if ($('#activeuser-' + id).is(':checked')) {
|
if ($('#activeuser-' + id).is(':checked')) {
|
||||||
enabled = '1';
|
enabled = '1';
|
||||||
}
|
}
|
||||||
toastr.remove();
|
|
||||||
let jsonData = {
|
let jsonData = {
|
||||||
"username": $('#login-' + id).val(),
|
"username": $('#login-' + id).val(),
|
||||||
"email": $('#email-' + id).val(),
|
"email": $('#email-' + id).val(),
|
||||||
|
|
|
@ -138,31 +138,25 @@ function addBackup(dialog_id) {
|
||||||
valid = valid && checkLength($('#backup-time'), "backup time", 1);
|
valid = valid && checkLength($('#backup-time'), "backup time", 1);
|
||||||
valid = valid && checkLength($('#backup-credentials'), "backup credentials", 1);
|
valid = valid && checkLength($('#backup-credentials'), "backup credentials", 1);
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
let jsonData = {
|
||||||
|
"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()
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/server/backup/create",
|
url: "/app/server/backup",
|
||||||
data: {
|
data: JSON.stringify(jsonData),
|
||||||
server: $('#backup-server').val(),
|
type: "PUT",
|
||||||
rserver: $('#rserver').val(),
|
contentType: "application/json; charset=utf-8",
|
||||||
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) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
if (data.status === 'failed') {
|
||||||
if (data.indexOf('error:') != '-1') {
|
toastr.error(data.error);
|
||||||
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 {
|
} else {
|
||||||
common_ajax_action_after_success(dialog_id, 'newbackup', 'ajax-backup-table', data);
|
common_ajax_action_after_success(dialog_id, 'newbackup', 'ajax-backup-table', data.data);
|
||||||
$("select").selectmenu();
|
$("select").selectmenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,47 +206,46 @@ function addS3Backup(dialog_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function addGit(dialog_id) {
|
function addGit(dialog_id) {
|
||||||
let valid = true;
|
|
||||||
toastr.clear();
|
toastr.clear();
|
||||||
allFields = $([]).add($('#git-server')).add($('#git-service')).add($('#git-time')).add($('#git-credentials')).add($('#git-branch'))
|
let valid = true;
|
||||||
allFields.removeClass("ui-state-error");
|
let server_div = $('#git-server');
|
||||||
valid = valid && checkLength($('#git-server'), "Server ", 1);
|
let service_div = $('#git-service');
|
||||||
valid = valid && checkLength($('#git-service'), "Service", 1);
|
let branch_div = $('#git-branch');
|
||||||
valid = valid && checkLength($('#git-credentials'), "Credentials", 1);
|
let time_div = $('#git-time');
|
||||||
valid = valid && checkLength($('#git-branch'), "Branch name", 1);
|
let cred_div = $('#git-credentials');
|
||||||
let git_init = 0;
|
let git_init = 0;
|
||||||
if ($('#git-init').is(':checked')) {
|
if ($('#git-init').is(':checked')) {
|
||||||
git_init = '1';
|
git_init = '1';
|
||||||
}
|
}
|
||||||
|
let allFields = $([]).add(server_div).add(service_div).add(time_div).add(cred_div).add(branch_div);
|
||||||
|
allFields.removeClass("ui-state-error");
|
||||||
|
valid = valid && checkLength(server_div, "Server ", 1);
|
||||||
|
valid = valid && checkLength(service_div, "Service", 1);
|
||||||
|
valid = valid && checkLength(cred_div, "Credentials", 1);
|
||||||
|
valid = valid && checkLength(branch_div, "Branch name", 1);
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
let jsonData = {
|
||||||
|
"server": server_div.val(),
|
||||||
|
"service": service_div.val(),
|
||||||
|
"init": git_init,
|
||||||
|
"repo": $('#git-repo').val(),
|
||||||
|
"branch": branch_div.val(),
|
||||||
|
"time": time_div.val(),
|
||||||
|
"cred": cred_div.val(),
|
||||||
|
"del_job": 0,
|
||||||
|
"desc": $('#git-description').text(),
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/server/git/create",
|
url: "/app/server/git",
|
||||||
data: {
|
data: JSON.stringify(jsonData),
|
||||||
server: $('#git-server').val(),
|
contentType: "application/json; charset=utf-8",
|
||||||
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",
|
type: "POST",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
if (data.status === 'failed') {
|
||||||
if (data.indexOf('error:') != '-1') {
|
toastr.error(data.error);
|
||||||
toastr.error(data);
|
} else {
|
||||||
} else if (data.indexOf('success: ') != '-1') {
|
common_ajax_action_after_success(dialog_id, 'newgit', 'ajax-git-table', data.data);
|
||||||
common_ajax_action_after_success(dialog_id, 'newgit', 'ajax-git-table', data);
|
|
||||||
$("select").selectmenu();
|
$("select").selectmenu();
|
||||||
} else if (data.indexOf('info: ') != '-1') {
|
|
||||||
toastr.clear();
|
|
||||||
toastr.info(data);
|
|
||||||
} else if (data.indexOf('warning: ') != '-1') {
|
|
||||||
toastr.clear();
|
|
||||||
toastr.warning(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -344,22 +337,22 @@ function cloneS3Backup(id) {
|
||||||
}
|
}
|
||||||
function removeBackup(id) {
|
function removeBackup(id) {
|
||||||
$("#backup-table-" + id).css("background-color", "#f2dede");
|
$("#backup-table-" + id).css("background-color", "#f2dede");
|
||||||
|
let jsonData = {
|
||||||
|
"del_id": id,
|
||||||
|
"cred": $('#backup-credentials-' + id).val(),
|
||||||
|
"server": $('#backup-server-' + id).text(),
|
||||||
|
"rserver": $('#backup-rserver-' + id).val()
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/server/backup/delete",
|
url: "/app/server/backup",
|
||||||
data: {
|
data: JSON.stringify(jsonData),
|
||||||
deljob: id,
|
type: "DELETE",
|
||||||
cred: $('#backup-credentials-' + id).val(),
|
contentType: "application/json; charset=utf-8",
|
||||||
server: $('#backup-server-' + id).text(),
|
|
||||||
rserver: $('#backup-rserver-' + id).val(),
|
|
||||||
token: $('#token').val()
|
|
||||||
},
|
|
||||||
type: "POST",
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
if (data.status === 'failed') {
|
||||||
if (data.indexOf('ok') != '-1') {
|
toastr.error(data.error);
|
||||||
|
} else {
|
||||||
$("#backup-table-" + id).remove();
|
$("#backup-table-" + id).remove();
|
||||||
} else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') {
|
|
||||||
toastr.error(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -387,27 +380,28 @@ function removeS3Backup(id) {
|
||||||
}
|
}
|
||||||
function removeGit(id) {
|
function removeGit(id) {
|
||||||
$("#git-table-" + id).css("background-color", "#f2dede");
|
$("#git-table-" + id).css("background-color", "#f2dede");
|
||||||
|
let jsonData = {
|
||||||
|
"backup_id": id,
|
||||||
|
"del_job": 1,
|
||||||
|
"init": 0,
|
||||||
|
"repo": 0,
|
||||||
|
"branch": 0,
|
||||||
|
"time": 0,
|
||||||
|
"cred": $('#git-credentials-id-' + id).text(),
|
||||||
|
"server": $('#git-server-id-' + id).text(),
|
||||||
|
"service": $('#git-service-id-' + id).text(),
|
||||||
|
"desc": '',
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/server/git/delete",
|
url: "/app/server/git",
|
||||||
data: {
|
data: JSON.stringify(jsonData),
|
||||||
git_backup: id,
|
contentType: "application/json; charset=utf-8",
|
||||||
git_deljob: 1,
|
type: "DELETE",
|
||||||
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) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
if (data.status === 'failed') {
|
||||||
if (data.indexOf('ok') != '-1') {
|
toastr.error(data.error);
|
||||||
|
} else {
|
||||||
$("#git-table-" + id).remove();
|
$("#git-table-" + id).remove();
|
||||||
} else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') {
|
|
||||||
toastr.error(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -417,24 +411,24 @@ function updateBackup(id) {
|
||||||
if ($("#backup-type-" + id + " option:selected").val() == "-------" || $('#backup-rserver-' + id).val() == '' || $('#backup-rpath-' + id).val() == '') {
|
if ($("#backup-type-" + id + " option:selected").val() == "-------" || $('#backup-rserver-' + id).val() == '' || $('#backup-rpath-' + id).val() == '') {
|
||||||
toastr.error('All fields must be completed');
|
toastr.error('All fields must be completed');
|
||||||
} else {
|
} else {
|
||||||
|
let jsonData = {
|
||||||
|
"update_id": 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()
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/server/backup/update",
|
url: "/app/server/backup",
|
||||||
data: {
|
data: JSON.stringify(jsonData),
|
||||||
backupupdate: id,
|
type: "PUT",
|
||||||
server: $('#backup-server-' + id).text(),
|
contentType: "application/json; charset=utf-8",
|
||||||
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) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
if (data.status === 'failed') {
|
||||||
if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') {
|
toastr.error(data.error);
|
||||||
toastr.error(data);
|
|
||||||
} else {
|
} else {
|
||||||
toastr.clear();
|
toastr.clear();
|
||||||
$("#backup-table-" + id).addClass("update", 1000);
|
$("#backup-table-" + id).addClass("update", 1000);
|
||||||
|
|
|
@ -183,6 +183,9 @@ function createUDPListenerStep2(edited, listener_id, place) {
|
||||||
}, {
|
}, {
|
||||||
text: apply_word,
|
text: apply_word,
|
||||||
click: function () {
|
click: function () {
|
||||||
|
if (!validateUDPListenerForm(place)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
jsonData = getFormData($("#create_udp_listener"));
|
jsonData = getFormData($("#create_udp_listener"));
|
||||||
saveUdpListener(jsonData, $(this), listener_id, edited, 1);
|
saveUdpListener(jsonData, $(this), listener_id, edited, 1);
|
||||||
}
|
}
|
||||||
|
@ -254,7 +257,6 @@ function getFormData($form) {
|
||||||
let unindexed_array = $form.serializeArray();
|
let unindexed_array = $form.serializeArray();
|
||||||
let indexed_array = {};
|
let indexed_array = {};
|
||||||
indexed_array['servers'] = {};
|
indexed_array['servers'] = {};
|
||||||
console.log(unindexed_array)
|
|
||||||
|
|
||||||
$.map(unindexed_array, function (n, i) {
|
$.map(unindexed_array, function (n, i) {
|
||||||
indexed_array[n['name']] = n['value'];
|
indexed_array[n['name']] = n['value'];
|
||||||
|
@ -449,6 +451,7 @@ function ajaxActionListener(action, listener_id) {
|
||||||
} else {
|
} else {
|
||||||
toastr.success(`Listener has been ${action}ed`);
|
toastr.success(`Listener has been ${action}ed`);
|
||||||
getUDPListener(listener_id);
|
getUDPListener(listener_id);
|
||||||
|
checkStatus(listener_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -466,3 +469,39 @@ function createBackendServer(server='', port='', weight='1') {
|
||||||
'</div>').insertBefore('.add-server');
|
'</div>').insertBefore('.add-server');
|
||||||
$.getScript(awesome);
|
$.getScript(awesome);
|
||||||
}
|
}
|
||||||
|
function checkStatus(listener_id) {
|
||||||
|
if (sessionStorage.getItem('check-service-udp') == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
NProgress.configure({showSpinner: false});
|
||||||
|
let listener_div = $('#listener-' + listener_id);
|
||||||
|
$.ajax({
|
||||||
|
url: "/app/udp/listener/" + listener_id + "/check",
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
success: function (data) {
|
||||||
|
try {
|
||||||
|
if (data.indexOf('logout') != '-1') {
|
||||||
|
sessionStorage.setItem('check-service-udp', 0);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
if (data.status === 'ok') {
|
||||||
|
listener_div.addClass('div-server-head-up');
|
||||||
|
listener_div.attr('title', 'All services are UP');
|
||||||
|
listener_div.removeClass('div-server-head-down');
|
||||||
|
listener_div.removeClass('div-server-head-unknown');
|
||||||
|
} else if (data.status === 'failed' || data.status === 'error') {
|
||||||
|
listener_div.removeClass('div-server-head-unknown');
|
||||||
|
listener_div.removeClass('div-server-head-up');
|
||||||
|
listener_div.addClass('div-server-head-down');
|
||||||
|
listener_div.attr('title', 'All services are DOWN');
|
||||||
|
} else if (data.status === 'warning') {
|
||||||
|
listener_div.addClass('div-server-head-unknown');
|
||||||
|
listener_div.removeClass('div-server-head-up');
|
||||||
|
listener_div.removeClass('div-server-head-down');
|
||||||
|
listener_div.attr('title', 'Not all services are UP');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
NProgress.configure({showSpinner: true});
|
||||||
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if b.description != 'None' %}
|
{% if b.description != 'None' %}
|
||||||
<input type="text" id="backup-description-{{b.id}}" value="{{b.description}}" class="form-control">
|
<input type="text" id="backup-description-{{b.id}}" value="{{b.description.replace("'", "")}}" class="form-control">
|
||||||
{% else %}
|
{% else %}
|
||||||
<input type="text" id="backup-description-{{b.id}}" class="form-control">
|
<input type="text" id="backup-description-{{b.id}}" class="form-control">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{% include 'include/admin_servers.html' %}
|
{% include 'include/admin_servers.html' %}
|
||||||
<script>
|
<script>
|
||||||
$( function() {
|
$( function() {
|
||||||
{% if page != "servers.py" %}
|
{% if g.user_params['role'] == 1 %}
|
||||||
$("#servergroup-{{ server.0}}" ).selectmenu({
|
$("#servergroup-{{ server.0}}" ).selectmenu({
|
||||||
width: 100
|
width: 100
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
<a class="ui-button ui-widget ui-corner-all" title="{{lang.words.show|title()}} {{lang.words.versions}}" onclick="openVersions()">{{lang.menu_links.versions.link}}</a>
|
<a class="ui-button ui-widget ui-corner-all" title="{{lang.words.show|title()}} {{lang.words.versions}}" onclick="openVersions()">{{lang.menu_links.versions.link}}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if g.user_params['role'] <= 2 %}
|
{% if g.user_params['role'] <= 2 %}
|
||||||
<a href="/app/servers#backup" class="ui-button ui-widget ui-corner-all" title="Git">Git</a>
|
<a href="/app/admin#backup" class="ui-button ui-widget ui-corner-all" title="Git">Git</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if b.description is not none %}
|
{% if b.description is not none %}
|
||||||
{{ input('backup-description-'+b.id|string(), value=b.description) }}
|
{{ input('backup-description-'+b.id|string(), value=b.description.replace("'", "")) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ input('backup-description-'+b.id|string()) }}
|
{{ input('backup-description-'+b.id|string()) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
<option disabled selected>{{lang.words.select|title()}} {{lang.words.w_a}} {{lang.words.role}}</option>
|
<option disabled selected>{{lang.words.select|title()}} {{lang.words.w_a}} {{lang.words.role}}</option>
|
||||||
{% for role in roles %}
|
{% for role in roles %}
|
||||||
{% if role.name != "superAdmin" %}
|
{% if role.name != "superAdmin" %}
|
||||||
<option value="{{ role.name }}">{{ role.name }}</option>
|
<option value="{{ role.role_id }}">{{ role.name }}</option>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -39,3 +39,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
checkStatus('{{listener.id}}');
|
||||||
|
setInterval(checkStatus, 15000, '{{listener.id}}');
|
||||||
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue