Files
Termix/scripts/patch-guacamole-lite.cjs
T

86 lines
2.6 KiB
JavaScript
Raw Normal View History

2026-05-28 22:29:20 -05:00
const fs = require("fs");
const path = require("path");
const filePath = path.join(
__dirname,
"..",
"node_modules",
"guacamole-lite",
"lib",
"GuacdClient.js",
);
if (!fs.existsSync(filePath)) {
console.log("[patch-guacamole-lite] File not found, skipping");
process.exit(0);
}
let content = fs.readFileSync(filePath, "utf8");
2026-05-28 22:05:25 -04:00
// Patch 1: version acceptance list
const oldVersionCheck = "if (version === '1_0_0' || version === '1_1_0') {";
const newVersionCheck =
2026-05-28 22:29:20 -05:00
"if (version === '1_0_0' || version === '1_1_0' || version === '1_3_0' || version === '1_5_0') {";
2026-05-28 22:05:25 -04:00
// Patch 2: timezone instruction must be sent for all protocols >= 1.1.0, not just 1.1.0
const oldTimezone = "if (protocolVersion === '1_1_0') {";
const newTimezone = "if (protocolVersion !== '1_0_0') {";
2026-06-04 15:16:53 -04:00
// Patch 3: send the `name` handshake instruction for protocol >= 1.3.0.
// The Guacamole protocol added the `name` instruction in 1.3.0 (an optional
// human-readable identifier for the joining user). guacd 1.6.0 began requiring
// it during the VNC handshake even when negotiating older protocol versions,
// causing connections to silently drop right after "User joined". See
// Termix-SSH/Support#567 and #734.
const oldConnect =
" this.sendInstruction(['connect'].concat(connectArgs));";
const newConnect =
" if (protocolVersion === '1_3_0' || protocolVersion === '1_5_0') {\n" +
" this.sendInstruction(['name', this.connectionSettings.name || 'guacamole-lite']);\n" +
" }\n" +
"\n" +
" this.sendInstruction(['connect'].concat(connectArgs));";
2026-05-28 22:05:25 -04:00
let patched = false;
if (!content.includes(newVersionCheck)) {
if (!content.includes(oldVersionCheck)) {
2026-06-04 15:16:53 -04:00
console.log(
"[patch-guacamole-lite] Version check target not found, skipping",
);
2026-05-28 22:05:25 -04:00
process.exit(0);
}
content = content.replace(oldVersionCheck, newVersionCheck);
patched = true;
}
if (!content.includes(newTimezone)) {
if (!content.includes(oldTimezone)) {
console.log("[patch-guacamole-lite] Timezone target not found, skipping");
process.exit(0);
}
content = content.replace(oldTimezone, newTimezone);
patched = true;
}
2026-06-04 15:16:53 -04:00
if (!content.includes(newConnect)) {
if (!content.includes(oldConnect)) {
console.log(
"[patch-guacamole-lite] Connect target not found, skipping name patch",
);
process.exit(0);
}
content = content.replace(oldConnect, newConnect);
patched = true;
}
2026-05-28 22:05:25 -04:00
if (!patched) {
2026-05-28 22:29:20 -05:00
console.log("[patch-guacamole-lite] Already patched");
process.exit(0);
}
fs.writeFileSync(filePath, content);
console.log(
2026-06-04 15:16:53 -04:00
"[patch-guacamole-lite] Patched to support protocol VERSION_1_3_0 and VERSION_1_5_0 with name handshake instruction",
2026-05-28 22:29:20 -05:00
);