Files
TrollSSH/src/index.ts
T

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-02-12 13:39:42 +07:00
import fs from "fs";
import path from "path";
2026-07-13 15:12:04 +07:00
import { loadConfig, loadOptionalTextFile } from "./config";
import { ensureHostKeys } from "./hostKeys";
import { loadFrames } from "./frames";
import { createServer } from "./server";
import videoProcessor from "./videoProcessor";
2023-02-12 13:39:42 +07:00
async function main() {
2026-07-13 15:12:04 +07:00
const config = loadConfig();
const configDir = path.join(process.cwd(), "config");
2023-02-12 13:39:42 +07:00
2026-07-13 15:12:04 +07:00
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir);
2023-02-12 13:39:42 +07:00
}
2026-07-13 15:12:04 +07:00
const bannerText = loadOptionalTextFile(path.join(configDir, "banner.txt"));
const fakeLoginText = loadOptionalTextFile(
path.join(configDir, "fakelogin.txt")
);
const goodbyeText = loadOptionalTextFile(
path.join(configDir, "goodbye.txt")
);
2023-02-12 13:39:42 +07:00
2026-07-13 15:12:04 +07:00
ensureHostKeys(configDir);
const hostKey = fs.readFileSync(path.join(configDir, "id_rsa"));
2023-02-12 13:39:42 +07:00
2026-07-13 15:12:04 +07:00
const framesPath = path.join(configDir, "frames.json");
if (!fs.existsSync(framesPath)) {
2023-02-12 13:39:42 +07:00
console.error("frames.json not found!, generating frames.json...");
2026-07-13 15:12:04 +07:00
await videoProcessor.process("video.mp4", framesPath);
2023-02-12 13:39:42 +07:00
}
2026-07-13 15:12:04 +07:00
const videoData = loadFrames(framesPath);
2023-02-12 13:39:42 +07:00
console.log("Loaded frames");
2026-07-13 15:12:04 +07:00
const server = createServer({
config,
hostKey,
bannerText,
fakeLoginText,
goodbyeText,
videoData,
2023-02-12 13:39:42 +07:00
});
2026-07-13 15:12:04 +07:00
server.listen(config.port, config.host);
2023-02-12 13:39:42 +07:00
}
2026-07-13 15:12:04 +07:00
2023-02-12 13:39:42 +07:00
main();