From 78a1792c0488ed31da5577664924694bf1fb4e40 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Mon, 29 Mar 2010 16:13:26 +0200 Subject: [PATCH] move to sqlite merged --- docs/INSTALL | 28 ++---- docs/TODO | 5 -- docs/owncloud.sql | 60 +++++-------- inc/HTTP/WebDAV/Server/Filesystem.php | 74 ++++------------ inc/lib_base.php | 52 +++++------ inc/lib_config.php | 123 +++++++------------------- inc/templates/configform.php | 25 ++---- webdav/owncloud.php | 3 - 8 files changed, 105 insertions(+), 265 deletions(-) mode change 100644 => 100755 inc/lib_config.php diff --git a/docs/INSTALL b/docs/INSTALL index 6a31bc57f0..f8509f363a 100755 --- a/docs/INSTALL +++ b/docs/INSTALL @@ -1,34 +1,18 @@ == PREREQUISITS == php5 -currently mysql, should optionally be sqlite +sqlite == SETUP == -Set up your paths in: -config/config.php - -Your data will be in: -$CONFIG_DATADIRECTORY = '/www/testy'; -Apache needs to have write permissions to this directory. - -And the ownCloud path is: -$CONFIG_DOCUMENTROOT = '/www/owncloud/htdocs'; -The ownCloud checkout should be in the root of "htdocs". - -Both are absolute paths, so if your server is in /var/www, you need to add the /var +Place owncloud in a subdirectory of your web server. Go to that directory with +a web browser and the first run wizard should take it from there. == Database == -The database should by default be sqlite. No configuration there. +The database is sqlite. If you are having trouble make sure that the line -But until then you need some setup with mysql: +extension=sqlite.so -Create a table "owncloud": -mysqladmin create owncloud -u root -p - -Dump the default database schema: -mysql owncloud -u root -p < owncloud.sql - -TODO: you also need to create a mysql user that is configured in config/config.php +appears in your php.ini Please help improving this documentation! diff --git a/docs/TODO b/docs/TODO index b04bd735c8..aba8f8345a 100755 --- a/docs/TODO +++ b/docs/TODO @@ -1,8 +1,3 @@ - -- remove dependency on mysql. replace with sqlite to make it easier to install - -- simplify installation - - write installation documentation - better ajax web gui diff --git a/docs/owncloud.sql b/docs/owncloud.sql index f7b6b010e0..5ef008b62f 100755 --- a/docs/owncloud.sql +++ b/docs/owncloud.sql @@ -1,39 +1,27 @@ +CREATE TABLE 'locks' ( + 'token' VARCHAR(255) NOT NULL DEFAULT '', + 'path' varchar(200) NOT NULL DEFAULT '', + 'expires' int(11) NOT NULL DEFAULT '0', + 'owner' varchar(200) DEFAULT NULL, + 'recursive' int(11) DEFAULT '0', + 'writelock' int(11) DEFAULT '0', + 'exclusivelock' int(11) NOT NULL DEFAULT '0', + PRIMARY KEY ('token'), + UNIQUE ('token') + ); -SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; - -CREATE TABLE IF NOT EXISTS `locks` ( - `token` varchar(255) NOT NULL DEFAULT '', - `path` varchar(200) NOT NULL DEFAULT '', - `expires` int(11) NOT NULL DEFAULT '0', - `owner` varchar(200) DEFAULT NULL, - `recursive` int(11) DEFAULT '0', - `writelock` int(11) DEFAULT '0', - `exclusivelock` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`token`), - UNIQUE KEY `token` (`token`), - KEY `path` (`path`), - KEY `path_2` (`path`), - KEY `path_3` (`path`,`token`), - KEY `expires` (`expires`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -CREATE TABLE IF NOT EXISTS `log` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `timestamp` int(11) NOT NULL, - `user` varchar(250) NOT NULL, - `type` int(11) NOT NULL, - `message` varchar(250) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ; - - -CREATE TABLE IF NOT EXISTS `properties` ( - `path` varchar(255) NOT NULL DEFAULT '', - `name` varchar(120) NOT NULL DEFAULT '', - `ns` varchar(120) NOT NULL DEFAULT 'DAV:', - `value` text, - PRIMARY KEY (`path`,`name`,`ns`), - KEY `path` (`path`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +CREATE TABLE 'log' ( + 'timestamp' int(11) NOT NULL, + 'user' varchar(250) NOT NULL, + 'type' int(11) NOT NULL, + 'message' varchar(250) NOT NULL +); +CREATE TABLE 'properties' ( + 'path' varchar(255) NOT NULL DEFAULT '', + 'name' varchar(120) NOT NULL DEFAULT '', + 'ns' varchar(120) NOT NULL DEFAULT 'DAV:', + 'value' text, + PRIMARY KEY ('path','name','ns') +); diff --git a/inc/HTTP/WebDAV/Server/Filesystem.php b/inc/HTTP/WebDAV/Server/Filesystem.php index eeec0af41b..81dd64983f 100755 --- a/inc/HTTP/WebDAV/Server/Filesystem.php +++ b/inc/HTTP/WebDAV/Server/Filesystem.php @@ -1,5 +1,6 @@ base = $_SERVER['DOCUMENT_ROOT']; } - // establish connection to property/locking db - mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error()); - mysql_select_db($this->db_name) or die(mysql_error()); - // TODO throw on connection problems - // let the base class do all the work parent::ServeRequest(); } @@ -192,11 +156,11 @@ // get additional properties from database $query = "SELECT ns, name, value FROM properties WHERE path = '$path'"; - $res = mysql_query($query); - while ($row = mysql_fetch_assoc($res)) { + $res = OC_DB::query($query); + while ($row = OC_DB::fetch_assoc($res)) { $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); } - mysql_free_result($res); + OC_DB::free_result($res); return $info; } @@ -478,13 +442,13 @@ if (is_dir($path)) { $query = "DELETE FROM properties WHERE path LIKE '".$this->_slashify($options["path"])."%'"; - mysql_query($query); + OC_DB::query($query); System::rm("-rf $path"); } else { unlink ($path); } $query = "DELETE FROM properties WHERE path = '$options[path]'"; - mysql_query($query); + OC_DB::query($query); return "204 No Content"; } @@ -568,13 +532,13 @@ $query = "UPDATE properties SET path = REPLACE(path, '".$options["path"]."', '".$destpath."') WHERE path LIKE '".$this->_slashify($options["path"])."%'"; - mysql_query($query); + OC_DB::query($query); } $query = "UPDATE properties SET path = '".$destpath."' WHERE path = '".$options["path"]."'"; - mysql_query($query); + OC_DB::query($query); } else { if (is_dir($source)) { $files = System::find($source); @@ -644,7 +608,7 @@ } else { $query = "DELETE FROM properties WHERE path = '$options[path]' AND name = '$prop[name]' AND ns = '$prop[ns]'"; } - mysql_query($query); + OC_DB::query($query); } } @@ -662,9 +626,9 @@ { if (isset($options["update"])) { // Lock Update $query = "UPDATE locks SET expires = ".(time()+300); - mysql_query($query); + OC_DB::query($query); - if (mysql_affected_rows()) { + if (OC_DB::affected_rows()) { $options["timeout"] = 300; // 5min hardcoded return true; } else { @@ -681,9 +645,9 @@ , expires = '$options[timeout]' , exclusivelock = " .($options['scope'] === "exclusive" ? "1" : "0") ; - mysql_query($query); + OC_DB::query($query); - return mysql_affected_rows() ? "200 OK" : "409 Conflict"; + return OC_DB::affected_rows() ? "200 OK" : "409 Conflict"; } /** @@ -697,9 +661,9 @@ $query = "DELETE FROM locks WHERE path = '$options[path]' AND token = '$options[token]'"; - mysql_query($query); + OC_DB::query($query); - return mysql_affected_rows() ? "204 No Content" : "409 Conflict"; + return OC_DB::affected_rows() ? "204 No Content" : "409 Conflict"; } /** @@ -716,11 +680,11 @@ FROM locks WHERE path = '$path' "; - $res = mysql_query($query); + $res = OC_DB::query($query); if ($res) { - $row = mysql_fetch_array($res); - mysql_free_result($res); + $row = OC_DB::fetch_assoc($res); + OC_DB::free_result($res); if ($row) { $result = array( "type" => "write", diff --git a/inc/lib_base.php b/inc/lib_base.php index f30c85d7ae..96ba05b581 100755 --- a/inc/lib_base.php +++ b/inc/lib_base.php @@ -45,10 +45,7 @@ $CONFIG_ADMINPASSWORD=''; $CONFIG_DATADIRECTORY=$SERVERROOT.$WEBROOT.'/data'; $CONFIG_HTTPFORCESSL=false; $CONFIG_DATEFORMAT='j M Y G:i'; -$CONFIG_DBHOST='localhost'; $CONFIG_DBNAME='owncloud'; -$CONFIG_DBUSER=''; -$CONFIG_DBPASSWORD=''; // include the generated configfile @include_once('config.php'); @@ -111,9 +108,9 @@ class OC_USER { * */ public static function logoutlisener(){ - if(isset($_GET['logoutbutton'])){ + if(isset($_GET['logoutbutton']) && isset($_SESSION['username'])){ OC_LOG::event($_SESSION['username'],2,''); - if(isset($_SESSION['username'])) unset($_SESSION['username']); + unset($_SESSION['username']); } } @@ -238,14 +235,12 @@ class OC_DB { * @return result-set */ static function query($cmd) { + global $DOCUMENTROOT; global $DBConnection; - global $CONFIG_DBHOST; global $CONFIG_DBNAME; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; if(!isset($DBConnection)) { - $DBConnection = @new mysqli($CONFIG_DBHOST, $CONFIG_DBUSER, $CONFIG_DBPASSWORD,$CONFIG_DBNAME); - if (mysqli_connect_errno()) { + $DBConnection = @new SQLiteDatabase($DOCUMENTROOT.'/'.$CONFIG_DBNAME); + if (!$DBConnection) { @ob_end_clean(); echo('can not connect to database.'); exit(); @@ -253,12 +248,12 @@ class OC_DB { } $result = @$DBConnection->query($cmd); if (!$result) { - $entry='DB Error: "'.$DBConnection->error.'"
'; + $entry='DB Error: "'.sqlite_error_string($DBConnection->lastError()).'"
'; $entry.='Offending command was: '.$cmd.'
'; echo($entry); } return $result; - } + } /** * executes multiply queries on the database @@ -267,22 +262,20 @@ class OC_DB { * @return result-set */ static function multiquery($cmd) { + global $DOCUMENTROOT; global $DBConnection; - global $CONFIG_DBHOST; global $CONFIG_DBNAME; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; if(!isset($DBConnection)) { - $DBConnection = @new mysqli($CONFIG_DBHOST, $CONFIG_DBUSER, $CONFIG_DBPASSWORD,$CONFIG_DBNAME); - if (mysqli_connect_errno()) { + $DBConnection = @new SQLiteDatabase($DOCUMENTROOT.'/'.$CONFIG_DBNAME); + if (!$DBConnection) { @ob_end_clean(); echo('can not connect to database.'); exit(); } } - $result = @$DBConnection->multi_query($cmd); + $result = @$DBConnection->queryExec($cmd); if (!$result) { - $entry='DB Error: "'.$DBConnection->error.'"
'; + $entry='DB Error: "'.sqlite_error_string($DBConnection->lastError()).'"
'; $entry.='Offending command was: '.$cmd.'
'; echo($entry); } @@ -312,7 +305,7 @@ class OC_DB { */ static function insertid() { global $DBConnection; - return(mysqli_insert_id($DBConnection)); + return $DBConnectio->lastInsertRowid(); } /** @@ -323,7 +316,7 @@ class OC_DB { */ static function numrows($result) { if(!isset($result) or ($result == false)) return 0; - $num= mysqli_num_rows($result); + $num= $result->numRows(); return($num); } @@ -335,7 +328,7 @@ class OC_DB { static function affected_rows() { global $DBConnection; if(!isset($DBConnection) or ($DBConnection==false)) return 0; - $num= mysqli_affected_rows($DBConnection); + $num= $DBConnection->changes(); return($num); } @@ -348,16 +341,10 @@ class OC_DB { * @return unknown */ static function result($result, $i, $field) { - //return @mysqli_result($result, $i, $field); - - mysqli_data_seek($result,$i); - if (is_string($field)) - $tmp=mysqli_fetch_array($result,MYSQLI_BOTH); - else - $tmp=mysqli_fetch_array($result,MYSQLI_NUM); + $result->seek($ii); + $tmp=$result->fetch(); $tmp=$tmp[$field]; return($tmp); - } /** @@ -367,7 +354,7 @@ class OC_DB { * @return data */ static function fetch_assoc($result) { - return mysqli_fetch_assoc($result); + return $result->fetch(SQLITE_ASSOC); } @@ -378,7 +365,8 @@ class OC_DB { * @return bool */ static function free_result($result) { - return @mysqli_free_result($result); + $result = null; //No native way to do this + return true; } } diff --git a/inc/lib_config.php b/inc/lib_config.php old mode 100644 new mode 100755 index ff0c38f170..8718a603d6 --- a/inc/lib_config.php +++ b/inc/lib_config.php @@ -10,10 +10,7 @@ class OC_CONFIG{ global $CONFIG_DATADIRECTORY; global $CONFIG_HTTPFORCESSL; global $CONFIG_DATEFORMAT; - global $CONFIG_DBHOST; global $CONFIG_DBNAME; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; require('templates/configform.php'); } @@ -24,17 +21,12 @@ class OC_CONFIG{ public static function writeconfiglisener(){ global $DOCUMENTROOT; global $WEBROOT; - global $CONFIG_DBHOST; global $CONFIG_DBNAME; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; - global $CONFIG_ADMINLOGIN; - global $CONFIG_ADMINPASSWORD; if(isset($_POST['set_config'])){ //checkdata $error=''; - $FIRSTRUN=empty($CONFIG_ADMINLOGIN); + $FIRSTRUN=isset($CONFIG_ADMINLOGIN); if(!$FIRSTRUN){ if($_POST['currentpassword']!=$CONFIG_ADMINPASSWORD){ $error.='wrong password'; @@ -46,27 +38,15 @@ class OC_CONFIG{ 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['dbhost']) or empty($_POST['dbhost'])) $error.='database host not set
'; if(!isset($_POST['dbname']) or empty($_POST['dbname'])) $error.='databasename not set
'; - if(!isset($_POST['dbuser']) or empty($_POST['dbuser'])) $error.='database user not set
'; - if(!isset($_POST['dbpassword']) or empty($_POST['dbpassword'])) $error.='database password not set
'; - if(!isset($_POST['dbpassword2']) or empty($_POST['dbpassword2'])) $error.='retype database password not set
'; - if($_POST['dbpassword']<>$_POST['dbpassword2'] ) $error.='database passwords are not the same
'; 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; } - if(empty($error)) { //create/fill database - $CONFIG_DBHOST=$_POST['dbhost']; $CONFIG_DBNAME=$_POST['dbname']; - $CONFIG_DBUSER=$_POST['dbuser']; - $CONFIG_DBPASSWORD=$_POST['dbpassword']; - if(isset($_POST['createdatabase'])){ - self::createdatabase($_POST['dbadminuser'],$_POST['dbadminpwd']); - } if(isset($_POST['filldb'])){ self::filldatabase(); } @@ -78,11 +58,8 @@ 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_DBHOST=\''.$_POST['dbhost']."';\n"; $config.='$CONFIG_DBNAME=\''.$_POST['dbname']."';\n"; - $config.='$CONFIG_DBUSER=\''.$_POST['dbuser']."';\n"; - $config.='$CONFIG_DBPASSWORD=\''.$_POST['dbpassword']."';\n"; - $config.='?>'; + $config.='?> '; $filename=$DOCUMENTROOT.'/config/config.php'; file_put_contents($filename,$config); @@ -96,81 +73,43 @@ class OC_CONFIG{ } - /** - * Create the database and user - * @param string adminUser - * @param string adminPwd - * - */ - private static function createdatabase($adminUser,$adminPwd){ - global $CONFIG_DBHOST; - global $CONFIG_DBNAME; - global $CONFIG_DBUSER; - global $CONFIG_DBPWD; - //we cant user OC_BD functions here because we need to connect as the administrative user. - $connection = @new mysqli($CONFIG_DBHOST, $adminUser, $adminPwd); - if (mysqli_connect_errno()) { - @ob_end_clean(); - echo('

can not connect to database as administrative user.
'); - exit(); - } - $query="CREATE USER '{$_POST['dbuser']}' IDENTIFIED BY '{$_POST['dbpassword']}'; - -CREATE DATABASE IF NOT EXISTS `{$_POST['dbname']}` ; - -GRANT ALL PRIVILEGES ON `{$_POST['dbname']}` . * TO '{$_POST['dbuser']}';"; - $result = @$connection->multi_query($query); - if (!$result) { - $entry='DB Error: "'.$connection->error.'"
'; - $entry.='Offending command was: '.$query.'
'; - echo($entry); - } - $connection->close(); - } - /** * 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" */ private static function filldatabase(){ - $query="SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"; + $query="CREATE TABLE 'locks' ( + 'token' VARCHAR(255) NOT NULL DEFAULT '', + 'path' varchar(200) NOT NULL DEFAULT '', + 'expires' int(11) NOT NULL DEFAULT '0', + 'owner' varchar(200) DEFAULT NULL, + 'recursive' int(11) DEFAULT '0', + 'writelock' int(11) DEFAULT '0', + 'exclusivelock' int(11) NOT NULL DEFAULT '0', + PRIMARY KEY ('token'), + UNIQUE ('token') + ); -CREATE TABLE IF NOT EXISTS `locks` ( - `token` varchar(255) NOT NULL DEFAULT '', - `path` varchar(200) NOT NULL DEFAULT '', - `expires` int(11) NOT NULL DEFAULT '0', - `owner` varchar(200) DEFAULT NULL, - `recursive` int(11) DEFAULT '0', - `writelock` int(11) DEFAULT '0', - `exclusivelock` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`token`), - UNIQUE KEY `token` (`token`), - KEY `path` (`path`), - KEY `path_2` (`path`), - KEY `path_3` (`path`,`token`), - KEY `expires` (`expires`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -CREATE TABLE IF NOT EXISTS `log` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `timestamp` int(11) NOT NULL, - `user` varchar(250) NOT NULL, - `type` int(11) NOT NULL, - `message` varchar(250) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ; +CREATE TABLE 'log' ( + 'timestamp' int(11) NOT NULL, + 'user' varchar(250) NOT NULL, + 'type' int(11) NOT NULL, + 'message' varchar(250) NOT NULL +); -CREATE TABLE IF NOT EXISTS `properties` ( - `path` varchar(255) NOT NULL DEFAULT '', - `name` varchar(120) NOT NULL DEFAULT '', - `ns` varchar(120) NOT NULL DEFAULT 'DAV:', - `value` text, - PRIMARY KEY (`path`,`name`,`ns`), - KEY `path` (`path`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; -"; +CREATE TABLE 'properties' ( + 'path' varchar(255) NOT NULL DEFAULT '', + 'name' varchar(120) NOT NULL DEFAULT '', + 'ns' varchar(120) NOT NULL DEFAULT 'DAV:', + 'value' text, + PRIMARY KEY ('path','name','ns') +);"; OC_DB::multiquery($query); } } ?> + + diff --git a/inc/templates/configform.php b/inc/templates/configform.php index 8a65474b44..5d44d8f279 100755 --- a/inc/templates/configform.php +++ b/inc/templates/configform.php @@ -1,16 +1,9 @@ - -
+ @@ -19,20 +12,12 @@ document.getElementById('dbAdminPwd').style.display=(show)?'table-row':'none'; } ?> - + - - + - - - - - - - - +
admin login:
admin password:(leave empty to keep current password)
admin password:(leave empty to keep current pass
retype admin password:
data directory:
force ssl:
data directory:< +
force ssl:date format:
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:>
automaticly fill initial database:
- diff --git a/webdav/owncloud.php b/webdav/owncloud.php index 33fc5f37c3..6151e6e13f 100755 --- a/webdav/owncloud.php +++ b/webdav/owncloud.php @@ -41,10 +41,7 @@ $passwd=$_SERVER['PHP_AUTH_PW']; if(($user==$CONFIG_ADMINLOGIN) and ($passwd==$CONFIG_ADMINPASSWORD )){ $server = new HTTP_WebDAV_Server_Filesystem(); - $server->db_host = $CONFIG_DBHOST; $server->db_name = $CONFIG_DBNAME; - $server->db_user = $CONFIG_DBUSER; - $server->db_passwd = $CONFIG_DBPASSWORD; $server->ServeRequest($CONFIG_DATADIRECTORY); }else{