bool SSH_Socket::onEnter() { // For testing and getting debugging output //int verb = SSH_LOG_PROTOCOL; int rc; // Setup new SSH Shell session = ssh_new(); if(session == nullptr) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Closed Session", "User has closed the program.", nullptr); TheSocketHandler::Instance()->setActive(false); return false; } std::cout << "Connecting to: " << host << ":" << port << std::endl; std::cout << "User: "******"Starting up SSH Connection, this can take few moments" << std::endl; // SSH Connect rc = ssh_connect(session); if(rc != SSH_OK) { std::cout << "Error: ssh_connect: " << host << " " << ssh_get_error(session) << std::endl; SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Closed Session", "Unable to Connect to Server!", nullptr); TheSocketHandler::Instance()->setActive(false); return false; } // Verify Server is a known host. rc = verify_knownhost(); if(rc < 0) { std::cout << "Error: verify_knownhost: " << host << " " << ssh_get_error(session) << " " << rc << std::endl; SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Closed Session", "User has closed the program.", nullptr); TheSocketHandler::Instance()->setActive(false); return false; } //if ((ssh_userauth_password(session, NULL, password) == SSH_AUTH_SUCCESS) rc = authenticate_console(); if(rc != SSH_AUTH_SUCCESS) { std::cout << "Error: authenticate: " << host << " " << ssh_get_error(session) << " " << rc << std::endl; TheSocketHandler::Instance()->setActive(false); return false; } // Setup Channel for Socket Communications sshChannel = ssh_channel_new(session); if(sshChannel == nullptr) { std::cout << "Error: ssh_channel_new: " << host << " " << ssh_get_error(session) << " " << rc << std::endl; TheSocketHandler::Instance()->setActive(false); return false; } // Open A shell Session rc = ssh_channel_open_session(sshChannel); if(rc != SSH_OK) { std::cout << "Error: ssh_channel_open_session: " << host << " " << ssh_get_error(session) << " " << rc << std::endl; TheSocketHandler::Instance()->setActive(false); return false; } /* Don't need this when we use the PTY size, it does both! // Setup sockets or "channels" within the session if(ssh_channel_request_pty(sshChannel)) { printf("\r\n SSH Error, Request for PTY Failed. %s: %s - %i \r\n", host, ssh_get_error(session), rc); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Closed Session", "User has closed the program.", NULL); onExit(); }*/ // Set the term and pty size of the terminal. // Only After the Shell has been initialized. if(ssh_channel_request_pty_size(sshChannel, "ansi", 80, 25)) { std::cout << "Error: ssh_channel_request_pty_size: " << host << " " << ssh_get_error(session) << " " << rc << std::endl; // Not an error to exit the connection on. //return 0; } // Now request a shell with the pty to get read/write if(ssh_channel_request_shell(sshChannel)) { std::cout << "Error: ssh_channel_request_shell: " << host << " " << ssh_get_error(session) << " " << rc << std::endl; TheSocketHandler::Instance()->setActive(false); return false; } return true; }
int channel_request_pty_size(ssh_channel channel, const char *term, int cols, int rows){ return ssh_channel_request_pty_size(channel, term, cols, rows); }