Index.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\home\controller;
  3. use think\Lang;
  4. use think\Cache;
  5. class Index extends AdminControl
  6. {
  7. public function _initialize()
  8. {
  9. parent::_initialize();
  10. Lang::load(APP_PATH . 'home/lang/' . config('default_lang') . '/index.lang.php');
  11. }
  12. public function index()
  13. {
  14. $allpower = $this->qxhans();
  15. $this->assign('allpower',$allpower);
  16. $this->assign('admin_info', $this->getAdminInfo());
  17. return $this->fetch();
  18. }
  19. /**
  20. * 修改密码
  21. */
  22. public function modifypw()
  23. {
  24. if (request()->isPost()) {
  25. $new_pw = trim(input('post.new_pw'));
  26. $new_pw2 = trim(input('post.new_pw2'));
  27. $old_pw = trim(input('post.old_pw'));
  28. if ($new_pw !== $new_pw2) {
  29. $this->error(lang('index_modifypw_repeat_error'));
  30. }
  31. $admininfo = $this->getAdminInfo();
  32. //查询管理员信息
  33. $service_model = model('service');
  34. $admininfo = $service_model->getserviceInfo(array('service_id' => $admininfo['service_id']));
  35. if (!is_array($admininfo) || count($admininfo) <= 0) {
  36. $this->error(lang('index_modifypw_admin_error'));
  37. }
  38. //旧密码是否正确
  39. if ($admininfo['service_password'] != md5($old_pw)) {
  40. $this->error(lang('index_modifypw_oldpw_error'));
  41. }
  42. $new_pw = md5($new_pw);
  43. $result = $service_model->editService(array('service_id' => $admininfo['service_id']), array('service_password' => $new_pw));
  44. if ($result) {
  45. session(null);
  46. dsLayerOpenSuccess(lang('index_modifypw_succ'));
  47. } else {
  48. $this->error(lang('index_modifypw_fail'));
  49. }
  50. } else {
  51. $this->setAdminCurItem('modifypw');
  52. return $this->fetch();
  53. }
  54. }
  55. /**
  56. * 首页
  57. * @return mixed
  58. */
  59. // public function welCome()
  60. // {
  61. // $setup_date = config('setup_date');
  62. // $statistics['os'] = PHP_OS;
  63. // $statistics['web_server'] = $_SERVER['SERVER_SOFTWARE'];
  64. // $statistics['php_version'] = PHP_VERSION;
  65. // $statistics['sql_version'] = $this->_mysql_version();
  66. // $statistics['setup_date'] = substr($setup_date, 0, 10);
  67. // $statistics['domain'] = $_SERVER['HTTP_HOST'];
  68. // $statistics['ip'] = GetHostByName($_SERVER['SERVER_NAME']);
  69. // $statistics['zlib'] = function_exists('gzclose') ? 'YES' : 'NO'; //zlib
  70. // $statistics['safe_mode'] = (boolean)ini_get('safe_mode') ? 'YES' : 'NO'; //safe_mode = Off
  71. // $statistics['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
  72. // $statistics['curl'] = function_exists('curl_init') ? 'YES' : 'NO';
  73. // $statistics['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknown';
  74. // $statistics['max_ex_time'] = @ini_get("max_execution_time") . 's'; //脚本最大执行时间
  75. // $statistics['set_time_limit'] = function_exists("set_time_limit") ? true : false;
  76. // $statistics['memory_limit'] = ini_get('memory_limit');
  77. // $statistics['version'] = file_get_contents(APP_PATH . 'version.php');
  78. // if (function_exists("gd_info")) {
  79. // $gd = gd_info();
  80. // $statistics['gdinfo'] = $gd['GD Version'];
  81. // } else {
  82. // $statistics['gdinfo'] = lang('Unknown');
  83. // }
  84. // $this->assign('statistics', $statistics);
  85. // return $this->fetch('welcome');
  86. // }
  87. private function _mysql_version()
  88. {
  89. $version = db()->query("select version() as ver");
  90. return $version[0]['ver'];
  91. }
  92. /**
  93. * 修改当前语言
  94. */
  95. public function setLanguageCookie()
  96. {
  97. $language = input('param.language');
  98. if ($language == config('default_lang')) {
  99. $this->error(\lang('ds_language_repetition'), url('Index/index'));
  100. exit();
  101. }
  102. setcookie("ds_admin_lang", $language, 0, '/');
  103. $this->success(\lang('ds_language_switching'), url('Index/index'));
  104. exit();
  105. }
  106. /**
  107. * 删除缓存
  108. */
  109. function clear()
  110. {
  111. $this->delCacheFile('temp');
  112. $this->delCacheFile('cache');
  113. Cache::clear();
  114. ds_json_encode(10000, lang('eliminate_succ'));
  115. exit();
  116. }
  117. /**
  118. * 删除缓存目录下的文件或子目录文件
  119. *
  120. * @param string $dir 目录名或文件名
  121. * @return boolean
  122. */
  123. function delCacheFile($dir)
  124. {
  125. //防止删除cache以外的文件
  126. if (strpos($dir, '..') !== false)
  127. return false;
  128. $path = RUNTIME_PATH . '/' . $dir;
  129. if (is_dir($path)) {
  130. $file_list = array();
  131. read_file_list($path, $file_list);
  132. if (!empty($file_list)) {
  133. foreach ($file_list as $v) {
  134. if (basename($v) != 'index.html')
  135. @unlink($v);
  136. }
  137. }
  138. } else {
  139. if (basename($path) != 'index.html')
  140. @unlink($path);
  141. }
  142. return true;
  143. }
  144. }