Changeset - 580641ce8334
[Not reviewed]
0 1 0
Jan Kaluza - 10 years ago 2016-01-07 08:57:09
jkaluza@redhat.com
Disable access to admin pages for regular user
1 file changed with 31 insertions and 0 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/server.cpp
Show inline comments
 
@@ -231,24 +231,30 @@ std::string Server::send_command(const std::string &jid, const std::string &cmd)
 
	gettimeofday(&td_end, NULL);
 

	
 
	time_t started = time(NULL);
 
	while(get_response().empty() && td_end.tv_sec - td_start.tv_sec < 1) {
 
		gettimeofday(&td_end, NULL);
 
		eventLoop.runOnce();
 
	}
 

	
 
	return get_response();
 
}
 

	
 
void Server::serve_onlineusers(struct mg_connection *conn, struct http_message *hm) {
 
	Server:session *session = get_session(hm);
 
	if (!session->admin) {
 
		redirect_to(conn, hm, "/");
 
		return;
 
	}
 

	
 
	std::string html;
 
	std::string jid = get_http_var(hm, "jid");
 

	
 
	html += std::string("<h2>") + jid + " online users</h2><table><tr><th>JID<th>Command</th></tr>";
 

	
 
	Swift::SimpleEventLoop eventLoop;
 
	Swift::BoostNetworkFactories networkFactories(&eventLoop);
 

	
 
	ask_local_server(m_config, networkFactories, jid, "online_users");
 
	eventLoop.runUntilEvents();
 
	while(get_response().empty()) {
 
		eventLoop.runUntilEvents();
 
@@ -259,24 +265,30 @@ void Server::serve_onlineusers(struct mg_connection *conn, struct http_message *
 
	boost::split(users, response, boost::is_any_of("\n"));
 

	
 
	BOOST_FOREACH(std::string &user, users) {
 
		html += "<tr><td>" + user + "</td><td></td></tr>";
 
	}
 

	
 
	html += "</table><a href=\"/\">Back to main page</a>";
 
	html += "</body></html>";
 
	print_html(conn, hm, html);
 
}
 

	
 
void Server::serve_cmd(struct mg_connection *conn, struct http_message *hm) {
 
	Server:session *session = get_session(hm);
 
	if (!session->admin) {
 
		redirect_to(conn, hm, "/");
 
		return;
 
	}
 

	
 
	std::string html;
 
	std::string jid = get_http_var(hm, "jid");
 
	std::string cmd = get_http_var(hm, "cmd");
 

	
 
	html += std::string("<h2>") + jid + " command result</h2>";
 

	
 
	Swift::SimpleEventLoop eventLoop;
 
	Swift::BoostNetworkFactories networkFactories(&eventLoop);
 

	
 
	ask_local_server(m_config, networkFactories, jid, cmd);
 
	while(get_response().empty()) {
 
		eventLoop.runUntilEvents();
 
@@ -335,24 +347,31 @@ void Server::serve_users_remove(struct mg_connection *conn, struct http_message
 
	}
 

	
 
	std::string user = get_http_var(hm, "user");
 
	UserInfo info;
 
	m_storage->getUser(user, info);
 
	m_storage->removeUser(info.id);
 
	redirect_to(conn, hm, "/users");
 
}
 

	
 
void Server::serve_users(struct mg_connection *conn, struct http_message *hm) {
 
	std::string html = "<h2>Spectrum 2 manager users</h2>";
 

	
 
	Server:session *session = get_session(hm);
 
	if (!session->admin) {
 
		html += "<p>Only Spectrum 2 manager administrator can access this page.</p>";
 
		print_html(conn, hm, html);
 
		return;
 
	}
 

	
 
	html += "<p>Here, you can add new users who will have access to this web interface. "
 
			"These users will be able to register new accounts on all Spectrum 2 instances "
 
			"running on these server. They won't be able to change any Spectrum 2 instance "
 
			"configuration influencing other users.</p>";
 

	
 
	if (!m_storage) {
 
		print_html(conn, hm, html);
 
		return;
 
	}
 

	
 
	html += "<form action=\"/users/add\" class=\"basic-grey\" method=\"POST\"> \
 
	<h1>Add user \
 
@@ -377,38 +396,50 @@ void Server::serve_users(struct mg_connection *conn, struct http_message *hm) {
 
	BOOST_FOREACH(std::string &user, users) {
 
		html += "<tr>";
 
		html += "<td><a href=\"/users?jid=" + user + "\">" + user + "</a></td>";
 
		html += "<td><a href=\"/users/remove?user=" + user + "\">Remove</a></td>";
 
		html += "</tr>";
 
	}
 
	html += "</table>";
 

	
 
	print_html(conn, hm, html);
 
}
 

	
 
void Server::serve_instances_start(struct mg_connection *conn, struct http_message *hm) {
 
	Server:session *session = get_session(hm);
 
	if (!session->admin) {
 
		redirect_to(conn, hm, "/");
 
		return;
 
	}
 

	
 
	std::string html;
 
	std::string jid = get_http_var(hm, "jid");
 
	if (jid.empty()) {
 
		redirect_to(conn, hm, "/");
 
		return;
 
	}
 

	
 
	start_instances(m_config, jid);
 
	html += "<h2>Starting Spectrum 2 instance</h2>";
 
	html += "<b>" + get_response() + "</b><br/><a href=\"/\">Back to main page</a>";
 
	print_html(conn, hm, html);
 
}
 

	
 
void Server::serve_instances_stop(struct mg_connection *conn, struct http_message *hm) {
 
	Server:session *session = get_session(hm);
 
	if (!session->admin) {
 
		redirect_to(conn, hm, "/");
 
		return;
 
	}
 

	
 
	std::string html;
 
	std::string jid = get_http_var(hm, "jid");
 

	
 
	stop_instances(m_config, jid);
 
	html += "<b>" + get_response() + "</b><br/><a href=\"/\">Back to main page</a>";
 
	html += "</body></html>";
 
	print_html(conn, hm, html);
 
}
 

	
 
void Server::serve_instance(struct mg_connection *conn, struct http_message *hm, const std::string &jid) {
 
	std::string html = "<h2>Spectrum 2 instance: " + jid + "</h2>";
 

	
0 comments (0 inline, 0 general)