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

158 lines
5.3KB

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