/** * login page and post */ public function doIndex() { global $MONGO; $password = trim(xn("password")); $this->username = trim(xn("username")); $this->db = trim(xn("db")); $this->hostIndex = xi("host"); $this->languages = rock_load_languages(); $this->expires = array(3 => "3 " . rock_lang("hours"), 720 => "1 " . rock_lang("month")); $this->moreOptions = xi("more"); if ($this->isPost()) { //server exists? if (!isset($MONGO["servers"][$this->hostIndex])) { $this->message = "Server does not exist"; return; } //authenticate $server = MServer::serverWithIndex($this->hostIndex); if (!$server->auth($this->username, $password, $this->db)) { $this->message = rock_lang("can_not_auth"); $this->display(); return; } //remember user import("models.MUser"); MUser::login($this->username, $password, $this->hostIndex, $this->db, xi("expire") * 3600); //remember lang setcookie("ROCK_LANG", x("lang"), time() + 365 * 86400); //jump to admin page $this->redirect("admin.index", array("host" => $this->hostIndex)); } else { $this->display(); } }
/** 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"); }
/** create new collection **/ public function doNewCollection() { $this->db = xn("db"); $this->name = trim(xn("name")); $this->isCapped = xi("is_capped"); $this->size = xi("size"); $this->max = xi("max"); if ($this->isPost()) { $db = $this->_mongo->selectDB($this->db); MCollection::createCollection($db, $this->name, array("capped" => $this->isCapped, "size" => $this->size, "max" => $this->max)); $this->message = "New collection is created. <a href=\"?action=collection.index&db={$this->db}&collection={$this->name}\">[GO »]</a>"; //add index if (!$this->isCapped) { $db->selectCollection($this->name)->ensureIndex(array("_id" => 1)); } } $this->display(); }
/** collection properties **/ public function doCollectionProps() { $this->db = xn("db"); $this->collection = xn("collection"); $ret = $this->_mongo->selectDB($this->db)->selectCollection("system.namespaces")->findOne(array("name" => $this->db . "." . $this->collection)); $this->isCapped = 0; $this->size = 0; $this->max = 0; if (isset($ret["options"]["capped"])) { $this->isCapped = $ret["options"]["capped"]; } if (isset($ret["options"]["size"])) { $this->size = $ret["options"]["size"]; } if (isset($ret["options"]["max"])) { $this->max = $ret["options"]["max"]; } if ($this->isPost()) { $this->isCapped = xi("is_capped"); $this->size = xi("size"); $this->max = xi("max"); //rename current collection $bkCollection = $this->collection . "_rockmongo_bk_" . uniqid(); $this->ret = $this->_mongo->selectDB($this->db)->execute('function (coll, newname, dropExists) { db.getCollection(coll).renameCollection(newname, dropExists);}', array($this->collection, $bkCollection, true)); if (!$this->ret["ok"]) { $this->error = "There is something wrong:<font color=\"red\">{$this->ret['errmsg']}</font>, please refresh the page to try again."; $this->display(); return; } //create new collection $db = $this->_mongo->selectDB($this->db); MCollection::createCollection($db, $this->collection, array("capped" => $this->isCapped, "size" => $this->size, "max" => $this->max)); //copy data to new collection if (!$this->_copyCollection($db, $bkCollection, $this->collection, true)) { //try to recover $this->ret = $db->execute('function (coll, newname, dropExists) { db.getCollection(coll).renameCollection(newname, dropExists);}', array($bkCollection, $this->collection, true)); $this->error = "There is something wrong:<font color=\"red\">{$ret['errmsg']}</font>, please refresh the page to try again."; $this->display(); return; } //drop current collection $db->dropCollection($bkCollection); } $this->display(); }
} ?> </span> <!-- end query fields and hints --> <label id="limitLabel" <?php if (x("command") != "findAll") { ?> style="display:none"<?php } ?> ><?php hm("limit"); ?> :<input type="text" name="limit" size="5" value="<?php h(xi("limit")); ?> "/> |</label> <span id="pageSetLabel" <?php if (x("command") != "findAll") { ?> style="display:none"<?php } ?> > <select name="pagesize" title="<?php hm("rows_per_page"); ?> "> <?php foreach (array(10, 15, 20, 30, 50, 100, 200) as $pagesize) {
/** create new collection **/ public function doNewCollection() { $this->db = xn("db"); $this->name = trim(xn("name")); $this->isCapped = xi("is_capped"); $this->size = xi("size"); $this->max = xi("max"); if ($this->isPost()) { $db = $this->_mongo->selectDB($this->db); $db->createCollection($this->name, $this->isCapped, $this->size, $this->max); $this->message = "New collection is created."; //add index if (!$this->isCapped) { $db->selectCollection($this->name)->ensureIndex(array("_id" => 1)); } } $this->display(); }
function calculateOverlap($c1x, $c1y, $r1, $c2x, $c2y, $r2) { $c1 = array("x" => $c1x, "y" => $c1y); $c2 = array("x" => $c2x, "y" => $c2y); $t1 = trans($c1, $c1); $t2 = trans($c2, $c1); $z1 = rot($t1, $c1, $c2); $z2 = rot($t2, $c1, $c2); $ksi = xi($z2["x"], $r1, $r2); $eta = yi($z2["x"], $r1, $r2); $d1 = $ksi; $d2 = $z2["x"] - $ksi; $A1 = 0; $A2 = 0; if ($z2["x"] > $r1 + $r2) { /* No overlap */ //echo "No overlap</br>"; $A1 = 0; $A2 = 0; } elseif ($z2["x"] + $r1 < $r2) { /* Circle 1 is inside circle 2 */ //echo "C1 in C2</br>"; $A1 = $r1 * $r1 * pi(); $A2 = 0; } elseif ($z2["x"] + $r2 < $r1) { /* Circle 2 is inside circle 1 */ //echo "C2 in C1</br>"; $A1 = 0; $A2 = $r2 * $r2 * pi(); } else { //echo "Crossing</br>"; $A1 = Ai($r1, $d1); $A2 = Ai($r2, $d2); } return $A1 + $A2; }
/** kill one operation in processlist **/ public function doKillOp() { $opid = xi("opid"); $query = $this->_mongo->selectDB("admin")->execute('function (opid){ return db.killOp(opid); }', array($opid)); if ($query["ok"]) { $this->redirect("server.processlist"); } $this->ret = $this->_highlight($query, "json"); $this->display(); }
if ($level == 2) { ?> selected="selected"<?php } ?> ><?php echo hm("profiling_level3"); ?> </option> </select><br/> <div id="slowmsDiv" style="display:none"> <?php echo hm("timecost"); ?> > <input type="text" name="slowms" size="7" value="<?php h(xi("slowms")); ?> "/> ms </div> <input type="submit" value="<?php hm("save"); ?> "/> </form> </div> <script language="javascript"> function changeLevel(select) { if (select.value == 1) { //$("#slowmsDiv").show(); }