summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMichael Gapczynski <GapczynskiM@gmail.com>2011-08-07 15:56:26 -0400
committerMichael Gapczynski <GapczynskiM@gmail.com>2011-08-07 15:56:26 -0400
commit1aa89b7cbb051875ffa577a6a89e9cf9bb6eafee (patch)
treeb4923b27fc550d37eeb609db02ef6d20a508ab30 /lib
parent5d521d7c7c8f8e796a3ddc81e1e4430238ba5451 (diff)
parent3e8ae8636cad91877c727c7b1ea77436816e7c3d (diff)
downloadnextcloud-server-1aa89b7cbb051875ffa577a6a89e9cf9bb6eafee.tar.gz
nextcloud-server-1aa89b7cbb051875ffa577a6a89e9cf9bb6eafee.zip
Merge branch 'master' into sharing
Conflicts: files/css/files.css lib/base.php
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php80
-rw-r--r--lib/connector/sabre/principal.php181
-rwxr-xr-xlib/crypt.php62
-rw-r--r--lib/db.php39
-rwxr-xr-xlib/helper.php2
-rw-r--r--lib/log.php4
-rw-r--r--lib/ocs.php2
-rw-r--r--lib/search/provider/file.php9
-rw-r--r--lib/setup.php102
-rw-r--r--lib/template.php33
-rw-r--r--lib/util.php16
11 files changed, 505 insertions, 25 deletions
diff --git a/lib/base.php b/lib/base.php
index b2cbde5679c..51dee60d672 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -20,13 +20,56 @@
*
*/
-// Get rid of this stupid require_once OC_...
-function OC_autoload($className) {
- if(strpos($className,'OC_')===0) {
- require_once strtolower(str_replace('_','/',substr($className,3)) . '.php');
+/**
+ * Class that is a namespace for all global OC variables
+ * No, we can not put this class in its own file because it is used by
+ * OC_autoload!
+ */
+class OC{
+ /**
+ * Assoziative array for autoloading. classname => filename
+ */
+ public static $CLASSPATH = array();
+ /**
+ * $_SERVER['DOCUMENTROOT'] but without symlinks
+ */
+ public static $DOCUMENTROOT = '';
+ /**
+ * The installation path for owncloud on the server (e.g. /srv/http/owncloud)
+ */
+ public static $SERVERROOT = '';
+ /**
+ * the current request path relative to the owncloud root (e.g. files/index.php)
+ */
+ public static $SUBURI = '';
+ /**
+ * the owncloud root path for http requests (e.g. owncloud/)
+ */
+ public static $WEBROOT = '';
+ /**
+ * the folder that stores that data files for the filesystem of the user (e.g. /srv/http/owncloud/data/myusername/files)
+ */
+ public static $CONFIG_DATADIRECTORY = '';
+ /**
+ * the folder that stores the data for the root filesystem (e.g. /srv/http/owncloud/data)
+ */
+ public static $CONFIG_DATADIRECTORY_ROOT = '';
+
+ /**
+ * SPL autoload
+ */
+ public static function autoload($className){
+ if(array_key_exists($className,OC::$CLASSPATH)){
+ require_once OC::$CLASSPATH[$className];
+ }
+ elseif(strpos($className,'OC_')===0){
+ require_once strtolower(str_replace('_','/',substr($className,3)) . '.php');
+ }
}
}
-spl_autoload_register('OC_autoload');
+
+// this requires all our OC_* classes
+spl_autoload_register(array('OC','autoload'));
// set some stuff
//ob_start();
@@ -38,9 +81,8 @@ ini_set('session.cookie_httponly','1;');
session_start();
// calculate the documentroot
-$SERVERROOT=substr(__FILE__,0,-13);
$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
-$SERVERROOT=str_replace("\\",'/',$SERVERROOT);
+$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13));
$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT));
$scriptName=$_SERVER["SCRIPT_NAME"];
if(substr($scriptName,-1)=='/'){
@@ -55,7 +97,10 @@ if($WEBROOT!='' and $WEBROOT[0]!=='/'){
}
// set the right include path
-set_include_path($SERVERROOT.'/lib'.PATH_SEPARATOR.$SERVERROOT.'/config'.PATH_SEPARATOR.$SERVERROOT.'/3dparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.$SERVERROOT);
+set_include_path($SERVERROOT.'/lib'.PATH_SEPARATOR.$SERVERROOT.'/config'.PATH_SEPARATOR.$SERVERROOT.'/3rdparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.$SERVERROOT);
+
+//Some libs we really depend on
+require_once('Sabre/autoload.php');
// define runtime variables - unless this already has been done
if( !isset( $RUNTIME_NOSETUPFS )){
@@ -80,7 +125,9 @@ if( OC_Config::getValue( "forcessl", false )){
}
}
-$error=(count(OC_Util::checkServer())>0);
+$errors=OC_Util::checkServer();
+$error=(count($errors)>0);
+
// User and Groups
if( !OC_Config::getValue( "installed", false )){
@@ -113,6 +160,21 @@ if(!$error and !$RUNTIME_NOSETUPFS ){
OC_Util::setupFS();
}
+// Last part: connect some hooks
+OC_HOOK::connect('OC_User', 'post_createUser', 'OC_Connector_Sabre_Principal', 'addPrincipal');
+OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Connector_Sabre_Principal', 'deletePrincipal');
+
+
+
+if($error) {
+ $tmpl = new OC_Template( '', 'error', 'guest' );
+ $tmpl->assign('errors',$errors);
+ $tmpl->printPage();
+ exit;
+}
+
+
+
// FROM Connect.php
function OC_CONNECT_TEST($path,$user,$password){
diff --git a/lib/connector/sabre/principal.php b/lib/connector/sabre/principal.php
new file mode 100644
index 00000000000..9c386f85e15
--- /dev/null
+++ b/lib/connector/sabre/principal.php
@@ -0,0 +1,181 @@
+<?php
+
+class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
+ /**
+ * TODO: write doc
+ */
+ public static function addPrincipal($params){
+ // Add the user
+ $uri = 'principals/'.$params['uid'];
+ $displayname = $params['uid'];
+ $query = OC_DB::prepare('INSERT INTO *PREFIX*principals (uri,displayname) VALUES(?,?)');
+ $query->execute(array($uri,$displayname));
+
+ // Add calendar and addressbook read and write support (sharing calendars)
+ $uri = 'principals/'.$params['uid'].'/calendar-proxy-read';
+ $displayname = null;
+ $query->execute(array($uri,$displayname));
+ $uri = 'principals/'.$params['uid'].'/calendar-proxy-write';
+ $query->execute(array($uri,$displayname));
+ $uri = 'principals/'.$params['uid'].'/addressbook-proxy-read';
+ $query->execute(array($uri,$displayname));
+ $uri = 'principals/'.$params['uid'].'/addressbook-proxy-write';
+ $query->execute(array($uri,$displayname));
+
+ return true;
+ }
+
+ /**
+ * TODO: write doc
+ */
+ public static function deletePrincipal($params){
+ $query = OC_DB::prepare('SELECT * FROM *PREFIX*principals');
+ $result = $query->execute();
+
+ $deleteprincipal = OC_DB::prepare('DELETE FROM *PREFIX*principals WHERE id = ?');
+ $deletegroup = OC_DB::prepare('DELETE FROM *PREFIX*principalgroups WHERE principal_id = ? OR member_id = ?');
+ // We have to delete the principals and relations! Principals include
+ while($row = $result->fetchRow()){
+ // Checking if the principal is in the prefix
+ $array = explode('/',$row['uri']);
+ if ($array[1] != $params['uid']) continue;
+ $deleteprincipal->execute(array($row['id']));
+ $deletegroup->execute(array($row['id'],$row['id']));
+ }
+ return true;
+ }
+ /**
+ * Returns a list of principals based on a prefix.
+ *
+ * This prefix will often contain something like 'principals'. You are only
+ * expected to return principals that are in this base path.
+ *
+ * You are expected to return at least a 'uri' for every user, you can
+ * return any additional properties if you wish so. Common properties are:
+ * {DAV:}displayname
+ *
+ * @param string $prefixPath
+ * @return array
+ */
+ public function getPrincipalsByPrefix( $prefixPath ){
+ $query = OC_DB::prepare('SELECT * FROM *PREFIX*principals');
+ $result = $query->execute();
+
+ $principals = array();
+
+ while($row = $result->fetchRow()){
+ // Checking if the principal is in the prefix
+ list($rowPrefix) = Sabre_DAV_URLUtil::splitPath($row['uri']);
+ if ($rowPrefix !== $prefixPath) continue;
+
+ $principals[] = array(
+ 'uri' => $row['uri'],
+ '{DAV:}displayname' => $row['displayname']?$row['displayname']:basename($row['uri'])
+ );
+
+ }
+
+ return $principals;
+ }
+
+ /**
+ * Returns a specific principal, specified by it's path.
+ * The returned structure should be the exact same as from
+ * getPrincipalsByPrefix.
+ *
+ * @param string $path
+ * @return array
+ */
+ public function getPrincipalByPath($path) {
+ $query = OC_DB::prepare('SELECT * FROM *PREFIX*principals WHERE uri=?');
+ $result = $query->execute(array($path));
+
+ $users = array();
+
+ $row = $result->fetchRow();
+ if (!$row) return;
+
+ return array(
+ 'id' => $row['id'],
+ 'uri' => $row['uri'],
+ '{DAV:}displayname' => $row['displayname']?$row['displayname']:basename($row['uri'])
+ );
+
+ }
+
+ /**
+ * Returns the list of members for a group-principal
+ *
+ * @param string $principal
+ * @return array
+ */
+ public function getGroupMemberSet($principal) {
+ $principal = $this->getPrincipalByPath($principal);
+ if (!$principal) throw new Sabre_DAV_Exception('Principal not found');
+
+ $query = OC_DB::prepare('SELECT principals.uri as uri FROM *PREFIX*principalgroups AS groupmembers LEFT JOIN *PREFIX*principals AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?');
+ $result = $query->execute(array($principal['id']));
+
+ $return = array();
+ while ($row = $result->fetchRow()){
+ $return[] = $row['uri'];
+ }
+ return $return;
+ }
+
+ /**
+ * Returns the list of groups a principal is a member of
+ *
+ * @param string $principal
+ * @return array
+ */
+ public function getGroupMembership($principal) {
+ $principal = $this->getPrincipalByPath($principal);
+ if (!$principal) throw new Sabre_DAV_Exception('Principal not found');
+
+ $query = OC_DB::prepare('SELECT principals.uri as uri FROM *PREFIX*principalgroups AS groupmembers LEFT JOIN *PREFIX*principals AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.member_id = ?');
+ $result = $query->execute(array($principal['id']));
+
+ $return = array();
+ while ($row = $result->fetchRow()){
+ $return[] = $row['uri'];
+ }
+ return $return;
+ }
+
+ /**
+ * Updates the list of group members for a group principal.
+ *
+ * The principals should be passed as a list of uri's.
+ *
+ * @param string $principal
+ * @param array $members
+ * @return void
+ */
+ public function setGroupMemberSet($principal, array $members) {
+ $query = OC_DB::prepare('SELECT id, uri FROM *PREFIX*principals WHERE uri IN (? '.str_repeat(', ?', count($members)).')');
+ $result = $query->execute(array_merge(array($principal), $members));
+
+ $memberIds = array();
+ $principalId = null;
+
+ while($row = $$result->fetchRow()) {
+ if ($row['uri'] == $principal) {
+ $principalId = $row['id'];
+ }
+ else{
+ $memberIds[] = $row['id'];
+ }
+ }
+ if (!$principalId) throw new Sabre_DAV_Exception('Principal not found');
+
+ // Wiping out old members
+ $query = OC_DB::prepare('DELETE FROM *PREFIX*principalgroups WHERE principal_id = ?');
+ $query->execute(array($principalID));
+
+ $query = OC_DB::prepare('INSERT INTO *PREFIX*principalgroups (principal_id, member_id) VALUES (?, ?);');
+ foreach($memberIds as $memberId) {
+ $query->execute(array($principalId, $memberId));
+ }
+ }
+}
diff --git a/lib/crypt.php b/lib/crypt.php
new file mode 100755
index 00000000000..baa433f9dcc
--- /dev/null
+++ b/lib/crypt.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Frank Karlitschek
+ * @author Jakob Sack
+ * @copyright 2010 Frank Karlitschek karlitschek@kde.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+require_once('Crypt_Blowfish/Blowfish.php');
+
+/**
+ * This class is for crypting and decrypting
+ */
+class OC_Crypt {
+
+ /**
+ * @brief encrypts an content
+ * @param $content the cleartext message you want to encrypt
+ * @param $key the encryption key
+ * @returns encrypted content
+ *
+ * This function encrypts an content
+ */
+ public static function encrypt( $content, $key) {
+ $bf = new Crypt_Blowfish($key);
+ return($bf->encrypt($contents));
+ }
+
+
+ /**
+ * @brief decryption of an content
+ * @param $content the cleartext message you want to decrypt
+ * @param $key the encryption key
+ * @returns cleartext content
+ *
+ * This function decrypts an content
+ */
+ public static function decrypt( $content, $key) {
+ $bf = new Crypt_Blowfish($key);
+ return($bf->encrypt($contents));
+ }
+
+
+
+
+
+}
diff --git a/lib/db.php b/lib/db.php
index 858db09b764..76d3fe5efcb 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -237,6 +237,7 @@ class OC_DB {
public static function createDbFromStructure( $file ){
$CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" );
$CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" );
+ $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
self::connectScheme();
@@ -247,6 +248,9 @@ class OC_DB {
$file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' );
$content = str_replace( '*dbname*', $CONFIG_DBNAME, $content );
$content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content );
+ if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite don't
+ $content = str_replace( '<default>0000-00-00 00:00:00</default>', '<default>CURRENT_TIMESTAMP</default>', $content );
+ }
file_put_contents( $file2, $content );
// Try to create tables
@@ -361,4 +365,39 @@ class OC_DB {
self::dropTable($name);
}
}
+
+ /**
+ * Start a transaction or set a savepoint.
+ * @param string $savePoint (optional) name of the savepoint to set
+ */
+ public static function beginTransaction($savePoint=''){
+ self::connect();
+ if (!self::$DBConnection->supports('transactions')) {
+ return false;
+ }
+ if($savePoint && !self::$DBConnection->supports('savepoints')){
+ return false;
+ }
+ if($savePoint){
+ self::$DBConnection->beginTransaction($savePoint);
+ }else{
+ self::$DBConnection->beginTransaction();
+ }
+ }
+
+ /**
+ * Commit the database changes done during a transaction that is in progress or release a savepoint.
+ * @param string $savePoint (optional) name of the savepoint to commit
+ */
+ public static function commit($savePoint=''){
+ self::connect();
+ if(!self::$DBConnection->inTransaction()){
+ return false;
+ }
+ if($savePoint){
+ self::$DBConnection->commit($savePoint);
+ }else{
+ self::$DBConnection->commit();
+ }
+ }
}
diff --git a/lib/helper.php b/lib/helper.php
index 5dc3dd44a15..fa5163ac266 100755
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -204,7 +204,7 @@ class OC_Helper {
}
}
closedir($dh);
- if(chmod($path, $filemode))
+ if(@chmod($path, $filemode))
return TRUE;
else
return FALSE;
diff --git a/lib/log.php b/lib/log.php
index d51b2ef0785..1ed8e0e33c2 100644
--- a/lib/log.php
+++ b/lib/log.php
@@ -51,7 +51,7 @@ class OC_Log {
* This function adds another entry to the log database
*/
public static function add( $appid, $subject, $predicate, $object = ' ' ){
- $query=OC_DB::prepare("INSERT INTO `*PREFIX*log`(moment,appid,user,action,info) VALUES(NOW(),?,?,?,?)");
+ $query=OC_DB::prepare("INSERT INTO `*PREFIX*log`(moment,appid,`user`,action,info) VALUES(NOW(),?,?,?,?)");
$result=$query->execute(array($appid,$subject,$predicate,$object));
// Die if we have an error
if( PEAR::isError($result)) {
@@ -90,7 +90,7 @@ class OC_Log {
array_push($params,$filter('until'));
}
if(isset($filter['user'])){
- $queryString.='AND user=? ';
+ $queryString.='AND `user`=? ';
array_push($params,$filter('user'));
}
if(isset($filter['app'])){
diff --git a/lib/ocs.php b/lib/ocs.php
index 8c7556a173b..bcacfe704c0 100644
--- a/lib/ocs.php
+++ b/lib/ocs.php
@@ -407,7 +407,7 @@ class OC_OCS {
$entry=$result->fetchRow();
$totalcount=$entry['co'];
- $query=OC_DB::prepare('select id,timestamp,user,type,message from *PREFIX*log order by timestamp desc limit ?,?');
+ $query=OC_DB::prepare('select id,timestamp,`user`,type,message from *PREFIX*log order by timestamp desc limit ?,?');
$result = $query->execute(array(($page*$pagesize),$pagesize))->fetchAll();
$itemscount=count($result);
diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php
index f3d235abdce..5fd35fa3e52 100644
--- a/lib/search/provider/file.php
+++ b/lib/search/provider/file.php
@@ -13,11 +13,18 @@ class OC_Search_Provider_File extends OC_Search_Provider{
switch($mimeBase){
case 'audio':
break;
+ case 'text':
+ $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Text');
+ break;
case 'image':
$results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Images');
break;
default:
- $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Files');
+ if($mime=='application/xml'){
+ $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Text');
+ }else{
+ $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Files');
+ }
}
}
}
diff --git a/lib/setup.php b/lib/setup.php
index 41cfa1750ab..f87581d7582 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -2,10 +2,12 @@
$hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3'));
$hasMySQL = is_callable('mysql_connect');
+$hasPostgreSQL = is_callable('pg_connect');
$datadir = OC_Config::getValue('datadir', $SERVERROOT.'/data');
$opts = array(
'hasSQLite' => $hasSQLite,
'hasMySQL' => $hasMySQL,
+ 'hasPostgreSQL' => $hasPostgreSQL,
'directory' => $datadir,
'errors' => array(),
);
@@ -43,6 +45,7 @@ class OC_Setup {
if(empty($options['directory'])) {
$error[] = 'STEP 2 : data directory path is not set.';
}
+
if($dbtype=='mysql') { //mysql needs more config options
if(empty($options['dbuser'])) {
$error[] = 'STEP 3 : MySQL database user is not set.';
@@ -61,6 +64,24 @@ class OC_Setup {
}
}
+ if($dbtype=='pgsql') { //postgresql needs more config options
+ if(empty($options['pg_dbuser'])) {
+ $error[] = 'STEP 3 : PostgreSQL database user is not set.';
+ }
+ if(empty($options['pg_dbpass'])) {
+ $error[] = 'STEP 3 : PostgreSQL database password is not set.';
+ }
+ if(empty($options['pg_dbname'])) {
+ $error[] = 'STEP 3 : PostgreSQL database name is not set.';
+ }
+ if(empty($options['pg_dbhost'])) {
+ $error[] = 'STEP 3 : PostgreSQL database host is not set.';
+ }
+ if(!isset($options['pg_dbtableprefix'])) {
+ $error[] = 'STEP 3 : PostgreSQL database table prefix is not set.';
+ }
+ }
+
if(count($error) == 0) { //no errors, good
$username = htmlspecialchars_decode($options['adminlogin']);
$password = htmlspecialchars_decode($options['adminpass']);
@@ -99,7 +120,7 @@ class OC_Setup {
//use the admin login data for the new database user
//add prefix to the mysql user name to prevent collissions
- $dbusername='oc_mysql_'.$username;
+ $dbusername=substr('oc_mysql_'.$username,0,16);
//hash the password so we don't need to store the admin config in the config file
$dbpassword=md5(time().$password);
@@ -128,6 +149,62 @@ class OC_Setup {
mysql_close($connection);
}
}
+ elseif($dbtype == 'pgsql') {
+ $dbuser = $options['pg_dbuser'];
+ $dbpass = $options['pg_dbpass'];
+ $dbname = $options['pg_dbname'];
+ $dbhost = $options['pg_dbhost'];
+ $dbtableprefix = $options['pg_dbtableprefix'];
+ OC_CONFIG::setValue('dbname', $dbname);
+ OC_CONFIG::setValue('dbhost', $dbhost);
+ OC_CONFIG::setValue('dbtableprefix', $dbtableprefix);
+
+ //check if the database user has admin right
+ $connection_string = "host=$dbhost dbname=postgres user=$dbuser password=$dbpass";
+ $connection = @pg_connect($connection_string);
+ if(!$connection) {
+ $error[] = array(
+ 'error' => 'postgresql username and/or password not valid',
+ 'hint' => 'you need to enter either an existing account, or the administrative account if you wish to create a new user for ownCloud'
+ );
+ }
+ else {
+ //check for roles creation rights in postgresql
+ $query="SELECT 1 FROM pg_roles WHERE rolcreaterole=TRUE AND rolname='$dbuser'";
+ $result = pg_query($connection, $query);
+ if($result and pg_num_rows($result) > 0) {
+ //use the admin login data for the new database user
+
+ //add prefix to the postgresql user name to prevent collissions
+ $dbusername='oc_'.$username;
+ //hash the password so we don't need to store the admin config in the config file
+ $dbpassword=md5(time().$password);
+
+ self::pg_createDBUser($dbusername, $dbpassword, $connection);
+
+ OC_CONFIG::setValue('dbuser', $dbusername);
+ OC_CONFIG::setValue('dbpassword', $dbpassword);
+
+ //create the database
+ self::pg_createDatabase($dbname, $dbusername, $connection);
+ }
+ else {
+ OC_CONFIG::setValue('dbuser', $dbuser);
+ OC_CONFIG::setValue('dbpassword', $dbpass);
+
+ //create the database
+ self::pg_createDatabase($dbname, $dbuser, $connection);
+ }
+
+ //fill the database if needed
+ $query="SELECT * FROM {$dbtableprefix}users";
+ $result = pg_query($connection, $query);
+ if(!$result) {
+ OC_DB::createDbFromStructure('db_structure.xml');
+ }
+ pg_close($connection);
+ }
+ }
else {
//delete the old sqlite database first, might cause infinte loops otherwise
if(file_exists("$datadir/owncloud.db")){
@@ -179,6 +256,29 @@ class OC_Setup {
$result = mysql_query($query, $connection);
}
+ public static function pg_createDatabase($name,$user,$connection) {
+ //we cant user OC_BD functions here because we need to connect as the administrative user.
+ $query = "CREATE DATABASE $name OWNER $user";
+ $result = pg_query($connection, $query);
+ if(!$result) {
+ $entry='DB Error: "'.pg_last_error($connection).'"<br />';
+ $entry.='Offending command was: '.$query.'<br />';
+ echo($entry);
+ }
+ $query = "REVOKE ALL PRIVILEGES ON DATABASE $name FROM PUBLIC";
+ $result = pg_query($connection, $query);
+ }
+
+ private static function pg_createDBUser($name,$password,$connection) {
+ $query = "CREATE USER $name CREATEDB PASSWORD '$password';";
+ $result = pg_query($connection, $query);
+ if(!$result) {
+ $entry='DB Error: "'.pg_last_error($connection).'"<br />';
+ $entry.='Offending command was: '.$query.'<br />';
+ echo($entry);
+ }
+ }
+
/**
* create .htaccess files for apache hosts
*/
diff --git a/lib/template.php b/lib/template.php
index fe173f609b2..124343bd85b 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -82,19 +82,19 @@ function relative_modified_date($timestamp) {
$diffdays = round($diffhours/24);
$diffmonths = round($diffdays/31);
$diffyears = round($diffdays/365);
+
if($timediff < 60) { return 'seconds ago'; }
else if($timediff < 120) { return '1 minute ago'; }
else if($timediff < 3600) { return $diffminutes.' minutes ago'; }
//else if($timediff < 7200) { return '1 hour ago'; }
//else if($timediff < 86400) { return $diffhours.' hours ago'; }
- else if($timediff < 86400) { return 'today'; }
- else if($timediff < 172800) { return 'yesterday'; }
+ else if((date('G')-$diffhours) > 0) { return 'today'; }
+ else if((date('G')-$diffhours) > -24) { return 'yesterday'; }
else if($timediff < 2678400) { return $diffdays.' days ago'; }
else if($timediff < 5184000) { return 'last month'; }
- //else if($timediff < 31556926) { return $diffmonths.' months ago'; }
- else if($timediff < 31556926) { return 'months ago'; }
+ else if((date('n')-$diffmonths) > 0) { return 'months ago'; }
else if($timediff < 63113852) { return 'last year'; }
- else { return $diffyears.' years ago'; }
+ else { return 'years ago'; }
}
@@ -139,12 +139,14 @@ class OC_Template{
}
// Templates have the ending .php
+ $path = $template;
$template .= "$name.php";
// Set the private data
$this->renderas = $renderas;
$this->application = $app;
$this->template = $template;
+ $this->path = $path;
$this->vars = array();
$this->l10n = new OC_L10N($app);
}
@@ -321,6 +323,27 @@ class OC_Template{
}
/**
+ * @brief Include template
+ * @returns returns content of included template
+ *
+ * Includes another template. use <?php echo $this->inc('template'); ?> to
+ * do this.
+ */
+ public function inc( $file ){
+ // $_ erstellen
+ $_ = $this->vars;
+
+ // Einbinden
+ ob_start();
+ include( $this->path.$file.'.php' );
+ $data = ob_get_contents();
+ ob_end_clean();
+
+ // Daten zurückgeben
+ return $data;
+ }
+
+ /**
* @brief Shortcut to print a simple page for users
* @param $application The application we render the template for
* @param $name Name of the template
diff --git a/lib/util.php b/lib/util.php
index 3e2e4fa34e4..10cd320977a 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -25,7 +25,13 @@ class OC_Util {
// Create root dir
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
- @mkdir($CONFIG_DATADIRECTORY_ROOT) or die("Can't create data directory ($CONFIG_DATADIRECTORY_ROOT), you can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (www-data for debian/ubuntu)");
+ $success=@mkdir($CONFIG_DATADIRECTORY_ROOT);
+ if(!$success) {
+ $tmpl = new OC_Template( '', 'error', 'guest' );
+ $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory ($CONFIG_DATADIRECTORY_ROOT)",'hint'=>"You can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (".exec('whoami').")")));
+ $tmpl->printPage();
+ exit;
+ }
}
// If we are not forced to load a specific user we load the one that is logged in
@@ -214,21 +220,21 @@ class OC_Util {
//check for correct file permissions
if(!stristr(PHP_OS, 'WIN')){
- $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
+ $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
if(substr($prems,-1)!='0'){
OC_Helper::chmodr($CONFIG_DATADIRECTORY_ROOT,0770);
clearstatcache();
- $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
+ $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
if(substr($prems,2,1)!='0'){
$errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>','hint'=>$permissionsHint);
}
}
if( OC_Config::getValue( "enablebackup", false )){
- $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
+ $prems=substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)),-3);
if(substr($prems,-1)!='0'){
OC_Helper::chmodr($CONFIG_BACKUPDIRECTORY,0770);
clearstatcache();
- $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
+ $prems=substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)),-3);
if(substr($prems,2,1)!='0'){
$errors[]=array('error'=>'Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>','hint'=>$permissionsHint);
}