from aiohttp import web from ..utils.auth import panel_auth def setup_routes(app, prefix=''): app.router.add_post(f'{prefix}/api/command', panel_auth(exec_cmd)) async def exec_cmd(req): d = await req.json() cs = req.app.get('service_manager').get_service("command") if not cs: return web.json_response({"error": "Missing"}, 503) try: res = await cs.execute_command(d.get('command','')) return web.json_response({"success": True, "output": str(res)}) except Exception as e: return web.json_response({"success": False, "error": str(e)})