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

230 lines
6.7KB

  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) 2007 - 2020, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.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_name = '_csrf_name_'.substr(md5(md5($cfg_cookie_encode)),0,8);
  24. $_csrf_hash = GetCookie($_csrf_name);
  25. if ( empty($_csrf_hash) )
  26. {
  27. $_csrf_hash = md5(uniqid(mt_rand(), TRUE));
  28. if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST')
  29. {
  30. PutCookie($_csrf_name, $_csrf_hash, 7200, '/');
  31. }
  32. }
  33. $_csrf = array(
  34. 'name' =>'_dede'.$_csrf_name,
  35. 'hash' => $_csrf_hash,
  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. $cfg_remote_site = empty($cfg_remote_site)? 'N' : $cfg_remote_site;
  44. //检验用户登录状态
  45. $cuserLogin = new userLogin();
  46. if($cuserLogin->getUserID()==-1)
  47. {
  48. if ( preg_match("#PHP (.*) Development Server#",$_SERVER['SERVER_SOFTWARE']) )
  49. {
  50. $dirname = dirname($_SERVER['SCRIPT_NAME']);
  51. header("location:{$dirname}/login.php?gotopage=".urlencode($dedeNowurl));
  52. } else {
  53. header("location:login.php?gotopage=".urlencode($dedeNowurl));
  54. }
  55. exit();
  56. }
  57. function csrf_check()
  58. {
  59. global $token;
  60. if(!isset($token) || strcasecmp($token, $_SESSION['token']) !== 0){
  61. echo '<a href="http://bbs.dedecms.com/907721.html">DedeCMS:CSRF Token Check Failed!</a>';
  62. exit;
  63. }
  64. }
  65. function XSSClean($val)
  66. {
  67. if (is_array($val))
  68. {
  69. foreach ($val as $key => $v) {
  70. if(in_array($key,array('tags','body','dede_fields','dede_addonfields','dopost','introduce'))) continue;
  71. $val[$key] = XSSClean($val[$key]);
  72. }
  73. return $val;
  74. }
  75. return RemoveXss($val);
  76. }
  77. if($cfg_dede_log=='Y')
  78. {
  79. $s_nologfile = '_main|_list';
  80. $s_needlogfile = 'sys_|file_';
  81. $s_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
  82. $s_query = isset($dedeNowurls[1]) ? $dedeNowurls[1] : '';
  83. $s_scriptNames = explode('/', $s_scriptName);
  84. $s_scriptNames = $s_scriptNames[count($s_scriptNames)-1];
  85. $s_userip = GetIP();
  86. if( $s_method=='POST' || (!preg_match("#".$s_nologfile."#i", $s_scriptNames) && $s_query!='') || preg_match("#".$s_needlogfile."#i",$s_scriptNames) )
  87. {
  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. {
  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. {
  113. echo "配置文件'{$configfile}'不支持写入,无法修改系统配置参数!";
  114. exit();
  115. }
  116. $fp = fopen($configfile,'w');
  117. flock($fp,3);
  118. fwrite($fp,"<"."?php\r\n");
  119. $dsql->SetQuery("SELECT `varname`,`type`,`value`,`groupid` FROM `#@__sysconfig` ORDER BY aid ASC ");
  120. $dsql->Execute();
  121. while($row = $dsql->GetArray())
  122. {
  123. if($row['type']=='number')
  124. {
  125. if($row['value']=='') $row['value'] = 0;
  126. fwrite($fp,"\${$row['varname']} = ".$row['value'].";\r\n");
  127. }
  128. else
  129. {
  130. fwrite($fp,"\${$row['varname']} = '".str_replace("'",'',$row['value'])."';\r\n");
  131. }
  132. }
  133. fwrite($fp,"?".">");
  134. fclose($fp);
  135. }
  136. /**
  137. * 更新栏目缓存
  138. *
  139. * @access public
  140. * @return void
  141. */
  142. function UpDateCatCache()
  143. {
  144. global $dsql, $cfg_multi_site, $cache1, $cacheFile, $cuserLogin;
  145. $cache2 = DEDEDATA.'/cache/channelsonlist.inc';
  146. $cache3 = DEDEDATA.'/cache/channeltoplist.inc';
  147. $dsql->SetQuery("SELECT id,reid,channeltype,issend,typename FROM `#@__arctype`");
  148. $dsql->Execute();
  149. $fp1 = fopen($cache1,'w');
  150. $phph = '?';
  151. $fp1Header = "<{$phph}php\r\nglobal \$cfg_Cs;\r\n\$cfg_Cs=array();\r\n";
  152. fwrite($fp1,$fp1Header);
  153. while($row=$dsql->GetObject())
  154. {
  155. // 将typename缓存起来
  156. $row->typename = base64_encode($row->typename);
  157. fwrite($fp1,"\$cfg_Cs[{$row->id}]=array({$row->reid},{$row->channeltype},{$row->issend},'{$row->typename}');\r\n");
  158. }
  159. fwrite($fp1, "{$phph}>");
  160. fclose($fp1);
  161. $cuserLogin->ReWriteAdminChannel();
  162. @unlink($cache2);
  163. @unlink($cache3);
  164. }
  165. // 清空选项缓存
  166. function ClearOptCache()
  167. {
  168. $tplCache = DEDEDATA.'/tplcache/';
  169. $fileArray = glob($tplCache."inc_option_*.inc");
  170. if (count($fileArray) > 1)
  171. {
  172. foreach ($fileArray as $key => $value)
  173. {
  174. if (file_exists($value)) unlink($value);
  175. else continue;
  176. }
  177. return TRUE;
  178. }
  179. return FALSE;
  180. }
  181. /**
  182. * 引入模板文件
  183. *
  184. * @access public
  185. * @param string $filename 文件名称
  186. * @param bool $isabs 是否为管理目录
  187. * @return string
  188. */
  189. function DedeInclude($filename, $isabs=FALSE)
  190. {
  191. return $isabs ? $filename : DEDEADMIN.'/'.$filename;
  192. }
  193. helper('cache');
  194. /**
  195. * 根据用户mid获取用户名称
  196. *
  197. * @access public
  198. * @param int $mid 用户ID
  199. * @return string
  200. */
  201. if(!function_exists('GetMemberName')){
  202. function GetMemberName($mid=0)
  203. {
  204. global $dsql;
  205. $rs = GetCache('memberlogin', $mid);
  206. if( empty($rs) )
  207. {
  208. $rs = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='{$mid}' ");
  209. SetCache('memberlogin', $mid, $rs, 1800);
  210. }
  211. return $rs['uname'];
  212. }
  213. }