国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
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.

193 lines
6.7KB

  1. <?php
  2. /**
  3. * 管理目录配置文件
  4. *
  5. * @version $Id: config.php 1 14:31 2010年7月12日Z tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2021, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. define('DEDEADMIN', str_replace("\\", '/', dirname(__FILE__)));
  12. require_once(DEDEADMIN . '/../include/common.inc.php');
  13. require_once(DEDEINC . '/userlogin.class.php');
  14. header('Cache-Control:private');
  15. $dsql->safeCheck = FALSE;
  16. $dsql->SetLongLink();
  17. $cfg_admin_skin = 1;//后台管理风格
  18. if (file_exists(DEDEDATA . '/admin/skin.txt')) {
  19. $skin = file_get_contents(DEDEDATA . '/admin/skin.txt');
  20. $cfg_admin_skin = !in_array($skin, array(1, 2, 3, 4)) ? 1 : $skin;
  21. }
  22. //检查CSRF
  23. function CheckCSRF()
  24. {
  25. $cc_csrf_token_check = GetCookie("dede_csrf_token");
  26. DropCookie("dede_csrf_token");
  27. }
  28. //生成CSRF校验token,在比较重要的表单中应该要加上这个token校验
  29. $cc_csrf_token = GetCookie("dede_csrf_token");
  30. if (!isset($GLOBALS['csrf_token']) || $GLOBALS['csrf_token'] === null) {
  31. if (
  32. isset($cc_csrf_token) && is_string($cc_csrf_token)
  33. && preg_match('#^[0-9a-f]{32}$#iS', $cc_csrf_token) === 1
  34. ) {
  35. $GLOBALS['csrf_token'] = $cc_csrf_token;
  36. } else {
  37. $GLOBALS['csrf_token'] = md5(uniqid(mt_rand(), TRUE));
  38. }
  39. }
  40. if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST') {
  41. PutCookie('dede_csrf_token', $GLOBALS['csrf_token'], 7200, '/');
  42. }
  43. //获得当前脚本名称,如果您的系统被禁用了$_SERVER变量,请自行更改这个选项
  44. $dedeNowurl = $s_scriptName = '';
  45. $isUrlOpen = @ini_get('allow_url_fopen');
  46. $dedeNowurl = GetCurUrl();
  47. $dedeNowurls = explode('?', $dedeNowurl);
  48. $s_scriptName = $dedeNowurls[0];
  49. //检验用户登录状态
  50. $cuserLogin = new userLogin();
  51. if ($cuserLogin->getUserID() == -1) {
  52. if (preg_match("#PHP (.*) Development Server#", $_SERVER['SERVER_SOFTWARE'])) {
  53. $dirname = dirname($_SERVER['SCRIPT_NAME']);
  54. header("location:{$dirname}/login.php?gotopage=" . urlencode($dedeNowurl));
  55. } else {
  56. header("location:login.php?gotopage=" . urlencode($dedeNowurl));
  57. }
  58. exit();
  59. }
  60. function XSSClean($val)
  61. {
  62. if (is_array($val)) {
  63. foreach ($val as $key => $v) {
  64. if (in_array($key, array('tags', 'body', 'dede_fields', 'dede_addonfields', 'dopost', 'introduce'))) continue;
  65. $val[$key] = XSSClean($val[$key]);
  66. }
  67. return $val;
  68. }
  69. return RemoveXss($val);
  70. }
  71. if ($cfg_dede_log == 'Y') {
  72. $s_nologfile = '_main|_list';
  73. $s_needlogfile = 'sys_|file_';
  74. $s_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
  75. $s_query = isset($dedeNowurls[1]) ? $dedeNowurls[1] : '';
  76. $s_scriptNames = explode('/', $s_scriptName);
  77. $s_scriptNames = $s_scriptNames[count($s_scriptNames) - 1];
  78. $s_userip = GetIP();
  79. if ($s_method == 'POST' || (!preg_match("#" . $s_nologfile . "#i", $s_scriptNames) && $s_query != '') || preg_match("#" . $s_needlogfile . "#i", $s_scriptNames)) {
  80. $inquery = "INSERT INTO `#@__log`(adminid,filename,method,query,cip,dtime)
  81. VALUES ('" . $cuserLogin->getUserID() . "','{$s_scriptNames}','{$s_method}','" . addslashes($s_query) . "','{$s_userip}','" . time() . "');";
  82. $dsql->ExecuteNoneQuery($inquery);
  83. }
  84. }
  85. //管理缓存管理员频道缓存
  86. $cache1 = DEDEDATA . '/cache/inc_catalog_base.inc';
  87. if (!file_exists($cache1)) UpDateCatCache();
  88. $cacheFile = DEDEDATA . '/cache/admincat_' . $cuserLogin->userID . '.inc';
  89. if (file_exists($cacheFile)) require_once($cacheFile);
  90. //更新服务器
  91. require_once(DEDEDATA . '/admin/config_update.php');
  92. if (strlen($cfg_cookie_encode) <= 10) {
  93. $chars = 'abcdefghigklmnopqrstuvwxwyABCDEFGHIGKLMNOPQRSTUVWXWY0123456789';
  94. $hash = '';
  95. $length = rand(28, 32);
  96. $max = strlen($chars) - 1;
  97. for ($i = 0; $i < $length; $i++) {
  98. $hash .= $chars[mt_rand(0, $max)];
  99. }
  100. $dsql->ExecuteNoneQuery("UPDATE `#@__sysconfig` SET `value`='{$hash}' WHERE varname='cfg_cookie_encode' ");
  101. $configfile = DEDEDATA . '/config.cache.inc.php';
  102. if (!is_writeable($configfile)) {
  103. echo "配置文件'{$configfile}'不支持写入,无法修改系统配置参数";
  104. exit();
  105. }
  106. $fp = fopen($configfile, 'w');
  107. flock($fp, 3);
  108. fwrite($fp, "<" . "?php\r\n");
  109. $dsql->SetQuery("SELECT `varname`,`type`,`value`,`groupid` FROM `#@__sysconfig` ORDER BY aid ASC ");
  110. $dsql->Execute();
  111. while ($row = $dsql->GetArray()) {
  112. if ($row['type'] == 'number') {
  113. if ($row['value'] == '') $row['value'] = 0;
  114. fwrite($fp, "\${$row['varname']} = " . $row['value'] . ";\r\n");
  115. } else {
  116. fwrite($fp, "\${$row['varname']} = '" . str_replace("'", '', $row['value']) . "';\r\n");
  117. }
  118. }
  119. fwrite($fp, "?" . ">");
  120. fclose($fp);
  121. }
  122. /**
  123. * 更新栏目缓存
  124. *
  125. * @access public
  126. * @return void
  127. */
  128. function UpDateCatCache()
  129. {
  130. global $dsql, $cache1, $cuserLogin;
  131. $cache2 = DEDEDATA . '/cache/channelsonlist.inc';
  132. $cache3 = DEDEDATA . '/cache/channeltoplist.inc';
  133. $dsql->SetQuery("SELECT id,reid,channeltype,issend,typename FROM `#@__arctype`");
  134. $dsql->Execute();
  135. $fp1 = fopen($cache1, 'w');
  136. $phph = '?';
  137. $fp1Header = "<{$phph}php\r\nglobal \$cfg_Cs;\r\n\$cfg_Cs=array();\r\n";
  138. fwrite($fp1, $fp1Header);
  139. while ($row = $dsql->GetObject()) {
  140. //将typename缓存起来
  141. $row->typename = base64_encode($row->typename);
  142. fwrite($fp1, "\$cfg_Cs[{$row->id}]=array({$row->reid},{$row->channeltype},{$row->issend},'{$row->typename}');\r\n");
  143. }
  144. fwrite($fp1, "{$phph}>");
  145. fclose($fp1);
  146. $cuserLogin->ReWriteAdminChannel();
  147. @unlink($cache2);
  148. @unlink($cache3);
  149. }
  150. //清空选项缓存
  151. function ClearOptCache()
  152. {
  153. $tplCache = DEDEDATA . '/tplcache/';
  154. $fileArray = glob($tplCache . "inc_option_*.inc");
  155. if (count($fileArray) > 1) {
  156. foreach ($fileArray as $key => $value) {
  157. if (file_exists($value)) unlink($value);
  158. else continue;
  159. }
  160. return TRUE;
  161. }
  162. return FALSE;
  163. }
  164. /**
  165. * 引入模板文件
  166. *
  167. * @access public
  168. * @param string $filename 文件名称
  169. * @param bool $isabs 是否为管理目录
  170. * @return string
  171. */
  172. function DedeInclude($filename, $isabs = FALSE)
  173. {
  174. return $isabs ? $filename : DEDEADMIN . '/' . $filename;
  175. }
  176. /**
  177. * 根据用户mid获取用户名称
  178. *
  179. * @access public
  180. * @param int $mid 用户ID
  181. * @return string
  182. */
  183. if (!function_exists('GetMemberName')) {
  184. function GetMemberName($mid = 0)
  185. {
  186. global $dsql;
  187. if (empty($mid)) {
  188. return "管理员";
  189. }
  190. $rs = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='{$mid}' ");
  191. return $rs['uname'];
  192. }
  193. }