fix: sudo incorrect styling and remove expiration date

This commit is contained in:
LukeGus
2025-12-20 01:15:25 -06:00
parent c104197dd6
commit b7fdb2143d
11 changed files with 1419 additions and 1531 deletions

View File

@@ -211,7 +211,6 @@ async function initializeCompleteDatabase(): Promise<void> {
docker_config TEXT, docker_config TEXT,
terminal_config TEXT, terminal_config TEXT,
notes TEXT, notes TEXT,
expiration_date TEXT,
use_socks5 INTEGER, use_socks5 INTEGER,
socks5_host TEXT, socks5_host TEXT,
socks5_port INTEGER, socks5_port INTEGER,
@@ -578,7 +577,6 @@ const migrateSchema = () => {
addColumnIfNotExists("ssh_data", "docker_config", "TEXT"); addColumnIfNotExists("ssh_data", "docker_config", "TEXT");
addColumnIfNotExists("ssh_data", "notes", "TEXT"); addColumnIfNotExists("ssh_data", "notes", "TEXT");
addColumnIfNotExists("ssh_data", "expiration_date", "TEXT");
// SOCKS5 Proxy columns // SOCKS5 Proxy columns
addColumnIfNotExists("ssh_data", "use_socks5", "INTEGER"); addColumnIfNotExists("ssh_data", "use_socks5", "INTEGER");

View File

@@ -94,7 +94,6 @@ export const sshData = sqliteTable("ssh_data", {
terminalConfig: text("terminal_config"), terminalConfig: text("terminal_config"),
quickActions: text("quick_actions"), quickActions: text("quick_actions"),
notes: text("notes"), notes: text("notes"),
expirationDate: text("expiration_date"),
useSocks5: integer("use_socks5", { mode: "boolean" }), useSocks5: integer("use_socks5", { mode: "boolean" }),
socks5Host: text("socks5_host"), socks5Host: text("socks5_host"),

View File

@@ -256,7 +256,6 @@ router.post(
terminalConfig, terminalConfig,
forceKeyboardInteractive, forceKeyboardInteractive,
notes, notes,
expirationDate,
useSocks5, useSocks5,
socks5Host, socks5Host,
socks5Port, socks5Port,
@@ -316,7 +315,6 @@ router.post(
terminalConfig: terminalConfig ? JSON.stringify(terminalConfig) : null, terminalConfig: terminalConfig ? JSON.stringify(terminalConfig) : null,
forceKeyboardInteractive: forceKeyboardInteractive ? "true" : "false", forceKeyboardInteractive: forceKeyboardInteractive ? "true" : "false",
notes: notes || null, notes: notes || null,
expirationDate: expirationDate || null,
useSocks5: useSocks5 ? 1 : 0, useSocks5: useSocks5 ? 1 : 0,
socks5Host: socks5Host || null, socks5Host: socks5Host || null,
socks5Port: socks5Port || null, socks5Port: socks5Port || null,
@@ -508,7 +506,6 @@ router.put(
terminalConfig, terminalConfig,
forceKeyboardInteractive, forceKeyboardInteractive,
notes, notes,
expirationDate,
useSocks5, useSocks5,
socks5Host, socks5Host,
socks5Port, socks5Port,
@@ -518,9 +515,6 @@ router.put(
overrideCredentialUsername, overrideCredentialUsername,
} = hostData; } = hostData;
// Temporary logging to debug notes and expirationDate
console.log("DEBUG - Update host data:", { notes, expirationDate });
if ( if (
!isNonEmptyString(userId) || !isNonEmptyString(userId) ||
!isNonEmptyString(ip) || !isNonEmptyString(ip) ||
@@ -566,7 +560,6 @@ router.put(
terminalConfig: terminalConfig ? JSON.stringify(terminalConfig) : null, terminalConfig: terminalConfig ? JSON.stringify(terminalConfig) : null,
forceKeyboardInteractive: forceKeyboardInteractive ? "true" : "false", forceKeyboardInteractive: forceKeyboardInteractive ? "true" : "false",
notes: notes || null, notes: notes || null,
expirationDate: expirationDate || null,
useSocks5: useSocks5 ? 1 : 0, useSocks5: useSocks5 ? 1 : 0,
socks5Host: socks5Host || null, socks5Host: socks5Host || null,
socks5Port: socks5Port || null, socks5Port: socks5Port || null,
@@ -773,7 +766,6 @@ router.get(
overrideCredentialUsername: sshData.overrideCredentialUsername, overrideCredentialUsername: sshData.overrideCredentialUsername,
quickActions: sshData.quickActions, quickActions: sshData.quickActions,
notes: sshData.notes, notes: sshData.notes,
expirationDate: sshData.expirationDate,
enableDocker: sshData.enableDocker, enableDocker: sshData.enableDocker,
useSocks5: sshData.useSocks5, useSocks5: sshData.useSocks5,
socks5Host: sshData.socks5Host, socks5Host: sshData.socks5Host,
@@ -1677,15 +1669,21 @@ async function resolveHostCredentials(
if (credentials.length > 0) { if (credentials.length > 0) {
const credential = credentials[0]; const credential = credentials[0];
return { const resolvedHost: Record<string, unknown> = {
...host, ...host,
username: credential.username,
authType: credential.auth_type || credential.authType, authType: credential.auth_type || credential.authType,
password: credential.password, password: credential.password,
key: credential.key, key: credential.key,
keyPassword: credential.key_password || credential.keyPassword, keyPassword: credential.key_password || credential.keyPassword,
keyType: credential.key_type || credential.keyType, keyType: credential.key_type || credential.keyType,
}; };
// Only override username if overrideCredentialUsername is not enabled
if (!host.overrideCredentialUsername) {
resolvedHost.username = credential.username;
}
return resolvedHost;
} }
} }

View File

@@ -56,6 +56,8 @@ export function useConfirmation() {
}, },
duration: 10000, duration: 10000,
className: variant === "destructive" ? "border-red-500" : "", className: variant === "destructive" ? "border-red-500" : "",
actionButtonStyle: { marginLeft: "0.1rem" },
cancelButtonStyle: { marginRight: "0.1rem" },
}); });
return Promise.resolve(true); return Promise.resolve(true);
} }
@@ -65,7 +67,8 @@ export function useConfirmation() {
const options = opts as ConfirmationOptions; const options = opts as ConfirmationOptions;
const actionText = options.confirmText || "Confirm"; const actionText = options.confirmText || "Confirm";
const cancelText = options.cancelText || "Cancel"; const cancelText = options.cancelText || "Cancel";
const variantClass = options.variant === "destructive" ? "border-red-500" : ""; const variantClass =
options.variant === "destructive" ? "border-red-500" : "";
toast(options.title, { toast(options.title, {
description: options.description, description: options.description,

View File

@@ -1617,7 +1617,7 @@
"folder": "folder", "folder": "folder",
"password": "password", "password": "password",
"keyPassword": "key password", "keyPassword": "key password",
"notes": "Add notes about this host...", "notes": "add notes about this host...",
"expirationDate": "Select expiration date", "expirationDate": "Select expiration date",
"pastePrivateKey": "Paste your private key here...", "pastePrivateKey": "Paste your private key here...",
"pastePublicKey": "Paste your public key here...", "pastePublicKey": "Paste your public key here...",

View File

@@ -48,7 +48,6 @@ export interface SSHHost {
statsConfig?: string | Record<string, unknown>; statsConfig?: string | Record<string, unknown>;
terminalConfig?: TerminalConfig; terminalConfig?: TerminalConfig;
notes?: string; notes?: string;
expirationDate?: string;
useSocks5?: boolean; useSocks5?: boolean;
socks5Host?: string; socks5Host?: string;
@@ -110,7 +109,6 @@ export interface SSHHostData {
statsConfig?: string | Record<string, unknown>; statsConfig?: string | Record<string, unknown>;
terminalConfig?: TerminalConfig; terminalConfig?: TerminalConfig;
notes?: string; notes?: string;
expirationDate?: string;
// SOCKS5 Proxy configuration // SOCKS5 Proxy configuration
useSocks5?: boolean; useSocks5?: boolean;

View File

@@ -536,7 +536,6 @@ export function HostManagerEditor({
) )
.default([]), .default([]),
notes: z.string().optional(), notes: z.string().optional(),
expirationDate: z.string().optional(),
useSocks5: z.boolean().optional(), useSocks5: z.boolean().optional(),
socks5Host: z.string().optional(), socks5Host: z.string().optional(),
socks5Port: z.coerce.number().min(1).max(65535).optional(), socks5Port: z.coerce.number().min(1).max(65535).optional(),
@@ -643,7 +642,6 @@ export function HostManagerEditor({
terminalConfig: DEFAULT_TERMINAL_CONFIG, terminalConfig: DEFAULT_TERMINAL_CONFIG,
forceKeyboardInteractive: false, forceKeyboardInteractive: false,
notes: "", notes: "",
expirationDate: "",
useSocks5: false, useSocks5: false,
socks5Host: "", socks5Host: "",
socks5Port: 1080, socks5Port: 1080,
@@ -747,7 +745,6 @@ export function HostManagerEditor({
}, },
forceKeyboardInteractive: Boolean(cleanedHost.forceKeyboardInteractive), forceKeyboardInteractive: Boolean(cleanedHost.forceKeyboardInteractive),
notes: cleanedHost.notes || "", notes: cleanedHost.notes || "",
expirationDate: cleanedHost.expirationDate || "",
useSocks5: Boolean(cleanedHost.useSocks5), useSocks5: Boolean(cleanedHost.useSocks5),
socks5Host: cleanedHost.socks5Host || "", socks5Host: cleanedHost.socks5Host || "",
socks5Port: cleanedHost.socks5Port || 1080, socks5Port: cleanedHost.socks5Port || 1080,
@@ -1389,26 +1386,6 @@ export function HostManagerEditor({
)} )}
/> />
<FormField
control={form.control}
name="expirationDate"
render={({ field }) => (
<FormItem className="col-span-10">
<FormLabel>{t("hosts.expirationDate")}</FormLabel>
<FormControl>
<Input
type="date"
placeholder={t("placeholders.expirationDate")}
value={field.value || ""}
onChange={field.onChange}
onBlur={field.onBlur}
name={field.name}
/>
</FormControl>
</FormItem>
)}
/>
<FormField <FormField
control={form.control} control={form.control}
name="notes" name="notes"

View File

@@ -1,82 +0,0 @@
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { KeyRound } from "lucide-react";
import { Button } from "@/components/ui/button.tsx";
interface SudoPasswordPopupProps {
isOpen: boolean;
hostPassword: string;
backgroundColor: string;
onConfirm: (password: string) => void;
onDismiss: () => void;
}
export function SudoPasswordPopup({
isOpen,
hostPassword,
backgroundColor,
onConfirm,
onDismiss
}: SudoPasswordPopupProps) {
const { t } = useTranslation();
useEffect(() => {
if (!isOpen) return;
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === "Enter") {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
onConfirm(hostPassword);
} else if (e.key === "Escape") {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
onDismiss();
}
};
window.addEventListener("keydown", handleKeyDown, true);
return () => window.removeEventListener("keydown", handleKeyDown, true);
}, [isOpen, onConfirm, onDismiss, hostPassword]);
if (!isOpen) return null;
return (
<div
className="absolute bottom-4 right-4 z-50 backdrop-blur-sm border border-border rounded-lg shadow-lg p-4 min-w-[280px]"
style={{ backgroundColor: backgroundColor }}
>
<div className="flex items-center gap-3 mb-3">
<div className="p-2 bg-primary/10 rounded-full">
<KeyRound className="h-5 w-5 text-primary" />
</div>
<div>
<h4 className="font-medium text-sm">
{t("terminal.sudoPasswordPopupTitle", "Insert password?")}
</h4>
<p className="text-xs text-muted-foreground">
{t("terminal.sudoPasswordPopupHint", "Press Enter to insert, Esc to dismiss")}
</p>
</div>
</div>
<div className="flex gap-2 justify-end">
<Button
variant="ghost"
size="sm"
onClick={onDismiss}
>
{t("terminal.sudoPasswordPopupDismiss", "Dismiss")}
</Button>
<Button
variant="default"
size="sm"
onClick={() => onConfirm(hostPassword)}
>
{t("terminal.sudoPasswordPopupConfirm", "Insert")}
</Button>
</div>
</div>
);
}

View File

@@ -32,7 +32,7 @@ import { useCommandHistory as useCommandHistoryHook } from "@/ui/hooks/useComman
import { useCommandHistory } from "@/ui/desktop/apps/terminal/command-history/CommandHistoryContext.tsx"; import { useCommandHistory } from "@/ui/desktop/apps/terminal/command-history/CommandHistoryContext.tsx";
import { CommandAutocomplete } from "./command-history/CommandAutocomplete.tsx"; import { CommandAutocomplete } from "./command-history/CommandAutocomplete.tsx";
import { SimpleLoader } from "@/ui/desktop/navigation/animations/SimpleLoader.tsx"; import { SimpleLoader } from "@/ui/desktop/navigation/animations/SimpleLoader.tsx";
import { SudoPasswordPopup } from "./SudoPasswordPopup.tsx"; import { useConfirmation } from "@/hooks/use-confirmation.ts";
interface HostConfig { interface HostConfig {
id?: number; id?: number;
@@ -93,6 +93,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
const { t } = useTranslation(); const { t } = useTranslation();
const { instance: terminal, ref: xtermRef } = useXTerm(); const { instance: terminal, ref: xtermRef } = useXTerm();
const commandHistoryContext = useCommandHistory(); const commandHistoryContext = useCommandHistory();
const { confirmWithToast } = useConfirmation();
const config = { ...DEFAULT_TERMINAL_CONFIG, ...hostConfig.terminalConfig }; const config = { ...DEFAULT_TERMINAL_CONFIG, ...hostConfig.terminalConfig };
const themeColors = const themeColors =
@@ -174,7 +175,6 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
const [showHistoryDialog, setShowHistoryDialog] = useState(false); const [showHistoryDialog, setShowHistoryDialog] = useState(false);
const [commandHistory, setCommandHistory] = useState<string[]>([]); const [commandHistory, setCommandHistory] = useState<string[]>([]);
const [isLoadingHistory, setIsLoadingHistory] = useState(false); const [isLoadingHistory, setIsLoadingHistory] = useState(false);
const [showSudoPasswordPopup, setShowSudoPasswordPopup] = useState(false);
const setIsLoadingRef = useRef(commandHistoryContext.setIsLoading); const setIsLoadingRef = useRef(commandHistoryContext.setIsLoading);
const setCommandHistoryContextRef = useRef( const setCommandHistoryContextRef = useRef(
@@ -214,7 +214,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
useEffect(() => { useEffect(() => {
const autocompleteEnabled = const autocompleteEnabled =
localStorage.getItem("commandAutocomplete") !== "false"; localStorage.getItem("commandAutocomplete") === "true";
if (hostConfig.id && autocompleteEnabled) { if (hostConfig.id && autocompleteEnabled) {
import("@/ui/main-axios.ts") import("@/ui/main-axios.ts")
@@ -244,6 +244,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
}, [autocompleteSelectedIndex]); }, [autocompleteSelectedIndex]);
const activityLoggingRef = useRef(false); const activityLoggingRef = useRef(false);
const sudoPromptShownRef = useRef(false);
const lastSentSizeRef = useRef<{ cols: number; rows: number } | null>(null); const lastSentSizeRef = useRef<{ cols: number; rows: number } | null>(null);
const pendingSizeRef = useRef<{ cols: number; rows: number } | null>(null); const pendingSizeRef = useRef<{ cols: number; rows: number } | null>(null);
@@ -663,9 +664,37 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
if (typeof msg.data === "string") { if (typeof msg.data === "string") {
terminal.write(msg.data); terminal.write(msg.data);
// Sudo password prompt detection // Sudo password prompt detection
const sudoPasswordPattern = /(?:\[sudo\] password for \S+:|sudo: a password is required)/; const sudoPasswordPattern =
if (config.sudoPasswordAutoFill && sudoPasswordPattern.test(msg.data)) { /(?:\[sudo\] password for \S+:|sudo: a password is required)/;
setShowSudoPasswordPopup(true); if (
config.sudoPasswordAutoFill &&
sudoPasswordPattern.test(msg.data) &&
hostConfig.password &&
!sudoPromptShownRef.current
) {
sudoPromptShownRef.current = true;
confirmWithToast(
t("terminal.sudoPasswordPopupTitle", "Insert password?"),
async () => {
if (
webSocketRef.current &&
webSocketRef.current.readyState === WebSocket.OPEN
) {
webSocketRef.current.send(
JSON.stringify({
type: "input",
data: hostConfig.password + "\n",
}),
);
}
setTimeout(() => {
sudoPromptShownRef.current = false;
}, 3000);
},
);
setTimeout(() => {
sudoPromptShownRef.current = false;
}, 15000);
} }
} else { } else {
terminal.write(String(msg.data)); terminal.write(String(msg.data));
@@ -964,9 +993,8 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
if (!hostConfig.id) return; if (!hostConfig.id) return;
try { try {
const { deleteCommandFromHistory } = await import( const { deleteCommandFromHistory } =
"@/ui/main-axios.ts" await import("@/ui/main-axios.ts");
);
await deleteCommandFromHistory(hostConfig.id, command); await deleteCommandFromHistory(hostConfig.id, command);
setCommandHistory((prev) => { setCommandHistory((prev) => {
@@ -1095,22 +1123,6 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
navigator.platform.toUpperCase().indexOf("MAC") >= 0 || navigator.platform.toUpperCase().indexOf("MAC") >= 0 ||
navigator.userAgent.toUpperCase().indexOf("MAC") >= 0; navigator.userAgent.toUpperCase().indexOf("MAC") >= 0;
if (
e.ctrlKey &&
e.key === "r" &&
!e.shiftKey &&
!e.altKey &&
!e.metaKey
) {
e.preventDefault();
e.stopPropagation();
setShowHistoryDialog(true);
if (commandHistoryContext.openCommandHistory) {
commandHistoryContext.openCommandHistory();
}
return false;
}
if ( if (
config.backspaceMode === "control-h" && config.backspaceMode === "control-h" &&
e.key === "Backspace" && e.key === "Backspace" &&
@@ -1301,7 +1313,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
e.stopPropagation(); e.stopPropagation();
const autocompleteEnabled = const autocompleteEnabled =
localStorage.getItem("commandAutocomplete") !== "false"; localStorage.getItem("commandAutocomplete") === "true";
if (!autocompleteEnabled) { if (!autocompleteEnabled) {
if (webSocketRef.current?.readyState === 1) { if (webSocketRef.current?.readyState === 1) {
@@ -1507,19 +1519,6 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
onSelect={handleAutocompleteSelect} onSelect={handleAutocompleteSelect}
/> />
<SudoPasswordPopup
isOpen={showSudoPasswordPopup}
hostPassword={hostConfig.password || ""}
backgroundColor={backgroundColor}
onConfirm={(password) => {
setShowSudoPasswordPopup(false);
if (webSocketRef.current && webSocketRef.current.readyState === WebSocket.OPEN) {
webSocketRef.current.send(JSON.stringify({ type: "input", data: password + "\n" }));
}
}}
onDismiss={() => setShowSudoPasswordPopup(false)}
/>
<SimpleLoader <SimpleLoader
visible={isConnecting} visible={isConnecting}
message={t("terminal.connecting")} message={t("terminal.connecting")}

View File

@@ -101,7 +101,7 @@ export function UserProfile({
localStorage.getItem("fileColorCoding") !== "false", localStorage.getItem("fileColorCoding") !== "false",
); );
const [commandAutocomplete, setCommandAutocomplete] = useState<boolean>( const [commandAutocomplete, setCommandAutocomplete] = useState<boolean>(
localStorage.getItem("commandAutocomplete") !== "false", localStorage.getItem("commandAutocomplete") === "true",
); );
const [defaultSnippetFoldersCollapsed, setDefaultSnippetFoldersCollapsed] = const [defaultSnippetFoldersCollapsed, setDefaultSnippetFoldersCollapsed] =
useState<boolean>( useState<boolean>(

View File

@@ -927,7 +927,6 @@ export async function createSSHHost(hostData: SSHHostData): Promise<SSHHost> {
terminalConfig: hostData.terminalConfig || null, terminalConfig: hostData.terminalConfig || null,
forceKeyboardInteractive: Boolean(hostData.forceKeyboardInteractive), forceKeyboardInteractive: Boolean(hostData.forceKeyboardInteractive),
notes: hostData.notes || "", notes: hostData.notes || "",
expirationDate: hostData.expirationDate || "",
useSocks5: Boolean(hostData.useSocks5), useSocks5: Boolean(hostData.useSocks5),
socks5Host: hostData.socks5Host || null, socks5Host: hostData.socks5Host || null,
socks5Port: hostData.socks5Port || null, socks5Port: hostData.socks5Port || null,
@@ -1002,7 +1001,6 @@ export async function updateSSHHost(
terminalConfig: hostData.terminalConfig || null, terminalConfig: hostData.terminalConfig || null,
forceKeyboardInteractive: Boolean(hostData.forceKeyboardInteractive), forceKeyboardInteractive: Boolean(hostData.forceKeyboardInteractive),
notes: hostData.notes || "", notes: hostData.notes || "",
expirationDate: hostData.expirationDate || "",
useSocks5: Boolean(hostData.useSocks5), useSocks5: Boolean(hostData.useSocks5),
socks5Host: hostData.socks5Host || null, socks5Host: hostData.socks5Host || null,
socks5Port: hostData.socks5Port || null, socks5Port: hostData.socks5Port || null,