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

323 lines
9.5KB

  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. //启用远程站点则创建FTP类
  94. if($cfg_remote_site=='Y')
  95. {
  96. require_once(DEDEINC.'/ftp.class.php');
  97. if(file_exists(DEDEDATA."/cache/inc_remote_config.php"))
  98. {
  99. require_once DEDEDATA."/cache/inc_remote_config.php";
  100. }
  101. if(empty($remoteuploads)) $remoteuploads = 0;
  102. if(empty($remoteupUrl)) $remoteupUrl = '';
  103. $config = array(
  104. 'hostname' => $GLOBALS['cfg_ftp_host'],
  105. 'username' => $GLOBALS['cfg_ftp_user'],
  106. 'password' => $GLOBALS['cfg_ftp_pwd'],
  107. 'debug' => 'TRUE'
  108. );
  109. $ftp = new FTP($config);
  110. //初始化FTP配置
  111. if($remoteuploads==1){
  112. $ftpconfig = array(
  113. 'hostname'=>$rmhost,
  114. 'port'=>$rmport,
  115. 'username'=>$rmname,
  116. 'password'=>$rmpwd
  117. );
  118. }
  119. }
  120. //管理缓存、管理员频道缓存
  121. $cache1 = DEDEDATA.'/cache/inc_catalog_base.inc';
  122. if(!file_exists($cache1)) UpDateCatCache();
  123. $cacheFile = DEDEDATA.'/cache/admincat_'.$cuserLogin->userID.'.inc';
  124. if(file_exists($cacheFile)) require_once($cacheFile);
  125. //更新服务器
  126. require_once (DEDEDATA.'/admin/config_update.php');
  127. if(strlen($cfg_cookie_encode)<=10)
  128. {
  129. $chars='abcdefghigklmnopqrstuvwxwyABCDEFGHIGKLMNOPQRSTUVWXWY0123456789';
  130. $hash='';
  131. $length = rand(28,32);
  132. $max = strlen($chars) - 1;
  133. for($i = 0; $i < $length; $i++) {
  134. $hash .= $chars[mt_rand(0, $max)];
  135. }
  136. $dsql->ExecuteNoneQuery("UPDATE `#@__sysconfig` SET `value`='{$hash}' WHERE varname='cfg_cookie_encode' ");
  137. $configfile = DEDEDATA.'/config.cache.inc.php';
  138. if(!is_writeable($configfile))
  139. {
  140. echo "配置文件'{$configfile}'不支持写入,无法修改系统配置参数!";
  141. exit();
  142. }
  143. $fp = fopen($configfile,'w');
  144. flock($fp,3);
  145. fwrite($fp,"<"."?php\r\n");
  146. $dsql->SetQuery("SELECT `varname`,`type`,`value`,`groupid` FROM `#@__sysconfig` ORDER BY aid ASC ");
  147. $dsql->Execute();
  148. while($row = $dsql->GetArray())
  149. {
  150. if($row['type']=='number')
  151. {
  152. if($row['value']=='') $row['value'] = 0;
  153. fwrite($fp,"\${$row['varname']} = ".$row['value'].";\r\n");
  154. }
  155. else
  156. {
  157. fwrite($fp,"\${$row['varname']} = '".str_replace("'",'',$row['value'])."';\r\n");
  158. }
  159. }
  160. fwrite($fp,"?".">");
  161. fclose($fp);
  162. }
  163. /**
  164. * 更新栏目缓存
  165. *
  166. * @access public
  167. * @return void
  168. */
  169. function UpDateCatCache()
  170. {
  171. global $dsql, $cfg_multi_site, $cache1, $cacheFile, $cuserLogin;
  172. $cache2 = DEDEDATA.'/cache/channelsonlist.inc';
  173. $cache3 = DEDEDATA.'/cache/channeltoplist.inc';
  174. $dsql->SetQuery("SELECT id,reid,channeltype,issend,typename FROM `#@__arctype`");
  175. $dsql->Execute();
  176. $fp1 = fopen($cache1,'w');
  177. $phph = '?';
  178. $fp1Header = "<{$phph}php\r\nglobal \$cfg_Cs;\r\n\$cfg_Cs=array();\r\n";
  179. fwrite($fp1,$fp1Header);
  180. while($row=$dsql->GetObject())
  181. {
  182. // 将typename缓存起来
  183. $row->typename = base64_encode($row->typename);
  184. fwrite($fp1,"\$cfg_Cs[{$row->id}]=array({$row->reid},{$row->channeltype},{$row->issend},'{$row->typename}');\r\n");
  185. }
  186. fwrite($fp1, "{$phph}>");
  187. fclose($fp1);
  188. $cuserLogin->ReWriteAdminChannel();
  189. @unlink($cache2);
  190. @unlink($cache3);
  191. }
  192. // 清空选项缓存
  193. function ClearOptCache()
  194. {
  195. $tplCache = DEDEDATA.'/tplcache/';
  196. $fileArray = glob($tplCache."inc_option_*.inc");
  197. if (count($fileArray) > 1)
  198. {
  199. foreach ($fileArray as $key => $value)
  200. {
  201. if (file_exists($value)) unlink($value);
  202. else continue;
  203. }
  204. return TRUE;
  205. }
  206. return FALSE;
  207. }
  208. /**
  209. * 更新会员模型缓存
  210. *
  211. * @access public
  212. * @return void
  213. */
  214. function UpDateMemberModCache()
  215. {
  216. global $dsql;
  217. $cachefile = DEDEDATA.'/cache/member_model.inc';
  218. $dsql->SetQuery("SELECT * FROM `#@__member_model` WHERE state='1'");
  219. $dsql->Execute();
  220. $fp1 = fopen($cachefile,'w');
  221. $phph = '?';
  222. $fp1Header = "<{$phph}php\r\nglobal \$_MemberMod;\r\n\$_MemberMod=array();\r\n";
  223. fwrite($fp1,$fp1Header);
  224. while($row=$dsql->GetObject())
  225. {
  226. fwrite($fp1,"\$_MemberMod[{$row->id}]=array('{$row->name}','{$row->table}');\r\n");
  227. }
  228. fwrite($fp1,"{$phph}>");
  229. fclose($fp1);
  230. }
  231. /**
  232. * 引入模板文件
  233. *
  234. * @access public
  235. * @param string $filename 文件名称
  236. * @param bool $isabs 是否为管理目录
  237. * @return string
  238. */
  239. function DedeInclude($filename, $isabs=FALSE)
  240. {
  241. return $isabs ? $filename : DEDEADMIN.'/'.$filename;
  242. }
  243. /**
  244. * 获取当前用户的ftp站点
  245. *
  246. * @access public
  247. * @param string $current 当前站点
  248. * @param string $formname 表单名称
  249. * @return string
  250. */
  251. function GetFtp($current='', $formname='')
  252. {
  253. global $dsql;
  254. $formname = empty($formname)? 'serviterm' : $formname;
  255. $cuserLogin = new userLogin();
  256. $row=$dsql->GetOne("SELECT servinfo FROM `#@__multiserv_config`");
  257. $row['servinfo']=trim($row['servinfo']);
  258. if(!empty($row['servinfo'])){
  259. $servinfos = explode("\n", $row['servinfo']);
  260. $select="";
  261. echo '<select name="'.$formname.'" size="1" id="serviterm">';
  262. $i=0;
  263. foreach($servinfos as $servinfo){
  264. $servinfo = trim($servinfo);
  265. list($servname,$servurl,$servport,$servuser,$servpwd,$userlist) = explode('|',$servinfo);
  266. $servname = trim($servname);
  267. $servurl = trim($servurl);
  268. $servport = trim($servport);
  269. $servuser = trim($servuser);
  270. $servpwd = trim($servpwd);
  271. $userlist = trim($userlist);
  272. $checked = ($current == $i)? ' selected="selected"' : '';
  273. if(strstr($userlist,$cuserLogin->getUserName()))
  274. {
  275. $select.="<option value='".$servurl.",".$servuser.",".$servpwd."'{$checked}>".$servname."</option>";
  276. }
  277. $i++;
  278. }
  279. echo $select."</select>";
  280. }
  281. }
  282. helper('cache');
  283. /**
  284. * 根据用户mid获取用户名称
  285. *
  286. * @access public
  287. * @param int $mid 用户ID
  288. * @return string
  289. */
  290. if(!function_exists('GetMemberName')){
  291. function GetMemberName($mid=0)
  292. {
  293. global $dsql;
  294. $rs = GetCache('memberlogin', $mid);
  295. if( empty($rs) )
  296. {
  297. $rs = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='{$mid}' ");
  298. SetCache('memberlogin', $mid, $rs, 1800);
  299. }
  300. return $rs['uname'];
  301. }
  302. }