/** * input and check if database connection is valid * create ./protected/config/environment.php file * * @return void */ public function actionStep2() { Yii::app()->session->remove('env'); $model = new ConfigForm(); if (isset($_POST['ConfigForm']) === true) { $model->attributes = $_POST['ConfigForm']; $model->password = $_POST['ConfigForm']['password']; if ($model->validate() === true) { if ($model->checkConnection() !== true) { //Attemting To Create The Database @mysql_connect("{$model->host}", "{$model->username}", "{$model->password}"); if (mysql_query("CREATE DATABASE {$model->dbName}")) { $flag_db_created = 1; } else { $flag_db_created = 0; } } if ($model->checkConnection() === true) { //create enviroment file $configPath = Yii::getPathOfAlias('application.config'); $envSampleFile = $configPath . DIRECTORY_SEPARATOR . 'environment-sample.php'; if (file_exists($envSampleFile) === false) { throw new CHttpException(500, 'File not found "' . $envSampleFile . '"'); } $content = file_get_contents($envSampleFile); $searches = array('@base_url@', '@host@', '@port@', '@dbname@', '@username@', '@password@'); $replaces = array($model->baseUrl, $model->host, $model->port, $model->dbName, $model->username, $model->password); $content = str_replace($searches, $replaces, $content); if (is_writable($configPath) === true || is_writable($configPath . '/environment.php') === true) { file_put_contents($configPath . '/environment.php', $content); } else { Yii::app()->session['env'] = $content; } $this->redirect(array('default/step3')); } else { $this->render('Step2ErrorDb'); } } } //Check if (isset(Yii::app()->session['key']) and isset(Yii::app()->session['email'])) { $key_info['key'] = Yii::app()->session['key']; Yii::app()->session->remove('key'); //Remove $key_info['email'] = Yii::app()->session['email']; Yii::app()->session->remove('email'); //Remove Yii::app()->session['key'] = $key_info['key']; Yii::app()->session['email'] = $key_info['email']; $this->render('step2', array('model' => $model)); } else { //session expired or direct link $this->redirect(array('index')); } }
/** * input and check if database connection is valid * create ./protected/config/environment.php file * * @return void */ public function actionStep2() { Yii::app()->session->remove('env'); $model = new ConfigForm(); if (isset($_POST['ConfigForm']) === true) { $model->attributes = $_POST['ConfigForm']; $model->password = $_POST['ConfigForm']['password']; if ($model->validate() === true) { if ($model->checkConnection() !== true) { //Attemting To Create The Database @mysql_connect("{$model->host}", "{$model->username}", "{$model->password}"); if (mysql_query("CREATE DATABASE {$model->dbName}")) { $flag_db_created = 1; } else { $flag_db_created = 0; } } if ($model->checkConnection() === true) { //create enviroment file $configPath = Yii::getPathOfAlias('application.config'); $envSampleFile = $configPath . DIRECTORY_SEPARATOR . 'environment-sample.php'; if (file_exists($envSampleFile) === false) { throw new CHttpException(500, 'File not found "' . $envSampleFile . '"'); } $content = file_get_contents($envSampleFile); $searches = array('@base_url@', '@host@', '@port@', '@dbname@', '@username@', '@password@'); $replaces = array($model->baseUrl, $model->host, $model->port, $model->dbName, $model->username, $model->password); $content = str_replace($searches, $replaces, $content); if (is_writable($configPath) === true || is_writable($configPath . '/environment.php') === true) { file_put_contents($configPath . '/environment.php', $content); } else { Yii::app()->session['env'] = $content; } $this->redirect(array('default/step3')); } else { $this->render('Step2ErrorDb'); } } } //Check if (isset(Yii::app()->session['key']) and isset(Yii::app()->session['email'])) { $key_info['key'] = Yii::app()->session['key']; Yii::app()->session->remove('key'); //Remove $key_info['email'] = Yii::app()->session['email']; Yii::app()->session->remove('email'); //Remove $serverurl = "http://licence-server.open-school.org/server.php"; // $ch = curl_init ($serverurl); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt ($ch, CURLOPT_POST, true); // curl_setopt ($ch, CURLOPT_POSTFIELDS, $key_info); // $result = curl_exec ($ch); // $result = json_decode($result, true); // if($result['valid'] == 'true') if (1) { Yii::app()->session['key'] = $key_info['key']; Yii::app()->session['email'] = $key_info['email']; $this->render('step2', array('model' => $model)); } else { //session contains invalid key //die("Invalid Key!"); echo 'Invalid Key'; $this->redirect(array('index')); } } else { //session expired or direct link $this->redirect(array('index')); } }