installAction.php 4.9 KB

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