mainmenu.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. include_once __DIR__ . '/../../Amfphp/Util/HttpUtil.php';
  3. include_once __DIR__ . '/debug.php';
  4. use loyalsoft\RenderTime;
  5. /**
  6. * Description of MainMenu
  7. * 后台主界面
  8. * @author gwang (mail@wanggangzero.cn)
  9. */
  10. class MainMenu extends core
  11. {
  12. //put your code here
  13. public static function index()
  14. {
  15. if (self::_checkGrant()) {
  16. self::view('mainmenu.tpl');
  17. } else {
  18. self::login();
  19. }
  20. }
  21. public static function login()
  22. {
  23. // 访问授权控制
  24. $accessManager = new Amfphp_BackOffice_AccessManager();
  25. $isAccessGranted = $accessManager->isAccessGranted();
  26. $name = "91bfa85e5204b5806d536a098caacd31";
  27. $pwd = "a08dd655a04c8c4cd541c92c6d5d1350";
  28. $errorMessage = '';
  29. $redirectToHome = false;
  30. try {
  31. if ($isAccessGranted) {
  32. $redirectToHome = true;
  33. } else if (isset($_POST['username'])) {
  34. //user is logging in.
  35. $username = $_POST['username'];
  36. $password = $_POST['password'];
  37. if (md5($username) == $name && md5($password) == $pwd) {
  38. if (session_id() == '') {
  39. session_start();
  40. }
  41. if (!isset($_SESSION[$name])) {
  42. $_SESSION[$name] = array();
  43. }
  44. $_SESSION[$name][$pwd] = true; # 设置授权
  45. $redirectToHome = true;
  46. } else {
  47. throw new Exception('Invalid username/password');
  48. }
  49. }
  50. if ($redirectToHome) {
  51. echo "<script> window.location = './index.php'; </script>";
  52. return;
  53. }
  54. } catch (Exception $e) {
  55. $errorMessage = $e->getMessage();
  56. }
  57. self::view('login.tpl', compact('redirectToHome', 'errorMessage'));
  58. }
  59. public static function debug()
  60. {
  61. if (self::_checkGrant()) {
  62. self::view(__FUNCTION__ . ".tpl");
  63. } else {
  64. self::login();
  65. }
  66. }
  67. public static function monitor()
  68. {
  69. if (self::_checkGrant()) {
  70. self::view(__FUNCTION__ . ".tpl");
  71. } else {
  72. self::login();
  73. }
  74. }
  75. public static function call()
  76. {
  77. if (self::_checkGrant()) {
  78. $params = loyalsoft\query_paras();
  79. $className = $params['className'];
  80. $mname = $params['method'];
  81. if ($className && $mname) {
  82. include_once __DIR__ . '/../../Amfphp/Services/' . str_replace("loyalsoft", "", $className) . '.php';
  83. # 直接向客户端输出返回值
  84. $rt = new RenderTime();
  85. ob_start();
  86. $result = call_user_func_array(array($className, $mname), array_values($_POST));
  87. $content = ob_end_flush();
  88. $rt->end();
  89. if (strlen($content) > 0) {
  90. echoLine("输出: " . $content);
  91. }
  92. echo "<hr/><hr/>";
  93. echoLine("返回值: " . json_encode($result));
  94. echo "<hr/><hr/>";
  95. echoLine("耗时:", $rt->getRenderTime());
  96. }
  97. } else {
  98. self::login();
  99. }
  100. }
  101. /**
  102. * 查验授权
  103. * @return boolean
  104. */
  105. private static function _checkGrant()
  106. { // 访问授权控制
  107. $accessManager = new Amfphp_BackOffice_AccessManager();
  108. return $accessManager->isAccessGranted();
  109. }
  110. }