Changeset - 35c13f038f69
[Not reviewed]
0 4 0
Jan Kaluza - 13 years ago 2012-08-29 15:33:43
hanzz.k@gmail.com
Hidden password, allow seeting port
4 files changed with 6 insertions and 5 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/main.cpp
Show inline comments
 
@@ -130,25 +130,25 @@ int main(int argc, char **argv)
 
	}
 
	else if (command[0] == "stop") {
 
		stop_instances(&config);
 
	}
 
	else if (command[0] == "status") {
 
		return show_status(&config);
 
	}
 
	else if (command[0] == "list") {
 
		std::vector<std::string> list = show_list(&config);
 
	}
 
	else if (command[0] == "server") {
 
		Server server(&config);
 
		server.start(8080);
 
		server.start();
 
		while (1) { sleep(10); }
 
	}
 
	else {
 
		if (command.size() < 2) {
 
			std::cout << desc << "\n";
 
			return 11;
 
		}
 
		Swift::SimpleEventLoop eventLoop;
 
		Swift::BoostNetworkFactories networkFactories(&eventLoop);
 
 
		std::string jid = command[0];
 
		command.erase(command.begin());
spectrum_manager/src/managerconfig.cpp
Show inline comments
 
@@ -22,24 +22,25 @@
 
#include <fstream>
 

	
 
using namespace boost::program_options;
 

	
 
bool ManagerConfig::load(const std::string &configfile, boost::program_options::options_description &opts) {
 
	std::ifstream ifs(configfile.c_str());
 
	if (!ifs.is_open())
 
		return false;
 

	
 
	opts.add_options()
 
		("service.admin_username", value<std::string>()->default_value(""), "Administrator username.")
 
		("service.admin_password", value<std::string>()->default_value(""), "Administrator password.")
 
		("service.port", value<int>()->default_value(8081), "Web interface port.")
 
		("service.config_directory", value<std::string>()->default_value("/etc/spectrum2/transports/"), "Directory with spectrum2 configuration files. One .cfg file per one instance")
 
		("servers.server", value<std::vector<std::string> >()->multitoken(), "Server.")
 
	;
 

	
 
	store(parse_config_file(ifs, opts), m_variables);
 
	notify(m_variables);
 

	
 
	m_file = configfile;
 

	
 
	onManagerConfigReloaded();
 

	
 
	return true;
spectrum_manager/src/server.cpp
Show inline comments
 
@@ -149,27 +149,27 @@ Server::Server(ManagerConfig *config) {
 
}
 

	
 
Server::~Server() {
 
	mg_stop(ctx);
 
}
 

	
 

	
 
static void *_event_handler(enum mg_event event, struct mg_connection *conn) {
 
	const struct mg_request_info *request_info = mg_get_request_info(conn);
 
	return static_cast<Server *>(request_info->user_data)->event_handler(event, conn);
 
}
 

	
 
bool Server::start(int port) {
 
bool Server::start() {
 
	const char *options[] = {
 
		"listening_ports", boost::lexical_cast<std::string>(port).c_str(),
 
		"listening_ports", boost::lexical_cast<std::string>(CONFIG_INT(m_config, "service.port")).c_str(),
 
		"num_threads", "1",
 
		NULL
 
	};
 

	
 
	// Setup and start Mongoose
 
	if ((ctx = mg_start(&_event_handler, this, options)) == NULL) {
 
		return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
@@ -287,25 +287,25 @@ void Server::serve_login(struct mg_connection *conn, const struct mg_request_inf
 
  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \
 
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" dir=\"ltr\"> \
 
  <head>\
 
    <title>Spectrum 2 web interface</title>\
 
    <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\
 
  </head>\
 
  <body>\
 
    <center>\
 
      <h2>Spectrum 2 web interface login</h2>\
 
      <br/>\
 
      <form action=\"/authorize\">\
 
        Username: <input type=\"text\" name=\"user\"></input><br/>\
 
        Password: <input type=\"text\" name=\"password\"></input><br/>\
 
        Password: <input type=\"password\" name=\"password\"></input><br/>\
 
        <input type=\"submit\" value=\"Login\"></input>\
 
      </form>\
 
    </center>\
 
  </body>\
 
</html>";
 

	
 
	print_html(conn, request_info, html);
 
}
 

	
 
void Server::serve_onlineusers(struct mg_connection *conn, const struct mg_request_info *request_info) {
 
	std::string html = get_header();
 
	char jid[255];
spectrum_manager/src/server.h
Show inline comments
 
@@ -37,25 +37,25 @@ class Server {
 
			char session_id[33];      // Session ID, must be unique
 
			char random[20];          // Random data used for extra user validation
 
			char user[255];  // Authenticated user
 
			time_t expire;            // Expiration timestamp, UTC
 
		};
 

	
 
		/// Constructor.
 
		Server(ManagerConfig *config);
 

	
 
		/// Destructor
 
		virtual ~Server();
 

	
 
		bool start(int port);
 
		bool start();
 

	
 
		void *event_handler(enum mg_event event, struct mg_connection *conn);
 

	
 
	private:
 
		void serve_login(struct mg_connection *conn, const struct mg_request_info *request_info);
 
		void serve_root(struct mg_connection *conn, const struct mg_request_info *request_info);
 
		void serve_start(struct mg_connection *conn, const struct mg_request_info *request_info);
 
		void serve_stop(struct mg_connection *conn, const struct mg_request_info *request_info);
 
		void serve_onlineusers(struct mg_connection *conn, const struct mg_request_info *request_info);
 
		void serve_cmd(struct mg_connection *conn, const struct mg_request_info *request_info);
 
		void print_html(struct mg_connection *conn, const struct mg_request_info *request_info, const std::string &html);
 

	
0 comments (0 inline, 0 general)