installAction.php 5.0 KB

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