/[sudobot]/trunk/scripts/log-client.js
ViewVC logotype

Contents of /trunk/scripts/log-client.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (show annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: text/javascript
File size: 1846 byte(s)
chore: add trunk
1 #!/usr/bin/env node
2
3 /*
4 * This file is part of SudoBot.
5 *
6 * Copyright (C) 2021-2023 OSN Developers.
7 *
8 * SudoBot is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * SudoBot is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 /*
23 * Required packages: socket.io-client
24 */
25
26 const io = require("socket.io-client");
27 const { createInterface } = require("readline/promises");
28
29 function error(message) {
30 console.error("Error:", message);
31 process.exit(1);
32 }
33
34 async function main() {
35 const colors = process.argv.includes("--color");
36 const url = process.argv[2];
37
38 if (!url) {
39 error("Please specify the Log Server hostname to connect!");
40 }
41
42 const readline = createInterface({
43 input: process.stdin,
44 output: process.stdout
45 });
46
47 const password = await readline.question("Password: ");
48 readline.close();
49
50 const client = io(url.startsWith("http://") ? url : `http://${url}`, {
51 extraHeaders: {
52 Authorization: `Bearer ${password}`,
53 "X-Colorize": colors ? "Yes" : "No"
54 }
55 });
56
57 console.log("Connecting to:", url);
58
59 client.on("open", () => {
60 console.log("Connection established. Streaming logs...");
61 });
62
63 client.on("message", event => {
64 console.log(event.toString());
65 });
66 }
67
68 main();

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26