fun.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <?php
  2. //返回编码
  3. function InstallReturnDbChar(){
  4. if(EmpireCMS_CHARVER=='UTF-8')//简体UTF-8
  5. {
  6. $ret_r['dbchar']='utf8';
  7. $ret_r['setchar']='utf8';
  8. $ret_r['headerchar']='utf-8';
  9. }
  10. elseif(EmpireCMS_CHARVER=='BIG5')//繁体BIG5
  11. {
  12. $ret_r['dbchar']='big5';
  13. $ret_r['setchar']='big5';
  14. $ret_r['headerchar']='big5';
  15. }
  16. elseif(EmpireCMS_CHARVER=='TC-UTF-8')//繁体UTF-8
  17. {
  18. $ret_r['dbchar']='utf8';
  19. $ret_r['setchar']='utf8';
  20. $ret_r['headerchar']='utf-8';
  21. }
  22. else//简体GBK
  23. {
  24. $ret_r['dbchar']='gbk';
  25. $ret_r['setchar']='gbk';
  26. $ret_r['headerchar']='gb2312';
  27. }
  28. return $ret_r;
  29. }
  30. //取得随机数
  31. function InstallMakePassword($pw_length){
  32. $low_ascii_bound=65;
  33. $upper_ascii_bound=90;
  34. $notuse=array(58,59,60,61,62,63,64,91,92,93,94,95,96,108,111);
  35. while($i<$pw_length)
  36. {
  37. if(PHP_VERSION<'4.2.0')
  38. {
  39. mt_srand((double)microtime()*1000000);
  40. }
  41. mt_srand();
  42. $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
  43. if(!in_array($randnum,$notuse))
  44. {
  45. $password1=$password1.chr($randnum);
  46. $i++;
  47. }
  48. }
  49. return $password1;
  50. }
  51. //函数是否存在
  52. function HaveFun($fun){
  53. if(function_exists($fun))
  54. {
  55. $word="支持";
  56. }
  57. else
  58. {
  59. $word="不支持";
  60. }
  61. return $word;
  62. }
  63. //返回符号
  64. function ReturnResult($st){
  65. if($st==1)
  66. {
  67. $w="√";
  68. }
  69. elseif($st==2)
  70. {
  71. $w="---";
  72. }
  73. else
  74. {
  75. $w="<font color=red>×</font>";
  76. }
  77. return $w;
  78. }
  79. //取得php版本
  80. function GetPhpVer(){
  81. $r['ver']=PHP_VERSION;
  82. if($r['ver'])
  83. {
  84. $r['result']=($r['ver']<"4.2.3")?ReturnResult(0):ReturnResult(1);
  85. }
  86. else
  87. {
  88. $r['ver']="---";
  89. $r['result']=ReturnResult(2);
  90. }
  91. return $r;
  92. }
  93. //取得php运行模式
  94. function GetPhpMod(){
  95. $mod=strtoupper(php_sapi_name());
  96. if(empty($mod))
  97. {
  98. $mod="---";
  99. }
  100. return $mod;
  101. }
  102. //是否运行于安全模式
  103. function GetPhpSafemod(){
  104. $phpsafemod=get_cfg_var("safe_mode");
  105. if($phpsafemod==1)
  106. {
  107. $r['word']="是";
  108. $r['result']=ReturnResult(0);
  109. }
  110. else
  111. {
  112. $r['word']="否";
  113. $r['result']=ReturnResult(1);
  114. }
  115. return $r;
  116. }
  117. //是否支持mysql
  118. function CanMysql(){
  119. $r['can']=function_exists('mysql_connect')||function_exists('mysqli_connect')?'支持':'不支持';
  120. $r['result']=$r[can]=="支持"?ReturnResult(1):ReturnResult(0);
  121. return $r;
  122. }
  123. //取得mysql版本
  124. function GetMysqlVer(){
  125. $r['ver']=do_eGetDBVer(0);
  126. if(empty($r['ver']))
  127. {
  128. $r['ver']="---";
  129. $r['result']=ReturnResult(2);
  130. }
  131. else
  132. {
  133. $r['result']=ReturnResult(1);
  134. }
  135. return $r;
  136. }
  137. //取得mysql版本(数据库)
  138. function GetMysqlVerForDb(){
  139. $sql=do_dbquery_common("select version() as version",$GLOBALS['link']);
  140. $r=do_dbfetch_common($sql);
  141. return ReturnMysqlVer($r['version']);
  142. }
  143. //返回mysql版本
  144. function ReturnMysqlVer($dbver){
  145. if(empty($dbver))
  146. {
  147. return '';
  148. }
  149. if($dbver>='6.0')
  150. {
  151. $dbver='6.0';
  152. }
  153. elseif($dbver>='5.0')
  154. {
  155. $dbver='5.0';
  156. }
  157. elseif($dbver>='4.1')
  158. {
  159. $dbver='4.1';
  160. }
  161. else
  162. {
  163. $dbver='4.0';
  164. }
  165. return $dbver;
  166. }
  167. //取得操作系统
  168. function GetUseSys(){
  169. $phpos=explode(" ",php_uname());
  170. $sys=$phpos[0]."&nbsp;".$phpos[1];
  171. if(empty($phpos[0]))
  172. {
  173. $sys="---";
  174. }
  175. return $sys;
  176. }
  177. //是否支持zend
  178. function GetZend(){
  179. @ob_start();
  180. @include("data/zend.php");
  181. $string=@ob_get_contents();
  182. @ob_end_clean();
  183. if($string=="www.phome.net"||strstr($string,"bytes in"))
  184. {
  185. $r['word']="支持";
  186. $r['result']=ReturnResult(1);
  187. }
  188. else
  189. {
  190. $r['word']="不支持";
  191. $r['result']=ReturnResult(0);
  192. }
  193. return $r;
  194. }
  195. //检查上传
  196. function CheckTranMode(){
  197. @ob_start();
  198. @include("../class/connect.php");
  199. @include("../class/functions.php");
  200. $string=@ob_get_contents();
  201. @ob_end_clean();
  202. if(strstr($string,"bytes in"))
  203. {
  204. echo"您没有二进制上传文件!请重新二进制上传文件,然后再安装。";
  205. exit();
  206. }
  207. }
  208. //是否支持采集
  209. function GetCj(){
  210. $cj=get_cfg_var("allow_url_fopen");
  211. if($cj==1)
  212. {
  213. $r['word']="支持";
  214. $r['result']=ReturnResult(1);
  215. }
  216. else
  217. {
  218. $r['word']="不支持";
  219. $r['result']=ReturnResult(0);
  220. }
  221. return $r;
  222. }
  223. //测试采集
  224. function TestCj(){
  225. $r=@file("http://www.163.com");
  226. if($r[5])
  227. {
  228. echo"<br>测试结果:<b>支持采集</b>";
  229. }
  230. else
  231. {
  232. echo"<br>测试结果:<b>不支持采集</b>";
  233. }
  234. exit();
  235. }
  236. //是否支持gd库
  237. function GetGd(){
  238. $r['can']=HaveFun("gd_info");
  239. $r['result']=$r[can]=="支持"?ReturnResult(1):ReturnResult(0);
  240. return $r;
  241. }
  242. //是否支持ICONV库
  243. function GetIconv(){
  244. $r['can']=HaveFun("iconv");
  245. $r['result']=$r[can]=="支持"?ReturnResult(1):ReturnResult(0);
  246. return $r;
  247. }
  248. //提示信息
  249. function InstallShowMsg($msg,$url=''){
  250. if(empty($url))
  251. {
  252. echo"<script>alert('".$msg."');history.go(-1);</script>";
  253. }
  254. else
  255. {
  256. echo"<script>alert('".$msg."');self.location.href='$url';</script>";
  257. }
  258. exit();
  259. }
  260. //返回目录权限结果
  261. function ReturnPathLevelResult($path){
  262. $testfile=$path."/test.test";
  263. $fp=@fopen($testfile,"wb");
  264. if($fp)
  265. {
  266. @fclose($fp);
  267. @unlink($testfile);
  268. return 1;
  269. }
  270. else
  271. {
  272. return 0;
  273. }
  274. }
  275. //返回文件权限结果
  276. function ReturnFileLevelResult($filename){
  277. return is_writable($filename);
  278. }
  279. //检测目录权限
  280. function CheckFileMod($filename,$smallfile=""){
  281. $succ="√";
  282. $error="<font color=red>×</font>";
  283. if(!file_exists($filename)||($smallfile&&!file_exists($smallfile)))
  284. {
  285. return $error;
  286. }
  287. if(is_dir($filename))//目录
  288. {
  289. if(!ReturnPathLevelResult($filename))
  290. {
  291. return $error;
  292. }
  293. //子目录
  294. if($smallfile)
  295. {
  296. if(is_dir($smallfile))
  297. {
  298. if(!ReturnPathLevelResult($smallfile))
  299. {
  300. return $error;
  301. }
  302. }
  303. else//文件
  304. {
  305. if(!ReturnFileLevelResult($smallfile))
  306. {
  307. return $error;
  308. }
  309. }
  310. }
  311. }
  312. else//文件
  313. {
  314. if(!ReturnFileLevelResult($filename))
  315. {
  316. return $error;
  317. }
  318. if($smallfile)
  319. {
  320. if(!ReturnFileLevelResult($smallfile))
  321. {
  322. return $error;
  323. }
  324. }
  325. }
  326. return $succ;
  327. }
  328. //信息
  329. function InstallSuccessShowInfo(){
  330. $time=time();
  331. $chkey='ta1-pb2h-b8ot-ftm87ep-fhng-ftt';
  332. $key=md5($chkey.md5($time));
  333. $getver=base64_encode("empirecms,".EmpireCMS_VERSION.",".EmpireCMS_CHARVER.",".EmpireCMS_LASTTIME.",".$_SERVER['HTTP_HOST'].",".$_SERVER['REMOTE_ADDR'].",".urlencode($_SERVER['PHP_SELF'])."");
  334. $dourl="http://ecmsuser.phome.net/empirecmsupdate/?ecms=EmpireCMSUpdate&time=$time&key=$key&ver=$getver";
  335. echo'<img src="'.$dourl.'" width="0" height="0">';
  336. }
  337. //建表
  338. function DoCreateTable($sql,$mysqlver,$dbcharset){
  339. $type=strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU","\\2",$sql));
  340. $type=in_array($type,array('MYISAM','HEAP'))?$type:'MYISAM';
  341. return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU","\\1",$sql).
  342. ($mysqlver>='4.1'?" ENGINE=$type DEFAULT CHARSET=$dbcharset":" TYPE=$type");
  343. }
  344. //运行SQL
  345. function DoRunQuery($sql,$mydbchar,$mydbtbpre,$mydbver){
  346. $sql=str_replace("\r","\n",str_replace(' `phome_',' `'.$mydbtbpre,$sql));
  347. $ret=array();
  348. $num=0;
  349. foreach(explode(";\n",trim($sql)) as $query)
  350. {
  351. $queries=explode("\n",trim($query));
  352. foreach($queries as $query)
  353. {
  354. $ret[$num].=$query[0]=='#'||$query[0].$query[1]=='--'?'':$query;
  355. }
  356. $num++;
  357. }
  358. unset($sql);
  359. foreach($ret as $query)
  360. {
  361. $query=trim($query);
  362. if($query)
  363. {
  364. if(substr($query,0,12)=='CREATE TABLE')
  365. {
  366. $name=preg_replace("/CREATE TABLE `([a-z0-9_]+)` .*/is","\\1",$query);
  367. echo"建立数据表: <b>".$name."</b> 完毕......<br>";
  368. do_dbquery_common(DoCreateTable($query,$mydbver,$mydbchar),$GLOBALS['link'],1);
  369. }
  370. else
  371. {
  372. do_dbquery_common($query,$GLOBALS['link'],1);
  373. }
  374. }
  375. }
  376. }
  377. //password
  378. function ins_DoEmpireCMSAdminPassword($password,$salt,$salt2){
  379. $pw=md5($salt2.'E!m^p-i(r#e.C:M?S'.md5(md5($password).$salt).'d)i.g^o-d'.$salt);
  380. return $pw;
  381. }
  382. //取得随机数
  383. function ins_make_password($pw_length){
  384. $low_ascii_bound=48;
  385. $upper_ascii_bound=122;
  386. $notuse=array(58,59,60,61,62,63,64,91,92,93,94,95,96);
  387. while($i<$pw_length)
  388. {
  389. if(PHP_VERSION<'4.2.0')
  390. {
  391. mt_srand((double)microtime()*1000000);
  392. }
  393. mt_srand();
  394. $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
  395. if(!in_array($randnum,$notuse))
  396. {
  397. $password1=$password1.chr($randnum);
  398. $i++;
  399. }
  400. }
  401. return $password1;
  402. }
  403. //取得IP
  404. function ins_egetip(){
  405. if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown'))
  406. {
  407. $ip=getenv('HTTP_CLIENT_IP');
  408. }
  409. elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown'))
  410. {
  411. $ip=getenv('HTTP_X_FORWARDED_FOR');
  412. }
  413. elseif(getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown'))
  414. {
  415. $ip=getenv('REMOTE_ADDR');
  416. }
  417. elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown'))
  418. {
  419. $ip=$_SERVER['REMOTE_ADDR'];
  420. }
  421. $ip=addslashes(preg_replace("/^([\d\.]+).*/","\\1",$ip));
  422. return $ip;
  423. }
  424. //取得端口
  425. function ins_egetipport(){
  426. $ipport=(int)$_SERVER['REMOTE_PORT'];
  427. return $ipport;
  428. }
  429. //初使化管理员
  430. function FirstAdmin($add){
  431. if(!trim($add['username'])||!trim($add['password']))
  432. {
  433. InstallShowMsg('请输入管理员用户名与密码');
  434. }
  435. if($add['password']!=$add['repassword'])
  436. {
  437. InstallShowMsg('两次输入的密码不一致,请重新输入');
  438. }
  439. //链接数据库
  440. @include("../config/config.php");
  441. $dbver=InstallConnectDb($ecms_config['db']['dbver'],$ecms_config['db']['dbserver'],$ecms_config['db']['dbport'],$ecms_config['db']['dbusername'],$ecms_config['db']['dbpassword'],$ecms_config['db']['dbname'],$ecms_config['db']['setchar'],$ecms_config['db']['dbchar']);
  442. $salt=ins_make_password(8);
  443. $salt2=ins_make_password(20);
  444. $username=addslashes($add['username']);
  445. $password=ins_DoEmpireCMSAdminPassword($add['password'],$salt,$salt2);
  446. $rnd=ins_make_password(20);
  447. $userprikey=ins_make_password(48);
  448. $addtime=time();
  449. $addip=ins_egetip();
  450. $addipport=ins_egetipport();
  451. $sql=do_dbquery_common("INSERT INTO `".$dbtbpre."enewsuser`(userid,username,password,rnd,adminclass,groupid,checked,styleid,filelevel,salt,loginnum,lasttime,lastip,truename,email,classid,pretime,preip,addtime,addip,userprikey,salt2,lastipport,preipport,addipport) VALUES (1,'$username','$password','$rnd','',1,0,1,0,'$salt',0,0,'','','',0,0,'','$addtime','$addip','$userprikey','$salt2','$addipport','$addipport','$addipport');",$GLOBALS['link']);
  452. $sql2=do_dbquery_common("INSERT INTO `".$dbtbpre."enewsuseradd` VALUES (1,0,'','','',0);",$GLOBALS['link']);
  453. do_dbclose($GLOBALS['link']);
  454. //认证码
  455. RepEcmsConfigLoginauth($add);
  456. if($sql)
  457. {
  458. echo"初始化管理员账号完毕!<script>self.location.href='changedata.php?defaultdata=$add[defaultdata]';</script>";
  459. exit();
  460. }
  461. else
  462. {
  463. InstallShowMsg('初使化管理员不成功,意外出错,请重新安装一次.');
  464. }
  465. }
  466. //导入测试数据
  467. function InstallDefaultData($add){
  468. //链接数据库
  469. @include("../config/config.php");
  470. $dbver=InstallConnectDb($ecms_config['db']['dbver'],$ecms_config['db']['dbserver'],$ecms_config['db']['dbport'],$ecms_config['db']['dbusername'],$ecms_config['db']['dbpassword'],$ecms_config['db']['dbname'],$ecms_config['db']['setchar'],$ecms_config['db']['dbchar']);
  471. //执行SQL语句
  472. DoRunQuery(ReturnInstallSql(1),$ecms_config['db']['dbchar'],$dbtbpre,$ecms_config['db']['dbver']);
  473. do_dbclose($GLOBALS['link']);
  474. echo"导入测试数据完毕!<script>self.location.href='index.php?enews=firstadmin&f=5&defaultdata=$add[defaultdata]';</script>";
  475. exit();
  476. }
  477. //导入模板数据
  478. function InstallTemplateData($add){
  479. //链接数据库
  480. @include("../config/config.php");
  481. $dbver=InstallConnectDb($ecms_config['db']['dbver'],$ecms_config['db']['dbserver'],$ecms_config['db']['dbport'],$ecms_config['db']['dbusername'],$ecms_config['db']['dbpassword'],$ecms_config['db']['dbname'],$ecms_config['db']['setchar'],$ecms_config['db']['dbchar']);
  482. //执行SQL语句
  483. DoRunQuery(ReturnInstallSql(2),$ecms_config['db']['dbchar'],$dbtbpre,$ecms_config['db']['dbver']);
  484. do_dbclose($GLOBALS['link']);
  485. if(empty($add['defaultdata']))
  486. {
  487. InstallDelArticleTxtFile();
  488. echo"导入模板数据完毕!<script>self.location.href='index.php?enews=firstadmin&f=5&defaultdata=$add[defaultdata]';</script>";
  489. }
  490. else
  491. {
  492. echo"导入模板数据完毕,正进入测试数据导入......<script>self.location.href='index.php?enews=defaultdata&f=4&ok=1&defaultdata=$add[defaultdata]';</script>";
  493. }
  494. exit();
  495. }
  496. //导入系统模型数据
  497. function InstallModData($add){
  498. //链接数据库
  499. @include("../config/config.php");
  500. $dbver=InstallConnectDb($ecms_config['db']['dbver'],$ecms_config['db']['dbserver'],$ecms_config['db']['dbport'],$ecms_config['db']['dbusername'],$ecms_config['db']['dbpassword'],$ecms_config['db']['dbname'],$ecms_config['db']['setchar'],$ecms_config['db']['dbchar']);
  501. //执行SQL语句
  502. DoRunQuery(ReturnInstallSql(3),$ecms_config['db']['dbchar'],$dbtbpre,$ecms_config['db']['dbver']);
  503. do_dbclose($GLOBALS['link']);
  504. echo"导入系统模型数据完毕,正进入模板数据导入......<script>self.location.href='index.php?enews=templatedata&f=4&ok=1&defaultdata=$add[defaultdata]';</script>";
  505. exit();
  506. }
  507. //链接数据库
  508. function InstallConnectDb($phome_use_dbver,$phome_db_server,$phome_db_port,$phome_db_username,$phome_db_password,$phome_db_dbname,$phome_db_char,$phome_db_dbchar){
  509. global $link;
  510. $link=do_dbconnect_common($phome_db_server,$phome_db_port,$phome_db_username,$phome_db_password,$phome_db_dbname);
  511. if(!$link)
  512. {
  513. InstallShowMsg('您的数据库用户名或密码有误,链接不上MYSQL数据库');
  514. }
  515. //mysql版本
  516. if($phome_use_dbver=='auto')
  517. {
  518. $phome_use_dbver=GetMysqlVerForDb();
  519. if(!$phome_use_dbver)
  520. {
  521. InstallShowMsg('系统无法自动识别MYSQL版本,请手动选择MYSQL版本');
  522. }
  523. }
  524. //编码
  525. if($phome_use_dbver>='4.1')
  526. {
  527. $q='';
  528. if($phome_db_char)
  529. {
  530. $q='character_set_connection='.$phome_db_char.',character_set_results='.$phome_db_char.',character_set_client=binary';
  531. }
  532. if($phome_use_dbver>='5.0')
  533. {
  534. $q.=(empty($q)?'':',').'sql_mode=\'\'';
  535. }
  536. if($q)
  537. {
  538. do_dbquery_common('SET '.$q,$link);
  539. }
  540. }
  541. $db=do_eUseDb($phome_db_dbname,$link);
  542. //数据库不存在
  543. if(!$db)
  544. {
  545. if($phome_use_dbver>='4.1')
  546. {
  547. $createdb=do_dbquery_common("CREATE DATABASE IF NOT EXISTS ".$phome_db_dbname." DEFAULT CHARACTER SET ".$phome_db_dbchar,$link);
  548. }
  549. else
  550. {
  551. $createdb=do_dbquery_common("CREATE DATABASE IF NOT EXISTS ".$phome_db_dbname,$link);
  552. }
  553. if(!$createdb)
  554. {
  555. InstallShowMsg('您输入的数据库名不存在');
  556. }
  557. do_eUseDb($phome_db_dbname,$link);
  558. }
  559. return $phome_use_dbver;
  560. }
  561. //配置数据库
  562. function SetDb($add){
  563. global $version;
  564. if(!$add['mydbver']||!$add['mydbhost']||!$add['mydbname']||!$add['mydbtbpre']||!$add['mycookievarpre']||!$add['myadmincookievarpre'])
  565. {
  566. InstallShowMsg('带*项不能为空');
  567. }
  568. //链接数据库
  569. $dbver=InstallConnectDb($add['mydbver'],$add['mydbhost'],$add['mydbport'],$add['mydbusername'],$add['mydbpassword'],$add['mydbname'],$add['mysetchar'],$add['mydbchar']);
  570. if($add['mydbver']=='auto')
  571. {
  572. $add['mydbver']=$dbver;
  573. }
  574. //初使化网站信息
  575. $siteurl=ReturnEcmsSiteUrl();
  576. $add['keyrnd']=ins_make_password(32);
  577. $add['downpass']=ins_make_password(20);
  578. $add['hkeyrnd']=ins_make_password(36);
  579. $add['ctimernd']=ins_make_password(42);
  580. $add['autodopostpass']=ins_make_password(60);
  581. //配置文件
  582. RepEcmsConfig($add,$siteurl);
  583. //执行SQL语句
  584. DoRunQuery(ReturnInstallSql(0),$add['mydbchar'],$add['mydbtbpre'],$add['mydbver']);
  585. do_dbquery_common("update ".$add['mydbtbpre']."enewspublic set newsurl='$siteurl',fileurl='".$siteurl."d/file/',softversion='$version',keyrnd='$add[keyrnd]',downpass='$add[downpass]',hkeyrnd='$add[hkeyrnd]' limit 1",$GLOBALS['link']);
  586. do_dbquery_common("update ".$add['mydbtbpre']."enewspublicadd set ctimernd='$add[ctimernd]',autodopostpass='$add[autodopostpass]' limit 1",$GLOBALS['link']);
  587. do_dbquery_common("update ".$add['mydbtbpre']."enewspl_set set plurl='".$siteurl."e/pl/' limit 1",$GLOBALS['link']);
  588. do_dbquery_common("update ".$add['mydbtbpre']."enewsshoppayfs set payurl='".$siteurl."e/payapi/ShopPay.php?paytype=alipay' where payid=3",$GLOBALS['link']);
  589. do_dbclose($GLOBALS['link']);
  590. echo"配置数据库完毕,正进入系统模型数据导入......<script>self.location.href='index.php?enews=moddata&f=4&ok=1&defaultdata=$add[defaultdata]';</script>";
  591. exit();
  592. }
  593. //处理配置文件
  594. function RepEcmsConfig($add,$siteurl){
  595. global $headerchar;
  596. //初使化配置文件
  597. $fp=@fopen("data/config.php","r");
  598. if(!$fp)
  599. {
  600. InstallShowMsg('请检查 /e/install/data/config.php 文件是否存在!');
  601. }
  602. $data=@fread($fp,filesize("data/config.php"));
  603. fclose($fp);
  604. $data=str_replace('<!--dbtype.phome.net-->',$add['mydbtype'],$data);
  605. $data=str_replace('<!--dbver.phome.net-->',$add['mydbver'],$data);
  606. $data=str_replace('<!--host.phome.net-->',$add['mydbhost'],$data);
  607. $data=str_replace('<!--port.phome.net-->',$add['mydbport'],$data);
  608. $data=str_replace('<!--username.phome.net-->',$add['mydbusername'],$data);
  609. $data=str_replace('<!--password.phome.net-->',$add['mydbpassword'],$data);
  610. $data=str_replace('<!--name.phome.net-->',$add['mydbname'],$data);
  611. $data=str_replace('<!--char.phome.net-->',$add['mysetchar'],$data);
  612. $data=str_replace('<!--dbchar.phome.net-->',$add['mydbchar'],$data);
  613. $data=str_replace('<!--tbpre.phome.net-->',$add['mydbtbpre'],$data);
  614. $data=str_replace('<!--cookiepre.phome.net-->',$add['mycookievarpre'],$data);
  615. $data=str_replace('<!--admincookiepre.phome.net-->',$add['myadmincookievarpre'],$data);
  616. $data=str_replace('<!--headerchar.phome.net-->',$headerchar,$data);
  617. $data=str_replace('<!--cookiernd.phome.net-->',ins_make_password(36),$data);
  618. $data=str_replace('<!--qcookiernd.phome.net-->',ins_make_password(35),$data);
  619. $data=str_replace('<!--qcookierndtwo.phome.net-->',ins_make_password(34),$data);
  620. $data=str_replace('<!--qcookierndthree.phome.net-->',ins_make_password(33),$data);
  621. $data=str_replace('<!--qcookierndfour.phome.net-->',ins_make_password(32),$data);
  622. $data=str_replace('<!--qcookierndfive.phome.net-->',ins_make_password(31),$data);
  623. $data=str_replace('<!--ecms.newsurl-->',$siteurl,$data);
  624. $data=str_replace('<!--ecms.fileurl-->',$siteurl."d/file/",$data);
  625. $data=str_replace('<!--ecms.plurl-->',$siteurl."e/pl/",$data);
  626. $data=str_replace('<!--ecms.downpass-->',$add['downpass'],$data);
  627. $data=str_replace('<!--ecms.hkeyrnd-->',$add['hkeyrnd'],$data);
  628. $data=str_replace('<!--ecms.ctimernd-->',$add['ctimernd'],$data);
  629. $data=str_replace('<!--ecms.autodopostpass-->',$add['autodopostpass'],$data);
  630. $data=str_replace('<!--ecms.keyrnd-->',$add['keyrnd'],$data);
  631. //写入配置文件
  632. $fp1=@fopen("../config/config.php","w");
  633. if(!$fp1)
  634. {
  635. InstallShowMsg(' /e/config/config.php 文件权限没有设为0777,配置数据库不成功');
  636. }
  637. @fputs($fp1,$data);
  638. @fclose($fp1);
  639. }
  640. //处理认证码
  641. function RepEcmsConfigLoginauth($add){
  642. global $headerchar;
  643. //初使化配置文件
  644. $fp=@fopen("../config/config.php","r");
  645. if(!$fp)
  646. {
  647. InstallShowMsg('请检查 /e/config/config.php 文件是否存在!');
  648. }
  649. $data=@fread($fp,filesize("../config/config.php"));
  650. fclose($fp);
  651. $data=str_replace('<!--loginauth.phome.net-->',$add['loginauth'],$data);
  652. //写入配置文件
  653. $fp1=@fopen("../config/config.php","w");
  654. if(!$fp1)
  655. {
  656. InstallShowMsg(' /e/config/config.php 文件权限没有设为0777,配置不成功');
  657. }
  658. @fputs($fp1,$data);
  659. @fclose($fp1);
  660. }
  661. //返回SQL语句
  662. function ReturnInstallSql($defaultdata=1){
  663. if($defaultdata==0)
  664. {
  665. $sqlfile="data/empirecms.com.sql";
  666. }
  667. elseif($defaultdata==2)
  668. {
  669. $sqlfile="data/empirecms.temp.sql";
  670. }
  671. elseif($defaultdata==3)
  672. {
  673. $sqlfile="data/empirecms.mod.sql";
  674. }
  675. else
  676. {
  677. $sqlfile="data/empirecms.data.sql";
  678. }
  679. $fp=fopen($sqlfile,'r');
  680. $sql=fread($fp,filesize($sqlfile));
  681. fclose($fp);
  682. if(empty($sql))
  683. {
  684. InstallShowMsg(' /e/install/'.$sqlfile.' 文件丢失,安装不成功','index.php?enews=setdb&f=4');
  685. }
  686. //替换测试数据网址
  687. if($sqlfile=='data/empirecms.data.sql')
  688. {
  689. $sql=InstallReplaceTestDataUrl($sql);
  690. }
  691. return $sql;
  692. }
  693. //取得网站地址
  694. function ReturnEcmsSiteUrl(){
  695. $siteurl=str_replace('e/install/index.php','',$_SERVER['PHP_SELF']);
  696. $siteurl=str_replace('e/install/','',$siteurl);
  697. $siteurl=str_replace('e/install','',$siteurl);
  698. return $siteurl;
  699. }
  700. //删除存文本文件
  701. function InstallDelArticleTxtFile(){
  702. @include("../class/delpath.php");
  703. $DelPath="../../d/txt/2012";
  704. $wm_chief=new del_path();
  705. $wm_chief_ok=$wm_chief->wm_chief_delpath($DelPath);
  706. return $wm_chief_ok;
  707. }
  708. //替换测试数据网址
  709. function InstallReplaceTestDataUrl($text){
  710. $baseurl=ReturnEcmsSiteUrl();
  711. $text=str_replace('/ecms75/',$baseurl,$text);
  712. $text=str_replace('http://demo.phome.net/defdata/demopic/',$baseurl.'testdata/demopic/',$text);
  713. return $text;
  714. }
  715. ?>