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
 
@@ -237,12 +237,18 @@ std::string Server::send_command(const std::string &jid, const std::string &cmd)
 
	}
 

	
 
	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;
 
@@ -265,12 +271,18 @@ void Server::serve_onlineusers(struct mg_connection *conn, struct http_message *
 
	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>";
 

	
 
@@ -341,12 +353,19 @@ void Server::serve_users_remove(struct mg_connection *conn, struct http_message
 
	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) {
 
@@ -383,12 +402,18 @@ void Server::serve_users(struct mg_connection *conn, struct http_message *hm) {
 
	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;
 
	}
 
@@ -397,12 +422,18 @@ void Server::serve_instances_start(struct mg_connection *conn, struct http_messa
 
	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>";
0 comments (0 inline, 0 general)