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:
|
def action_haproxy(server_ip: str, action: str) -> str:
|
||||||
haproxy_service_name = "haproxy"
|
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):
|
if service_common.check_haproxy_config(server_ip):
|
||||||
server_id = sql.select_server_id_by_ip(server_ip=server_ip)
|
server_id = sql.select_server_id_by_ip(server_ip=server_ip)
|
||||||
is_docker = sql.select_service_setting(server_id, 'haproxy', 'dockerized')
|
is_docker = sql.select_service_setting(server_id, 'haproxy', 'dockerized')
|
||||||
|
|
||||||
if action == 'restart':
|
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':
|
if is_docker == '1':
|
||||||
container_name = sql.get_setting('haproxy_container_name')
|
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:
|
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):
|
if service_common.check_nginx_config(server_ip):
|
||||||
server_id = sql.select_server_id_by_ip(server_ip=server_ip)
|
server_id = sql.select_server_id_by_ip(server_ip=server_ip)
|
||||||
|
|
||||||
if action == 'restart':
|
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')
|
is_docker = sql.select_service_setting(server_id, 'nginx', 'dockerized')
|
||||||
|
|
||||||
if is_docker == '1':
|
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:
|
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"]
|
commands = [f"sudo systemctl {action} keepalived"]
|
||||||
server_mod.ssh_command(server_ip, commands)
|
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:
|
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)
|
server_id = sql.select_server_id_by_ip(server_ip)
|
||||||
|
|
||||||
if action == 'restart':
|
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')
|
is_docker = sql.select_service_setting(server_id, 'apache', 'dockerized')
|
||||||
if is_docker == '1':
|
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:
|
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,
|
roxywi_common.logging(server_ip, f'HAProxy WAF service has been {action}ed', roxywi=1, login=1, keep_history=1,
|
||||||
service='haproxy')
|
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:
|
def action_nginx_waf(server_ip: str, action: str) -> str:
|
||||||
config_dir = common.return_nice_path(sql.get_setting('nginx_dir'))
|
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_new_state = 'on' if action == 'start' else 'off'
|
||||||
waf_old_state = 'off' if action == 'start' else 'on'
|
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)
|
user_role = sql.get_user_role_by_uuid(user_uuid, group_id)
|
||||||
|
|
||||||
if sql.is_serv_protected(server_ip) and int(user_role) > 2:
|
if sql.is_serv_protected(server_ip) and int(user_role) > 2:
|
||||||
print(f'error: This server is protected. You cannot {action} it')
|
raise Exception(f'error: This server is protected. You cannot {action} it')
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def is_not_allowed_to_restart(server_id: int, service: str) -> None:
|
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'])
|
@bp.route('/setting/<param>/<val>', methods=['POST'])
|
||||||
def update_settings(param, val):
|
def update_settings(param, val):
|
||||||
|
val = val.replace('92', '/')
|
||||||
user_group = roxywi_common.get_user_group(id=1)
|
user_group = roxywi_common.get_user_group(id=1)
|
||||||
if sql.update_setting(param, val, user_group):
|
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)
|
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}'
|
return f'error: {e}'
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/create/after', methods=['POST'])
|
@bp.post('/create/after')
|
||||||
def after_add():
|
def after_add():
|
||||||
hostname = common.checkAjaxInput(request.form.get('servername'))
|
hostname = common.checkAjaxInput(request.form.get('servername'))
|
||||||
ip = common.is_ip_or_dns(request.form.get('newip'))
|
ip = common.is_ip_or_dns(request.form.get('newip'))
|
||||||
|
@ -121,7 +121,7 @@ def after_add():
|
||||||
return str(e)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/update', methods=['POST'])
|
@bp.post('/update')
|
||||||
def update_server():
|
def update_server():
|
||||||
roxywi_auth.page_for_admin(level=2)
|
roxywi_auth.page_for_admin(level=2)
|
||||||
name = request.form.get('updateserver')
|
name = request.form.get('updateserver')
|
||||||
|
|
|
@ -1392,6 +1392,7 @@ function addGit(dialog_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function updateSettings(param, val) {
|
function updateSettings(param, val) {
|
||||||
|
val = val.replace(/\//g, "92");
|
||||||
toastr.clear();
|
toastr.clear();
|
||||||
$.ajax( {
|
$.ajax( {
|
||||||
url: "/app/admin/setting/" + param + "/" + val,
|
url: "/app/admin/setting/" + param + "/" + val,
|
||||||
|
@ -1926,7 +1927,7 @@ function updateServer(id) {
|
||||||
servergroup = $('#new-server-group-add').val();
|
servergroup = $('#new-server-group-add').val();
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/admin/update",
|
url: "/app/server/update",
|
||||||
data: {
|
data: {
|
||||||
updateserver: $('#hostname-' + id).val(),
|
updateserver: $('#hostname-' + id).val(),
|
||||||
port: $('#port-' + id).val(),
|
port: $('#port-' + id).val(),
|
||||||
|
|
Loading…
Reference in New Issue