installAction.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. set_time_limit(600);
  3. class installClassAction extends ActionNot{
  4. public function initAction()
  5. {
  6. if(getconfig('systype')=='demo' || getconfig('install'))exit('');
  7. }
  8. public function defaultAction()
  9. {
  10. $this->tpltype = 'html';
  11. $this->title = TITLE.'_安装';
  12. $dbdiz = '';
  13. $paths = '../../mysql5.6.10/my.ini';
  14. if(@file_exists($paths)){
  15. $_conts = @file_get_contents($paths);
  16. if($_conts && contain($_conts,'3307'))$dbdiz='3307';
  17. }
  18. $this->assign('dbdiz', $dbdiz);
  19. }
  20. private function rmdirs($dir){
  21. $dir_arr = scandir($dir);
  22. foreach($dir_arr as $key=>$val){
  23. if($val == '.' || $val == '..'){
  24. }else{
  25. @unlink($dir.'/'.$val);
  26. }
  27. }
  28. @rmdir($dir);
  29. }
  30. public function delinstallAjax()
  31. {
  32. $this->delinstall();
  33. echo 'success';
  34. }
  35. private function delinstall()
  36. {
  37. $dir = ROOT_PATH.'/'.PROJECT.'/install';
  38. $this->rmdirs($dir);
  39. }
  40. private function isbasecz($db, $base){
  41. $dbrows = $db->getall("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$base'");
  42. return $dbrows;
  43. }
  44. public function saveAjax()
  45. {
  46. $dbtype = $this->post('dbtype');
  47. $host = $this->post('host');
  48. $user = $this->post('user');
  49. $duankou = $this->post('duankou');
  50. $pass = $this->post('pass');
  51. $base = $this->post('base');
  52. $xinhukey = $this->post('xinhukey');
  53. $perfix = strtolower($this->post('perfix','xinhu_'));
  54. $engine = $this->post('engine','MyISAM');
  55. $title = '信呼协同办公系统';
  56. $qom = 'xinhu_';
  57. $url = $this->post('url');
  58. $paths = ''.P.'/'.P.'Config.php';
  59. $paths1 = ''.P.'/'.P.'Config.php1';
  60. $inpaths = ROOT_PATH.'/'.$paths.'';
  61. if($duankou)$host.=':'.$duankou.'';
  62. $msg = '';
  63. if($dbtype=='mysql' && !function_exists('mysql_connect'))exit('未开启mysql扩展模块');
  64. if($dbtype=='mysqli' && !class_exists('mysqli'))exit('未开启mysqli扩展模块');
  65. @unlink($inpaths);
  66. $this->rock->createtxt($paths, '<?php return array();');
  67. if(file_exists($inpaths))exit('无法写入文件夹'.P.',<a href="'.URLY.'view_wuxux.html" target="_blank" style="color:blue">[帮助]</a>');
  68. //1
  69. $db1 = import($dbtype);
  70. $db1->changeattr($host, $user, $pass, 'information_schema');
  71. $db1->connectdb();
  72. $msg = $db1->errormsg;
  73. if(!$this->isempt($msg))exit('数据库用户名/密码有误:'.$msg.'');
  74. if(!$this->isbasecz($db1, $base)){
  75. if($user=='root'){
  76. $db1->query("CREATE DATABASE `$base` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
  77. if(!$this->isbasecz($db1, $base))exit('无法创建数据库:'.$base.',请自己手动创建');
  78. }else{
  79. exit('数据库'.$base.'不存在,因为非root帐号,请自己手动创建');
  80. }
  81. }
  82. //2
  83. $db = import($dbtype);
  84. $db->changeattr($host, $user, $pass, $base);
  85. $db->connectdb();
  86. $msg = $db->errormsg;
  87. if(!$this->isempt($msg))exit('数据库错误:'.$msg.'');
  88. $dburl = ROOT_PATH.'/'.PROJECT.'/install/rockxinhu.sql';
  89. if(!file_exists($dburl))exit('数据库sql文件不存在');
  90. $sqlss = file_get_contents($dburl);
  91. $a = explode(";
  92. ", $sqlss);
  93. for($i=0; $i<count($a)-1; $i++){
  94. $sql = $a[$i];
  95. $sql = str_replace('`xinhu_', '`'.$perfix.'', $sql);
  96. $sql = str_replace('ENGINE=MyISAM', 'ENGINE='.$engine.'', $sql); //使用引擎
  97. $bo = $db->query($sql);
  98. if(!$bo){
  99. exit('导入失败:'.$db->error().'');
  100. }
  101. }
  102. $db->query("delete from `".$perfix."option` where `name` is null");
  103. $urs = $db->getone("".$perfix."admin", "`id`=1");
  104. if(!is_array($urs))exit('安装失败:'.$db->error().',可选择手动安装<a href="'.URLY.'view_anzz.html" style="color:blue" target="_blank">[查看]</a>');
  105. $rand = $this->rock->jm->getRandkey();
  106. $asynkey= md5($this->rock->jm->getRandkey());
  107. $openkey= md5($this->rock->jm->getRandkey());
  108. $txt = "<?php
  109. if(!defined('HOST'))die('not access');
  110. //系统配置文件
  111. return array(
  112. 'url' => '', //系统URL
  113. 'localurl' => '', //本地系统URL,用于服务器上浏览地址
  114. 'title' => '$title', //系统默认标题
  115. 'apptitle' => '信呼OA', //APP上或PC客户端上的标题
  116. 'db_host' => '$host', //数据库地址
  117. 'db_user' => '$user', //数据库用户名
  118. 'db_pass' => '$pass', //数据库密码
  119. 'db_base' => '$base', //数据库名称
  120. 'db_engine' => '$engine', //数据库使用引擎
  121. 'perfix' => '$perfix', //数据库表名前缀
  122. 'qom' => '$qom', //session、cookie前缀
  123. 'highpass' => '', //超级管理员密码,可用于登录任何帐号
  124. 'db_drive' => '$dbtype', //操作数据库驱动有mysql,mysqli,pdo三种
  125. 'randkey' => '$rand', //系统随机字符串密钥
  126. 'asynkey' => '$asynkey', //这是异步任务key
  127. 'openkey' => '$openkey', //对外接口openkey
  128. 'updir' => 'upload', //默认上传目录
  129. 'sqllog' => false, //是否记录sql日志保存upload/sqllog下
  130. 'asynsend' => false, //是否异步发送提醒消息,为true需开启服务端
  131. 'editpass' => '1', //用户登录修改密码:0不用修改,1强制用户必须修改
  132. 'install' => true, //已安装,不要去掉啊
  133. 'xinhukey' => '$xinhukey', //信呼官网key,在线升级使用
  134. );";
  135. $this->rock->createtxt($paths, $txt);
  136. $this->delinstall();
  137. if(file_exists($paths1))@unlink($paths1);
  138. c('xinhu')->getdata('xinhuinstall');//这个只是用于统计安装数而已
  139. echo 'success';
  140. }
  141. }
粤ICP备19079148号