#!/usr/bin/env python3.14# -*- coding: utf-8 -*-"""Web-shell service entry point: `python -m euler_webshell.ws`.Run by `euler-ws@<profile>.service` as the per-profile `euler-ws-<profile>`uid from the `/opt/euler` system venv, configured entirely by the environment.Binds the public unix socket (`/run/euler/ws-<profile>.sock`, group`euler-web` — Caddy's upstream) and serves until SIGTERM.For local testing, bind a TCP port (the fake-auth harness in`tests/test_ws.py` covers the full attach path without a deployed stack):: EULER_WS_TCP=127.0.0.1:8082 EULER_PROFILE=contributor \\ EULER_AUTH_SOCKET=/tmp/dev-auth.sock python -m euler_webshell.ws"""from__future__importannotationsimportasyncioimportloggingimportosimportshutilimportsignalfromaiohttpimportwebfromeuler_webshell.ws.appimportbuild_appfromeuler_webshell.ws.configimportWsConfiglog=logging.getLogger('euler-ws')asyncdefserve()->None:config=WsConfig.from_env()runner=web.AppRunner(build_app(config),access_log=None)awaitrunner.setup()ifconfig.tcp_bind:# dev: TCP listenerhost,_,port=config.tcp_bind.partition(':')site:web.BaseSite=web.TCPSite(runner,hostor'127.0.0.1',int(portor'8082'))awaitsite.start()log.info('listening on %s (tcp, dev)',config.tcp_bind)else:# prod: unix socketpath=config.socket_pathpath.parent.mkdir(parents=True,exist_ok=True)path.unlink(missing_ok=True)site=web.UnixSite(runner,str(path))awaitsite.start()os.chmod(path,0o660)try:shutil.chown(path,group=config.socket_group)except(LookupError,PermissionError,OSError)asexc:log.warning('could not set group %r on %s (%s) — dev run?',config.socket_group,path,exc)log.info('listening on %s (group %s)',path,config.socket_group)stop=asyncio.Event()loop=asyncio.get_running_loop()forsigin(signal.SIGTERM,signal.SIGINT):loop.add_signal_handler(sig,stop.set)log.info('web-shell service up (profile %s)',config.profileor'<unpinned dev>')awaitstop.wait()log.info('shutting down')awaitrunner.cleanup()# on_cleanup reaps every shelldefmain()->None:logging.basicConfig(level=logging.INFO,format='%(name)s: %(message)s')asyncio.run(serve())if__name__=='__main__':main()