Install.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. defined('BASEPATH') or exit( 'No direct script access allowed' );
  3. class Install extends CI_Controller
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. if( file_exists(FCPATH . 'packs/install/install.lock') )
  9. {
  10. exit( '重新安装,请删除./packs/install/install.lock文件' );
  11. }
  12. $ip = ("/" == DIRECTORY_SEPARATOR ? $_SERVER["SERVER_ADDR"] : gethostbyname($_SERVER["SERVER_NAME"]));
  13. return NULL;
  14. }
  15. public function index()
  16. {
  17. $this->load->view("install.html");
  18. }
  19. public function save()
  20. {
  21. $host = $this->input->post("host", true);
  22. $port = (int) $this->input->post("port", true);
  23. $name = $this->input->post("name", true);
  24. $prefix = $this->input->post("prefix", true);
  25. $user = $this->input->post("user", true);
  26. $pass = $this->input->post("pass", true);
  27. $admin_name = $this->input->post("admin_name", true);
  28. $admin_pass = $this->input->post("admin_pass", true);
  29. if( $port == 0 )
  30. {
  31. $port = "";
  32. }
  33. if( empty($host) || empty($name) || empty($user) || empty($pass) || empty($admin_name) || empty($admin_pass) )
  34. {
  35. exit( "<script>alert('数据不完整~!');history.go(-1);</script>" );
  36. }
  37. $this->load->helper("string");
  38. $Encryption_Key = random_string("alnum", 12);
  39. $driver = (is_php("5.4") ? "mysqli" : "mysql");
  40. $config = file_get_contents(FCPATH . "libraries/database.php");
  41. $config = preg_replace("/'CS_Sqlserver','(.*?)'/", "'CS_Sqlserver','" . $host . "'", $config);
  42. $config = preg_replace("/'CS_Sqlport','(.*?)'/", "'CS_Sqlport','" . $port . "'", $config);
  43. $config = preg_replace("/'CS_Sqlname','(.*?)'/", "'CS_Sqlname','" . $name . "'", $config);
  44. $config = preg_replace("/'CS_Sqluid','(.*?)'/", "'CS_Sqluid','" . $user . "'", $config);
  45. $config = preg_replace("/'CS_Sqlpwd','(.*?)'/", "'CS_Sqlpwd','" . $pass . "'", $config);
  46. $config = preg_replace("/'CS_Dbdriver','(.*?)'/", "'CS_Dbdriver','" . $driver . "'", $config);
  47. $config = preg_replace("/'CS_SqlPrefix','(.*?)'/", "'CS_SqlPrefix','" . $prefix . "'", $config);
  48. $config = preg_replace("/'CS_Encryption_Key','(.*?)'/", "'CS_Encryption_Key','" . $Encryption_Key . "'", $config);
  49. if( !write_file(FCPATH . 'libraries/database.php', $config) )
  50. {
  51. exit( "<script>alert('./libraries/database.php文件没有修改权限');history.go(-1);</script>" );
  52. }
  53. $mukey = random_string("alnum", 16);
  54. $web_path = str_replace("\\", "/", str_replace(getcwd(), "", FCPATH));
  55. $config2 = file_get_contents(FCPATH . "libraries/config.php");
  56. $config2 = preg_replace("/'Mu_Key','(.*?)'/", "'Mu_Key','" . $mukey . "'", $config2);
  57. $config2 = preg_replace("/'Admin_Name','(.*?)'/", "'Admin_Name','" . $admin_name . "'", $config2);
  58. $config2 = preg_replace("/'Admin_Code','(.*?)'/", "'Admin_Code','" . $admin_pass . "'", $config2);
  59. $config2 = preg_replace("/'Web_Path','(.*?)'/", "'Web_Path','" . $web_path . "'", $config2);
  60. if( !write_file(FCPATH . 'libraries/config.php', $config2) )
  61. {
  62. exit( "<script>alert('./libraries/config.php文件没有修改权限');history.go(-1);</script>" );
  63. }
  64. $sql = "CREATE TABLE IF NOT EXISTS `" . $prefix . "queue` (\n\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t `vid` int(11) DEFAULT '0' COMMENT '视频ID',\n\t\t `xu` tinyint(1) DEFAULT '1' COMMENT '转码码率序号',\n\t\t `path` varchar(255) DEFAULT '' COMMENT '源文件路径',\n\t\t `jpg` varchar(255) DEFAULT '' COMMENT 'JPG图片保存路径',\n\t\t `gif` varchar(255) DEFAULT '' COMMENT 'GIF图片保存路径',\n\t\t `m3u8` varchar(255) DEFAULT '' COMMENT 'm3u8文件保存路径',\n\t\t `duration` varchar(64) DEFAULT '' COMMENT '视频时长',\n\t\t `sid` tinyint(1) DEFAULT '0' COMMENT '0待转码1转码中',\n\t\t `addtime` int(10) DEFAULT '0' COMMENT '转码开始时间',\n\t\t PRIMARY KEY (`id`),\n\t\t KEY `vid` (`vid`)\n\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='转码队列表';\n\t\t#ctcms#\n\t\tCREATE TABLE IF NOT EXISTS `" . $prefix . "class` (\n\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t `name` varchar(255) DEFAULT '' COMMENT '分类名称',\n\t\t `xid` tinyint(4) DEFAULT '10' COMMENT '排序越小越前',\n\t\t PRIMARY KEY (`id`)\n\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='分类列表';\n\t\t#ctcms#\n\t\tCREATE TABLE IF NOT EXISTS `" . $prefix . "video` (\n\t\t `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t `cid` int(11) DEFAULT '0',\n\t\t `name` varchar(255) DEFAULT '' COMMENT '视频名称',\n\t\t `pic` varchar(255) DEFAULT '' COMMENT '图片保存路径',\n\t\t `path` varchar(255) DEFAULT '' COMMENT '原文件保存路径',\n\t\t `m3u8` varchar(255) DEFAULT '' COMMENT 'm3u8文件保存路径',\n\t\t `md5` varchar(40) DEFAULT '' COMMENT '文件md5',\n\t\t `vid` varchar(64) DEFAULT '' COMMENT '自定义ID',\n\t\t `sid` tinyint(3) DEFAULT '0' COMMENT '转码状态,0待转码,1完成,2失败,3异常',\n\t\t `duration` varchar(64) DEFAULT '' COMMENT '时长',\n\t\t `size` bigint(20) DEFAULT '0' COMMENT '大小',\n\t\t `addtime` int(10) DEFAULT '0' COMMENT '上传时间',\n\t\t PRIMARY KEY (`id`),\n\t\t KEY `vid` (`vid`),\n\t\t KEY `md5` (`md5`)\n\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='上传视频记录表'";
  65. if( is_php('5.4') )
  66. {
  67. $mysqli = new mysqli($host, $user, $pass);
  68. if( mysqli_connect_errno() )
  69. {
  70. exit( '<script>alert(\'数据库链接失败~!\');history.go(-1);</script>' );
  71. }
  72. if( !$mysqli->select_db($name) )
  73. {
  74. if( !$mysqli->query("CREATE DATABASE `" . $name . "`") )
  75. {
  76. exit( "<script>alert('数据库表《" . $name . "》不存在,请手动创建~!');history.go(-1);</script>" );
  77. }
  78. $mysqli->select_db($name);
  79. }
  80. $mysqli->query("SET NAMES utf8");
  81. $sqlarr = explode("#ctcms#", $sql);
  82. $i = 0;
  83. while( $i < count($sqlarr) )
  84. {
  85. if( !empty($sqlarr[$i]) )
  86. {
  87. $mysqli->query($sqlarr[$i]);
  88. }
  89. $i++;
  90. }
  91. }
  92. else
  93. {
  94. $lnk = mysql_connect($host, $user, $pass);
  95. if( !$lnk )
  96. {
  97. exit( "<script>alert('数据库链接失败~!');history.go(-1);</script>" );
  98. }
  99. if( !mysql_select_db($name, $lnk) )
  100. {
  101. if( !mysql_query("CREATE DATABASE `" . $name . "`") )
  102. {
  103. exit( "<script>alert('数据库表《" . $name . "》不存在,请手动创建~!');history.go(-1);</script>" );
  104. }
  105. mysql_select_db($name, $lnk);
  106. }
  107. mysql_query('SET NAMES utf8', $lnk);
  108. $sqlarr = explode("#ctcms#", $sql);
  109. $i = 0;
  110. while( $i < count($sqlarr) )
  111. {
  112. if( !empty($sqlarr[$i]) )
  113. {
  114. mysql_query($sqlarr[$i]);
  115. }
  116. $i++;
  117. }
  118. }
  119. if( !write_file(FCPATH . 'packs/install/install.lock', 'ctcms') )
  120. {
  121. exit( '<script>alert(\'./packs/install/目录没有写入权限\');history.go(-1);</script>' );
  122. }
  123. exit( '<script>alert(\'恭喜您,安装完成\');window.location.href=\'' . $web_path . "admin.php';</script>" );
  124. }
  125. }