diff options
Diffstat (limited to 'src/mongo/db/dbwebserver.cpp')
-rw-r--r-- | src/mongo/db/dbwebserver.cpp | 136 |
1 files changed, 92 insertions, 44 deletions
diff --git a/src/mongo/db/dbwebserver.cpp b/src/mongo/db/dbwebserver.cpp index bee10b95a5b..b7a856ef167 100644 --- a/src/mongo/db/dbwebserver.cpp +++ b/src/mongo/db/dbwebserver.cpp @@ -35,7 +35,6 @@ #include "mongo/db/dbwebserver.h" -#include <boost/date_time/posix_time/posix_time.hpp> #include <pcrecpp.h> #include "mongo/base/init.h" @@ -63,7 +62,6 @@ #include "mongo/util/ramlog.h" #include "mongo/util/version.h" - namespace mongo { using std::map; @@ -84,19 +82,77 @@ void doUnlockedStuff(stringstream& ss) { ss << "</pre>"; } - bool prisort(const Prioritizable* a, const Prioritizable* b) { return a->priority() < b->priority(); } - -struct Timing { - Timing() { - start = timeLocked = 0; +void htmlHelp(Command* command, stringstream& ss) { + string helpStr; + { + stringstream h; + command->help(h); + helpStr = h.str(); } - unsigned long long start, timeLocked; -}; + ss << "\n<tr><td>"; + if (command->isWebUI()) + ss << "<a href=\"/" << command->getName() << "?text=1\">"; + ss << command->getName(); + if (command->isWebUI()) + ss << "</a>"; + ss << "</td>\n"; + ss << "<td>"; + ss << "UNUSED "; + if (command->slaveOk()) + ss << "S "; + if (command->adminOnly()) + ss << "A"; + ss << "</td>"; + ss << "<td>"; + if (helpStr != "no help defined") { + const char* p = helpStr.c_str(); + while (*p) { + if (*p == '<') { + ss << "<"; + p++; + continue; + } else if (*p == '{') + ss << "<code>"; + else if (*p == '}') { + ss << "}</code>"; + p++; + continue; + } + if (strncmp(p, "http:", 5) == 0) { + ss << "<a href=\""; + const char* q = p; + while (*q && *q != ' ' && *q != '\n') + ss << *q++; + ss << "\">"; + q = p; + if (str::startsWith(q, "http://www.mongodb.org/display/")) + q += 31; + while (*q && *q != ' ' && *q != '\n') { + ss << (*q == '+' ? ' ' : *q); + q++; + if (*q == '#') + while (*q && *q != ' ' && *q != '\n') + q++; + } + ss << "</a>"; + p = q; + continue; + } + if (*p == '\n') + ss << "<br>"; + else + ss << *p; + p++; + } + } + ss << "</td>"; + ss << "</tr>\n"; +} class LogPlugin : public WebStatusPlugin { public: @@ -112,7 +168,6 @@ public: RamLog* _log; }; - class FavIconHandler : public DbWebHandler { public: FavIconHandler() : DbWebHandler("favicon.ico", 0, false) {} @@ -132,7 +187,6 @@ public: } faviconHandler; - class StatusHandler : public DbWebHandler { public: StatusHandler() : DbWebHandler("_status", 1, false) {} @@ -188,7 +242,6 @@ public: } statusHandler; - class CommandListHandler : public DbWebHandler { public: CommandListHandler() : DbWebHandler("_commands", 1, true) {} @@ -217,7 +270,7 @@ public: 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); + htmlHelp(i->second, ss); } ss << _table() << _end(); @@ -225,7 +278,6 @@ public: } } commandListHandler; - class CommandsHandler : public DbWebHandler { public: CommandsHandler() : DbWebHandler("DUMMY COMMANDS", 2, true) {} @@ -236,16 +288,13 @@ public: return true; } - Command* _cmd(const string& cmd) const { - const Command::CommandMap* m = Command::webCommands(); - if (!m) - return 0; - - Command::CommandMap::const_iterator i = m->find(cmd); - if (i == m->end()) - return 0; + Command* _cmd(const string& cmdName) const { + Command* cmd = Command::findCommand(cmdName); + if (cmd->isWebUI()) { + return cmd; + } - return i->second; + return nullptr; } virtual bool handles(const string& url) const { @@ -398,29 +447,28 @@ void DbWebServer::doRequest(const char* rq, 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") << ": "; - - 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 << 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> "; - } - ss << '\n'; + auto m = Command::commandsByBestName(); + + for (Command::CommandMap::const_iterator i = m->begin(); i != m->end(); ++i) { + if (!i->second->isWebUI()) + continue; + + 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 << ">" << i->first << "</a> "; } ss << '\n'; |