国内流行的内容管理系统(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.

221 lines
7.1KB

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