From 132695ceb1d7ab0e4bfbb141e9e9639111dd25b5 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Tue, 1 Mar 2011 23:20:16 +0100 Subject: Start of the refactoring. Commit is quite big because I forgot to use git right from the beginning. Sorry. --- lib/base.php | 807 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 807 insertions(+) create mode 100644 lib/base.php (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php new file mode 100644 index 00000000000..4694f826a52 --- /dev/null +++ b/lib/base.php @@ -0,0 +1,807 @@ +. +* +*/ + + +// set some stuff +ob_start(); +// error_reporting(E_ALL | E_STRICT); +error_reporting( E_ERROR | E_PARSE | E_WARNING ); // MDB2 gives loads of strict error, disabling for now + +date_default_timezone_set('Europe/Berlin'); +ini_set('arg_separator.output','&'); +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); +$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT)); +$WEBROOT=substr($_SERVER["SCRIPT_NAME"],0,strlen($_SERVER["SCRIPT_NAME"])-strlen($SUBURI)); + + + +if($WEBROOT!='' and $WEBROOT[0]!=='/'){ + $WEBROOT='/'.$WEBROOT; +} + +// set the right include path +// set_include_path(get_include_path().PATH_SEPARATOR.$SERVERROOT.PATH_SEPARATOR.$SERVERROOT.'/inc'.PATH_SEPARATOR.$SERVERROOT.'/config'); + +// define default config values +$CONFIG_INSTALLED=false; +$CONFIG_DATADIRECTORY=$SERVERROOT.'/data'; +$CONFIG_BACKUPDIRECTORY=$SERVERROOT.'/backup'; +$CONFIG_HTTPFORCESSL=false; +$CONFIG_ENABLEBACKUP=false; +$CONFIG_DATEFORMAT='j M Y G:i'; +$CONFIG_DBNAME='owncloud'; +$CONFIG_DBTYPE='sqlite'; +$CONFIG_FILESYSTEM=array(); + +// include the generated configfile +@include_once($SERVERROOT.'/config/config.php'); + + +$CONFIG_DATADIRECTORY_ROOT=$CONFIG_DATADIRECTORY;// store this in a seperate variable so we can change the data directory to jail users. +// redirect to https site if configured +if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){ + if(!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') { + $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; + header("Location: $url"); + exit; + } +} + +// load core libs +oc_require_once('files.php'); +oc_require_once('filesystem.php'); +oc_require_once('filestorage.php'); +oc_require_once('fileobserver.php'); +oc_require_once('log.php'); +oc_require_once('config.php'); +oc_require_once('user.php'); +oc_require_once('ocs.php'); +oc_require_once('connect.php'); +oc_require_once('remotestorage.php'); +oc_require_once('plugin.php'); + +OC_PLUGIN::loadPlugins(); + +if(!isset($CONFIG_BACKEND)){ + $CONFIG_BACKEND='database'; +} +OC_USER::setBackend($CONFIG_BACKEND); + +OC_UTIL::setupFS(); + +oc_startup(); + + + +// check if the server is correctly configured for ownCloud +OC_UTIL::checkserver(); + +// listen for login or logout actions +OC_USER::logoutlistener(); +$loginresult=OC_USER::loginlistener(); + +/** + * Class for utility functions + * + */ +class OC_UTIL { + public static $scripts=array(); + public static $styles=array(); + public static $adminpages = array(); + public static $applications = array(); + public static $navigation = array(); + public static $personalmenu = array(); + private static $fsSetup=false; + + public static function setupFS(){// configure the initial filesystem based on the configuration + if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble + return false; + } + global $SERVERROOT; + global $CONFIG_DATADIRECTORY_ROOT; + global $CONFIG_DATADIRECTORY; + global $CONFIG_BACKUPDIRECTORY; + global $CONFIG_ENABLEBACKUP; + global $CONFIG_FILESYSTEM; + 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)"); + } + if(OC_USER::isLoggedIn()){ //if we aren't logged in, there is no use to set up the filesystem + //first set up the local "root" storage and the backupstorage if needed + $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY)); + if($CONFIG_ENABLEBACKUP){ + if(!is_dir($CONFIG_BACKUPDIRECTORY)){ + mkdir($CONFIG_BACKUPDIRECTORY); + } + if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean'])){ + mkdir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean']); + } + $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); + $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); + $rootStorage->addObserver($backup); + } + OC_FILESYSTEM::mount($rootStorage,'/'); + + $CONFIG_DATADIRECTORY=$CONFIG_DATADIRECTORY_ROOT.'/'.$_SESSION['username_clean']; + if(!is_dir($CONFIG_DATADIRECTORY)){ + mkdir($CONFIG_DATADIRECTORY); + } + + //set up the other storages according to the system settings + foreach($CONFIG_FILESYSTEM as $storageConfig){ + if(OC_FILESYSTEM::hasStorageType($storageConfig['type'])){ + $arguments=$storageConfig; + unset($arguments['type']); + unset($arguments['mountpoint']); + $storage=OC_FILESYSTEM::createStorage($storageConfig['type'],$arguments); + if($storage){ + OC_FILESYSTEM::mount($storage,$storageConfig['mountpoint']); + } + } + } + + //jail the user into his "home" directory + OC_FILESYSTEM::chroot('/'.$_SESSION['username_clean']); + self::$fsSetup=true; + } + } + + /** + * get the current installed version of ownCloud + * @return array + */ + public static function getVersion(){ + return array(1,2,0); + } + + /** + * Create an url + * + * @param string $application + * @param string $file + */ + public static function linkTo( $application, $file = null ){ + global $WEBROOT; + if( is_null( $file )){ + $file = $application; + $application = ""; + } + return "$WEBROOT/$application/$file"; + } + + /** + * Create an image link + * + * @param string $application + * @param string $file + */ + public static function imagePath( $application, $file = null ){ + global $WEBROOT; + if( is_null( $file )){ + $file = $application; + $application = ""; + } + return "$WEBROOT/$application/img/$file"; + } + + /** + * add a javascript file + * + * @param url $url + */ + public static function addScript( $application, $file = null ){ + if( is_null( $file )){ + $file = $application; + $application = ""; + } + self::$scripts[] = "$application/js/$file"; + } + + /** + * add a css file + * + * @param url $url + */ + public static function addStyle( $application, $file = null ){ + if( is_null( $file )){ + $file = $application; + $application = ""; + } + self::$styles[] = "$application/css/$file"; + } + + /** + * add an entry to the main navigation + * + * @param array $entry + */ + public static function addNavigationEntry( $entry){ + OC_UTIL::$navigation[] = $entry; + } + + /** + * add administration pages + * + * @param array $entry + */ + public static function addAdminPage( $entry){ + OC_UTIL::$adminpages[] = $entry; + } + + /** + * add application + * + * @param array $entry + */ + public static function addApplication( $entry){ + OC_UTIL::$applications[] = $entry; + } + + /** + * add an entry to the personal menu + * + * @param array $entry + */ + public static function addPersonalMenuEntry( $entry){ + OC_UTIL::$personalmenu[] = $entry; + } + + /** + * check if the current server configuration is suitable for ownCloud + * + */ + public static function checkServer(){ + global $SERVERROOT; + global $CONFIG_DATADIRECTORY_ROOT; + global $CONFIG_BACKUPDIRECTORY; + global $CONFIG_ENABLEBACKUP; + global $CONFIG_INSTALLED; + $error=''; + if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ + $error.='No database drivers (sqlite or mysql) installed.
'; + } + global $CONFIG_DBTYPE; + global $CONFIG_DBNAME; + if(!stristr(PHP_OS, 'WIN')){ + if($CONFIG_DBTYPE=='sqlite'){ + $file=$SERVERROOT.'/'.$CONFIG_DBNAME; + if(file_exists($file)){ + $prems=substr(decoct(fileperms($file)),-3); + if(substr($prems,2,1)!='0'){ + @chmod($file,0660); + clearstatcache(); + $prems=substr(decoct(fileperms($file)),-3); + if(substr($prems,2,1)!='0'){ + $error.='SQLite database file ('.$file.') is readable from the web
'; + } + } + } + } + $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); + if(substr($prems,-1)!='0'){ + chmodr($CONFIG_DATADIRECTORY_ROOT,0770); + clearstatcache(); + $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); + if(substr($prems,2,1)!='0'){ + $error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web
'; + } + } + if($CONFIG_ENABLEBACKUP){ + $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); + if(substr($prems,-1)!='0'){ + chmodr($CONFIG_BACKUPDIRECTORY,0770); + clearstatcache(); + $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); + if(substr($prems,2,1)!='0'){ + $error.='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web
'; + } + } + } + }else{ + //TODO: premisions checks for windows hosts + } + if($error){ + die($error); + } + } + + /** + * check if we need to use the layout optimized for smaller screen, currently only checks for iPhone/Android + * @return bool + */ + public static function hasSmallScreen(){ + $userAgent=strtolower($_SERVER['HTTP_USER_AGENT']); + if(strpos($userAgent,'android') or strpos($userAgent,'iphone') or strpos($userAgent,'ipod')){//todo, add support for more devices + return true; + } + return false; + } + + /** + * show an icon for a filetype + * + */ + public static function showIcon($filetype){ + global $WEBROOT; + if($filetype=='dir'){ echo(''); + }elseif($filetype=='foo'){ echo('foo'); + }else{ echo(''); + } + } +} + + +/** + * Class for database access + * + */ +class OC_DB { + static private $DBConnection=false; + static private $schema=false; + static private $affected=0; + static private $result=false; + /** + * connect to the datbase if not already connected + */ + public static function connect(){ + global $CONFIG_DBNAME; + global $CONFIG_DBHOST; + global $CONFIG_DBUSER; + global $CONFIG_DBPASSWORD; + global $CONFIG_DBTYPE; + global $DOCUMENTROOT; + global $SERVERROOT; + @oc_require_once('MDB2.php'); + if(!self::$DBConnection){ + $options = array( + 'portability' => MDB2_PORTABILITY_ALL, + 'log_line_break' => '
', + 'idxname_format' => '%s', + 'debug' => true, + 'quote_identifier' => true, + ); + if($CONFIG_DBTYPE=='sqlite'){ + $dsn = array( + 'phptype' => 'sqlite', + 'database' => $SERVERROOT.'/'.$CONFIG_DBNAME, + 'mode' => '0644', + ); + }elseif($CONFIG_DBTYPE=='mysql'){ + $dsn = array( + 'phptype' => 'mysql', + 'username' => $CONFIG_DBUSER, + 'password' => $CONFIG_DBPASSWORD, + 'hostspec' => $CONFIG_DBHOST, + 'database' => $CONFIG_DBNAME, + ); + }elseif($CONFIG_DBTYPE=='pgsql'){ + $dsn = array( + 'phptype' => 'pgsql', + 'username' => $CONFIG_DBUSER, + 'password' => $CONFIG_DBPASSWORD, + 'hostspec' => $CONFIG_DBHOST, + 'database' => $CONFIG_DBNAME, + ); + } + self::$DBConnection=MDB2::factory($dsn,$options); + + if (PEAR::isError(self::$DBConnection)) { + echo('can not connect to database, using '.$CONFIG_DBTYPE.'. ('.self::$DBConnection->getUserInfo().')'); + $error=self::$DBConnection->getMessage(); + error_log("$error"); + error_log(self::$DBConnection->getUserInfo()); + die($error); + } + self::$DBConnection->setFetchMode(MDB2_FETCHMODE_ASSOC); + } + } + + public static function connectScheme(){ + self::connect(); + @oc_require_once('MDB2/Schema.php'); + if(!self::$schema){ + self::$schema=&MDB2_Schema::factory(self::$DBConnection); + } + } + + /** + * executes a query on the database + * + * @param string $cmd + * @return result-set + */ + static function query($cmd){ + global $CONFIG_DBTYPE; + if(!trim($cmd)){ + return false; + } + OC_DB::connect(); + //fix differences between sql versions + + //differences in escaping of table names (` for mysql) + if($CONFIG_DBTYPE=='sqlite'){ + $cmd=str_replace('`','\'',$cmd); + }elseif($CONFIG_DBTYPE=='pgsql'){ + $cmd=str_replace('`','"',$cmd); + } + $result=self::$DBConnection->exec($cmd); + if (PEAR::isError($result)) { + $entry='DB Error: "'.$result->getMessage().'"
'; + $entry.='Offending command was: '.$cmd.'
'; + error_log($entry); + die($entry); + }else{ + self::$affected=$result; + } + self::$result=$result; + return $result; + } + + /** + * executes a query on the database and returns the result in an array + * + * @param string $cmd + * @return result-set + */ + static function select($cmd){ + OC_DB::connect(); + global $CONFIG_DBTYPE; + //fix differences between sql versions + + //differences in escaping of table names (` for mysql) + if($CONFIG_DBTYPE=='sqlite'){ + $cmd=str_replace('`','\'',$cmd); + }elseif($CONFIG_DBTYPE=='pgsql'){ + $cmd=str_replace('`','"',$cmd); + } + $result=self::$DBConnection->queryAll($cmd); + if (PEAR::isError($result)){ + $entry='DB Error: "'.$result->getMessage().'"
'; + $entry.='Offending command was: '.$cmd.'
'; + die($entry); + } + return $result; + } + + /** + * executes multiply queries on the database + * + * @param string $cmd + * @return result-set + */ + static function multiquery($cmd) { + $queries=explode(';',$cmd); + foreach($queries as $query){ + OC_DB::query($query); + } + return true; + } + + + /** + * closing a db connection + * + * @return bool + */ + static function close() { + self::$DBConnection->disconnect(); + self::$DBConnection=false; + } + + + /** + * Returning primarykey if last statement was an insert. + * + * @return primarykey + */ + static function insertid() { + $id=self::$DBConnection->lastInsertID(); + return $id; + } + + /** + * Returning number of rows in a result + * + * @param resultset $result + * @return int + */ + static function numrows($result) { + $result->numRows(); + } + /** + * Returning number of affected rows + * + * @return int + */ + static function affected_rows() { + return self::$affected; + } + + /** + * get a field from the resultset + * + * @param resultset $result + * @param int $i + * @param int $field + * @return unknown + */ + static function result($result, $i, $field) { + $tmp=$result->fetchRow(MDB2_FETCHMODE_ASSOC,$i); + $tmp=$tmp[$field]; + return($tmp); + } + + /** + * get data-array from resultset + * + * @param resultset $result + * @return data + */ + static function fetch_assoc($result){ + return $result->fetchRow(MDB2_FETCHMODE_ASSOC); + } + + /** + * Freeing resultset (performance) + * + * @param unknown_type $result + * @return bool + */ + static function free_result() { + if(self::$result){ + self::$result->free(); + self::$result=false; + } + } + + static public function disconnect(){ + if(self::$DBConnection){ + self::$DBConnection->disconnect(); + self::$DBConnection=false; + } + } + + /** + * escape strings so they can be used in queries + * + * @param string string + * @return string + */ + static function escape($string){ + OC_DB::connect(); + return self::$DBConnection->escape($string); + } + + static function getDbStructure($file){ + OC_DB::connectScheme(); + $definition = self::$schema->getDefinitionFromDatabase(); + $dump_options = array( + 'output_mode' => 'file', + 'output' => $file, + 'end_of_line' => "\n" + ); + self::$schema->dumpDatabase($definition, $dump_options, MDB2_SCHEMA_DUMP_STRUCTURE); + } + + static function createDbFromStructure($file){ + OC_DB::connectScheme(); + global $CONFIG_DBNAME; + global $CONFIG_DBTABLEPREFIX; + $content=file_get_contents($file); + $file2=tempnam(sys_get_temp_dir(),'oc_db_scheme_'); + $content=str_replace('*dbname*',$CONFIG_DBNAME,$content); + $content=str_replace('*dbprefix*',$CONFIG_DBTABLEPREFIX,$content); + file_put_contents($file2,$content); + $definition=@self::$schema->parseDatabaseDefinitionFile($file2); + unlink($file2); + if($definition instanceof MDB2_Schema_Error){ + die($definition->getMessage() . ': ' . $definition->getUserInfo()); + } + $ret=@self::$schema->createDatabase($definition); + if($ret instanceof MDB2_Error) { + die ($ret->getMessage() . ': ' . $ret->getUserInfo()); + }else{ + return true; + } + } +} + + +//custom require/include functions because not all hosts allow us to set the include path +function oc_require($file){ + global $SERVERROOT; + global $DOCUMENTROOT; + global $WEBROOT; + global $CONFIG_DBNAME; + global $CONFIG_DBHOST; + global $CONFIG_DBUSER; + global $CONFIG_DBPASSWORD; + global $CONFIG_DBTYPE; + global $CONFIG_DATADIRECTORY; + global $CONFIG_HTTPFORCESSL; + global $CONFIG_DATEFORMAT; + global $CONFIG_INSTALLED; + + if(is_file($file)){ + return require($file); + } + elseif(is_file($SERVERROOT.'/'.$file)){ + return require($SERVERROOT.'/'.$file); + } + elseif(is_file($SERVERROOT.'/lib/'.$file)){ + return require($SERVERROOT.'/lib/'.$file); + } + elseif(is_file($SERVERROOT.'/3dparty/'.$file)){ + return require($SERVERROOT.'/3dparty/'.$file); + } +} + +function oc_require_once($file){ + global $SERVERROOT; + global $DOCUMENTROOT; + global $WEBROOT; + global $CONFIG_DBNAME; + global $CONFIG_DBHOST; + global $CONFIG_DBUSER; + global $CONFIG_DBPASSWORD; + global $CONFIG_DBTYPE; + global $CONFIG_DATADIRECTORY; + global $CONFIG_HTTPFORCESSL; + global $CONFIG_DATEFORMAT; + global $CONFIG_INSTALLED; + + if(is_file($file)){ + return require_once($file); + } + elseif(is_file($SERVERROOT.'/'.$file)){ + return require_once($SERVERROOT.'/'.$file); + } + elseif(is_file($SERVERROOT.'/lib/'.$file)){ + return require_once($SERVERROOT.'/lib/'.$file); + } + elseif(is_file($SERVERROOT.'/3dparty/'.$file)){ + return require_once($SERVERROOT.'/3dparty/'.$file); + } +} + +function oc_include($file){ + global $SERVERROOT; + global $DOCUMENTROOT; + global $WEBROOT; + global $CONFIG_DBNAME; + global $CONFIG_DBHOST; + global $CONFIG_DBUSER; + global $CONFIG_DBPASSWORD; + global $CONFIG_DBTYPE; + global $CONFIG_DATADIRECTORY; + global $CONFIG_HTTPFORCESSL; + global $CONFIG_DATEFORMAT; + global $CONFIG_INSTALLED; + + if(is_file($file)){ + return include($file); + } + elseif(is_file($SERVERROOT.'/'.$file)){ + return include($SERVERROOT.'/'.$file); + } + elseif(is_file($SERVERROOT.'/lib/'.$file)){ + return include($SERVERROOT.'/lib/'.$file); + } + elseif(is_file($SERVERROOT.'/3dparty/'.$file)){ + return include($SERVERROOT.'/3dparty/'.$file); + } +} + +function oc_include_once($file){ + global $SERVERROOT; + global $DOCUMENTROOT; + global $WEBROOT; + global $CONFIG_DBNAME; + global $CONFIG_DBHOST; + global $CONFIG_DBUSER; + global $CONFIG_DBPASSWORD; + global $CONFIG_DBTYPE; + global $CONFIG_DATADIRECTORY; + global $CONFIG_HTTPFORCESSL; + global $CONFIG_DATEFORMAT; + global $CONFIG_INSTALLED; + + if(is_file($file)){ + return include_once($file); + } + elseif(is_file($SERVERROOT.'/'.$file)){ + return include_once($SERVERROOT.'/'.$file); + } + elseif(is_file($SERVERROOT.'/lib/'.$file)){ + return include_once($SERVERROOT.'/lib/'.$file); + } + elseif(is_file($SERVERROOT.'/3dparty/'.$file)){ + return include_once($SERVERROOT.'/3dparty/'.$file); + } +} + +function chmodr($path, $filemode) { +// echo "$path
"; + if (!is_dir($path)) + return chmod($path, $filemode); + $dh = opendir($path); + while (($file = readdir($dh)) !== false) { + if($file != '.' && $file != '..') { + $fullpath = $path.'/'.$file; + if(is_link($fullpath)) + return FALSE; + elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode)) + return FALSE; + elseif(!chmodr($fullpath, $filemode)) + return FALSE; + } + } + closedir($dh); + if(chmod($path, $filemode)) + return TRUE; + else + return FALSE; +} + +function oc_startup(){ + global $SERVERROOT; + global $DOCUMENTROOT; + global $WEBROOT; + global $CONFIG_DBNAME; + global $CONFIG_DBHOST; + global $CONFIG_DBUSER; + global $CONFIG_DBPASSWORD; + global $CONFIG_DBTYPE; + global $CONFIG_DATADIRECTORY; + global $CONFIG_HTTPFORCESSL; + global $CONFIG_DATEFORMAT; + global $CONFIG_INSTALLED; + + // Add the stuff we need always + OC_UTIL::addPersonalMenuEntry( array( "file" => "index.php?logout=1", "name" => "Logout" )); + OC_UTIL::addScript( "jquery-1.5.min" ); + OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" ); + OC_UTIL::addScript( "js" ); + OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); + OC_UTIL::addStyle( "styles" ); + + // Require all appinfo.php + $dir = opendir( $SERVERROOT ); + while( false !== ( $filename = readdir( $dir ))){ + if( substr( $filename, 0, 1 ) != '.' ){ + if( file_exists( "$SERVERROOT/$filename/appinfo.php" )){ + oc_require( "$filename/appinfo.php" ); + } + } + } + closedir( $dir ); + + // Everything done + return true; +} + +?> -- cgit v1.2.3 From dfa6b749baf95856601ea476e58f884cfb453055 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Wed, 2 Mar 2011 22:18:22 +0100 Subject: Introducing OC_HELPER for small helper functions; making setup of filesystem optional --- img/actions/go-home.png | Bin 0 -> 635 bytes img/mimetypes/application-octet-stream.png | Bin 0 -> 1854 bytes img/places/folder.png | Bin 0 -> 386 bytes lib/base.php | 135 ++++++++++------------------- lib/helper.php | 84 ++++++++++++++++++ lib/template.php | 8 +- 6 files changed, 133 insertions(+), 94 deletions(-) create mode 100644 img/actions/go-home.png create mode 100644 img/mimetypes/application-octet-stream.png create mode 100644 img/places/folder.png create mode 100644 lib/helper.php (limited to 'lib/base.php') diff --git a/img/actions/go-home.png b/img/actions/go-home.png new file mode 100644 index 00000000000..9ee717c8b12 Binary files /dev/null and b/img/actions/go-home.png differ diff --git a/img/mimetypes/application-octet-stream.png b/img/mimetypes/application-octet-stream.png new file mode 100644 index 00000000000..0a90cf06b5f Binary files /dev/null and b/img/mimetypes/application-octet-stream.png differ diff --git a/img/places/folder.png b/img/places/folder.png new file mode 100644 index 00000000000..536da3d1c39 Binary files /dev/null and b/img/places/folder.png differ diff --git a/lib/base.php b/lib/base.php index 4694f826a52..ac293cf193b 100644 --- a/lib/base.php +++ b/lib/base.php @@ -46,6 +46,11 @@ if($WEBROOT!='' and $WEBROOT[0]!=='/'){ // set the right include path // set_include_path(get_include_path().PATH_SEPARATOR.$SERVERROOT.PATH_SEPARATOR.$SERVERROOT.'/inc'.PATH_SEPARATOR.$SERVERROOT.'/config'); +// define runtime variables - unless this already has been done +if( !isset( $RUNTIME_NOSETUPFS )){ + $RUNTIME_NOSETUPFS = false; +} + // define default config values $CONFIG_INSTALLED=false; $CONFIG_DATADIRECTORY=$SERVERROOT.'/data'; @@ -91,19 +96,35 @@ if(!isset($CONFIG_BACKEND)){ } OC_USER::setBackend($CONFIG_BACKEND); -OC_UTIL::setupFS(); +// Set up file system unless forbidden +if( !$RUNTIME_NOSETUPFS ){ + OC_UTIL::setupFS(); +} -oc_startup(); +// Add the stuff we need always +OC_UTIL::addPersonalMenuEntry( array( "file" => "index.php?logout=1", "name" => "Logout" )); +OC_UTIL::addScript( "jquery-1.5.min" ); +OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" ); +OC_UTIL::addScript( "js" ); +OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); +OC_UTIL::addStyle( "styles" ); + +// Require all appinfo.php +$dir = opendir( $SERVERROOT ); +while( false !== ( $filename = readdir( $dir ))){ + if( substr( $filename, 0, 1 ) != '.' ){ + if( file_exists( "$SERVERROOT/$filename/appinfo.php" )){ + oc_require( "$filename/appinfo.php" ); + } + } +} +closedir( $dir ); // check if the server is correctly configured for ownCloud OC_UTIL::checkserver(); -// listen for login or logout actions -OC_USER::logoutlistener(); -$loginresult=OC_USER::loginlistener(); - /** * Class for utility functions * @@ -117,28 +138,39 @@ class OC_UTIL { public static $personalmenu = array(); private static $fsSetup=false; - public static function setupFS(){// configure the initial filesystem based on the configuration + // Can be set up + public static function setupFS( $user = "" ){// configure the initial filesystem based on the configuration if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble return false; } + + // Global Variables global $SERVERROOT; global $CONFIG_DATADIRECTORY_ROOT; global $CONFIG_DATADIRECTORY; global $CONFIG_BACKUPDIRECTORY; global $CONFIG_ENABLEBACKUP; global $CONFIG_FILESYSTEM; + + // 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)"); } - if(OC_USER::isLoggedIn()){ //if we aren't logged in, there is no use to set up the filesystem + + // If we are not forced to load a specific user we load the one that is logged in + if( $user == "" && OC_USER::isLoggedIn()){ + $user = $_SESSION['username_clean']; + } + + if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem //first set up the local "root" storage and the backupstorage if needed $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY)); if($CONFIG_ENABLEBACKUP){ if(!is_dir($CONFIG_BACKUPDIRECTORY)){ mkdir($CONFIG_BACKUPDIRECTORY); } - if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean'])){ - mkdir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean']); + if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$user )){ + mkdir($CONFIG_BACKUPDIRECTORY.'/'.$user ); } $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); @@ -146,7 +178,7 @@ class OC_UTIL { } OC_FILESYSTEM::mount($rootStorage,'/'); - $CONFIG_DATADIRECTORY=$CONFIG_DATADIRECTORY_ROOT.'/'.$_SESSION['username_clean']; + $CONFIG_DATADIRECTORY=$CONFIG_DATADIRECTORY_ROOT.'/'.$user; if(!is_dir($CONFIG_DATADIRECTORY)){ mkdir($CONFIG_DATADIRECTORY); } @@ -165,7 +197,7 @@ class OC_UTIL { } //jail the user into his "home" directory - OC_FILESYSTEM::chroot('/'.$_SESSION['username_clean']); + OC_FILESYSTEM::chroot('/'.$user); self::$fsSetup=true; } } @@ -178,36 +210,6 @@ class OC_UTIL { return array(1,2,0); } - /** - * Create an url - * - * @param string $application - * @param string $file - */ - public static function linkTo( $application, $file = null ){ - global $WEBROOT; - if( is_null( $file )){ - $file = $application; - $application = ""; - } - return "$WEBROOT/$application/$file"; - } - - /** - * Create an image link - * - * @param string $application - * @param string $file - */ - public static function imagePath( $application, $file = null ){ - global $WEBROOT; - if( is_null( $file )){ - $file = $application; - $application = ""; - } - return "$WEBROOT/$application/img/$file"; - } - /** * add a javascript file * @@ -340,18 +342,6 @@ class OC_UTIL { } return false; } - - /** - * show an icon for a filetype - * - */ - public static function showIcon($filetype){ - global $WEBROOT; - if($filetype=='dir'){ echo(''); - }elseif($filetype=='foo'){ echo('foo'); - }else{ echo(''); - } - } } @@ -767,41 +757,4 @@ function chmodr($path, $filemode) { return FALSE; } -function oc_startup(){ - global $SERVERROOT; - global $DOCUMENTROOT; - global $WEBROOT; - global $CONFIG_DBNAME; - global $CONFIG_DBHOST; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; - global $CONFIG_DBTYPE; - global $CONFIG_DATADIRECTORY; - global $CONFIG_HTTPFORCESSL; - global $CONFIG_DATEFORMAT; - global $CONFIG_INSTALLED; - - // Add the stuff we need always - OC_UTIL::addPersonalMenuEntry( array( "file" => "index.php?logout=1", "name" => "Logout" )); - OC_UTIL::addScript( "jquery-1.5.min" ); - OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" ); - OC_UTIL::addScript( "js" ); - OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); - OC_UTIL::addStyle( "styles" ); - - // Require all appinfo.php - $dir = opendir( $SERVERROOT ); - while( false !== ( $filename = readdir( $dir ))){ - if( substr( $filename, 0, 1 ) != '.' ){ - if( file_exists( "$SERVERROOT/$filename/appinfo.php" )){ - oc_require( "$filename/appinfo.php" ); - } - } - } - closedir( $dir ); - - // Everything done - return true; -} - ?> diff --git a/lib/helper.php b/lib/helper.php new file mode 100644 index 00000000000..085ab67e737 --- /dev/null +++ b/lib/helper.php @@ -0,0 +1,84 @@ +. +* +*/ + + +/** + * Class for utility functions + * + */ +class OC_HELPER { + /** + * Create an url + * + * @param string $application + * @param string $file + */ + public static function linkTo( $application, $file = null ){ + global $WEBROOT; + if( is_null( $file )){ + $file = $application; + $application = ""; + } + return "$WEBROOT/$application/$file"; + } + + /** + * Create an image link + * + * @param string $application + * @param string $file + */ + public static function imagePath( $application, $file = null ){ + global $WEBROOT; + if( is_null( $file )){ + $file = $application; + $application = ""; + } + return "$WEBROOT/$application/img/$file"; + } + + /** + * show an icon for a filetype + * + */ + public static function showIcon( $mimetype ){ + global $SERVERROOT; + global $WEBROOT; + // Replace slash with a minus + $mimetype = str_replace( "/", "-", $mimetype ); + + // Is it a dir? + if( $mimetype == "dir" ){ + return "$WEBROOT/img/places/folder.png"; + } + + // Icon exists? + if( file_exists( "$SERVERROOT/img/mimetypes/$mimetype.png" )){ + return "$WEBROOT/img/mimetypes/$mimetype.png"; + } + else{ + return "$WEBROOT/img/mimetypes/application-octet-stream.png"; + } + } +} + +?> diff --git a/lib/template.php b/lib/template.php index 6415ab6a845..efa8dde8b9d 100644 --- a/lib/template.php +++ b/lib/template.php @@ -21,18 +21,20 @@ * */ +oc_include_once( "helper.php" ); + /** * */ function link_to( $app, $file ){ - return OC_UTIL::linkTo( $app, $file ); + return OC_HELPER::linkTo( $app, $file ); } /** * */ function image_path( $app, $file ){ - return OC_UTIL::imagePath( $app, $file ); + return OC_HELPER::imagePath( $app, $file ); } class OC_TEMPLATE{ @@ -67,7 +69,7 @@ class OC_TEMPLATE{ public function append( $a, $b ){ if( array_key_exists( $a, $this->vars )){ - if( is_a( $this->vars[$a], "array" )){ + if( is_array( $this->vars[$a] )){ $this->vars[$a][] = $b; } else -- cgit v1.2.3 From 94b405b64fdd1427873e49888fb0527640a10eb6 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Thu, 3 Mar 2011 21:25:22 +0100 Subject: Make it possible to use several datadirs. This could be useful if the user does not want his gallery images on the webdav storage. --- lib/base.php | 19 +++++++++---------- lib/template.php | 2 -- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index ac293cf193b..e379a4ba618 100644 --- a/lib/base.php +++ b/lib/base.php @@ -88,6 +88,7 @@ oc_require_once('ocs.php'); oc_require_once('connect.php'); oc_require_once('remotestorage.php'); oc_require_once('plugin.php'); +oc_require_once('helper.php'); OC_PLUGIN::loadPlugins(); @@ -139,7 +140,7 @@ class OC_UTIL { private static $fsSetup=false; // Can be set up - public static function setupFS( $user = "" ){// configure the initial filesystem based on the configuration + public static function setupFS( $user = "", $root = "files" ){// configure the initial filesystem based on the configuration if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble return false; } @@ -166,11 +167,9 @@ class OC_UTIL { //first set up the local "root" storage and the backupstorage if needed $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY)); if($CONFIG_ENABLEBACKUP){ - if(!is_dir($CONFIG_BACKUPDIRECTORY)){ - mkdir($CONFIG_BACKUPDIRECTORY); - } - if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$user )){ - mkdir($CONFIG_BACKUPDIRECTORY.'/'.$user ); + // This creates the Directorys recursively + if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ + mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0x777, true ); } $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); @@ -178,9 +177,9 @@ class OC_UTIL { } OC_FILESYSTEM::mount($rootStorage,'/'); - $CONFIG_DATADIRECTORY=$CONFIG_DATADIRECTORY_ROOT.'/'.$user; - if(!is_dir($CONFIG_DATADIRECTORY)){ - mkdir($CONFIG_DATADIRECTORY); + $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; + if( !is_dir( $CONFIG_DATADIRECTORY )){ + mkdir( $CONFIG_DATADIRECTORY, 0x777, true ); } //set up the other storages according to the system settings @@ -197,7 +196,7 @@ class OC_UTIL { } //jail the user into his "home" directory - OC_FILESYSTEM::chroot('/'.$user); + OC_FILESYSTEM::chroot("/$user/$root"); self::$fsSetup=true; } } diff --git a/lib/template.php b/lib/template.php index 79899efee49..cd576a89f94 100644 --- a/lib/template.php +++ b/lib/template.php @@ -21,8 +21,6 @@ * */ -oc_include_once( "helper.php" ); - /** * */ -- cgit v1.2.3 From ae5dc3efdffef75c48e5ef7cac6b40cd5720442b Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Thu, 3 Mar 2011 21:55:32 +0100 Subject: New classes for owncloud: OC_APP for applications, OC_PREFERENCES for user preferences --- admin/appinfo.php | 12 ------------ admin/appinfo/app.php | 12 ++++++++++++ admin/index.php | 2 +- files/appinfo.php | 6 ------ files/appinfo/app.php | 7 +++++++ lib/app.php | 40 ++++++++++++++++++++++++++++++++++++++++ lib/appconfig.php | 11 ----------- lib/base.php | 29 +++++------------------------ lib/preferences.php | 35 +++++++++++++++++++++++++++++++++++ log/appinfo.php | 6 ------ log/appinfo/app.php | 6 ++++++ settings/appinfo.php | 6 ------ settings/appinfo/app.php | 6 ++++++ 13 files changed, 112 insertions(+), 66 deletions(-) delete mode 100644 admin/appinfo.php create mode 100644 admin/appinfo/app.php delete mode 100644 files/appinfo.php create mode 100644 files/appinfo/app.php create mode 100644 lib/app.php create mode 100644 lib/preferences.php delete mode 100644 log/appinfo.php create mode 100644 log/appinfo/app.php delete mode 100644 settings/appinfo.php create mode 100644 settings/appinfo/app.php (limited to 'lib/base.php') diff --git a/admin/appinfo.php b/admin/appinfo.php deleted file mode 100644 index 0b2e4dbf85d..00000000000 --- a/admin/appinfo.php +++ /dev/null @@ -1,12 +0,0 @@ - "admin", "name" => "Administration" )); -if( OC_USER::ingroup( $_SESSION['username'], 'admin' )) -{ - OC_UTIL::addNavigationEntry( array( "app" => "admin", "file" => "index.php", "name" => "Administration" )); -} -OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "system.php", "name" => "System Settings" )); -OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "users.php", "name" => "Users" )); -OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "plugins.php", "name" => "Plugins" )); - -?> diff --git a/admin/appinfo/app.php b/admin/appinfo/app.php new file mode 100644 index 00000000000..befe8e678f0 --- /dev/null +++ b/admin/appinfo/app.php @@ -0,0 +1,12 @@ + "admin", "name" => "Administration" )); +if( OC_USER::ingroup( $_SESSION['username'], 'admin' )) +{ + OC_UTIL::addNavigationEntry( array( "app" => "admin", "file" => "index.php", "name" => "Administration" )); +} +OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "system.php", "name" => "System Settings" )); +OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "users.php", "name" => "Users" )); +OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "plugins.php", "name" => "Plugins" )); + +?> diff --git a/admin/index.php b/admin/index.php index cfcb70d056b..96fa2007244 100644 --- a/admin/index.php +++ b/admin/index.php @@ -30,7 +30,7 @@ if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' $adminpages = array(); -foreach( OC_UTIL::$adminpages as $i ){ +foreach( OC_APP::list() as $i ){ // Do some more work here soon $adminpages[] = $i; } diff --git a/files/appinfo.php b/files/appinfo.php deleted file mode 100644 index 44a533cf4a0..00000000000 --- a/files/appinfo.php +++ /dev/null @@ -1,6 +0,0 @@ - "files", "name" => "Files" )); -OC_UTIL::addNavigationEntry( array( "app" => "files", "file" => "index.php", "name" => "Files" )); - -?> diff --git a/files/appinfo/app.php b/files/appinfo/app.php new file mode 100644 index 00000000000..aa0054fc43d --- /dev/null +++ b/files/appinfo/app.php @@ -0,0 +1,7 @@ + "files", "name" => "Files" )); +OC_UTIL::addNavigationEntry( array( "app" => "files", "file" => "index.php", "name" => "Files" )); +OC_UTIL::addAdminPage( array( "app" => "files", "file" => "admin.php", "name" => "Files" )); + +?> diff --git a/lib/app.php b/lib/app.php new file mode 100644 index 00000000000..181af8a4faf --- /dev/null +++ b/lib/app.php @@ -0,0 +1,40 @@ + diff --git a/lib/appconfig.php b/lib/appconfig.php index f1bccc0a250..844d4cf54e8 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -1,16 +1,5 @@ $CONFIG_BACKUPDIRECTORY)); $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); @@ -179,7 +169,7 @@ class OC_UTIL { $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ - mkdir( $CONFIG_DATADIRECTORY, 0x777, true ); + mkdir( $CONFIG_DATADIRECTORY, 0x755, true ); } //set up the other storages according to the system settings @@ -253,15 +243,6 @@ class OC_UTIL { OC_UTIL::$adminpages[] = $entry; } - /** - * add application - * - * @param array $entry - */ - public static function addApplication( $entry){ - OC_UTIL::$applications[] = $entry; - } - /** * add an entry to the personal menu * diff --git a/lib/preferences.php b/lib/preferences.php new file mode 100644 index 00000000000..bd4ff55cc5c --- /dev/null +++ b/lib/preferences.php @@ -0,0 +1,35 @@ + diff --git a/log/appinfo.php b/log/appinfo.php deleted file mode 100644 index e4ffa79efe1..00000000000 --- a/log/appinfo.php +++ /dev/null @@ -1,6 +0,0 @@ - "log", "name" => "Log" )); -OC_UTIL::addNavigationEntry( array( "app" => "log", "file" => "index.php", "name" => "Log" )); - -?> diff --git a/log/appinfo/app.php b/log/appinfo/app.php new file mode 100644 index 00000000000..292d59ee578 --- /dev/null +++ b/log/appinfo/app.php @@ -0,0 +1,6 @@ + "log", "name" => "Log" )); +OC_UTIL::addNavigationEntry( array( "app" => "log", "file" => "index.php", "name" => "Log" )); + +?> diff --git a/settings/appinfo.php b/settings/appinfo.php deleted file mode 100644 index 232aaa0f0e7..00000000000 --- a/settings/appinfo.php +++ /dev/null @@ -1,6 +0,0 @@ - "settings", "name" => "Settings" )); -OC_UTIL::addNavigationEntry( array( "app" => "settings", "file" => "index.php", "name" => "Settings" )); - -?> diff --git a/settings/appinfo/app.php b/settings/appinfo/app.php new file mode 100644 index 00000000000..0db99441574 --- /dev/null +++ b/settings/appinfo/app.php @@ -0,0 +1,6 @@ + "settings", "name" => "Settings" )); +OC_UTIL::addNavigationEntry( array( "app" => "settings", "file" => "index.php", "name" => "Settings" )); + +?> -- cgit v1.2.3 From f7f957abb92e5ce359d7eafa136406822fee0a51 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Thu, 3 Mar 2011 23:08:11 +0100 Subject: Base for a more flexible navigation --- admin/appinfo/app.php | 10 +++++----- admin/img/navicon.png | Bin 0 -> 874 bytes admin/index.php | 2 +- admin/templates/index.php | 2 +- files/appinfo/app.php | 7 ++++--- files/img/navicon.png | Bin 0 -> 635 bytes img/actions/arrow-down.png | Bin 0 -> 525 bytes img/actions/arrow-left.png | Bin 0 -> 512 bytes img/actions/arrow-right.png | Bin 0 -> 527 bytes img/actions/arrow-up.png | Bin 0 -> 484 bytes lib/app.php | 12 +++++++----- lib/base.php | 10 +++++----- log/appinfo/app.php | 4 ++-- settings/appinfo/app.php | 2 +- templates/layout.admin.php | 7 +++---- templates/layout.user.php | 4 ++-- 16 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 admin/img/navicon.png create mode 100644 files/img/navicon.png create mode 100644 img/actions/arrow-down.png create mode 100644 img/actions/arrow-left.png create mode 100644 img/actions/arrow-right.png create mode 100644 img/actions/arrow-up.png (limited to 'lib/base.php') diff --git a/admin/appinfo/app.php b/admin/appinfo/app.php index befe8e678f0..3221e276c5f 100644 --- a/admin/appinfo/app.php +++ b/admin/appinfo/app.php @@ -1,12 +1,12 @@ "admin", "name" => "Administration" )); +OC_APP::register( array( "order" => 1, "id" => "admin", "name" => "Administration" )); if( OC_USER::ingroup( $_SESSION['username'], 'admin' )) { - OC_UTIL::addNavigationEntry( array( "app" => "admin", "file" => "index.php", "name" => "Administration" )); + OC_UTIL::addNavigationEntry( array( "id" => "admin_index", "order" => 1, "href" => OC_HELPER::linkTo( "admin", "index.php" ), "icon" => OC_HELPER::imagePath( "admin", "navicon.png" ), "name" => "Administration" )); } -OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "system.php", "name" => "System Settings" )); -OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "users.php", "name" => "Users" )); -OC_UTIL::addAdminPage( array( "app" => "admin", "file" => "plugins.php", "name" => "Plugins" )); +OC_UTIL::addAdminPage( array( "order" => 1, "href" => OC_HELPER::linkTo( "admin", "system.php" ), "name" => "System settings" )); +OC_UTIL::addAdminPage( array( "order" => 2, "href" => OC_HELPER::linkTo( "admin", "users.php" ), "name" => "Users" )); +OC_UTIL::addAdminPage( array( "order" => 3, "href" => OC_HELPER::linkTo( "admin", "plugins.php" ), "name" => "Plugins" )); ?> diff --git a/admin/img/navicon.png b/admin/img/navicon.png new file mode 100644 index 00000000000..f2c7c0867f6 Binary files /dev/null and b/admin/img/navicon.png differ diff --git a/admin/index.php b/admin/index.php index 96fa2007244..cfcb70d056b 100644 --- a/admin/index.php +++ b/admin/index.php @@ -30,7 +30,7 @@ if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' $adminpages = array(); -foreach( OC_APP::list() as $i ){ +foreach( OC_UTIL::$adminpages as $i ){ // Do some more work here soon $adminpages[] = $i; } diff --git a/admin/templates/index.php b/admin/templates/index.php index 56f85cbbbc5..f13d5634eac 100644 --- a/admin/templates/index.php +++ b/admin/templates/index.php @@ -7,6 +7,6 @@ diff --git a/files/appinfo/app.php b/files/appinfo/app.php index aa0054fc43d..8b1a806b7be 100644 --- a/files/appinfo/app.php +++ b/files/appinfo/app.php @@ -1,7 +1,8 @@ "files", "name" => "Files" )); -OC_UTIL::addNavigationEntry( array( "app" => "files", "file" => "index.php", "name" => "Files" )); -OC_UTIL::addAdminPage( array( "app" => "files", "file" => "admin.php", "name" => "Files" )); +OC_APP::register( array( "order" => 2, "id" => "files", "name" => "Files" )); + +OC_UTIL::addNavigationEntry( array( "id" => "files_index", "order" => 1, "href" => OC_HELPER::linkTo( "files", "index.php" ), "icon" => OC_HELPER::imagePath( "files", "navicon.png" ), "name" => "Files" )); +OC_UTIL::addAdminPage( array( "order" => 1, "href" => OC_HELPER::linkTo( "files", "admin.php" ), "name" => "Files" )); ?> diff --git a/files/img/navicon.png b/files/img/navicon.png new file mode 100644 index 00000000000..9ee717c8b12 Binary files /dev/null and b/files/img/navicon.png differ diff --git a/img/actions/arrow-down.png b/img/actions/arrow-down.png new file mode 100644 index 00000000000..03f201428ad Binary files /dev/null and b/img/actions/arrow-down.png differ diff --git a/img/actions/arrow-left.png b/img/actions/arrow-left.png new file mode 100644 index 00000000000..b56cfee03df Binary files /dev/null and b/img/actions/arrow-left.png differ diff --git a/img/actions/arrow-right.png b/img/actions/arrow-right.png new file mode 100644 index 00000000000..0acee70bcdd Binary files /dev/null and b/img/actions/arrow-right.png differ diff --git a/img/actions/arrow-up.png b/img/actions/arrow-up.png new file mode 100644 index 00000000000..5e423213fbd Binary files /dev/null and b/img/actions/arrow-up.png differ diff --git a/lib/app.php b/lib/app.php index 181af8a4faf..0bef7381262 100644 --- a/lib/app.php +++ b/lib/app.php @@ -6,13 +6,15 @@ class OC_APP{ /** * */ - public static function init(){ + public static function loadApps(){ + global $SERVERROOT; + // Get all appinfo $dir = opendir( $SERVERROOT ); while( false !== ( $filename = readdir( $dir ))){ if( substr( $filename, 0, 1 ) != '.' ){ - if( file_exists( "$SERVERROOT/$filename/appinfo.php" )){ - oc_require( "$filename/appinfo.php" ); + if( file_exists( "$SERVERROOT/$filename/appinfo/app.php" )){ + oc_require( "$filename/appinfo/app.php" ); } } } @@ -32,8 +34,8 @@ class OC_APP{ /** * */ - public static function list(){ - return OC_APP::$apps[]; + public static function getApps(){ + return OC_APP::$apps; } } diff --git a/lib/base.php b/lib/base.php index c7f0fea6820..09e0a1e299a 100644 --- a/lib/base.php +++ b/lib/base.php @@ -77,6 +77,7 @@ if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){ } // load core libs +oc_require_once('helper.php'); oc_require_once('app.php'); oc_require_once('files.php'); oc_require_once('filesystem.php'); @@ -89,7 +90,6 @@ oc_require_once('ocs.php'); oc_require_once('connect.php'); oc_require_once('remotestorage.php'); oc_require_once('plugin.php'); -oc_require_once('helper.php'); OC_PLUGIN::loadPlugins( "" ); @@ -104,15 +104,15 @@ if( !$RUNTIME_NOSETUPFS ){ } // Add the stuff we need always -OC_UTIL::addPersonalMenuEntry( array( "file" => "index.php?logout=1", "name" => "Logout" )); +OC_UTIL::addPersonalMenuEntry( array( "order" => 1000, "href" => OC_HELPER::linkTo( "", "index.php?logout=1" ), "name" => "Logout" )); OC_UTIL::addScript( "jquery-1.5.min" ); OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" ); OC_UTIL::addScript( "js" ); OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); OC_UTIL::addStyle( "styles" ); -// Require all appinfo.php -OC_APP::init(); +// Load Apps +OC_APP::loadApps(); // check if the server is correctly configured for ownCloud OC_UTIL::checkserver(); @@ -239,7 +239,7 @@ class OC_UTIL { * * @param array $entry */ - public static function addAdminPage( $entry){ + public static function addAdminPage( $entry ){ OC_UTIL::$adminpages[] = $entry; } diff --git a/log/appinfo/app.php b/log/appinfo/app.php index 292d59ee578..e639982a89c 100644 --- a/log/appinfo/app.php +++ b/log/appinfo/app.php @@ -1,6 +1,6 @@ "log", "name" => "Log" )); -OC_UTIL::addNavigationEntry( array( "app" => "log", "file" => "index.php", "name" => "Log" )); +OC_APP::register( array( "order" => 1, "id" => "log", "name" => "Log" )); +OC_UTIL::addPersonalMenuEntry( array( "order" => 2, "href" => OC_HELPER::linkTo( "log", "index.php" ), "name" => "Log" )); ?> diff --git a/settings/appinfo/app.php b/settings/appinfo/app.php index 0db99441574..c43d47f0dd6 100644 --- a/settings/appinfo/app.php +++ b/settings/appinfo/app.php @@ -1,6 +1,6 @@ "settings", "name" => "Settings" )); -OC_UTIL::addNavigationEntry( array( "app" => "settings", "file" => "index.php", "name" => "Settings" )); +OC_UTIL::addPersonalMenuEntry( array( "order" => 1, "href" => OC_HELPER::linkTo( "settings", "index.php" ), "name" => "Settings" )); ?> diff --git a/templates/layout.admin.php b/templates/layout.admin.php index b4fcc915882..849ed6656be 100644 --- a/templates/layout.admin.php +++ b/templates/layout.admin.php @@ -25,7 +25,7 @@ Username @@ -34,9 +34,8 @@
diff --git a/templates/layout.user.php b/templates/layout.user.php index 0643c99e933..ff845a9b957 100644 --- a/templates/layout.user.php +++ b/templates/layout.user.php @@ -25,7 +25,7 @@ Username
@@ -35,7 +35,7 @@ -- cgit v1.2.3 From 883c7a582de8e9f9455751927069755e74fbd1e3 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Fri, 11 Mar 2011 15:25:48 +0100 Subject: Small fixes in OC_APP, removed functions in OC_UTIL that now are in OC_APP --- lib/app.php | 45 +++++++++++++++++++++++++++++++++++++-------- lib/base.php | 30 ------------------------------ 2 files changed, 37 insertions(+), 38 deletions(-) (limited to 'lib/base.php') diff --git a/lib/app.php b/lib/app.php index f71c1c70153..72b6693686e 100644 --- a/lib/app.php +++ b/lib/app.php @@ -1,7 +1,32 @@ . + * + */ + class OC_APP{ static private $init = false; static private $apps = array(); + static private $adminpages = array(); + static private $navigation = array(); + static private $personalmenu = array(); /** * @brief loads all apps @@ -45,6 +70,7 @@ class OC_APP{ * The following keys are required: * - id: id of the application, has to be unique ("addressbook") * - name: Human readable name ("Addressbook") + * - version: array with Version (major, minor, bugfix) ( array(1, 0, 2)) * * The following keys are optional: * - order: integer, that influences the position of your application in @@ -84,6 +110,7 @@ class OC_APP{ */ public static function addNavigationEntry( $data ){ // TODO: write function + OC_APP::$navigation[] = $data; return true; } @@ -144,6 +171,7 @@ class OC_APP{ */ public static function addPersonalMenuEntry( $data ){ // TODO: write function + OC_APP::$personalmenu[] = $data; return true; } @@ -165,6 +193,7 @@ class OC_APP{ */ public static function addAdminPage( $data = array()){ // TODO: write function + OC_APP::$adminpages[] = $data; return true; } @@ -179,9 +208,9 @@ class OC_APP{ * - children: array that is empty if the key "active" is false or * contains the subentries if the key "active" is true */ - public static function getNavigation( $data = array()){ + public static function getNavigation(){ // TODO: write function - return true; + return OC_APP::$navigation; } /** @@ -191,9 +220,9 @@ class OC_APP{ * This function returns an array containing all personal menu entries * added. The entries are sorted by the key "order" ascending. */ - public static function getPersonalMenu( $data = array()){ + public static function getPersonalMenu(){ // TODO: write function - return true; + return OC_APP::$personalmenu; } /** @@ -203,13 +232,13 @@ class OC_APP{ * This function returns an array containing all admin pages added. The * entries are sorted by the key "order" ascending. */ - public static function getAdminPages( $data = array()){ + public static function getAdminPages(){ // TODO: write function - return true; + return OC_APP::$adminpages; } /** - * @brief Installs an appl + * @brief Installs an app * @param $data array with all information * @returns integer * @@ -285,7 +314,7 @@ class OC_APP{ * @returns true/false * * This function removes an app. $options is an associative array. The - * following keys are optional: + * following keys are optional:ja * - keeppreferences: boolean, if true the user preferences won't be deleted * - keepappconfig: boolean, if true the config will be kept * - keeptables: boolean, if true the database will be kept diff --git a/lib/base.php b/lib/base.php index 09e0a1e299a..c99de774c2d 100644 --- a/lib/base.php +++ b/lib/base.php @@ -124,9 +124,6 @@ OC_UTIL::checkserver(); class OC_UTIL { public static $scripts=array(); public static $styles=array(); - public static $adminpages = array(); - public static $navigation = array(); - public static $personalmenu = array(); private static $fsSetup=false; // Can be set up @@ -225,33 +222,6 @@ class OC_UTIL { self::$styles[] = "$application/css/$file"; } - /** - * add an entry to the main navigation - * - * @param array $entry - */ - public static function addNavigationEntry( $entry){ - OC_UTIL::$navigation[] = $entry; - } - - /** - * add administration pages - * - * @param array $entry - */ - public static function addAdminPage( $entry ){ - OC_UTIL::$adminpages[] = $entry; - } - - /** - * add an entry to the personal menu - * - * @param array $entry - */ - public static function addPersonalMenuEntry( $entry){ - OC_UTIL::$personalmenu[] = $entry; - } - /** * check if the current server configuration is suitable for ownCloud * -- cgit v1.2.3 From 1df039716391d0708168ee6fd0c2c2ad4bac8059 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 6 Feb 2011 01:54:07 +0100 Subject: only load mdb2 once as it was before --- lib/base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index c99de774c2d..01a53656789 100644 --- a/lib/base.php +++ b/lib/base.php @@ -315,8 +315,8 @@ class OC_DB { global $CONFIG_DBTYPE; global $DOCUMENTROOT; global $SERVERROOT; - @oc_require_once('MDB2.php'); if(!self::$DBConnection){ + @oc_require_once('MDB2.php'); $options = array( 'portability' => MDB2_PORTABILITY_ALL, 'log_line_break' => '
', @@ -362,8 +362,8 @@ class OC_DB { public static function connectScheme(){ self::connect(); - @oc_require_once('MDB2/Schema.php'); if(!self::$schema){ + @oc_require_once('MDB2/Schema.php'); self::$schema=&MDB2_Schema::factory(self::$DBConnection); } } -- cgit v1.2.3 From 0f494970d1b299171ff36ef395adb444bf775355 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 18 Mar 2011 14:12:06 +0100 Subject: Fix a couple of minor coding errors --- admin/appinfo/app.php | 8 ++++---- admin/index.php | 2 +- admin/system.php | 2 +- files/appinfo/app.php | 4 ++-- lib/app.php | 6 +++--- lib/base.php | 2 +- lib/template.php | 6 +++--- log/appinfo/app.php | 2 +- settings/appinfo/app.php | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) (limited to 'lib/base.php') diff --git a/admin/appinfo/app.php b/admin/appinfo/app.php index 3221e276c5f..f4a36160936 100644 --- a/admin/appinfo/app.php +++ b/admin/appinfo/app.php @@ -3,10 +3,10 @@ OC_APP::register( array( "order" => 1, "id" => "admin", "name" => "Administration" )); if( OC_USER::ingroup( $_SESSION['username'], 'admin' )) { - OC_UTIL::addNavigationEntry( array( "id" => "admin_index", "order" => 1, "href" => OC_HELPER::linkTo( "admin", "index.php" ), "icon" => OC_HELPER::imagePath( "admin", "navicon.png" ), "name" => "Administration" )); + OC_APP::addNavigationEntry( array( "id" => "admin_index", "order" => 1, "href" => OC_HELPER::linkTo( "admin", "index.php" ), "icon" => OC_HELPER::imagePath( "admin", "navicon.png" ), "name" => "Administration" )); } -OC_UTIL::addAdminPage( array( "order" => 1, "href" => OC_HELPER::linkTo( "admin", "system.php" ), "name" => "System settings" )); -OC_UTIL::addAdminPage( array( "order" => 2, "href" => OC_HELPER::linkTo( "admin", "users.php" ), "name" => "Users" )); -OC_UTIL::addAdminPage( array( "order" => 3, "href" => OC_HELPER::linkTo( "admin", "plugins.php" ), "name" => "Plugins" )); +OC_APP::addAdminPage( array( "order" => 1, "href" => OC_HELPER::linkTo( "admin", "system.php" ), "name" => "System settings" )); +OC_APP::addAdminPage( array( "order" => 2, "href" => OC_HELPER::linkTo( "admin", "users.php" ), "name" => "Users" )); +OC_APP::addAdminPage( array( "order" => 3, "href" => OC_HELPER::linkTo( "admin", "plugins.php" ), "name" => "Plugins" )); ?> diff --git a/admin/index.php b/admin/index.php index cfcb70d056b..5d8ac140511 100644 --- a/admin/index.php +++ b/admin/index.php @@ -30,7 +30,7 @@ if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' $adminpages = array(); -foreach( OC_UTIL::$adminpages as $i ){ +foreach( OC_APP::getAdminPages() as $i ){ // Do some more work here soon $adminpages[] = $i; } diff --git a/admin/system.php b/admin/system.php index cfcb70d056b..5d8ac140511 100644 --- a/admin/system.php +++ b/admin/system.php @@ -30,7 +30,7 @@ if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' $adminpages = array(); -foreach( OC_UTIL::$adminpages as $i ){ +foreach( OC_APP::getAdminPages() as $i ){ // Do some more work here soon $adminpages[] = $i; } diff --git a/files/appinfo/app.php b/files/appinfo/app.php index 8b1a806b7be..a3532e805d2 100644 --- a/files/appinfo/app.php +++ b/files/appinfo/app.php @@ -2,7 +2,7 @@ OC_APP::register( array( "order" => 2, "id" => "files", "name" => "Files" )); -OC_UTIL::addNavigationEntry( array( "id" => "files_index", "order" => 1, "href" => OC_HELPER::linkTo( "files", "index.php" ), "icon" => OC_HELPER::imagePath( "files", "navicon.png" ), "name" => "Files" )); -OC_UTIL::addAdminPage( array( "order" => 1, "href" => OC_HELPER::linkTo( "files", "admin.php" ), "name" => "Files" )); +OC_APP::addNavigationEntry( array( "id" => "files_index", "order" => 1, "href" => OC_HELPER::linkTo( "files", "index.php" ), "icon" => OC_HELPER::imagePath( "files", "navicon.png" ), "name" => "Files" )); +OC_APP::addAdminPage( array( "order" => 1, "href" => OC_HELPER::linkTo( "files", "admin.php" ), "name" => "Files" )); ?> diff --git a/lib/app.php b/lib/app.php index 203bf7b684c..ecab723a6ad 100644 --- a/lib/app.php +++ b/lib/app.php @@ -45,8 +45,8 @@ class OC_APP{ global $SERVERROOT; // Did we allready load everything? - if( $self::init ){ - return true + if( self::$init ){ + return true; } // Get all appinfo @@ -60,7 +60,7 @@ class OC_APP{ } closedir( $dir ); - $self::init = true; + self::$init = true; // return return true; diff --git a/lib/base.php b/lib/base.php index 01a53656789..75914d61688 100644 --- a/lib/base.php +++ b/lib/base.php @@ -104,7 +104,7 @@ if( !$RUNTIME_NOSETUPFS ){ } // Add the stuff we need always -OC_UTIL::addPersonalMenuEntry( array( "order" => 1000, "href" => OC_HELPER::linkTo( "", "index.php?logout=1" ), "name" => "Logout" )); +OC_APP::addPersonalMenuEntry( array( "order" => 1000, "href" => OC_HELPER::linkTo( "", "index.php?logout=1" ), "name" => "Logout" )); OC_UTIL::addScript( "jquery-1.5.min" ); OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" ); OC_UTIL::addScript( "js" ); diff --git a/lib/template.php b/lib/template.php index 6184e4f59a2..12a32c1f052 100644 --- a/lib/template.php +++ b/lib/template.php @@ -99,8 +99,8 @@ class OC_TEMPLATE{ $template = "$SERVERROOT/$app/templates/"; } - // Templates have the ending .tmpl - $template .= "$name.html"; + // Templates have the ending .php + $template .= "$name.php"; // Set the private data $this->renderas = $renderas; @@ -206,7 +206,7 @@ class OC_TEMPLATE{ // Add navigation entry and personal menu $page->assign( "navigation", OC_APP::getNavigation()); - $page->assign( "personalmenu", OC_UTIL::getPersonalMenu()); + $page->assign( "personalmenu", OC_APP::getPersonalMenu()); // Add css files and js files $page->assign( "content", $data ); diff --git a/log/appinfo/app.php b/log/appinfo/app.php index e639982a89c..d3e848e9606 100644 --- a/log/appinfo/app.php +++ b/log/appinfo/app.php @@ -1,6 +1,6 @@ 1, "id" => "log", "name" => "Log" )); -OC_UTIL::addPersonalMenuEntry( array( "order" => 2, "href" => OC_HELPER::linkTo( "log", "index.php" ), "name" => "Log" )); +OC_APP::addPersonalMenuEntry( array( "order" => 2, "href" => OC_HELPER::linkTo( "log", "index.php" ), "name" => "Log" )); ?> diff --git a/settings/appinfo/app.php b/settings/appinfo/app.php index c43d47f0dd6..a7813893036 100644 --- a/settings/appinfo/app.php +++ b/settings/appinfo/app.php @@ -1,6 +1,6 @@ "settings", "name" => "Settings" )); -OC_UTIL::addPersonalMenuEntry( array( "order" => 1, "href" => OC_HELPER::linkTo( "settings", "index.php" ), "name" => "Settings" )); +OC_APP::addPersonalMenuEntry( array( "order" => 1, "href" => OC_HELPER::linkTo( "settings", "index.php" ), "name" => "Settings" )); ?> -- cgit v1.2.3 From d3502315bda8e21e3daa29e5a4dbb2031e7ba522 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Tue, 29 Mar 2011 20:21:00 +0200 Subject: added class OC_HOOK to base.php. It is in base.php because it is needed very ofter and it is quite small. --- lib/base.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 10 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 75914d61688..e38b76fff90 100644 --- a/lib/base.php +++ b/lib/base.php @@ -280,21 +280,75 @@ class OC_UTIL { die($error); } } +} - /** - * check if we need to use the layout optimized for smaller screen, currently only checks for iPhone/Android - * @return bool - */ - public static function hasSmallScreen(){ - $userAgent=strtolower($_SERVER['HTTP_USER_AGENT']); - if(strpos($userAgent,'android') or strpos($userAgent,'iphone') or strpos($userAgent,'ipod')){//todo, add support for more devices - return true; +/** + * This class manages the hooks. It basically provides two functions: adding + * slots and emitting signals. + */ +class OC_HOOK{ + static private $registered = array(); + + /** + * @brief connects a function to a hook + * @param $signalclass class name of emitter + * @param $signalname name of signal + * @param $slotclass class name of slot + * @param $slotname name of slot + * @returns true/false + * + * This function makes it very easy to connect to use hooks. + * + * TODO: write example + */ + public function connect( $signalclass, $signalname, $slotclass, $slotname ){ + // Cerate the data structure + if( !array_key_exists( $signalclass, self::$registered )){ + self::$registered[$signalclass] = array(); + } + if( !array_key_exists( $signalname, self::$registered[$signalclass] )){ + self::$registered[$signalclass][$signalname] = array(); + } + + // register hook + self::$registered[$signalclass][$signalname][] = array( + "class" => $slotclass, + "name" => $slotname ); + + // No chance for failure ;-) + return true; + } + + /** + * @brief emitts a signal + * @param $signalclass class name of emitter + * @param $signalname name of signal + * @param $params defautl: array() array with additional data + * @returns true if slots exists or false if not + * + * Emits a signal. To get data from the slot use references! + * + * TODO: write example + */ + public function emit( $signalclass, $signalname, $params = array()){ + // Return false if there are no slots + if( !array_key_exists( $signalclass, self::$registered )){ + return false; } - return false; + if( !array_key_exists( $signalname, self::$registered[$signalclass] )){ + return false; + } + + // Call all slots + foreach( $registered[$signalclass][$signalname] as $i ){ + call_user_func( array( $i["class"], $i["name"] ), $params ); + } + + // return true + return true; } } - /** * Class for database access * -- cgit v1.2.3 From 908e377246cd770b7a3f9f2f4d929e29ffb22f25 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Fri, 8 Apr 2011 16:53:17 +0200 Subject: Refactoring of OC_DB --- lib/base.php | 414 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 218 insertions(+), 196 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index e38b76fff90..3bf74e233a5 100644 --- a/lib/base.php +++ b/lib/base.php @@ -350,18 +350,23 @@ class OC_HOOK{ } /** - * Class for database access - * + * This class manages the access to the database. It basically is a wrapper for + * MDB2 with some adaptions. */ class OC_DB { static private $DBConnection=false; static private $schema=false; static private $affected=0; static private $result=false; + /** - * connect to the datbase if not already connected - */ - public static function connect(){ + * @brief connects to the database + * @returns true if connection can be established or nothing (die()) + * + * Connects to the database as specified in config.php + */ + static public function connect(){ + // The global data we need global $CONFIG_DBNAME; global $CONFIG_DBHOST; global $CONFIG_DBUSER; @@ -369,8 +374,13 @@ class OC_DB { global $CONFIG_DBTYPE; global $DOCUMENTROOT; global $SERVERROOT; + + // do nothing if the connection already has been established if(!self::$DBConnection){ + // Require MDB2.php (TODO: why here not in head of file?) @oc_require_once('MDB2.php'); + + // Prepare options array $options = array( 'portability' => MDB2_PORTABILITY_ALL, 'log_line_break' => '
', @@ -378,249 +388,261 @@ class OC_DB { 'debug' => true, 'quote_identifier' => true, ); + + // Add the dsn according to the database type if($CONFIG_DBTYPE=='sqlite'){ + // sqlite $dsn = array( - 'phptype' => 'sqlite', - 'database' => $SERVERROOT.'/'.$CONFIG_DBNAME, - 'mode' => '0644', - ); - }elseif($CONFIG_DBTYPE=='mysql'){ + 'phptype' => 'sqlite', + 'database' => "$SERVERROOT/$CONFIG_DBNAME", + 'mode' => '0644' ); + } + elseif($CONFIG_DBTYPE=='mysql'){ + // MySQL $dsn = array( - 'phptype' => 'mysql', - 'username' => $CONFIG_DBUSER, - 'password' => $CONFIG_DBPASSWORD, - 'hostspec' => $CONFIG_DBHOST, - 'database' => $CONFIG_DBNAME, - ); - }elseif($CONFIG_DBTYPE=='pgsql'){ + 'phptype' => 'mysql', + 'username' => $CONFIG_DBUSER, + 'password' => $CONFIG_DBPASSWORD, + 'hostspec' => $CONFIG_DBHOST, + 'database' => $CONFIG_DBNAME ); + } + elseif($CONFIG_DBTYPE=='pgsql'){ + // PostgreSQL $dsn = array( - 'phptype' => 'pgsql', - 'username' => $CONFIG_DBUSER, - 'password' => $CONFIG_DBPASSWORD, - 'hostspec' => $CONFIG_DBHOST, - 'database' => $CONFIG_DBNAME, - ); + 'phptype' => 'pgsql', + 'username' => $CONFIG_DBUSER, + 'password' => $CONFIG_DBPASSWORD, + 'hostspec' => $CONFIG_DBHOST, + 'database' => $CONFIG_DBNAME ); } - self::$DBConnection=MDB2::factory($dsn,$options); - - if (PEAR::isError(self::$DBConnection)) { - echo('can not connect to database, using '.$CONFIG_DBTYPE.'. ('.self::$DBConnection->getUserInfo().')'); - $error=self::$DBConnection->getMessage(); - error_log("$error"); - error_log(self::$DBConnection->getUserInfo()); - die($error); + + // Try to establish connection + self::$DBConnection = MDB2::factory( $dsn, $options ); + + // Die if we could not connect + if( PEAR::isError( self::$DBConnection )){ + echo( 'can not connect to database, using '.$CONFIG_DBTYPE.'. ('.self::$DBConnection->getUserInfo().')'); + $error = self::$DBConnection->getMessage(); + error_log( $error); + error_log( self::$DBConnection->getUserInfo()); + die( $error ); } + + // We always, really always want associative arrays self::$DBConnection->setFetchMode(MDB2_FETCHMODE_ASSOC); } - } - public static function connectScheme(){ - self::connect(); - if(!self::$schema){ - @oc_require_once('MDB2/Schema.php'); - self::$schema=&MDB2_Schema::factory(self::$DBConnection); - } + // we are done. great! + return true; } /** - * executes a query on the database + * @brief SQL query + * @param $query Query string + * @returns result as MDB2_Result * - * @param string $cmd - * @return result-set + * SQL query via MDB2 query() */ - static function query($cmd){ - global $CONFIG_DBTYPE; - if(!trim($cmd)){ - return false; - } - OC_DB::connect(); - //fix differences between sql versions + static public function query( $query ){ + // Optimize the query + $query = self::processQuery( $query ); - //differences in escaping of table names (` for mysql) - if($CONFIG_DBTYPE=='sqlite'){ - $cmd=str_replace('`','\'',$cmd); - }elseif($CONFIG_DBTYPE=='pgsql'){ - $cmd=str_replace('`','"',$cmd); - } - $result=self::$DBConnection->exec($cmd); - if (PEAR::isError($result)) { - $entry='DB Error: "'.$result->getMessage().'"
'; - $entry.='Offending command was: '.$cmd.'
'; - error_log($entry); - die($entry); - }else{ - self::$affected=$result; - } - self::$result=$result; - return $result; - } + self::connect(); + //fix differences between sql versions - /** - * executes a query on the database and returns the result in an array - * - * @param string $cmd - * @return result-set - */ - static function select($cmd){ - OC_DB::connect(); - global $CONFIG_DBTYPE; - //fix differences between sql versions + // return the result + $result = self::$DBConnection->exec( $query ); - //differences in escaping of table names (` for mysql) - if($CONFIG_DBTYPE=='sqlite'){ - $cmd=str_replace('`','\'',$cmd); - }elseif($CONFIG_DBTYPE=='pgsql'){ - $cmd=str_replace('`','"',$cmd); - } - $result=self::$DBConnection->queryAll($cmd); - if (PEAR::isError($result)){ - $entry='DB Error: "'.$result->getMessage().'"
'; - $entry.='Offending command was: '.$cmd.'
'; - die($entry); + // Die if we have an error (error means: bad query, not 0 results!) + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"
'; + $entry .= 'Offending command was: '.$cmd.'
'; + error_log( $entry ); + die( $entry ); } + return $result; } /** - * executes multiply queries on the database - * - * @param string $cmd - * @return result-set - */ - static function multiquery($cmd) { - $queries=explode(';',$cmd); - foreach($queries as $query){ - OC_DB::query($query); - } - return true; - } - + * @brief Prepare a SQL query + * @param $query Query string + * @returns prepared SQL query + * + * SQL query via MDB2 prepare(), needs to be execute()'d! + */ + static public function prepare( $query ){ + // Optimize the query + $query = self::processQuery( $query ); - /** - * closing a db connection - * - * @return bool - */ - static function close() { - self::$DBConnection->disconnect(); - self::$DBConnection=false; - } + self::connect(); + //fix differences between sql versions + // return the result + $result = self::$DBConnection->prepare( $query ); - /** - * Returning primarykey if last statement was an insert. - * - * @return primarykey - */ - static function insertid() { - $id=self::$DBConnection->lastInsertID(); - return $id; - } + // Die if we have an error (error means: bad query, not 0 results!) + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"
'; + $entry .= 'Offending command was: '.$cmd.'
'; + error_log( $entry ); + die( $entry ); + } - /** - * Returning number of rows in a result - * - * @param resultset $result - * @return int - */ - static function numrows($result) { - $result->numRows(); - } - /** - * Returning number of affected rows - * - * @return int - */ - static function affected_rows() { - return self::$affected; - } - - /** - * get a field from the resultset - * - * @param resultset $result - * @param int $i - * @param int $field - * @return unknown - */ - static function result($result, $i, $field) { - $tmp=$result->fetchRow(MDB2_FETCHMODE_ASSOC,$i); - $tmp=$tmp[$field]; - return($tmp); + return $result; } /** - * get data-array from resultset - * - * @param resultset $result - * @return data - */ - static function fetch_assoc($result){ - return $result->fetchRow(MDB2_FETCHMODE_ASSOC); + * @brief gets last value of autoincrement + * @returns id + * + * MDB2 lastInsertID() + * + * Call this method right after the insert command or other functions may + * cause trouble! + */ + public static function insertid(){ + self::connect(); + return self::$DBConnection->lastInsertID(); } /** - * Freeing resultset (performance) - * - * @param unknown_type $result - * @return bool - */ - static function free_result() { - if(self::$result){ - self::$result->free(); - self::$result=false; - } - } - - static public function disconnect(){ + * @brief Disconnect + * @returns true/false + * + * This is good bye, good bye, yeah! + */ + public static function disconnect(){ + // Cut connection if required if(self::$DBConnection){ self::$DBConnection->disconnect(); self::$DBConnection=false; } + + return true; } /** - * escape strings so they can be used in queries - * - * @param string string - * @return string - */ - static function escape($string){ - OC_DB::connect(); - return self::$DBConnection->escape($string); - } - - static function getDbStructure($file){ - OC_DB::connectScheme(); + * @brief Escapes bad characters + * @param $string string with dangerous characters + * @returns escaped string + * + * MDB2 escape() + */ + public static function escape( $string ){ + self::connect(); + return self::$DBConnection->escape( $string ); + } + + /** + * @brief saves database scheme to xml file + * @param $file name of file + * @returns true/false + * + * TODO: write more documentation + */ + public static function getDbStructure( $file ){ + self::connectScheme(); + + // write the scheme $definition = self::$schema->getDefinitionFromDatabase(); $dump_options = array( 'output_mode' => 'file', 'output' => $file, 'end_of_line' => "\n" ); - self::$schema->dumpDatabase($definition, $dump_options, MDB2_SCHEMA_DUMP_STRUCTURE); + self::$schema->dumpDatabase( $definition, $dump_options, MDB2_SCHEMA_DUMP_STRUCTURE ); + + return true; } - static function createDbFromStructure($file){ - OC_DB::connectScheme(); + /** + * @brief Creates tables from XML file + * @param $file file to read structure from + * @returns true/false + * + * TODO: write more documentation + */ + public static function createDbFromStructure( $file ){ global $CONFIG_DBNAME; global $CONFIG_DBTABLEPREFIX; - $content=file_get_contents($file); - $file2=tempnam(sys_get_temp_dir(),'oc_db_scheme_'); - $content=str_replace('*dbname*',$CONFIG_DBNAME,$content); - $content=str_replace('*dbprefix*',$CONFIG_DBTABLEPREFIX,$content); - file_put_contents($file2,$content); - $definition=@self::$schema->parseDatabaseDefinitionFile($file2); - unlink($file2); - if($definition instanceof MDB2_Schema_Error){ - die($definition->getMessage() . ': ' . $definition->getUserInfo()); + + self::connectScheme(); + + // read file + $content = file_get_contents( $file ); + + // Make changes and save them to a temporary file + $file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' ); + $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); + $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content ); + file_put_contents( $file2, $content ); + + // Try to create tables + $definition = @self::$schema->parseDatabaseDefinitionFile( $file2 ); + + // Delete our temporary file + unlink( $file2 ); + + // Die in case something went wrong + if( $definition instanceof MDB2_Schema_Error ){ + die( $definition->getMessage().': '.$definition->getUserInfo()); } - $ret=@self::$schema->createDatabase($definition); - if($ret instanceof MDB2_Error) { + $ret=@self::$schema->createDatabase( $definition ); + + // Die in case something went wrong + if( $ret instanceof MDB2_Error ){ die ($ret->getMessage() . ': ' . $ret->getUserInfo()); - }else{ - return true; } + + return true; + } + + /** + * @brief connects to a MDB2 database scheme + * @returns true/false + * + * Connects to a MDB2 database scheme + */ + private static function connectScheme(){ + // We need a database connection + self::connect(); + + // Connect if this did not happen before + if(!self::$schema){ + @oc_require_once('MDB2/Schema.php'); + self::$schema=&MDB2_Schema::factory(self::$DBConnection); + } + + return true; + } + + /** + * @brief does minor chages to query + * @param $query Query string + * @returns corrected query string + * + * This function replaces *PREFIX* with the value of $CONFIG_DBTABLEPREFIX + * and replaces the ` woth ' or " according to the database driver. + */ + private static function processQuery( $query ){ + // We need Database type and table prefix + global $CONFIG_DBTYPE; + global $CONFIG_DBTABLEPREFIX; + + // differences in escaping of table names (` for mysql) + // Problem: what if there is a ` in the value we want to insert? + if( $CONFIG_DBTYPE == 'sqlite' ){ + $query = str_replace( '`', '\'', $query ); + } + elseif( $CONFIG_DBTYPE == 'pgsql' ){ + $query = str_replace( '`', '"', $query ); + } + + // replace table names + $query = str_replace( '*PREFIX*', $CONFIG_DBTABLEPREFIX, $query ); + + return $query; } } -- cgit v1.2.3 From 149793f2e7c701434698a1e6f8af251fe786d320 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Fri, 15 Apr 2011 17:14:02 +0200 Subject: First version of the new user management --- lib/Group/backend.php | 74 +++++++++ lib/Group/database.php | 138 +++++++++++++++++ lib/User/backend.php | 118 +++------------ lib/User/database.php | 400 +++++++++---------------------------------------- lib/base.php | 4 +- lib/group.php | 137 +++++++++++++++++ lib/user.php | 268 +++++++++++---------------------- 7 files changed, 526 insertions(+), 613 deletions(-) create mode 100644 lib/Group/backend.php create mode 100644 lib/Group/database.php create mode 100644 lib/group.php (limited to 'lib/base.php') diff --git a/lib/Group/backend.php b/lib/Group/backend.php new file mode 100644 index 00000000000..c70bd6665cb --- /dev/null +++ b/lib/Group/backend.php @@ -0,0 +1,74 @@ +. +* +*/ + + + +/** + * Base class for user management + * + */ +abstract class OC_GROUP_BACKEND { + /** + * Try to create a new group + * + * @param string $groupName The name of the group to create + */ + abstract public static function createGroup($groupName); + + /** + * Check if a user belongs to a group + * + * @param string $username Name of the user to check + * @param string $groupName Name of the group + */ + abstract public static function inGroup($username, $groupName); + + /** + * Add a user to a group + * + * @param string $username Name of the user to add to group + * @param string $groupName Name of the group in which add the user + */ + abstract public static function addToGroup($username, $groupName); + + /** + * Remove a user from a group + * + * @param string $username Name of the user to remove from group + * @param string $groupName Name of the group from which remove the user + */ + abstract public static function removeFromGroup($username,$groupName); + + /** + * Get all groups the user belongs to + * + * @param string $username Name of the user + */ + abstract public static function getUserGroups($username); + + /** + * get a list of all groups + * + */ + abstract public static function getGroups(); +} diff --git a/lib/Group/database.php b/lib/Group/database.php new file mode 100644 index 00000000000..8e7f1203cd2 --- /dev/null +++ b/lib/Group/database.php @@ -0,0 +1,138 @@ +. + * + */ +/* + * + * The following SQL statement is just a help for developers and will not be + * executed! + * + * CREATE TABLE `groups` ( + * `gid` varchar(64) COLLATE utf8_unicode_ci NOT NULL, + * PRIMARY KEY (`gid`) + * ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + * + * CREATE TABLE `group_user` ( + * `gid` varchar(64) COLLATE utf8_unicode_ci NOT NULL, + * `uid` varchar(64) COLLATE utf8_unicode_ci NOT NULL + * ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + * + */ + +oc_require_once( 'Group/backend.php' ); + +/** + * Class for group management in a SQL Database (e.g. MySQL, SQLite) + * + */ +class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { + static private $userGroupCache=array(); + + /** + * Try to create a new group + * + * @param string $groupName The name of the group to create + */ + public static function createGroup( $gid ){ + $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*groups` WHERE `gid` = ?" ); + $result = $query->execute( $gid ); + + if( $result->numRows() > 0 ){ + return false; + } + else{ + $query = OC_DB::prepare( "INSERT INTO `*PREFIX*groups` ( `gid` ) VALUES( ? )" ); + $result = $query->prepare( $gid ); + + return $result ? true : false; + } + } + + /** + * Check if a user belongs to a group + * + * @param string $username Name of the user to check + * @param string $groupName Name of the group + */ + public static function inGroup($username,$groupName) { + $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` = ?" ); + $result = $query->execute( $groupName, $username ); + + return $result->numRows() > 0 ? true : false; + } + + /** + * Add a user to a group + * + * @param string $username Name of the user to add to group + * @param string $groupName Name of the group in which add the user + */ + public static function addToGroup($username, $groupName) { + if( !OC_USER::inGroup( $username, $groupName )){ + $query = OC_DB::prepare( "INSERT INTO `*PREFIX*group_user` ( `uid`, `gid` ) VALUES( ?, ? )" ); + $result = $query->execute( $username, $groupName ); + } + } + + /** + * Remove a user from a group + * + * @param string $username Name of the user to remove from group + * @param string $groupName Name of the group from which remove the user + */ + public static function removeFromGroup($username,$groupName){ + $query = OC_DB::prepare( "DELETE FROM `*PREFIX*group_user` WHERE `uid` = ? AND `gid` = ?" ); + $result = $query->execute( $username, $groupName ); + } + + /** + * Get all groups the user belongs to + * + * @param string $username Name of the user + */ + public static function getUserGroups($username) { + $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE `uid` = ?" ); + $result = $query->execute( $username ); + + $groups = array(); + while( $row = $result->fetchRow()){ + $groups[] = $row; + } + + return $groups; + } + + /** + * get a list of all groups + * + */ + public static function getGroups() { + $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*groups`" ); + $result = $query->execute(); + + $groups = array(); + while( $row = $result->fetchRow()){ + $groups[] = $row; + } + + return $groups; + } +} diff --git a/lib/User/backend.php b/lib/User/backend.php index a486ea1cbcc..ab053661f88 100644 --- a/lib/User/backend.php +++ b/lib/User/backend.php @@ -1,25 +1,25 @@ . -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @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 . + * + */ @@ -29,12 +29,6 @@ */ abstract class OC_USER_BACKEND { - /** - * Check if the login button is pressed and log the user in - * - */ - abstract public static function loginListener(); - /** * Try to create a new user * @@ -51,85 +45,17 @@ abstract class OC_USER_BACKEND { */ abstract public static function login($username, $password); - /** - * Check if the logout button is pressed and logout the user - * - */ - abstract public static function logoutListener(); - /** * Check if some user is logged in * */ abstract public static function isLoggedIn(); - /** - * Try to create a new group - * - * @param string $groupName The name of the group to create - */ - abstract public static function createGroup($groupName); - - /** - * Get the ID of a user - * - * @param string $username Name of the user to find the ID - * @param boolean $noCache If false the cache is used to find the ID - */ - abstract public static function getUserId($username, $noCache=false); - - /** - * Get the ID of a group - * - * @param string $groupName Name of the group to find the ID - * @param boolean $noCache If false the cache is used to find the ID - */ - abstract public static function getGroupId($groupName, $noCache=false); - - /** - * Get the name of a group - * - * @param string $groupId ID of the group - * @param boolean $noCache If false the cache is used to find the name of the group - */ - abstract public static function getGroupName($groupId, $noCache=false); - - /** - * Check if a user belongs to a group - * - * @param string $username Name of the user to check - * @param string $groupName Name of the group - */ - abstract public static function inGroup($username, $groupName); - - /** - * Add a user to a group - * - * @param string $username Name of the user to add to group - * @param string $groupName Name of the group in which add the user - */ - abstract public static function addToGroup($username, $groupName); - - /** - * Remove a user from a group - * - * @param string $username Name of the user to remove from group - * @param string $groupName Name of the group from which remove the user - */ - abstract public static function removeFromGroup($username,$groupName); - /** * Generate a random password */ abstract public static function generatePassword(); - /** - * Get all groups the user belongs to - * - * @param string $username Name of the user - */ - abstract public static function getUserGroups($username); - /** * Set the password of a user * @@ -152,10 +78,4 @@ abstract class OC_USER_BACKEND { * */ abstract public static function getUsers(); - - /** - * get a list of all groups - * - */ - abstract public static function getGroups(); } diff --git a/lib/User/database.php b/lib/User/database.php index defaf7f8f40..b6305220f3d 100644 --- a/lib/User/database.php +++ b/lib/User/database.php @@ -1,30 +1,40 @@ . -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @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 . + * + */ +/* + * + * The following SQL statement is just a help for developers and will not be + * executed! + * + * CREATE TABLE `users` ( + * `uid` varchar(64) COLLATE utf8_unicode_ci NOT NULL, + * `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + * PRIMARY KEY (`uid`) + * ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + * + */ oc_require_once('User/backend.php'); - - /** * Class for user management in a SQL Database (e.g. MySQL, SQLite) * @@ -32,51 +42,24 @@ oc_require_once('User/backend.php'); class OC_USER_DATABASE extends OC_USER_BACKEND { static private $userGroupCache=array(); - /** - * Check if the login button is pressed and log the user in - * - */ - public static function loginListener(){ - if ( isset($_POST['loginbutton']) AND isset($_POST['password']) AND isset($_POST['login']) ) { - if ( OC_USER::login($_POST['login'], $_POST['password']) ) { - echo 1; - OC_LOG::event($_SESSION['username'], 1, ''); - echo 2; - if ( (isset($CONFIG_HTTPFORCESSL) AND $CONFIG_HTTPFORCESSL) - OR (isset($_SERVER['HTTPS']) AND ('on' == $_SERVER['HTTPS'])) ) { - $url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; - } else { - $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; - } - header("Location: $url"); - die(); - } else { - return('error'); - } - } - return(''); - } - /** * Try to create a new user * * @param string $username The username of the user to create * @param string $password The password of the new user */ - public static function createUser($username, $password) { - self::clearCache(); - global $CONFIG_DBTABLEPREFIX; + public static function createUser( $uid, $password ){ + $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*users` WHERE `uid` = ?" ); + $result = $query->execute( $uid ); + // Check if the user already exists - if ( 0 != OC_USER::getUserId($username, true) ) { + if ( $result->numRows() > 0 ){ return false; - } else { - $usernameClean = strToLower($username); - $password = sha1($password); - $username = OC_DB::escape($username); - $usernameClean = OC_DB::escape($usernameClean); - $query = "INSERT INTO `{$CONFIG_DBTABLEPREFIX}users` (`user_name` ,`user_name_clean` ,`user_password`) " - . "VALUES ('$username', '$usernameClean', '$password')"; - $result = OC_DB::query($query); + } + else{ + $query = OC_DB::prepare( "INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )" ); + $result = $query->prepare( $uid, sha1( $password )); + return $result ? true : false; } } @@ -87,39 +70,17 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { * @param string $username The username of the user to log in * @param string $password The password of the user */ - public static function login($username,$password){ - global $CONFIG_DBTABLEPREFIX; + public static function login( $username, $password ){ + $query = OC_DB::prepare( "SELECT `uid`, `name` FROM `*PREFIX*users` WHERE `uid` = ? AND `password` = ?" ); + $result = $query->execute( $username, sha1( $password )); - $password = sha1($password); - $usernameClean = strtolower($username); - $username = OC_DB::escape($username); - $usernameClean = OC_DB::escape($usernameClean); - $query = "SELECT user_id FROM {$CONFIG_DBTABLEPREFIX}users " - . "WHERE user_name_clean = '$usernameClean' AND user_password = '$password' LIMIT 1"; - $result = OC_DB::select($query); - if ( isset($result[0]) AND isset($result[0]['user_id']) ) { - $_SESSION['user_id'] = $result[0]['user_id']; - $_SESSION['username'] = $username; - $_SESSION['username_clean'] = $usernameClean; + if( $result->numRows() > 0 ){ + $row = $result->fetchRow(); + $_SESSION['user_id'] = $row["uid"]; return true; - } else { - return false; } - } - - /** - * Check if the logout button is pressed and logout the user - * - */ - public static function logoutListener() { - global $WEBROOT; - if ( isset($_GET['logoutbutton']) AND isset($_SESSION['username']) ) { - OC_LOG::event($_SESSION['username'], 2, ''); - $_SESSION['user_id'] = false; - $_SESSION['username'] = ''; - $_SESSION['username_clean'] = ''; - - header("location: $WEBROOT"); + else{ + return false; } } @@ -128,10 +89,8 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { * */ public static function logout() { - OC_LOG::event($_SESSION['username'], 2, ''); + OC_LOG::add( "core", $_SESSION['user_id'], "logout" ); $_SESSION['user_id'] = false; - $_SESSION['username'] = ''; - $_SESSION['username_clean'] = ''; } /** @@ -139,179 +98,14 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { * */ public static function isLoggedIn() { - if ( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) { + if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ){ return true; - } else { - return false; } - } - - /** - * Try to create a new group - * - * @param string $groupName The name of the group to create - */ - public static function createGroup($groupName) { - self::clearCache(); - global $CONFIG_DBTABLEPREFIX; - if (0 == OC_USER::getGroupId($groupName) ) { - $groupName = OC_DB::escape($groupName); - $query = "INSERT INTO `{$CONFIG_DBTABLEPREFIX}groups` (`group_name`) VALUES ('$groupName')"; - $result = OC_DB::query($query); - return $result ? true : false; - } else { + else{ return false; } } - /** - * Get the ID of a user - * - * @param string $username Name of the user to find the ID - * @param boolean $noCache If false the cache is used to find the ID - */ - public static function getUserId($username, $noCache=false) { - global $CONFIG_DBTABLEPREFIX; - - $usernameClean = strToLower($username); - // Try to use cached value to avoid an SQL query - if ( !$noCache AND isset($_SESSION['user_id_cache'][$usernameClean]) ) { - return $_SESSION['user_id_cache'][$usernameClean]; - } - $usernameClean = OC_DB::escape($usernameClean); - $query = "SELECT user_id FROM {$CONFIG_DBTABLEPREFIX}users WHERE user_name_clean = '$usernameClean'"; - $result = OC_DB::select($query); - if ( !is_array($result) ) { - return 0; - } - if ( isset($result[0]) AND isset($result[0]['user_id']) ) { - $_SESSION['user_id_cache'][$usernameClean] = $result[0]['user_id']; - return $result[0]['user_id']; - } else { - return 0; - } - } - - /** - * Get the ID of a group - * - * @param string $groupName Name of the group to find the ID - * @param boolean $noCache If false the cache is used to find the ID - */ - public static function getGroupId($groupName, $noCache=false) { - global $CONFIG_DBTABLEPREFIX; - - // Try to use cached value to avoid an SQL query - if ( !$noCache AND isset($_SESSION['group_id_cache'][$groupName]) ) { - return $_SESSION['group_id_cache'][$groupName]; - } - $groupName = OC_DB::escape($groupName); - $query = "SELECT group_id FROM {$CONFIG_DBTABLEPREFIX}groups WHERE group_name = '$groupName'"; - $result = OC_DB::select($query); - if ( !is_array($result) ) { - return 0; - } - if ( isset($result[0]) AND isset($result[0]['group_id']) ){ - $_SESSION['group_id_cache'][$groupName] = $result[0]['group_id']; - return $result[0]['group_id']; - } else { - return 0; - } - } - - /** - * Get the name of a group - * - * @param string $groupId ID of the group - * @param boolean $noCache If false the cache is used to find the name of the group - */ - public static function getGroupName($groupId, $noCache=false) { - global $CONFIG_DBTABLEPREFIX; - - // Try to use cached value to avoid an sql query - if ( !$noCache AND ($name = array_search($groupId, $_SESSION['group_id_cache'])) ) { - return $name; - } - $groupId = (integer)$groupId; - $query = "SELECT group_name FROM {$CONFIG_DBTABLEPREFIX}groups WHERE group_id = '$groupId' LIMIT 1"; - $result = OC_DB::select($query); - if ( isset($result[0]) AND isset($result[0]['group_name']) ) { - return $result[0]['group_name']; - } else { - return 0; - } - } - - /** - * Check if a user belongs to a group - * - * @param string $username Name of the user to check - * @param string $groupName Name of the group - */ - public static function inGroup($username,$groupName) { - global $CONFIG_DBTABLEPREFIX; - $userId = OC_USER::getUserId($username); - $groupId = OC_USER::getGroupId($groupName); - self::getUserGroups($username); - $groups=self::$userGroupCache[$userId]; - return (array_search($groupId,$groups)!==false); - } - - /** - * Add a user to a group - * - * @param string $username Name of the user to add to group - * @param string $groupName Name of the group in which add the user - */ - public static function addToGroup($username, $groupName) { - global $CONFIG_DBTABLEPREFIX; - self::clearCache(); - if ( !OC_USER::inGroup($username, $groupName) ) { - $userId = OC_USER::getUserId($username,true); - $groupId = OC_USER::getGroupId($groupName,true); - if ( (0 != $groupId) AND (0 != $userId) ) { - $query = "INSERT INTO `{$CONFIG_DBTABLEPREFIX}user_group` (`user_id` ,`group_id`) VALUES ('$userId', '$groupId');"; - $result = OC_DB::query($query); - if ( $result ) { - self::clearCache(); - return true; - } else { - return false; - } - } else { - return false; - } - } else { - return true; - } - } - - /** - * Remove a user from a group - * - * @param string $username Name of the user to remove from group - * @param string $groupName Name of the group from which remove the user - */ - public static function removeFromGroup($username,$groupName){ - global $CONFIG_DBTABLEPREFIX; - self::clearCache(); - if (OC_USER::inGroup($username, $groupName) ) { - $userId = OC_USER::getUserId($username,true); - $groupId = OC_USER::getGroupId($groupName,true); - if ( (0 != $groupId) AND (0 != $userId) ) { - $query="DELETE FROM `{$CONFIG_DBTABLEPREFIX}user_group` WHERE `group_id` =$groupId AND `user_id`=$userId"; - $result = OC_DB::query($query); - if ( $result ) { - self::clearCache(); - return true; - } else { - return false; - } - } - } - return false; - } - /** * Generate a random password */ @@ -319,48 +113,20 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { return uniqId(); } - /** - * Get all groups the user belongs to - * - * @param string $username Name of the user - */ - public static function getUserGroups($username) { - global $CONFIG_DBTABLEPREFIX; - - $userId = OC_USER::getUserId($username); - if(!isset(self::$userGroupCache[$userId])){ - $query = "SELECT group_id FROM {$CONFIG_DBTABLEPREFIX}user_group WHERE user_id = '$userId'"; - $result = OC_DB::select($query); - $groupsId = array(); - if ( is_array($result) ) { - foreach ( $result as $group ) { - $groupId = $group['group_id']; - $groupsId[]=$groupId; - } - } - self::$userGroupCache[$userId]=$groupsId; - return $groupsId; - }else{ - return self::$userGroupCache[$userId]; - } - } - /** * Set the password of a user * * @param string $username User who password will be changed * @param string $password The new password for the user */ - public static function setPassword($username, $password) { - global $CONFIG_DBTABLEPREFIX; + public static function setPassword( $username, $password ){ + $query = OC_DB::prepare( "UPDATE `*PREFIX*users` SET `password` = ? WHERE `uid` = ?" ); + $result = $query->execute( sha1( $password ), $username ); - $password = sha1($password); - $userId = OC_USER::getUserId($username); - $query = "UPDATE {$CONFIG_DBTABLEPREFIX}users SET user_password = '$password' WHERE user_id ='$userId'"; - $result = OC_DB::query($query); - if ( $result ) { + if( $result->numRows() > 0 ){ return true; - } else { + } + else{ return false; } } @@ -371,19 +137,14 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { * @param string $username Name of the user * @param string $password Password of the user */ - public static function checkPassword($username, $password) { - global $CONFIG_DBTABLEPREFIX; + public static function checkPassword( $username, $password ){ + $query = OC_DB::prepare( "SELECT `uid` FROM `*PREFIX*users` WHERE `uid` = ? AND `password` = ?" ); + $result = $query->execute( $username, sha1( $password )); - $password = sha1($password); - $usernameClean = strToLower($username); - $usernameClean = OC_DB::escape($usernameClean); - $username = OC_DB::escape($username); - $query = "SELECT user_id FROM `{$CONFIG_DBTABLEPREFIX}users` " - . "WHERE user_name_clean = '$usernameClean' AND user_password = '$password' LIMIT 1"; - $result = OC_DB::select($query); - if ( isset($result[0]) AND isset($result[0]['user_id']) AND ($result[0]['user_id'] > 0) ) { + if( $result->numRows() > 0 ){ return true; - } else { + } + else{ return false; } } @@ -392,37 +153,14 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { * get a list of all users * */ - public static function getUsers() { - global $CONFIG_DBTABLEPREFIX; + public static function getUsers(){ + $query = OC_DB::prepare( "SELECT `uid` FROM `*PREFIX*users`" ); + $result = $query->execute(); - $query = "SELECT user_name FROM `{$CONFIG_DBTABLEPREFIX}users`"; - $result = OC_DB::select($query); $users=array(); - foreach($result as $user){ - $users[]=$user['user_name']; + while( $row = $result->fetchRow()){ + $users[] = $row["uid"]; } return $users; } - - /** - * get a list of all groups - * - */ - public static function getGroups() { - global $CONFIG_DBTABLEPREFIX; - - $query = "SELECT group_name FROM `{$CONFIG_DBTABLEPREFIX}groups`"; - $result = OC_DB::select($query); - $groups=array(); - foreach($result as $group){ - $groups[]=$group['group_name']; - } - return $groups; - } - - private static function clearCache(){ - self::$userGroupCache=array(); - $_SESSION['user_id_cache']=array(); - $_SESSION['group_id_cache']=array(); - } } diff --git a/lib/base.php b/lib/base.php index 3bf74e233a5..e29cf5292c2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -22,7 +22,7 @@ // set some stuff -ob_start(); +//ob_start(); // error_reporting(E_ALL | E_STRICT); error_reporting( E_ERROR | E_PARSE | E_WARNING ); // MDB2 gives loads of strict error, disabling for now @@ -30,6 +30,7 @@ date_default_timezone_set('Europe/Berlin'); ini_set('arg_separator.output','&'); ini_set('session.cookie_httponly','1;'); session_start(); + // calculate the documentroot $SERVERROOT=substr(__FILE__,0,-13); $DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); @@ -86,6 +87,7 @@ oc_require_once('fileobserver.php'); oc_require_once('log.php'); oc_require_once('config.php'); oc_require_once('user.php'); +oc_require_once('group.php'); oc_require_once('ocs.php'); oc_require_once('connect.php'); oc_require_once('remotestorage.php'); diff --git a/lib/group.php b/lib/group.php new file mode 100644 index 00000000000..0701627e4ee --- /dev/null +++ b/lib/group.php @@ -0,0 +1,137 @@ +. + * + */ + +/** + * This class provides all methods needed for managing groups. + */ +class OC_GROUP { + // The backend used for user management + private static $_backend; + + // Backends available (except database) + private static $_backends = array(); + + /** + * @brief registers backend + * @param $name name of the backend + * @returns true/false + * + * Makes a list of backends that can be used by other modules + */ + public static function registerBackend( $name ){ + self::$_backends[] = $name; + return true; + } + + /** + * @brief gets available backends + * @returns array of backends + * + * Returns the names of all backends. + */ + public static function getBackends(){ + return self::$_backends; + } + + /** + * @brief set the group backend + * @param string $backend The backend to use for user managment + * @returns true/false + */ + public static function setBackend( $backend = 'database' ){ + // You'll never know what happens + if( null === $backend OR !is_string( $backend )){ + $backend = 'database'; + } + + // Load backend + switch( $backend ){ + case 'database': + case 'mysql': + case 'sqlite': + oc_require_once('User/database.php'); + self::$_backend = new OC_USER_DATABASE(); + break; + default: + $className = 'OC_USER_' . strToUpper($backend); + self::$_backend = new $className(); + break; + } + } + + /** + * Get the name of a group + * + * @param string $groupId ID of the group + * @param boolean $noCache If false the cache is used to find the name of the group + */ + public static function getGroupName($groupId, $noCache=false) { + return self::$_backend->getGroupName($groupId, $noCache); + } + + /** + * Check if a user belongs to a group + * + * @param string $username Name of the user to check + * @param string $groupName Name of the group + */ + public static function inGroup($username, $groupName) { + return self::$_backend->inGroup($username, $groupName); + } + + /** + * Add a user to a group + * + * @param string $username Name of the user to add to group + * @param string $groupName Name of the group in which add the user + */ + public static function addToGroup($username, $groupName) { + return self::$_backend->addToGroup($username, $groupName); + } + + /** + * Remove a user from a group + * + * @param string $username Name of the user to remove from group + * @param string $groupName Name of the group from which remove the user + */ + public static function removeFromGroup($username,$groupName){ + return self::$_backend->removeFromGroup($username, $groupName); + } + + /** + * Get all groups the user belongs to + * + * @param string $username Name of the user + */ + public static function getUserGroups($username) { + return self::$_backend->getUserGroups($username); + } + + /** + * get a list of all groups + * + */ + public static function getGroups() { + return self::$_backend->getGroups(); + } +} diff --git a/lib/user.php b/lib/user.php index 431d0bfc359..645bda4ed5d 100644 --- a/lib/user.php +++ b/lib/user.php @@ -1,66 +1,76 @@ . -* -*/ - - - - -if ( !$CONFIG_INSTALLED ) { - $_SESSION['user_id'] = false; - $_SESSION['username'] = ''; - $_SESSION['username_clean'] = ''; -} + * ownCloud + * + * @author Frank Karlitschek + * @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 . + * + */ -//cache the userid's an groupid's -if ( !isset($_SESSION['user_id_cache']) ) { - $_SESSION['user_id_cache'] = array(); -} -if ( !isset($_SESSION['group_id_cache']) ) { - $_SESSION['group_id_cache'] = array(); +if( !$CONFIG_INSTALLED ){ + $_SESSION['user_id'] = ''; } - - - /** - * Class for User Management - * + * This class provides all methods for user management. */ class OC_USER { - // The backend used for user management - private static $_backend; + private static $_backend = null; + + // Backends available (except database) + private static $_backends = array(); /** - * Set the User Authentication Module + * @brief registers backend + * @param $name name of the backend + * @returns true/false * - * @param string $backend The backend to use for user managment + * Makes a list of backends that can be used by other modules */ - public static function setBackend($backend='database') { - if ( (null === $backend) OR (!is_string($backend)) ) { + public static function registerBackend( $name ){ + self::$_backends[] = $name; + return true; + } + + /** + * @brief gets available backends + * @returns array of backends + * + * Returns the names of all backends. + */ + public static function getBackends(){ + return self::$_backends; + } + + /** + * @brief Sets the backend + * @param $backend default: database The backend to use for user managment + * @returns true/false + * + * Set the User Authentication Module + */ + public static function setBackend( $backend = 'database' ){ + // You'll never know what happens + if( null === $backend OR !is_string( $backend )){ $backend = 'database'; } - switch ( $backend ) { + // Load backend + switch( $backend ){ case 'database': case 'mysql': case 'sqlite': @@ -72,178 +82,72 @@ class OC_USER { self::$_backend = new $className(); break; } - } - /** - * Check if the login button is pressed and log the user in - * - */ - public static function loginListener() { - return self::$_backend->loginListener(); - } - - /** - * Try to create a new user - * - * @param string $username The username of the user to create - * @param string $password The password of the new user - */ - public static function createUser($username, $password) { - return self::$_backend->createUser($username, $password); + true; } /** - * Try to login a user - * - * @param string $username The username of the user to log in - * @param string $password The password of the user + * @brief Creates a new user + * @param $username The username of the user to create + * @param $password The password of the new user */ - public static function login($username, $password) { - return self::$_backend->login($username, $password); + public static function createUser( $username, $password ){ + return self::$_backend->createUser( $username, $password ); } /** - * Check if the logout button is pressed and logout the user - * + * @brief try to login a user + * @param $username The username of the user to log in + * @param $password The password of the user */ - public static function logoutListener() { - return self::$_backend->logoutListener(); + public static function login( $username, $password ){ + return self::$_backend->login( $username, $password ); } /** - * Kick the user - * + * @brief Kick the user */ - public static function logout() { + public static function logout(){ return self::$_backend->logout(); } /** - * Check if the user is logged in - * + * @brief Check if the user is logged in */ - public static function isLoggedIn() { + public static function isLoggedIn(){ return self::$_backend->isLoggedIn(); } /** - * Try to create a new group - * - * @param string $groupName The name of the group to create + * @brief Generate a random password */ - public static function createGroup($groupName) { - return self::$_backend->createGroup($groupName); + public static function generatePassword(){ + return substr( md5( uniqId().time()), 0, 10 ); } /** - * Get the ID of a user - * - * @param string $username Name of the user to find the ID - * @param boolean $noCache If false the cache is used to find the ID + * @brief Set the password of a user + * @param $username User whose password will be changed + * @param $password The new password for the user */ - public static function getUserId($username, $noCache=false) { - return self::$_backend->getUserId($username, $noCache); + public static function setPassword( $username, $password ){ + return self::$_backend->setPassword( $username, $password ); } /** - * Get the ID of a group - * - * @param string $groupName Name of the group to find the ID - * @param boolean $noCache If false the cache is used to find the ID - */ - public static function getGroupId($groupName, $noCache=false) { - return self::$_backend->getGroupId($groupName, $noCache); - } - - /** - * Get the name of a group - * - * @param string $groupId ID of the group - * @param boolean $noCache If false the cache is used to find the name of the group - */ - public static function getGroupName($groupId, $noCache=false) { - return self::$_backend->getGroupName($groupId, $noCache); - } - - /** - * Check if a user belongs to a group - * - * @param string $username Name of the user to check - * @param string $groupName Name of the group - */ - public static function inGroup($username, $groupName) { - return self::$_backend->inGroup($username, $groupName); - } - - /** - * Add a user to a group - * - * @param string $username Name of the user to add to group - * @param string $groupName Name of the group in which add the user - */ - public static function addToGroup($username, $groupName) { - return self::$_backend->addToGroup($username, $groupName); - } - - /** - * Remove a user from a group - * - * @param string $username Name of the user to remove from group - * @param string $groupName Name of the group from which remove the user - */ - public static function removeFromGroup($username,$groupName){ - return self::$_backend->removeFromGroup($username, $groupName); - } - - /** - * Generate a random password - */ - public static function generatePassword() { - return substr(md5(uniqId().time()),0,10); - } - - /** - * Get all groups the user belongs to - * - * @param string $username Name of the user - */ - public static function getUserGroups($username) { - return self::$_backend->getUserGroups($username); - } - - /** - * Set the password of a user - * - * @param string $username User who password will be changed - * @param string $password The new password for the user - */ - public static function setPassword($username, $password) { - return self::$_backend->setPassword($username, $password); - } - - /** - * Check if the password of the user is correct - * + * @brief Check if the password of the user is correct * @param string $username Name of the user * @param string $password Password of the user */ - public static function checkPassword($username, $password) { - return self::$_backend->checkPassword($username, $password); + public static function checkPassword( $username, $password ){ + return self::$_backend->checkPassword( $username, $password ); } /** - * get a list of all users - * + * @brief get a list of all users + * @returns array with uids */ - public static function getUsers() { + public static function getUsers(){ return self::$_backend->getUsers(); } - - /** - * get a list of all groups - * - */ - public static function getGroups() { - return self::$_backend->getGroups(); - } } -- cgit v1.2.3 From 3c01e307484a2738ed0314b7acf829cb7c9d8cdb Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Fri, 15 Apr 2011 18:13:49 +0200 Subject: Try to make owncloud working again --- admin/appinfo/app.php | 2 +- admin/index.php | 2 +- admin/plugins.php | 2 +- admin/system.php | 2 +- admin/users.php | 2 +- files/admin.php | 2 +- lib/Group/database.php | 13 +++++++------ lib/base.php | 22 +++++++++++----------- lib/group.php | 16 +++------------- 9 files changed, 27 insertions(+), 36 deletions(-) (limited to 'lib/base.php') diff --git a/admin/appinfo/app.php b/admin/appinfo/app.php index f4a36160936..a0ee0a0e55b 100644 --- a/admin/appinfo/app.php +++ b/admin/appinfo/app.php @@ -1,7 +1,7 @@ 1, "id" => "admin", "name" => "Administration" )); -if( OC_USER::ingroup( $_SESSION['username'], 'admin' )) +if( OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )) { OC_APP::addNavigationEntry( array( "id" => "admin_index", "order" => 1, "href" => OC_HELPER::linkTo( "admin", "index.php" ), "icon" => OC_HELPER::imagePath( "admin", "navicon.png" ), "name" => "Administration" )); } diff --git a/admin/index.php b/admin/index.php index 5d8ac140511..36c9229d2f5 100644 --- a/admin/index.php +++ b/admin/index.php @@ -23,7 +23,7 @@ require_once('../lib/base.php'); oc_require( 'template.php' ); -if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' )){ +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); } diff --git a/admin/plugins.php b/admin/plugins.php index d281f897ecb..ae6d35c3227 100644 --- a/admin/plugins.php +++ b/admin/plugins.php @@ -23,7 +23,7 @@ require_once('../lib/base.php'); oc_require( 'template.php' ); -if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' )){ +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); } diff --git a/admin/system.php b/admin/system.php index 5d8ac140511..36c9229d2f5 100644 --- a/admin/system.php +++ b/admin/system.php @@ -23,7 +23,7 @@ require_once('../lib/base.php'); oc_require( 'template.php' ); -if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' )){ +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); } diff --git a/admin/users.php b/admin/users.php index d4eebb44178..cfcb7a253fb 100644 --- a/admin/users.php +++ b/admin/users.php @@ -23,7 +23,7 @@ require_once('../lib/base.php'); oc_require( 'template.php' ); -if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' )){ +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); } diff --git a/files/admin.php b/files/admin.php index 4c442c4b111..9470bcf90bd 100644 --- a/files/admin.php +++ b/files/admin.php @@ -27,7 +27,7 @@ require_once('../lib/base.php'); oc_require( 'template.php' ); // Check if we are a user -if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' )){ +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); } diff --git a/lib/Group/database.php b/lib/Group/database.php index 8e7f1203cd2..e99f8486af7 100644 --- a/lib/Group/database.php +++ b/lib/Group/database.php @@ -72,9 +72,10 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { * @param string $username Name of the user to check * @param string $groupName Name of the group */ - public static function inGroup($username,$groupName) { + public static function inGroup( $username, $groupName ){ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` = ?" ); $result = $query->execute( $groupName, $username ); +var_dump( $result ); return $result->numRows() > 0 ? true : false; } @@ -85,8 +86,8 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { * @param string $username Name of the user to add to group * @param string $groupName Name of the group in which add the user */ - public static function addToGroup($username, $groupName) { - if( !OC_USER::inGroup( $username, $groupName )){ + public static function addToGroup( $username, $groupName ){ + if( !self::inGroup( $username, $groupName )){ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*group_user` ( `uid`, `gid` ) VALUES( ?, ? )" ); $result = $query->execute( $username, $groupName ); } @@ -98,7 +99,7 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { * @param string $username Name of the user to remove from group * @param string $groupName Name of the group from which remove the user */ - public static function removeFromGroup($username,$groupName){ + public static function removeFromGroup( $username, $groupName ){ $query = OC_DB::prepare( "DELETE FROM `*PREFIX*group_user` WHERE `uid` = ? AND `gid` = ?" ); $result = $query->execute( $username, $groupName ); } @@ -108,7 +109,7 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { * * @param string $username Name of the user */ - public static function getUserGroups($username) { + public static function getUserGroups( $username ){ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE `uid` = ?" ); $result = $query->execute( $username ); @@ -124,7 +125,7 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { * get a list of all groups * */ - public static function getGroups() { + public static function getGroups(){ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*groups`" ); $result = $query->execute(); diff --git a/lib/base.php b/lib/base.php index e29cf5292c2..f013cb8213d 100644 --- a/lib/base.php +++ b/lib/base.php @@ -98,7 +98,8 @@ OC_PLUGIN::loadPlugins( "" ); if(!isset($CONFIG_BACKEND)){ $CONFIG_BACKEND='database'; } -OC_USER::setBackend($CONFIG_BACKEND); +OC_USER::setBackend( $CONFIG_BACKEND ); +OC_GROUP::setBackend( $CONFIG_BACKEND ); // Set up file system unless forbidden if( !$RUNTIME_NOSETUPFS ){ @@ -149,7 +150,7 @@ class OC_UTIL { // If we are not forced to load a specific user we load the one that is logged in if( $user == "" && OC_USER::isLoggedIn()){ - $user = $_SESSION['username_clean']; + $user = $_SESSION['user_id']; } if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem @@ -384,22 +385,21 @@ class OC_DB { // Prepare options array $options = array( - 'portability' => MDB2_PORTABILITY_ALL, - 'log_line_break' => '
', - 'idxname_format' => '%s', - 'debug' => true, - 'quote_identifier' => true, - ); + 'portability' => MDB2_PORTABILITY_ALL, + 'log_line_break' => '
', + 'idxname_format' => '%s', + 'debug' => true, + 'quote_identifier' => true ); // Add the dsn according to the database type - if($CONFIG_DBTYPE=='sqlite'){ + if( $CONFIG_DBTYPE == 'sqlite' ){ // sqlite $dsn = array( 'phptype' => 'sqlite', 'database' => "$SERVERROOT/$CONFIG_DBNAME", 'mode' => '0644' ); } - elseif($CONFIG_DBTYPE=='mysql'){ + elseif( $CONFIG_DBTYPE == 'mysql' ){ // MySQL $dsn = array( 'phptype' => 'mysql', @@ -408,7 +408,7 @@ class OC_DB { 'hostspec' => $CONFIG_DBHOST, 'database' => $CONFIG_DBNAME ); } - elseif($CONFIG_DBTYPE=='pgsql'){ + elseif( $CONFIG_DBTYPE == 'pgsql' ){ // PostgreSQL $dsn = array( 'phptype' => 'pgsql', diff --git a/lib/group.php b/lib/group.php index 0701627e4ee..06c91bc2436 100644 --- a/lib/group.php +++ b/lib/group.php @@ -68,26 +68,16 @@ class OC_GROUP { case 'database': case 'mysql': case 'sqlite': - oc_require_once('User/database.php'); - self::$_backend = new OC_USER_DATABASE(); + oc_require_once('Group/database.php'); + self::$_backend = new OC_GROUP_DATABASE(); break; default: - $className = 'OC_USER_' . strToUpper($backend); + $className = 'OC_GROUP_' . strToUpper($backend); self::$_backend = new $className(); break; } } - /** - * Get the name of a group - * - * @param string $groupId ID of the group - * @param boolean $noCache If false the cache is used to find the name of the group - */ - public static function getGroupName($groupId, $noCache=false) { - return self::$_backend->getGroupName($groupId, $noCache); - } - /** * Check if a user belongs to a group * -- cgit v1.2.3 From 3d89b2caa41bc99f48b8377c87e9c653f467631d Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Fri, 15 Apr 2011 19:24:23 +0200 Subject: php is not perl --- lib/Group/database.php | 13 ++++++------- lib/User/database.php | 10 +++++----- lib/appconfig.php | 12 ++++++------ lib/base.php | 40 +++++++++++++++++++--------------------- lib/preferences.php | 18 +++++++++--------- 5 files changed, 45 insertions(+), 48 deletions(-) (limited to 'lib/base.php') diff --git a/lib/Group/database.php b/lib/Group/database.php index e99f8486af7..c10f6db80e0 100644 --- a/lib/Group/database.php +++ b/lib/Group/database.php @@ -53,14 +53,14 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { */ public static function createGroup( $gid ){ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*groups` WHERE `gid` = ?" ); - $result = $query->execute( $gid ); + $result = $query->execute( array( $gid )); if( $result->numRows() > 0 ){ return false; } else{ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*groups` ( `gid` ) VALUES( ? )" ); - $result = $query->prepare( $gid ); + $result = $query->execute( array( $gid )); return $result ? true : false; } @@ -74,8 +74,7 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { */ public static function inGroup( $username, $groupName ){ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` = ?" ); - $result = $query->execute( $groupName, $username ); -var_dump( $result ); + $result = $query->execute( array( $groupName, $username )); return $result->numRows() > 0 ? true : false; } @@ -89,7 +88,7 @@ var_dump( $result ); public static function addToGroup( $username, $groupName ){ if( !self::inGroup( $username, $groupName )){ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*group_user` ( `uid`, `gid` ) VALUES( ?, ? )" ); - $result = $query->execute( $username, $groupName ); + $result = $query->execute( array( $username, $groupName )); } } @@ -101,7 +100,7 @@ var_dump( $result ); */ public static function removeFromGroup( $username, $groupName ){ $query = OC_DB::prepare( "DELETE FROM `*PREFIX*group_user` WHERE `uid` = ? AND `gid` = ?" ); - $result = $query->execute( $username, $groupName ); + $result = $query->execute( array( $username, $groupName )); } /** @@ -111,7 +110,7 @@ var_dump( $result ); */ public static function getUserGroups( $username ){ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE `uid` = ?" ); - $result = $query->execute( $username ); + $result = $query->execute( array( $username )); $groups = array(); while( $row = $result->fetchRow()){ diff --git a/lib/User/database.php b/lib/User/database.php index b6305220f3d..45aab061e39 100644 --- a/lib/User/database.php +++ b/lib/User/database.php @@ -50,7 +50,7 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { */ public static function createUser( $uid, $password ){ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*users` WHERE `uid` = ?" ); - $result = $query->execute( $uid ); + $result = $query->execute( array( $uid )); // Check if the user already exists if ( $result->numRows() > 0 ){ @@ -58,7 +58,7 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { } else{ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )" ); - $result = $query->prepare( $uid, sha1( $password )); + $result = $query->execute( array( $uid, sha1( $password ))); return $result ? true : false; } @@ -72,7 +72,7 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { */ public static function login( $username, $password ){ $query = OC_DB::prepare( "SELECT `uid`, `name` FROM `*PREFIX*users` WHERE `uid` = ? AND `password` = ?" ); - $result = $query->execute( $username, sha1( $password )); + $result = $query->execute( array( $username, sha1( $password ))); if( $result->numRows() > 0 ){ $row = $result->fetchRow(); @@ -121,7 +121,7 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { */ public static function setPassword( $username, $password ){ $query = OC_DB::prepare( "UPDATE `*PREFIX*users` SET `password` = ? WHERE `uid` = ?" ); - $result = $query->execute( sha1( $password ), $username ); + $result = $query->execute( array( sha1( $password ), $username )); if( $result->numRows() > 0 ){ return true; @@ -139,7 +139,7 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { */ public static function checkPassword( $username, $password ){ $query = OC_DB::prepare( "SELECT `uid` FROM `*PREFIX*users` WHERE `uid` = ? AND `password` = ?" ); - $result = $query->execute( $username, sha1( $password )); + $result = $query->execute( array( $username, sha1( $password ))); if( $result->numRows() > 0 ){ return true; diff --git a/lib/appconfig.php b/lib/appconfig.php index 81e5717f647..df338a412db 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -69,7 +69,7 @@ class OC_APPCONFIG{ public static function getKeys( $app ){ // No magic in here as well $query = OC_DB::prepare( 'SELECT `key` FROM `*PREFIX*appconfig` WHERE `appid` = ?' ); - $result = $query->execute( $app ); + $result = $query->execute( array( $app )); $keys = array(); while( $row = $result->fetchRow()){ @@ -92,7 +92,7 @@ class OC_APPCONFIG{ public static function getValue( $app, $key, $default = null ){ // At least some magic in here :-) $query = OC_DB::prepare( 'SELECT `value` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `key` = ?' ); - $result = $query->execute( $app, $key ); + $result = $query->execute( array( $app, $key )); if( !$result->numRows()){ return $default; @@ -119,11 +119,11 @@ class OC_APPCONFIG{ // null: does not exist if( is_null( $exists )){ $query = OC_DB::prepare( 'INSERT INTO `*PREFIX*appconfig` ( `appid`, `key`, `value` ) VALUES( ?, ?, ? )' ); - $query->execute( $app, $key, $value ); + $query->execute( array( $app, $key, $value )); } else{ $query = OC_DB::prepare( 'UPDATE `*PREFIX*appconfig` SET `value` = ? WHERE `appid` = ? AND `key` = ?' ); - $query->execute( $value, $app, $key ); + $query->execute( array( $value, $app, $key )); } } @@ -138,7 +138,7 @@ class OC_APPCONFIG{ public static function deleteKey( $app, $key ){ // Boring! $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `key` = ?' ); - $query->execute( $app, $key ); + $query->execute( array( $app, $key )); return true; } @@ -153,7 +153,7 @@ class OC_APPCONFIG{ public static function deleteApp( $app ){ // Nothing special $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?' ); - $query->execute( $app ); + $query->execute( array( $app )); return true; } diff --git a/lib/base.php b/lib/base.php index f013cb8213d..054ba2415e0 100644 --- a/lib/base.php +++ b/lib/base.php @@ -1,24 +1,24 @@ . -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @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 . + * + */ // set some stuff @@ -478,8 +478,6 @@ class OC_DB { $query = self::processQuery( $query ); self::connect(); - //fix differences between sql versions - // return the result $result = self::$DBConnection->prepare( $query ); diff --git a/lib/preferences.php b/lib/preferences.php index 7b510e5b7de..6fb3cf1312f 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -69,7 +69,7 @@ class OC_PREFERENCES{ public static function getApps( $user ){ // No need for more comments $query = OC_DB::prepare( 'SELECT DISTINCT( `appid` ) FROM `*PREFIX*preferences` WHERE `userid` = ?' ); - $result = $query->execute( $user ); + $result = $query->execute( array( $user )); $apps = array(); while( $row = $result->fetchRow()){ @@ -91,7 +91,7 @@ class OC_PREFERENCES{ public static function getKeys( $user, $app ){ // No need for more comments $query = OC_DB::prepare( 'SELECT `key` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?' ); - $result = $query->execute( $user, $app ); + $result = $query->execute( array( $user, $app )); $keys = array(); while( $row = $result->fetchRow()){ @@ -115,7 +115,7 @@ class OC_PREFERENCES{ public static function getValue( $user, $app, $key, $default = null ){ // Try to fetch the value, return default if not exists. $query = OC_DB::prepare( 'SELECT `value` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `key` = ?' ); - $result = $query->execute( $user, $app, $key ); + $result = $query->execute( array( $user, $app, $key )); if( !$result->numRows()){ return $default; @@ -144,11 +144,11 @@ class OC_PREFERENCES{ // null: does not exist. Insert. if( is_null( $exists )){ $query = OC_DB::prepare( 'INSERT INTO `*PREFIX*preferences` ( `userid`, `appid`, `key`, `value` ) VALUES( ?, ?, ?, ? )' ); - $query->execute( $user, $app, $key, $value ); + $query->execute( array( $user, $app, $key, $value )); } else{ $query = OC_DB::prepare( 'UPDATE `*PREFIX*preferences` SET `value` = ? WHERE `userid` = ? AND `appid` = ? AND `key` = ?' ); - $query->execute( $value, $user, $app, $key ); + $query->execute( array( $value, $user, $app, $key )); } } @@ -164,7 +164,7 @@ class OC_PREFERENCES{ public static function deleteKey( $user, $app, $key ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `key` = ?' ); - $result = $query->execute( $user, $app, $key ); + $result = $query->execute( array( $user, $app, $key )); return true; } @@ -180,7 +180,7 @@ class OC_PREFERENCES{ public static function deleteApp( $user, $app ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?' ); - $result = $query->execute( $user, $app ); + $result = $query->execute( array( $user, $app )); return true; } @@ -195,7 +195,7 @@ class OC_PREFERENCES{ public static function deleteUser( $user ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?' ); - $result = $query->execute( $user ); + $result = $query->execute( array( $user )); return true; } @@ -210,7 +210,7 @@ class OC_PREFERENCES{ public static function deleteAppFromAllUsers( $app ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `appid` = ?' ); - $result = $query->execute( $app ); + $result = $query->execute( array( $app )); return true; } -- cgit v1.2.3 From f1015c88faf8ce418c5e0f983756d71403044210 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Fri, 15 Apr 2011 23:09:05 +0200 Subject: Minor bug fixing --- lib/app.php | 2 +- lib/base.php | 8 ++++---- templates/layout.admin.php | 2 +- templates/layout.user.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/base.php') diff --git a/lib/app.php b/lib/app.php index ecab723a6ad..3827afb5d15 100644 --- a/lib/app.php +++ b/lib/app.php @@ -281,7 +281,7 @@ class OC_APP{ } /** - * @brief Installs an application + * @brief Update an application * @param $data array with all information * @returns integer * diff --git a/lib/base.php b/lib/base.php index 054ba2415e0..58589db7c8c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -159,7 +159,7 @@ class OC_UTIL { if($CONFIG_ENABLEBACKUP){ // This creates the Directorys recursively if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ - mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0x755, true ); + mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true ); } $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); @@ -169,7 +169,7 @@ class OC_UTIL { $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ - mkdir( $CONFIG_DATADIRECTORY, 0x755, true ); + mkdir( $CONFIG_DATADIRECTORY, 0755, true ); } //set up the other storages according to the system settings @@ -304,7 +304,7 @@ class OC_HOOK{ * * TODO: write example */ - public function connect( $signalclass, $signalname, $slotclass, $slotname ){ + static public function connect( $signalclass, $signalname, $slotclass, $slotname ){ // Cerate the data structure if( !array_key_exists( $signalclass, self::$registered )){ self::$registered[$signalclass] = array(); @@ -333,7 +333,7 @@ class OC_HOOK{ * * TODO: write example */ - public function emit( $signalclass, $signalname, $params = array()){ + static public function emit( $signalclass, $signalname, $params = array()){ // Return false if there are no slots if( !array_key_exists( $signalclass, self::$registered )){ return false; diff --git a/templates/layout.admin.php b/templates/layout.admin.php index 22de64335fd..85eba138274 100644 --- a/templates/layout.admin.php +++ b/templates/layout.admin.php @@ -22,7 +22,7 @@ " title="" id="owncloud">" alt="ownCloud" />
- Username +
  • " title="">
  • diff --git a/templates/layout.user.php b/templates/layout.user.php index 7529f2c720a..9fc4f97e1dc 100644 --- a/templates/layout.user.php +++ b/templates/layout.user.php @@ -22,7 +22,7 @@ " title="" id="owncloud">" alt="ownCloud" />
    - Username +
    • " title="">
    • -- cgit v1.2.3 From 232654cb606af856d24c4b01353f18ac4a48e9bc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Apr 2011 10:12:53 +0200 Subject: get rid of the oc_require and friends --- 3dparty/Console/Getopt.php | 2 +- 3dparty/HTTP/WebDAV/Server.php | 6 +- 3dparty/MDB2.php | 6 +- 3dparty/MDB2/Driver/Datatype/Common.php | 2 +- 3dparty/MDB2/Driver/Datatype/mysql.php | 2 +- 3dparty/MDB2/Driver/Datatype/pgsql.php | 2 +- 3dparty/MDB2/Driver/Datatype/sqlite.php | 2 +- 3dparty/MDB2/Driver/Function/mysql.php | 2 +- 3dparty/MDB2/Driver/Function/pgsql.php | 2 +- 3dparty/MDB2/Driver/Function/sqlite.php | 2 +- 3dparty/MDB2/Driver/Manager/mysql.php | 2 +- 3dparty/MDB2/Driver/Manager/pgsql.php | 2 +- 3dparty/MDB2/Driver/Manager/sqlite.php | 2 +- 3dparty/MDB2/Driver/Reverse/mysql.php | 2 +- 3dparty/MDB2/Driver/Reverse/pgsql.php | 2 +- 3dparty/MDB2/Driver/Reverse/sqlite.php | 2 +- 3dparty/MDB2/LOB.php | 2 +- 3dparty/MDB2/Schema/Parser.php | 4 +- 3dparty/System.php | 4 +- 3dparty/XML/Parser.php | 2 +- admin/index.php | 2 +- admin/plugins.php | 2 +- admin/system.php | 2 +- admin/users.php | 2 +- files/admin.php | 2 +- files/download.php | 2 +- files/index.php | 2 +- files/settings.php | 2 +- files/webdav.php | 2 +- index.php | 4 +- lib/Group/database.php | 9 +- lib/HTTP/WebDAV/Server/Filesystem.php | 4 +- lib/User/database.php | 2 +- lib/app.php | 2 +- lib/base.php | 154 +++------------------ lib/files.php | 2 +- lib/group.php | 2 +- lib/user.php | 2 +- log/index.php | 2 +- plugins/ldap/lib_ldap.php | 2 +- .../syntaxhighlighter/compass/shThemeDefault.scss | 4 +- .../syntaxhighlighter/compass/shThemeDjango.scss | 11 +- .../syntaxhighlighter/compass/shThemeEclipse.scss | 41 +++--- .../syntaxhighlighter/compass/shThemeEmacs.scss | 12 +- .../compass/shThemeFadeToGrey.scss | 13 +- .../syntaxhighlighter/compass/shThemeMDUltra.scss | 27 ++-- .../syntaxhighlighter/compass/shThemeMidnight.scss | 3 +- .../syntaxhighlighter/compass/shThemeRDark.scss | 3 +- settings/index.php | 2 +- skeleton/admin.php | 2 +- skeleton/index.php | 2 +- 51 files changed, 149 insertions(+), 226 deletions(-) (limited to 'lib/base.php') diff --git a/3dparty/Console/Getopt.php b/3dparty/Console/Getopt.php index 6f2f9c73079..aec980b34d5 100644 --- a/3dparty/Console/Getopt.php +++ b/3dparty/Console/Getopt.php @@ -18,7 +18,7 @@ // // $Id: Getopt.php,v 1.21.4.7 2003/12/05 21:57:01 andrei Exp $ -oc_require_once( 'PEAR.php'); +require_once( 'PEAR.php'); /** * Command-line options parsing class. diff --git a/3dparty/HTTP/WebDAV/Server.php b/3dparty/HTTP/WebDAV/Server.php index c407d74c89f..ceed7214e93 100644 --- a/3dparty/HTTP/WebDAV/Server.php +++ b/3dparty/HTTP/WebDAV/Server.php @@ -33,9 +33,9 @@ +----------------------------------------------------------------------+ */ -oc_require_once("HTTP/WebDAV/Tools/_parse_propfind.php"); -oc_require_once("HTTP/WebDAV/Tools/_parse_proppatch.php"); -oc_require_once("HTTP/WebDAV/Tools/_parse_lockinfo.php"); +require_once("HTTP/WebDAV/Tools/_parse_propfind.php"); +require_once("HTTP/WebDAV/Tools/_parse_proppatch.php"); +require_once("HTTP/WebDAV/Tools/_parse_lockinfo.php"); /** diff --git a/3dparty/MDB2.php b/3dparty/MDB2.php index faf405b4112..c07545588dc 100644 --- a/3dparty/MDB2.php +++ b/3dparty/MDB2.php @@ -52,7 +52,7 @@ * @author Lukas Smith */ -oc_require_once('PEAR.php'); +require_once('PEAR.php'); // {{{ Error constants @@ -330,9 +330,9 @@ class MDB2 if (!MDB2::classExists($class_name)) { $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php'; if ($debug) { - $include = oc_include_once($file_name); + $include = include_once($file_name); } else { - $include = oc_include_once($file_name); + $include = include_once($file_name); } if (!$include) { if (!MDB2::fileExists($file_name)) { diff --git a/3dparty/MDB2/Driver/Datatype/Common.php b/3dparty/MDB2/Driver/Datatype/Common.php index 750dbb24772..6ef557ad371 100644 --- a/3dparty/MDB2/Driver/Datatype/Common.php +++ b/3dparty/MDB2/Driver/Datatype/Common.php @@ -44,7 +44,7 @@ // // $Id: Common.php,v 1.139 2008/12/04 11:50:42 afz Exp $ -oc_require_once('MDB2/LOB.php'); +require_once('MDB2/LOB.php'); /** * @package MDB2 diff --git a/3dparty/MDB2/Driver/Datatype/mysql.php b/3dparty/MDB2/Driver/Datatype/mysql.php index 944248f57c3..490dacdcc7d 100644 --- a/3dparty/MDB2/Driver/Datatype/mysql.php +++ b/3dparty/MDB2/Driver/Datatype/mysql.php @@ -46,7 +46,7 @@ // $Id: mysql.php,v 1.65 2008/02/22 19:23:49 quipo Exp $ // -oc_require_once('MDB2/Driver/Datatype/Common.php'); +require_once('MDB2/Driver/Datatype/Common.php'); /** * MDB2 MySQL driver diff --git a/3dparty/MDB2/Driver/Datatype/pgsql.php b/3dparty/MDB2/Driver/Datatype/pgsql.php index fe18729c84f..e0bb31bccf1 100644 --- a/3dparty/MDB2/Driver/Datatype/pgsql.php +++ b/3dparty/MDB2/Driver/Datatype/pgsql.php @@ -44,7 +44,7 @@ // // $Id: pgsql.php,v 1.93 2008/08/28 20:32:57 afz Exp $ -oc_require_once('MDB2/Driver/Datatype/Common.php'); +require_once('MDB2/Driver/Datatype/Common.php'); /** * MDB2 PostGreSQL driver diff --git a/3dparty/MDB2/Driver/Datatype/sqlite.php b/3dparty/MDB2/Driver/Datatype/sqlite.php index 533d0e9510b..572ccc38e71 100644 --- a/3dparty/MDB2/Driver/Datatype/sqlite.php +++ b/3dparty/MDB2/Driver/Datatype/sqlite.php @@ -46,7 +46,7 @@ // $Id: sqlite.php,v 1.67 2008/02/22 19:58:06 quipo Exp $ // -oc_require_once('MDB2/Driver/Datatype/Common.php'); +require_once('MDB2/Driver/Datatype/Common.php'); /** * MDB2 SQLite driver diff --git a/3dparty/MDB2/Driver/Function/mysql.php b/3dparty/MDB2/Driver/Function/mysql.php index aff531c9f3a..44183c3aa06 100644 --- a/3dparty/MDB2/Driver/Function/mysql.php +++ b/3dparty/MDB2/Driver/Function/mysql.php @@ -45,7 +45,7 @@ // $Id: mysql.php,v 1.12 2008/02/17 18:54:08 quipo Exp $ // -oc_require_once('MDB2/Driver/Function/Common.php'); +require_once('MDB2/Driver/Function/Common.php'); /** * MDB2 MySQL driver for the function modules diff --git a/3dparty/MDB2/Driver/Function/pgsql.php b/3dparty/MDB2/Driver/Function/pgsql.php index cb47ea57d9f..173bfc91494 100644 --- a/3dparty/MDB2/Driver/Function/pgsql.php +++ b/3dparty/MDB2/Driver/Function/pgsql.php @@ -44,7 +44,7 @@ // // $Id: pgsql.php,v 1.11 2008/11/09 19:46:50 quipo Exp $ -oc_require_once('MDB2/Driver/Function/Common.php'); +require_once('MDB2/Driver/Function/Common.php'); /** * MDB2 MySQL driver for the function modules diff --git a/3dparty/MDB2/Driver/Function/sqlite.php b/3dparty/MDB2/Driver/Function/sqlite.php index f5499599dd5..8a5b7ec8fad 100644 --- a/3dparty/MDB2/Driver/Function/sqlite.php +++ b/3dparty/MDB2/Driver/Function/sqlite.php @@ -45,7 +45,7 @@ // $Id: sqlite.php,v 1.10 2008/02/17 18:54:08 quipo Exp $ // -oc_require_once('MDB2/Driver/Function/Common.php'); +require_once('MDB2/Driver/Function/Common.php'); /** * MDB2 SQLite driver for the function modules diff --git a/3dparty/MDB2/Driver/Manager/mysql.php b/3dparty/MDB2/Driver/Manager/mysql.php index 7bd6a3623a3..29d644a957a 100644 --- a/3dparty/MDB2/Driver/Manager/mysql.php +++ b/3dparty/MDB2/Driver/Manager/mysql.php @@ -45,7 +45,7 @@ // $Id: mysql.php,v 1.113 2008/11/23 20:30:29 quipo Exp $ // -oc_require_once('MDB2/Driver/Manager/Common.php'); +require_once('MDB2/Driver/Manager/Common.php'); /** * MDB2 MySQL driver for the management modules diff --git a/3dparty/MDB2/Driver/Manager/pgsql.php b/3dparty/MDB2/Driver/Manager/pgsql.php index 1a7e851897c..490f697aa5b 100644 --- a/3dparty/MDB2/Driver/Manager/pgsql.php +++ b/3dparty/MDB2/Driver/Manager/pgsql.php @@ -44,7 +44,7 @@ // // $Id: pgsql.php,v 1.87 2008/11/29 14:09:59 afz Exp $ -oc_require_once('MDB2/Driver/Manager/Common.php'); +require_once('MDB2/Driver/Manager/Common.php'); /** * MDB2 MySQL driver for the management modules diff --git a/3dparty/MDB2/Driver/Manager/sqlite.php b/3dparty/MDB2/Driver/Manager/sqlite.php index 85751d39a3f..e985298c2c3 100644 --- a/3dparty/MDB2/Driver/Manager/sqlite.php +++ b/3dparty/MDB2/Driver/Manager/sqlite.php @@ -46,7 +46,7 @@ // $Id: sqlite.php,v 1.76 2008/05/31 11:48:48 quipo Exp $ // -oc_require_once('MDB2/Driver/Manager/Common.php'); +require_once('MDB2/Driver/Manager/Common.php'); /** * MDB2 SQLite driver for the management modules diff --git a/3dparty/MDB2/Driver/Reverse/mysql.php b/3dparty/MDB2/Driver/Reverse/mysql.php index 40c62da3baa..856d2427ab4 100644 --- a/3dparty/MDB2/Driver/Reverse/mysql.php +++ b/3dparty/MDB2/Driver/Reverse/mysql.php @@ -45,7 +45,7 @@ // $Id: mysql.php,v 1.80 2008/03/26 21:15:37 quipo Exp $ // -oc_require_once('MDB2/Driver/Reverse/Common.php'); +require_once('MDB2/Driver/Reverse/Common.php'); /** * MDB2 MySQL driver for the schema reverse engineering module diff --git a/3dparty/MDB2/Driver/Reverse/pgsql.php b/3dparty/MDB2/Driver/Reverse/pgsql.php index d010292cd8c..649c1cad9ee 100644 --- a/3dparty/MDB2/Driver/Reverse/pgsql.php +++ b/3dparty/MDB2/Driver/Reverse/pgsql.php @@ -45,7 +45,7 @@ // // $Id: pgsql.php,v 1.75 2008/08/22 16:36:20 quipo Exp $ -oc_require_once('MDB2/Driver/Reverse/Common.php'); +require_once('MDB2/Driver/Reverse/Common.php'); /** * MDB2 PostGreSQL driver for the schema reverse engineering module diff --git a/3dparty/MDB2/Driver/Reverse/sqlite.php b/3dparty/MDB2/Driver/Reverse/sqlite.php index 1b85aa71f9a..b83544835fe 100644 --- a/3dparty/MDB2/Driver/Reverse/sqlite.php +++ b/3dparty/MDB2/Driver/Reverse/sqlite.php @@ -46,7 +46,7 @@ // $Id: sqlite.php,v 1.80 2008/05/03 10:30:14 quipo Exp $ // -oc_require_once('MDB2/Driver/Reverse/Common.php'); +require_once('MDB2/Driver/Reverse/Common.php'); /** * MDB2 SQlite driver for the schema reverse engineering module diff --git a/3dparty/MDB2/LOB.php b/3dparty/MDB2/LOB.php index 2cdf67afa92..ae67224020e 100644 --- a/3dparty/MDB2/LOB.php +++ b/3dparty/MDB2/LOB.php @@ -50,7 +50,7 @@ * @author Lukas Smith */ -oc_require_once('MDB2.php'); +require_once('MDB2.php'); /** * MDB2_LOB: user land stream wrapper implementation for LOB support diff --git a/3dparty/MDB2/Schema/Parser.php b/3dparty/MDB2/Schema/Parser.php index ed31ba03bdf..7c22012c416 100644 --- a/3dparty/MDB2/Schema/Parser.php +++ b/3dparty/MDB2/Schema/Parser.php @@ -54,8 +54,8 @@ */ -oc_require_once('XML/Parser.php'); -oc_require_once('MDB2/Schema/Validate.php'); +require_once('XML/Parser.php'); +require_once('MDB2/Schema/Validate.php'); /** * Parses an XML schema file diff --git a/3dparty/System.php b/3dparty/System.php index a9279ff687d..97de96b14ca 100644 --- a/3dparty/System.php +++ b/3dparty/System.php @@ -19,8 +19,8 @@ // $Id: System.php,v 1.36 2004/06/15 16:33:46 pajoye Exp $ // -oc_require_once( 'PEAR.php'); -oc_require_once( 'Console/Getopt.php'); +require_once( 'PEAR.php'); +require_once( 'Console/Getopt.php'); $GLOBALS['_System_temp_files'] = array(); diff --git a/3dparty/XML/Parser.php b/3dparty/XML/Parser.php index 6f77b5c66da..6b65066d028 100644 --- a/3dparty/XML/Parser.php +++ b/3dparty/XML/Parser.php @@ -36,7 +36,7 @@ /** * uses PEAR's error handling */ -oc_require_once('PEAR.php'); +require_once('PEAR.php'); /** * resource could not be created diff --git a/admin/index.php b/admin/index.php index 36c9229d2f5..8abef287098 100644 --- a/admin/index.php +++ b/admin/index.php @@ -22,7 +22,7 @@ */ require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); diff --git a/admin/plugins.php b/admin/plugins.php index ae6d35c3227..60d23585a4f 100644 --- a/admin/plugins.php +++ b/admin/plugins.php @@ -22,7 +22,7 @@ */ require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); diff --git a/admin/system.php b/admin/system.php index 36c9229d2f5..8abef287098 100644 --- a/admin/system.php +++ b/admin/system.php @@ -22,7 +22,7 @@ */ require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); diff --git a/admin/users.php b/admin/users.php index cfcb7a253fb..4d14c791c3c 100644 --- a/admin/users.php +++ b/admin/users.php @@ -22,7 +22,7 @@ */ require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); diff --git a/files/admin.php b/files/admin.php index 9470bcf90bd..3cc8a57d4cb 100644 --- a/files/admin.php +++ b/files/admin.php @@ -24,7 +24,7 @@ // Init owncloud require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); // Check if we are a user if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ diff --git a/files/download.php b/files/download.php index d6d39c82126..f890036a32e 100644 --- a/files/download.php +++ b/files/download.php @@ -23,7 +23,7 @@ // Init owncloud require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); // Check if we are a user if( !OC_USER::isLoggedIn()){ diff --git a/files/index.php b/files/index.php index 25a9f0297dc..6d237ed6152 100644 --- a/files/index.php +++ b/files/index.php @@ -24,7 +24,7 @@ // Init owncloud require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); // Check if we are a user if( !OC_USER::isLoggedIn()){ diff --git a/files/settings.php b/files/settings.php index 25a9f0297dc..6d237ed6152 100644 --- a/files/settings.php +++ b/files/settings.php @@ -24,7 +24,7 @@ // Init owncloud require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); // Check if we are a user if( !OC_USER::isLoggedIn()){ diff --git a/files/webdav.php b/files/webdav.php index 7863818cc20..4b1393c110b 100644 --- a/files/webdav.php +++ b/files/webdav.php @@ -23,7 +23,7 @@ require_once('../lib/base.php'); -oc_require_once('HTTP/WebDAV/Server/Filesystem.php'); +require_once('HTTP/WebDAV/Server/Filesystem.php'); ini_set('default_charset', 'UTF-8'); diff --git a/index.php b/index.php index 23aa30dcb4e..62a515fa20f 100644 --- a/index.php +++ b/index.php @@ -22,8 +22,8 @@ */ require_once( 'lib/base.php' ); -oc_require_once( 'appconfig.php' ); -oc_require_once( 'template.php' ); +require_once( 'appconfig.php' ); +require_once( 'template.php' ); if( OC_USER::isLoggedIn()){ if( $_GET["logout"] ){ OC_USER::logout(); diff --git a/lib/Group/database.php b/lib/Group/database.php index c10f6db80e0..bdf5bbc5c55 100644 --- a/lib/Group/database.php +++ b/lib/Group/database.php @@ -37,7 +37,7 @@ * */ -oc_require_once( 'Group/backend.php' ); +require_once( 'Group/backend.php' ); /** * Class for group management in a SQL Database (e.g. MySQL, SQLite) @@ -75,7 +75,12 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { public static function inGroup( $username, $groupName ){ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` = ?" ); $result = $query->execute( array( $groupName, $username )); - + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"
      '; + $entry .= 'Offending command was: '.$result->getDebugInfo().'
      '; + error_log( $entry ); + die( $entry ); + } return $result->numRows() > 0 ? true : false; } diff --git a/lib/HTTP/WebDAV/Server/Filesystem.php b/lib/HTTP/WebDAV/Server/Filesystem.php index 0615c600e07..c0be27d7c05 100644 --- a/lib/HTTP/WebDAV/Server/Filesystem.php +++ b/lib/HTTP/WebDAV/Server/Filesystem.php @@ -34,8 +34,8 @@ --- modified for ownCloud --- */ require_once("lib/base.php"); - oc_require_once("HTTP/WebDAV/Server.php"); - oc_require_once("System.php"); + require_once("HTTP/WebDAV/Server.php"); + require_once("System.php"); /** * Filesystem access using WebDAV diff --git a/lib/User/database.php b/lib/User/database.php index 45aab061e39..d521cc23c42 100644 --- a/lib/User/database.php +++ b/lib/User/database.php @@ -33,7 +33,7 @@ * */ -oc_require_once('User/backend.php'); +require_once('User/backend.php'); /** * Class for user management in a SQL Database (e.g. MySQL, SQLite) diff --git a/lib/app.php b/lib/app.php index ecab723a6ad..ddbad4ee2ec 100644 --- a/lib/app.php +++ b/lib/app.php @@ -54,7 +54,7 @@ class OC_APP{ while( false !== ( $filename = readdir( $dir ))){ if( substr( $filename, 0, 1 ) != '.' ){ if( file_exists( "$SERVERROOT/$filename/appinfo/app.php" )){ - oc_require( "$filename/appinfo/app.php" ); + require( "$filename/appinfo/app.php" ); } } } diff --git a/lib/base.php b/lib/base.php index 054ba2415e0..033052a3c3b 100644 --- a/lib/base.php +++ b/lib/base.php @@ -45,7 +45,7 @@ if($WEBROOT!='' and $WEBROOT[0]!=='/'){ } // set the right include path -// set_include_path(get_include_path().PATH_SEPARATOR.$SERVERROOT.PATH_SEPARATOR.$SERVERROOT.'/inc'.PATH_SEPARATOR.$SERVERROOT.'/config'); +set_include_path($SERVERROOT.'/lib'.PATH_SEPARATOR.$SERVERROOT.'/config'.PATH_SEPARATOR.$SERVERROOT.'/3dparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.$SERVERROOT); // define runtime variables - unless this already has been done if( !isset( $RUNTIME_NOSETUPFS )){ @@ -66,7 +66,6 @@ $CONFIG_FILESYSTEM=array(); // include the generated configfile @include_once($SERVERROOT.'/config/config.php'); - $CONFIG_DATADIRECTORY_ROOT=$CONFIG_DATADIRECTORY;// store this in a seperate variable so we can change the data directory to jail users. // redirect to https site if configured if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){ @@ -78,20 +77,20 @@ if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){ } // load core libs -oc_require_once('helper.php'); -oc_require_once('app.php'); -oc_require_once('files.php'); -oc_require_once('filesystem.php'); -oc_require_once('filestorage.php'); -oc_require_once('fileobserver.php'); -oc_require_once('log.php'); -oc_require_once('config.php'); -oc_require_once('user.php'); -oc_require_once('group.php'); -oc_require_once('ocs.php'); -oc_require_once('connect.php'); -oc_require_once('remotestorage.php'); -oc_require_once('plugin.php'); +require_once('helper.php'); +require_once('app.php'); +require_once('files.php'); +require_once('filesystem.php'); +require_once('filestorage.php'); +require_once('fileobserver.php'); +require_once('log.php'); +require_once('config.php'); +require_once('user.php'); +require_once('group.php'); +require_once('ocs.php'); +require_once('connect.php'); +require_once('remotestorage.php'); +require_once('plugin.php'); OC_PLUGIN::loadPlugins( "" ); @@ -113,13 +112,11 @@ OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" ); OC_UTIL::addScript( "js" ); OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); OC_UTIL::addStyle( "styles" ); - // Load Apps OC_APP::loadApps(); // check if the server is correctly configured for ownCloud OC_UTIL::checkserver(); - /** * Class for utility functions * @@ -380,8 +377,8 @@ class OC_DB { // do nothing if the connection already has been established if(!self::$DBConnection){ - // Require MDB2.php (TODO: why here not in head of file?) - @oc_require_once('MDB2.php'); + // Require MDB2.php (not required in the head of the file so we only load it when needed) + require_once('MDB2.php'); // Prepare options array $options = array( @@ -610,7 +607,7 @@ class OC_DB { // Connect if this did not happen before if(!self::$schema){ - @oc_require_once('MDB2/Schema.php'); + require_once('MDB2/Schema.php'); self::$schema=&MDB2_Schema::factory(self::$DBConnection); } @@ -646,120 +643,6 @@ class OC_DB { } } - -//custom require/include functions because not all hosts allow us to set the include path -function oc_require($file){ - global $SERVERROOT; - global $DOCUMENTROOT; - global $WEBROOT; - global $CONFIG_DBNAME; - global $CONFIG_DBHOST; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; - global $CONFIG_DBTYPE; - global $CONFIG_DATADIRECTORY; - global $CONFIG_HTTPFORCESSL; - global $CONFIG_DATEFORMAT; - global $CONFIG_INSTALLED; - - if(is_file($file)){ - return require($file); - } - elseif(is_file($SERVERROOT.'/'.$file)){ - return require($SERVERROOT.'/'.$file); - } - elseif(is_file($SERVERROOT.'/lib/'.$file)){ - return require($SERVERROOT.'/lib/'.$file); - } - elseif(is_file($SERVERROOT.'/3dparty/'.$file)){ - return require($SERVERROOT.'/3dparty/'.$file); - } -} - -function oc_require_once($file){ - global $SERVERROOT; - global $DOCUMENTROOT; - global $WEBROOT; - global $CONFIG_DBNAME; - global $CONFIG_DBHOST; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; - global $CONFIG_DBTYPE; - global $CONFIG_DATADIRECTORY; - global $CONFIG_HTTPFORCESSL; - global $CONFIG_DATEFORMAT; - global $CONFIG_INSTALLED; - - if(is_file($file)){ - return require_once($file); - } - elseif(is_file($SERVERROOT.'/'.$file)){ - return require_once($SERVERROOT.'/'.$file); - } - elseif(is_file($SERVERROOT.'/lib/'.$file)){ - return require_once($SERVERROOT.'/lib/'.$file); - } - elseif(is_file($SERVERROOT.'/3dparty/'.$file)){ - return require_once($SERVERROOT.'/3dparty/'.$file); - } -} - -function oc_include($file){ - global $SERVERROOT; - global $DOCUMENTROOT; - global $WEBROOT; - global $CONFIG_DBNAME; - global $CONFIG_DBHOST; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; - global $CONFIG_DBTYPE; - global $CONFIG_DATADIRECTORY; - global $CONFIG_HTTPFORCESSL; - global $CONFIG_DATEFORMAT; - global $CONFIG_INSTALLED; - - if(is_file($file)){ - return include($file); - } - elseif(is_file($SERVERROOT.'/'.$file)){ - return include($SERVERROOT.'/'.$file); - } - elseif(is_file($SERVERROOT.'/lib/'.$file)){ - return include($SERVERROOT.'/lib/'.$file); - } - elseif(is_file($SERVERROOT.'/3dparty/'.$file)){ - return include($SERVERROOT.'/3dparty/'.$file); - } -} - -function oc_include_once($file){ - global $SERVERROOT; - global $DOCUMENTROOT; - global $WEBROOT; - global $CONFIG_DBNAME; - global $CONFIG_DBHOST; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; - global $CONFIG_DBTYPE; - global $CONFIG_DATADIRECTORY; - global $CONFIG_HTTPFORCESSL; - global $CONFIG_DATEFORMAT; - global $CONFIG_INSTALLED; - - if(is_file($file)){ - return include_once($file); - } - elseif(is_file($SERVERROOT.'/'.$file)){ - return include_once($SERVERROOT.'/'.$file); - } - elseif(is_file($SERVERROOT.'/lib/'.$file)){ - return include_once($SERVERROOT.'/lib/'.$file); - } - elseif(is_file($SERVERROOT.'/3dparty/'.$file)){ - return include_once($SERVERROOT.'/3dparty/'.$file); - } -} - function chmodr($path, $filemode) { // echo "$path
      "; if (!is_dir($path)) @@ -782,5 +665,4 @@ function chmodr($path, $filemode) { else return FALSE; } - ?> diff --git a/lib/files.php b/lib/files.php index bf629a59d44..a1f983b6b2f 100644 --- a/lib/files.php +++ b/lib/files.php @@ -21,7 +21,7 @@ * */ -oc_require_once("log.php"); +require_once("log.php"); /** diff --git a/lib/group.php b/lib/group.php index 06c91bc2436..18e34c72773 100644 --- a/lib/group.php +++ b/lib/group.php @@ -68,7 +68,7 @@ class OC_GROUP { case 'database': case 'mysql': case 'sqlite': - oc_require_once('Group/database.php'); + require_once('Group/database.php'); self::$_backend = new OC_GROUP_DATABASE(); break; default: diff --git a/lib/user.php b/lib/user.php index 645bda4ed5d..9841b8ef276 100644 --- a/lib/user.php +++ b/lib/user.php @@ -74,7 +74,7 @@ class OC_USER { case 'database': case 'mysql': case 'sqlite': - oc_require_once('User/database.php'); + require_once('User/database.php'); self::$_backend = new OC_USER_DATABASE(); break; default: diff --git a/log/index.php b/log/index.php index e0f48d168cd..a401a38fa1a 100644 --- a/log/index.php +++ b/log/index.php @@ -24,7 +24,7 @@ //require_once('../../config/config.php'); require_once('../lib/base.php'); -oc_require( 'template.php' ); +require( 'template.php' ); if( !OC_USER::isLoggedIn()){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); diff --git a/plugins/ldap/lib_ldap.php b/plugins/ldap/lib_ldap.php index 383e7f7ab0a..d2095a022ff 100644 --- a/plugins/ldap/lib_ldap.php +++ b/plugins/ldap/lib_ldap.php @@ -21,7 +21,7 @@ * */ -oc_require_once('inc/User/backend.php'); +require_once('inc/User/backend.php'); diff --git a/plugins/textviewer/syntaxhighlighter/compass/shThemeDefault.scss b/plugins/textviewer/syntaxhighlighter/compass/shThemeDefault.scss index 1574dae8053..6ff829ef321 100644 --- a/plugins/textviewer/syntaxhighlighter/compass/shThemeDefault.scss +++ b/plugins/textviewer/syntaxhighlighter/compass/shThemeDefault.scss @@ -3,5 +3,7 @@ @import "_theme_template.scss"; .syntaxhighlighter { - .keyword { font-weight: bold !important; } +.keyword { font-weight: + bold !important; + } } diff --git a/plugins/textviewer/syntaxhighlighter/compass/shThemeDjango.scss b/plugins/textviewer/syntaxhighlighter/compass/shThemeDjango.scss index 8e95c567aeb..45e3f0917c3 100644 --- a/plugins/textviewer/syntaxhighlighter/compass/shThemeDjango.scss +++ b/plugins/textviewer/syntaxhighlighter/compass/shThemeDjango.scss @@ -3,7 +3,8 @@ $background: #0a2b1d !default; $line_highlighted_background: #233729 !default; -$line_highlighted_number: white !default; +$line_highlighted_number: +white !default; $gutter_text: #497958 !default; $gutter_border_color: #41a83e !default; @@ -31,6 +32,10 @@ $code_color3: #edef7d !default; @import "_theme_template.scss"; .syntaxhighlighter { - .comments { font-style: italic !important; } - .keyword { font-weight: bold !important; } +.comments { font-style: + italic !important; + } +.keyword { font-weight: + bold !important; + } } diff --git a/plugins/textviewer/syntaxhighlighter/compass/shThemeEclipse.scss b/plugins/textviewer/syntaxhighlighter/compass/shThemeEclipse.scss index 193fb1d877a..33cf5a3cac1 100644 --- a/plugins/textviewer/syntaxhighlighter/compass/shThemeEclipse.scss +++ b/plugins/textviewer/syntaxhighlighter/compass/shThemeEclipse.scss @@ -15,9 +15,11 @@ $toolbar_collapsed_a_hover: #aa7700 !default; $toolbar_collapsed_background: #fff !default; $toolbar_a: #a0a0a0 !default; -$toolbar_a_hover: red !default; +$toolbar_a_hover: +red !default; -$code_plain: black !default; +$code_plain: +black !default; $code_comments: #3f5fbf !default; $code_string: #2a00ff !default; $code_keyword: #7f0055 !default; @@ -26,23 +28,30 @@ $code_variable: #aa7700 !default; $code_value: #009900 !default; $code_functions: #ff1493 !default; $code_constants: #0066cc !default; -$code_color1: gray !default; +$code_color1: +gray !default; $code_color2: #ff1493 !default; -$code_color3: red !default; +$code_color3: +red !default; @import "_theme_template.scss"; .syntaxhighlighter { - .keyword { font-weight: bold !important; } - - .xml { - .keyword { - color: #3f7f7f !important; - font-weight: normal !important; } - .color1, .color1 a { color: #7f007f !important; } - .string { - font-style: italic !important; - color: #2a00ff !important; - } - } +.keyword { font-weight: + bold !important; + } + + .xml { + .keyword { +color: #3f7f7f !important; +font-weight: + normal !important; + } +.color1, .color1 a { color: #7f007f !important; } + .string { +font-style: + italic !important; +color: #2a00ff !important; + } + } } diff --git a/plugins/textviewer/syntaxhighlighter/compass/shThemeEmacs.scss b/plugins/textviewer/syntaxhighlighter/compass/shThemeEmacs.scss index 11c9deb4d08..2589374f5be 100644 --- a/plugins/textviewer/syntaxhighlighter/compass/shThemeEmacs.scss +++ b/plugins/textviewer/syntaxhighlighter/compass/shThemeEmacs.scss @@ -1,17 +1,20 @@ // Emacs SyntaxHighlighter theme based on theme by Joshua Emmons // http://www.skia.net/ -$background: black !default; +$background: +black !default; $line_highlighted_background: #2A3133 !default; -$line_highlighted_number: white !default; +$line_highlighted_number: +white !default; $gutter_text: #d3d3d3 !default; $gutter_border_color: #990000 !default; $toolbar_collapsed_a: #ebdb8d !default; $toolbar_collapsed_a_hover: #ff7d27 !default; -$toolbar_collapsed_background: black !default; +$toolbar_collapsed_background: +black !default; $toolbar_a: #fff !default; $toolbar_a_hover: #9ccff4 !default; @@ -19,7 +22,8 @@ $toolbar_a_hover: #9ccff4 !default; $code_plain: #d3d3d3 !default; $code_comments: #ff7d27 !default; $code_string: #ff9e7b !default; -$code_keyword: aqua !default; +$code_keyword: +aqua !default; $code_preprocessor: #aec4de !default; $code_variable: #ffaa3e !default; $code_value: #009900 !default; diff --git a/plugins/textviewer/syntaxhighlighter/compass/shThemeFadeToGrey.scss b/plugins/textviewer/syntaxhighlighter/compass/shThemeFadeToGrey.scss index 7963814952f..3ec13b18277 100644 --- a/plugins/textviewer/syntaxhighlighter/compass/shThemeFadeToGrey.scss +++ b/plugins/textviewer/syntaxhighlighter/compass/shThemeFadeToGrey.scss @@ -4,19 +4,22 @@ $background: #121212 !default; $line_highlighted_background: #2C2C29 !default; -$line_highlighted_number: white !default; +$line_highlighted_number: +white !default; $gutter_text: #afafaf !default; $gutter_border_color: #3185b9 !default; $toolbar_collapsed_a: #3185b9 !default; $toolbar_collapsed_a_hover: #d01d33 !default; -$toolbar_collapsed_background: black !default; +$toolbar_collapsed_background: +black !default; $toolbar_a: #fff !default; $toolbar_a_hover: #96daff !default; -$code_plain: white !default; +$code_plain: +white !default; $code_comments: #696854 !default; $code_string: #e3e658 !default; $code_keyword: #d01d33 !default; @@ -32,5 +35,7 @@ $code_color3: #96daff !default; @import "_theme_template.scss"; .syntaxhighlighter { - .functions { font-weight: bold !important; } +.functions { font-weight: + bold !important; + } } diff --git a/plugins/textviewer/syntaxhighlighter/compass/shThemeMDUltra.scss b/plugins/textviewer/syntaxhighlighter/compass/shThemeMDUltra.scss index 0356fa6c934..c09517bdc86 100644 --- a/plugins/textviewer/syntaxhighlighter/compass/shThemeMDUltra.scss +++ b/plugins/textviewer/syntaxhighlighter/compass/shThemeMDUltra.scss @@ -4,29 +4,38 @@ $background: #222222 !default; $line_highlighted_background: #253e5a !default; -$line_highlighted_number: white !default; +$line_highlighted_number: +white !default; $gutter_text: #38566f !default; $gutter_border_color: #435a5f !default; $toolbar_collapsed_a: #428bdd !default; -$toolbar_collapsed_a_hover: lime !default; -$toolbar_collapsed_background: black !default; +$toolbar_collapsed_a_hover: +lime !default; +$toolbar_collapsed_background: +black !default; $toolbar_a: #aaaaff !default; $toolbar_a_hover: #9ccff4 !default; -$code_plain: lime !default; +$code_plain: +lime !default; $code_comments: #428bdd !default; -$code_string: lime !default; +$code_string: +lime !default; $code_keyword: #aaaaff !default; $code_preprocessor: #8aa6c1 !default; -$code_variable: aqua !default; +$code_variable: +aqua !default; $code_value: #f7e741 !default; $code_functions: #ff8000 !default; -$code_constants: yellow !default; -$code_color1: red !default; -$code_color2: yellow !default; +$code_constants: +yellow !default; +$code_color1: +red !default; +$code_color2: +yellow !default; $code_color3: #ffaa3e !default; @import "_theme_template.scss"; diff --git a/plugins/textviewer/syntaxhighlighter/compass/shThemeMidnight.scss b/plugins/textviewer/syntaxhighlighter/compass/shThemeMidnight.scss index a4dae02305f..55a630bb331 100644 --- a/plugins/textviewer/syntaxhighlighter/compass/shThemeMidnight.scss +++ b/plugins/textviewer/syntaxhighlighter/compass/shThemeMidnight.scss @@ -26,7 +26,8 @@ $code_value: #f7e741 !default; $code_functions: #ffaa3e !default; $code_constants: #e0e8ff !default; $code_color1: #f8bb00 !default; -$code_color2: white !default; +$code_color2: +white !default; $code_color3: #ffaa3e !default; @import "_theme_template.scss"; diff --git a/plugins/textviewer/syntaxhighlighter/compass/shThemeRDark.scss b/plugins/textviewer/syntaxhighlighter/compass/shThemeRDark.scss index 3b67b153721..f37acb25c42 100644 --- a/plugins/textviewer/syntaxhighlighter/compass/shThemeRDark.scss +++ b/plugins/textviewer/syntaxhighlighter/compass/shThemeRDark.scss @@ -26,7 +26,8 @@ $code_value: #009900 !default; $code_functions: #ffaa3e !default; $code_constants: #e0e8ff !default; $code_color1: #e0e8ff !default; -$code_color2: white !default; +$code_color2: +white !default; $code_color3: #ffaa3e !default; @import "_theme_template.scss"; diff --git a/settings/index.php b/settings/index.php index 9791e287306..85e4281c919 100644 --- a/settings/index.php +++ b/settings/index.php @@ -1,7 +1,7 @@ Date: Sat, 16 Apr 2011 10:17:40 +0200 Subject: move OC_DB to it's own file --- lib/app.php | 2 +- lib/base.php | 295 +-------------------------------------------------- lib/database.php | 316 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 318 insertions(+), 295 deletions(-) create mode 100644 lib/database.php (limited to 'lib/base.php') diff --git a/lib/app.php b/lib/app.php index f9101ba4052..cbcb1f7b8d3 100644 --- a/lib/app.php +++ b/lib/app.php @@ -51,7 +51,7 @@ class OC_APP{ // Our very own core apps are hardcoded foreach( array( "admin", "files", "log", "settings" ) as $app ){ - oc_require( "$app/appinfo/app.php" ); + require( "$app/appinfo/app.php" ); } // The rest comes here diff --git a/lib/base.php b/lib/base.php index 4e87ea66e2a..9df61da78c3 100644 --- a/lib/base.php +++ b/lib/base.php @@ -78,6 +78,7 @@ if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){ // load core libs require_once('helper.php'); +require_once('database.php'); require_once('app.php'); require_once('files.php'); require_once('filesystem.php'); @@ -349,300 +350,6 @@ class OC_HOOK{ } } -/** - * This class manages the access to the database. It basically is a wrapper for - * MDB2 with some adaptions. - */ -class OC_DB { - static private $DBConnection=false; - static private $schema=false; - static private $affected=0; - static private $result=false; - - /** - * @brief connects to the database - * @returns true if connection can be established or nothing (die()) - * - * Connects to the database as specified in config.php - */ - static public function connect(){ - // The global data we need - global $CONFIG_DBNAME; - global $CONFIG_DBHOST; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; - global $CONFIG_DBTYPE; - global $DOCUMENTROOT; - global $SERVERROOT; - - // do nothing if the connection already has been established - if(!self::$DBConnection){ - // Require MDB2.php (not required in the head of the file so we only load it when needed) - require_once('MDB2.php'); - - // Prepare options array - $options = array( - 'portability' => MDB2_PORTABILITY_ALL, - 'log_line_break' => '
      ', - 'idxname_format' => '%s', - 'debug' => true, - 'quote_identifier' => true ); - - // Add the dsn according to the database type - if( $CONFIG_DBTYPE == 'sqlite' ){ - // sqlite - $dsn = array( - 'phptype' => 'sqlite', - 'database' => "$SERVERROOT/$CONFIG_DBNAME", - 'mode' => '0644' ); - } - elseif( $CONFIG_DBTYPE == 'mysql' ){ - // MySQL - $dsn = array( - 'phptype' => 'mysql', - 'username' => $CONFIG_DBUSER, - 'password' => $CONFIG_DBPASSWORD, - 'hostspec' => $CONFIG_DBHOST, - 'database' => $CONFIG_DBNAME ); - } - elseif( $CONFIG_DBTYPE == 'pgsql' ){ - // PostgreSQL - $dsn = array( - 'phptype' => 'pgsql', - 'username' => $CONFIG_DBUSER, - 'password' => $CONFIG_DBPASSWORD, - 'hostspec' => $CONFIG_DBHOST, - 'database' => $CONFIG_DBNAME ); - } - - // Try to establish connection - self::$DBConnection = MDB2::factory( $dsn, $options ); - - // Die if we could not connect - if( PEAR::isError( self::$DBConnection )){ - echo( 'can not connect to database, using '.$CONFIG_DBTYPE.'. ('.self::$DBConnection->getUserInfo().')'); - $error = self::$DBConnection->getMessage(); - error_log( $error); - error_log( self::$DBConnection->getUserInfo()); - die( $error ); - } - - // We always, really always want associative arrays - self::$DBConnection->setFetchMode(MDB2_FETCHMODE_ASSOC); - } - - // we are done. great! - return true; - } - - /** - * @brief SQL query - * @param $query Query string - * @returns result as MDB2_Result - * - * SQL query via MDB2 query() - */ - static public function query( $query ){ - // Optimize the query - $query = self::processQuery( $query ); - - self::connect(); - //fix differences between sql versions - - // return the result - $result = self::$DBConnection->exec( $query ); - - // Die if we have an error (error means: bad query, not 0 results!) - if( PEAR::isError($result)) { - $entry = 'DB Error: "'.$result->getMessage().'"
      '; - $entry .= 'Offending command was: '.$cmd.'
      '; - error_log( $entry ); - die( $entry ); - } - - return $result; - } - - /** - * @brief Prepare a SQL query - * @param $query Query string - * @returns prepared SQL query - * - * SQL query via MDB2 prepare(), needs to be execute()'d! - */ - static public function prepare( $query ){ - // Optimize the query - $query = self::processQuery( $query ); - - self::connect(); - // return the result - $result = self::$DBConnection->prepare( $query ); - - // Die if we have an error (error means: bad query, not 0 results!) - if( PEAR::isError($result)) { - $entry = 'DB Error: "'.$result->getMessage().'"
      '; - $entry .= 'Offending command was: '.$cmd.'
      '; - error_log( $entry ); - die( $entry ); - } - - return $result; - } - - /** - * @brief gets last value of autoincrement - * @returns id - * - * MDB2 lastInsertID() - * - * Call this method right after the insert command or other functions may - * cause trouble! - */ - public static function insertid(){ - self::connect(); - return self::$DBConnection->lastInsertID(); - } - - /** - * @brief Disconnect - * @returns true/false - * - * This is good bye, good bye, yeah! - */ - public static function disconnect(){ - // Cut connection if required - if(self::$DBConnection){ - self::$DBConnection->disconnect(); - self::$DBConnection=false; - } - - return true; - } - - /** - * @brief Escapes bad characters - * @param $string string with dangerous characters - * @returns escaped string - * - * MDB2 escape() - */ - public static function escape( $string ){ - self::connect(); - return self::$DBConnection->escape( $string ); - } - - /** - * @brief saves database scheme to xml file - * @param $file name of file - * @returns true/false - * - * TODO: write more documentation - */ - public static function getDbStructure( $file ){ - self::connectScheme(); - - // write the scheme - $definition = self::$schema->getDefinitionFromDatabase(); - $dump_options = array( - 'output_mode' => 'file', - 'output' => $file, - 'end_of_line' => "\n" - ); - self::$schema->dumpDatabase( $definition, $dump_options, MDB2_SCHEMA_DUMP_STRUCTURE ); - - return true; - } - - /** - * @brief Creates tables from XML file - * @param $file file to read structure from - * @returns true/false - * - * TODO: write more documentation - */ - public static function createDbFromStructure( $file ){ - global $CONFIG_DBNAME; - global $CONFIG_DBTABLEPREFIX; - - self::connectScheme(); - - // read file - $content = file_get_contents( $file ); - - // Make changes and save them to a temporary file - $file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' ); - $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); - $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content ); - file_put_contents( $file2, $content ); - - // Try to create tables - $definition = @self::$schema->parseDatabaseDefinitionFile( $file2 ); - - // Delete our temporary file - unlink( $file2 ); - - // Die in case something went wrong - if( $definition instanceof MDB2_Schema_Error ){ - die( $definition->getMessage().': '.$definition->getUserInfo()); - } - $ret=@self::$schema->createDatabase( $definition ); - - // Die in case something went wrong - if( $ret instanceof MDB2_Error ){ - die ($ret->getMessage() . ': ' . $ret->getUserInfo()); - } - - return true; - } - - /** - * @brief connects to a MDB2 database scheme - * @returns true/false - * - * Connects to a MDB2 database scheme - */ - private static function connectScheme(){ - // We need a database connection - self::connect(); - - // Connect if this did not happen before - if(!self::$schema){ - require_once('MDB2/Schema.php'); - self::$schema=&MDB2_Schema::factory(self::$DBConnection); - } - - return true; - } - - /** - * @brief does minor chages to query - * @param $query Query string - * @returns corrected query string - * - * This function replaces *PREFIX* with the value of $CONFIG_DBTABLEPREFIX - * and replaces the ` woth ' or " according to the database driver. - */ - private static function processQuery( $query ){ - // We need Database type and table prefix - global $CONFIG_DBTYPE; - global $CONFIG_DBTABLEPREFIX; - - // differences in escaping of table names (` for mysql) - // Problem: what if there is a ` in the value we want to insert? - if( $CONFIG_DBTYPE == 'sqlite' ){ - $query = str_replace( '`', '\'', $query ); - } - elseif( $CONFIG_DBTYPE == 'pgsql' ){ - $query = str_replace( '`', '"', $query ); - } - - // replace table names - $query = str_replace( '*PREFIX*', $CONFIG_DBTABLEPREFIX, $query ); - - return $query; - } -} - function chmodr($path, $filemode) { // echo "$path
      "; if (!is_dir($path)) diff --git a/lib/database.php b/lib/database.php new file mode 100644 index 00000000000..6d65665df43 --- /dev/null +++ b/lib/database.php @@ -0,0 +1,316 @@ +. + * + */ + +/** + * This class manages the access to the database. It basically is a wrapper for + * MDB2 with some adaptions. + */ +class OC_DB { + static private $DBConnection=false; + static private $schema=false; + static private $affected=0; + static private $result=false; + + /** + * @brief connects to the database + * @returns true if connection can be established or nothing (die()) + * + * Connects to the database as specified in config.php + */ + static public function connect(){ + // The global data we need + global $CONFIG_DBNAME; + global $CONFIG_DBHOST; + global $CONFIG_DBUSER; + global $CONFIG_DBPASSWORD; + global $CONFIG_DBTYPE; + global $DOCUMENTROOT; + global $SERVERROOT; + + // do nothing if the connection already has been established + if(!self::$DBConnection){ + // Require MDB2.php (not required in the head of the file so we only load it when needed) + require_once('MDB2.php'); + + // Prepare options array + $options = array( + 'portability' => MDB2_PORTABILITY_ALL, + 'log_line_break' => '
      ', + 'idxname_format' => '%s', + 'debug' => true, + 'quote_identifier' => true ); + + // Add the dsn according to the database type + if( $CONFIG_DBTYPE == 'sqlite' ){ + // sqlite + $dsn = array( + 'phptype' => 'sqlite', + 'database' => "$SERVERROOT/$CONFIG_DBNAME", + 'mode' => '0644' ); + } + elseif( $CONFIG_DBTYPE == 'mysql' ){ + // MySQL + $dsn = array( + 'phptype' => 'mysql', + 'username' => $CONFIG_DBUSER, + 'password' => $CONFIG_DBPASSWORD, + 'hostspec' => $CONFIG_DBHOST, + 'database' => $CONFIG_DBNAME ); + } + elseif( $CONFIG_DBTYPE == 'pgsql' ){ + // PostgreSQL + $dsn = array( + 'phptype' => 'pgsql', + 'username' => $CONFIG_DBUSER, + 'password' => $CONFIG_DBPASSWORD, + 'hostspec' => $CONFIG_DBHOST, + 'database' => $CONFIG_DBNAME ); + } + + // Try to establish connection + self::$DBConnection = MDB2::factory( $dsn, $options ); + + // Die if we could not connect + if( PEAR::isError( self::$DBConnection )){ + echo( 'can not connect to database, using '.$CONFIG_DBTYPE.'. ('.self::$DBConnection->getUserInfo().')'); + $error = self::$DBConnection->getMessage(); + error_log( $error); + error_log( self::$DBConnection->getUserInfo()); + die( $error ); + } + + // We always, really always want associative arrays + self::$DBConnection->setFetchMode(MDB2_FETCHMODE_ASSOC); + } + + // we are done. great! + return true; + } + + /** + * @brief SQL query + * @param $query Query string + * @returns result as MDB2_Result + * + * SQL query via MDB2 query() + */ + static public function query( $query ){ + // Optimize the query + $query = self::processQuery( $query ); + + self::connect(); + //fix differences between sql versions + + // return the result + $result = self::$DBConnection->exec( $query ); + + // Die if we have an error (error means: bad query, not 0 results!) + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"
      '; + $entry .= 'Offending command was: '.$cmd.'
      '; + error_log( $entry ); + die( $entry ); + } + + return $result; + } + + /** + * @brief Prepare a SQL query + * @param $query Query string + * @returns prepared SQL query + * + * SQL query via MDB2 prepare(), needs to be execute()'d! + */ + static public function prepare( $query ){ + // Optimize the query + $query = self::processQuery( $query ); + + self::connect(); + // return the result + $result = self::$DBConnection->prepare( $query ); + + // Die if we have an error (error means: bad query, not 0 results!) + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"
      '; + $entry .= 'Offending command was: '.$cmd.'
      '; + error_log( $entry ); + die( $entry ); + } + + return $result; + } + + /** + * @brief gets last value of autoincrement + * @returns id + * + * MDB2 lastInsertID() + * + * Call this method right after the insert command or other functions may + * cause trouble! + */ + public static function insertid(){ + self::connect(); + return self::$DBConnection->lastInsertID(); + } + + /** + * @brief Disconnect + * @returns true/false + * + * This is good bye, good bye, yeah! + */ + public static function disconnect(){ + // Cut connection if required + if(self::$DBConnection){ + self::$DBConnection->disconnect(); + self::$DBConnection=false; + } + + return true; + } + + /** + * @brief Escapes bad characters + * @param $string string with dangerous characters + * @returns escaped string + * + * MDB2 escape() + */ + public static function escape( $string ){ + self::connect(); + return self::$DBConnection->escape( $string ); + } + + /** + * @brief saves database scheme to xml file + * @param $file name of file + * @returns true/false + * + * TODO: write more documentation + */ + public static function getDbStructure( $file ){ + self::connectScheme(); + + // write the scheme + $definition = self::$schema->getDefinitionFromDatabase(); + $dump_options = array( + 'output_mode' => 'file', + 'output' => $file, + 'end_of_line' => "\n" + ); + self::$schema->dumpDatabase( $definition, $dump_options, MDB2_SCHEMA_DUMP_STRUCTURE ); + + return true; + } + + /** + * @brief Creates tables from XML file + * @param $file file to read structure from + * @returns true/false + * + * TODO: write more documentation + */ + public static function createDbFromStructure( $file ){ + global $CONFIG_DBNAME; + global $CONFIG_DBTABLEPREFIX; + + self::connectScheme(); + + // read file + $content = file_get_contents( $file ); + + // Make changes and save them to a temporary file + $file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' ); + $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); + $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content ); + file_put_contents( $file2, $content ); + + // Try to create tables + $definition = @self::$schema->parseDatabaseDefinitionFile( $file2 ); + + // Delete our temporary file + unlink( $file2 ); + + // Die in case something went wrong + if( $definition instanceof MDB2_Schema_Error ){ + die( $definition->getMessage().': '.$definition->getUserInfo()); + } + $ret=@self::$schema->createDatabase( $definition ); + + // Die in case something went wrong + if( $ret instanceof MDB2_Error ){ + die ($ret->getMessage() . ': ' . $ret->getUserInfo()); + } + + return true; + } + + /** + * @brief connects to a MDB2 database scheme + * @returns true/false + * + * Connects to a MDB2 database scheme + */ + private static function connectScheme(){ + // We need a database connection + self::connect(); + + // Connect if this did not happen before + if(!self::$schema){ + require_once('MDB2/Schema.php'); + self::$schema=&MDB2_Schema::factory(self::$DBConnection); + } + + return true; + } + + /** + * @brief does minor chages to query + * @param $query Query string + * @returns corrected query string + * + * This function replaces *PREFIX* with the value of $CONFIG_DBTABLEPREFIX + * and replaces the ` woth ' or " according to the database driver. + */ + private static function processQuery( $query ){ + // We need Database type and table prefix + global $CONFIG_DBTYPE; + global $CONFIG_DBTABLEPREFIX; + + // differences in escaping of table names (` for mysql) + // Problem: what if there is a ` in the value we want to insert? + if( $CONFIG_DBTYPE == 'sqlite' ){ + $query = str_replace( '`', '\'', $query ); + } + elseif( $CONFIG_DBTYPE == 'pgsql' ){ + $query = str_replace( '`', '"', $query ); + } + + // replace table names + $query = str_replace( '*PREFIX*', $CONFIG_DBTABLEPREFIX, $query ); + + return $query; + } +} +?> \ No newline at end of file -- cgit v1.2.3 From 69289bf9438f11df8d75fd034776983b997aa7b0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Apr 2011 10:23:15 +0200 Subject: move chmodr to OC_HELPER --- lib/base.php | 27 ++------------------------- lib/helper.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 25 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 9df61da78c3..c84d61b3214 100644 --- a/lib/base.php +++ b/lib/base.php @@ -256,7 +256,7 @@ class OC_UTIL { } $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); if(substr($prems,-1)!='0'){ - chmodr($CONFIG_DATADIRECTORY_ROOT,0770); + OC_HELPER::chmodr($CONFIG_DATADIRECTORY_ROOT,0770); clearstatcache(); $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); if(substr($prems,2,1)!='0'){ @@ -266,7 +266,7 @@ class OC_UTIL { if($CONFIG_ENABLEBACKUP){ $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); if(substr($prems,-1)!='0'){ - chmodr($CONFIG_BACKUPDIRECTORY,0770); + OC_HELPER::chmodr($CONFIG_BACKUPDIRECTORY,0770); clearstatcache(); $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); if(substr($prems,2,1)!='0'){ @@ -349,27 +349,4 @@ class OC_HOOK{ return true; } } - -function chmodr($path, $filemode) { -// echo "$path
      "; - if (!is_dir($path)) - return chmod($path, $filemode); - $dh = opendir($path); - while (($file = readdir($dh)) !== false) { - if($file != '.' && $file != '..') { - $fullpath = $path.'/'.$file; - if(is_link($fullpath)) - return FALSE; - elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode)) - return FALSE; - elseif(!chmodr($fullpath, $filemode)) - return FALSE; - } - } - closedir($dh); - if(chmod($path, $filemode)) - return TRUE; - else - return FALSE; -} ?> diff --git a/lib/helper.php b/lib/helper.php index 982da7b6cc3..c51629f21cb 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -113,6 +113,35 @@ class OC_HELPER { $bytes = round( $bytes / 1024, 1 ); return "$bytes GB"; } + + /** + * @brief Recusive editing of file permissions + * @param $path path to file or folder + * @param $filemode unix style file permissions as integer + * + * Makes 2048 to 2 kB. + */ + function chmodr($path, $filemode) { + if (!is_dir($path)) + return chmod($path, $filemode); + $dh = opendir($path); + while (($file = readdir($dh)) !== false) { + if($file != '.' && $file != '..') { + $fullpath = $path.'/'.$file; + if(is_link($fullpath)) + return FALSE; + elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode)) + return FALSE; + elseif(!chmodr($fullpath, $filemode)) + return FALSE; + } + } + closedir($dh); + if(chmod($path, $filemode)) + return TRUE; + else + return FALSE; + } } ?> -- cgit v1.2.3 From fc33094429a942c97fb098b6ecc2c6708f507603 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Sat, 16 Apr 2011 11:11:16 +0200 Subject: replaced $CONFIG_DB* with OC_CONFIG::getValue( "db*" ) --- lib/base.php | 14 ++++++++++---- lib/database.php | 18 +++++++++--------- lib/plugin.php | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index c84d61b3214..270bf09e9ac 100644 --- a/lib/base.php +++ b/lib/base.php @@ -51,6 +51,9 @@ set_include_path($SERVERROOT.'/lib'.PATH_SEPARATOR.$SERVERROOT.'/config'.PATH_SE if( !isset( $RUNTIME_NOSETUPFS )){ $RUNTIME_NOSETUPFS = false; } +if( !isset( $RUNTIME_NOAPPS )){ + $RUNTIME_NOAPPS = false; +} // define default config values $CONFIG_INSTALLED=false; @@ -113,8 +116,11 @@ OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" ); OC_UTIL::addScript( "js" ); OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); OC_UTIL::addStyle( "styles" ); + // Load Apps -OC_APP::loadApps(); +if( !$RUNTIME_NOAPPS ){ + OC_APP::loadApps(); +} // check if the server is correctly configured for ownCloud OC_UTIL::checkserver(); @@ -232,13 +238,13 @@ class OC_UTIL { global $CONFIG_DATADIRECTORY_ROOT; global $CONFIG_BACKUPDIRECTORY; global $CONFIG_ENABLEBACKUP; - global $CONFIG_INSTALLED; + $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); $error=''; if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ $error.='No database drivers (sqlite or mysql) installed.
      '; } - global $CONFIG_DBTYPE; - global $CONFIG_DBNAME; + $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); + $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); if(!stristr(PHP_OS, 'WIN')){ if($CONFIG_DBTYPE=='sqlite'){ $file=$SERVERROOT.'/'.$CONFIG_DBNAME; diff --git a/lib/database.php b/lib/database.php index 6d65665df43..dc4bf75649b 100644 --- a/lib/database.php +++ b/lib/database.php @@ -38,11 +38,11 @@ class OC_DB { */ static public function connect(){ // The global data we need - global $CONFIG_DBNAME; - global $CONFIG_DBHOST; - global $CONFIG_DBUSER; - global $CONFIG_DBPASSWORD; - global $CONFIG_DBTYPE; + $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" );; + $CONFIG_DBHOST = OC_CONFIG::getValue( "dbhost", "" );; + $CONFIG_DBUSER = OC_CONFIG::getValue( "dbuser", "" );; + $CONFIG_DBPASSWORD = OC_CONFIG::getValue( "dbpassword", "" );; + $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" );; global $DOCUMENTROOT; global $SERVERROOT; @@ -232,8 +232,8 @@ class OC_DB { * TODO: write more documentation */ public static function createDbFromStructure( $file ){ - global $CONFIG_DBNAME; - global $CONFIG_DBTABLEPREFIX; + $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); + $CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" ); self::connectScheme(); @@ -295,8 +295,8 @@ class OC_DB { */ private static function processQuery( $query ){ // We need Database type and table prefix - global $CONFIG_DBTYPE; - global $CONFIG_DBTABLEPREFIX; + $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); + $CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" ); // differences in escaping of table names (` for mysql) // Problem: what if there is a ` in the value we want to insert? diff --git a/lib/plugin.php b/lib/plugin.php index 0cec329ea35..0d4e9744dc3 100644 --- a/lib/plugin.php +++ b/lib/plugin.php @@ -90,7 +90,7 @@ class OC_PLUGIN{ * Load all plugins that aren't blacklisted */ public static function loadPlugins() { - global $CONFIG_INSTALLED; + $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); if($CONFIG_INSTALLED){ global $SERVERROOT; $plugins = self::listPlugins(); -- cgit v1.2.3 From 177fd27382ca425594037389ada6f7fa3392ba04 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Sat, 16 Apr 2011 11:25:21 +0200 Subject: Make OC_CONFIG working again --- lib/base.php | 3 --- lib/config.php | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 270bf09e9ac..20ce6dcc4c4 100644 --- a/lib/base.php +++ b/lib/base.php @@ -56,14 +56,11 @@ if( !isset( $RUNTIME_NOAPPS )){ } // define default config values -$CONFIG_INSTALLED=false; $CONFIG_DATADIRECTORY=$SERVERROOT.'/data'; $CONFIG_BACKUPDIRECTORY=$SERVERROOT.'/backup'; $CONFIG_HTTPFORCESSL=false; $CONFIG_ENABLEBACKUP=false; $CONFIG_DATEFORMAT='j M Y G:i'; -$CONFIG_DBNAME='owncloud'; -$CONFIG_DBTYPE='sqlite'; $CONFIG_FILESYSTEM=array(); // include the generated configfile diff --git a/lib/config.php b/lib/config.php index 1b7783403ca..ceea05c139b 100644 --- a/lib/config.php +++ b/lib/config.php @@ -126,8 +126,8 @@ class OC_CONFIG{ * * Reads the config file and saves it to the cache */ - private static function readData( $key ){ - if( !self::$init ){ + private static function readData(){ + if( self::$init ){ return true; } @@ -155,7 +155,7 @@ class OC_CONFIG{ * * Known flaws: Strings are not escaped properly */ - public static function writeData( $key ){ + public static function writeData(){ // We need the serverroot path global $SERVERROOT; -- cgit v1.2.3 From 8465f76e7e1aa5512d62905cc60a10f0fe3f0e02 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Sat, 16 Apr 2011 12:18:42 +0200 Subject: Use OC_CONFIG where possible --- config/config.sample.php | 25 +++++++++------- index.php | 42 +++++++++++++------------- lib/base.php | 76 ++++++++++++++++++++++-------------------------- lib/config.php | 2 +- lib/connect.php | 56 +++++++++++++++++------------------ lib/user.php | 2 +- 6 files changed, 101 insertions(+), 102 deletions(-) (limited to 'lib/base.php') diff --git a/config/config.sample.php b/config/config.sample.php index dc1a62f46e3..5575340bc1b 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -1,12 +1,15 @@ - false, +"dbtype" => "sqlite", +"dbname" => "owncloud", +"dbuser" => "", +"dbpassword" => "", +"dbhost" => "", +"dbtableprefix" => "", +"forcessl" => false, +"enablebackup" => false, +// "datadirectory" => "" +); ?> diff --git a/index.php b/index.php index 62a515fa20f..2f56510bfbb 100644 --- a/index.php +++ b/index.php @@ -24,29 +24,31 @@ require_once( 'lib/base.php' ); require_once( 'appconfig.php' ); require_once( 'template.php' ); +var_dump( $_SESSION ); +//exit; if( OC_USER::isLoggedIn()){ - if( $_GET["logout"] ){ - OC_USER::logout(); - OC_TEMPLATE::printGuestPage( "", "logout" ); - } - else{ - header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); - exit(); - } + if( $_GET["logout"] ){ + OC_USER::logout(); + OC_TEMPLATE::printGuestPage( "", "logout" ); + } + else{ + header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); + exit(); + } } else{ - if( OC_USER::login( $_POST["user"], $_POST["password"] )){ - header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); - exit(); - } - else{ - $error = false; - // Say "bad login" in case the user wanted to login - if( $_POST["user"] && $_POST["password"] ){ - $error = true; - } - OC_TEMPLATE::printGuestPage( "", "login", array( "error" => $error )); - } + if( OC_USER::login( $_POST["user"], $_POST["password"] )){ + header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); + exit(); + } + else{ + $error = false; + // Say "bad login" in case the user wanted to login + if( $_POST["user"] && $_POST["password"] ){ + $error = true; + } + OC_TEMPLATE::printGuestPage( "", "login", array( "error" => $error )); + } } ?> diff --git a/lib/base.php b/lib/base.php index 20ce6dcc4c4..6b3ca59e6be 100644 --- a/lib/base.php +++ b/lib/base.php @@ -55,24 +55,21 @@ if( !isset( $RUNTIME_NOAPPS )){ $RUNTIME_NOAPPS = false; } -// define default config values -$CONFIG_DATADIRECTORY=$SERVERROOT.'/data'; -$CONFIG_BACKUPDIRECTORY=$SERVERROOT.'/backup'; -$CONFIG_HTTPFORCESSL=false; -$CONFIG_ENABLEBACKUP=false; -$CONFIG_DATEFORMAT='j M Y G:i'; -$CONFIG_FILESYSTEM=array(); - -// include the generated configfile -@include_once($SERVERROOT.'/config/config.php'); - -$CONFIG_DATADIRECTORY_ROOT=$CONFIG_DATADIRECTORY;// store this in a seperate variable so we can change the data directory to jail users. +// Doing the config stuff first +require_once('config.php'); + +// TODO: we should get rid of this one, too +// WARNING: to make everything even more confusing, DATADIRECTORY is a var that +// changes and DATATIRECTORY_ROOT stays the same, but is set by +// "datadirectory". Any questions? +$CONFIG_DATADIRECTORY = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" ); + // redirect to https site if configured -if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){ +if( OC_CONFIG::getValue( "forcessl", false )){ if(!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') { $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; header("Location: $url"); - exit; + exit(); } } @@ -85,7 +82,6 @@ require_once('filesystem.php'); require_once('filestorage.php'); require_once('fileobserver.php'); require_once('log.php'); -require_once('config.php'); require_once('user.php'); require_once('group.php'); require_once('ocs.php'); @@ -95,11 +91,8 @@ require_once('plugin.php'); OC_PLUGIN::loadPlugins( "" ); -if(!isset($CONFIG_BACKEND)){ - $CONFIG_BACKEND='database'; -} -OC_USER::setBackend( $CONFIG_BACKEND ); -OC_GROUP::setBackend( $CONFIG_BACKEND ); +OC_USER::setBackend( OC_CONFIG::getValue( "userbackend", "database" )); +OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" )); // Set up file system unless forbidden if( !$RUNTIME_NOSETUPFS ){ @@ -138,11 +131,10 @@ class OC_UTIL { // Global Variables global $SERVERROOT; - global $CONFIG_DATADIRECTORY_ROOT; global $CONFIG_DATADIRECTORY; - global $CONFIG_BACKUPDIRECTORY; - global $CONFIG_ENABLEBACKUP; - global $CONFIG_FILESYSTEM; + + $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" ); + $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" ); // Create root dir if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ @@ -157,7 +149,7 @@ class OC_UTIL { if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem //first set up the local "root" storage and the backupstorage if needed $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY)); - if($CONFIG_ENABLEBACKUP){ + if( OC_CONFIG::getValue( "enablebackup", false )){ // This creates the Directorys recursively if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true ); @@ -173,18 +165,19 @@ class OC_UTIL { mkdir( $CONFIG_DATADIRECTORY, 0755, true ); } - //set up the other storages according to the system settings - foreach($CONFIG_FILESYSTEM as $storageConfig){ - if(OC_FILESYSTEM::hasStorageType($storageConfig['type'])){ - $arguments=$storageConfig; - unset($arguments['type']); - unset($arguments['mountpoint']); - $storage=OC_FILESYSTEM::createStorage($storageConfig['type'],$arguments); - if($storage){ - OC_FILESYSTEM::mount($storage,$storageConfig['mountpoint']); - } - } - } +// TODO: find a cool way for doing this +// //set up the other storages according to the system settings +// foreach($CONFIG_FILESYSTEM as $storageConfig){ +// if(OC_FILESYSTEM::hasStorageType($storageConfig['type'])){ +// $arguments=$storageConfig; +// unset($arguments['type']); +// unset($arguments['mountpoint']); +// $storage=OC_FILESYSTEM::createStorage($storageConfig['type'],$arguments); +// if($storage){ +// OC_FILESYSTEM::mount($storage,$storageConfig['mountpoint']); +// } +// } +// } //jail the user into his "home" directory OC_FILESYSTEM::chroot("/$user/$root"); @@ -232,9 +225,10 @@ class OC_UTIL { */ public static function checkServer(){ global $SERVERROOT; - global $CONFIG_DATADIRECTORY_ROOT; - global $CONFIG_BACKUPDIRECTORY; - global $CONFIG_ENABLEBACKUP; + global $CONFIG_DATADIRECTORY; + + $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );; + $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" ); $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); $error=''; if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ @@ -266,7 +260,7 @@ class OC_UTIL { $error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web
      '; } } - if($CONFIG_ENABLEBACKUP){ + if( OC_CONFIG::getValue( "enablebackup", false )){ $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); if(substr($prems,-1)!='0'){ OC_HELPER::chmodr($CONFIG_BACKUPDIRECTORY,0770); diff --git a/lib/config.php b/lib/config.php index ceea05c139b..2660f43cad7 100644 --- a/lib/config.php +++ b/lib/config.php @@ -172,7 +172,7 @@ class OC_CONFIG{ } else{ $value = str_replace( "'", "\\'", $value ); - $configContent .= "\"$key\" => '$value',\n"; + $content .= "\"$key\" => '$value',\n"; } } $content .= ");\n?>\n"; diff --git a/lib/connect.php b/lib/connect.php index 695ae482451..6fc8f2165cf 100644 --- a/lib/connect.php +++ b/lib/connect.php @@ -3,22 +3,22 @@ /** * ownCloud * -* @author Frank Karlitschek -* @copyright 2010 Frank Karlitschek karlitschek@kde.org -* +* @author Frank Karlitschek +* @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 +* 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 +* +* You should have received a copy of the GNU Affero General Public * License along with this library. If not, see . -* +* */ /** @@ -27,7 +27,7 @@ */ class OC_CONNECT{ static private $clouds=array(); - + static function connect($path,$user,$password){ $cloud=new OC_REMOTE_CLOUD($path,$user,$password); if($cloud->connected){ @@ -48,7 +48,7 @@ class OC_REMOTE_CLOUD{ private $path; private $connected=false; private $cookiefile=false; - + /** * make an api call to the remote cloud * @param string $action @@ -72,8 +72,8 @@ class OC_REMOTE_CLOUD{ curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($parameters)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); - curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); - curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); + curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); + curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $result=curl_exec($ch); $result=trim($result); @@ -86,12 +86,12 @@ class OC_REMOTE_CLOUD{ return false; } } - + public function __construct($path,$user,$password){ $this->path=$path; $this->connected=$this->apiCall('login',array('username'=>$user,'password'=>$password)); } - + /** * check if we are stull logged in on the remote cloud * @@ -102,14 +102,14 @@ class OC_REMOTE_CLOUD{ } return $this->apiCall('checklogin'); } - + public function __get($name){ switch($name){ case 'connected': return $this->connected; } } - + /** * disconnect from the remote cloud * @@ -121,7 +121,7 @@ class OC_REMOTE_CLOUD{ } $this->cookiefile=false; } - + /** * create a new file or directory * @param string $dir @@ -134,7 +134,7 @@ class OC_REMOTE_CLOUD{ } return $this->apiCall('new',array('dir'=>$dir,'name'=>$name,'type'=>$type),true); } - + /** * deletes a file or directory * @param string $dir @@ -146,7 +146,7 @@ class OC_REMOTE_CLOUD{ } return $this->apiCall('delete',array('dir'=>$dir,'file'=>$name),true); } - + /** * moves a file or directory * @param string $sorceDir @@ -160,7 +160,7 @@ class OC_REMOTE_CLOUD{ } return $this->apiCall('move',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true); } - + /** * copies a file or directory * @param string $sorceDir @@ -174,7 +174,7 @@ class OC_REMOTE_CLOUD{ } return $this->apiCall('copy',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true); } - + /** * get a file tree * @param string $dir @@ -185,7 +185,7 @@ class OC_REMOTE_CLOUD{ } return $this->apiCall('gettree',array('dir'=>$dir),true); } - + /** * get the files inside a directory of the remote cloud * @param string $dir @@ -196,7 +196,7 @@ class OC_REMOTE_CLOUD{ } return $this->apiCall('getfiles',array('dir'=>$dir),true); } - + /** * get a remove file and save it in a temporary file and return the path of the temporary file * @param string $dir @@ -215,28 +215,28 @@ class OC_REMOTE_CLOUD{ $fp=fopen($tmpfile,'w+'); $url=$this->path.="/files/api.php?action=get&dir=$dir&file=$file"; curl_setopt($ch,CURLOPT_URL,$url); - curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); - curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); + curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); + curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); fclose($fp); curl_close($ch); return $tmpfile; } - + public function sendFile($sourceDir,$sourceFile,$targetDir,$targetFile){ global $WEBROOT; $source=$sourceDir.'/'.$sourceFile; $tmp=OC_FILESYSTEM::toTmpFile($source); return $this->sendTmpFile($tmp,$targetDir,$targetFile); } - + public function sendTmpFile($tmp,$targetDir,$targetFile){ $token=sha1(uniqid().$tmp); global $WEBROOT; $file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token; rename($tmp,$file); - if((isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') { + if( OC_CONFIG::getValue( "forcessl", false ) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') { $url = "https://". $_SERVER['SERVER_NAME'] . $WEBROOT; }else{ $url = "http://". $_SERVER['SERVER_NAME'] . $WEBROOT; diff --git a/lib/user.php b/lib/user.php index 9841b8ef276..d70443b7e61 100644 --- a/lib/user.php +++ b/lib/user.php @@ -20,7 +20,7 @@ * */ -if( !$CONFIG_INSTALLED ){ +if( !OC_CONFIG::getValue( "installed", false )){ $_SESSION['user_id'] = ''; } -- cgit v1.2.3 From 1495ec0f31b63c9bb04047f47cbf68abaab30b12 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Apr 2011 15:47:27 +0200 Subject: show server configuration errors on seperate page --- index.php | 10 +++++++--- lib/base.php | 36 +++++++++++++++++++++++------------- templates/error.php | 15 +++++++++++++++ 3 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 templates/error.php (limited to 'lib/base.php') diff --git a/index.php b/index.php index 8f5c99fcd85..105a04ad76e 100644 --- a/index.php +++ b/index.php @@ -24,7 +24,12 @@ require_once( 'lib/base.php' ); require_once( 'appconfig.php' ); require_once( 'template.php' ); -if( OC_USER::isLoggedIn()){ + +// check if the server is correctly configured for ownCloud +$errors=OC_UTIL::checkServer(); +if(count($errors)>0){ + OC_TEMPLATE::printGuestPage( "", "error", array( "errors" => $errors )); +}elseif( OC_USER::isLoggedIn()){ if( $_GET["logout"] ){ OC_USER::logout(); header( "Location: $WEBROOT"); @@ -34,8 +39,7 @@ if( OC_USER::isLoggedIn()){ header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); exit(); } -} -else{ +}else{ if( OC_USER::login( $_POST["user"], $_POST["password"] )){ header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); exit(); diff --git a/lib/base.php b/lib/base.php index 6b3ca59e6be..31d4142900f 100644 --- a/lib/base.php +++ b/lib/base.php @@ -89,13 +89,17 @@ require_once('connect.php'); require_once('remotestorage.php'); require_once('plugin.php'); -OC_PLUGIN::loadPlugins( "" ); +$error=(count(OC_UTIL::checkServer())>0); + +if(!$error){ + OC_PLUGIN::loadPlugins( "" ); +} OC_USER::setBackend( OC_CONFIG::getValue( "userbackend", "database" )); OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" )); // Set up file system unless forbidden -if( !$RUNTIME_NOSETUPFS ){ +if(!$error and !$RUNTIME_NOSETUPFS ){ OC_UTIL::setupFS(); } @@ -108,12 +112,10 @@ OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); OC_UTIL::addStyle( "styles" ); // Load Apps -if( !$RUNTIME_NOAPPS ){ +if(!$error and !$RUNTIME_NOAPPS ){ OC_APP::loadApps(); } -// check if the server is correctly configured for ownCloud -OC_UTIL::checkserver(); /** * Class for utility functions * @@ -221,7 +223,7 @@ class OC_UTIL { /** * check if the current server configuration is suitable for ownCloud - * + * @return array with error messages */ public static function checkServer(){ global $SERVERROOT; @@ -230,12 +232,16 @@ class OC_UTIL { $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );; $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" ); $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); - $error=''; + $errors=array(); + + //check for database drivers if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ - $error.='No database drivers (sqlite or mysql) installed.
      '; + $errors[]='No database drivers (sqlite or mysql) installed.
      '; } $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); + + //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ if($CONFIG_DBTYPE=='sqlite'){ $file=$SERVERROOT.'/'.$CONFIG_DBNAME; @@ -246,7 +252,7 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($file)),-3); if(substr($prems,2,1)!='0'){ - $error.='SQLite database file ('.$file.') is readable from the web
      '; + $errors[]='SQLite database file ('.$file.') is readable from the web
      '; } } } @@ -257,7 +263,7 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); if(substr($prems,2,1)!='0'){ - $error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web
      '; + $errors[]='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web
      '; } } if( OC_CONFIG::getValue( "enablebackup", false )){ @@ -267,16 +273,20 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); if(substr($prems,2,1)!='0'){ - $error.='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web
      '; + $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web
      '; } } } }else{ //TODO: premisions checks for windows hosts } - if($error){ - die($error); + if(!is_writable($CONFIG_DATADIRECTORY_ROOT)){ + $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') not writable by ownCloud
      '; } + + //TODO: check for php modules + + return $errors; } } diff --git a/templates/error.php b/templates/error.php new file mode 100644 index 00000000000..e8f56d63bd1 --- /dev/null +++ b/templates/error.php @@ -0,0 +1,15 @@ + +
      + " alt="ownCloud" /> +



      +
        + +
      • + +
      +
      + -- cgit v1.2.3 From 964a55033adba52d3004ec90a82cdb5d521a7a97 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Sat, 16 Apr 2011 18:08:40 +0200 Subject: never ever call a function you just removed --- lib/base.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 31d4142900f..712ea54d706 100644 --- a/lib/base.php +++ b/lib/base.php @@ -104,7 +104,6 @@ if(!$error and !$RUNTIME_NOSETUPFS ){ } // Add the stuff we need always -OC_APP::addPersonalMenuEntry( array( "order" => 1000, "href" => OC_HELPER::linkTo( "", "index.php?logout=1" ), "name" => "Logout" )); OC_UTIL::addScript( "jquery-1.5.min" ); OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" ); OC_UTIL::addScript( "js" ); @@ -233,14 +232,14 @@ class OC_UTIL { $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" ); $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); $errors=array(); - + //check for database drivers if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ $errors[]='No database drivers (sqlite or mysql) installed.
      '; } $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); - + //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ if($CONFIG_DBTYPE=='sqlite'){ @@ -283,9 +282,9 @@ class OC_UTIL { if(!is_writable($CONFIG_DATADIRECTORY_ROOT)){ $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') not writable by ownCloud
      '; } - + //TODO: check for php modules - + return $errors; } } -- cgit v1.2.3 From f0e59b9043292a5abfb0b0d21763a0cd7306dad7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Apr 2011 18:26:13 +0200 Subject: better display for server configuration errors --- css/styles.css | 15 +++++++++++++++ lib/base.php | 26 +++++++++++++++++++------- templates/error.php | 6 ++++-- 3 files changed, 38 insertions(+), 9 deletions(-) (limited to 'lib/base.php') diff --git a/css/styles.css b/css/styles.css index 4fc5a39b8c0..d6e5ea8fcc0 100644 --- a/css/styles.css +++ b/css/styles.css @@ -633,3 +633,18 @@ p.actions a.delete border: 1px solid #CCC; text-align: right; } + +li.error{ + list-style:none; + width: 640px; + margin: 4em auto; + padding: 1em 1em 1em 4em; + background-color: #FEE; + background-image: url(../img/task-attention.png); + background-position: 0.8em 0.8em; + background-repeat: no-repeat; + border: 1px solid #CCC; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; +} \ No newline at end of file diff --git a/lib/base.php b/lib/base.php index 712ea54d706..dbeba1dd1f9 100644 --- a/lib/base.php +++ b/lib/base.php @@ -222,7 +222,7 @@ class OC_UTIL { /** * check if the current server configuration is suitable for ownCloud - * @return array with error messages + * @return array arrays with error messages and hints */ public static function checkServer(){ global $SERVERROOT; @@ -235,11 +235,23 @@ class OC_UTIL { //check for database drivers if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ - $errors[]='No database drivers (sqlite or mysql) installed.
      '; + $errors[]=array('error'=>'No database drivers (sqlite or mysql) installed.
      ','hint'=>'');//TODO: sane hint } $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); - + + //try to get the username the httpd server runs on, used in hints + $stat=stat($_SERVER['DOCUMENT_ROOT']); + if(is_callable('posix_getpwuid')){ + $serverUser=posix_getpwuid($stat['uid']); + $serverUser='\''.$serverUser['name'].'\''; + }else{ + $serverUser='\'www-data\' for ubuntu/debian';//TODO: try to detect the distro and give a guess based on that + } + + //common hint for all file permissons error messages + $permissionsHint="Permissions can usually be fixed by setting the owner of the directory to the user the web server runs as ($serverUser)"; + //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ if($CONFIG_DBTYPE=='sqlite'){ @@ -251,7 +263,7 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($file)),-3); if(substr($prems,2,1)!='0'){ - $errors[]='SQLite database file ('.$file.') is readable from the web
      '; + $errors[]=array('error'=>'SQLite database file ('.$file.') is readable from the web
      ','hint'=>$permissionsHint); } } } @@ -262,7 +274,7 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); if(substr($prems,2,1)!='0'){ - $errors[]='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web
      '; + $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web
      ','hint'=>$permissionsHint); } } if( OC_CONFIG::getValue( "enablebackup", false )){ @@ -272,7 +284,7 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); if(substr($prems,2,1)!='0'){ - $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web
      '; + $errors[]=array('error'=>'Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web
      ','hint'=>$permissionsHint); } } } @@ -280,7 +292,7 @@ class OC_UTIL { //TODO: premisions checks for windows hosts } if(!is_writable($CONFIG_DATADIRECTORY_ROOT)){ - $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') not writable by ownCloud
      '; + $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') not writable by ownCloud
      ','hint'=>$permissionsHint); } //TODO: check for php modules diff --git a/templates/error.php b/templates/error.php index e8f56d63bd1..5b71c1ef751 100644 --- a/templates/error.php +++ b/templates/error.php @@ -5,10 +5,12 @@ ?>
      " alt="ownCloud" /> -



        -
      • +
      • +
        +

        +
      -- cgit v1.2.3 From 5ccdea8e5bc80201ed8abab5b3a38e20b8b992cd Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Apr 2011 19:06:45 +0200 Subject: save installation state of databases in appconfig instead of plugin.xml --- lib/base.php | 1 + lib/plugin.php | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 9ecf7db0778..93d6fb66c7e 100644 --- a/lib/base.php +++ b/lib/base.php @@ -77,6 +77,7 @@ if( OC_CONFIG::getValue( "forcessl", false )){ require_once('helper.php'); require_once('database.php'); require_once('app.php'); +require_once('appconfig.php'); require_once('files.php'); require_once('filesystem.php'); require_once('filestorage.php'); diff --git a/lib/plugin.php b/lib/plugin.php index 0d4e9744dc3..d8291a8a758 100644 --- a/lib/plugin.php +++ b/lib/plugin.php @@ -52,7 +52,8 @@ class OC_PLUGIN{ //check for uninstalled db's if(isset($data['install']) and isset($data['install']['database'])){ foreach($data['install']['database'] as $db){ - if(!$data['install']['database_installed'][$db]){ + $installed=OC_APPCONFIG::getValue('plugin_installer','database_installed_'.$id.'_'.$db,'false'); + if($installed!='true'){ self::installDB($id); break; } @@ -339,13 +340,13 @@ class OC_PLUGIN{ global $SERVERROOT; $data=OC_PLUGIN::getPluginData($id); foreach($data['install']['database'] as $db){ - if (!$data['install']['database_installed'][$db]){ + $installed=OC_APPCONFIG::getValue('plugin_installer','database_installed_'.$id.'_'.$db,'false'); + if ($installed!='true'){ $file=$SERVERROOT.'/plugins/'.$id.'/'.$db; OC_DB::createDbFromStructure($file); - $data['install']['database_installed'][$db]=true; + OC_APPCONFIG::setValue('plugin_installer','database_installed_'.$id.'_'.$db,'true'); } } - self::savePluginData($id,$data); return true; } @@ -363,14 +364,13 @@ class OC_PLUGIN{ if(isset($pluginData['install'])){ foreach($pluginData['install']['database'] as $db){ OC_DB::createDbFromStructure($folder.'/'.$db); - $pluginData['install']['database_installed'][$db]=true; + OC_APPCONFIG::setValue('plugin_installer','database_installed_'.$id.'_'.$db,'true'); } foreach($pluginData['install']['include'] as $include){ include($folder.'/'.$include); } } recursive_copy($folder,$SERVERROOT.'/plugins/'.$pluginData['info']['id']); - self::savePluginData($SERVERROOT.'/plugins/'.$pluginData['info']['id'].'/plugin.xml',$pluginData); } } delTree($folder); -- cgit v1.2.3 From d002ed0b944ec2ed269d2aedd589a51b64c67a60 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Apr 2011 20:07:57 +0200 Subject: set strict error reporting --- lib/base.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 93d6fb66c7e..7e862b978b1 100644 --- a/lib/base.php +++ b/lib/base.php @@ -23,8 +23,7 @@ // set some stuff //ob_start(); -// error_reporting(E_ALL | E_STRICT); -error_reporting( E_ERROR | E_PARSE | E_WARNING ); // MDB2 gives loads of strict error, disabling for now +error_reporting(E_ALL | E_STRICT); date_default_timezone_set('Europe/Berlin'); ini_set('arg_separator.output','&'); -- cgit v1.2.3 From bf45dcb959a4afbfcfb158dea55acf3804c49ea9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Apr 2011 20:27:08 +0200 Subject: only check for permissions for folders that exists --- lib/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 7e862b978b1..05ff4040b9d 100644 --- a/lib/base.php +++ b/lib/base.php @@ -292,7 +292,7 @@ class OC_UTIL { }else{ //TODO: premisions checks for windows hosts } - if(!is_writable($CONFIG_DATADIRECTORY_ROOT)){ + if(is_dir($CONFIG_DATADIRECTORY_ROOT) and !is_writable($CONFIG_DATADIRECTORY_ROOT)){ $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') not writable by ownCloud
      ','hint'=>$permissionsHint); } -- cgit v1.2.3 From 1372d8339d78c01b1514708f26520e244cc991e2 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Sat, 16 Apr 2011 20:34:18 +0200 Subject: add a date format function for more eyecandy --- admin/apps.php | 35 ++++++++++++++++++++++++++--------- admin/templates/apps.php | 4 ++-- lib/base.php | 12 ++++++++++++ lib/ocsclient.php | 2 +- 4 files changed, 41 insertions(+), 12 deletions(-) (limited to 'lib/base.php') diff --git a/admin/apps.php b/admin/apps.php index b03357a0fb0..b433fe0875b 100644 --- a/admin/apps.php +++ b/admin/apps.php @@ -28,25 +28,42 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' exit(); } - // Load the files we need //OC_UTIL::addStyle( "", "files" ); //OC_UTIL::addScript( "", "files" ); +if(isset($_GET['id'])) $id=$_GET['id']; else $id=0; +if(isset($_GET['cat'])) $cat=$_GET['cat']; else $cat=0; + $categories=OC_OCSCLIENT::getCategories(); -//print_r($categories); -$apps=OC_OCSCLIENT::getApplications($categories); -//print_r($apps); +if($id==0) { + + if($cat==0){ + $apps=OC_OCSCLIENT::getApplications($categories); + }else{ + $apps=OC_OCSCLIENT::getApplications($cat); + } + + // return template + $tmpl = new OC_TEMPLATE( "admin", "apps", "admin" ); -// return template -$tmpl = new OC_TEMPLATE( "admin", "apps", "admin" ); + $tmpl->assign( "categories", $categories ); + $tmpl->assign( "apps", $apps ); + $tmpl->printPage(); + unset($tmpl); -$tmpl->assign( "categories", $categories ); -$tmpl->assign( "apps", $apps ); -$tmpl->printPage(); +}else{ + $app=OC_OCSCLIENT::getApplication($id); + + $tmpl = new OC_TEMPLATE( "admin", "app", "admin" ); + $tmpl->assign( "app", $app ); + $tmpl->printPage(); + unset($tmpl); + +} ?> diff --git a/admin/templates/apps.php b/admin/templates/apps.php index c3f4fdfcc19..2f584775815 100644 --- a/admin/templates/apps.php +++ b/admin/templates/apps.php @@ -18,9 +18,9 @@ - "") { echo(''); } ?> + "") { echo(''); } ?> - + + diff --git a/lib/base.php b/lib/base.php index 93d6fb66c7e..8504518dbfb 100644 --- a/lib/base.php +++ b/lib/base.php @@ -222,6 +222,18 @@ class OC_UTIL { self::$styles[] = "$application/css/$file"; } + /** + * formats a timestamp in the "right" way + * + * @param timestamp $timestamp + */ + public static function formatDate( $timestamp ){ + $timeformat='F j, Y, H:i'; + return date($timeformat,$timestamp); + } + + + /** * check if the current server configuration is suitable for ownCloud * @return array arrays with error messages and hints diff --git a/lib/ocsclient.php b/lib/ocsclient.php index e58a210077e..d9ce11d537e 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -74,7 +74,7 @@ class OC_OCSCLIENT{ $app['personid']=$tmp[$i]->personid; $app['detailpage']=$tmp[$i]->detailpage; $app['preview']=$tmp[$i]->smallpreviewpic1; - $app['changed']=$tmp[$i]->changed; + $app['changed']=strtotime($tmp[$i]->changed); $app['description']=$tmp[$i]->description; $apps[]=$app; -- cgit v1.2.3 From 7b021516397648e51e6052d9fad4dfb422e09377 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 17 Apr 2011 18:19:40 +0200 Subject: make the file permissions hint more clear --- lib/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 9fc9d57f7ae..fad4007aa19 100644 --- a/lib/base.php +++ b/lib/base.php @@ -263,7 +263,7 @@ class OC_UTIL { } //common hint for all file permissons error messages - $permissionsHint="Permissions can usually be fixed by setting the owner of the directory to the user the web server runs as ($serverUser)"; + $permissionsHint="Permissions can usually be fixed by setting the owner of the file or directory to the user the web server runs as ($serverUser)"; //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ -- cgit v1.2.3 From 91b5d8575a403877106e4cd048d90e0c117dae66 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Sun, 17 Apr 2011 19:46:09 +0200 Subject: add pager function to the base lib and remove the default table width --- css/styles.css | 19 ++++++++++++++++++- help/index.php | 7 +++++++ help/templates/index.php | 6 +++++- lib/base.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) (limited to 'lib/base.php') diff --git a/css/styles.css b/css/styles.css index a186c173241..f0832d05947 100644 --- a/css/styles.css +++ b/css/styles.css @@ -70,7 +70,7 @@ form a { color:#000; text-decoration:none; } /* CONTENT ------------------------------------------------------------------ */ #content { margin:7em 0 0 16em; } -table { width:90%; margin:1em 5em 2em 3em; } +table { margin:1em 5em 2em 3em; } table tr.mouseOver td { background-color:#eee; } table th, table td { padding:0; border-bottom:1px solid #ddd; text-align:left; font-style:italic; } table th { padding:0.5em; } @@ -118,6 +118,23 @@ p.actions a.delete { background-image:url('../img/delete.png'); } #quota_indicator { margin:0 4em 1em 0; padding:0; border:1px solid #ddd; border-radius:10px; -webkit-border-radius:10px; -moz-border-radius:10px; } #quota_indicator div { background-color:#76A9EA; border-radius:10px; -webkit-border-radius:10px; -moz-border-radius:10px; } + +/* PAGER ------------------------------------------------------------ */ +.pager tr td +{ + border-bottom: 0px; +} + + +.pager tr td a +{ + text-decoration: none; + color: #666666; + font-size: 0.9em; + text-align: center; +} + + /* LOGS --------------------------------------------------------------------- */ #logs_options { width:auto; margin:0; } #logs_options p { padding:0.5em; text-align:left; } diff --git a/help/index.php b/help/index.php index 426abe39560..f77972f58a7 100644 --- a/help/index.php +++ b/help/index.php @@ -7,6 +7,11 @@ if( !OC_USER::isLoggedIn()){ exit(); } +//hardcode for testing +$pagecount=8; +$page=2; + + // Load the files we need OC_UTIL::addStyle( "help", "help" ); @@ -17,6 +22,8 @@ $kbe=OC_OCSCLIENT::getKnownledgebaseEntries(); $tmpl = new OC_TEMPLATE( "help", "index", "admin" ); $tmpl->assign( "kbe", $kbe ); +$tmpl->assign( "pagecount", $pagecount ); +$tmpl->assign( "page", $page ); $tmpl->printPage(); ?> diff --git a/help/templates/index.php b/help/templates/index.php index b8444c556e9..262ab3d8cab 100644 --- a/help/templates/index.php +++ b/help/templates/index.php @@ -1,7 +1,7 @@

      Questions and Answers

      - +
      @@ -13,6 +13,10 @@
      + ASK A QUESTION diff --git a/lib/base.php b/lib/base.php index fad4007aa19..ec305250809 100644 --- a/lib/base.php +++ b/lib/base.php @@ -231,6 +231,48 @@ class OC_UTIL { return date($timeformat,$timestamp); } + /** + * Shows a pagenavi widget where you can jump to different pages. + * + * @param int $pagecount + * @param int $page + * @param string $url + * @return html-string + */ + public static function showPageNavi($pagecount,$page,$url) { + + $pagelinkcount=8; + $txt=''; + if ($pagecount>1) { + $txt.='
      '; + + if ($page>'0') { + $txt.='prev  '; + } + $txt.=''; + + $pagestart=$page-$pagelinkcount; + if($pagestart<0) $pagestart=0; + $pagestop=$page+$pagelinkcount; + if($pagestop>$pagecount) $pagestop=$pagecount; + if ($pagestart<>0) $txt.='...'; + for ($i=$pagestart; $i < $pagestop;$i++) { + if ($i<>$page) { + $txt.=' '.($i+1).' '; + } else { + $txt.=' '.($i+1).' '; + } + } + if ($pagecount>$pagestop) $txt.='...'; + $txt.=''; + if (($page+1)<$pagecount) { + $txt.='next'; + } + $txt.='
      '; + } + echo($txt); + } + /** -- cgit v1.2.3 From 900ece18e787b294aa1c424af543ec14817b2302 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 18 Apr 2011 11:30:56 +0200 Subject: seperate view and logic for pagenavi --- lib/base.php | 31 ++++++++----------------------- templates/part.pagenavi.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 templates/part.pagenavi.php (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index ec305250809..352474e1e83 100644 --- a/lib/base.php +++ b/lib/base.php @@ -242,35 +242,20 @@ class OC_UTIL { public static function showPageNavi($pagecount,$page,$url) { $pagelinkcount=8; - $txt=''; if ($pagecount>1) { - $txt.='
      '; - - if ($page>'0') { - $txt.='prev  '; - } - $txt.=''; - $pagestart=$page-$pagelinkcount; if($pagestart<0) $pagestart=0; $pagestop=$page+$pagelinkcount; if($pagestop>$pagecount) $pagestop=$pagecount; - if ($pagestart<>0) $txt.='...'; - for ($i=$pagestart; $i < $pagestop;$i++) { - if ($i<>$page) { - $txt.=' '.($i+1).' '; - } else { - $txt.=' '.($i+1).' '; - } - } - if ($pagecount>$pagestop) $txt.='...'; - $txt.=''; - if (($page+1)<$pagecount) { - $txt.='next'; - } - $txt.='
      '; + + $tmpl = new OC_TEMPLATE( '', 'part.pagenavi', '' ); + $tmpl->assign('page',$page); + $tmpl->assign('pagecount',$pagecount); + $tmpl->assign('pagestart',$pagestart); + $tmpl->assign('pagestop',$pagestop); + $tmpl->assign('url',$url); + $tmpl->printPage(); } - echo($txt); } diff --git a/templates/part.pagenavi.php b/templates/part.pagenavi.php new file mode 100644 index 00000000000..1bb99b6173b --- /dev/null +++ b/templates/part.pagenavi.php @@ -0,0 +1,31 @@ +
      + + + + + + +
      + 0):?> + prev   + + + 0):?> + ... + + + +   + +   + + + + ... + + + + next + +
      +
      \ No newline at end of file -- cgit v1.2.3 From 67ba9b320ee37c3a89614f3241550c3a0176202a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 18 Apr 2011 12:16:47 +0200 Subject: seperate hooks for OC_FILESYSTEM and OC_FILESTORAGE --- lib/base.php | 1 - lib/filestorage.php | 56 +++++++++++++++++++++++++++++++---------------------- lib/filesystem.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 24 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 352474e1e83..15f849ce476 100644 --- a/lib/base.php +++ b/lib/base.php @@ -80,7 +80,6 @@ require_once('appconfig.php'); require_once('files.php'); require_once('filesystem.php'); require_once('filestorage.php'); -require_once('fileobserver.php'); require_once('log.php'); require_once('user.php'); require_once('group.php'); diff --git a/lib/filestorage.php b/lib/filestorage.php index c20d6d7b3e0..576a6dbdf34 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -24,11 +24,11 @@ * Privde a common interface to all different storage options * * Hooks provided: - * read(path) - * write(path) - * create(path) - * delete(path) - * rename(oldpath,newpath) + * read(storage,path) + * write(storage,path) + * create(storage,path) (when a file is created both, write and create will be emited) + * delete(storage,path) + * rename(storage,oldpath,newpath) */ class OC_FILESTORAGE{ public function __construct($parameters){} @@ -85,14 +85,14 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } public function rmdir($path){ if($return=rmdir($this->datadir.$path)){ - OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $path)); $this->clearFolderSizeCache($path); } return $return; } public function opendir($path){ if($return=opendir($this->datadir.$path)){ - OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); } return $return; } @@ -130,7 +130,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } public function readfile($path){ if($return=readfile($this->datadir.$path)){ - OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); } return $return; } @@ -145,26 +145,29 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } public function file_get_contents($path){ if($return=file_get_contents($this->datadir.$path)){ - OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); } return $return; } public function file_put_contents($path,$data){ + if(!$this->file_exists($path)){ + OC_HOOK::emit( 'OC_FILESTORAGE', 'create', array( 'storage'=>$this, 'path' => $path)); + } if($return=file_put_contents($this->datadir.$path,$data)){ - OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path)); $this->clearFolderSizeCache($path); } } public function unlink($path){ if($return=unlink($this->datadir.$path)){ - OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $path)); $this->clearFolderSizeCache($path); } return $return; } public function rename($path1,$path2){ if($return=rename($this->datadir.$path1,$this->datadir.$path2)){ - OC_HOOK::emit( "OC_FILESYSTEM", "rename", array( 'oldpath' => $path1, 'newpath' => $path2)); + OC_HOOK::emit( 'OC_FILESTORAGE', "rename", array( 'storage'=>$this, 'oldpath' => $path1, 'newpath' => $path2)); } return $return; } @@ -177,29 +180,36 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ $path2.=$source; } if($return=copy($this->datadir.$path1,$this->datadir.$path2)){ - OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path2)); + OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path2)); $this->clearFolderSizeCache($path); } return $return; } public function fopen($path,$mode){ + $exists=$this->file_exists($path); if($return=fopen($this->datadir.$path,$mode)){ switch($mode){ case 'r': - OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); break; case 'r+': case 'w+': case 'x+': case 'a+': - OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path)); - OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path)); + if(!$exists($path)){ + OC_HOOK::emit( 'OC_FILESTORAGE', 'create', array( 'storage'=>$this, 'path' => $path)); + } $this->clearFolderSizeCache($path); break; case 'w': case 'x': case 'a': - OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path)); + if(!$exists($path)){ + OC_HOOK::emit( 'OC_FILESTORAGE', 'create', array( 'storage'=>$this, 'path' => $path)); + } $this->clearFolderSizeCache($path); break; } @@ -362,7 +372,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ $fileStats = stat($this->datadir.$path); if(copy($this->datadir.$path,$filename)){ touch($filename, $fileStats['mtime'], $fileStats['atime']); - OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); return $filename; }else{ return false; @@ -373,7 +383,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ $fileStats = stat($tmpFile); if(rename($tmpFile,$this->datadir.$path)){ touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); - OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path)); $this->clearFolderSizeCache($path); return true; }else{ @@ -385,7 +395,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ $fileStats = stat($tmpFile); if(move_uploaded_file($tmpFile,$this->datadir.$path)){ touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); - OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path)); $this->clearFolderSizeCache($path); return true; }else{ @@ -402,7 +412,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ if ($item == '.' || $item == '..') continue; if(is_file($dir.'/'.$item)){ if(unlink($dir.'/'.$item)){ - OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $dir.'/'.$item)); + OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $dir.'/'.$item)); $this->clearFolderSizeCache($path); } }elseif(is_dir($dir.'/'.$item)){ @@ -412,7 +422,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } } if($return=rmdir($dir)){ - OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $dir)); + OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $dir)); $this->clearFolderSizeCache($path); } return $return; @@ -450,7 +460,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ public function hash($type,$path,$raw){ if($return=hash_file($type,$this->datadir.$path,$raw)){ - OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); } return $return; } diff --git a/lib/filesystem.php b/lib/filesystem.php index 033f50e2aba..ca4d1a2c474 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -26,6 +26,13 @@ * Class for abstraction of filesystem functions * This class won't call any filesystem functions for itself but but will pass them to the correct OC_FILESTORAGE object * this class should also handle all the file premission related stuff + * + * Hooks provided: + * read(path) + * write(path) + * create(path) (when a file is created both, write and create will be emited) + * delete(path) + * rename(oldpath,newpath) */ class OC_FILESYSTEM{ static private $storages=array(); @@ -191,16 +198,19 @@ class OC_FILESYSTEM{ static public function mkdir($path){ $parent=substr($path,0,strrpos($path,'/')); if(self::canWrite($parent) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path)); return $storage->mkdir(self::getInternalPath($path)); } } static public function rmdir($path){ if(self::canWrite($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'delete', array( 'path' => $path)); return $storage->rmdir(self::getInternalPath($path)); } } static public function opendir($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); return $storage->opendir(self::getInternalPath($path)); } } @@ -237,6 +247,7 @@ class OC_FILESYSTEM{ } static public function readfile($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); return $storage->readfile(self::getInternalPath($path)); } } @@ -278,16 +289,22 @@ class OC_FILESYSTEM{ } static public function file_get_contents($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); return $storage->file_get_contents(self::getInternalPath($path)); } } static public function file_put_contents($path,$data){ if(self::canWrite($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path)); + if(!self::file_exists($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path)); + } return $storage->file_put_contents(self::getInternalPath($path),$data); } } static public function unlink($path){ if(self::canWrite($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'delete', array( 'path' => $path)); return $storage->unlink(self::getInternalPath($path)); } } @@ -305,6 +322,7 @@ class OC_FILESYSTEM{ $storage1->unlink(self::getInternalPath($path1)); return $result; } + OC_HOOK::emit( 'OC_FILESYSTEM', 'rename', array( 'oldpath' => $path1 ,'newpath'=>$path2)); } } static public function copy($path1,$path2){ @@ -319,28 +337,61 @@ class OC_FILESYSTEM{ $tmpFile=$storage1->toTmpFile(self::getInternalPath($path1)); return $storage2->fromTmpFile(self::getInternalPath($path2)); } + OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path2)); } } static public function fopen($path,$mode){ $allowed=((strpos($path,'r')===false and strpos($path,'r+')!==false and self::canRead) or self::canWrite($path)); if($allowed){ if($storage=self::getStorage($path)){ + switch($mode){ + case 'r': + OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + break; + case 'r+': + case 'w+': + case 'x+': + case 'a+': + OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path)); + if(!self::file_exists($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path)); + } + break; + case 'w': + case 'x': + case 'a': + OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path)); + if(!self::file_exists($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path)); + } + break; + } return $storage->fopen(self::getInternalPath($path),$mode); } } } static public function toTmpFile($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); return $storage->toTmpFile(self::getInternalPath($path)); } } static public function fromTmpFile($tmpFile,$path){ if(self::canWrite($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path)); + if(!self::file_exists($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path)); + } return $storage->fromTmpFile($tmpFile,self::getInternalPath($path)); } } static public function fromUploadedFile($tmpFile,$path){ if(self::canWrite($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path)); + if(!self::file_exists($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path)); + } return $storage->fromUploadedFile($tmpFile,self::getInternalPath($path)); } } @@ -351,6 +402,7 @@ class OC_FILESYSTEM{ } static public function delTree($path){ if(self::canWrite($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'delete', array( 'path' => $path)); return $storage->delTree(self::getInternalPath($path)); } } @@ -383,6 +435,7 @@ class OC_FILESYSTEM{ } static public function hash($type,$path,$raw=false){ if(self::canRead($path) and $storage=self::getStorage($path)){ + OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); return $storage->hash($type,self::getInternalPath($path),$raw); } } -- cgit v1.2.3 From fe90bf4bdce4eb03722382ecbd054035d6b3c590 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 18 Apr 2011 12:18:45 +0200 Subject: disable the backup system for now --- lib/base.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 15f849ce476..acdea093d91 100644 --- a/lib/base.php +++ b/lib/base.php @@ -150,15 +150,15 @@ class OC_UTIL { if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem //first set up the local "root" storage and the backupstorage if needed $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY)); - if( OC_CONFIG::getValue( "enablebackup", false )){ - // This creates the Directorys recursively - if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ - mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true ); - } - $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); - $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); - $rootStorage->addObserver($backup); - } +// if( OC_CONFIG::getValue( "enablebackup", false )){ +// // This creates the Directorys recursively +// if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ +// mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true ); +// } +// $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); +// $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); +// $rootStorage->addObserver($backup); +// } OC_FILESYSTEM::mount($rootStorage,'/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; -- cgit v1.2.3 From d1b4f74bc2108963c347a6fb2526e89bbfb5afeb Mon Sep 17 00:00:00 2001 From: Marco Michelino Date: Tue, 19 Apr 2011 12:32:37 +0200 Subject: Avoid // in URIs --- lib/base.php | 12 ++++++++++-- lib/helper.php | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index acdea093d91..324b2f7e0a0 100644 --- a/lib/base.php +++ b/lib/base.php @@ -204,7 +204,11 @@ class OC_UTIL { $file = $application; $application = ""; } - self::$scripts[] = "$application/js/$file"; + if( !empty( $application )){ + self::$scripts[] = "$application/js/$file"; + }else{ + self::$scripts[] = "js/$file"; + } } /** @@ -217,7 +221,11 @@ class OC_UTIL { $file = $application; $application = ""; } - self::$styles[] = "$application/css/$file"; + if( !empty( $application )){ + self::$styles[] = "$application/css/$file"; + }else{ + self::$styles[] = "css/$file"; + } } /** diff --git a/lib/helper.php b/lib/helper.php index c4352ca3344..c141d6f0499 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -63,7 +63,11 @@ class OC_HELPER { if( file_exists( "$SERVERROOT/apps/img/$app/$image" )){ return "$WEBROOT/apps/img/$app/$image"; } - return "$WEBROOT/$app/img/$image"; + if( !empty( $app )){ + return "$WEBROOT/$app/img/$image"; + }else{ + return "$WEBROOT/img/$image"; + } } /** -- cgit v1.2.3 From cf76cad9317fae94c4dc9328db777e0feb562d26 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 21 Apr 2011 23:04:16 +0200 Subject: change printPageNavi() to getPageNavi() to allow some more flexibility --- help/templates/index.php | 3 ++- lib/base.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/base.php') diff --git a/help/templates/index.php b/help/templates/index.php index 262ab3d8cab..a117c3d5fb4 100644 --- a/help/templates/index.php +++ b/help/templates/index.php @@ -15,7 +15,8 @@ printPage(); ?> ASK A QUESTION diff --git a/lib/base.php b/lib/base.php index 324b2f7e0a0..1ab9b23bccb 100644 --- a/lib/base.php +++ b/lib/base.php @@ -244,9 +244,9 @@ class OC_UTIL { * @param int $pagecount * @param int $page * @param string $url - * @return html-string + * @return OC_TEMPLATE */ - public static function showPageNavi($pagecount,$page,$url) { + public static function getPageNavi($pagecount,$page,$url) { $pagelinkcount=8; if ($pagecount>1) { @@ -261,7 +261,7 @@ class OC_UTIL { $tmpl->assign('pagestart',$pagestart); $tmpl->assign('pagestop',$pagestop); $tmpl->assign('url',$url); - $tmpl->printPage(); + return $tmpl; } } -- cgit v1.2.3 From 4c0d6dc9e7842e1a21e5c01f50e0b61edffa34bf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 22 Apr 2011 17:50:04 +0200 Subject: make OC_HOOKS actually work --- lib/base.php | 10 +++++----- lib/filesystem.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 1ab9b23bccb..3f1bb6f3149 100644 --- a/lib/base.php +++ b/lib/base.php @@ -91,9 +91,9 @@ require_once('plugin.php'); $error=(count(OC_UTIL::checkServer())>0); -if(!$error){ - OC_PLUGIN::loadPlugins( "" ); -} +// if(!$error){ //disable untill plugin system is proper converted to the new code base +// OC_PLUGIN::loadPlugins( "" ); +// } OC_USER::setBackend( OC_CONFIG::getValue( "userbackend", "database" )); OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" )); @@ -191,7 +191,7 @@ class OC_UTIL { * @return array */ public static function getVersion(){ - return array(1,2,0); + return array(1,60,0); } /** @@ -406,7 +406,7 @@ class OC_HOOK{ } // Call all slots - foreach( $registered[$signalclass][$signalname] as $i ){ + foreach( self::$registered[$signalclass][$signalname] as $i ){ call_user_func( array( $i["class"], $i["name"] ), $params ); } diff --git a/lib/filesystem.php b/lib/filesystem.php index ca4d1a2c474..03fbecdc4c0 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -194,6 +194,18 @@ class OC_FILESYSTEM{ } return $foundMountPoint; } + /** + * return the path to a local version of the file + * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed + * @param string path + * @return string + */ + static public function getLocalFile($path){ + $parent=substr($path,0,strrpos($path,'/')); + if(self::canRead($parent) and $storage=self::getStorage($path)){ + return $storage->getLocalFile(self::getInternalPath($path)); + } + } static public function mkdir($path){ $parent=substr($path,0,strrpos($path,'/')); -- cgit v1.2.3 From b7aba15f179125455298aaee411864ebf4ed86f9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 24 Apr 2011 16:09:07 +0200 Subject: add search functionality, for now only searches files but plugins/apps can extend that --- css/styles.css | 4 ++ lib/base.php | 1 + lib/filestorage.php | 21 +++++++- lib/filesystem.php | 15 ++++++ lib/search.php | 121 +++++++++++++++++++++++++++++++++++++++++++ lib/template.php | 6 +++ search/appinfo/app.php | 5 ++ search/css/search.css | 17 ++++++ search/index.php | 55 ++++++++++++++++++++ search/templates/index.php | 17 ++++++ templates/layout.admin.php | 2 +- templates/layout.user.php | 2 +- templates/part.searchbox.php | 4 ++ 13 files changed, 267 insertions(+), 3 deletions(-) create mode 100644 lib/search.php create mode 100644 search/appinfo/app.php create mode 100644 search/css/search.css create mode 100644 search/index.php create mode 100644 search/templates/index.php create mode 100644 templates/part.searchbox.php (limited to 'lib/base.php') diff --git a/css/styles.css b/css/styles.css index 6b866843541..b737181d01b 100644 --- a/css/styles.css +++ b/css/styles.css @@ -130,3 +130,7 @@ p.actions a.delete, div.actions a.delete { background-image:url('../img/delete.p #logs_options input[type="submit"] { float:right; margin:0 2em 0 0; } #logs_options input[type="text"] { margin:0; padding:0; border:1px solid #ccc; text-align:right; } li.error{ list-style:none; width:640px; margin:4em auto; padding:1em 1em 1em 4em; background-color:#fee; background-image:url('../img/task-attention.png'); background-position:0.8em 0.8em; background-repeat:no-repeat; border:1px solid #ccc; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; } + +/* SEARCH --------------------------------------------------------------------- */ +form.searchbox{display:inline; position:fixed; top:1.5em; right:9em; margin:0; padding:0;}; +form.searchbox .prettybutton{font-size:1.5em !important}; \ No newline at end of file diff --git a/lib/base.php b/lib/base.php index 3f1bb6f3149..10d59a9d0d6 100644 --- a/lib/base.php +++ b/lib/base.php @@ -88,6 +88,7 @@ require_once('ocsclient.php'); require_once('connect.php'); require_once('remotestorage.php'); require_once('plugin.php'); +require_once('search.php'); $error=(count(OC_UTIL::checkServer())>0); diff --git a/lib/filestorage.php b/lib/filestorage.php index 3d0bdf4cc0e..429961b3d69 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -62,6 +62,7 @@ class OC_FILESTORAGE{ public function getTree($path){} public function hash($type,$path,$raw){} public function free_space($path){} + public function search($query){} } @@ -468,7 +469,25 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ public function free_space($path){ return disk_free_space($this->datadir.$path); } - + + public function search($query){ + return $this->searchInDir($query); + } + + private function searchInDir($query,$dir=''){ + $files=array(); + foreach (scandir($this->datadir.$dir) as $item) { + if ($item == '.' || $item == '..') continue; + if(strstr(strtolower($item),strtolower($query))!==false){ + $files[]=$dir.'/'.$item; + } + if(is_dir($this->datadir.$dir.'/'.$item)){ + $files=array_merge($files,$this->searchInDir($query,$dir.'/'.$item)); + } + } + return $files; + } + /** * @brief get the size of folder and it's content * @param string $path file path diff --git a/lib/filesystem.php b/lib/filesystem.php index 03fbecdc4c0..2b5c3a56b6e 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -457,5 +457,20 @@ class OC_FILESYSTEM{ return $storage->free_space($path); } } + + static public function search($query){ + $files=array(); + $fakeRootLength=strlen(self::$fakeRoot); + foreach(self::$storages as $mountpoint=>$storage){ + $results=$storage->search($query); + foreach($results as $result){ + $file=str_replace('//','/',$mountpoint.$result); + $file=substr($file,$fakeRootLength); + $files[]=$file; + } + } + return $files; + + } } ?> diff --git a/lib/search.php b/lib/search.php new file mode 100644 index 00000000000..ef82e225f3d --- /dev/null +++ b/lib/search.php @@ -0,0 +1,121 @@ +. + * + */ + + +/** + * provides an interface to all search providers + */ +class OC_SEARCH{ + static private $providers=array(); + + /** + * register a new search provider to be used + * @param OC_SearchProvider $provider + */ + public static function registerProvider($provider){ + self::$providers[]=$provider; + } + + /** + * search all provider for $query + * @param string query + * @return array An array of OC_SearchResult's + */ + public static function search($query){ + $results=array(); + foreach(self::$providers as $provider){ + $results=array_merge($results,$provider->search($query)); + } + return $results; + } +} + +/** + * provides search functionalty + */ +abstract class OC_SearchProvider{ + public function __construct(){ + OC_SEARCH::registerProvider($this); + } + + /** + * search for $query + * @param string $query + * @return array An array of OC_SearchResult's + */ + abstract function search($query); +} + +/** + * a result of a search + */ +class OC_SearchResult{ + private $name; + private $text; + private $link; + private $type; + + /** + * create a new search result + * @param string $name short name for the result + * @param string $text some more information about the result + * @param string $link link for the result + * @param string $type the type of result as human readable string ('File', 'Music', etc) + */ + public function __construct($name,$text,$link,$type){ + $this->name=$name; + $this->text=$text; + $this->link=$link; + $this->type=$type; + } + + public function __get($name){ + switch($name){ + case 'name': + return $this->name; + case 'text': + return $this->text; + case 'link': + return $this->link; + case 'type': + return $this->type; + } + } +} + +class OC_FileSearchProvider extends OC_SearchProvider{ + function search($query){ + $files=OC_FILESYSTEM::search($query); + $results=array(); + foreach($files as $file){ + if(OC_FILESYSTEM::is_dir($file)){ + $results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'index.php?dir='.$file ),'Files'); + }else{ + $results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'download.php?file='.$file ),'Files'); + } + } + return $results; + } +} + +new OC_FileSearchProvider(); +?> \ No newline at end of file diff --git a/lib/template.php b/lib/template.php index 75e4303ff6a..0d6776aa26d 100644 --- a/lib/template.php +++ b/lib/template.php @@ -190,6 +190,9 @@ class OC_TEMPLATE{ if( $this->renderas == "user" ) { $page = new OC_TEMPLATE( "core", "layout.user" ); + $search=new OC_TEMPLATE( 'core', 'part.searchbox'); + $search->assign('searchurl',OC_HELPER::linkTo( 'search', 'index.php' )); + $page->assign('searchbox', $search->fetchPage()); // Add menu data // Add navigation entry @@ -198,6 +201,9 @@ class OC_TEMPLATE{ elseif( $this->renderas == "admin" ) { $page = new OC_TEMPLATE( "core", "layout.admin" ); + $search=new OC_TEMPLATE( 'core', 'part.searchbox'); + $search->assign('searchurl',OC_HELPER::linkTo( 'search', 'index.php' )); + $page->assign('searchbox', $search->fetchPage()); // Add menu data if( OC_GROUP::inGroup( $_SESSION["user_id"], "admin" )){ $page->assign( "settingsnavigation", OC_APP::getSettingsNavigation()); diff --git a/search/appinfo/app.php b/search/appinfo/app.php new file mode 100644 index 00000000000..44834498fec --- /dev/null +++ b/search/appinfo/app.php @@ -0,0 +1,5 @@ + 2, "id" => 'search', 'name' => 'Search' )); + +?> diff --git a/search/css/search.css b/search/css/search.css new file mode 100644 index 00000000000..df0712be03f --- /dev/null +++ b/search/css/search.css @@ -0,0 +1,17 @@ +#searchresults{ + margin: 2em; + list-style:none; + border: solid 1px #CCC; +} + +#searchresults li.resultHeader{ + font-size:1.2em; + font-weight:bold; + border-bottom: solid 1px #CCC; + padding:0.2em; + background-color:#eee; +} + +#searchresults li.result{ + margin-left:2em; +} \ No newline at end of file diff --git a/search/index.php b/search/index.php new file mode 100644 index 00000000000..e6f41528ea3 --- /dev/null +++ b/search/index.php @@ -0,0 +1,55 @@ +. +* +*/ + + +// Init owncloud +require_once('../lib/base.php'); +require( 'template.php' ); + +// Check if we are a user +if( !OC_USER::isLoggedIn()){ + header( "Location: ".OC_HELPER::linkTo( '', 'index.php' )); + exit(); +} + +// Load the files we need +OC_UTIL::addStyle( 'search', 'search' ); + +$query=(isset($_POST['query']))?$_POST['query']:''; +if($query){ + $results=OC_SEARCH::search($query); +} + +$resultTypes=array(); +foreach($results as $result){ + if(!isset($resultTypes[$result->type])){ + $resultTypes[$result->type]=array(); + } + $resultTypes[$result->type][]=$result; +} + +$tmpl = new OC_TEMPLATE( 'search', 'index', 'user' ); +$tmpl->assign('resultTypes',$resultTypes); +$tmpl->printPage(); + +?> diff --git a/search/templates/index.php b/search/templates/index.php new file mode 100644 index 00000000000..7241553e7fc --- /dev/null +++ b/search/templates/index.php @@ -0,0 +1,17 @@ +
        + +
      • +

        type?>

        +
      • + +
      • +

        + name?> +

        +

        + text?> +

        +
      • + + +
      diff --git a/templates/layout.admin.php b/templates/layout.admin.php index 0212419a952..efd9a8b6fdb 100644 --- a/templates/layout.admin.php +++ b/templates/layout.admin.php @@ -15,7 +15,7 @@