mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-31 07:35:24 +00:00
* feat: let the login page send the token back to the mobile app * feat: add host-scripts entry to the plugin sdk * feat: let plugins say how they show in the mobile app * feat: frame host for running one plugin view outside the shell * fix: build the SDK host modules in production mode * chore: note the SDK host build fix in the changelog * feat: list plugin engine ranges for the mobile app * feat: host color and icon columns that sync * chore: update translations and plugin pins * fix: test * fix: show source address when rejecting proxy auth * fix: deleting your own account removes all of its data * fix(deps): update body-parser to 2.4.0 (#1736) * fix: body-parser 보안 패치 반영 * chore: 자동 검사를 막던 기존 JSON 서식 정리 --------- Co-authored-by: renovys <180682734+renovys@users.noreply.github.com> * fix(sdk): decode command output as GBK when it is not valid UTF-8 (#1735) * fix: honor shared credentials on shared hosts (#1730) * fix: honor shared credentials on shared hosts and in personal SSH auth * fix: snapshot shared SSH auth from a credential shared with the host owner * fix: size DataView list columns by the table's own width (#1713) * fix: size DataView list columns by the table's own width The list grid was built from every column, so columns hidden below md/lg left empty tracks and the visible cells landed under the wrong headers. Each width now gets a template of only its visible columns (CSS variables + container queries on the table, so a narrow panel counts, not the window), the header uses the same gap as the rows, and rows use a minimum height so wrapped cells no longer overlap. * test: wait for the title bar offset effect before asserting The bar shows once getTitleBarVisible resolves, but --termix-titlebar-height is set in a later passive effect, so reading it right after findByText raced (3-5 of 40 runs under load, on main too). * chore: rerun CI against dev-26.10.6 * fix: unlock passphrase keys once per connect burst (#1737) * feat: give ssh transports the host origin and sync id (#1717) * fix: wake other clients after a sync push (Plugin-Sync#1) * feat: look up local row ids by sync id for the sync plugin (Plugin-Sync#4) * feat: rail items can show a status dot (Plugin-Sync#5) * fix: add the desktop shared copy banner text (#1709) * feat: sidebar preference for alternating rows (#1712) * fix: striped rows text * feat: shell can open a saved host's editor for plugins (Plugin-SSH-Terminal#36) * fix: show the logo in the macos menu bar (#1728) * fix: number shortcuts skip the home tab (#1724) * fix: show plugins that could not be downloaded as failed (#1714) * fix: pass the host id as text when opening its editor * fix: retry a plugin bundle that was not ready yet (#1708) * fix: let commonjs plugins fall back to core packages on the desktop * fix: let non docker installs switch nginx to https (#1711) * feat: remove a folder share from its hosts too (#1719) * chore: changelog for merged pull requests * fix: accept the release .sig when installing a plugin from a file * feat: folder logins for shared hosts, read only plugin sync, full desktop builds * fix: test * fix: stop dev runner restart loops and narrow plugin watchers * chore: update translations and plugin pins * chore: lint, format, and bump version to 26.10.6 --------- Co-authored-by: renovys <renovy@gmail.com> Co-authored-by: renovys <180682734+renovys@users.noreply.github.com> Co-authored-by: Sebastian Cao <cycsmail@gmail.com> Co-authored-by: Jonathan Rehuel Lewerissa <jonathan.rehuel16@gmail.com> Co-authored-by: Rhiz3K <33246262+Rhiz3K@users.noreply.github.com>
119 lines
3.4 KiB
TypeScript
119 lines
3.4 KiB
TypeScript
/**
|
|
* Quoting, encoding and the error type the host scripts share.
|
|
*
|
|
* No Node APIs here: this entry also runs in the mobile app.
|
|
*/
|
|
|
|
/** A bad input to a host script builder. `status` is the HTTP status to answer with. */
|
|
export class HostScriptError extends Error {
|
|
constructor(
|
|
message: string,
|
|
readonly status = 400,
|
|
readonly extra: Record<string, unknown> = {},
|
|
) {
|
|
super(message);
|
|
this.name = "HostScriptError";
|
|
}
|
|
}
|
|
|
|
/** Wraps a value in single quotes for a POSIX shell. */
|
|
export function shellQuote(value: string): string {
|
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
}
|
|
|
|
// Written by hand because some JS engines (Hermes) have no TextDecoder.
|
|
|
|
/** UTF-8 bytes of a string. */
|
|
export function utf8Encode(text: string): Uint8Array {
|
|
const out: number[] = [];
|
|
for (const char of text) {
|
|
const cp = char.codePointAt(0) ?? 0xfffd;
|
|
if (cp < 0x80) out.push(cp);
|
|
else if (cp < 0x800) out.push(0xc0 | (cp >> 6), 0x80 | (cp & 63));
|
|
else if (cp < 0x10000) {
|
|
out.push(0xe0 | (cp >> 12), 0x80 | ((cp >> 6) & 63), 0x80 | (cp & 63));
|
|
} else {
|
|
out.push(
|
|
0xf0 | (cp >> 18),
|
|
0x80 | ((cp >> 12) & 63),
|
|
0x80 | ((cp >> 6) & 63),
|
|
0x80 | (cp & 63),
|
|
);
|
|
}
|
|
}
|
|
return Uint8Array.from(out);
|
|
}
|
|
|
|
/** A string from UTF-8 bytes. Bad sequences become U+FFFD. */
|
|
export function utf8Decode(bytes: ArrayLike<number>): string {
|
|
let out = "";
|
|
let i = 0;
|
|
while (i < bytes.length) {
|
|
const b = bytes[i];
|
|
let need = 0;
|
|
let cp = 0;
|
|
if (b < 0x80) cp = b;
|
|
else if (b >= 0xc2 && b < 0xe0) [need, cp] = [1, b & 31];
|
|
else if (b >= 0xe0 && b < 0xf0) [need, cp] = [2, b & 15];
|
|
else if (b >= 0xf0 && b < 0xf5) [need, cp] = [3, b & 7];
|
|
else {
|
|
out += "\ufffd";
|
|
i++;
|
|
continue;
|
|
}
|
|
let j = 1;
|
|
for (; j <= need; j++) {
|
|
const next = bytes[i + j];
|
|
if (next === undefined || (next & 0xc0) !== 0x80) break;
|
|
cp = (cp << 6) | (next & 63);
|
|
}
|
|
const tooSmall = [0, 0x80, 0x800, 0x10000][need];
|
|
if (
|
|
j <= need ||
|
|
cp < tooSmall ||
|
|
cp > 0x10ffff ||
|
|
(cp >= 0xd800 && cp < 0xe000)
|
|
) {
|
|
out += "\ufffd";
|
|
i += Math.max(1, j);
|
|
continue;
|
|
}
|
|
out += String.fromCodePoint(cp);
|
|
i += need + 1;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
/** Base64 of the UTF-8 bytes of a string, for `base64 -d` on the host. */
|
|
export function toBase64(text: string): string {
|
|
const bytes = utf8Encode(text);
|
|
let out = "";
|
|
for (let i = 0; i < bytes.length; i += 3) {
|
|
const a = bytes[i];
|
|
const b = i + 1 < bytes.length ? bytes[i + 1] : 0;
|
|
const c = i + 2 < bytes.length ? bytes[i + 2] : 0;
|
|
const n = (a << 16) | (b << 8) | c;
|
|
out += B64[(n >> 18) & 63] + B64[(n >> 12) & 63];
|
|
out += i + 1 < bytes.length ? B64[(n >> 6) & 63] : "=";
|
|
out += i + 2 < bytes.length ? B64[n & 63] : "=";
|
|
}
|
|
return out;
|
|
}
|
|
|
|
/** Reads key=value lines. Only the first = splits a line. */
|
|
export function parseKeys(output: string): Record<string, string> {
|
|
const out: Record<string, string> = {};
|
|
for (const line of output.split("\n")) {
|
|
const eq = line.indexOf("=");
|
|
if (eq > 0) out[line.slice(0, eq).trim()] = line.slice(eq + 1).trim();
|
|
}
|
|
return out;
|
|
}
|
|
|
|
/** Trims output and keeps it short enough to show. */
|
|
export function scrub(text: string, max = 600): string {
|
|
return text.trim().slice(0, max);
|
|
}
|