/** called before any actions **/ public function onBefore() { global $MONGO; //exception handler set_exception_handler(array($this, "exceptionHandler")); $this->_admin = MUser::userInSession(); if (!$this->_admin) { //if user is loged in? $server = MServer::serverWithIndex(xi("host")); //filter server plugins if (class_exists("RFilter")) { RFilter::apply("SERVER_FILTER", $server); } //if auth is disabled if ($server && !$server->mongoAuth() && !$server->controlAuth()) { MUser::login("rockmongo_memo", "rockmongo_memo", xi("host"), "admin", 10800); $this->_admin = MUser::userInSession(); } else { $this->redirect("login.index", array("host" => xi("host"))); } } if (!$this->_admin->validate()) { $this->redirect("login.index", array("host" => $this->_admin->hostIndex())); } $this->_server = MServer::serverWithIndex($this->_admin->hostIndex()); $this->_mongo = $this->_server->mongo(); //log query if (isset($MONGO["features"]["log_query"]) && $MONGO["features"]["log_query"] == "on") { $this->_logQuery = true; } //render header if (!$this->isAjax()) { render_view("header"); } }
/** change current host **/ public function doChangeHost() { $index = xi("index"); MUser::userInSession()->changeHost($index); $this->redirect("admin.index"); }
/** * Construct mongo server connection URI * * @return string */ public function uri() { $host = $this->_mongoHost . ":" . $this->_mongoPort; if ($this->_mongoAuth) { $user = MUser::userInSession(); return $user->username() . ":" . $user->password() . "@" . $host; } if (empty($this->_mongoUser)) { return $host; } return $this->_mongoUser . ":" . $user->_mongoPass . "@" . $host; }