fix: sudo incorrect styling and remove expiration date
This commit is contained in:
@@ -211,7 +211,6 @@ async function initializeCompleteDatabase(): Promise<void> {
|
||||
docker_config TEXT,
|
||||
terminal_config TEXT,
|
||||
notes TEXT,
|
||||
expiration_date TEXT,
|
||||
use_socks5 INTEGER,
|
||||
socks5_host TEXT,
|
||||
socks5_port INTEGER,
|
||||
@@ -578,7 +577,6 @@ const migrateSchema = () => {
|
||||
addColumnIfNotExists("ssh_data", "docker_config", "TEXT");
|
||||
|
||||
addColumnIfNotExists("ssh_data", "notes", "TEXT");
|
||||
addColumnIfNotExists("ssh_data", "expiration_date", "TEXT");
|
||||
|
||||
// SOCKS5 Proxy columns
|
||||
addColumnIfNotExists("ssh_data", "use_socks5", "INTEGER");
|
||||
|
||||
@@ -94,7 +94,6 @@ export const sshData = sqliteTable("ssh_data", {
|
||||
terminalConfig: text("terminal_config"),
|
||||
quickActions: text("quick_actions"),
|
||||
notes: text("notes"),
|
||||
expirationDate: text("expiration_date"),
|
||||
|
||||
useSocks5: integer("use_socks5", { mode: "boolean" }),
|
||||
socks5Host: text("socks5_host"),
|
||||
|
||||
@@ -256,7 +256,6 @@ router.post(
|
||||
terminalConfig,
|
||||
forceKeyboardInteractive,
|
||||
notes,
|
||||
expirationDate,
|
||||
useSocks5,
|
||||
socks5Host,
|
||||
socks5Port,
|
||||
@@ -316,7 +315,6 @@ router.post(
|
||||
terminalConfig: terminalConfig ? JSON.stringify(terminalConfig) : null,
|
||||
forceKeyboardInteractive: forceKeyboardInteractive ? "true" : "false",
|
||||
notes: notes || null,
|
||||
expirationDate: expirationDate || null,
|
||||
useSocks5: useSocks5 ? 1 : 0,
|
||||
socks5Host: socks5Host || null,
|
||||
socks5Port: socks5Port || null,
|
||||
@@ -508,7 +506,6 @@ router.put(
|
||||
terminalConfig,
|
||||
forceKeyboardInteractive,
|
||||
notes,
|
||||
expirationDate,
|
||||
useSocks5,
|
||||
socks5Host,
|
||||
socks5Port,
|
||||
@@ -518,9 +515,6 @@ router.put(
|
||||
overrideCredentialUsername,
|
||||
} = hostData;
|
||||
|
||||
// Temporary logging to debug notes and expirationDate
|
||||
console.log("DEBUG - Update host data:", { notes, expirationDate });
|
||||
|
||||
if (
|
||||
!isNonEmptyString(userId) ||
|
||||
!isNonEmptyString(ip) ||
|
||||
@@ -566,7 +560,6 @@ router.put(
|
||||
terminalConfig: terminalConfig ? JSON.stringify(terminalConfig) : null,
|
||||
forceKeyboardInteractive: forceKeyboardInteractive ? "true" : "false",
|
||||
notes: notes || null,
|
||||
expirationDate: expirationDate || null,
|
||||
useSocks5: useSocks5 ? 1 : 0,
|
||||
socks5Host: socks5Host || null,
|
||||
socks5Port: socks5Port || null,
|
||||
@@ -773,7 +766,6 @@ router.get(
|
||||
overrideCredentialUsername: sshData.overrideCredentialUsername,
|
||||
quickActions: sshData.quickActions,
|
||||
notes: sshData.notes,
|
||||
expirationDate: sshData.expirationDate,
|
||||
enableDocker: sshData.enableDocker,
|
||||
useSocks5: sshData.useSocks5,
|
||||
socks5Host: sshData.socks5Host,
|
||||
@@ -1677,15 +1669,21 @@ async function resolveHostCredentials(
|
||||
|
||||
if (credentials.length > 0) {
|
||||
const credential = credentials[0];
|
||||
return {
|
||||
const resolvedHost: Record<string, unknown> = {
|
||||
...host,
|
||||
username: credential.username,
|
||||
authType: credential.auth_type || credential.authType,
|
||||
password: credential.password,
|
||||
key: credential.key,
|
||||
keyPassword: credential.key_password || credential.keyPassword,
|
||||
keyType: credential.key_type || credential.keyType,
|
||||
};
|
||||
|
||||
// Only override username if overrideCredentialUsername is not enabled
|
||||
if (!host.overrideCredentialUsername) {
|
||||
resolvedHost.username = credential.username;
|
||||
}
|
||||
|
||||
return resolvedHost;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@ export function useConfirmation() {
|
||||
},
|
||||
duration: 10000,
|
||||
className: variant === "destructive" ? "border-red-500" : "",
|
||||
actionButtonStyle: { marginLeft: "0.1rem" },
|
||||
cancelButtonStyle: { marginRight: "0.1rem" },
|
||||
});
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
@@ -65,7 +67,8 @@ export function useConfirmation() {
|
||||
const options = opts as ConfirmationOptions;
|
||||
const actionText = options.confirmText || "Confirm";
|
||||
const cancelText = options.cancelText || "Cancel";
|
||||
const variantClass = options.variant === "destructive" ? "border-red-500" : "";
|
||||
const variantClass =
|
||||
options.variant === "destructive" ? "border-red-500" : "";
|
||||
|
||||
toast(options.title, {
|
||||
description: options.description,
|
||||
|
||||
@@ -1617,7 +1617,7 @@
|
||||
"folder": "folder",
|
||||
"password": "password",
|
||||
"keyPassword": "key password",
|
||||
"notes": "Add notes about this host...",
|
||||
"notes": "add notes about this host...",
|
||||
"expirationDate": "Select expiration date",
|
||||
"pastePrivateKey": "Paste your private key here...",
|
||||
"pastePublicKey": "Paste your public key here...",
|
||||
|
||||
@@ -48,7 +48,6 @@ export interface SSHHost {
|
||||
statsConfig?: string | Record<string, unknown>;
|
||||
terminalConfig?: TerminalConfig;
|
||||
notes?: string;
|
||||
expirationDate?: string;
|
||||
|
||||
useSocks5?: boolean;
|
||||
socks5Host?: string;
|
||||
@@ -110,7 +109,6 @@ export interface SSHHostData {
|
||||
statsConfig?: string | Record<string, unknown>;
|
||||
terminalConfig?: TerminalConfig;
|
||||
notes?: string;
|
||||
expirationDate?: string;
|
||||
|
||||
// SOCKS5 Proxy configuration
|
||||
useSocks5?: boolean;
|
||||
|
||||
@@ -536,7 +536,6 @@ export function HostManagerEditor({
|
||||
)
|
||||
.default([]),
|
||||
notes: z.string().optional(),
|
||||
expirationDate: z.string().optional(),
|
||||
useSocks5: z.boolean().optional(),
|
||||
socks5Host: z.string().optional(),
|
||||
socks5Port: z.coerce.number().min(1).max(65535).optional(),
|
||||
@@ -643,7 +642,6 @@ export function HostManagerEditor({
|
||||
terminalConfig: DEFAULT_TERMINAL_CONFIG,
|
||||
forceKeyboardInteractive: false,
|
||||
notes: "",
|
||||
expirationDate: "",
|
||||
useSocks5: false,
|
||||
socks5Host: "",
|
||||
socks5Port: 1080,
|
||||
@@ -747,7 +745,6 @@ export function HostManagerEditor({
|
||||
},
|
||||
forceKeyboardInteractive: Boolean(cleanedHost.forceKeyboardInteractive),
|
||||
notes: cleanedHost.notes || "",
|
||||
expirationDate: cleanedHost.expirationDate || "",
|
||||
useSocks5: Boolean(cleanedHost.useSocks5),
|
||||
socks5Host: cleanedHost.socks5Host || "",
|
||||
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
|
||||
control={form.control}
|
||||
name="notes"
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import { useCommandHistory as useCommandHistoryHook } from "@/ui/hooks/useComman
|
||||
import { useCommandHistory } from "@/ui/desktop/apps/terminal/command-history/CommandHistoryContext.tsx";
|
||||
import { CommandAutocomplete } from "./command-history/CommandAutocomplete.tsx";
|
||||
import { SimpleLoader } from "@/ui/desktop/navigation/animations/SimpleLoader.tsx";
|
||||
import { SudoPasswordPopup } from "./SudoPasswordPopup.tsx";
|
||||
import { useConfirmation } from "@/hooks/use-confirmation.ts";
|
||||
|
||||
interface HostConfig {
|
||||
id?: number;
|
||||
@@ -93,6 +93,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
const { t } = useTranslation();
|
||||
const { instance: terminal, ref: xtermRef } = useXTerm();
|
||||
const commandHistoryContext = useCommandHistory();
|
||||
const { confirmWithToast } = useConfirmation();
|
||||
|
||||
const config = { ...DEFAULT_TERMINAL_CONFIG, ...hostConfig.terminalConfig };
|
||||
const themeColors =
|
||||
@@ -174,7 +175,6 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
const [showHistoryDialog, setShowHistoryDialog] = useState(false);
|
||||
const [commandHistory, setCommandHistory] = useState<string[]>([]);
|
||||
const [isLoadingHistory, setIsLoadingHistory] = useState(false);
|
||||
const [showSudoPasswordPopup, setShowSudoPasswordPopup] = useState(false);
|
||||
|
||||
const setIsLoadingRef = useRef(commandHistoryContext.setIsLoading);
|
||||
const setCommandHistoryContextRef = useRef(
|
||||
@@ -214,7 +214,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
|
||||
useEffect(() => {
|
||||
const autocompleteEnabled =
|
||||
localStorage.getItem("commandAutocomplete") !== "false";
|
||||
localStorage.getItem("commandAutocomplete") === "true";
|
||||
|
||||
if (hostConfig.id && autocompleteEnabled) {
|
||||
import("@/ui/main-axios.ts")
|
||||
@@ -244,6 +244,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
}, [autocompleteSelectedIndex]);
|
||||
|
||||
const activityLoggingRef = useRef(false);
|
||||
const sudoPromptShownRef = useRef(false);
|
||||
|
||||
const lastSentSizeRef = 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") {
|
||||
terminal.write(msg.data);
|
||||
// Sudo password prompt detection
|
||||
const sudoPasswordPattern = /(?:\[sudo\] password for \S+:|sudo: a password is required)/;
|
||||
if (config.sudoPasswordAutoFill && sudoPasswordPattern.test(msg.data)) {
|
||||
setShowSudoPasswordPopup(true);
|
||||
const sudoPasswordPattern =
|
||||
/(?:\[sudo\] password for \S+:|sudo: a password is required)/;
|
||||
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 {
|
||||
terminal.write(String(msg.data));
|
||||
@@ -964,9 +993,8 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
if (!hostConfig.id) return;
|
||||
|
||||
try {
|
||||
const { deleteCommandFromHistory } = await import(
|
||||
"@/ui/main-axios.ts"
|
||||
);
|
||||
const { deleteCommandFromHistory } =
|
||||
await import("@/ui/main-axios.ts");
|
||||
await deleteCommandFromHistory(hostConfig.id, command);
|
||||
|
||||
setCommandHistory((prev) => {
|
||||
@@ -1095,22 +1123,6 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
navigator.platform.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 (
|
||||
config.backspaceMode === "control-h" &&
|
||||
e.key === "Backspace" &&
|
||||
@@ -1301,7 +1313,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
e.stopPropagation();
|
||||
|
||||
const autocompleteEnabled =
|
||||
localStorage.getItem("commandAutocomplete") !== "false";
|
||||
localStorage.getItem("commandAutocomplete") === "true";
|
||||
|
||||
if (!autocompleteEnabled) {
|
||||
if (webSocketRef.current?.readyState === 1) {
|
||||
@@ -1507,19 +1519,6 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
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
|
||||
visible={isConnecting}
|
||||
message={t("terminal.connecting")}
|
||||
|
||||
@@ -101,7 +101,7 @@ export function UserProfile({
|
||||
localStorage.getItem("fileColorCoding") !== "false",
|
||||
);
|
||||
const [commandAutocomplete, setCommandAutocomplete] = useState<boolean>(
|
||||
localStorage.getItem("commandAutocomplete") !== "false",
|
||||
localStorage.getItem("commandAutocomplete") === "true",
|
||||
);
|
||||
const [defaultSnippetFoldersCollapsed, setDefaultSnippetFoldersCollapsed] =
|
||||
useState<boolean>(
|
||||
|
||||
@@ -927,7 +927,6 @@ export async function createSSHHost(hostData: SSHHostData): Promise<SSHHost> {
|
||||
terminalConfig: hostData.terminalConfig || null,
|
||||
forceKeyboardInteractive: Boolean(hostData.forceKeyboardInteractive),
|
||||
notes: hostData.notes || "",
|
||||
expirationDate: hostData.expirationDate || "",
|
||||
useSocks5: Boolean(hostData.useSocks5),
|
||||
socks5Host: hostData.socks5Host || null,
|
||||
socks5Port: hostData.socks5Port || null,
|
||||
@@ -1002,7 +1001,6 @@ export async function updateSSHHost(
|
||||
terminalConfig: hostData.terminalConfig || null,
|
||||
forceKeyboardInteractive: Boolean(hostData.forceKeyboardInteractive),
|
||||
notes: hostData.notes || "",
|
||||
expirationDate: hostData.expirationDate || "",
|
||||
useSocks5: Boolean(hostData.useSocks5),
|
||||
socks5Host: hostData.socks5Host || null,
|
||||
socks5Port: hostData.socks5Port || null,
|
||||
|
||||
Reference in New Issue
Block a user