levix-bot 4.9.1 → 4.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/dashboard/assets/index-4xhK_Tpl.js +561 -0
- package/public/dashboard/index.html +1 -1
- package/src/bootstrap/core.js +4 -0
- package/src/config/baileys.config.js +15 -2
- package/src/config/settings.cjs +17 -0
- package/src/core/connection.js +40 -1
- package/src/core/session.js +11 -2
- package/src/diagnostics/baileysLog.cjs +87 -0
- package/src/diagnostics/nodeRuntime.cjs +131 -0
- package/src/utils/logger.cjs +6 -0
- package/public/dashboard/assets/index-B1sOW2VX.js +0 -561
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
12
12
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
13
13
|
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Tajawal:wght@400;500;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
|
|
14
|
-
<script type="module" crossorigin src="/dashboard/assets/index-
|
|
14
|
+
<script type="module" crossorigin src="/dashboard/assets/index-4xhK_Tpl.js"></script>
|
|
15
15
|
<link rel="stylesheet" crossorigin href="/dashboard/assets/index-CK8osB4o.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|
package/src/bootstrap/core.js
CHANGED
|
@@ -41,6 +41,10 @@ export async function bootstrapCore({ autoStart = false } = {}) {
|
|
|
41
41
|
// the first one is using.
|
|
42
42
|
acquireSingleInstanceLock();
|
|
43
43
|
|
|
44
|
+
// Runtime, CA store and (when connection debug logging is on) every
|
|
45
|
+
// outbound socket. See src/diagnostics/nodeRuntime.cjs.
|
|
46
|
+
require("../diagnostics/nodeRuntime.cjs").installNodeDiagnostics();
|
|
47
|
+
|
|
44
48
|
// Temp media the commands write while answering lives with the rest of the
|
|
45
49
|
// bot's state, not next to the code.
|
|
46
50
|
ensureDataDir("media");
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { Browsers } from "@whiskeysockets/baileys";
|
|
2
|
+
import { createRequire } from "module";
|
|
2
3
|
import NodeCache from "node-cache";
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const settings = require("./settings.cjs");
|
|
7
|
+
const { createBaileysLogger } = require("../diagnostics/baileysLog.cjs");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Baileys writes into the sanitized debug log at the operator's chosen level,
|
|
11
|
+
* through the shaping in src/diagnostics/baileysLog.cjs. Read per socket, so a
|
|
12
|
+
* change applies on the next session start.
|
|
13
|
+
*/
|
|
14
|
+
export function baileysLogger() {
|
|
15
|
+
return createBaileysLogger(settings.get("connection_log_level") || "info");
|
|
16
|
+
}
|
|
4
17
|
|
|
5
18
|
// rc10 supports several pluggable caches; we keep them in-process so message
|
|
6
19
|
// retries / device discovery don't keep slamming the network.
|
|
@@ -31,7 +44,7 @@ export const BAILEYS_BROWSER_PAIRING = Browsers.macOS("Chrome");
|
|
|
31
44
|
export const getBaileysConfig = (cachedGroupMetadata, { pairingCode = false } = {}) => ({
|
|
32
45
|
browser: pairingCode ? BAILEYS_BROWSER_PAIRING : BAILEYS_BROWSER_QR,
|
|
33
46
|
markOnlineOnConnect: false,
|
|
34
|
-
logger:
|
|
47
|
+
logger: baileysLogger(),
|
|
35
48
|
cachedGroupMetadata,
|
|
36
49
|
version: [2, 3000, 1044062641],
|
|
37
50
|
|
package/src/config/settings.cjs
CHANGED
|
@@ -435,6 +435,23 @@ const SETTINGS = [
|
|
|
435
435
|
label: "Proxy password",
|
|
436
436
|
hint: "Stored like an API key: never sent back to this page, never logged.",
|
|
437
437
|
},
|
|
438
|
+
{
|
|
439
|
+
key: "connection_log_level",
|
|
440
|
+
type: "string",
|
|
441
|
+
default: "info",
|
|
442
|
+
choices: ["silent", "error", "warn", "info", "debug", "trace"],
|
|
443
|
+
choiceLabels: {
|
|
444
|
+
silent: "Off",
|
|
445
|
+
error: "Errors",
|
|
446
|
+
warn: "Warnings",
|
|
447
|
+
info: "Info",
|
|
448
|
+
debug: "Debug (detailed)",
|
|
449
|
+
trace: "Trace (every frame)",
|
|
450
|
+
},
|
|
451
|
+
group: "whatsapp",
|
|
452
|
+
label: "Connection debug logging",
|
|
453
|
+
hint: "How much Baileys and Node's network layer write to the sanitized debug log, which leaves the device only when you attach it to a crash report or feedback. Applies on the next session start. Trace records every protocol frame and fills the 5 MB daily cap fast.",
|
|
454
|
+
},
|
|
438
455
|
|
|
439
456
|
// --- Server ------------------------------------------------------------
|
|
440
457
|
{
|
package/src/core/connection.js
CHANGED
|
@@ -105,6 +105,43 @@ export function classifyDisconnect(statusCode) {
|
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* The facts inside a close, for the log. Baileys wraps a WebSocket error in a
|
|
110
|
+
* Boom whose default status is 500 and whose payload says only "Internal
|
|
111
|
+
* Server Error"; the useful part (a TLS, DNS or socket error) rides in
|
|
112
|
+
* `error.data`. No message content is ever in here.
|
|
113
|
+
*
|
|
114
|
+
* @param {any} error - `lastDisconnect.error`
|
|
115
|
+
*/
|
|
116
|
+
export function describeCloseError(error) {
|
|
117
|
+
if (!error || typeof error !== "object") return { detail: String(error ?? "") };
|
|
118
|
+
const cause = (e) =>
|
|
119
|
+
e && typeof e === "object"
|
|
120
|
+
? {
|
|
121
|
+
name: e.name,
|
|
122
|
+
detail: e.message,
|
|
123
|
+
code: e.code,
|
|
124
|
+
errno: e.errno,
|
|
125
|
+
syscall: e.syscall,
|
|
126
|
+
address: e.address,
|
|
127
|
+
port: e.port,
|
|
128
|
+
hostname: e.hostname,
|
|
129
|
+
reason: e.reason,
|
|
130
|
+
cause: e.cause?.message ?? e.cause?.code,
|
|
131
|
+
}
|
|
132
|
+
: e;
|
|
133
|
+
return {
|
|
134
|
+
name: error.name,
|
|
135
|
+
detail: error.message,
|
|
136
|
+
statusCode: error.output?.statusCode,
|
|
137
|
+
payload: error.output?.payload?.error,
|
|
138
|
+
data: cause(error.data),
|
|
139
|
+
cause: cause(error.cause),
|
|
140
|
+
stack:
|
|
141
|
+
typeof error.stack === "string" ? error.stack.split("\n").slice(0, 6).join("\n") : undefined,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
108
145
|
/**
|
|
109
146
|
* Everything that has to happen the moment a connection is open: record the
|
|
110
147
|
* paired account as an owner, seed the permission rosters, (re)start the
|
|
@@ -196,7 +233,9 @@ let lastFullGroupSyncAt = 0;
|
|
|
196
233
|
|
|
197
234
|
export async function cacheAllGroups(sock, { force = false, now = Date.now() } = {}) {
|
|
198
235
|
if (!force && lastFullGroupSyncAt && now - lastFullGroupSyncAt < GROUP_SYNC_TTL_MS) {
|
|
199
|
-
logger.info(
|
|
236
|
+
logger.info(
|
|
237
|
+
"[Cache] Recent full group sync is still fresh — skipping groupFetchAllParticipating",
|
|
238
|
+
);
|
|
200
239
|
return;
|
|
201
240
|
}
|
|
202
241
|
|
package/src/core/session.js
CHANGED
|
@@ -60,7 +60,7 @@ import {
|
|
|
60
60
|
pauseAllSchedules,
|
|
61
61
|
saveQrCode,
|
|
62
62
|
} from "../utils/storage.esm.js";
|
|
63
|
-
import { classifyDisconnect, handleConnectionOpen } from "./connection.js";
|
|
63
|
+
import { classifyDisconnect, describeCloseError, handleConnectionOpen } from "./connection.js";
|
|
64
64
|
import { setupEventListeners } from "./events.js";
|
|
65
65
|
import {
|
|
66
66
|
createProxyAgents,
|
|
@@ -265,6 +265,8 @@ export class WhatsAppSession {
|
|
|
265
265
|
emit = () => {},
|
|
266
266
|
retryDelaysMs = RETRY_SCHEDULE_MS,
|
|
267
267
|
log = logger,
|
|
268
|
+
// Detail that belongs only in the sanitized debug log.
|
|
269
|
+
debugLog = logger.debugOnly,
|
|
268
270
|
pairingCodeDelayMs = 1500,
|
|
269
271
|
isLinked = isPairedSession,
|
|
270
272
|
clearDirectory = clearAccountScopedState,
|
|
@@ -282,6 +284,7 @@ export class WhatsAppSession {
|
|
|
282
284
|
this.clearCredentials = clearCredentials;
|
|
283
285
|
this.retryDelaysMs = retryDelaysMs;
|
|
284
286
|
this.log = log;
|
|
287
|
+
this.debugLog = debugLog;
|
|
285
288
|
this.pairingCodeDelayMs = pairingCodeDelayMs;
|
|
286
289
|
}
|
|
287
290
|
|
|
@@ -867,8 +870,10 @@ export class WhatsAppSession {
|
|
|
867
870
|
|
|
868
871
|
async #onClose(lastDisconnect) {
|
|
869
872
|
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
873
|
+
// The message first: for a WebSocket error the payload is only the HTTP
|
|
874
|
+
// phrase for Boom's default 500, while the message names the real error.
|
|
870
875
|
const reasonText =
|
|
871
|
-
lastDisconnect?.error?.
|
|
876
|
+
lastDisconnect?.error?.message || lastDisconnect?.error?.output?.payload?.error || "Unknown";
|
|
872
877
|
|
|
873
878
|
this.#lastDisconnect = { statusCode: statusCode ?? null, reason: reasonText, at: Date.now() };
|
|
874
879
|
const closedSocket = this.#socket;
|
|
@@ -896,6 +901,10 @@ export class WhatsAppSession {
|
|
|
896
901
|
`[Session] Connection closed (${statusCode ?? "no status"}: ${reasonText}) — ${verdict.label}` +
|
|
897
902
|
(this.#proxyLabel ? ` via ${this.#proxyLabel}` : ""),
|
|
898
903
|
);
|
|
904
|
+
this.debugLog.warn(
|
|
905
|
+
{ close: describeCloseError(lastDisconnect?.error), verdict: verdict.reason },
|
|
906
|
+
"[Session] close detail",
|
|
907
|
+
);
|
|
899
908
|
|
|
900
909
|
if (this.#shuttingDown) return;
|
|
901
910
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// What Baileys may put in the debug log.
|
|
2
|
+
//
|
|
3
|
+
// Baileys logs whole protocol objects: binary nodes, their attrs (`notify`
|
|
4
|
+
// carries a contact's display name), the paired account (`me.name`), app-state
|
|
5
|
+
// patches (contacts, chat actions) and pushName updates. The debug log
|
|
6
|
+
// sanitizer strips JIDs, numbers and secret-named keys, but a display name or
|
|
7
|
+
// a group subject is ordinary text to it. So every Baileys record passes
|
|
8
|
+
// through these serializers first: the listed keys keep their structure (node
|
|
9
|
+
// tags, attribute names, sizes) and a short allowlist of protocol attribute
|
|
10
|
+
// values, and lose every other string.
|
|
11
|
+
|
|
12
|
+
const logger = require("../utils/logger.cjs");
|
|
13
|
+
|
|
14
|
+
// Top-level keys Baileys uses for protocol objects or personal data.
|
|
15
|
+
const SHAPED_KEYS = [
|
|
16
|
+
"node",
|
|
17
|
+
"groupNode",
|
|
18
|
+
"payload",
|
|
19
|
+
"payloadNode",
|
|
20
|
+
"data",
|
|
21
|
+
"updates",
|
|
22
|
+
"attrs",
|
|
23
|
+
"msgAttrs",
|
|
24
|
+
"content",
|
|
25
|
+
"child",
|
|
26
|
+
"fullErrorNode",
|
|
27
|
+
"reasonNode",
|
|
28
|
+
"uploadResult",
|
|
29
|
+
"helloMsg",
|
|
30
|
+
"me",
|
|
31
|
+
"name",
|
|
32
|
+
"xml",
|
|
33
|
+
"frame",
|
|
34
|
+
"msg",
|
|
35
|
+
"fullMessage",
|
|
36
|
+
"collections",
|
|
37
|
+
"errors",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// Protocol attribute values that explain a failure and name nobody.
|
|
41
|
+
const SAFE_VALUE_KEYS = new Set([
|
|
42
|
+
"tag",
|
|
43
|
+
"type",
|
|
44
|
+
"code",
|
|
45
|
+
"reason",
|
|
46
|
+
"class",
|
|
47
|
+
"xmlns",
|
|
48
|
+
"status",
|
|
49
|
+
"text_code",
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
const MAX_DEPTH = 4;
|
|
53
|
+
const MAX_ITEMS = 8;
|
|
54
|
+
|
|
55
|
+
/** Structure without personal text. */
|
|
56
|
+
function shape(value, depth = 0, key = "") {
|
|
57
|
+
if (value == null || typeof value === "number" || typeof value === "boolean") return value;
|
|
58
|
+
if (typeof value === "string") {
|
|
59
|
+
if (SAFE_VALUE_KEYS.has(key) && value.length <= 64) return value;
|
|
60
|
+
// binaryNodeToString output: keep the outer tag, drop everything inside.
|
|
61
|
+
const tag = /^<([\w:.-]{1,40})/.exec(value);
|
|
62
|
+
return tag ? `<${tag[1]}> [${value.length} chars]` : `[${value.length} chars]`;
|
|
63
|
+
}
|
|
64
|
+
if (typeof value === "bigint") return `[bigint]`;
|
|
65
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array) return `[${value.length} bytes]`;
|
|
66
|
+
if (typeof value !== "object") return `[${typeof value}]`;
|
|
67
|
+
if (depth >= MAX_DEPTH) return "[…]";
|
|
68
|
+
if (Array.isArray(value)) {
|
|
69
|
+
const items = value.slice(0, MAX_ITEMS).map((item) => shape(item, depth + 1));
|
|
70
|
+
if (value.length > MAX_ITEMS) items.push(`[+${value.length - MAX_ITEMS} more]`);
|
|
71
|
+
return items;
|
|
72
|
+
}
|
|
73
|
+
const out = {};
|
|
74
|
+
for (const [k, v] of Object.entries(value)) out[k] = shape(v, depth + 1, k);
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const serializers = Object.fromEntries(
|
|
79
|
+
SHAPED_KEYS.map((key) => [key, (value) => shape(value, 0, key)]),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
/** Baileys' logger: the debug log only, at `level`, with the shaping above. */
|
|
83
|
+
function createBaileysLogger(level) {
|
|
84
|
+
return logger.debugOnly.child({ module: "baileys" }, { level, serializers });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = { createBaileysLogger, shape, SHAPED_KEYS };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Node-level diagnostics for connection problems.
|
|
2
|
+
//
|
|
3
|
+
// Baileys reports most transport failures as one generic close. The facts that
|
|
4
|
+
// explain it (DNS, TCP, TLS and the CA store Node trusts) live one layer down,
|
|
5
|
+
// so this module writes them to the sanitized debug log (logger.debugOnly):
|
|
6
|
+
//
|
|
7
|
+
// - once at boot: the runtime and its certificate store
|
|
8
|
+
// - always: process warnings
|
|
9
|
+
// - when `connection_log_level` is debug or trace: every outbound socket's
|
|
10
|
+
// connect, TLS result and error, through node:diagnostics_channel
|
|
11
|
+
//
|
|
12
|
+
// Only hosts, ports, codes and TLS facts are logged. Never a request body.
|
|
13
|
+
|
|
14
|
+
const dc = require("node:diagnostics_channel");
|
|
15
|
+
const tls = require("node:tls");
|
|
16
|
+
|
|
17
|
+
const logger = require("../utils/logger.cjs");
|
|
18
|
+
const settings = require("../config/settings.cjs");
|
|
19
|
+
|
|
20
|
+
const log = logger.debugOnly.child({ module: "node" });
|
|
21
|
+
let installed = false;
|
|
22
|
+
|
|
23
|
+
function verbose() {
|
|
24
|
+
const level = settings.get("connection_log_level");
|
|
25
|
+
return level === "debug" || level === "trace";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function caCount(type) {
|
|
29
|
+
try {
|
|
30
|
+
return tls.getCACertificates?.(type)?.length ?? null;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return `error: ${error?.message}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function errorFacts(error) {
|
|
37
|
+
return {
|
|
38
|
+
name: error?.name,
|
|
39
|
+
detail: error?.message,
|
|
40
|
+
code: error?.code,
|
|
41
|
+
errno: error?.errno,
|
|
42
|
+
syscall: error?.syscall,
|
|
43
|
+
address: error?.address,
|
|
44
|
+
port: error?.port,
|
|
45
|
+
hostname: error?.hostname,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function onSocket({ socket }) {
|
|
50
|
+
if (!socket || !verbose()) return;
|
|
51
|
+
const started = Date.now();
|
|
52
|
+
const target = () => ({
|
|
53
|
+
host: socket.servername || socket._host,
|
|
54
|
+
remote: socket.remoteAddress,
|
|
55
|
+
port: socket.remotePort,
|
|
56
|
+
ms: Date.now() - started,
|
|
57
|
+
});
|
|
58
|
+
socket.once("lookup", (error, address, family, host) => {
|
|
59
|
+
if (error) log.debug({ host, err: errorFacts(error) }, "[net] DNS lookup failed");
|
|
60
|
+
else log.debug({ host, address, family }, "[net] DNS lookup");
|
|
61
|
+
});
|
|
62
|
+
socket.once("connect", () => log.debug(target(), "[net] TCP connected"));
|
|
63
|
+
socket.once("secureConnect", () => {
|
|
64
|
+
log.debug(
|
|
65
|
+
{
|
|
66
|
+
...target(),
|
|
67
|
+
authorized: socket.authorized,
|
|
68
|
+
authorizationError: socket.authorizationError?.toString?.() ?? socket.authorizationError,
|
|
69
|
+
protocol: socket.getProtocol?.(),
|
|
70
|
+
alpn: socket.alpnProtocol,
|
|
71
|
+
cipher: socket.getCipher?.()?.name,
|
|
72
|
+
issuer: socket.getPeerCertificate?.()?.issuer?.CN,
|
|
73
|
+
},
|
|
74
|
+
"[tls] handshake done",
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
socket.once("error", (error) =>
|
|
78
|
+
log.debug({ ...target(), err: errorFacts(error) }, "[net] socket error"),
|
|
79
|
+
);
|
|
80
|
+
socket.once("close", (hadError) => log.trace({ ...target(), hadError }, "[net] socket closed"));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function onRequestStart({ request }) {
|
|
84
|
+
if (!verbose()) return;
|
|
85
|
+
log.debug({ method: request?.method, host: request?.host }, "[http] request start");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function onRequestError({ request, error }) {
|
|
89
|
+
if (!verbose()) return;
|
|
90
|
+
log.debug({ host: request?.host, err: errorFacts(error) }, "[http] request failed");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function onResponse({ request, response }) {
|
|
94
|
+
if (!verbose()) return;
|
|
95
|
+
log.debug({ host: request?.host, status: response?.statusCode }, "[http] response");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Install once per process. Safe to call again. */
|
|
99
|
+
function installNodeDiagnostics() {
|
|
100
|
+
if (installed) return;
|
|
101
|
+
installed = true;
|
|
102
|
+
|
|
103
|
+
log.info(
|
|
104
|
+
{
|
|
105
|
+
node: process.version,
|
|
106
|
+
openssl: process.versions.openssl,
|
|
107
|
+
uv: process.versions.uv,
|
|
108
|
+
platform: process.platform,
|
|
109
|
+
arch: process.arch,
|
|
110
|
+
android: process.env.LEVIX_ANDROID === "1",
|
|
111
|
+
caBundled: caCount("bundled"),
|
|
112
|
+
caSystem: caCount("system"),
|
|
113
|
+
caDefault: caCount("default"),
|
|
114
|
+
extraCa: Boolean(process.env.NODE_EXTRA_CA_CERTS),
|
|
115
|
+
opensslConf: process.env.OPENSSL_CONF || null,
|
|
116
|
+
connectionLogLevel: settings.get("connection_log_level"),
|
|
117
|
+
},
|
|
118
|
+
"[runtime] Node runtime",
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
process.on("warning", (warning) => {
|
|
122
|
+
log.warn({ err: warning }, `[runtime] process warning: ${warning?.message}`);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
dc.subscribe("net.client.socket", onSocket);
|
|
126
|
+
dc.subscribe("http.client.request.start", onRequestStart);
|
|
127
|
+
dc.subscribe("http.client.request.error", onRequestError);
|
|
128
|
+
dc.subscribe("http.client.response.finish", onResponse);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = { installNodeDiagnostics };
|
package/src/utils/logger.cjs
CHANGED
|
@@ -65,6 +65,12 @@ const logger = pino(
|
|
|
65
65
|
]),
|
|
66
66
|
);
|
|
67
67
|
|
|
68
|
+
// Writes only to the sanitized debug log: never combined.log, error.log or the
|
|
69
|
+
// console. For detail that matters only when diagnosing (Baileys, Node's
|
|
70
|
+
// network layer), and that leaves the device only inside an operator-sent
|
|
71
|
+
// crash report or feedback with diagnostics ticked.
|
|
72
|
+
logger.debugOnly = pino(base, debugLog.stream);
|
|
73
|
+
|
|
68
74
|
const MAX_READ_BYTES = 256 * 1024;
|
|
69
75
|
|
|
70
76
|
/** Read only the bounded tail of the operational log, never arbitrary files. */
|