Changeset - c4eda8c23b75
[Not reviewed]
0 3 0
Jan Kaluza - 10 years ago 2016-02-01 18:18:28
jkaluza@redhat.com
Web interface: Use [identity] name instead of hostname when set
3 files changed with 17 insertions and 7 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/APIServer.cpp
Show inline comments
 
@@ -85,50 +85,60 @@ void APIServer::serve_instances(Server *server, Server::session *session, struct
 
	std::vector<std::string> usernames;
 
	std::vector<std::string> list = show_list(m_config, false);
 

	
 
	Document json;
 
	json.SetObject();
 
	json.AddMember("error", 0, json.GetAllocator());
 

	
 
	Value instances(kArrayType);
 
	BOOST_FOREACH(std::string &id, list) {
 
		Value instance;
 
		instance.SetObject();
 
		instance.AddMember("id", id.c_str(), json.GetAllocator());
 
		instance.AddMember("name", id.c_str(), json.GetAllocator());
 

	
 
		std::string name = get_config(m_config, id, "identity.name");
 
		if (name.empty() || name == "Spectrum 2 Transport") {
 
			instance.AddMember("name", id.c_str(), json.GetAllocator());
 
		}
 
		else {
 
			statuses.push_back(name);
 
			instance.AddMember("name", statuses.back().c_str(), json.GetAllocator());
 
		}
 

	
 
		std::string status = server->send_command(id, "status");
 
		if (status.empty()) {
 
			status = "Cannot get the instance status.";
 
		}
 

	
 
		statuses.push_back(status);
 
		instance.AddMember("status", statuses.back().c_str(), json.GetAllocator());
 

	
 
		bool running = true;
 
		if (status.find("Running") == std::string::npos) {
 
			running = false;
 
		}
 
		instance.AddMember("running", running, json.GetAllocator());
 

	
 
		UserInfo info;
 
		m_storage->getUser(session->user, info);
 
		std::string username = "";
 
		int type = (int) TYPE_STRING;
 
		m_storage->getUserSetting(info.id, id, type, username);
 

	
 
		usernames.push_back(username);
 
		instance.AddMember("registered", !username.empty(), json.GetAllocator());
 
		instance.AddMember("username", usernames.back().c_str(), json.GetAllocator());
 
		instance.AddMember("frontend", is_slack(m_config, id) ? "slack" : "xmpp", json.GetAllocator());
 

	
 
		usernames.push_back(get_config(m_config, id, "service.frontend"));
 
		instance.AddMember("frontend", usernames.back().c_str(), json.GetAllocator());
 

	
 
		instances.PushBack(instance, json.GetAllocator());
 
	}
 

	
 
	json.AddMember("instances", instances, json.GetAllocator());
 
	send_json(conn, json);
 
}
 

	
 
void APIServer::serve_instances_list_rooms(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	std::string uri(hm->uri.p, hm->uri.len);
 
	std::string instance = uri.substr(uri.rfind("/") + 1);
 

	
spectrum_manager/src/methods.cpp
Show inline comments
 
@@ -492,25 +492,25 @@ static void handleConnected(boost::shared_ptr<Swift::Connection> m_conn, const s
 

	
 
		WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_QUERY);
 

	
 
		uint32_t size = htonl(message.size());
 
		char *header = (char *) &size;
 

	
 
		
 
		// send header together with wrapper message
 
		m_conn->write(Swift::createSafeByteArray(std::string(header, 4) + message));
 
	}
 
}
 

	
 
bool is_slack(ManagerConfig *config, const std::string &jid) {
 
std::string get_config(ManagerConfig *config, const std::string &jid, const std::string &key) {
 
	path p(CONFIG_STRING(config, "service.config_directory"));
 

	
 
	try {
 
		if (!exists(p)) {
 
			std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
 
			exit(6);
 
		}
 

	
 
		if (!is_directory(p)) {
 
			std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
 
			exit(7);
 
		}
 
@@ -519,34 +519,34 @@ bool is_slack(ManagerConfig *config, const std::string &jid) {
 
		for (directory_iterator itr(p); itr != end_itr; ++itr) {
 
			if (is_regular(itr->path()) && extension(itr->path()) == ".cfg") {
 
				Config cfg;
 
				if (cfg.load(itr->path().string()) == false) {
 
					std::cerr << "Can't load config file " << itr->path().string() << ". Skipping...\n";
 
					continue;
 
				}
 

	
 
				if (CONFIG_STRING(&cfg, "service.jid") != jid) {
 
					continue;
 
				}
 

	
 
				return CONFIG_STRING(&cfg, "service.frontend") == "slack";
 
				return CONFIG_STRING(&cfg, key);
 
			}
 
		}
 

	
 
	}
 
	catch (const filesystem_error& ex) {
 
		return false;
 
		return "";
 
	}
 

	
 
	return false;
 
	return "";
 
}
 

	
 
void ask_local_server(ManagerConfig *config, Swift::BoostNetworkFactories &networkFactories, const std::string &jid, const std::string &message) {
 
	response = "";
 
	path p(CONFIG_STRING(config, "service.config_directory"));
 

	
 
	try {
 
		if (!exists(p)) {
 
			std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
 
			exit(6);
 
		}
 

	
spectrum_manager/src/methods.h
Show inline comments
 
@@ -42,17 +42,17 @@ std::string searchForBinary(const std::string &binary);
 
unsigned long exec_(std::string path, std::string config, std::string jid = "");
 

	
 
int getPort(const std::string &portfile);
 

	
 
int isRunning(const std::string &pidfile);
 
int start_instances(ManagerConfig *config, const std::string &_jid = "");
 
int restart_instances(ManagerConfig *config, const std::string &_jid = "");
 
void stop_instances(ManagerConfig *config, const std::string &_jid = "");
 

	
 
int show_status(ManagerConfig *config);
 

	
 
void ask_local_server(ManagerConfig *config, Swift::BoostNetworkFactories &networkFactories, const std::string &jid, const std::string &message);
 
bool is_slack(ManagerConfig *config, const std::string &jid);
 
std::string get_config(ManagerConfig *config, const std::string &jid, const std::string &key);
 

	
 
std::vector<std::string> show_list(ManagerConfig *config, bool show = true);
 

	
 
std::string get_response();
0 comments (0 inline, 0 general)