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

222 lines
7.2KB

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