diff --git a/inc/lib_base.php b/inc/lib_base.php index d7189d9c5b4..5d02cfeaa97 100755 --- a/inc/lib_base.php +++ b/inc/lib_base.php @@ -46,6 +46,7 @@ $CONFIG_DATADIRECTORY=$SERVERROOT.$WEBROOT.'/data'; $CONFIG_HTTPFORCESSL=false; $CONFIG_DATEFORMAT='j M Y G:i'; $CONFIG_DBNAME='owncloud'; +$CONFIG_DBTYPE='sqlite'; // include the generated configfile @include_once('config.php'); @@ -245,20 +246,34 @@ class OC_DB { * @return result-set */ static function query($cmd) { - global $DOCUMENTROOT; + global $DOCUMENTROOT; global $DBConnection; global $CONFIG_DBNAME; + global $CONFIG_DBHOST; + global $CONFIG_DBUSER; + global $CONFIG_DBPASSWORD; + global $CONFIG_DBTYPE; if(!isset($DBConnection)) { - $DBConnection = @new SQLiteDatabase($DOCUMENTROOT.'/'.$CONFIG_DBNAME); + if($CONFIG_DBTYPE=='sqlite'){ + $DBConnection = @new SQLiteDatabase($DOCUMENTROOT.'/'.$CONFIG_DBNAME); + }elseif($CONFIG_DBTYPE=='mysql'){ + $DBConnection = @new mysqli($CONFIG_DBHOST, $CONFIG_DBUSER, $CONFIG_DBPASSWORD,$CONFIG_DBNAME); + } if (!$DBConnection) { @ob_end_clean(); - echo('can not connect to database.'); + echo('can not connect to database, using '.$CONFIG_DBTYPE.'.'); exit(); } } $result = @$DBConnection->query($cmd); if (!$result) { - $entry='DB Error: "'.sqlite_error_string($DBConnection->lastError()).'"
'; + if($CONFIG_DBTYPE=='sqlite'){ + $error=sqlite_error_string($DBConnection->lastError()); + }elseif($CONFIG_DBTYPE=='mysql'){ + print_r($DBConnection); + $error=$DBConnection->error; + } + $entry='DB Error: "'.$error.'"
'; $entry.='Offending command was: '.$cmd.'
'; echo($entry); } @@ -275,17 +290,31 @@ class OC_DB { global $DOCUMENTROOT; global $DBConnection; global $CONFIG_DBNAME; + global $CONFIG_DBTYPE; if(!isset($DBConnection)) { - $DBConnection = @new SQLiteDatabase($DOCUMENTROOT.'/'.$CONFIG_DBNAME); + if($CONFIG_DBTYPE=='sqlite'){ + $DBConnection = @new SQLiteDatabase($DOCUMENTROOT.'/'.$CONFIG_DBNAME); + }elseif($CONFIG_DBTYPE=='mysql'){ + $DBConnection = @new mysqli($CONFIG_DBHOST, $CONFIG_DBUSER, $CONFIG_DBPASSWORD,$CONFIG_DBNAME); + } if (!$DBConnection) { @ob_end_clean(); - echo('can not connect to database.'); + echo('can not connect to database, using '.$CONFIG_DBTYPE.'.'); exit(); } } - $result = @$DBConnection->queryExec($cmd); + if($CONFIG_DBTYPE=='sqlite'){ + $result = @$DBConnection->queryExec($cmd); + }elseif($CONFIG_DBTYPE=='mysql'){ + $result = @$DBConnection->multi_query($cmd); + } if (!$result) { - $entry='DB Error: "'.sqlite_error_string($DBConnection->lastError()).'"
'; + if($CONFIG_DBTYPE=='sqlite'){ + $error=sqlite_error_string($DBConnection->lastError()); + }elseif($CONFIG_DBTYPE=='mysql'){ + $error=$DBConnection->error; + } + $entry='DB Error: "'.$error.'"
'; $entry.='Offending command was: '.$cmd.'
'; echo($entry); } @@ -299,6 +328,7 @@ class OC_DB { * @return bool */ static function close() { + global $CONFIG_DBTYPE; global $DBConnection; if(isset($DBConnection)) { return $DBConnection->close(); @@ -315,7 +345,12 @@ class OC_DB { */ static function insertid() { global $DBConnection; - return $DBConnectio->lastInsertRowid(); + global $CONFIG_DBTYPE; + if($CONFIG_DBTYPE=='sqlite'){ + return $DBConnection->lastInsertRowid(); + }elseif($CONFIG_DBTYPE=='mysql'){ + return(mysqli_insert_id($DBConnection)); + } } /** @@ -326,7 +361,12 @@ class OC_DB { */ static function numrows($result) { if(!isset($result) or ($result == false)) return 0; - $num= $result->numRows(); + global $CONFIG_DBTYPE; + if($CONFIG_DBTYPE=='sqlite'){ + $num= $result->numRows(); + }elseif($CONFIG_DBTYPE=='mysql'){ + $num= mysqli_num_rows($result); + } return($num); } @@ -337,8 +377,13 @@ class OC_DB { */ static function affected_rows() { global $DBConnection; + global $CONFIG_DBTYPE; if(!isset($DBConnection) or ($DBConnection==false)) return 0; - $num= $DBConnection->changes(); + if($CONFIG_DBTYPE=='sqlite'){ + $num= $DBConnection->changes(); + }elseif($CONFIG_DBTYPE=='mysql'){ + $num= mysqli_affected_rows($DBConnection); + } return($num); } @@ -351,10 +396,20 @@ class OC_DB { * @return unknown */ static function result($result, $i, $field) { - $result->seek($ii); - $tmp=$result->fetch(); + global $CONFIG_DBTYPE; + if($CONFIG_DBTYPE=='sqlite'){ + $result->seek($i); + $tmp=$result->fetch(); + }elseif($CONFIG_DBTYPE=='mysql'){ + mysqli_data_seek($result,$i); + if (is_string($field)) + $tmp=mysqli_fetch_array($result,MYSQLI_BOTH); + else + $tmp=mysqli_fetch_array($result,MYSQLI_NUM); + } $tmp=$tmp[$field]; return($tmp); + return($tmp); } /** @@ -364,7 +419,12 @@ class OC_DB { * @return data */ static function fetch_assoc($result) { - return $result->fetch(SQLITE_ASSOC); + global $CONFIG_DBTYPE; + if($CONFIG_DBTYPE=='sqlite'){ + return $result->fetch(SQLITE_ASSOC); + }elseif($CONFIG_DBTYPE=='mysql'){ + return mysqli_fetch_assoc($result); + } } @@ -375,8 +435,13 @@ class OC_DB { * @return bool */ static function free_result($result) { - $result = null; //No native way to do this - return true; + global $CONFIG_DBTYPE; + if($CONFIG_DBTYPE=='sqlite'){ + $result = null; //No native way to do this + return true; + }elseif($CONFIG_DBTYPE=='mysql'){ + return @mysqli_free_result($result); + } } } diff --git a/inc/lib_config.php b/inc/lib_config.php index 8718a603d61..b54a4f4f168 100755 --- a/inc/lib_config.php +++ b/inc/lib_config.php @@ -20,6 +20,7 @@ class OC_CONFIG{ */ public static function writeconfiglisener(){ global $DOCUMENTROOT; + global $SERVERROOT; global $WEBROOT; global $CONFIG_DBNAME; if(isset($_POST['set_config'])){ @@ -37,18 +38,25 @@ class OC_CONFIG{ if(!isset($_POST['adminpassword']) or empty($_POST['adminpassword']) and $FIRSTRUN) $error.='admin password not set
'; if(!isset($_POST['adminpassword2']) or empty($_POST['adminpassword2']) and $FIRSTRUN) $error.='retype admin password not set
'; if(!isset($_POST['datadirectory']) or empty($_POST['datadirectory'])) $error.='data directory not set
'; - if(!isset($_POST['dateformat']) or empty($_POST['dateformat'])) $error.='dteformat not set
'; + if(!isset($_POST['dateformat']) or empty($_POST['dateformat'])) $error.='dateformat not set
'; if(!isset($_POST['dbname']) or empty($_POST['dbname'])) $error.='databasename not set
'; if($_POST['adminpassword']<>$_POST['adminpassword2'] ) $error.='admin passwords are not the same
'; if(!isset($_POST['adminpassword']) or empty($_POST['adminpassword']) and !$FIRSTRUN){ $_POST['adminpassword']=$CONFIG_ADMINPASSWORD; } + $dbtype=$_POST['dbtype']; + if($dbtype=='mysql'){ + if(!isset($_POST['dbhost']) or empty($_POST['dbhost'])) $error.='database host not set
'; + if(!isset($_POST['dbuser']) or empty($_POST['dbuser'])) $error.='database user not set
'; + if($_POST['dbpassword']<>$_POST['dbpassword2'] ) $error.='database passwords are not the same
'; + + } if(empty($error)) { //create/fill database $CONFIG_DBNAME=$_POST['dbname']; if(isset($_POST['filldb'])){ - self::filldatabase(); +// self::filldatabase(); } //storedata @@ -58,13 +66,19 @@ class OC_CONFIG{ $config.='$CONFIG_DATADIRECTORY=\''.$_POST['datadirectory']."';\n"; if(isset($_POST['forcessl'])) $config.='$CONFIG_HTTPFORCESSL=true'.";\n"; else $config.='$CONFIG_HTTPFORCESSL=false'.";\n"; $config.='$CONFIG_DATEFORMAT=\''.$_POST['dateformat']."';\n"; + $config.='$CONFIG_DBTYPE=\''.$dbtype."';\n"; $config.='$CONFIG_DBNAME=\''.$_POST['dbname']."';\n"; + if($dbtype=='mysql'){ + $config.='$CONFIG_DBHOST=\''.$_POST['dbhost']."';\n"; + $config.='$CONFIG_DBUSER=\''.$_POST['dbuser']."';\n"; + $config.='$CONFIG_DBPASSWORD=\''.$_POST['dbpassword']."';\n"; + } $config.='?> '; - $filename=$DOCUMENTROOT.'/config/config.php'; + $filename=$SERVERROOT.'/config/config.php'; file_put_contents($filename,$config); - header("Location: ".$WEBROOT."/"); + header("Location: ".$WEBROOT."/"); } return($error); diff --git a/inc/templates/configform.php b/inc/templates/configform.php index 9b3cee53f1f..82a1efeee19 100755 --- a/inc/templates/configform.php +++ b/inc/templates/configform.php @@ -1,8 +1,49 @@ + +
+ + + +
current password
+ + + + + + + +
data directory:
force ssl:
date format:
database type: + +
database host:
database name:
database user:
database password:
retype database password:
create database and user: onchange='showDBAdmin()'>
database administrative user:
database administrative password:
automaticly fill initial database:>
+ \ No newline at end of file diff --git a/webdav/owncloud.php b/webdav/owncloud.php index 6151e6e13f7..6699526be28 100755 --- a/webdav/owncloud.php +++ b/webdav/owncloud.php @@ -28,7 +28,7 @@ require_once('HTTP/WebDAV/Server/Filesystem.php'); ini_set('default_charset', 'UTF-8'); #ini_set('error_reporting', ''); - +ob_clean(); if(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['REDIRECT_REMOTE_USER'])) { header('WWW-Authenticate: Basic realm="ownCloud"');