1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| public function step($step) { $data['step']=$step; if($step==1 || $step==2){ $data['permission'] = $this->_checkFileRight(); $this->load->view('install',$data); } if($step==3){ $this->_install_do(); } }
function _install_do() { $data['step']=3; if($_POST){ $dbhost = $this->input->post('dbhost'); $dbport = $this->input->post('dbport'); $dbname = $this->input->post('dbname'); $dbuser = $this->input->post('dbuser'); $dbpwd = $this->input->post('dbpwd')?$this->input->post('dbpwd'):''; $dbprefix = $this->input->post('dbprefix'); $userid = $this->input->post('admin'); $pwd = md5($this->input->post('pwd')); $email = $this->input->post('email'); $sub_folder = '/'.$this->input->post('base_url').'/'; $conn = mysql_connect($dbhost.':'.$dbport,$dbuser,$dbpwd); if (!$conn) { die('无法连接到数据库服务器,请检查用户名和密码是否正确'); } if($this->input->post('creatdb')){ if([email protected]_query('CREATE DATABASE IF NOT EXISTS '.$dbname)){ die('指定的数据库('.$dbname.')系统尝试创建失败,请通过其他方式建立数据库'); } } if(!mysql_select_db($dbname,$conn)){ die($dbname.'数据库不存在,请创建或检查数据名.');
} $sql = file_get_contents(FCPATH.'app/config/startbbs.sql'); $sql = str_replace("sb_",$dbprefix,$sql); $explode = explode(";",$sql); $data['msg1']="创建表".$dbname."成功,请稍后……<br/>"; foreach ($explode as $key=>$value){ if(!empty($value)){ if(trim($value)){ mysql_query($value.";"); } } } $password = $pwd; $ip=$this->myclass->get_ip(); $insert= "INSERT INTO ".$dbprefix."users (group_type,gid,is_active,username,password,email,regtime,ip) VALUES ('0','1','1','".$userid."','".$password."','".$email."','".time()."','".$ip."')"; mysql_query($insert); mysql_close($conn); $data['msg2']="安装完成,正在保存配置文件,请稍后……"; $dbconfig = "<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');\n" ."\$active_group = 'default';\n" ."\$active_record = TRUE;\n" ."\$db['default']['hostname'] = '".$dbhost."';\n" ."\$db['default']['port'] = '".$dbport."';\n" ."\$db['default']['username'] = '".$dbuser."';\n" ."\$db['default']['password'] = '".$dbpwd."';\n" ."\$db['default']['database'] = '".$dbname."';\n" ."\$db['default']['dbdriver'] = 'mysql';\n" ."\$db['default']['dbprefix'] = '".$dbprefix."';\n" ."\$db['default']['pconnect'] = TRUE;\n" ."\$db['default']['db_debug'] = TRUE;\n" ."\$db['default']['cache_on'] = FALSE;\n" ."\$db['default']['cachedir'] = 'app/cache';\n" ."\$db['default']['char_set'] = 'utf8';\n" ."\$db['default']['dbcollat'] = 'utf8_general_ci';\n" ."\$db['default']['swap_pre'] = '';\n" ."\$db['default']['autoinit'] = TRUE;\n" ."\$db['default']['stricton'] = FALSE;"; $file = FCPATH.'/app/config/database.php'; file_put_contents($file,$dbconfig); if($sub_folder){ $this->config->update('myconfig','sub_folder', $sub_folder); } $encryption_key = md5(uniqid()); if($encryption_key){ $this->config->update('myconfig','encryption_key', $encryption_key); }
$data['msg3']="保存配置文件完成!"; touch(FCPATH.'install.lock'); $data['msg4']="创建锁定安装文件install.lock成功"; $data['msg5']="安装startbbs成功!"; } $this->load->view('install',$data); }
|