mirror of https://github.com/Aidaho12/haproxy-wi
v8.1.7: Update service action routing and validation logic
Revised the action route to use a restricted list of allowed actions via the `any` converter. Improved service name validation by refining the regex pattern and adjusted logging message formatting for consistency.pull/418/head v8.1.7
parent
60044a8cff
commit
c153da9842
|
@ -100,7 +100,7 @@ def action_service(action: str, service: str) -> str:
|
|||
'stop': 'disable --now',
|
||||
'restart': 'restart',
|
||||
}
|
||||
if not re.match(r'^[a-zA-Z0-9\.\-]+$', service):
|
||||
if not re.match(r'^[a-zA-Z0-9._-]+$', service):
|
||||
return f"Invalid service name: {service}. Only alphanumeric characters, dots, and hyphens are allowed."
|
||||
cmd = f"sudo systemctl {actions[action]} {service}"
|
||||
if not roxy_sql.get_user().Status:
|
||||
|
@ -109,7 +109,7 @@ def action_service(action: str, service: str) -> str:
|
|||
if is_in_docker:
|
||||
cmd = f"sudo supervisorctl {action} {service}"
|
||||
os.system(cmd)
|
||||
roxywi_common.logging('Roxy-WI server', f' The service {service} has been {action}ed', roxywi=1, login=1)
|
||||
roxywi_common.logging('Roxy-WI server', f'The service {service} has been {action}ed', roxywi=1, login=1)
|
||||
return 'ok'
|
||||
|
||||
|
||||
|
|
|
@ -85,11 +85,9 @@ def update_tools(service):
|
|||
return f'error: {e}'
|
||||
|
||||
|
||||
@bp.route('/tools/action/<service>/<action>')
|
||||
@bp.route('/tools/action/<service>/<any(start, stop, restart):action>')
|
||||
def action_tools(service, action):
|
||||
roxywi_auth.page_for_admin()
|
||||
if action not in ('start', 'stop', 'restart'):
|
||||
return 'error: wrong action'
|
||||
|
||||
return roxy.action_service(action, service)
|
||||
|
||||
|
|
Loading…
Reference in New Issue