rbox
Terminal offline. Script has not started.
(function start() { const root = document.getElementById("relay"); if (!root) { if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start, {once:true}); return; } if (root.dataset.ready) return; const find = selector => root.querySelector(selector); const status = find("[data-status]"); try { const screen = find(".screen"), output = find('[role="log"]'); const boot = find(".boot"), matches = find(".matches"); const input = find("input"), prompt = find(".prompt"); const home = "/home/guest", profile = home+"/profile.txt", contact = home+"/contact.txt"; const email = "himself@robertgustafsson.com"; const links = [ ["✉️",email,"mailto:"+email], ["🎧","Spotify","https://open.spotify.com/artist/2ay7yD0TzqJw0Y5B5U9Pnm?si=DurtNaKUTA6LiWNSiAf6_A","https://open.spotifycdn.com/cdn/images/favicon32.b64ecc03.png"], ["▶️","YouTube","https://www.youtube.com/@RobertTMGustafsson","https://www.youtube.com/favicon.ico"] ]; const dirs = new Set(["/","/etc","/home",home,"/proc","/root","/srv","/srv/www","/tmp","/usr","/usr/bin","/var","/var/log"]); const files = new Map([ [home+"/README.txt","Replikant's public shell.\ncat profile.txt Show the profile\ncat contact.txt Get in touch"], [home+"/.profile","export EDITOR=vi"], [profile,[ "Name: Robert Gustafsson", "Alias: replikant", "Year of Birth: 1983", "Last known location: Luleå, Sweden", "", "I'm a nerdy hacker with a habit of making computers do things my way, whether they like it or not, and a connoisseur of video games and tabletop RPGs. I also produce electronic music, mostly by spending three hours tweaking a synth patch that nobody will notice.", "", "When I'm not staring at screens, I train Brazilian jiu-jitsu and Muay Thai, because apparently getting beaten up voluntarily is a perfectly reasonable hobby." ].join("\n")], [contact,email], ["/etc/hostname","rbox"], ["/etc/hosts","127.0.0.1 localhost\n127.0.1.1 rbox\n::1 localhost ip6-localhost"], ["/etc/os-release",'NAME="Debian GNU/Linux"\nVERSION_ID="13"\nID=debian'], ["/etc/passwd","root:x:0:0:root:/root:/bin/bash\nguest:x:1000:1000:Guest:/home/guest:/bin/bash"], ["/etc/group","root:x:0:\nguest:x:1000:"], ["/etc/shadow",""], ["/proc/sysinfo","hostname=rbox\nsession=guest"], ["/srv/www/index.html","Replikant terminal"], ["/var/log/relay.log","10:30:00 rbox systemd[1]: Started public terminal.\n10:30:01 rbox terminal[418]: Guest session opened."] ]); const paths = ["ls","cd","cat"]; const commands = ["help","pwd","whoami",...paths,"clear","exit"]; const history = []; let cwd = home, index = 0, draft = ""; const parent = path => path.slice(0,path.lastIndexOf("/")) || "/"; const name = path => path.split("/").pop() || "/"; const locked = path => path === "/root" || path === "/etc/shadow"; const children = path => [...dirs,...files.keys()] .filter(item => item !== "/" && parent(item) === path).sort(); function check(path) { if (locked(path)) throw Error("Permission denied"); } function resolve(raw) { const target = raw.replace(/^~(?=\/|$)/,home); let path = target.startsWith("/") ? "/" : cwd; for (const part of target.split("/").filter(Boolean)) { check(path); if (!dirs.has(path)) throw Error("Not a directory"); if (part === ".") continue; path = part === ".." ? parent(path) : (path === "/" ? "" : path)+"/"+part; if (!dirs.has(path) && !files.has(path)) throw Error("No such file or directory"); } if (target.endsWith("/") && !dirs.has(path)) throw Error("Not a directory"); return path; } function element(tag,className) { const node = document.createElement(tag); node.className = className; return node; } function print(text,style="",target=output) { const line = element("div","line "+style); line.textContent = text; target.append(line); return line; } function showProfile() { const row = element("div","profile"), portrait = element("figure","portrait"); const frame = element("div","frame"), surface = element("div","surface"); const image = document.createElement("img"); image.alt = "Replikant profile image"; image.onload = () => portrait.classList.add("loaded"); image.onerror = () => portrait.remove(); print(files.get(profile),"",row); surface.append(image); frame.append(surface); portrait.append(frame); row.append(portrait); output.append(row); image.src = "/assets/images/image01.jpg"; } function showContact() { for (const [icon,label,url,logo] of links) { const link = document.createElement("a"); link.href = url; link.textContent = label; const line = print(logo ? "" : icon+" "); if (logo) { const image = element("img","icon"); image.alt = ""; image.onerror = () => image.replaceWith(icon+" "); line.append(image); image.src = logo; } line.append(link); } } function list(path,flags) { let rows = [[name(path),path]]; if (dirs.has(path)) { check(path); rows = children(path).map(item => [name(item),item]); if (flags.includes("a")) rows.unshift([".",path],["..",parent(path)]); else rows = rows.filter(([label]) => !label.startsWith(".")); } if (!rows.length) return; const long = flags.includes("l"); print(rows.map(([label,item]) => { if (!long) return label; const owner = item === home || parent(item) === home ? "guest" : "root"; let mode = dirs.has(item) ? "drwxr-xr-x" : "-rw-r--r--"; if (locked(item)) mode = dirs.has(item) ? "drwx------" : "-rw-------"; if (item === "/tmp") mode = "drwxrwxrwt"; return mode+" "+owner.padEnd(5)+" "+label; }).join(long ? "\n" : " ")); } function execute(cmd,args) { switch (cmd) { case "help": { const line = print("pwd | whoami | ls [-la] [path] | cd [path]\ncat | clear | exit\n\nTry "); const command = element("span","help-command"); command.textContent = "cat profile.txt"; line.append(command, ". Tab completes. Up/Down recalls commands."); return; } case "pwd": return print(cwd); case "whoami": return print("guest"); case "exit": cwd = home; return print("Guest session reset."); } if (!paths.includes(cmd)) throw Error("Unknown command. Type help."); const flags = cmd === "ls" && /^-[al]+$/.test(args[0]) ? args.shift() : ""; if (args.length > 1 || (cmd === "cat" && !args.length)) throw Error("Invalid arguments"); if (cmd === "ls" && (args[0] || "").startsWith("-")) throw Error("Usage: ls [-la] [path]"); const path = resolve(args[0] || (cmd === "cd" ? "~" : ".")); if (cmd === "ls") return list(path,flags); check(path); if (cmd === "cd") { if (!dirs.has(path)) throw Error("Not a directory"); cwd = path; return; } if (dirs.has(path)) throw Error("Is a directory"); if (path === profile) { showProfile(); return true; } if (path === contact) return showContact(); const text = files.get(path); if (text) print(text); } function complete(event) { const value = input.value; if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey || input.selectionStart !== value.length || input.selectionEnd !== value.length) return; const [cmd,...args] = value.trimStart().split(/\s+/); if (!cmd) return; let choices; if (!args.length) { choices = commands.filter(item => item.startsWith(cmd)).map(item => item+" "); } else { if (!paths.includes(cmd)) return; const flag = cmd === "ls" && /^-[al]+$/.test(args[0]) ? args.shift() : ""; if (args.length > 1) return; const part = args[0] || ""; const base = part.slice(0,part.lastIndexOf("/")+1); const leaf = part.slice(base.length); try { const dir = resolve(base || "."); if (!dirs.has(dir) || locked(dir)) return; const prefix = [cmd,flag].filter(Boolean).join(" ")+" "; choices = children(dir).filter(path => name(path).startsWith(leaf) && (leaf.startsWith(".") || !name(path).startsWith(".")) && (cmd !== "cd" || dirs.has(path))) .map(path => prefix+base+name(path)+(dirs.has(path) ? "/" : "")); } catch { return; } } const suggestions = choices.join(" "); if (choices.length === 1 && choices[0] !== value) { event.preventDefault(); input.value = choices[0]; matches.textContent = ""; } else if (choices.length > 1 && matches.textContent !== suggestions) { event.preventDefault(); matches.textContent = suggestions; screen.scrollTop = screen.scrollHeight; } } function run() { const text = input.value.trim(); if (!text) return; history.push(text); index = history.length; draft = input.value = matches.textContent = ""; if (text === "clear") { boot.hidden = true; output.textContent = ""; screen.scrollTop = 0; return; } const echo = print(prompt.textContent+" "+text,"prompt"); const [cmd,...args] = text.split(/\s+/); let shown; try { shown = execute(cmd,args); } catch (error) { print(cmd+": "+error.message,"error"); } prompt.textContent = "guest@rbox:"+(cwd === home ? "~" : cwd)+"$"; screen.scrollTop = shown === true ? screen.scrollTop + echo.getBoundingClientRect().top - screen.getBoundingClientRect().top : screen.scrollHeight; } input.addEventListener("input",() => { matches.textContent = ""; }); input.addEventListener("keydown",event => { if (event.isComposing) return; if (event.key === "Tab") { complete(event); return; } if (event.key === "Enter") { event.preventDefault(); run(); return; } if (!history.length || !["ArrowUp","ArrowDown"].includes(event.key)) return; event.preventDefault(); if (event.key === "ArrowUp" && index === history.length) draft = input.value; const step = event.key === "ArrowUp" ? -1 : 1; index = Math.max(0,Math.min(history.length,index+step)); input.value = index === history.length ? draft : history[index]; matches.textContent = ""; }); find("label").hidden = false; boot.hidden = false; const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches; boot.querySelectorAll("[hidden]").forEach((line,i) => { if (reduced) line.hidden = false; else setTimeout(() => { line.hidden = false; },(i+1)*500); }); root.dataset.ready = "true"; status.hidden = true; input.focus({preventScroll:true}); } catch (error) { status.textContent = "Terminal setup error: "+error.message; } })();