From 15615e76a494d39a6645dba965d2dbadaf7295f5 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 19 Jun 2025 16:59:10 +0100 Subject: [PATCH] =?UTF-8?q?YESS=20ok=20mb=20before,=20but=20it=20fking=20w?= =?UTF-8?q?orks!!!!!=20like=20i=20can=20login=20to=20my=20mac=20from=20ssh?= =?UTF-8?q?shell=20come=20on=20just=20need=20to=20figure=20out=20how=20to?= =?UTF-8?q?=20type=20and=20what=20to=20do=20with=20all=20the=20[0m=1B[49m?= =?UTF-8?q?=1B[39m=1B]133;B=07=1B[K=1B[=3F25h=1B[=3F2004h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShhShell/SSH/SSHHandler.swift | 76 +++----------------------------- ShhShell/Views/ContentView.swift | 4 +- 2 files changed, 7 insertions(+), 73 deletions(-) diff --git a/ShhShell/SSH/SSHHandler.swift b/ShhShell/SSH/SSHHandler.swift index ffc5e4e..118101c 100644 --- a/ShhShell/SSH/SSHHandler.swift +++ b/ShhShell/SSH/SSHHandler.swift @@ -57,7 +57,7 @@ class SSHHandler: ObservableObject { self.host.key = getHostkey() } - var verbosity: Int = 0 + var verbosity: Int = SSH_LOG_FUNCTIONS session = ssh_new() guard session != nil else { @@ -228,59 +228,6 @@ class SSHHandler: ObservableObject { return true } -// func authWithKbInt() -> Bool { -// var status: CInt -// status = ssh_userauth_kbdint(session, nil, nil) -// while status == SSH_AUTH_INFO.rawValue { -// let name, instruction: String -// var nprompts: CInt -// -// if let namePtr = ssh_userauth_kbdint_getname(session) { -// name = String(cString: namePtr) -// } else { -// return false -// } -// if let instrPtr = ssh_userauth_kbdint_getinstruction(session) { -// instruction = String(cString: instrPtr) -// } else { -// return false -// } -// nprompts = ssh_userauth_kbdint_getnprompts(session) -// -// if name.count > 0 { -// print(name) -// } -// if instruction.count > 0 { -// print(instruction) -// } -// for promptI in 0.. -// var echo: CChar = 0 -// prompt = ssh_userauth_kbdint_getprompt(session, UInt32(promptI), &echo) -// if echo != 0 { -// var buffer: [CChar] = Array(repeating: 0, count: 128) -// let ptr: UnsafeMutablePointer = .init(mutating: buffer) -// print(prompt) -// if fgets(&buffer, Int32(MemoryLayout.size(ofValue: buffer)), stdin) == nil { -// return false -// } -// ptr.pointee = 0//prob fucked -// if ssh_userauth_kbdint_setanswer(session, UInt32(promptI), buffer) < 0 { -// return false -// } -// memset(&buffer, 0, buffer.count) -// } else { -// if (ssh_userauth_kbdint_setanswer(session, UInt32(promptI), &password) != 0) { -// return false -// } -// } -// } -// status = ssh_userauth_kbdint(session, nil, nil) -// } -// authorized = true -// return true -// } - func authWithNone() -> Bool { let status = ssh_userauth_none(session, nil) guard status == SSH_AUTH_SUCCESS.rawValue else { return false } @@ -339,27 +286,16 @@ class SSHHandler: ObservableObject { private func interactiveShellSession() { var status: CInt - status = ssh_channel_request_pty(channel) + status = ssh_channel_request_pty(self.channel) guard status == SSH_OK else { return } - status = ssh_channel_change_pty_size(channel, 80, 24) + status = ssh_channel_change_pty_size(self.channel, 80, 24) guard status == SSH_OK else { return } - status = ssh_channel_request_shell(channel) + status = ssh_channel_request_shell(self.channel) guard status == SSH_OK else { return } -// while ssh_channel_is_open(channel) != 0 && ssh_channel_is_eof(channel) == 0 { -// var buffer: [CChar] = Array(repeating: 0, count: 256) -// let nbytes = ssh_channel_read_nonblocking(channel, &buffer, UInt32(buffer.count), 0) -// -// guard nbytes > 0 else { return } -// write(1, buffer, Int(nbytes)) -// -// let data = Data(bytes: buffer, count: buffer.count) -// print(String(data: data, encoding: .utf8)!) -// } - - readTimer = Timer(timeInterval: 0.1, repeats: true) { timer in + self.readTimer = Timer(timeInterval: 0.1, repeats: true) { timer in guard ssh_channel_is_open(self.channel) != 0 else { timer.invalidate() self.readTimer = nil @@ -372,7 +308,7 @@ class SSHHandler: ObservableObject { } self.readFromChannel() } - RunLoop.main.add(readTimer!, forMode: .common) + RunLoop.main.add(self.readTimer!, forMode: .common) } func readFromChannel() { diff --git a/ShhShell/Views/ContentView.swift b/ShhShell/Views/ContentView.swift index 8a35d05..1f6c87f 100644 --- a/ShhShell/Views/ContentView.swift +++ b/ShhShell/Views/ContentView.swift @@ -97,9 +97,7 @@ struct ContentView: View { } else { let _ = handler.authWithPw() } -// DispatchQueue.main.asyncAfter(deadline: .now()+10) { - handler.openShell() -// } + handler.openShell() } label: { Label("Connect", systemImage: "powerplug.portrait") }