Compare commits

..

No commits in common. "fc10dcfe1bac1dda4c91fb2216a2366dff58512a" and "650afe91a39246c906907c2e25b90ebbcf36e211" have entirely different histories.

7 changed files with 21 additions and 167 deletions

View File

@ -23,9 +23,6 @@ module.exports = (argv, terminal) => {
terminal.writeln(`${argv[0]}: ${file}: no such file or directory`);
return;
}
if (!fs.accessSync(file, fs.constants.R_OK)) {
terminal.writeln(`${argv[0]}: read ${file}: access denied`);
}
const lines = fs.readFileSync(file).toString().split('\n');
if (numbers) {

View File

@ -8,6 +8,7 @@ let cmds = {
'wget': require('./wget'),
'export_file': require('./export_file'),
'import_file': require('./import_file'),
'zsh': require('./zsh'),
'ps': require('./ps'),
'clear': require('./clear'),
'rm': require('./rm'),
@ -15,10 +16,6 @@ let cmds = {
'exit': require('./exit'),
'systemctl': require('./systemctl'),
'set-hostname': require('./set-hostname.js'),
// funny stuff
'su': require('./su'),
'zsh': require('./zsh'),
'guide': require('./guide'),

View File

@ -1,6 +1,7 @@
const { Terminal } = require("xterm");
const orig_ip = data.ip;
const original_data = Object.freeze(data);
global.orig = original_data;
/**
*
@ -8,26 +9,22 @@ const orig_ip = data.ip;
* @param {Terminal} terminal
*/
module.exports = (argv, terminal, zsh) => {
if (argv.indexOf('--help') !== -1 | (!argv[1])) {
terminal.writeln(`Usage: ${argv[0]} [hostname] [-R] [--help]
-R Reset it to original IP (${orig_ip})
if (argv.indexOf('--help') !== -1) {
terminal.writeln(`
Usage: ${argv[0]} [hostname] [-R] [--help]
-R Reset it to original IP (${original_data.ip})
--help Show this page`
);
return 0;
}
if (argv.indexOf('-R') !== -1) {
data.ip = orig_ip;
data.ip = original_data.ip;
zsh.update_prompt();
return 0;
}
if (argv[1] == 'blek.codes') {
terminal.writeln(`${argv[0]}: cannot set hostname to ${argv[1]}: permission denied (you are not on blek.codes you moron)`);
return 1;
}
data.ip = argv[1];
data.ip = argv[1] || 'resume.js';
zsh.update_prompt();
return 0;
}

View File

@ -1,62 +0,0 @@
const { Terminal } = require("xterm");
const sleep = require("../../lib/sleep");
/**
* @param {string[]} argv
* @param {Terminal} terminal
*/
module.exports = async (argv, terminal, zsh) => {
if (argv.indexOf('--help') !== -1) {
terminal.writeln(
`Usage: ${argv[0]} [options] [<user>]` + '\n' +
'Change the user ID and group ID to <user>\'s.' + '\n' +
'\n' +
'If <user> is not giver, root is assumed.' + '\n' +
'This command is an easter egg. Try to guess the root\'s password!'
);
return;
}
const user = argv[1] || 'root';
const users = Object.freeze(['root', 'daemon', 'bin', 'sys', 'adm', 'nobody', 'lpd', 'lp', 'ipsec', 'user']);
if (users.indexOf(user) == -1) {
terminal.writeln(`${argv[0]}: user ${user} does not exist or the user entry does not contain all the required fields`);
return 2;
}
terminal.write('Password: ');
/** @type {string} */
const pass = await zsh.get_stdin({hide: true});
const some_random_array = new Uint16Array([12319, 14486, 12589, 13232]);
let checksum = new Uint32Array(pass.length);
let i = 0;
for (const letter of pass) {
checksum[i] = letter.charCodeAt(0) * 128;
checksum[i] += (i*8) - letter.charCodeAt(0);
i++;
}
i = undefined;
console.log(checksum, some_random_array);
let valid = true;
if (checksum.length == some_random_array.length)
for (let i = 0; i != some_random_array.length; i++) {
if (checksum[i] != some_random_array[i])
valid = false;
}
else
valid = false;
console.log(valid);
if (valid) {
terminal.writeln('yay, you did it!! congratulations :3');
} else {
await sleep(3000);
terminal.writeln('su: Authentication failure');
return 1;
}
}

View File

@ -19,6 +19,4 @@ if (!fs.existsSync('dev'))
}
})();
ufs.constants = fs.constants;
module.exports = ufs;

View File

@ -8,6 +8,13 @@ global.fs = fs;
const cmds = require('./commands');
const sleep = require('../lib/sleep');
// ZSH api to be used in commands (see references)
const zshapi = {
update_prompt,
text_prompt,
pr_char
};
/**
* @type { Terminal }
*/
@ -18,16 +25,6 @@ let terminal;
*/
let dom;
// ZSH api to be used in commands (see references)
const zshapi = {
update_prompt,
text_prompt,
pr_char,
get_stdin,
terminal,
dom,
};
let prompt = `\x1b[1;32muser@${data.ip} \x1b[36m~ $ \x1b[0m`;
let cmd = '';
let lastcmd = window.sessionStorage.getItem('last_cmd') || '';
@ -40,69 +37,6 @@ function text_prompt() {
return prompt.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
}
let stdin_open = false;
/**
*
* @param {{hide: boolean}} opt
* @returns
*/
async function get_stdin(opt) {
if (opt == undefined) opt = {};
if (stdin_open) {
return 0;
}
stdin_open = true;
let input = '';
const get_char = function(e) {
if (break_loop) return;
/** @type {KeyboardEvent} */
const dom = e.domEvent;
const startX = terminal.buffer.active.cursorX;
if ((dom.key.length == 1 && !(dom.ctrlKey || dom.altKey))) {
// non-special key
if (!opt.hide) terminal.write(dom.key);
input += dom.key;
} else {
// special key
switch (dom.keyCode) {
case 8:
if (terminal.buffer.active.cursorX <= startX && (!opt.hide)) break;
if (!opt.hide) terminal.write('\b \b');
input = input.substring(0, input.length - 1);
break;
case 13:
break_loop = true;
terminal.write('\n');
break;
case 68:
if (dom.ctrlKey && dom.key.toLowerCase() == 'd') {
terminal.write('\x1b[0m\x1b[49m^D\x1b[0m');
break_loop = true;
}
}
}
}
let break_loop = false
terminal.onKey(get_char)
while (1) {
await sleep(5);
if (break_loop) break;
}
stdin_open = false;
return input;
}
/**
*
* @param { string } char
@ -156,10 +90,13 @@ async function exec_cmd() {
}
if (cmds[command] != undefined) {
const startY = terminal.buffer.normal.cursorY
// execute command
await cmds[command](c.split(' '), terminal, zshapi);
if (terminal.buffer.active.cursorX != 0 && startY != terminal.buffer.active.cursorY) {
terminal.write('\033[30;47m%\033[0m\n');
}
print_prompt();
return;
}
@ -232,13 +169,6 @@ async function control_char(id, dom) {
terminal.write(lastcmd);
break;
case 40:
if (cmd == '') break;
lastcmd = cmd;
reprint_prompt();
cmd = '';
break;
// Ctrl+c
case 67:
if (dom.ctrlKey) {
@ -264,7 +194,6 @@ async function control_char(id, dom) {
case 68:
if (dom.ctrlKey && dom.key.toLowerCase() == 'd') {
alert('you are a moron. zsh runs with PID 1');
terminal.writeln('');
pr_char = () => {};
exec_cmd = pr_char;
@ -292,8 +221,6 @@ async function control_char(id, dom) {
}
function key(e) {
if (stdin_open) return;
/** @type {KeyboardEvent} */
const dom = e.domEvent;
if (dom.key.length == 1 && !(dom.ctrlKey || dom.altKey)) {

View File

@ -5,7 +5,7 @@
<meta charset="utf-8" />
<link rel="stylesheet" href="standalone_page.css" />
<script>
let data = {
var data = {
ip: '127.0.0.1'
}
</script>