diff --git a/ShhShell/Host/Host.swift b/ShhShell/Host/Host.swift index c31e2ba..363510d 100644 --- a/ShhShell/Host/Host.swift +++ b/ShhShell/Host/Host.swift @@ -32,6 +32,7 @@ struct Host: HostPr { var password: String var privateKeyID: UUID? var key: String? + var startupSnippetID: UUID? var description: String { if name.isEmpty && address.isEmpty { diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index 028af07..1ccddb6 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -239,6 +239,7 @@ class HostsManager: ObservableObject, @unchecked Sendable { func duplicateHost(_ hostToDup: Host) { var hostNewID = hostToDup hostNewID.id = UUID() + hostNewID.name.append(" copy") if let index = hosts.firstIndex(where: { $0 == hostToDup }) { hosts.insert(hostNewID, at: index+1) Haptic.medium.trigger() diff --git a/ShhShell/SSH/SSHHandler.swift b/ShhShell/SSH/SSHHandler.swift index 25a6cc3..eacda5c 100644 --- a/ShhShell/SSH/SSHHandler.swift +++ b/ShhShell/SSH/SSHHandler.swift @@ -75,8 +75,6 @@ class SSHHandler: @unchecked Sendable, ObservableObject { } catch { print("auth with none is not authed") } guard state != .authorized else { return } - - for method in getAuthMethods() { guard state != .authorized else { break } switch method { diff --git a/ShhShell/Views/Hosts/ConnectionView.swift b/ShhShell/Views/Hosts/ConnectionView.swift index 545999d..561b438 100644 --- a/ShhShell/Views/Hosts/ConnectionView.swift +++ b/ShhShell/Views/Hosts/ConnectionView.swift @@ -57,6 +57,28 @@ struct ConnectionView: View { Text("None") .tag(nil as UUID?) } + .onAppear { + guard keyManager.keyIDs.contains(where: { $0 == handler.host.privateKeyID }) else { + handler.host.privateKeyID = nil + return + } + } + } + + Section() { + Picker("Startup Snippet", selection: $handler.host.startupSnippetID) { + ForEach(hostsManager.snippets) { snip in + Text(snip.name).tag(snip.id as UUID?) + } + Divider() + Text("None").tag(nil as UUID?) + } + .onAppear { + guard hostsManager.snippets.contains(where: { $0.id == handler.host.startupSnippetID }) else { + handler.host.startupSnippetID = nil + return + } + } } Button() { @@ -130,6 +152,9 @@ Hostkey fingerprint is \(handler.getHostkey() ?? "nil") Button() { handler.go() showTerminal = checkShell(handler.state) + if showTerminal { + handler.writeToChannel(hostsManager.snippets.first(where: { $0.id == handler.host.startupSnippetID })?.content) + } } label: { Label( handler.connected ? "Disconnect" : "Connect",