You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

94 lines
2.2 KiB

  1. <?php
  2. import("classes.BaseController");
  3. class AdminController extends BaseController {
  4. /** admin page **/
  5. public function doIndex() {
  6. $this->topUrl = $this->path("admin.top");
  7. $this->leftUrl = $this->path("admin.dbs");
  8. $this->rightUrl = $this->path("server.index");
  9. $this->display();
  10. }
  11. /** top frame **/
  12. public function doTop() {
  13. $this->logoutUrl = $this->path("logout.index");
  14. $this->admin = $this->_admin->username();
  15. $this->servers = $this->_admin->servers();
  16. $this->serverIndex = $this->_admin->hostIndex();
  17. $isMasterRet = null;
  18. try {
  19. $isMasterRet = $this->_mongo->selectDB($this->_admin->defaultDb())->command(array( "isMaster" => 1 ));
  20. if ($isMasterRet["ok"]) {
  21. $this->isMaster = $isMasterRet["ismaster"];
  22. }
  23. else {
  24. $this->isMaster = true;
  25. }
  26. } catch (MongoCursorException $e) {
  27. $this->isMaster = null;
  28. }
  29. $this->display();
  30. }
  31. /** show dbs in left frame **/
  32. public function doDbs() {
  33. $dbs = $this->_server->listDbs();
  34. $this->dbs = array_values(rock_array_sort($dbs["databases"], "name"));
  35. $this->baseUrl = $this->path("admin.dbs");
  36. $this->tableUrl = $this->path("collection.index");
  37. $this->showDbSelector = false;
  38. //add collection count
  39. foreach ($this->dbs as $index => $db) {
  40. $collectionCount = count(MDb::listCollections($this->_mongo->selectDB($db["name"])));
  41. $db["collectionCount"] = $collectionCount;
  42. if (isset($db["sizeOnDisk"])) {
  43. $db["size"] = round($db["sizeOnDisk"]/1024/1024, 2);//M
  44. }
  45. $this->dbs[$index] = $db;
  46. }
  47. //current db
  48. $db = x("db");
  49. $this->tables = array();
  50. if ($db) {
  51. $mongodb = $this->_mongo->selectDB($db);
  52. $tables = MDb::listCollections($mongodb);
  53. foreach ($tables as $table) {
  54. $this->tables[$table->getName()] = $table->count();
  55. }
  56. }
  57. $this->display();
  58. }
  59. /** about project and us **/
  60. public function doAbout() {
  61. $this->display();
  62. }
  63. /** change current host **/
  64. public function doChangeHost() {
  65. $index = xi("index");
  66. MUser::userInSession()->changeHost($index);
  67. $this->redirect("admin.index", array( "host" => $index ));
  68. }
  69. /**
  70. * change language of UI interface
  71. *
  72. */
  73. public function doChangeLang() {
  74. setcookie("ROCK_LANG", x("lang"), time() + 365 * 86400);
  75. header("location:index.php");
  76. }
  77. }
  78. ?>