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

392 lines
15KB

  1. <?php
  2. /**
  3. * @version $Id: index.php 1 13:41 2010年7月26日Z tianya $
  4. * @package DedeCMS.Install
  5. * @copyright Copyright (c) 2007 - 2018, DesDev, Inc.
  6. * @copyright Copyright (c) 2020, DedeBIZ.COM
  7. * @license https://www.dedebiz.com/license/v6
  8. * @link https://www.dedebiz.com
  9. */
  10. @set_time_limit(0);
  11. //error_reporting(E_ALL);
  12. error_reporting(E_ALL || ~E_NOTICE);
  13. $verMsg = ' V6 UTF8';
  14. $s_lang = 'utf-8';
  15. $dfDbname = 'dedecmsv6utf8';
  16. $errmsg = '';
  17. define('INSLOCKFILE', dirname(__FILE__).'/install_lock.txt');
  18. $moduleCacheFile = dirname(__FILE__).'/modules.tmp.inc';
  19. define('DEDEINC',dirname(__FILE__).'/../include');
  20. define('DEDEDATA',dirname(__FILE__).'/../data');
  21. define('DEDEROOT',preg_replace("#[\\\\\/]install#", '', dirname(__FILE__)));
  22. header("Content-Type: text/html; charset={$s_lang}");
  23. require_once(DEDEROOT.'/install/install.inc.php');
  24. require_once(DEDEINC.'/zip.class.php');
  25. foreach(Array('_GET','_POST','_COOKIE') as $_request)
  26. {
  27. foreach($$_request as $_k => $_v) ${$_k} = RunMagicQuotes($_v);
  28. }
  29. require_once(DEDEINC.'/common.func.php');
  30. if(file_exists(INSLOCKFILE))
  31. {
  32. exit(" 程序已运行安装,如果你确定要重新安装,请先从FTP中删除 install/install_lock.txt!");
  33. }
  34. if(empty($step))
  35. {
  36. $step = 1;
  37. }
  38. /*------------------------
  39. 使用协议书
  40. function _1_Agreement()
  41. ------------------------*/
  42. if($step==1)
  43. {
  44. include('./templates/step-1.html');
  45. exit();
  46. }
  47. /*------------------------
  48. 环境测试
  49. function _2_TestEnv()
  50. ------------------------*/
  51. else if($step==2)
  52. {
  53. $phpv = phpversion();
  54. $sp_os = PHP_OS;
  55. $sp_gd = gdversion();
  56. $sp_server = $_SERVER['SERVER_SOFTWARE'];
  57. $sp_host = (empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_HOST'] : $_SERVER['REMOTE_ADDR']);
  58. $sp_name = $_SERVER['SERVER_NAME'];
  59. $sp_max_execution_time = ini_get('max_execution_time');
  60. $sp_allow_reference = (ini_get('allow_call_time_pass_reference') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
  61. $sp_allow_url_fopen = (ini_get('allow_url_fopen') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
  62. $sp_safe_mode = (ini_get('safe_mode') ? '<font color=red>[×]On</font>' : '<font color=green>[√]Off</font>');
  63. $sp_gd = ($sp_gd>0 ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
  64. $sp_mysql = (function_exists('mysql_connect') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
  65. if($sp_mysql=='<font color=red>[×]Off</font>')
  66. $sp_mysql_err = TRUE;
  67. else
  68. $sp_mysql_err = FALSE;
  69. $sp_testdirs = array(
  70. '/',
  71. '/plus/*',
  72. '/dede/*',
  73. '/data/*',
  74. '/a/*',
  75. '/install',
  76. '/special',
  77. '/uploads/*'
  78. );
  79. include('./templates/step-2.html');
  80. exit();
  81. }
  82. /*------------------------
  83. 设置参数
  84. function _3_WriteSeting()
  85. ------------------------*/
  86. else if($step==3)
  87. {
  88. if(!empty($_SERVER['REQUEST_URI']))
  89. $scriptName = $_SERVER['REQUEST_URI'];
  90. else
  91. $scriptName = $_SERVER['PHP_SELF'];
  92. $basepath = preg_replace("#\/install(.*)$#i", '', $scriptName);
  93. if(!empty($_SERVER['HTTP_HOST']))
  94. $baseurl = 'http://'.$_SERVER['HTTP_HOST'];
  95. else
  96. $baseurl = "http://".$_SERVER['SERVER_NAME'];
  97. $chars='abcdefghigklmnopqrstuvwxwyABCDEFGHIGKLMNOPQRSTUVWXWY0123456789';
  98. $rnd_cookieEncode='';
  99. $length = rand(28,32);
  100. $max = strlen($chars) - 1;
  101. for($i = 0; $i < $length; $i++) {
  102. $rnd_cookieEncode .= $chars[mt_rand(0, $max)];
  103. }
  104. $module_local = DEDEDATA.'/module/';
  105. include('./templates/step-3.html');
  106. exit();
  107. }
  108. /*------------------------
  109. 普通安装
  110. function _4_Setup()
  111. ------------------------*/
  112. else if($step==4)
  113. {
  114. if ( $dbtype == 'sqlite' )
  115. {
  116. $db = new SQLite3(DEDEDATA.'/'.$dbname.'.db');
  117. } else {
  118. $dbtype = 'mysql';
  119. $conn = mysql_connect($dbhost,$dbuser,$dbpwd) or die("<script>alert('数据库服务器或登录密码无效,\\n\\n无法连接数据库,请重新设定!');history.go(-1);</script>");
  120. mysql_query("CREATE DATABASE IF NOT EXISTS `".$dbname."`;",$conn);
  121. mysql_select_db($dbname, $conn) or die("<script>alert('选择数据库失败,可能是你没权限,请预先创建一个数据库!');history.go(-1);</script>");
  122. //获得数据库版本信息
  123. $rs = mysql_query("SELECT VERSION();",$conn);
  124. $row = mysql_fetch_array($rs);
  125. $mysqlVersions = explode('.',trim($row[0]));
  126. $mysqlVersion = $mysqlVersions[0].".".$mysqlVersions[1];
  127. mysql_query("SET NAMES '$dblang',character_set_client=binary,sql_mode='';",$conn);
  128. }
  129. $fp = fopen(dirname(__FILE__)."/common.inc.php","r");
  130. $configStr1 = fread($fp,filesize(dirname(__FILE__)."/common.inc.php"));
  131. fclose($fp);
  132. $fp = fopen(dirname(__FILE__)."/config.cache.inc.php","r");
  133. $configStr2 = fread($fp,filesize(dirname(__FILE__)."/config.cache.inc.php"));
  134. fclose($fp);
  135. //common.inc.php
  136. $configStr1 = str_replace("~dbtype~",$dbtype,$configStr1);
  137. $configStr1 = str_replace("~dbhost~",$dbhost,$configStr1);
  138. $configStr1 = str_replace("~dbname~",$dbname,$configStr1);
  139. $configStr1 = str_replace("~dbuser~",$dbuser,$configStr1);
  140. $configStr1 = str_replace("~dbpwd~",$dbpwd,$configStr1);
  141. $configStr1 = str_replace("~dbprefix~",$dbprefix,$configStr1);
  142. $configStr1 = str_replace("~dblang~",$dblang,$configStr1);
  143. @chmod(DEDEDATA,0777);
  144. $fp = fopen(DEDEDATA."/common.inc.php","w") or die("<script>alert('写入配置失败,请检查../data目录是否可写入!');history.go(-1);</script>");
  145. fwrite($fp,$configStr1);
  146. fclose($fp);
  147. //config.cache.inc.php
  148. $cmspath = trim(preg_replace("#\/{1,}#", '/', $cmspath));
  149. if($cmspath!='' && !preg_match("#^\/#", $cmspath)) $cmspath = '/'.$cmspath;
  150. if($cmspath=='') $indexUrl = '/';
  151. else $indexUrl = $cmspath;
  152. $configStr2 = str_replace("~baseurl~",$baseurl,$configStr2);
  153. $configStr2 = str_replace("~basepath~",$cmspath,$configStr2);
  154. $configStr2 = str_replace("~indexurl~",$indexUrl,$configStr2);
  155. $configStr2 = str_replace("~cookieEncode~",$cookieencode,$configStr2);
  156. $configStr2 = str_replace("~webname~",$webname,$configStr2);
  157. $configStr2 = str_replace("~adminmail~",$adminmail,$configStr2);
  158. $fp = fopen(DEDEDATA.'/config.cache.inc.php','w');
  159. fwrite($fp,$configStr2);
  160. fclose($fp);
  161. $fp = fopen(DEDEDATA.'/config.cache.bak.php','w');
  162. fwrite($fp,$configStr2);
  163. fclose($fp);
  164. if($mysqlVersion >= 4.1)
  165. {
  166. $sql4tmp = "ENGINE=MyISAM DEFAULT CHARSET=".$dblang;
  167. }
  168. //创建数据表
  169. $query = '';
  170. $fp = fopen(dirname(__FILE__).'/sql-dftables.txt','r');
  171. while(!feof($fp))
  172. {
  173. $line = rtrim(fgets($fp,1024));
  174. if(preg_match("#;$#", $line))
  175. {
  176. $query .= $line."\n";
  177. $query = str_replace('#@__',$dbprefix,$query);
  178. if ( $dbtype == 'sqlite' )
  179. {
  180. $query = preg_replace('/character set (.*?) /i','',$query);
  181. $query = str_replace('unsigned','',$query);
  182. $query = str_replace('TYPE=MyISAM','',$query);
  183. $query = preg_replace ('/TINYINT\(([\d]+)\)/i','INTEGER',$query);
  184. $query = preg_replace ('/mediumint\(([\d]+)\)/i','INTEGER',$query);
  185. $query = preg_replace ('/smallint\(([\d]+)\)/i','INTEGER',$query);
  186. $query = preg_replace('/int\(([\d]+)\)/i','INTEGER',$query);
  187. $query = preg_replace('/auto_increment/i','PRIMARY KEY AUTOINCREMENT',$query);
  188. $query = preg_replace('/, KEY(.*?)MyISAM;/','',$query);
  189. $query = preg_replace('/, KEY(.*?);/',');',$query);
  190. $query = preg_replace('/, UNIQUE KEY(.*?);/',');',$query);
  191. $query = preg_replace('/set\(([^\)]*?)\)/','varchar',$query);
  192. $query = preg_replace('/enum\(([^\)]*?)\)/','varchar',$query);
  193. if ( preg_match("/PRIMARY KEY AUTOINCREMENT/",$query) )
  194. {
  195. $query = preg_replace('/,([\t\s ]+)PRIMARY KEY \(`([0-9a-zA-Z]+)`\)/i','',$query);
  196. $query = str_replace(', PRIMARY KEY (`id`)','',$query);
  197. }
  198. $db->exec($query);
  199. } else {
  200. if($mysqlVersion < 4.1)
  201. {
  202. $rs = mysql_query($query,$conn);
  203. } else {
  204. if(preg_match('#CREATE#i', $query))
  205. {
  206. $rs = mysql_query(preg_replace("#TYPE=MyISAM#i",$sql4tmp,$query),$conn);
  207. }
  208. else
  209. {
  210. $rs = mysql_query($query,$conn);
  211. }
  212. }
  213. }
  214. $query='';
  215. } else if(!preg_match("#^(\/\/|--)#", $line))
  216. {
  217. $query .= $line;
  218. }
  219. }
  220. fclose($fp);
  221. //导入默认数据
  222. $query = '';
  223. $fp = fopen(dirname(__FILE__).'/sql-dfdata.txt','r');
  224. while(!feof($fp))
  225. {
  226. $line = rtrim(fgets($fp, 1024));
  227. if(preg_match("#;$#", $line))
  228. {
  229. if ( $dbtype == 'sqlite' )
  230. {
  231. $query .= $line;
  232. $query = str_replace('#@__',$dbprefix,$query);
  233. $query = str_replace("\'","\"",$query);
  234. $db->exec($query);
  235. } else {
  236. $query .= $line;
  237. $query = str_replace('#@__',$dbprefix,$query);
  238. if($mysqlVersion < 4.1) $rs = mysql_query($query,$conn);
  239. else $rs = mysql_query(str_replace('#~lang~#',$dblang,$query),$conn);
  240. }
  241. $query='';
  242. } else if(!preg_match("#^(\/\/|--)#", $line))
  243. {
  244. $query .= $line;
  245. }
  246. }
  247. fclose($fp);
  248. //更新配置
  249. $cquery = "Update `{$dbprefix}sysconfig` set value='{$baseurl}' where varname='cfg_basehost';";
  250. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  251. $cquery = "Update `{$dbprefix}sysconfig` set value='{$cmspath}' where varname='cfg_cmspath';";
  252. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  253. $cquery = "Update `{$dbprefix}sysconfig` set value='{$indexUrl}' where varname='cfg_indexurl';";
  254. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  255. $cquery = "Update `{$dbprefix}sysconfig` set value='{$cookieencode}' where varname='cfg_cookie_encode';";
  256. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  257. $cquery = "Update `{$dbprefix}sysconfig` set value='{$webname}' where varname='cfg_webname';";
  258. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  259. $cquery = "Update `{$dbprefix}sysconfig` set value='{$adminmail}' where varname='cfg_adminemail';";
  260. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  261. //增加管理员帐号
  262. $adminquery = "INSERT INTO `{$dbprefix}admin` VALUES (1, 10, '$adminuser', '".substr(md5($adminpwd),5,20)."', 'admin', '', '', 0, '".time()."', '127.0.0.1');";
  263. $dbtype == 'sqlite'? $db->exec($adminquery) : mysql_query($adminquery,$conn);
  264. //关连前台会员帐号
  265. $adminquery = "INSERT INTO `{$dbprefix}member` (`mid`,`mtype`,`userid`,`pwd`,`uname`,`sex`,`rank`,`money`,`email`,
  266. `scores` ,`matt` ,`face`,`safequestion`,`safeanswer` ,`jointime` ,`joinip` ,`logintime` ,`loginip` )
  267. VALUES ('1','个人','$adminuser','".md5($adminpwd)."','$adminuser','男','100','0','','10000','10','','0','','".time()."','','0',''); ";
  268. $dbtype == 'sqlite'? $db->exec($adminquery) : mysql_query($adminquery,$conn);
  269. $adminquery = "INSERT INTO `{$dbprefix}member_person` (`mid`,`onlynet`,`sex`,`uname`,`qq`,`msn`,`tel`,`mobile`,`place`,`oldplace`,`birthday`,`star`,
  270. `income` , `education` , `height` , `bodytype` , `blood` , `vocation` , `smoke` , `marital` , `house` ,`drink` , `datingtype` , `language` , `nature` , `lovemsg` , `address`,`uptime`)
  271. VALUES ('1', '1', '男', '{$adminuser}', '', '', '', '', '0', '0','1980-01-01', '1', '0', '0', '160', '0', '0', '0', '0', '0', '0','0', '0', '', '', '', '','0'); ";
  272. $dbtype == 'sqlite'? $db->exec($adminquery) : mysql_query($adminquery,$conn);
  273. $adminquery = "INSERT INTO `{$dbprefix}member_tj` (`mid`,`article`,`album`,`archives`,`homecount`,`pagecount`,`feedback`,`friend`,`stow`)
  274. VALUES ('1','0','0','0','0','0','0','0','0'); ";
  275. $dbtype == 'sqlite'? $db->exec($adminquery): mysql_query($adminquery,$conn);
  276. $adminquery = "Insert Into `{$dbprefix}member_space`(`mid` ,`pagesize` ,`matt` ,`spacename` ,`spacelogo` ,`spacestyle`, `sign` ,`spacenews`)
  277. Values('1','10','0','{$adminuser}的空间','','person','',''); ";
  278. $dbtype == 'sqlite'? $db->exec($adminquery) : mysql_query($adminquery,$conn);
  279. //不安装任何可选模块
  280. if(!isset($modules) || !is_array($modules))
  281. {
  282. //锁定安装程序
  283. $fp = fopen($insLockfile,'w');
  284. fwrite($fp,'ok');
  285. fclose($fp);
  286. include('./templates/step-5.html');
  287. exit();
  288. }
  289. else
  290. {
  291. $module = join(',',$modules);
  292. $fp = fopen($moduleCacheFile,'w');
  293. fwrite($fp,'<'.'?php'."\r\n");
  294. fwrite($fp,'$selModule = "'.$module.'"; '."\r\n");
  295. fwrite($fp,'?'.'>');
  296. //如果不能写入缓存文件,退出模块安装
  297. if(!$fp)
  298. {
  299. //锁定安装程序
  300. $fp = fopen($insLockfile,'w');
  301. fwrite($fp,'ok');
  302. fclose($fp);
  303. $errmsg = "<font color='red'>由于无法写入模块缓存,安装可选模块失败,请登录后在模块管理处安装。</font>";
  304. include('./templates/step-5.html');
  305. exit();
  306. }
  307. fclose($fp);
  308. include('./templates/step-4.html');
  309. exit();
  310. }
  311. exit();
  312. }
  313. /*------------------------
  314. 安装可选模块
  315. function _5_SetupModule()
  316. ------------------------*/
  317. else if($step==5)
  318. {
  319. header("location:module-install.php");
  320. exit();
  321. }
  322. /*------------------------
  323. 检测数据库是否有效
  324. function _10_TestDbPwd()
  325. ------------------------*/
  326. else if($step==10)
  327. {
  328. header("Pragma:no-cache\r\n");
  329. header("Cache-Control:no-cache\r\n");
  330. header("Expires:0\r\n");
  331. $conn = @mysql_connect($dbhost,$dbuser,$dbpwd);
  332. if($conn)
  333. {
  334. if(empty($dbname)){
  335. echo "<font color='green'>信息正确</font>";
  336. }else{
  337. $info = mysql_select_db($dbname,$conn)?"<font color='red'>数据库已经存在,系统将覆盖数据库</font>":"<font color='green'>数据库不存在,系统将自动创建</font>";
  338. echo $info;
  339. }
  340. }
  341. else
  342. {
  343. echo "<font color='red'>数据库连接失败!</font>";
  344. }
  345. @mysql_close($conn);
  346. exit();
  347. }