various logging tweaks for admin commands

This commit is contained in:
Gunter Labes 2009-08-01 11:27:26 +00:00
parent 9a2b2d71e8
commit 9293f41da4

View File

@ -581,7 +581,9 @@ void server::run() {
// Process commands from the server socket/fifo
std::string admin_cmd;
if (input_ && input_->read_line(admin_cmd)) {
process_command(admin_cmd, "*socket*");
LOG_SERVER << "Admin Command: type: " << admin_cmd;
const std::string res = process_command(admin_cmd, "*socket*");
LOG_SERVER << "[admin_command_response]\n" << res << "\n" << "[/admin_command_response]\n";
}
time_t now = time(NULL);
@ -1205,7 +1207,6 @@ void server::start_new_server() {
std::string server::process_command(std::string query, std::string issuer_name) {
std::ostringstream out;
std::string log_prefix;
if (issuer_name == "*socket*" && query.at(0) == '+') {
// The first argument might be "+<issuer>: ".
// In that case we use +<issuer>+ as the issuer_name.
@ -1217,7 +1218,6 @@ std::string server::process_command(std::string query, std::string issuer_name)
issuer_name = "+" + issuer + "+";
query = std::string(issuer_end + 1, query.end());
utils::strip(query);
log_prefix = "admin_command_response: ";
}
}
const std::string::iterator i = std::find(query.begin(),query.end(),' ');
@ -1233,9 +1233,10 @@ std::string server::process_command(std::string query, std::string issuer_name)
" unban <ipmask>\n"
"Specific strings (those not inbetween <> like the command names)"
" are case insensitive.";
const std::string denied_msg = "You're not allowed to execute this command.";
// Shutdown, restart and sample commands can only be issued via the socket.
if (command == "shut_down") {
if (issuer_name != "*socket*" && !allow_remote_shutdown_) return "";
if (issuer_name != "*socket*" && !allow_remote_shutdown_) return denied_msg;
if (parameters == "now") {
throw network::error("shut down");
} else {
@ -1247,11 +1248,10 @@ std::string server::process_command(std::string query, std::string issuer_name)
out << "Server is doing graceful shut down.";
}
} else if (command == "restart") {
if (issuer_name != "*socket*" && !allow_remote_shutdown_) return "";
if (issuer_name != "*socket*" && !allow_remote_shutdown_) return denied_msg;
if (restart_command.empty()) {
out << "No restart_command configured! Not restarting.";
} else {
LOG_SERVER << "Graceful restart requested.";
graceful_restart = true;
// stop listening socket
server_.stop();
@ -1266,7 +1266,7 @@ std::string server::process_command(std::string query, std::string issuer_name)
out << "Current sample frequency: " << request_sample_frequency;
return out.str();
} else if (issuer_name != "*socket*") {
return "";
return denied_msg;
}
request_sample_frequency = atoi(parameters.c_str());
if (request_sample_frequency <= 0) {
@ -1581,7 +1581,6 @@ std::string server::process_command(std::string query, std::string issuer_name)
out << "Command '" << command << "' is not recognized.\n" << help_msg;
}
LOG_SERVER << log_prefix << out.str() << "\n";
return out.str();
}