ok mb before, but it fking works!!!!!
like i can login to my mac from sshshell come on
just need to figure out how to type and what to do with all the [0m]133;B[?25h[?2004h
This commit is contained in:
neon443
2025-06-19 16:59:10 +01:00
parent 73adfd8fc8
commit 15615e76a4
2 changed files with 7 additions and 73 deletions

View File

@@ -57,7 +57,7 @@ class SSHHandler: ObservableObject {
self.host.key = getHostkey() self.host.key = getHostkey()
} }
var verbosity: Int = 0 var verbosity: Int = SSH_LOG_FUNCTIONS
session = ssh_new() session = ssh_new()
guard session != nil else { guard session != nil else {
@@ -228,59 +228,6 @@ class SSHHandler: ObservableObject {
return true 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..<nprompts {
// let prompt: UnsafePointer<CChar>
// 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<CChar> = .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 { func authWithNone() -> Bool {
let status = ssh_userauth_none(session, nil) let status = ssh_userauth_none(session, nil)
guard status == SSH_AUTH_SUCCESS.rawValue else { return false } guard status == SSH_AUTH_SUCCESS.rawValue else { return false }
@@ -339,27 +286,16 @@ class SSHHandler: ObservableObject {
private func interactiveShellSession() { private func interactiveShellSession() {
var status: CInt var status: CInt
status = ssh_channel_request_pty(channel) status = ssh_channel_request_pty(self.channel)
guard status == SSH_OK else { return } 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 } 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 } guard status == SSH_OK else { return }
// while ssh_channel_is_open(channel) != 0 && ssh_channel_is_eof(channel) == 0 { self.readTimer = Timer(timeInterval: 0.1, repeats: true) { timer in
// 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
guard ssh_channel_is_open(self.channel) != 0 else { guard ssh_channel_is_open(self.channel) != 0 else {
timer.invalidate() timer.invalidate()
self.readTimer = nil self.readTimer = nil
@@ -372,7 +308,7 @@ class SSHHandler: ObservableObject {
} }
self.readFromChannel() self.readFromChannel()
} }
RunLoop.main.add(readTimer!, forMode: .common) RunLoop.main.add(self.readTimer!, forMode: .common)
} }
func readFromChannel() { func readFromChannel() {

View File

@@ -97,9 +97,7 @@ struct ContentView: View {
} else { } else {
let _ = handler.authWithPw() let _ = handler.authWithPw()
} }
// DispatchQueue.main.asyncAfter(deadline: .now()+10) { handler.openShell()
handler.openShell()
// }
} label: { } label: {
Label("Connect", systemImage: "powerplug.portrait") Label("Connect", systemImage: "powerplug.portrait")
} }