feature: Adds eslint rules.
This commit is contained in:
parent
09f7987e75
commit
3c95c23369
26 changed files with 124 additions and 95 deletions
|
@ -15,7 +15,7 @@ const serverBaseURL: string =
|
|||
|
||||
const axios = baseAxios.create({
|
||||
baseURL: serverBaseURL,
|
||||
validateStatus: () => true
|
||||
validateStatus: () => true,
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -39,13 +39,15 @@ if (!keyFile) throw new Error("Somehow failed to fetch the key file!");
|
|||
|
||||
const server: ssh2.Server = new ssh2.Server({
|
||||
hostKeys: [keyFile],
|
||||
banner: "NextNet-LOM (c) NextNet project et al."
|
||||
banner: "NextNet-LOM (c) NextNet project et al.",
|
||||
});
|
||||
|
||||
server.on("connection", client => {
|
||||
let token: string = "";
|
||||
|
||||
// eslint-disable-next-line
|
||||
let username: string = "";
|
||||
// eslint-disable-next-line
|
||||
let password: string = "";
|
||||
|
||||
client.on("authentication", async auth => {
|
||||
|
@ -54,11 +56,11 @@ server.on("connection", client => {
|
|||
username: auth.username,
|
||||
password: auth.password,
|
||||
});
|
||||
|
||||
|
||||
if (response.status == 403) {
|
||||
return auth.reject(["password"]);
|
||||
}
|
||||
|
||||
|
||||
token = response.data.token;
|
||||
|
||||
username = auth.username;
|
||||
|
@ -69,44 +71,44 @@ server.on("connection", client => {
|
|||
return auth.reject();
|
||||
// todo
|
||||
} else {
|
||||
return auth.reject(["password", "publickey"]);
|
||||
return auth.reject(["password", "publickey"]);
|
||||
}
|
||||
});
|
||||
|
||||
client.on("ready", () => {
|
||||
client.on("session", (accept, reject) => {
|
||||
client.on("session", accept => {
|
||||
const conn = accept();
|
||||
|
||||
conn.on("exec", async (accept, reject, info) => {
|
||||
const stream = accept();
|
||||
|
||||
// Matches on ; and &&
|
||||
const commandsRecv = info.command.split(/;|&&/).map((i) => i.trim());
|
||||
const commandsRecv = info.command.split(/;|&&/).map(i => i.trim());
|
||||
|
||||
function println(...data: any[]) {
|
||||
function println(...data: unknown[]) {
|
||||
stream.write(format(...data).replaceAll("\n", "\r\n"));
|
||||
};
|
||||
}
|
||||
|
||||
for (const command of commandsRecv) {
|
||||
const argv = parseArgsStringToArgv(command);
|
||||
|
||||
|
||||
if (argv[0] == "exit") {
|
||||
stream.close();
|
||||
} else {
|
||||
const command = commands.find(i => i.name == argv[0]);
|
||||
|
||||
|
||||
if (!command) {
|
||||
stream.write(
|
||||
`Unknown command ${argv[0]}.\r\n`,
|
||||
);
|
||||
stream.write(`Unknown command ${argv[0]}.\r\n`);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
await command.run(argv, println, axios, token, (disableEcho) => readFromKeyboard(stream, disableEcho));
|
||||
|
||||
await command.run(argv, println, axios, token, disableEcho =>
|
||||
readFromKeyboard(stream, disableEcho),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return stream.close();
|
||||
});
|
||||
|
||||
|
@ -123,26 +125,28 @@ server.on("connection", client => {
|
|||
"Welcome to NextNet LOM. Run 'help' to see commands.\r\n\r\n~$ ",
|
||||
);
|
||||
|
||||
function println(...data: any[]) {
|
||||
function println(...data: unknown[]) {
|
||||
stream.write(format(...data).replaceAll("\n", "\r\n"));
|
||||
};
|
||||
}
|
||||
|
||||
// FIXME (greysoh): wtf? this isn't setting correctly.
|
||||
// @eslint-disable-next-line
|
||||
while (true) {
|
||||
const line = await readFromKeyboard(stream);
|
||||
stream.write("\r\n");
|
||||
|
||||
|
||||
if (line == "") {
|
||||
stream.write(`~$ `);
|
||||
continue;
|
||||
}
|
||||
|
||||
const argv = parseArgsStringToArgv(line);
|
||||
|
||||
|
||||
if (argv[0] == "exit") {
|
||||
stream.close();
|
||||
} else {
|
||||
const command = commands.find(i => i.name == argv[0]);
|
||||
|
||||
|
||||
if (!command) {
|
||||
stream.write(
|
||||
`Unknown command ${argv[0]}. Run 'help' to see commands.\r\n~$ `,
|
||||
|
@ -150,8 +154,10 @@ server.on("connection", client => {
|
|||
|
||||
continue;
|
||||
}
|
||||
|
||||
await command.run(argv, println, axios, token, (disableEcho) => readFromKeyboard(stream, disableEcho));
|
||||
|
||||
await command.run(argv, println, axios, token, disableEcho =>
|
||||
readFromKeyboard(stream, disableEcho),
|
||||
);
|
||||
stream.write("~$ ");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue