2010-03-16 19:25:05 +00:00
|
|
|
<?php
|
|
|
|
class OC_CONFIG{
|
2010-08-12 15:30:20 +00:00
|
|
|
static public $forms=array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add a form to the settings page
|
|
|
|
* @param string name
|
|
|
|
* @param string url
|
|
|
|
*/
|
|
|
|
public static function addForm($name,$url){
|
|
|
|
self::$forms[$name]=$url;
|
|
|
|
}
|
|
|
|
|
2010-03-16 19:25:05 +00:00
|
|
|
/**
|
2010-08-12 15:30:20 +00:00
|
|
|
* settings page
|
2010-03-16 19:25:05 +00:00
|
|
|
*
|
|
|
|
*/
|
2010-08-12 15:30:20 +00:00
|
|
|
public static function showSettings(){
|
|
|
|
oc_require('templates/settings.php');
|
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
|
2010-03-16 19:25:05 +00:00
|
|
|
/**
|
2010-04-22 22:05:04 +00:00
|
|
|
* show the configform
|
2010-03-16 19:25:05 +00:00
|
|
|
*
|
|
|
|
*/
|
2010-07-10 17:41:30 +00:00
|
|
|
public static function showAdminForm(){
|
2010-04-19 17:46:42 +00:00
|
|
|
global $CONFIG_ADMINLOGIN;
|
|
|
|
global $CONFIG_ADMINPASSWORD;
|
2010-04-22 22:05:04 +00:00
|
|
|
global $CONFIG_DATADIRECTORY;
|
|
|
|
global $CONFIG_HTTPFORCESSL;
|
|
|
|
global $CONFIG_DATEFORMAT;
|
|
|
|
global $CONFIG_DBNAME;
|
2010-07-04 05:35:05 +00:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-04-22 22:05:04 +00:00
|
|
|
global $CONFIG_INSTALLED;
|
2010-04-23 16:27:36 +00:00
|
|
|
$allow=false;
|
|
|
|
if(!$CONFIG_INSTALLED){
|
|
|
|
$allow=true;
|
|
|
|
}elseif(OC_USER::isLoggedIn()){
|
|
|
|
if(OC_USER::ingroup($_SESSION['username'],'admin')){
|
|
|
|
$allow=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($allow){
|
2010-04-24 10:40:20 +00:00
|
|
|
oc_require('templates/adminform.php');
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-16 19:25:05 +00:00
|
|
|
|
2011-01-01 00:01:57 +00:00
|
|
|
public static function createUserListener(){
|
2010-04-23 16:27:36 +00:00
|
|
|
if(OC_USER::isLoggedIn()){
|
|
|
|
if(OC_USER::ingroup($_SESSION['username'],'admin')){
|
|
|
|
if(isset($_POST['new_username']) and isset($_POST['new_password'])){
|
|
|
|
if(OC_USER::createuser($_POST['new_username'],$_POST['new_password'])){
|
|
|
|
return 'user successfully created';
|
|
|
|
}else{
|
|
|
|
return 'error while trying to create user';
|
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}else{
|
2010-04-23 16:27:36 +00:00
|
|
|
return false;
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return false;
|
2010-04-19 17:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
|
2011-01-01 00:01:57 +00:00
|
|
|
public static function createGroupListener(){
|
2010-04-22 22:05:04 +00:00
|
|
|
if(OC_USER::isLoggedIn()){
|
|
|
|
if(isset($_POST['creategroup']) and $_POST['creategroup']==1){
|
|
|
|
if(OC_USER::creategroup($_POST['groupname'])){
|
2010-09-20 16:28:39 +00:00
|
|
|
return 'group successfully created';
|
2010-04-22 22:05:04 +00:00
|
|
|
}else{
|
|
|
|
return 'error while trying to create group';
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return false;
|
2010-04-19 17:46:42 +00:00
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}else{
|
|
|
|
return false;
|
2010-04-19 17:46:42 +00:00
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-01 00:08:40 +00:00
|
|
|
* listen for configuration changes
|
2010-04-22 22:05:04 +00:00
|
|
|
*
|
|
|
|
*/
|
2011-01-01 00:01:57 +00:00
|
|
|
public static function configListener(){
|
2010-04-22 22:05:04 +00:00
|
|
|
if(OC_USER::isLoggedIn()){
|
|
|
|
if(isset($_POST['config']) and $_POST['config']==1){
|
|
|
|
$error='';
|
|
|
|
if(!OC_USER::checkpassword($_SESSION['username'],$_POST['currentpassword'])){
|
|
|
|
$error.='wrong password<br />';
|
|
|
|
}else{
|
|
|
|
if(isset($_POST['changepass']) and $_POST['changepass']==1){
|
|
|
|
if(!isset($_POST['password']) or empty($_POST['password'])) $error.='password not set<br />';
|
|
|
|
if(!isset($_POST['password2']) or empty($_POST['password2'])) $error.='retype password not set<br />';
|
|
|
|
if($_POST['password']<>$_POST['password2'] ) $error.='passwords are not the same<br />';
|
|
|
|
if(empty($error)){
|
|
|
|
if(!OC_USER::setpassword($_SESSION['username'],$_POST['password'])){
|
|
|
|
$error.='error while trying to set password<br />';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $error;
|
|
|
|
}else{
|
|
|
|
return false;
|
2010-04-20 22:25:34 +00:00
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}else{
|
|
|
|
return false;
|
2010-04-20 22:25:34 +00:00
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
2010-07-11 20:44:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the configuration to the `config.php` file
|
|
|
|
*
|
2010-07-12 17:58:45 +00:00
|
|
|
* $configuration contains key/value pairs
|
2010-07-11 20:44:48 +00:00
|
|
|
* - the key is the option name without the 'CONFIG_' prefix
|
2010-07-12 17:58:45 +00:00
|
|
|
* - the value is a string, a boolean or a number
|
2010-07-11 20:44:48 +00:00
|
|
|
*
|
2010-07-12 11:24:02 +00:00
|
|
|
* @param array $configuration is an associative array
|
2010-07-11 20:44:48 +00:00
|
|
|
*/
|
|
|
|
protected static function saveConfiguration($configuration) {
|
|
|
|
global $SERVERROOT;
|
|
|
|
|
|
|
|
$configContent = '<?php';
|
|
|
|
foreach ( $configuration as $key => $value ) {
|
|
|
|
if ( is_string($value) ) {
|
2010-07-12 17:58:45 +00:00
|
|
|
$configContent .= "\n\$CONFIG_$key = '$value';"; // e.g. $CONFIG_DBTYPE = 'mysql';
|
2010-07-11 20:44:48 +00:00
|
|
|
} else if ( is_bool($value) ) {
|
|
|
|
$value = $value ? 'true' : 'false';
|
2010-07-12 17:58:45 +00:00
|
|
|
$configContent .= "\n\$CONFIG_$key = $value;"; // e.g. $CONFIG_INSTALLED = true;
|
|
|
|
} else if ( is_numeric($value) ) {
|
|
|
|
$configContent .= "\n\$CONFIG_$key = $value;"; // e.g. $CONFIG_PI = 3.14;
|
2010-07-11 20:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$filename = "$SERVERROOT/config/config.php";
|
|
|
|
file_put_contents($filename, $configContent);
|
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
|
|
|
|
/**
|
2011-01-01 00:08:40 +00:00
|
|
|
* listen for admin configuration changes and write it to the file
|
2010-04-22 22:05:04 +00:00
|
|
|
*4bd0be1185e76
|
|
|
|
*/
|
2011-01-01 00:01:57 +00:00
|
|
|
public static function writeAdminListener(){
|
2010-04-22 22:05:04 +00:00
|
|
|
global $CONFIG_INSTALLED;
|
2010-04-22 22:21:59 +00:00
|
|
|
$allow=false;
|
2010-04-23 16:27:36 +00:00
|
|
|
if(!$CONFIG_INSTALLED){
|
2010-04-22 22:21:59 +00:00
|
|
|
$allow=true;
|
|
|
|
}elseif(OC_USER::isLoggedIn()){
|
|
|
|
if(OC_USER::ingroup($_SESSION['username'],'admin')){
|
|
|
|
$allow=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($allow){
|
2010-04-22 22:05:04 +00:00
|
|
|
global $DOCUMENTROOT;
|
|
|
|
global $SERVERROOT;
|
|
|
|
global $WEBROOT;
|
|
|
|
global $CONFIG_DBHOST;
|
|
|
|
global $CONFIG_DBNAME;
|
2010-07-04 05:35:05 +00:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-05-09 14:33:16 +00:00
|
|
|
global $CONFIG_INSTALLED;
|
2010-04-22 22:05:04 +00:00
|
|
|
global $CONFIG_DBUSER;
|
|
|
|
global $CONFIG_DBPASSWORD;
|
|
|
|
global $CONFIG_DBTYPE;
|
|
|
|
global $CONFIG_ADMINLOGIN;
|
|
|
|
global $CONFIG_ADMINPASSWORD;
|
|
|
|
if(isset($_POST['set_config'])){
|
|
|
|
//checkdata
|
|
|
|
$error='';
|
2010-05-09 14:33:16 +00:00
|
|
|
$FIRSTRUN=!$CONFIG_INSTALLED;
|
2010-04-22 22:05:04 +00:00
|
|
|
if(!$FIRSTRUN){
|
2010-05-09 14:33:16 +00:00
|
|
|
if(!OC_USER::login($_SESSION['username'],$_POST['currentpassword'])){
|
2010-04-22 22:05:04 +00:00
|
|
|
$error.='wrong password<br />';
|
|
|
|
}
|
2010-04-19 17:46:42 +00:00
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
|
2010-05-09 14:33:16 +00:00
|
|
|
if((!isset($_POST['adminlogin']) or empty($_POST['adminlogin'])) and $FIRSTRUN) $error.='admin login not set<br />';
|
2010-04-22 22:05:04 +00:00
|
|
|
if((!isset($_POST['adminpassword']) or empty($_POST['adminpassword'])) and $FIRSTRUN) $error.='admin password not set<br />';
|
|
|
|
if((!isset($_POST['adminpassword2']) or empty($_POST['adminpassword2'])) and $FIRSTRUN) $error.='retype admin password not set<br />';
|
2010-09-05 12:21:07 +00:00
|
|
|
if((!isset($_POST['datadirectory']) or empty($_POST['datadirectory'])) and $FIRSTRUN) $error.='data directory not set<br />';
|
2010-04-22 22:05:04 +00:00
|
|
|
if(!isset($_POST['dateformat']) or empty($_POST['dateformat'])) $error.='dateformat not set<br />';
|
2010-09-05 12:21:07 +00:00
|
|
|
if((!isset($_POST['dbname']) or empty($_POST['dbname'])) and $FIRSTRUN) $error.='databasename not set<br />';
|
2010-05-09 14:33:16 +00:00
|
|
|
if($FIRSTRUN and $_POST['adminpassword']<>$_POST['adminpassword2'] ) $error.='admin passwords are not the same<br />';
|
2010-09-05 12:21:07 +00:00
|
|
|
$dbtype=(isset($_POST['dbtype']))?$_POST['dbtype']:$CONFIG_DBTYPE;
|
2010-04-22 22:05:04 +00:00
|
|
|
if($dbtype=='mysql'){
|
|
|
|
if(!isset($_POST['dbhost']) or empty($_POST['dbhost'])) $error.='database host not set<br />';
|
|
|
|
if(!isset($_POST['dbuser']) or empty($_POST['dbuser'])) $error.='database user not set<br />';
|
|
|
|
if($_POST['dbpassword']<>$_POST['dbpassword2'] ) $error.='database passwords are not the same<br />';
|
|
|
|
|
2010-04-19 17:46:42 +00:00
|
|
|
}
|
2010-05-08 19:32:20 +00:00
|
|
|
if(isset($_POST['enablebackup']) and $_POST['enablebackup']==1){
|
|
|
|
if(!isset($_POST['backupdirectory']) or empty($_POST['backupdirectory'])) $error.='backup directory not set<br />';
|
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
if(!$FIRSTRUN){
|
|
|
|
if(!isset($_POST['adminpassword']) or empty($_POST['adminpassword'])){
|
|
|
|
$_POST['adminpassword']=$CONFIG_ADMINPASSWORD;
|
|
|
|
}
|
|
|
|
if(!isset($_POST['dbpassword']) or empty($_POST['dbpassword'])){
|
|
|
|
$_POST['dbpassword']=$CONFIG_DBPASSWORD;
|
|
|
|
}
|
2010-09-05 12:21:07 +00:00
|
|
|
}else{
|
|
|
|
if(!is_dir($_POST['datadirectory'])){
|
|
|
|
try{
|
|
|
|
mkdir($_POST['datadirectory']);
|
|
|
|
}catch(Exception $e){
|
|
|
|
$error.='error while trying to create data directory<br/>';
|
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
if(empty($error)) {
|
2010-05-09 14:33:16 +00:00
|
|
|
if($CONFIG_DBTYPE!=$dbtype or $FIRSTRUN){
|
|
|
|
//create/fill database
|
|
|
|
$CONFIG_DBTYPE=$dbtype;
|
|
|
|
$CONFIG_DBNAME=$_POST['dbname'];
|
2010-06-20 15:58:39 +00:00
|
|
|
if($dbtype!='sqlite'){
|
2010-07-05 13:31:59 +00:00
|
|
|
$CONFIG_DBTABLEPREFIX=$_POST['dbtableprefix'];
|
2010-05-09 14:33:16 +00:00
|
|
|
$CONFIG_DBHOST=$_POST['dbhost'];
|
|
|
|
$CONFIG_DBUSER=$_POST['dbuser'];
|
|
|
|
$CONFIG_DBPASSWORD=$_POST['dbpassword'];
|
2010-07-05 13:31:59 +00:00
|
|
|
}else{
|
|
|
|
$_POST['dbtableprefix']='';
|
2010-07-06 08:37:11 +00:00
|
|
|
$CONFIG_DBTABLEPREFIX='';
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
2010-05-09 14:33:16 +00:00
|
|
|
try{
|
2010-06-20 15:58:39 +00:00
|
|
|
if(isset($_POST['createdatabase']) and $CONFIG_DBTYPE!='sqlite'){
|
2010-05-09 14:33:16 +00:00
|
|
|
self::createdatabase($_POST['dbadminuser'],$_POST['dbadminpwd']);
|
|
|
|
}
|
|
|
|
}catch(Exception $e){
|
|
|
|
$error.='error while trying to create the database<br/>';
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
2010-05-09 14:33:16 +00:00
|
|
|
if($CONFIG_DBTYPE=='sqlite'){
|
|
|
|
$f=@fopen($SERVERROOT.'/'.$CONFIG_DBNAME,'a+');
|
|
|
|
if(!$f){
|
|
|
|
$error.='path of sqlite database not writable by server<br/>';
|
|
|
|
}
|
|
|
|
OC_DB::disconnect();
|
|
|
|
unlink($SERVERROOT.'/'.$CONFIG_DBNAME);
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
2010-05-09 14:33:16 +00:00
|
|
|
try{
|
|
|
|
if(isset($_POST['filldb'])){
|
|
|
|
self::filldatabase();
|
|
|
|
}
|
|
|
|
}catch(Exception $e){
|
|
|
|
$error.='error while trying to fill the database<br/>';
|
|
|
|
}
|
|
|
|
if($CONFIG_DBTYPE=='sqlite'){
|
|
|
|
OC_DB::disconnect();
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-09 14:33:16 +00:00
|
|
|
if($FIRSTRUN){
|
|
|
|
if(!OC_USER::createuser($_POST['adminlogin'],$_POST['adminpassword']) && !OC_USER::login($_POST['adminlogin'],$_POST['adminpassword'])){
|
|
|
|
$error.='error while trying to create the admin user<br/>';
|
|
|
|
}
|
2010-09-20 18:27:43 +00:00
|
|
|
if(OC_USER::getgroupid('admin',true)==0){
|
2010-05-09 14:33:16 +00:00
|
|
|
if(!OC_USER::creategroup('admin')){
|
|
|
|
$error.='error while trying to create the admin group<br/>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!OC_USER::addtogroup($_POST['adminlogin'],'admin')){
|
|
|
|
$error.='error while trying to add the admin user to the admin group<br/>';
|
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
2010-07-11 20:44:48 +00:00
|
|
|
// Build the configuration array
|
|
|
|
$config = array();
|
|
|
|
$config['INSTALLED'] = true;
|
|
|
|
$config['DATADIRECTORY'] = $_POST['datadirectory'];
|
|
|
|
$config['HTTPFORCESSL'] = isset($_POST['forcessl']);
|
|
|
|
// Backup configuration
|
|
|
|
$config['ENABLEBACKUP'] = isset($_POST['enablebackup']);
|
|
|
|
if ( $config['ENABLEBACKUP'] AND (1 == $_POST['enablebackup']) )
|
|
|
|
$config['BACKUPDIRECTORY'] = $_POST['backupdirectory'];
|
|
|
|
$config['DATEFORMAT'] = $_POST['dateformat'];
|
|
|
|
// DB Configuration
|
|
|
|
$config['DBTYPE'] = $dbtype;
|
|
|
|
$config['DBNAME'] = $_POST['dbname'];
|
|
|
|
$config['DBTABLEPREFIX'] = $_POST['dbtableprefix'];
|
|
|
|
if ( 'sqlite' != $dbtype ) {
|
|
|
|
$config['DBHOST'] = $_POST['dbhost'];
|
|
|
|
$config['DBUSER'] = $_POST['dbuser'];
|
|
|
|
$config['DBPASSWORD'] = $_POST['dbpassword'];
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
|
2010-07-11 20:44:48 +00:00
|
|
|
if( empty($error) ) {
|
|
|
|
header("Location: $WEBROOT/");
|
|
|
|
try {
|
|
|
|
// Write the configuration array to `/config/config.php`
|
2010-07-12 11:24:02 +00:00
|
|
|
self::saveConfiguration($config);
|
2010-07-11 20:44:48 +00:00
|
|
|
} catch ( Exception $e ) {
|
2010-04-22 22:05:04 +00:00
|
|
|
$error.='error while trying to save the configuration file<br/>';
|
|
|
|
return $error;
|
|
|
|
}
|
2010-07-11 20:44:48 +00:00
|
|
|
} else {
|
2010-04-22 22:05:04 +00:00
|
|
|
return $error;
|
|
|
|
}
|
2010-04-19 17:46:42 +00:00
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
return($error);
|
|
|
|
}
|
2010-04-19 17:46:42 +00:00
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
2010-06-18 18:08:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills the database with the initial tables
|
|
|
|
* Note: while the AUTO_INCREMENT function is not supported by SQLite
|
|
|
|
* the same effect can be achieved by accessing the SQLite pseudo-column
|
|
|
|
* "rowid"
|
|
|
|
*/
|
2010-07-10 17:41:30 +00:00
|
|
|
private static function fillDatabase(){
|
2010-06-18 18:08:24 +00:00
|
|
|
global $SERVERROOT;
|
|
|
|
OC_DB::createDBFromStructure($SERVERROOT.'/db_structure.xml');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the database and user
|
|
|
|
* @param string adminUser
|
|
|
|
* @param string adminPwd
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 17:41:30 +00:00
|
|
|
private static function createDatabase($adminUser,$adminPwd){
|
2010-06-18 18:08:24 +00:00
|
|
|
global $CONFIG_DBHOST;
|
|
|
|
global $CONFIG_DBNAME;
|
|
|
|
global $CONFIG_DBUSER;
|
|
|
|
global $CONFIG_DBPWD;
|
2010-06-20 15:58:39 +00:00
|
|
|
global $CONFIG_DBTYPE;
|
2010-06-18 18:08:24 +00:00
|
|
|
//we cant user OC_BD functions here because we need to connect as the administrative user.
|
2010-06-20 15:58:39 +00:00
|
|
|
if($CONFIG_DBTYPE=='mysql'){
|
2010-09-20 16:28:39 +00:00
|
|
|
$connection=mysql_connect($CONFIG_DBHOST, $adminUser, $adminPwd);
|
|
|
|
if(!$connection) {
|
2010-06-20 15:58:39 +00:00
|
|
|
@ob_end_clean();
|
|
|
|
echo('<html><head></head><body bgcolor="#F0F0F0"><br /><br /><center><b>can not connect to database as administrative user.</center></body></html>');
|
|
|
|
exit();
|
|
|
|
}
|
2010-09-20 16:28:39 +00:00
|
|
|
$query="SELECT user FROM mysql.user WHERE user='{$_POST['dbuser']}'";
|
|
|
|
$result = mysql_query($query,$connection);
|
2010-06-20 15:58:39 +00:00
|
|
|
if (!$result) {
|
2010-09-20 16:28:39 +00:00
|
|
|
$entry='DB Error: "'.mysql_error($connection).'"<br />';
|
2010-06-20 15:58:39 +00:00
|
|
|
$entry.='Offending command was: '.$query.'<br />';
|
|
|
|
echo($entry);
|
|
|
|
}
|
2010-09-20 16:28:39 +00:00
|
|
|
if(mysql_num_rows($result)==0){
|
|
|
|
$pwd=$_POST['dbpassword'];
|
|
|
|
//we need to create 2 accounts, one for global use and one for local user. if we don't speccify the local one,
|
|
|
|
// the anonymous user would take precedence when there is one.
|
|
|
|
$query="CREATE USER '{$_POST['dbuser']}'@'localhost' IDENTIFIED BY '$pwd'";
|
|
|
|
$result = mysql_query($query,$connection);
|
|
|
|
if (!$result) {
|
|
|
|
$entry='DB Error: "'.mysql_error($connection).'"<br />';
|
|
|
|
$entry.='Offending command was: '.$query.'<br />';
|
|
|
|
echo($entry);
|
|
|
|
}
|
|
|
|
$query="CREATE USER '{$_POST['dbuser']}'@'%' IDENTIFIED BY '$pwd'";
|
|
|
|
$result = mysql_query($query,$connection);
|
|
|
|
if (!$result) {
|
|
|
|
$entry='DB Error: "'.mysql_error($connection).'"<br />';
|
|
|
|
$entry.='Offending command was: '.$query.'<br />';
|
|
|
|
echo($entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$query="CREATE DATABASE IF NOT EXISTS `{$_POST['dbname']}`";
|
|
|
|
$result = mysql_query($query,$connection);
|
|
|
|
if (!$result) {
|
|
|
|
$entry='DB Error: "'.mysql_error($connection).'"<br />';
|
|
|
|
$entry.='Offending command was: '.$query.'<br />';
|
|
|
|
echo($entry);
|
2010-06-20 15:58:39 +00:00
|
|
|
}
|
2010-09-20 16:28:39 +00:00
|
|
|
$query="GRANT ALL PRIVILEGES ON `{$_POST['dbname']}` . * TO '{$_POST['dbuser']}'";
|
|
|
|
$result = mysql_query($query,$connection);
|
2010-06-20 15:58:39 +00:00
|
|
|
if (!$result) {
|
2010-09-20 16:28:39 +00:00
|
|
|
$entry='DB Error: "'.mysql_error($connection).'"<br />';
|
2010-06-20 15:58:39 +00:00
|
|
|
$entry.='Offending command was: '.$query.'<br />';
|
|
|
|
echo($entry);
|
|
|
|
}
|
2010-09-20 16:28:39 +00:00
|
|
|
mysql_close($connection);
|
2010-06-20 15:58:39 +00:00
|
|
|
}elseif($CONFIG_DBTYPE=='pgsql'){
|
|
|
|
$connection = pg_connect("user='$adminUser' host='$CONFIG_DBHOST' password='$adminPwd'");
|
|
|
|
$query="CREATE USER {$_POST['dbuser']} WITH PASSWORD '{$_POST['dbpassword']}' CREATEDB;";
|
|
|
|
$result = pg_exec($connection, $query);
|
|
|
|
$query="select count(*) from pg_catalog.pg_database where datname = '{$_POST['dbname']}';";
|
|
|
|
$result = pg_exec($connection, $query);
|
|
|
|
if(pg_result($result,0,0)==0){
|
|
|
|
$query="CREATE DATABASE {$_POST['dbname']};";
|
|
|
|
$result = pg_exec($connection, $query);
|
|
|
|
$query="ALTER DATABASE {$_POST['dbname']} OWNER TO {$_POST['dbuser']};";
|
|
|
|
$result = pg_exec($connection, $query);
|
|
|
|
}
|
2010-06-18 18:08:24 +00:00
|
|
|
}
|
2010-04-08 12:49:48 +00:00
|
|
|
}
|
2010-03-16 19:25:05 +00:00
|
|
|
}
|
2010-03-24 07:31:30 +00:00
|
|
|
?>
|
2010-04-19 17:46:42 +00:00
|
|
|
|
|
|
|
|