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

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