示例#1
0
/**
 * 写入配置文件
 * @param  array $config 配置信息
 */
function sp_create_config($config, $authcode)
{
    if (is_array($config)) {
        //读取配置内容
        $conf = file_get_contents(MODULE_PATH . 'Data/config.php');
        //替换配置项
        foreach ($config as $key => $value) {
            $conf = str_replace("#{$key}#", $value, $conf);
        }
        $conf = str_replace('#AUTHCODE#', $authcode, $conf);
        $conf = str_replace('#COOKIE_PREFIX#', sp_random_string(6) . "_", $conf);
        //写入应用配置文件
        if (file_put_contents('data/conf/db.php', $conf)) {
            sp_show_msg('配置文件写入成功');
        } else {
            sp_show_msg('配置文件写入失败!', 'error');
        }
        return '';
    }
}
 public function step4()
 {
     if (IS_POST) {
         //创建数据库
         $dbconfig['DB_TYPE'] = "mysql";
         $dbconfig['DB_HOST'] = I('post.dbhost');
         $dbconfig['DB_USER'] = I('post.dbuser');
         $dbconfig['DB_PWD'] = I('post.dbpw');
         $dbconfig['DB_PORT'] = I('post.dbport');
         $db = Db::getInstance($dbconfig);
         $dbname = strtolower(I('post.dbname'));
         $sql = "CREATE DATABASE IF NOT EXISTS `{$dbname}` DEFAULT CHARACTER SET utf8";
         $db->execute($sql) || $this->error($db->getError());
         $this->display(":step4");
         //创建数据表
         $dbconfig['DB_NAME'] = $dbname;
         $dbconfig['DB_PREFIX'] = trim(I('post.dbprefix'));
         $db = Db::getInstance($dbconfig);
         $table_prefix = I("post.dbprefix");
         sp_execute_sql($db, "thinkcmf.sql", $table_prefix);
         //更新配置信息
         sp_update_site_configs($db, $table_prefix);
         $authcode = sp_random_string(18);
         //创建管理员
         sp_create_admin_account($db, $table_prefix, $authcode);
         //生成网站配置文件
         sp_create_config($dbconfig, $authcode);
         session("_install_step", 4);
         sleep(1);
         $this->redirect("step5");
     } else {
         exit;
     }
 }
示例#3
0
文件: index.php 项目: xxg3053/kcms
         mysql_query("INSERT INTO `{$dbPrefix}options` (option_value,option_name) VALUES ('{$site_options}','site_options')");
         //读取配置文件,并替换真实配置数据
         $strConfig = file_get_contents(SITEDIR . 'install/' . $configFile);
         $strConfig = str_replace('#DB_HOST#', $dbHost, $strConfig);
         $strConfig = str_replace('#DB_NAME#', $dbName, $strConfig);
         $strConfig = str_replace('#DB_USER#', $dbUser, $strConfig);
         $strConfig = str_replace('#DB_PWD#', $dbPwd, $strConfig);
         $strConfig = str_replace('#DB_PORT#', $dbPort, $strConfig);
         $strConfig = str_replace('#DB_PREFIX#', $dbPrefix, $strConfig);
         $strConfig = str_replace('#AUTHCODE#', sp_random_string(18), $strConfig);
         $strConfig = str_replace('#COOKIE_PREFIX#', sp_random_string(6) . "_", $strConfig);
         @chmod(SITEDIR . '/data/conf/db.php', 0777);
         @file_put_contents(SITEDIR . '/data/conf/db.php', $strConfig);
         //插入管理员
         //生成随机认证码
         $verify = sp_random_string(6);
         $time = time();
         $create_date = date("Y-m-d h:i:s");
         $ip = get_client_ip();
         $ip = empty($ip) ? "0.0.0.0" : $ip;
         $password = sp_password($password, $dbPrefix);
         $query = "INSERT INTO `{$dbPrefix}users` (id,user_login,user_pass,user_nicename,user_email,user_url,create_time,user_activation_key,user_status,last_login_ip,last_login_time) VALUES ('1', '{$username}', '{$password}', 'admin', '{$email}', '', '{$create_date}', '', '1', '{$ip}','{$create_date}');";
         mysql_query($query);
         $message = '成功添加管理员<br />成功写入配置文件<br>安装完成.';
         $arr = array('n' => 999999, 'msg' => $message);
         echo json_encode($arr);
         exit;
     }
     include_once "./templates/s4.php";
     exit;
 case '5':
示例#4
0
         //echo json_encode($arr); exit;
     }
 }
 if ($i == 999999) {
     exit;
 }
 //读取配置文件,并替换真实配置数据1
 $strConfig = file_get_contents(SITEDIR . 'Install/' . $configFile);
 $strConfig = str_replace('#DB_HOST#', $dbHost, $strConfig);
 $strConfig = str_replace('#DB_NAME#', $dbName, $strConfig);
 $strConfig = str_replace('#DB_USER#', $dbUser, $strConfig);
 $strConfig = str_replace('#DB_PWD#', $dbPwd, $strConfig);
 $strConfig = str_replace('#DB_PORT#', $dbPort, $strConfig);
 $strConfig = str_replace('#DB_PREFIX#', $dbPrefix, $strConfig);
 $strConfig = str_replace('#AUTHCODE#', sp_random_string(18), $strConfig);
 $strConfig = str_replace('#COOKIE_PREFIX#', sp_random_string(6) . "_", $strConfig);
 @chmod(SITEDIR . '/App/Common/Conf/config_db.php', 0777);
 //数据库配置文件的地址
 @file_put_contents(SITEDIR . '/App/Common/Conf/config_db.php', $strConfig);
 //数据库配置文件的地址
 //更新网站配置信息2
 $sitename = trim($_POST['sitename']);
 $siteurl = trim($_POST['siteurl']);
 $sitekeywords = trim($_POST['sitekeywords']);
 $siteinfo = trim($_POST['siteinfo']);
 mysql_query("INSERT INTO `{$dbPrefix}config` (id,config_webname,config_webtitle,config_webkw,config_cp,config_company,config_address,config_tel,config_weburl) VALUES ('1','{$sitename}','{$sitename}','{$sitekeywords}','{$siteinfo}','{$siteinfo}','海南省海口市','17889988281','www.yejiao.net')");
 //插入管理员表字段tuzi_admin表3
 $time = time();
 $create_date = date("Y-m-d h:i:s");
 $ip = get_client_ip();
 $ip = empty($ip) ? "0.0.0.0" : $ip;