Server ssh works!!
This commit is contained in:
@ -270,6 +270,10 @@ bool service_runner::run_command(const std::string& command) {
|
||||
return uninstall();
|
||||
if (command == "backup")
|
||||
return backup();
|
||||
if (command == "ssh") {
|
||||
interactive_ssh_service();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Run the generic command
|
||||
std::string run_cmd = construct_standard_command_run_cmd(command);
|
||||
@ -480,4 +484,48 @@ std::string service_runner::healthmark()
|
||||
return HealthStatus2String(status);
|
||||
}
|
||||
|
||||
void interactive_ssh(const std::string & server_name, const std::string & command) {
|
||||
std::string serverpath = get_local_server_path(server_name);
|
||||
if (serverpath.empty()) {
|
||||
std::cerr << "Error: Server not found: " << server_name << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
server_env env(server_name);
|
||||
if (!env.is_valid()) {
|
||||
std::cerr << "Error: Invalid server environment file: " << server_name << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string ssh_address = env.get_SSH_HOST();
|
||||
std::string ssh_user = env.get_SSH_USER();
|
||||
std::string ssh_port = env.get_SSH_PORT();
|
||||
|
||||
std::string login = ssh_user + "@" + ssh_address;
|
||||
|
||||
// Execute ssh with server_name and command
|
||||
if (command.empty())
|
||||
execlp("ssh", "ssh", login.c_str(), "-p", ssh_port.c_str(), nullptr);
|
||||
else
|
||||
execlp("ssh", "ssh", login.c_str(), "-p", ssh_port.c_str(), command.c_str(), nullptr);
|
||||
|
||||
// If exec returns, it means there was an error
|
||||
perror("ssh execution failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void service_runner::interactive_ssh_service()
|
||||
{
|
||||
std::set<std::string> used_commands = get_used_commands(m_server_name, m_service_info.service_name);
|
||||
if (used_commands.find("ssh") == used_commands.end()) {
|
||||
std::cerr << "Error: "<< m_service_info.service_name <<" does not support ssh" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string command = construct_standard_command_run_cmd("ssh");
|
||||
interactive_ssh(m_server_name, command);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace dropshell
|
Reference in New Issue
Block a user