This example implements a Linux-oriented browser terminal. Server-side Lua starts a shell through ba.forkpty(), bridges the pseudo-terminal to SMQ, and the browser renders the terminal with xterm.js.
README.mdfor the tutorial context, run command, and Linux dependency notes.www/.preloadforba.forkpty()startup, shell discovery, PTY lifecycle, SMQ broker setup, authentication hooks, and resize/data handling.www/index.lspfor the SMQ endpoint handling and browser terminal client.www/xterm.jsandwww/xterm.cssfor the vendored terminal UI assets.
Use the official Markdown documentation bundles for BAS Lua, auxiliary APIs, ba.forkpty, SMQ, sockets, authentication, Mako Server, and LSP. Do not invent BAS, Lua, SMQ, PTY, or authenticator APIs.
- BAS API bundle: https://realtimelogic.com/downloads/basapi.md
- BAS tutorials bundle: https://realtimelogic.com/downloads/tutorials.md
- Mako Server tutorials bundle: https://makoserver.net/download/tutorials.md
- This example is Mako/Linux-oriented as written.
- It requires a server build that includes
ba.forkpty()and an operating system with a usable shell such as/bin/shor/bin/bash. - It is not a generic Xedge example; do not classify it as Xedge-compatible unless PTY, shell, authentication, and OS assumptions are redesigned for the target.
A browser shell is high risk. Treat this example as a controlled learning tool unless authentication, authorization, network exposure, and command restrictions are designed for the deployment.
- Keep authentication enabled for real deployments.
- Do not expose the shell to untrusted networks.
- For local-only testing, bind Mako to loopback with
host="localhost"andsslhost="localhost"inmako.conf; the official Mako configuration docs definehostas the HTTP interface bind setting andsslhostas the HTTPS interface bind setting. - A minimal loopback-only
mako.conffor this example is:
host="localhost"
sslhost="localhost"
apps={{name="", path="www"}}- With that file in
Web-Shell/, start Mako from the example directory withmakoinstead ofmako -l::www. - Review which user account and environment the shell runs under.
- Review terminal escape handling and file-system access for the target system.
www/.preload: checksba.forkpty, discovers the user's shell, creates the SMQ broker, starts one PTY per SMQ client, forwards PTY output to the browser, writes browser input to the PTY, handles resize events, and configures authentication when available.www/index.lsp: serves the terminal UI, accepts SMQ requests, connects the browser SMQ client, subscribes to PTY output, publishes input and resize messages, and initializes xterm.js.www/xterm.jsandwww/xterm.css: local terminal rendering assets.
- Keep the PTY lifecycle tied to the SMQ client lifecycle; terminate the PTY on disconnect.
- Preserve resize handling so terminal applications behave correctly.
- Do not remove the
ba.forkptyavailability check. - If changing authentication, keep access control in
www/.preloadand test unauthenticated access explicitly. - Avoid adding broad command shortcuts or privileged operations unless the user has specified the security model.
cd Web-Shell
mako -l::wwwThen verify on a Linux-capable Mako build:
- Startup does not fail with the
ba.forkptyerror. - The browser opens the xterm.js terminal.
- Input typed in the browser reaches the shell.
- Shell output is displayed in the browser.
- Closing the browser terminates the associated PTY.