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

159 lines
5.3KB

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