mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-11-02 08: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>
216 lines
6.8 KiB
TypeScript
216 lines
6.8 KiB
TypeScript
import {
|
|
createCurrentCredentialRepository,
|
|
createCurrentHostResolutionRepository,
|
|
} from "../../database/repositories/factory.js";
|
|
import { hostTerminalExport } from "../../database/routes/host-normalizers.js";
|
|
import { loadHostPluginSettings } from "../../database/routes/host-plugin-settings.js";
|
|
import {
|
|
listProtocolLogins,
|
|
toPortableLogins,
|
|
} from "../protocol-auth/protocol-auth.js";
|
|
import { findHostProtocol } from "../protocol-auth/registry.js";
|
|
import { resolveHostCredentials } from "../resolve-host-credentials.js";
|
|
|
|
/**
|
|
* A share export leaves out every secret and credential link, the same as
|
|
* it does for SSH.
|
|
*/
|
|
function shareableLogins(
|
|
logins: ReturnType<typeof toPortableLogins>,
|
|
shareMode: boolean,
|
|
): ReturnType<typeof toPortableLogins> {
|
|
if (!shareMode) return logins;
|
|
const out: ReturnType<typeof toPortableLogins> = {};
|
|
for (const [protocol, login] of Object.entries(logins)) {
|
|
const declared = findHostProtocol(protocol);
|
|
const secret = new Set(
|
|
(declared?.credentialFields ?? [])
|
|
.filter((field) => field.secret)
|
|
.map((field) => field.key),
|
|
);
|
|
out[protocol] = {
|
|
authType: login.authType === "credential" ? "direct" : login.authType,
|
|
credentialId: null,
|
|
username: login.username,
|
|
password: null,
|
|
fields: Object.fromEntries(
|
|
Object.entries(login.fields).filter(
|
|
([key]) => declared && !secret.has(key),
|
|
),
|
|
),
|
|
};
|
|
}
|
|
return out;
|
|
}
|
|
|
|
type Row = Record<string, unknown>;
|
|
|
|
/** One host as the Termix JSON export carries it. */
|
|
async function exportRow(
|
|
host: Row,
|
|
userId: string,
|
|
shareMode: boolean,
|
|
pluginSettings: Awaited<ReturnType<typeof loadHostPluginSettings>>,
|
|
): Promise<{ data: Row; isRemoteDesktop: boolean; resolved: Row }> {
|
|
const resolvedHost = shareMode
|
|
? host
|
|
: (await resolveHostCredentials(host, userId)) || host;
|
|
const connectionType = (resolvedHost.connectionType as string) || "ssh";
|
|
const isRemoteDesktop = connectionType !== "ssh";
|
|
|
|
const base = {
|
|
exportId: resolvedHost.id,
|
|
connectionType,
|
|
name: resolvedHost.name,
|
|
ip: resolvedHost.ip,
|
|
port: resolvedHost.port,
|
|
username: resolvedHost.username,
|
|
password: shareMode ? null : resolvedHost.password || null,
|
|
folder: resolvedHost.folder,
|
|
tags:
|
|
typeof resolvedHost.tags === "string"
|
|
? resolvedHost.tags.split(",").filter(Boolean)
|
|
: resolvedHost.tags || [],
|
|
pin: !!resolvedHost.pin,
|
|
notes: resolvedHost.notes || null,
|
|
color: resolvedHost.color || null,
|
|
icon: resolvedHost.icon || null,
|
|
// Every plugin's host settings, secrets redacted, for import to hand back.
|
|
pluginSettings: pluginSettings.get(host.id as number) ?? {},
|
|
// Each plugin protocol's login, secrets included like the SSH ones.
|
|
protocolAuth: shareableLogins(
|
|
toPortableLogins(await listProtocolLogins(host.id as number, userId)),
|
|
shareMode,
|
|
),
|
|
};
|
|
|
|
if (isRemoteDesktop) {
|
|
return { data: base, isRemoteDesktop, resolved: resolvedHost };
|
|
}
|
|
|
|
const terminal = hostTerminalExport(resolvedHost);
|
|
const data = {
|
|
...base,
|
|
authType: resolvedHost.authType,
|
|
key: shareMode ? null : resolvedHost.key || null,
|
|
keyPassword: shareMode ? null : resolvedHost.keyPassword || null,
|
|
keyType: resolvedHost.keyType || null,
|
|
credentialId: resolvedHost.credentialId || null,
|
|
overrideCredentialUsername: !!resolvedHost.overrideCredentialUsername,
|
|
sudoPassword: shareMode ? null : resolvedHost.sudoPassword || null,
|
|
jumpHosts: resolvedHost.jumpHosts
|
|
? JSON.parse(resolvedHost.jumpHosts as string)
|
|
: null,
|
|
terminalConfig: terminal.terminalConfig ?? null,
|
|
sshOptions: terminal.sshOptions,
|
|
forceKeyboardInteractive: resolvedHost.forceKeyboardInteractive === "true",
|
|
useSocks5: !!resolvedHost.useSocks5,
|
|
socks5Host: resolvedHost.socks5Host || null,
|
|
socks5Port: resolvedHost.socks5Port || null,
|
|
socks5Username: resolvedHost.socks5Username || null,
|
|
socks5Password: shareMode ? null : resolvedHost.socks5Password || null,
|
|
socks5ProxyChain: resolvedHost.socks5ProxyChain
|
|
? JSON.parse(resolvedHost.socks5ProxyChain as string)
|
|
: null,
|
|
portKnockSequence: resolvedHost.portKnockSequence
|
|
? JSON.parse(resolvedHost.portKnockSequence as string)
|
|
: null,
|
|
};
|
|
return { data, isRemoteDesktop, resolved: resolvedHost };
|
|
}
|
|
|
|
export interface HostExport {
|
|
hosts: Row[];
|
|
/** Share mode only. */
|
|
version?: string;
|
|
exportedAt?: string;
|
|
credentials?: Row[];
|
|
}
|
|
|
|
/**
|
|
* All of the user's own hosts. Without shareMode credentials are decrypted and
|
|
* embedded. With it every secret is left out and credential logins point at a
|
|
* scrubbed credentials list by alias.
|
|
*/
|
|
export async function exportAllHosts(
|
|
userId: string,
|
|
shareMode: boolean,
|
|
hostIds?: number[],
|
|
): Promise<HostExport> {
|
|
const owned =
|
|
await createCurrentHostResolutionRepository().findHostsByUserId(userId);
|
|
const wanted = hostIds ? new Set(hostIds) : null;
|
|
const allHosts = wanted
|
|
? owned.filter((host) => wanted.has(host.id as number))
|
|
: owned;
|
|
const settings = await loadHostPluginSettings(
|
|
allHosts.map((h) => h.id as number),
|
|
);
|
|
|
|
const hosts: Row[] = [];
|
|
const usedCredentialIds = new Set<number>();
|
|
|
|
for (const host of allHosts) {
|
|
const { data, isRemoteDesktop, resolved } = await exportRow(
|
|
host as unknown as Row,
|
|
userId,
|
|
shareMode,
|
|
settings,
|
|
);
|
|
if (
|
|
shareMode &&
|
|
!isRemoteDesktop &&
|
|
resolved.authType === "credential" &&
|
|
resolved.credentialId
|
|
) {
|
|
usedCredentialIds.add(resolved.credentialId as number);
|
|
}
|
|
hosts.push(data);
|
|
}
|
|
|
|
if (!shareMode) return { hosts };
|
|
|
|
const credentials: Row[] = [];
|
|
if (usedCredentialIds.size > 0) {
|
|
const owned =
|
|
await createCurrentCredentialRepository().listDecryptedByUserId(userId);
|
|
const byId = new Map(
|
|
owned.map((credential) => [credential.id, credential]),
|
|
);
|
|
|
|
for (const host of hosts) {
|
|
const credentialId = host.credentialId as number | null;
|
|
if (!credentialId) continue;
|
|
const credential = byId.get(credentialId);
|
|
if (!credential) continue;
|
|
|
|
host.credentialAlias = credential.name;
|
|
|
|
if (!credentials.some((entry) => entry.alias === credential.name)) {
|
|
credentials.push({
|
|
alias: credential.name,
|
|
name: credential.name,
|
|
description: credential.description || null,
|
|
folder: credential.folder || null,
|
|
tags:
|
|
typeof credential.tags === "string"
|
|
? credential.tags.split(",").filter(Boolean)
|
|
: [],
|
|
authType: credential.authType,
|
|
username: credential.username || null,
|
|
keyType: credential.keyType || null,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
for (const host of hosts) delete host.credentialId;
|
|
|
|
return {
|
|
version: "1",
|
|
exportedAt: new Date().toISOString(),
|
|
credentials,
|
|
hosts,
|
|
};
|
|
}
|