diff --git a/app/classes/VarEval.php b/app/classes/VarEval.php index dab1352..4bb8d73 100644 --- a/app/classes/VarEval.php +++ b/app/classes/VarEval.php @@ -144,9 +144,74 @@ function ISODate (isoDateStr) { date_default_timezone_set($timezone); if ($ret["ok"]) { return $ret["retval"]; + } elseif($ret["errmsg"] === "unauthorized") { + return $this->parseBson($this->_source); } return false; } + + private function parseBson($source) + { + $pattern = "/([a-z]{1,})\(([^)]+)\)/i"; + $matches = null; + preg_match_all($pattern, $source, $matches); + + $sourceEscaped = $source; + + if(isset($matches[0])) + { + foreach($matches[0] as $matchKey => $objectString) + { + $tmpArray = array( + 'ClassName' => $matches[1][$matchKey], + 'Params' => $matches[2][$matchKey], + ); + + $sourceEscaped = str_replace($objectString, json_encode($tmpArray), $sourceEscaped); + } + } + $bson = $this->initBson(json_decode($sourceEscaped, true)); + return $bson; + } + + private function initBson($source) + { + foreach($source as $key => $val) + { + if(isset($val['ClassName'])) + { + + $paramWithoutQuotes = substr($val['Params'] , 1, -1 ); // remove quotes + + switch($val['ClassName']) + { + case 'ObjectId': + $source[$key] = new MongoId($paramWithoutQuotes); + break; + case 'NumberInt': + case 'NumberLong': + $source[$key] = (int) $val['Params']; + break; + case 'NumberDouble': + $source[$key] = (double) $val['Params']; + break; + case 'NumberFloat': + $source[$key] = (float) $val['Params']; + break; + case 'ISODate': + $dateTime = new DateTime($paramWithoutQuotes); + $source[$key] = new MongoDate($dateTime->getTimestamp(), $dateTime->format("u")); + default: + unset($source['key']); + } + } + elseif( is_array( $val ) || $val instanceof Traversable ) + { + $source[$key] = $this->initBson($val); + } + } + return $source; + } } ?> \ No newline at end of file diff --git a/app/controllers/server.php b/app/controllers/server.php index 86e7b4a..2a8395c 100644 --- a/app/controllers/server.php +++ b/app/controllers/server.php @@ -5,7 +5,7 @@ class ServerController extends BaseController { /** server infomation **/ public function doIndex() { - $db = $this->_mongo->selectDB("admin"); + $db = $this->_mongo->selectDB( empty($_SESSION['login']['db']) ? 'admin' : $_SESSION['login']['db'] ); //command line try { @@ -267,7 +267,7 @@ public function doReplication() { foreach ($query as $one) { foreach ($one as $param=>$value) { if ($param == "syncedTo") { - $one[$param] = date("Y-m-d H:i:s", $value->inc) . "." . $value->sec; + $one[$param] = date("Y-m-d H:i:s", $value->sec) . "." . $value->inc; } } $this->slaves[] = $one; @@ -284,7 +284,7 @@ public function doReplication() { foreach ($one as $param=>$value) { if ($param == "syncedTo" || $param == "localLogTs") { if ($value->inc > 0) { - $one[$param] = date("Y-m-d H:i:s", $value->inc) . "." . $value->sec; + $one[$param] = date("Y-m-d H:i:s", $value->sec) . "." . $value->inc; } } } diff --git a/app/lib/mongo/RMongo.php b/app/lib/mongo/RMongo.php index 7331152..4c0a7bc 100644 --- a/app/lib/mongo/RMongo.php +++ b/app/lib/mongo/RMongo.php @@ -17,7 +17,16 @@ class RMongo { */ public function __construct($server, array $options = array()) { if (class_exists("MongoClient")) { - $this->_mongo = new MongoClient($server, $options); + try { + $this->_mongo = new MongoClient($server, $options); + } catch ( Exception $e ) { + $options['db'] = 'admin'; + try { + $this->_mongo = new MongoClient($server, $options); + } catch ( Exception $tmp ) { + throw $e; + } + } } else { $this->_mongo = new Mongo($server, $options); @@ -123,7 +132,11 @@ public function lastError() { * @return array */ public function listDBs() { - return $this->_mongo->listDBs(); + try { + return $this->_mongo->listDBs(); + } catch( Exception $e ) { + return array(); + } } /** diff --git a/app/lib/page/lang/ru_ru.php b/app/lib/page/lang/ru_ru.php old mode 100755 new mode 100644 diff --git a/app/models/MDb.php b/app/models/MDb.php index 1f21b1c..45b8d84 100644 --- a/app/models/MDb.php +++ b/app/models/MDb.php @@ -28,7 +28,7 @@ static function listCollections(MongoDB $db) { $names = array(); try { - $names = self::exec($db, 'function (){ return db.getCollectionNames(); }'); + $names = $db->getCollectionNames(); } catch(Exception $e) { } diff --git a/app/models/MServer.php b/app/models/MServer.php index 4346784..9e412a8 100644 --- a/app/models/MServer.php +++ b/app/models/MServer.php @@ -253,11 +253,11 @@ public function docsNatureOrder() { return $this->_docsNatureOrder; } - /** + /** * Set documents highlight render * - * @param string $render can be "default" or "plain" - * @since 1.1.6 + * @param string $render can be "default" or "plain" + * @since 1.1.6 */ public function setDocsRender($render) { $renders = array( "default", "plain" ); @@ -338,7 +338,7 @@ public function auth($username, $password, $db = "admin") { //authenticate if (!empty($this->_mongoUser)) { - // "authenticate" can only be used between 1.0.1 - 1.2.11 + // "authenticate" can only be used between 1.0.1 - 1.2.11 if (RMongo::compareVersion("1.0.1") >= 0 && RMongo::compareVersion("1.2.11") < 0) { return $this->_mongo ->selectDB($db) @@ -349,7 +349,7 @@ public function auth($username, $password, $db = "admin") { else { //authenticate if (!empty($this->_mongoUser)) { - // "authenticate" can only be used between 1.0.1 - 1.2.11 + // "authenticate" can only be used between 1.0.1 - 1.2.11 if (RMongo::compareVersion("1.0.1") >= 0 && RMongo::compareVersion("1.2.11") < 0) { return $this->_mongo ->selectDB($db) @@ -381,7 +381,7 @@ public function listDbs() { } catch (Exception $e) { $dbs["ok"] = false; } - if (!$dbs["ok"]) { + if (empty($dbs["ok"])) { $user = MUser::userInSession(); $dbs = array(