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

235 lines
7.0KB

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