summaryrefslogtreecommitdiff
path: root/src/mongo/db/dbwebserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/dbwebserver.cpp')
-rw-r--r--src/mongo/db/dbwebserver.cpp826
1 files changed, 412 insertions, 414 deletions
diff --git a/src/mongo/db/dbwebserver.cpp b/src/mongo/db/dbwebserver.cpp
index 73662327766..1ad6e54a236 100644
--- a/src/mongo/db/dbwebserver.cpp
+++ b/src/mongo/db/dbwebserver.cpp
@@ -66,548 +66,546 @@
namespace mongo {
- using std::map;
- using std::stringstream;
- using std::vector;
+using std::map;
+using std::stringstream;
+using std::vector;
- using namespace html;
+using namespace html;
namespace {
- void doUnlockedStuff(stringstream& ss) {
- // This is in the header already ss << "port: " << port << '\n'
- ss << "<pre>";
- ss << mongodVersion() << '\n';
- ss << "git hash: " << gitVersion() << '\n';
- ss << openSSLVersion("OpenSSL version: ", "\n");
- ss << "uptime: " << time(0) - serverGlobalParams.started << " seconds\n";
- ss << "</pre>";
- }
-
+void doUnlockedStuff(stringstream& ss) {
+ // This is in the header already ss << "port: " << port << '\n'
+ ss << "<pre>";
+ ss << mongodVersion() << '\n';
+ ss << "git hash: " << gitVersion() << '\n';
+ ss << openSSLVersion("OpenSSL version: ", "\n");
+ ss << "uptime: " << time(0) - serverGlobalParams.started << " seconds\n";
+ ss << "</pre>";
+}
- bool prisort(const Prioritizable* a, const Prioritizable* b) {
- return a->priority() < b->priority();
- }
-
- struct Timing {
- Timing() {
- start = timeLocked = 0;
- }
- unsigned long long start, timeLocked;
- };
+bool prisort(const Prioritizable* a, const Prioritizable* b) {
+ return a->priority() < b->priority();
+}
- class LogPlugin : public WebStatusPlugin {
- public:
- LogPlugin() : WebStatusPlugin("Log", 100), _log(0) {
- _log = RamLog::get("global");
- }
-
- virtual void init() {}
-
- virtual void run(OperationContext* txn, stringstream& ss) {
- _log->toHTML(ss);
- }
- RamLog * _log;
- };
+struct Timing {
+ Timing() {
+ start = timeLocked = 0;
+ }
+ unsigned long long start, timeLocked;
+};
- class FavIconHandler : public DbWebHandler {
- public:
- FavIconHandler() : DbWebHandler("favicon.ico", 0, false) {}
+class LogPlugin : public WebStatusPlugin {
+public:
+ LogPlugin() : WebStatusPlugin("Log", 100), _log(0) {
+ _log = RamLog::get("global");
+ }
- virtual void handle(OperationContext* txn,
- const char *rq, const std::string& url, BSONObj params,
- string& responseMsg, int& responseCode,
- vector<string>& headers, const SockAddr &from) {
- responseCode = 404;
- headers.push_back("Content-Type: text/plain;charset=utf-8");
- responseMsg = "no favicon\n";
- }
+ virtual void init() {}
- } faviconHandler;
+ virtual void run(OperationContext* txn, stringstream& ss) {
+ _log->toHTML(ss);
+ }
+ RamLog* _log;
+};
+
+
+class FavIconHandler : public DbWebHandler {
+public:
+ FavIconHandler() : DbWebHandler("favicon.ico", 0, false) {}
+
+ virtual void handle(OperationContext* txn,
+ const char* rq,
+ const std::string& url,
+ BSONObj params,
+ string& responseMsg,
+ int& responseCode,
+ vector<string>& headers,
+ const SockAddr& from) {
+ responseCode = 404;
+ headers.push_back("Content-Type: text/plain;charset=utf-8");
+ responseMsg = "no favicon\n";
+ }
+} faviconHandler;
- class StatusHandler : public DbWebHandler {
- public:
- StatusHandler() : DbWebHandler("_status", 1, false) {}
- virtual void handle(OperationContext* txn,
- const char *rq, const std::string& url, BSONObj params,
- string& responseMsg, int& responseCode,
- vector<string>& headers, const SockAddr &from) {
- headers.push_back("Content-Type: application/json;charset=utf-8");
- responseCode = 200;
+class StatusHandler : public DbWebHandler {
+public:
+ StatusHandler() : DbWebHandler("_status", 1, false) {}
- static vector<string> commands;
- if (commands.size() == 0) {
- commands.push_back("serverStatus");
- commands.push_back("buildinfo");
- }
+ virtual void handle(OperationContext* txn,
+ const char* rq,
+ const std::string& url,
+ BSONObj params,
+ string& responseMsg,
+ int& responseCode,
+ vector<string>& headers,
+ const SockAddr& from) {
+ headers.push_back("Content-Type: application/json;charset=utf-8");
+ responseCode = 200;
- BSONObjBuilder buf(1024);
+ static vector<string> commands;
+ if (commands.size() == 0) {
+ commands.push_back("serverStatus");
+ commands.push_back("buildinfo");
+ }
- for (unsigned i = 0; i<commands.size(); i++) {
- string cmd = commands[i];
+ BSONObjBuilder buf(1024);
- Command * c = Command::findCommand(cmd);
- verify(c);
+ for (unsigned i = 0; i < commands.size(); i++) {
+ string cmd = commands[i];
- BSONObj co;
- {
- BSONObjBuilder b;
- b.append(cmd, 1);
+ Command* c = Command::findCommand(cmd);
+ verify(c);
- if (cmd == "serverStatus" && params["repl"].type()) {
- b.append("repl", atoi(params["repl"].valuestr()));
- }
+ BSONObj co;
+ {
+ BSONObjBuilder b;
+ b.append(cmd, 1);
- co = b.obj();
+ if (cmd == "serverStatus" && params["repl"].type()) {
+ b.append("repl", atoi(params["repl"].valuestr()));
}
- string errmsg;
-
- BSONObjBuilder sub;
- if (!c->run(txn, "admin.$cmd", co, 0, errmsg, sub))
- buf.append(cmd, errmsg);
- else
- buf.append(cmd, sub.obj());
+ co = b.obj();
}
- responseMsg = buf.obj().jsonString();
- }
+ string errmsg;
- } statusHandler;
+ BSONObjBuilder sub;
+ if (!c->run(txn, "admin.$cmd", co, 0, errmsg, sub))
+ buf.append(cmd, errmsg);
+ else
+ buf.append(cmd, sub.obj());
+ }
+ responseMsg = buf.obj().jsonString();
+ }
- class CommandListHandler : public DbWebHandler {
- public:
- CommandListHandler() : DbWebHandler("_commands", 1, true) {}
+} statusHandler;
- virtual void handle(OperationContext* txn,
- const char *rq, const std::string& url, BSONObj params,
- string& responseMsg, int& responseCode,
- vector<string>& headers, const SockAddr &from) {
- headers.push_back("Content-Type: text/html;charset=utf-8");
- responseCode = 200;
- stringstream ss;
- ss << start("Commands List");
- ss << p(a("/", "back", "Home"));
- ss << p("<b>MongoDB List of "
- "<a href=\"http://dochub.mongodb.org/core/commands\">Commands</a>"
- "</b>\n");
+class CommandListHandler : public DbWebHandler {
+public:
+ CommandListHandler() : DbWebHandler("_commands", 1, true) {}
- const Command::CommandMap* m = Command::commandsByBestName();
- ss << "S:slave-ok R:read-lock W:write-lock A:admin-only<br>\n";
- ss << table();
- ss << "<tr><th>Command</th><th>Attributes</th><th>Help</th></tr>\n";
- for (Command::CommandMap::const_iterator i = m->begin(); i != m->end(); ++i) {
- i->second->htmlHelp(ss);
- }
- ss << _table() << _end();
+ virtual void handle(OperationContext* txn,
+ const char* rq,
+ const std::string& url,
+ BSONObj params,
+ string& responseMsg,
+ int& responseCode,
+ vector<string>& headers,
+ const SockAddr& from) {
+ headers.push_back("Content-Type: text/html;charset=utf-8");
+ responseCode = 200;
- responseMsg = ss.str();
+ stringstream ss;
+ ss << start("Commands List");
+ ss << p(a("/", "back", "Home"));
+ ss << p(
+ "<b>MongoDB List of "
+ "<a href=\"http://dochub.mongodb.org/core/commands\">Commands</a>"
+ "</b>\n");
+
+ const Command::CommandMap* m = Command::commandsByBestName();
+ ss << "S:slave-ok R:read-lock W:write-lock A:admin-only<br>\n";
+ ss << table();
+ ss << "<tr><th>Command</th><th>Attributes</th><th>Help</th></tr>\n";
+ for (Command::CommandMap::const_iterator i = m->begin(); i != m->end(); ++i) {
+ i->second->htmlHelp(ss);
}
- } commandListHandler;
+ ss << _table() << _end();
+ responseMsg = ss.str();
+ }
+} commandListHandler;
- class CommandsHandler : public DbWebHandler {
- public:
- CommandsHandler() : DbWebHandler("DUMMY COMMANDS", 2, true) {}
- bool _cmd(const string& url, string& cmd, bool& text, bo params) const {
- cmd = str::after(url, '/');
- text = params["text"].boolean();
- return true;
- }
+class CommandsHandler : public DbWebHandler {
+public:
+ CommandsHandler() : DbWebHandler("DUMMY COMMANDS", 2, true) {}
- Command * _cmd(const string& cmd) const {
- const Command::CommandMap* m = Command::webCommands();
- if (!m)
- return 0;
+ bool _cmd(const string& url, string& cmd, bool& text, bo params) const {
+ cmd = str::after(url, '/');
+ text = params["text"].boolean();
+ return true;
+ }
- Command::CommandMap::const_iterator i = m->find(cmd);
- if (i == m->end())
- return 0;
+ Command* _cmd(const string& cmd) const {
+ const Command::CommandMap* m = Command::webCommands();
+ if (!m)
+ return 0;
- return i->second;
- }
+ Command::CommandMap::const_iterator i = m->find(cmd);
+ if (i == m->end())
+ return 0;
- virtual bool handles(const string& url) const {
- string cmd;
- bool text;
- if (!_cmd(url, cmd, text, bo()))
- return false;
- return _cmd(cmd) != 0;
- }
+ return i->second;
+ }
- virtual void handle(OperationContext* txn,
- const char *rq, const std::string& url, BSONObj params,
- string& responseMsg, int& responseCode,
- vector<string>& headers, const SockAddr &from) {
- string cmd;
- bool text = false;
- verify(_cmd(url, cmd, text, params));
- Command * c = _cmd(cmd);
- verify(c);
+ virtual bool handles(const string& url) const {
+ string cmd;
+ bool text;
+ if (!_cmd(url, cmd, text, bo()))
+ return false;
+ return _cmd(cmd) != 0;
+ }
- BSONObj cmdObj = BSON(cmd << 1);
+ virtual void handle(OperationContext* txn,
+ const char* rq,
+ const std::string& url,
+ BSONObj params,
+ string& responseMsg,
+ int& responseCode,
+ vector<string>& headers,
+ const SockAddr& from) {
+ string cmd;
+ bool text = false;
+ verify(_cmd(url, cmd, text, params));
+ Command* c = _cmd(cmd);
+ verify(c);
- rpc::CommandRequestBuilder requestBuilder{};
+ BSONObj cmdObj = BSON(cmd << 1);
- requestBuilder.setDatabase("admin")
- .setCommandName(cmd)
- .setMetadata(rpc::makeEmptyMetadata())
- .setCommandArgs(cmdObj);
+ rpc::CommandRequestBuilder requestBuilder{};
- auto cmdRequestMsg = requestBuilder.done();
- rpc::CommandRequest cmdRequest{cmdRequestMsg.get()};
- rpc::CommandReplyBuilder cmdReplyBuilder{};
+ requestBuilder.setDatabase("admin")
+ .setCommandName(cmd)
+ .setMetadata(rpc::makeEmptyMetadata())
+ .setCommandArgs(cmdObj);
- Command::execCommand(txn, c, cmdRequest, &cmdReplyBuilder);
+ auto cmdRequestMsg = requestBuilder.done();
+ rpc::CommandRequest cmdRequest{cmdRequestMsg.get()};
+ rpc::CommandReplyBuilder cmdReplyBuilder{};
- auto cmdReplyMsg = cmdReplyBuilder.done();
- rpc::CommandReply cmdReply{cmdReplyMsg.get()};
+ Command::execCommand(txn, c, cmdRequest, &cmdReplyBuilder);
- responseCode = 200;
+ auto cmdReplyMsg = cmdReplyBuilder.done();
+ rpc::CommandReply cmdReply{cmdReplyMsg.get()};
- string j = cmdReply.getCommandReply().jsonString(Strict, text);
- responseMsg = j;
+ responseCode = 200;
- if (text) {
- headers.push_back("Content-Type: text/plain;charset=utf-8");
- responseMsg += '\n';
- }
- else {
- headers.push_back("Content-Type: application/json;charset=utf-8");
- }
+ string j = cmdReply.getCommandReply().jsonString(Strict, text);
+ responseMsg = j;
+ if (text) {
+ headers.push_back("Content-Type: text/plain;charset=utf-8");
+ responseMsg += '\n';
+ } else {
+ headers.push_back("Content-Type: application/json;charset=utf-8");
}
+ }
- } commandsHandler;
+} commandsHandler;
- MONGO_INITIALIZER(WebStatusLogPlugin)(InitializerContext*) {
- if (serverGlobalParams.isHttpInterfaceEnabled) {
- new LogPlugin;
- }
- return Status::OK();
+MONGO_INITIALIZER(WebStatusLogPlugin)(InitializerContext*) {
+ if (serverGlobalParams.isHttpInterfaceEnabled) {
+ new LogPlugin;
}
+ return Status::OK();
+}
-} // namespace
+} // namespace
- DbWebServer::DbWebServer(const string& ip, int port, AdminAccess* webUsers)
- : MiniWebServer("admin web console", ip, port),
- _webUsers(webUsers) {
+DbWebServer::DbWebServer(const string& ip, int port, AdminAccess* webUsers)
+ : MiniWebServer("admin web console", ip, port), _webUsers(webUsers) {
+ WebStatusPlugin::initAll();
+}
- WebStatusPlugin::initAll();
- }
+void DbWebServer::doRequest(const char* rq,
+ string url,
+ string& responseMsg,
+ int& responseCode,
+ vector<string>& headers,
+ const SockAddr& from) {
+ Client* client = &cc();
+ auto txn = client->makeOperationContext();
- void DbWebServer::doRequest(const char *rq,
- string url,
- string& responseMsg,
- int& responseCode,
- vector<string>& headers,
- const SockAddr &from) {
+ if (url.size() > 1) {
+ if (!_allowed(txn.get(), rq, headers, from)) {
+ responseCode = 401;
+ headers.push_back("Content-Type: text/plain;charset=utf-8");
+ responseMsg = "not allowed\n";
+ return;
+ }
- Client* client = &cc();
- auto txn = client->makeOperationContext();
+ {
+ BSONObj params;
+ const size_t pos = url.find("?");
+ if (pos != string::npos) {
+ MiniWebServer::parseParams(params, url.substr(pos + 1));
+ url = url.substr(0, pos);
+ }
- if (url.size() > 1) {
+ DbWebHandler* handler = DbWebHandler::findHandler(url);
+ if (handler) {
+ if (handler->requiresREST(url) && !serverGlobalParams.rest) {
+ _rejectREST(responseMsg, responseCode, headers);
+ } else {
+ const string callback = params.getStringField("jsonp");
- if (!_allowed(txn.get(), rq, headers, from)) {
- responseCode = 401;
- headers.push_back("Content-Type: text/plain;charset=utf-8");
- responseMsg = "not allowed\n";
- return;
- }
+ uassert(13453,
+ "server not started with --jsonp",
+ callback.empty() || serverGlobalParams.jsonp);
- {
- BSONObj params;
- const size_t pos = url.find("?");
- if (pos != string::npos) {
- MiniWebServer::parseParams(params, url.substr(pos + 1));
- url = url.substr(0, pos);
- }
+ handler->handle(
+ txn.get(), rq, url, params, responseMsg, responseCode, headers, from);
- DbWebHandler * handler = DbWebHandler::findHandler(url);
- if (handler) {
- if (handler->requiresREST(url) && !serverGlobalParams.rest) {
- _rejectREST(responseMsg, responseCode, headers);
- }
- else {
- const string callback = params.getStringField("jsonp");
-
- uassert(13453,
- "server not started with --jsonp",
- callback.empty() || serverGlobalParams.jsonp);
-
- handler->handle(txn.get(),
- rq,
- url,
- params,
- responseMsg,
- responseCode,
- headers,
- from);
-
- if (responseCode == 200 && !callback.empty()) {
- responseMsg = callback + '(' + responseMsg + ')';
- }
+ if (responseCode == 200 && !callback.empty()) {
+ responseMsg = callback + '(' + responseMsg + ')';
}
-
- return;
}
- }
- if (!serverGlobalParams.rest) {
- _rejectREST(responseMsg, responseCode, headers);
return;
}
+ }
- responseCode = 404;
- headers.push_back("Content-Type: text/html;charset=utf-8");
- responseMsg = "<html><body>unknown url</body></html>\n";
+ if (!serverGlobalParams.rest) {
+ _rejectREST(responseMsg, responseCode, headers);
return;
}
- // generate home page
+ responseCode = 404;
+ headers.push_back("Content-Type: text/html;charset=utf-8");
+ responseMsg = "<html><body>unknown url</body></html>\n";
+ return;
+ }
- if (!_allowed(txn.get(), rq, headers, from)) {
- responseCode = 401;
- headers.push_back("Content-Type: text/plain;charset=utf-8");
- responseMsg = "not allowed\n";
- return;
- }
+ // generate home page
- responseCode = 200;
- stringstream ss;
- string dbname;
- {
- stringstream z;
- z << serverGlobalParams.binaryName << ' ' << prettyHostName();
- dbname = z.str();
- }
+ if (!_allowed(txn.get(), rq, headers, from)) {
+ responseCode = 401;
+ headers.push_back("Content-Type: text/plain;charset=utf-8");
+ responseMsg = "not allowed\n";
+ return;
+ }
- ss << start(dbname) << h2(dbname);
- ss << "<p><a href=\"/_commands\">List all commands</a> | \n";
- ss << "<a href=\"/_replSet\">Replica set status</a></p>\n";
+ responseCode = 200;
+ stringstream ss;
+ string dbname;
+ {
+ stringstream z;
+ z << serverGlobalParams.binaryName << ' ' << prettyHostName();
+ dbname = z.str();
+ }
- {
- const Command::CommandMap* m = Command::webCommands();
- if (m) {
- ss << a("",
- "These read-only context-less commands can be executed from the web "
- "interface. Results are json format, unless ?text=1 is appended in which "
- "case the result is output as text for easier human viewing",
- "Commands")
- << ": ";
-
- for (Command::CommandMap::const_iterator i = m->begin(); i != m->end(); ++i) {
- stringstream h;
- i->second->help(h);
-
- const string help = h.str();
- ss << "<a href=\"/" << i->first << "?text=1\"";
- if (help != "no help defined") {
- ss << " title=\"" << help << '"';
- }
+ ss << start(dbname) << h2(dbname);
+ ss << "<p><a href=\"/_commands\">List all commands</a> | \n";
+ ss << "<a href=\"/_replSet\">Replica set status</a></p>\n";
+
+ {
+ const Command::CommandMap* m = Command::webCommands();
+ if (m) {
+ ss << a("",
+ "These read-only context-less commands can be executed from the web "
+ "interface. Results are json format, unless ?text=1 is appended in which "
+ "case the result is output as text for easier human viewing",
+ "Commands") << ": ";
- ss << ">" << i->first << "</a> ";
+ for (Command::CommandMap::const_iterator i = m->begin(); i != m->end(); ++i) {
+ stringstream h;
+ i->second->help(h);
+
+ const string help = h.str();
+ ss << "<a href=\"/" << i->first << "?text=1\"";
+ if (help != "no help defined") {
+ ss << " title=\"" << help << '"';
}
- ss << '\n';
+
+ ss << ">" << i->first << "</a> ";
}
+ ss << '\n';
}
+ }
- ss << '\n';
+ ss << '\n';
- doUnlockedStuff(ss);
+ doUnlockedStuff(ss);
- WebStatusPlugin::runAll(txn.get(), ss);
+ WebStatusPlugin::runAll(txn.get(), ss);
- ss << "</body></html>\n";
- responseMsg = ss.str();
- headers.push_back("Content-Type: text/html;charset=utf-8");
- }
+ ss << "</body></html>\n";
+ responseMsg = ss.str();
+ headers.push_back("Content-Type: text/html;charset=utf-8");
+}
- bool DbWebServer::_allowed(OperationContext* txn,
- const char * rq,
- vector<string>& headers,
- const SockAddr &from) {
+bool DbWebServer::_allowed(OperationContext* txn,
+ const char* rq,
+ vector<string>& headers,
+ const SockAddr& from) {
+ AuthorizationSession* authSess = AuthorizationSession::get(txn->getClient());
+ if (!authSess->getAuthorizationManager().isAuthEnabled()) {
+ return true;
+ }
- AuthorizationSession* authSess = AuthorizationSession::get(txn->getClient());
- if (!authSess->getAuthorizationManager().isAuthEnabled()) {
- return true;
- }
+ if (from.isLocalHost() && !_webUsers->haveAdminUsers(txn)) {
+ authSess->grantInternalAuthorization();
+ return true;
+ }
- if (from.isLocalHost() && !_webUsers->haveAdminUsers(txn)) {
- authSess->grantInternalAuthorization();
- return true;
- }
+ string auth = getHeader(rq, "Authorization");
- string auth = getHeader(rq, "Authorization");
+ if (auth.size() > 0 && auth.find("Digest ") == 0) {
+ auth = auth.substr(7) + ", ";
- if (auth.size() > 0 && auth.find("Digest ") == 0) {
- auth = auth.substr(7) + ", ";
+ map<string, string> parms;
+ pcrecpp::StringPiece input(auth);
- map<string, string> parms;
- pcrecpp::StringPiece input(auth);
+ string name, val;
+ pcrecpp::RE re("(\\w+)=\"?(.*?)\"?,\\s*");
+ while (re.Consume(&input, &name, &val)) {
+ parms[name] = val;
+ }
- string name, val;
- pcrecpp::RE re("(\\w+)=\"?(.*?)\"?,\\s*");
- while (re.Consume(&input, &name, &val)) {
- parms[name] = val;
+ // Only users in the admin DB are visible by the webserver
+ UserName userName(parms["username"], "admin");
+ User* user;
+ AuthorizationManager& authzManager = authSess->getAuthorizationManager();
+ Status status = authzManager.acquireUser(txn, userName, &user);
+ if (!status.isOK()) {
+ if (status.code() != ErrorCodes::UserNotFound) {
+ uasserted(17051, status.reason());
}
+ } else {
+ uassert(
+ 17090, "External users don't have a password", !user->getCredentials().isExternal);
- // Only users in the admin DB are visible by the webserver
- UserName userName(parms["username"], "admin");
- User* user;
- AuthorizationManager& authzManager = authSess->getAuthorizationManager();
- Status status = authzManager.acquireUser(txn, userName, &user);
- if (!status.isOK()) {
- if (status.code() != ErrorCodes::UserNotFound) {
- uasserted(17051, status.reason());
- }
+ string ha1 = user->getCredentials().password;
+ authzManager.releaseUser(user);
+ if (ha1.empty()) {
+ return false;
}
- else {
- uassert(17090,
- "External users don't have a password",
- !user->getCredentials().isExternal);
-
- string ha1 = user->getCredentials().password;
- authzManager.releaseUser(user);
- if (ha1.empty()) {
- return false;
- }
- const string ha2 = md5simpledigest((string)"GET" + ":" + parms["uri"]);
-
- stringstream r;
- r << ha1 << ':' << parms["nonce"];
- if (parms["nc"].size() && parms["cnonce"].size() && parms["qop"].size()) {
- r << ':';
- r << parms["nc"];
- r << ':';
- r << parms["cnonce"];
- r << ':';
- r << parms["qop"];
- }
+ const string ha2 = md5simpledigest((string) "GET" + ":" + parms["uri"]);
+
+ stringstream r;
+ r << ha1 << ':' << parms["nonce"];
+ if (parms["nc"].size() && parms["cnonce"].size() && parms["qop"].size()) {
+ r << ':';
+ r << parms["nc"];
r << ':';
- r << ha2;
+ r << parms["cnonce"];
+ r << ':';
+ r << parms["qop"];
+ }
+ r << ':';
+ r << ha2;
- const string r1 = md5simpledigest(r.str());
+ const string r1 = md5simpledigest(r.str());
- if (r1 == parms["response"]) {
- Status status = authSess->addAndAuthorizeUser(txn, userName);
- uassertStatusOK(status);
- return true;
- }
+ if (r1 == parms["response"]) {
+ Status status = authSess->addAndAuthorizeUser(txn, userName);
+ uassertStatusOK(status);
+ return true;
}
}
-
- stringstream authHeader;
- authHeader << "WWW-Authenticate: "
- << "Digest realm=\"mongo\", "
- << "nonce=\"abc\", "
- << "algorithm=MD5, qop=\"auth\" ";
-
- headers.push_back(authHeader.str());
- return 0;
}
- void DbWebServer::_rejectREST(string& responseMsg, int& responseCode, vector<string>& headers) {
- responseCode = 403;
- stringstream ss;
- ss << "REST is not enabled. use --rest to turn on.\n";
- ss << "check that port " << _port << " is secured for the network too.\n";
- responseMsg = ss.str();
- headers.push_back("Content-Type: text/plain;charset=utf-8");
- }
+ stringstream authHeader;
+ authHeader << "WWW-Authenticate: "
+ << "Digest realm=\"mongo\", "
+ << "nonce=\"abc\", "
+ << "algorithm=MD5, qop=\"auth\" ";
+ headers.push_back(authHeader.str());
+ return 0;
+}
- // -- status framework ---
- WebStatusPlugin::WebStatusPlugin( const string& secionName , double priority , const string& subheader )
- : Prioritizable(priority), _name( secionName ) , _subHeading( subheader ) {
- if ( ! _plugins )
- _plugins = new vector<WebStatusPlugin*>();
- _plugins->push_back( this );
- }
+void DbWebServer::_rejectREST(string& responseMsg, int& responseCode, vector<string>& headers) {
+ responseCode = 403;
+ stringstream ss;
+ ss << "REST is not enabled. use --rest to turn on.\n";
+ ss << "check that port " << _port << " is secured for the network too.\n";
+ responseMsg = ss.str();
+ headers.push_back("Content-Type: text/plain;charset=utf-8");
+}
- void WebStatusPlugin::initAll() {
- if ( ! _plugins )
- return;
- sort( _plugins->begin(), _plugins->end() , prisort );
+// -- status framework ---
+WebStatusPlugin::WebStatusPlugin(const string& secionName, double priority, const string& subheader)
+ : Prioritizable(priority), _name(secionName), _subHeading(subheader) {
+ if (!_plugins)
+ _plugins = new vector<WebStatusPlugin*>();
+ _plugins->push_back(this);
+}
- for ( unsigned i=0; i<_plugins->size(); i++ )
- (*_plugins)[i]->init();
- }
+void WebStatusPlugin::initAll() {
+ if (!_plugins)
+ return;
- void WebStatusPlugin::runAll(OperationContext* txn, stringstream& ss) {
- if ( ! _plugins )
- return;
+ sort(_plugins->begin(), _plugins->end(), prisort);
- for ( unsigned i=0; i<_plugins->size(); i++ ) {
- WebStatusPlugin * p = (*_plugins)[i];
- ss << "<hr>\n"
- << "<b>" << p->_name << "</b>";
+ for (unsigned i = 0; i < _plugins->size(); i++)
+ (*_plugins)[i]->init();
+}
- ss << " " << p->_subHeading;
+void WebStatusPlugin::runAll(OperationContext* txn, stringstream& ss) {
+ if (!_plugins)
+ return;
- ss << "<br>\n";
+ for (unsigned i = 0; i < _plugins->size(); i++) {
+ WebStatusPlugin* p = (*_plugins)[i];
+ ss << "<hr>\n"
+ << "<b>" << p->_name << "</b>";
- p->run(txn, ss);
- }
-
- }
+ ss << " " << p->_subHeading;
- vector<WebStatusPlugin*> * WebStatusPlugin::_plugins = 0;
+ ss << "<br>\n";
+ p->run(txn, ss);
+ }
+}
- DbWebHandler::DbWebHandler( const string& name , double priority , bool requiresREST )
- : Prioritizable(priority), _name(name) , _requiresREST(requiresREST) {
+vector<WebStatusPlugin*>* WebStatusPlugin::_plugins = 0;
- {
- // setup strings
- _defaultUrl = "/";
- _defaultUrl += name;
- stringstream ss;
- ss << name << " priority: " << priority << " rest: " << requiresREST;
- _toString = ss.str();
- }
+DbWebHandler::DbWebHandler(const string& name, double priority, bool requiresREST)
+ : Prioritizable(priority), _name(name), _requiresREST(requiresREST) {
+ {
+ // setup strings
+ _defaultUrl = "/";
+ _defaultUrl += name;
- {
- // add to handler list
- if ( ! _handlers )
- _handlers = new vector<DbWebHandler*>();
- _handlers->push_back( this );
- sort( _handlers->begin() , _handlers->end() , prisort );
- }
+ stringstream ss;
+ ss << name << " priority: " << priority << " rest: " << requiresREST;
+ _toString = ss.str();
}
- DbWebHandler * DbWebHandler::findHandler( const string& url ) {
- if ( ! _handlers )
- return 0;
-
- for ( unsigned i=0; i<_handlers->size(); i++ ) {
- DbWebHandler * h = (*_handlers)[i];
- if ( h->handles( url ) )
- return h;
- }
+ {
+ // add to handler list
+ if (!_handlers)
+ _handlers = new vector<DbWebHandler*>();
+ _handlers->push_back(this);
+ sort(_handlers->begin(), _handlers->end(), prisort);
+ }
+}
+DbWebHandler* DbWebHandler::findHandler(const string& url) {
+ if (!_handlers)
return 0;
+
+ for (unsigned i = 0; i < _handlers->size(); i++) {
+ DbWebHandler* h = (*_handlers)[i];
+ if (h->handles(url))
+ return h;
}
- vector<DbWebHandler*> * DbWebHandler::_handlers = 0;
+ return 0;
+}
- void webServerListenThread(std::shared_ptr<DbWebServer> dbWebServer) {
- Client::initThread("websvr");
+vector<DbWebHandler*>* DbWebHandler::_handlers = 0;
- dbWebServer->initAndListen();
- }
+void webServerListenThread(std::shared_ptr<DbWebServer> dbWebServer) {
+ Client::initThread("websvr");
+
+ dbWebServer->initAndListen();
+}
-} // namespace mongo
+} // namespace mongo