This commit is contained in:
Your Name
2025-04-21 11:47:07 +12:00
parent 0eacb838ce
commit a718f23375
11 changed files with 235 additions and 10 deletions

View File

@ -86,4 +86,67 @@ void list_servers() {
}
}
void show_server_details(const std::string& server_name) {
std::string user_dir;
if (!get_user_directory(user_dir)) {
std::cerr << "Error: User directory not set" << std::endl;
return;
}
fs::path server_dir = fs::path(user_dir) / "servers" / server_name;
if (!fs::exists(server_dir)) {
std::cerr << "Error: Server '" << server_name << "' not found" << std::endl;
return;
}
fs::path env_file = server_dir / "_server.env";
if (!fs::exists(env_file)) {
std::cerr << "Error: Server configuration file not found" << std::endl;
return;
}
std::cout << "Server Details: " << server_name << std::endl;
std::cout << std::string(40, '-') << std::endl;
std::ifstream file(env_file.string());
std::string line;
while (std::getline(file, line)) {
if (!line.empty() && line[0] != '#') {
std::cout << line << std::endl;
}
}
// Check if server is reachable via SSH
std::string ssh_address;
file.clear();
file.seekg(0);
while (std::getline(file, line)) {
if (boost::starts_with(line, "SSH_ADDRESS=")) {
ssh_address = line.substr(12);
break;
}
}
if (!ssh_address.empty()) {
std::cout << std::endl << "Server Status:" << std::endl;
std::cout << std::string(40, '-') << std::endl;
// Try to connect to the server
std::string cmd = "ssh -o ConnectTimeout=5 " + ssh_address + " 'echo connected' 2>/dev/null";
int result = system(cmd.c_str());
if (result == 0) {
std::cout << "Status: Online" << std::endl;
// Get uptime if possible
cmd = "ssh " + ssh_address + " 'uptime' 2>/dev/null";
int rval = system(cmd.c_str());
if (rval != 0) {
std::cout << "Error: Failed to get uptime" << std::endl;
}
} else {
std::cout << "Status: Offline" << std::endl;
}
}
}
} // namespace dropshell