国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 14KB

2 년 전
2 년 전
2 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. /**
  3. * @version $Id: index.php 2022-01-03 tianya $
  4. * @package DedeBIZ.Install
  5. * @copyright Copyright (c) 2022, DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license
  7. * @link https://www.dedebiz.com
  8. */
  9. @set_time_limit(0);
  10. error_reporting(E_ALL || ~E_NOTICE);
  11. define('INSLOCKFILE', dirname(__FILE__).'/install_lock.txt');
  12. $verMsg = 'V6';
  13. $dfDbname = 'DedeBIZ';
  14. $cfg_version_detail = '6.1.10beta'; //详细版本号
  15. $errmsg = '';
  16. if (version_compare(PHP_VERSION, '8.0.0', '>=') && function_exists("mysqli_report")) {
  17. mysqli_report(MYSQLI_REPORT_OFF);
  18. }
  19. define('DEDEINC',dirname(__FILE__).'/../system');
  20. define('DEDEDATA',dirname(__FILE__).'/../data');
  21. define('DEDEROOT',preg_replace("#[\\\\\/]install#", '', dirname(__FILE__)));
  22. header("Content-Type: text/html; charset=utf-8");
  23. require_once(DEDEROOT.'/install/install.inc.php');
  24. require_once(DEDEINC.'/libraries/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. die(DedeAlert("程序已运行安装,如果您确定要重新安装,请先删除 /install/install_lock.txt",ALERT_DANGER));
  33. }
  34. if (empty($step))
  35. {
  36. $step = 1;
  37. }
  38. $proto = IsSSL()? "https://" : "http://";
  39. /*------------------------
  40. 使用协议书
  41. function _1_Agreement()
  42. ------------------------*/
  43. if ($step==1)
  44. {
  45. $arrMsg = array();
  46. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  47. $arrMsg[] = "PHP请升级到5.3及以上版本,低版本PHP环境将无法正常使用本系统";
  48. }
  49. if (!extension_loaded("openssl")) {
  50. $arrMsg[] = "OpenSSL未开启,将无法完成<a href='https://www.dedebiz.com' target='_blank'>DedeBIZ商业支持</a>";
  51. }
  52. if (!extension_loaded("sockets")) {
  53. $arrMsg[] = "Sockets未开启,将无法安装<a href='https://www.dedebiz.com/download#dedebiz' target='_blank'>DedeBIZ商业组件</a>";
  54. }
  55. if (!extension_loaded("fileinfo")) {
  56. $arrMsg[] = "Fileinfo未开启,将无法正常进行文件上传";
  57. }
  58. if (!function_exists('mysqli_connect')) {
  59. $arrMsg[] = "MySQL不支持,将无法使用本系统";
  60. }
  61. if (!extension_loaded("sqlite3")) {
  62. $arrMsg[] = "SQLite3未开启,将无法正常使用SQLite数据库";
  63. }
  64. if (!extension_loaded("gd")) {
  65. $arrMsg[] = "GD未开启,将无法使用验证码、二维码、图片水印等功能";
  66. }
  67. if (!empty($_SERVER['REQUEST_URI']))
  68. $scriptName = $_SERVER['REQUEST_URI'];
  69. else
  70. $scriptName = $_SERVER['PHP_SELF'];
  71. $basepath = preg_replace("#\/install(.*)$#i", '', $scriptName);
  72. if (!empty($_SERVER['HTTP_HOST']))
  73. $baseurl = $proto.$_SERVER['HTTP_HOST'];
  74. else
  75. $baseurl = $proto.$_SERVER['SERVER_NAME'];
  76. $chars='abcdefghigklmnopqrstuvwxwyABCDEFGHIGKLMNOPQRSTUVWXWY0123456789';
  77. $rnd_cookieEncode='';
  78. $length = rand(28,32);
  79. $max = strlen($chars) - 1;
  80. for($i = 0; $i < $length; $i++) {
  81. $rnd_cookieEncode .= $chars[mt_rand(0, $max)];
  82. }
  83. $module_local = DEDEDATA.'/module/';
  84. include('./install.html');
  85. exit();
  86. }
  87. /*------------------------
  88. 普通安装
  89. function _2_Setup()
  90. ------------------------*/
  91. else if ($step==2)
  92. {
  93. $dbtype = empty($dbtype)? "mysql" : $dbtype;
  94. $dblang = "utf8";
  95. if (!in_array($dbtype,array("mysql", "sqlite"))) {
  96. die("当前数据库类型不支持");
  97. }
  98. if (!empty($_SERVER['HTTP_HOST']))
  99. $dfbaseurl = $proto.$_SERVER['HTTP_HOST'];
  100. else
  101. $dfbaseurl = $proto.$_SERVER['SERVER_NAME'];
  102. $dfbasepath = preg_replace("#\/install(.*)$#i", '', $scriptName);
  103. $dbhost = empty($dbhost)? "localhost" : $dbhost;
  104. $dbuser = empty($dbuser)? "root" : $dbuser;
  105. $dbuser = empty($dbuser)? "root" : $dbuser;
  106. $dbprefix = empty($dbprefix)? "biz_" : $dbprefix;
  107. $dbname = empty($dbname)? $dfDbname : $dbname;
  108. $adminuser = empty($adminuser)? "admin" : $adminuser;
  109. $adminpwd = empty($adminpwd)? "admin" : $adminpwd;
  110. $webname = empty($webname)? "某某公司" : $webname;
  111. $baseurl = empty($baseurl)? $dfbaseurl : $baseurl;
  112. $cmspath = empty($cmspath)? $dfbasepath : $cmspath;
  113. if ( $dbtype == 'sqlite' )
  114. {
  115. $db = new SQLite3(DEDEDATA.'/'.$dbname.'.db');
  116. } else {
  117. $dbtype = 'mysql';
  118. $conn = mysql_connect($dbhost,$dbuser,$dbpwd) or die("<script>alert('数据库服务器或登录密码无效,\\n\\n无法连接数据库,请重新设定');history.go(-1);</script>");
  119. mysql_query("CREATE DATABASE IF NOT EXISTS `".$dbname."`;",$conn);
  120. mysql_select_db($dbname, $conn) or die("<script>alert('选择数据库失败,可能是您没权限,请预先创建一个数据库');history.go(-1);</script>");
  121. //获得数据库版本信息
  122. $rs = mysql_query("SELECT VERSION();",$conn);
  123. $row = mysql_fetch_array($rs);
  124. $mysqlVersions = explode('.',trim($row[0]));
  125. $mysqlVersion = $mysqlVersions[0].".".$mysqlVersions[1];
  126. mysql_query("SET NAMES '$dblang',character_set_client=binary,sql_mode='';",$conn);
  127. }
  128. $fp = fopen(dirname(__FILE__)."/common.inc.php","r");
  129. $configStr1 = fread($fp,filesize(dirname(__FILE__)."/common.inc.php"));
  130. fclose($fp);
  131. $fp = fopen(dirname(__FILE__)."/config.cache.inc.php","r");
  132. $configStr2 = fread($fp,filesize(dirname(__FILE__)."/config.cache.inc.php"));
  133. fclose($fp);
  134. //common.inc.php
  135. $configStr1 = str_replace("~dbtype~",$dbtype,$configStr1);
  136. $configStr1 = str_replace("~dbhost~",$dbhost,$configStr1);
  137. $configStr1 = str_replace("~dbname~",$dbname,$configStr1);
  138. $configStr1 = str_replace("~dbuser~",$dbuser,$configStr1);
  139. $configStr1 = str_replace("~dbpwd~",$dbpwd,$configStr1);
  140. $configStr1 = str_replace("~dbprefix~",$dbprefix,$configStr1);
  141. $configStr1 = str_replace("~dblang~",$dblang,$configStr1);
  142. @chmod(DEDEDATA,0777);
  143. $fp = fopen(DEDEDATA."/common.inc.php","w") or die("<script>alert('写入配置失败,请检查../data目录是否可写入');history.go(-1);</script>");
  144. fwrite($fp,$configStr1);
  145. fclose($fp);
  146. //config.cache.inc.php
  147. $cmspath = trim(preg_replace("#\/{1,}#", '/', $cmspath));
  148. if ($cmspath!='' && !preg_match("#^\/#", $cmspath)) $cmspath = '/'.$cmspath;
  149. if ($cmspath=='') $indexUrl = '/';
  150. else $indexUrl = $cmspath;
  151. $configStr2 = str_replace("~baseurl~",$baseurl,$configStr2);
  152. $configStr2 = str_replace("~basepath~",$cmspath,$configStr2);
  153. $configStr2 = str_replace("~indexurl~",$indexUrl,$configStr2);
  154. $configStr2 = str_replace("~cookieEncode~",$cookieencode,$configStr2);
  155. $configStr2 = str_replace("~webname~",$webname,$configStr2);
  156. $configStr2 = str_replace("~adminmail~",$adminmail,$configStr2);
  157. $fp = fopen(DEDEDATA.'/config.cache.inc.php','w');
  158. fwrite($fp,$configStr2);
  159. fclose($fp);
  160. $fp = fopen(DEDEDATA.'/config.cache.bak.php','w');
  161. fwrite($fp,$configStr2);
  162. fclose($fp);
  163. if ($mysqlVersion >= 4.1)
  164. {
  165. $sql4tmp = "ENGINE=MyISAM DEFAULT CHARSET=".$dblang;
  166. }
  167. //创建数据表
  168. $query = '';
  169. $fp = fopen(dirname(__FILE__).'/sql-dftables.txt','r');
  170. while(!feof($fp))
  171. {
  172. $line = rtrim(fgets($fp,1024));
  173. if (preg_match("#;$#", $line))
  174. {
  175. $query .= $line."\n";
  176. $query = str_replace('#@__',$dbprefix,$query);
  177. if ( $dbtype == 'sqlite' )
  178. {
  179. $query = preg_replace('/character set (.*?) /i','',$query);
  180. $query = str_replace('unsigned','',$query);
  181. $query = str_replace('TYPE=MyISAM','',$query);
  182. $query = preg_replace ('/TINYINT\(([\d]+)\)/i','INTEGER',$query);
  183. $query = preg_replace ('/mediumint\(([\d]+)\)/i','INTEGER',$query);
  184. $query = preg_replace ('/smallint\(([\d]+)\)/i','INTEGER',$query);
  185. $query = preg_replace('/int\(([\d]+)\)/i','INTEGER',$query);
  186. $query = preg_replace('/auto_increment/i','PRIMARY KEY AUTOINCREMENT',$query);
  187. $query = preg_replace('/, KEY(.*?)MyISAM;/','',$query);
  188. $query = preg_replace('/, KEY(.*?);/',');',$query);
  189. $query = preg_replace('/, UNIQUE KEY(.*?);/',');',$query);
  190. $query = preg_replace('/set\(([^\)]*?)\)/','varchar',$query);
  191. $query = preg_replace('/enum\(([^\)]*?)\)/','varchar',$query);
  192. if ( preg_match("/PRIMARY KEY AUTOINCREMENT/",$query) )
  193. {
  194. $query = preg_replace('/,([\t\s ]+)PRIMARY KEY \(`([0-9a-zA-Z]+)`\)/i','',$query);
  195. $query = str_replace(', PRIMARY KEY (`id`)','',$query);
  196. }
  197. $db->exec($query);
  198. } else {
  199. if ($mysqlVersion < 4.1)
  200. {
  201. $rs = mysql_query($query,$conn);
  202. } else {
  203. if (preg_match('#CREATE#i', $query))
  204. {
  205. $rs = mysql_query(preg_replace("#TYPE=MyISAM#i",$sql4tmp,$query),$conn);
  206. } else {
  207. $rs = mysql_query($query,$conn);
  208. }
  209. }
  210. }
  211. $query='';
  212. } else if (!preg_match("#^(\/\/|--)#", $line))
  213. {
  214. $query .= $line;
  215. }
  216. }
  217. fclose($fp);
  218. //导入默认数据
  219. $query = '';
  220. $fp = fopen(dirname(__FILE__).'/sql-dfdata.txt','r');
  221. while(!feof($fp))
  222. {
  223. $line = rtrim(fgets($fp, 1024));
  224. if (preg_match("#;$#", $line))
  225. {
  226. if ( $dbtype == 'sqlite' )
  227. {
  228. $query .= $line;
  229. $query = str_replace('#@__',$dbprefix,$query);
  230. $query = str_replace("\'","\"",$query);
  231. $db->exec($query);
  232. } else {
  233. $query .= $line;
  234. $query = str_replace('#@__',$dbprefix,$query);
  235. if ($mysqlVersion < 4.1) $rs = mysql_query($query,$conn);
  236. else $rs = mysql_query(str_replace('#~lang~#',$dblang,$query),$conn);
  237. }
  238. $query='';
  239. } else if (!preg_match("#^(\/\/|--)#", $line))
  240. {
  241. $query .= $line;
  242. }
  243. }
  244. fclose($fp);
  245. //更新配置
  246. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$baseurl}' WHERE varname='cfg_basehost';";
  247. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  248. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$cmspath}' WHERE varname='cfg_cmspath';";
  249. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  250. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$indexUrl}' WHERE varname='cfg_indexurl';";
  251. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  252. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$cookieencode}' WHERE varname='cfg_cookie_encode';";
  253. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  254. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$webname}' WHERE varname='cfg_webname';";
  255. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  256. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$adminmail}' WHERE varname='cfg_adminemail';";
  257. $dbtype == 'sqlite'? $db->exec($cquery) : mysql_query($cquery,$conn);
  258. $pfd = "pwd";
  259. $apwd = substr(md5($adminpwd),5,20);
  260. $upwd = md5($adminpwd);
  261. if (function_exists('password_hash')) {
  262. $pfd = "pwd_new";
  263. $apwd = password_hash($adminpwd, PASSWORD_BCRYPT);
  264. $upwd = password_hash($adminpwd, PASSWORD_BCRYPT);
  265. }
  266. //增加管理员帐号
  267. $adminquery = "INSERT INTO `{$dbprefix}admin` (`id`,`usertype`,`userid`,`$pfd`,`uname`,`tname`,`email`,`typeid`,`logintime`,`loginip`) VALUES (1,10,'$adminuser','".$apwd."','admin','','',0,'".time()."','127.0.0.1');";
  268. $dbtype == 'sqlite'? $db->exec($adminquery) : mysql_query($adminquery,$conn);
  269. //关连前台会员帐号
  270. $adminquery = "INSERT INTO `{$dbprefix}member` (`mid`,`mtype`,`userid`,`{$pfd}`,`uname`,`sex`,`rank`,`money`,`email`,`scores`,`matt`,`face`,`safequestion`,`safeanswer`,`jointime`,`joinip`,`logintime`,`loginip`) VALUES ('1','个人','$adminuser','".$upwd."','$adminuser','男','100','0','','10000','10','','0','','".time()."','','0',''); ";
  271. $dbtype == 'sqlite'? $db->exec($adminquery) : mysql_query($adminquery,$conn);
  272. $adminquery = "INSERT INTO `{$dbprefix}member_person` (`mid`,`onlynet`,`sex`,`uname`,`qq`,`msn`,`tel`,`mobile`,`place`,`oldplace`,`birthday`,`star`,`income`,`education`,`height`,`bodytype`,`blood`,`vocation`,`smoke`,`marital`,`house`,`drink`,`datingtype`,`language`,`nature`,`lovemsg`,`address`,`uptime`) VALUES ('1','1','男','{$adminuser}','','','','','0','0','1980-01-01','1','0','0','160','0','0','0','0','0','0','0','0','','','','','0'); ";
  273. $dbtype == 'sqlite'? $db->exec($adminquery) : mysql_query($adminquery,$conn);
  274. $adminquery = "INSERT INTO `{$dbprefix}member_tj` (`mid`,`article`,`album`,`archives`,`homecount`,`pagecount`,`feedback`,`friend`,`stow`) 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`) VALUES ('1','10','0','{$adminuser}的空间','','person','',''); ";
  277. $dbtype == 'sqlite'? $db->exec($adminquery) : mysql_query($adminquery,$conn);
  278. //锁定程序安装
  279. $fp = fopen(INSLOCKFILE,'w');
  280. fwrite($fp,'ok');
  281. fclose($fp);
  282. header('Location:../admin/index.php');
  283. exit();
  284. }
  285. /*------------------------
  286. 检测数据库是否有效
  287. function _10_TestDbPwd()
  288. ------------------------*/
  289. else if ($step==10)
  290. {
  291. header("Pragma:no-cache\r\n");
  292. header("Cache-Control:no-cache\r\n");
  293. header("Expires:0\r\n");
  294. $conn = @mysql_connect($dbhost,$dbuser,$dbpwd);
  295. $info = "";
  296. if ($conn)
  297. {
  298. if (empty($dbname)){
  299. $info = "信息正确";
  300. } else {
  301. $info = mysql_select_db($dbname,$conn)? "数据库已经存在,系统将覆盖数据库": "数据库不存在,系统将自动创建";
  302. }
  303. $result = array(
  304. "code" => 200,
  305. "data" => $info,
  306. );
  307. echo json_encode($result);
  308. } else {
  309. $result = array(
  310. "code" => -1,
  311. "data" => "数据库连接失败",
  312. );
  313. echo json_encode($result);
  314. }
  315. @mysql_close($conn);
  316. exit();
  317. }
  318. ?>