mirror of https://github.com/Aidaho12/haproxy-wi
parent
f4b7e67bc4
commit
f93bdc69bf
|
@ -21,14 +21,20 @@ def common_action(server_ip: str, action: str, service: str) -> str:
|
|||
def action_haproxy(server_ip: str, action: str) -> str:
|
||||
haproxy_service_name = "haproxy"
|
||||
|
||||
service_common.is_restarted(server_ip, action)
|
||||
try:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
if service_common.check_haproxy_config(server_ip):
|
||||
server_id = sql.select_server_id_by_ip(server_ip=server_ip)
|
||||
is_docker = sql.select_service_setting(server_id, 'haproxy', 'dockerized')
|
||||
|
||||
if action == 'restart':
|
||||
service_common.is_not_allowed_to_restart(server_id, 'haproxy')
|
||||
try:
|
||||
service_common.is_not_allowed_to_restart(server_id, 'haproxy')
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
if is_docker == '1':
|
||||
container_name = sql.get_setting('haproxy_container_name')
|
||||
|
@ -46,13 +52,19 @@ def action_haproxy(server_ip: str, action: str) -> str:
|
|||
|
||||
|
||||
def action_nginx(server_ip: str, action: str) -> str:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
try:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
if service_common.check_nginx_config(server_ip):
|
||||
server_id = sql.select_server_id_by_ip(server_ip=server_ip)
|
||||
|
||||
if action == 'restart':
|
||||
service_common.is_not_allowed_to_restart(server_id, 'nginx')
|
||||
try:
|
||||
service_common.is_not_allowed_to_restart(server_id, 'nginx')
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
is_docker = sql.select_service_setting(server_id, 'nginx', 'dockerized')
|
||||
|
||||
if is_docker == '1':
|
||||
|
@ -68,7 +80,10 @@ def action_nginx(server_ip: str, action: str) -> str:
|
|||
|
||||
|
||||
def action_keepalived(server_ip: str, action: str) -> str:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
try:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
commands = [f"sudo systemctl {action} keepalived"]
|
||||
server_mod.ssh_command(server_ip, commands)
|
||||
|
@ -77,12 +92,18 @@ def action_keepalived(server_ip: str, action: str) -> str:
|
|||
|
||||
|
||||
def action_apache(server_ip: str, action: str) -> str:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
try:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
server_id = sql.select_server_id_by_ip(server_ip)
|
||||
|
||||
if action == 'restart':
|
||||
service_common.is_not_allowed_to_restart(server_id, 'apache')
|
||||
try:
|
||||
service_common.is_not_allowed_to_restart(server_id, 'apache')
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
is_docker = sql.select_service_setting(server_id, 'apache', 'dockerized')
|
||||
if is_docker == '1':
|
||||
|
@ -98,7 +119,10 @@ def action_apache(server_ip: str, action: str) -> str:
|
|||
|
||||
|
||||
def action_haproxy_waf(server_ip: str, action: str) -> str:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
try:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
roxywi_common.logging(server_ip, f'HAProxy WAF service has been {action}ed', roxywi=1, login=1, keep_history=1,
|
||||
service='haproxy')
|
||||
|
@ -110,7 +134,10 @@ def action_haproxy_waf(server_ip: str, action: str) -> str:
|
|||
def action_nginx_waf(server_ip: str, action: str) -> str:
|
||||
config_dir = common.return_nice_path(sql.get_setting('nginx_dir'))
|
||||
|
||||
service_common.is_restarted(server_ip, action)
|
||||
try:
|
||||
service_common.is_restarted(server_ip, action)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
waf_new_state = 'on' if action == 'start' else 'off'
|
||||
waf_old_state = 'off' if action == 'start' else 'on'
|
||||
|
|
|
@ -32,8 +32,7 @@ def is_restarted(server_ip: str, action: str) -> None:
|
|||
user_role = sql.get_user_role_by_uuid(user_uuid, group_id)
|
||||
|
||||
if sql.is_serv_protected(server_ip) and int(user_role) > 2:
|
||||
print(f'error: This server is protected. You cannot {action} it')
|
||||
return
|
||||
raise Exception(f'error: This server is protected. You cannot {action} it')
|
||||
|
||||
|
||||
def is_not_allowed_to_restart(server_id: int, service: str) -> None:
|
||||
|
|
|
@ -212,6 +212,7 @@ def action_openvpn(action, openvpn):
|
|||
|
||||
@bp.route('/setting/<param>/<val>', methods=['POST'])
|
||||
def update_settings(param, val):
|
||||
val = val.replace('92', '/')
|
||||
user_group = roxywi_common.get_user_group(id=1)
|
||||
if sql.update_setting(param, val, user_group):
|
||||
roxywi_common.logging('Roxy-WI server', f'The {param} setting has been changed to: {val}', roxywi=1, login=1)
|
||||
|
|
|
@ -109,7 +109,7 @@ def create_server():
|
|||
return f'error: {e}'
|
||||
|
||||
|
||||
@bp.route('/create/after', methods=['POST'])
|
||||
@bp.post('/create/after')
|
||||
def after_add():
|
||||
hostname = common.checkAjaxInput(request.form.get('servername'))
|
||||
ip = common.is_ip_or_dns(request.form.get('newip'))
|
||||
|
@ -121,7 +121,7 @@ def after_add():
|
|||
return str(e)
|
||||
|
||||
|
||||
@bp.route('/update', methods=['POST'])
|
||||
@bp.post('/update')
|
||||
def update_server():
|
||||
roxywi_auth.page_for_admin(level=2)
|
||||
name = request.form.get('updateserver')
|
||||
|
|
|
@ -1392,6 +1392,7 @@ function addGit(dialog_id) {
|
|||
}
|
||||
}
|
||||
function updateSettings(param, val) {
|
||||
val = val.replace(/\//g, "92");
|
||||
toastr.clear();
|
||||
$.ajax( {
|
||||
url: "/app/admin/setting/" + param + "/" + val,
|
||||
|
@ -1926,7 +1927,7 @@ function updateServer(id) {
|
|||
servergroup = $('#new-server-group-add').val();
|
||||
}
|
||||
$.ajax({
|
||||
url: "/app/admin/update",
|
||||
url: "/app/server/update",
|
||||
data: {
|
||||
updateserver: $('#hostname-' + id).val(),
|
||||
port: $('#port-' + id).val(),
|
||||
|
|
Loading…
Reference in New Issue