From 5c6ab24ee20624f66a6cbf6d48a42bf481be08a8 Mon Sep 17 00:00:00 2001 From: Dwight Merriman Date: Mon, 19 Apr 2010 22:24:37 -0400 Subject: [PATCH] tweaking webserver --- db/dbwebserver.cpp | 40 +++++++++++++++++++++++----------------- util/message.h | 3 ++- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index 06fe5544dc5..d93ca4d3fed 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -319,6 +319,29 @@ namespace mongo { { if ( url.size() > 1 ) { + if ( url.find( "/_status" ) == 0 ){ + if ( ! allowed( rq , headers, from ) ){ + responseCode = 401; + headers.push_back( "Content-Type: text/plain" ); + responseMsg = "not allowed\n"; + return; + } + headers.push_back( "Content-Type: application/json" ); + generateServerStatus( url , responseMsg ); + responseCode = 200; + return; + } + + if ( ! cmdLine.rest ) { + 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" ); + return; + } + /* run a command from the web ui */ const char *p = url.c_str(); if( *p == '/' ) { @@ -350,23 +373,6 @@ namespace mongo { } } - if ( url.find( "/_status" ) == 0 ){ - if ( ! allowed( rq , headers, from ) ){ - responseCode = 401; - responseMsg = "not allowed\n"; - return; - } - headers.push_back( "Content-Type: application/json" ); - generateServerStatus( url , responseMsg ); - responseCode = 200; - return; - } - - if ( ! cmdLine.rest ){ - responseCode = 403; - responseMsg = "rest is not enabled. use --rest to turn on"; - return; - } if ( ! allowed( rq , headers, from ) ){ responseCode = 401; responseMsg = "not allowed\n"; diff --git a/util/message.h b/util/message.h index 7b8f1c4c58c..269277c422f 100644 --- a/util/message.h +++ b/util/message.h @@ -41,9 +41,10 @@ namespace mongo { assert(!"You must overwrite one of the accepted methods"); } + const int _port; + private: string _ip; - int _port; bool _logConnect; };