function clear() { document.getElementById('command_output').innerHTML = ''; document.getElementById('cmd_hist').innerHTML = ''; document.getElementById('content').innerHTML = ''; return ''; } function reboot() { window.location.reload(); return 'Rebooting...'; } function help(cmd) { let help_page = ''; let help_cmd = cmd[0]; if (help_cmd && !commands[help_cmd]) { return `Help page for '${help_cmd}' does not exist` } if (help_cmd) { let cmd_help = commands[help_cmd]['help'] help_page += `NAME: ${help_cmd}
`; help_page += `SUID: ${commands[help_cmd]['root_only']}
`; help_page += `DESCRIPTION: ${cmd_help['desc']}
`; help_page += `EXAMPLES:
`; for (const example in cmd_help['examples']) { help_page += `$ ${cmd_help['examples'][example]}
` } } else { for (const h in commands) { let cmd_help = commands[h]['help'] help_page += `NAME: ${h}
` help_page += `SUID: ${commands[h]['root_only']}
`; help_page += `DESCRIPTION: ${cmd_help['short_desc']}
` help_page += `EXAMPLE: ${cmd_help['examples'][0]}
` help_page += `
` } } return help_page; } function show(dest) { let dst = dest[0]; let iframe = document.createElement('iframe'); iframe.setAttribute('class', 'iframe'); if (!dst) { return help(['show']); } else { for (const l in locations) { if (locations[l]['aliases'].includes(dst)) { iframe.setAttribute('src', locations[l]['url']); break; } } } if (iframe.src) { return iframe.outerHTML; } else { return `Page '${dst}' not found`; } } function cd(dest) { let dst = dest[0]; if (!dst) { window.location = '/'; return 'Returning to the home page' } else { for (const l in locations) { if (locations[l]['aliases'].includes(dst)) { window.location = locations[l]['url']; return `Going to ${locations[l]['url']}` } } } return `Page ${dst} does not exist` } function list() { let locs = ''; for (const l in locations) { let loc = locations[l]; locs += `URL: ${loc['url']}
` locs += `DESCRIPTION: ${loc['desc']}
` locs += `ALIASES: ${loc['aliases'].join(", ")}
` locs += `
` } return locs; } function su(cmd) { let password_hash; if (!root) { password_hash = hash(prompt('Enter your password')); } if (!password_hash && !root) { return 'Not authenticated. (empty password)' } if (password_hash != localStorage.getItem('password') && !root) { return 'Wrong password.'; } if (cmd[0]) { if (cmd[0] == '.') { root = !root return `Switched to the ${root ? 'root' : localStorage.getItem('username')} user.` } else { root = true; let ret = 'Command not found'; try { ret = commands[cmd[0]]['func'](cmd.slice(1)); } catch {} root = false; return ret; } } else { return help(['su']); } } function passwd() { let current_password = hash(prompt("Current password")); let password1 = prompt("New password"); let password2 = prompt("Confirm new password"); if (current_password == localStorage.getItem('password')) { if (password1 === password2) { localStorage.setItem("password", bash(password1)) alert(`password set to '${password1}'`); } else { return "Passwords don't match" } } else { return 'Wrong password' } } function whoami() { return root ? "root" : window.localStorage.getItem("username"); }