aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--[-rwxr-xr-x]lib/app.php84
-rw-r--r--lib/appconfig.php34
-rw-r--r--lib/archive.php115
-rwxr-xr-xlib/archive/tar.php279
-rwxr-xr-xlib/archive/zip.php200
-rw-r--r--lib/base.php102
-rw-r--r--lib/connect.php40
-rw-r--r--lib/connector/sabre/directory.php2
-rw-r--r--lib/connector/sabre/principal.php4
-rw-r--r--lib/db.php40
-rw-r--r--lib/filecache.php97
-rw-r--r--lib/files.php19
-rw-r--r--lib/filestorage/common.php12
-rw-r--r--lib/filesystem.php49
-rw-r--r--lib/filesystemview.php19
-rw-r--r--lib/group.php7
-rw-r--r--lib/group/backend.php12
-rw-r--r--[-rwxr-xr-x]lib/helper.php108
-rw-r--r--lib/installer.php73
-rw-r--r--lib/json.php6
-rw-r--r--lib/l10n.php33
-rw-r--r--lib/log/owncloud.php12
-rw-r--r--lib/mail.php116
-rw-r--r--lib/migrate.php331
-rw-r--r--lib/migration/content.php18
-rw-r--r--lib/migration/provider.php8
-rw-r--r--lib/mimetypes.list.php2
-rw-r--r--[-rwxr-xr-x]lib/ocsclient.php6
-rw-r--r--lib/public/app.php169
-rw-r--r--lib/public/config.php133
-rw-r--r--lib/public/db.php92
-rw-r--r--lib/public/files.php114
-rw-r--r--lib/public/json.php94
-rw-r--r--lib/public/response.php106
-rw-r--r--lib/public/user.php106
-rw-r--r--lib/public/util.php200
-rw-r--r--lib/setup.php8
-rw-r--r--lib/template.php17
-rw-r--r--lib/updater.php4
-rw-r--r--lib/user.php9
-rw-r--r--lib/user/database.php2
-rw-r--r--lib/util.php68
-rw-r--r--lib/vobject.php6
43 files changed, 2586 insertions, 370 deletions
diff --git a/lib/app.php b/lib/app.php
index 1c81fbd4242..c8d3826bca5 100755..100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -35,6 +35,7 @@ class OC_App{
static private $adminForms = array();
static private $personalForms = array();
static private $appInfo = array();
+ static private $appTypes = array();
/**
* @brief loads all apps
@@ -54,7 +55,7 @@ class OC_App{
}
// Our very own core apps are hardcoded
- foreach( array('files', 'settings') as $app ){
+ foreach( array( 'settings') as $app ){
if(is_null($types)){
require( $app.'/appinfo/app.php' );
}
@@ -63,7 +64,7 @@ class OC_App{
// The rest comes here
$apps = self::getEnabledApps();
foreach( $apps as $app ){
- if(is_null($types) or self::isType($app,$types)){
+ if((is_null($types) or self::isType($app,$types))){
if(is_file(OC::$APPSROOT.'/apps/'.$app.'/appinfo/app.php')){
require( $app.'/appinfo/app.php' );
}
@@ -85,11 +86,7 @@ class OC_App{
if(is_string($types)){
$types=array($types);
}
- $appData=self::getAppInfo($app);
- if(!isset($appData['types'])){
- return false;
- }
- $appTypes=$appData['types'];
+ $appTypes=self::getAppTypes($app);
foreach($types as $type){
if(array_search($type,$appTypes)!==false){
return true;
@@ -99,14 +96,42 @@ class OC_App{
}
/**
+ * get the types of an app
+ * @param string $app
+ * @return array
+ */
+ private static function getAppTypes($app){
+ //load the cache
+ if(count(self::$appTypes)==0){
+ self::$appTypes=OC_Appconfig::getValues(false,'types');
+ }
+
+ //get it from info.xml if we haven't cached it
+ if(!isset(self::$appTypes[$app])){
+ $appData=self::getAppInfo($app);
+ if(isset($appData['types'])){
+ self::$appTypes[$app]=$appData['types'];
+ }else{
+ self::$appTypes[$app]=array();
+ }
+
+ OC_Appconfig::setValue($app,'types',implode(',',self::$appTypes[$app]));
+ }
+
+ return explode(',',self::$appTypes[$app]);
+ }
+
+ /**
* get all enabled apps
*/
public static function getEnabledApps(){
- $apps=array();
+ $apps=array('files');
$query = OC_DB::prepare( 'SELECT appid FROM *PREFIX*appconfig WHERE configkey = \'enabled\' AND configvalue=\'yes\'' );
$result=$query->execute();
while($row=$result->fetchRow()){
- $apps[]=$row['appid'];
+ if(array_search($row['appid'],$apps)===false){
+ $apps[]=$row['appid'];
+ }
}
return $apps;
}
@@ -139,13 +164,18 @@ class OC_App{
if(!is_numeric($app)){
OC_Installer::installShippedApp($app);
}else{
- $download=OC_OCSClient::getApplicationDownload($app,1);
- if(isset($download['downloadlink']) and $download['downloadlink']<>'') {
+ $download=OC_OCSClient::getApplicationDownload($app,1);
+ if(isset($download['downloadlink']) and $download['downloadlink']!='') {
$app=OC_Installer::installApp(array('source'=>'http','href'=>$download['downloadlink']));
}
}
}
- OC_Appconfig::setValue( $app, 'enabled', 'yes' );
+ if($app!==false){
+ OC_Appconfig::setValue( $app, 'enabled', 'yes' );
+ return true;
+ }else{
+ return false;
+ }
}
/**
@@ -249,7 +279,7 @@ class OC_App{
* entries are sorted by the key 'order' ascending.
*/
public static function getSettingsNavigation(){
- $l=new OC_L10N('core');
+ $l=OC_L10N::get('core');
$settings = array();
// by default, settings only contain the help menu
@@ -275,8 +305,6 @@ class OC_App{
$settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" ));
// admin apps menu
$settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
- // admin log menu
- $settings[] = array( "id" => "core_log", "order" => 4, "href" => OC_Helper::linkTo( "settings", "log.php" ), "name" => $l->t("Log"), "icon" => OC_Helper::imagePath( "settings", "log.svg" ));
$settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" ));
}
@@ -304,6 +332,20 @@ class OC_App{
}
/**
+ * get the last version of the app, either from appinfo/version or from appinfo/info.xml
+ */
+ public static function getAppVersion($appid){
+ $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/version';
+ $version=@file_get_contents($file);
+ if($version){
+ return $version;
+ }else{
+ $appData=self::getAppInfo($appid);
+ return $appData['version'];
+ }
+ }
+
+ /**
* @brief Read app metadata from the info.xml file
* @param string $appid id of the app or the path of the info.xml file
* @param boolean path (optional)
@@ -381,7 +423,6 @@ class OC_App{
$source=self::$settingsForms;
break;
case 'admin':
- $forms[] = include 'files/admin.php'; //hardcode own apps
$source=self::$adminForms;
break;
case 'personal':
@@ -436,12 +477,11 @@ class OC_App{
// The rest comes here
$versions = self::getAppVersions();
foreach( $versions as $app=>$installedVersion ){
- $appInfo=OC_App::getAppInfo($app);
- if (isset($appInfo['version'])) {
- $currentVersion=$appInfo['version'];
+ $currentVersion=OC_App::getAppVersion($app);
+ if ($currentVersion) {
if (version_compare($currentVersion, $installedVersion, '>')) {
OC_App::updateApp($app);
- OC_Appconfig::setValue($app,'installed_version',$appInfo['version']);
+ OC_Appconfig::setValue($app,'installed_version',OC_App::getAppVersion($app));
}
}
}
@@ -480,6 +520,10 @@ class OC_App{
public static function getStorage($appid){
if(OC_App::isEnabled($appid)){//sanity check
if(OC_User::isLoggedIn()){
+ $view = new OC_FilesystemView('/'.OC_User::getUser());
+ if(!$view->file_exists($appid)) {
+ $view->mkdir($appid);
+ }
return new OC_FilesystemView('/'.OC_User::getUser().'/'.$appid);
}else{
OC_Log::write('core','Can\'t get app storage, app, user not logged in',OC_Log::ERROR);
diff --git a/lib/appconfig.php b/lib/appconfig.php
index 2b5cef59adc..5aaaadd9c4a 100644
--- a/lib/appconfig.php
+++ b/lib/appconfig.php
@@ -163,4 +163,38 @@ class OC_Appconfig{
return true;
}
+
+ /**
+ * get multiply values, either the app or key can be used as wildcard by setting it to false
+ * @param app
+ * @param key
+ * @return array
+ */
+ public static function getValues($app,$key){
+ if($app!==false and $key!==false){
+ return false;
+ }
+ $where='WHERE';
+ $fields='configvalue';
+ $params=array();
+ if($app!==false){
+ $where.=' appid = ?';
+ $fields.=', configkey';
+ $params[]=$app;
+ $key='configkey';
+ }else{
+ $fields.=', appid';
+ $where.=' configkey = ?';
+ $params[]=$key;
+ $key='appid';
+ }
+ $queryString='SELECT '.$fields.' FROM *PREFIX*appconfig '.$where;
+ $query=OC_DB::prepare($queryString);
+ $result=$query->execute($params);
+ $values=array();
+ while($row=$result->fetchRow()){
+ $values[$row[$key]]=$row['configvalue'];
+ }
+ return $values;
+ }
}
diff --git a/lib/archive.php b/lib/archive.php
new file mode 100644
index 00000000000..113f92e9604
--- /dev/null
+++ b/lib/archive.php
@@ -0,0 +1,115 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+abstract class OC_Archive{
+ /**
+ * open any of the supporeted archive types
+ * @param string path
+ * @return OC_Archive
+ */
+ public static function open($path){
+ $ext=substr($path,strrpos($path,'.'));
+ switch($ext){
+ case '.zip':
+ return new OC_Archive_ZIP($path);
+ case '.gz':
+ case '.bz':
+ case '.bz2':
+ if(strpos($path,'.tar.')){
+ return new OC_Archive_TAR($path);
+ }
+ break;
+ case '.tgz':
+ return new OC_Archive_TAR($path);
+ }
+ }
+
+ abstract function __construct($source);
+ /**
+ * add an empty folder to the archive
+ * @param string path
+ * @return bool
+ */
+ abstract function addFolder($path);
+ /**
+ * add a file to the archive
+ * @param string path
+ * @param string source either a local file or string data
+ * @return bool
+ */
+ abstract function addFile($path,$source='');
+ /**
+ * rename a file or folder in the archive
+ * @param string source
+ * @param string dest
+ * @return bool
+ */
+ abstract function rename($source,$dest);
+ /**
+ * get the uncompressed size of a file in the archive
+ * @param string path
+ * @return int
+ */
+ abstract function filesize($path);
+ /**
+ * get the last modified time of a file in the archive
+ * @param string path
+ * @return int
+ */
+ abstract function mtime($path);
+ /**
+ * get the files in a folder
+ * @param path
+ * @return array
+ */
+ abstract function getFolder($path);
+ /**
+ *get all files in the archive
+ * @return array
+ */
+ abstract function getFiles();
+ /**
+ * get the content of a file
+ * @param string path
+ * @return string
+ */
+ abstract function getFile($path);
+ /**
+ * extract a single file from the archive
+ * @param string path
+ * @param string dest
+ * @return bool
+ */
+ abstract function extractFile($path,$dest);
+ /**
+ * extract the archive
+ * @param string path
+ * @param string dest
+ * @return bool
+ */
+ abstract function extract($dest);
+ /**
+ * check if a file or folder exists in the archive
+ * @param string path
+ * @return bool
+ */
+ abstract function fileExists($path);
+ /**
+ * remove a file or folder from the archive
+ * @param string path
+ * @return bool
+ */
+ abstract function remove($path);
+ /**
+ * get a file handler
+ * @param string path
+ * @param string mode
+ * @return resource
+ */
+ abstract function getStream($path,$mode);
+}
diff --git a/lib/archive/tar.php b/lib/archive/tar.php
new file mode 100755
index 00000000000..07f0ba5bd8a
--- /dev/null
+++ b/lib/archive/tar.php
@@ -0,0 +1,279 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once '3rdparty/Archive/Tar.php';
+
+class OC_Archive_TAR extends OC_Archive{
+ const PLAIN=0;
+ const GZIP=1;
+ const BZIP=2;
+
+ /**
+ * @var Archive_Tar tar
+ */
+ private $tar=null;
+ private $path;
+
+ function __construct($source){
+ $types=array(null,'gz','bz');
+ $this->path=$source;
+ $this->tar=new Archive_Tar($source,$types[self::getTarType($source)]);
+ }
+
+ /**
+ * try to detect the type of tar compression
+ * @param string file
+ * @return str
+ */
+ static public function getTarType($file){
+ if(strpos($file,'.')){
+ $extension=substr($file,strrpos($file,'.'));
+ switch($extension){
+ case 'gz':
+ case 'tgz':
+ return self::GZIP;
+ case 'bz':
+ case 'bz2':
+ return self::BZIP;
+ default:
+ return self::PLAIN;
+ }
+ }else{
+ return self::PLAIN;
+ }
+ }
+
+ /**
+ * add an empty folder to the archive
+ * @param string path
+ * @return bool
+ */
+ function addFolder($path){
+ $tmpBase=get_temp_dir().'/';
+ if(substr($path,-1,1)!='/'){
+ $path.='/';
+ }
+ if($this->fileExists($path)){
+ return false;
+ }
+ mkdir($tmpBase.$path);
+ $result=$this->tar->addModify(array($tmpBase.$path),'',$tmpBase);
+ rmdir($tmpBase.$path);
+ return $result;
+ }
+ /**
+ * add a file to the archive
+ * @param string path
+ * @param string source either a local file or string data
+ * @return bool
+ */
+ function addFile($path,$source=''){
+ if($this->fileExists($path)){
+ $this->remove($path);
+ }
+ if(file_exists($source)){
+ $header=array();
+ $dummy='';
+ $this->tar->_openAppend();
+ $result=$this->tar->_addfile($source,$header,$dummy,$dummy,$path);
+ }else{
+ $result=$this->tar->addString($path,$source);
+ }
+ return $result;
+ }
+
+ /**
+ * rename a file or folder in the archive
+ * @param string source
+ * @param string dest
+ * @return bool
+ */
+ function rename($source,$dest){
+ //no proper way to delete, rename entire archive, rename file and remake archive
+ $tmp=OCP\Files::tmpFolder();
+ $this->tar->extract($tmp);
+ rename($tmp.$source,$tmp.$dest);
+ $this->tar=null;
+ unlink($this->path);
+ $types=array(null,'gz','bz');
+ $this->tar=new Archive_Tar($this->path,$types[self::getTarType($this->path)]);
+ $this->tar->createModify(array($tmp),'',$tmp.'/');
+ }
+
+ private function getHeader($file){
+ $headers=$this->tar->listContent();
+ foreach($headers as $header){
+ if($file==$header['filename'] or $file.'/'==$header['filename']){
+ return $header;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * get the uncompressed size of a file in the archive
+ * @param string path
+ * @return int
+ */
+ function filesize($path){
+ $stat=$this->getHeader($path);
+ return $stat['size'];
+ }
+ /**
+ * get the last modified time of a file in the archive
+ * @param string path
+ * @return int
+ */
+ function mtime($path){
+ $stat=$this->getHeader($path);
+ return $stat['mtime'];
+ }
+
+ /**
+ * get the files in a folder
+ * @param path
+ * @return array
+ */
+ function getFolder($path){
+ $files=$this->getFiles();
+ $folderContent=array();
+ $pathLength=strlen($path);
+ foreach($files as $file){
+ if(substr($file,0,$pathLength)==$path and $file!=$path){
+ if(strrpos(substr($file,0,-1),'/')<=$pathLength){
+ $folderContent[]=substr($file,$pathLength);
+ }
+ }
+ }
+ return $folderContent;
+ }
+ /**
+ *get all files in the archive
+ * @return array
+ */
+ function getFiles(){
+ $headers=$this->tar->listContent();
+ $files=array();
+ foreach($headers as $header){
+ $files[]=$header['filename'];
+ }
+ return $files;
+ }
+ /**
+ * get the content of a file
+ * @param string path
+ * @return string
+ */
+ function getFile($path){
+ return $this->tar->extractInString($path);
+ }
+ /**
+ * extract a single file from the archive
+ * @param string path
+ * @param string dest
+ * @return bool
+ */
+ function extractFile($path,$dest){
+ $tmp=OCP\Files::tmpFolder();
+ if(!$this->fileExists($path)){
+ return false;
+ }
+ $success=$this->tar->extractList(array($path),$tmp);
+ if($success){
+ rename($tmp.$path,$dest);
+ }
+ OCP\Files::rmdirr($tmp);
+ return $success;
+ }
+ /**
+ * extract the archive
+ * @param string path
+ * @param string dest
+ * @return bool
+ */
+ function extract($dest){
+ return $this->tar->extract($dest);
+ }
+ /**
+ * check if a file or folder exists in the archive
+ * @param string path
+ * @return bool
+ */
+ function fileExists($path){
+ return $this->getHeader($path)!==null;
+ }
+
+ /**
+ * remove a file or folder from the archive
+ * @param string path
+ * @return bool
+ */
+ function remove($path){
+ if(!$this->fileExists($path)){
+ return false;
+ }
+ //no proper way to delete, extract entire archive, delete file and remake archive
+ $tmp=OCP\Files::tmpFolder();
+ $this->tar->extract($tmp);
+ OCP\Files::rmdirr($tmp.$path);
+ $this->tar=null;
+ unlink($this->path);
+ $this->reopen();
+ $this->tar->createModify(array($tmp),'',$tmp);
+ return true;
+ }
+ /**
+ * get a file handler
+ * @param string path
+ * @param string mode
+ * @return resource
+ */
+ function getStream($path,$mode){
+ if(strrpos($path,'.')!==false){
+ $ext=substr($path,strrpos($path,'.'));
+ }else{
+ $ext='';
+ }
+ $tmpFile=OCP\Files::tmpFile($ext);
+ if($this->fileExists($path)){
+ $this->extractFile($path,$tmpFile);
+ }elseif($mode=='r' or $mode=='rb'){
+ return false;
+ }
+ if($mode=='r' or $mode=='rb'){
+ return fopen($tmpFile,$mode);
+ }else{
+ OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
+ self::$tempFiles[$tmpFile]=$path;
+ return fopen('close://'.$tmpFile,$mode);
+ }
+ }
+
+ private static $tempFiles=array();
+ /**
+ * write back temporary files
+ */
+ function writeBack($tmpFile){
+ if(isset(self::$tempFiles[$tmpFile])){
+ $this->addFile(self::$tempFiles[$tmpFile],$tmpFile);
+ unlink($tmpFile);
+ }
+ }
+
+ /**
+ * reopen the archive to ensure everything is written
+ */
+ private function reopen(){
+ if($this->tar){
+ $this->tar->_close();
+ $this->tar=null;
+ }
+ $types=array(null,'gz','bz');
+ $this->tar=new Archive_Tar($this->path,$types[self::getTarType($this->path)]);
+ }
+}
diff --git a/lib/archive/zip.php b/lib/archive/zip.php
new file mode 100755
index 00000000000..22ab48937eb
--- /dev/null
+++ b/lib/archive/zip.php
@@ -0,0 +1,200 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class OC_Archive_ZIP extends OC_Archive{
+ /**
+ * @var ZipArchive zip
+ */
+ private $zip=null;
+ private $success=false;
+ private $path;
+
+ function __construct($source){
+ $this->path=$source;
+ $this->zip=new ZipArchive();
+ if($this->zip->open($source,ZipArchive::CREATE)){
+ }else{
+ OCP\Util::writeLog('files_archive','Error while opening archive '.$source,OCP\Util::WARN);
+ }
+ }
+ /**
+ * add an empty folder to the archive
+ * @param string path
+ * @return bool
+ */
+ function addFolder($path){
+ return $this->zip->addEmptyDir($path);
+ }
+ /**
+ * add a file to the archive
+ * @param string path
+ * @param string source either a local file or string data
+ * @return bool
+ */
+ function addFile($path,$source=''){
+ if(file_exists($source)){
+ $result=$this->zip->addFile($source,$path);
+ }else{
+ $result=$this->zip->addFromString($path,$source);
+ }
+ if($result){
+ $this->zip->close();//close and reopen to save the zip
+ $this->zip->open($this->path);
+ }
+ return $result;
+ }
+ /**
+ * rename a file or folder in the archive
+ * @param string source
+ * @param string dest
+ * @return bool
+ */
+ function rename($source,$dest){
+ $source=$this->stripPath($source);
+ $dest=$this->stripPath($dest);
+ $this->zip->renameName($source,$dest);
+ }
+ /**
+ * get the uncompressed size of a file in the archive
+ * @param string path
+ * @return int
+ */
+ function filesize($path){
+ $stat=$this->zip->statName($path);
+ return $stat['size'];
+ }
+ /**
+ * get the last modified time of a file in the archive
+ * @param string path
+ * @return int
+ */
+ function mtime($path){
+ $stat=$this->zip->statName($path);
+ return $stat['mtime'];
+ }
+ /**
+ * get the files in a folder
+ * @param path
+ * @return array
+ */
+ function getFolder($path){
+ $files=$this->getFiles();
+ $folderContent=array();
+ $pathLength=strlen($path);
+ foreach($files as $file){
+ if(substr($file,0,$pathLength)==$path and $file!=$path){
+ if(strrpos(substr($file,0,-1),'/')<=$pathLength){
+ $folderContent[]=substr($file,$pathLength);
+ }
+ }
+ }
+ return $folderContent;
+ }
+ /**
+ *get all files in the archive
+ * @return array
+ */
+ function getFiles(){
+ $fileCount=$this->zip->numFiles;
+ $files=array();
+ for($i=0;$i<$fileCount;$i++){
+ $files[]=$this->zip->getNameIndex($i);
+ }
+ return $files;
+ }
+ /**
+ * get the content of a file
+ * @param string path
+ * @return string
+ */
+ function getFile($path){
+ return $this->zip->getFromName($path);
+ }
+ /**
+ * extract a single file from the archive
+ * @param string path
+ * @param string dest
+ * @return bool
+ */
+ function extractFile($path,$dest){
+ $fp = $this->zip->getStream($path);
+ file_put_contents($dest,$fp);
+ }
+ /**
+ * extract the archive
+ * @param string path
+ * @param string dest
+ * @return bool
+ */
+ function extract($dest){
+ return $this->zip->extractTo($dest);
+ }
+ /**
+ * check if a file or folder exists in the archive
+ * @param string path
+ * @return bool
+ */
+ function fileExists($path){
+ return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false);
+ }
+ /**
+ * remove a file or folder from the archive
+ * @param string path
+ * @return bool
+ */
+ function remove($path){
+ if($this->fileExists($path.'/')){
+ return $this->zip->deleteName($path.'/');
+ }else{
+ return $this->zip->deleteName($path);
+ }
+ }
+ /**
+ * get a file handler
+ * @param string path
+ * @param string mode
+ * @return resource
+ */
+ function getStream($path,$mode){
+ if($mode=='r' or $mode=='rb'){
+ return $this->zip->getStream($path);
+ }else{//since we cant directly get a writable stream, make a temp copy of the file and put it back in the archive when the stream is closed
+ if(strrpos($path,'.')!==false){
+ $ext=substr($path,strrpos($path,'.'));
+ }else{
+ $ext='';
+ }
+ $tmpFile=OCP\Files::tmpFile($ext);
+ OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
+ if($this->fileExists($path)){
+ $this->extractFile($path,$tmpFile);
+ }
+ self::$tempFiles[$tmpFile]=$path;
+ return fopen('close://'.$tmpFile,$mode);
+ }
+ }
+
+ private static $tempFiles=array();
+ /**
+ * write back temporary files
+ */
+ function writeBack($tmpFile){
+ if(isset(self::$tempFiles[$tmpFile])){
+ $this->addFile(self::$tempFiles[$tmpFile],$tmpFile);
+ unlink($tmpFile);
+ }
+ }
+
+ private function stripPath($path){
+ if(substr($path,0,1)=='/'){
+ return substr($path,1);
+ }else{
+ return $path;
+ }
+ }
+}
diff --git a/lib/base.php b/lib/base.php
index f3dacdc0f76..40df2b0c56c 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -62,15 +62,22 @@ class OC{
* the root path of the 3rdparty folder for http requests (e.g. owncloud/3rdparty)
*/
public static $THIRDPARTYWEBROOT = '';
- /**
- * The installation path of the apps folder on the server (e.g. /srv/http/owncloud)
- */
- public static $APPSROOT = '';
- /**
- * the root path of the apps folder for http requests (e.g. owncloud)
- */
- public static $APPSWEBROOT = '';
-
+ /**
+ * The installation path of the apps folder on the server (e.g. /srv/http/owncloud)
+ */
+ public static $APPSROOT = '';
+ /**
+ * the root path of the apps folder for http requests (e.g. owncloud)
+ */
+ public static $APPSWEBROOT = '';
+ /*
+ * requested app
+ */
+ public static $REQUESTEDAPP = '';
+ /*
+ * requested file of app
+ */
+ public static $REQUESTEDFILE = '';
/**
* SPL autoload
*/
@@ -81,6 +88,9 @@ class OC{
elseif(strpos($className,'OC_')===0){
require_once strtolower(str_replace('_','/',substr($className,3)) . '.php');
}
+ elseif(strpos($className,'OCP\\')===0){
+ require_once 'public/'.strtolower(str_replace('\\','/',substr($className,3)) . '.php');
+ }
elseif(strpos($className,'Sabre_')===0) {
require_once str_replace('_','/',$className) . '.php';
}
@@ -161,12 +171,15 @@ class OC{
}
// search the apps folder
- if(file_exists(OC::$SERVERROOT.'/apps')){
+ if(OC_Config::getValue('appsroot', '')<>''){
+ OC::$APPSROOT=OC_Config::getValue('appsroot', '');
+ OC::$APPSWEBROOT=OC_Config::getValue('appsurl', '');
+ }elseif(file_exists(OC::$SERVERROOT.'/apps')){
OC::$APPSROOT=OC::$SERVERROOT;
OC::$APPSWEBROOT=OC::$WEBROOT;
}elseif(file_exists(OC::$SERVERROOT.'/../apps')){
- OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/');
+ OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
}else{
echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file.");
exit;
@@ -261,6 +274,34 @@ class OC{
ini_set('session.cookie_httponly','1;');
session_start();
}
+
+ public static function loadapp(){
+ if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php')){
+ require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php');
+ }else{
+ trigger_error('The requested App was not found.', E_USER_ERROR);//load default app instead?
+ }
+ }
+
+ public static function loadfile(){
+ if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE)){
+ if(substr(OC::$REQUESTEDFILE, -3) == 'css'){
+ $appswebroot = (string) OC::$APPSWEBROOT;
+ $webroot = (string) OC::$WEBROOT;
+ $cssfile = file_get_contents(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE);
+ $cssfile = str_replace('%appswebroot%', $appswebroot, $cssfile);
+ $cssfile = str_replace('%webroot%', $webroot, $cssfile);
+ header('Content-Type: text/css');
+ echo $cssfile;
+ exit;
+ }elseif(substr(OC::$REQUESTEDFILE, -3) == 'php'){
+ require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE);
+ }
+ }else{
+ header('HTTP/1.0 404 Not Found');
+ exit;
+ }
+ }
public static function init(){
// register autoloader
@@ -322,6 +363,16 @@ class OC{
self::checkInstalled();
self::checkSSL();
+ // CSRF protection
+ if(isset($_SERVER['HTTP_REFERER'])) $referer=$_SERVER['HTTP_REFERER']; else $referer='';
+ if(isset($_SERVER['HTTPS']) and $_SERVER['HTTPS']<>'') $protocol='https://'; else $protocol='http://';
+ $server=$protocol.$_SERVER['SERVER_NAME'];
+ if(($_SERVER['REQUEST_METHOD']=='POST') and (substr($referer,0,strlen($server))<>$server)) {
+ $url = $protocol.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php';
+ header("Location: $url");
+ exit();
+ }
+
self::initSession();
self::initTemplateEngine();
self::checkUpgrade();
@@ -371,6 +422,35 @@ class OC{
//make sure temporary files are cleaned up
register_shutdown_function(array('OC_Helper','cleanTmp'));
+
+ //parse the given parameters
+ self::$REQUESTEDAPP = (isset($_GET['app'])?strip_tags($_GET['app']):'files');
+ if(substr_count(self::$REQUESTEDAPP, '?') != 0){
+ $app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?'));
+ $param = substr(self::$REQUESTEDAPP, strpos(self::$REQUESTEDAPP, '?') + 1);
+ parse_str($param, $get);
+ $_GET = array_merge($_GET, $get);
+ self::$REQUESTEDAPP = $app;
+ $_GET['app'] = $app;
+ }
+ self::$REQUESTEDFILE = (isset($_GET['getfile'])?$_GET['getfile']:null);
+ if(substr_count(self::$REQUESTEDFILE, '?') != 0){
+ $file = substr(self::$REQUESTEDFILE, 0, strpos(self::$REQUESTEDFILE, '?'));
+ $param = substr(self::$REQUESTEDFILE, strpos(self::$REQUESTEDFILE, '?') + 1);
+ parse_str($param, $get);
+ $_GET = array_merge($_GET, $get);
+ self::$REQUESTEDFILE = $file;
+ $_GET['getfile'] = $file;
+ }
+ if(!is_null(self::$REQUESTEDFILE)){
+ $subdir = OC::$APPSROOT . '/' . self::$REQUESTEDAPP . '/' . self::$REQUESTEDFILE;
+ $parent = OC::$APPSROOT . '/' . self::$REQUESTEDAPP;
+ if(!OC_Helper::issubdirectory($subdir, $parent)){
+ self::$REQUESTEDFILE = null;
+ header('HTTP/1.0 404 Not Found');
+ exit;
+ }
+ }
}
}
diff --git a/lib/connect.php b/lib/connect.php
deleted file mode 100644
index 22e48750a62..00000000000
--- a/lib/connect.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-/**
-* 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 <http://www.gnu.org/licenses/>.
-*
-*/
-
-/**
- * Class for connecting multiply ownCloud installations
- *
- */
-class OC_Connect{
- static private $clouds=array();
-
- static function connect($path,$user,$password){
- $cloud=new OC_REMOTE_CLOUD($path,$user,$password);
- if($cloud->connected){
- self::$clouds[$path]=$cloud;
- return $cloud;
- }else{
- return false;
- }
- }
-}
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index cc37bf22d5d..912c8cd439a 100644
--- a/lib/connector/sabre/directory.php
+++ b/lib/connector/sabre/directory.php
@@ -50,7 +50,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
$path = $this->path . '/' . $name;
- if (!OC_Filesystem::file_exists($path)) throw new Sabre_DAV_Exception_FileNotFound('File with name ' . $path . ' could not be located');
+ if (!OC_Filesystem::file_exists($path)) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located');
if (OC_Filesystem::is_dir($path)) {
diff --git a/lib/connector/sabre/principal.php b/lib/connector/sabre/principal.php
index 28a36438e87..d1456f7c642 100644
--- a/lib/connector/sabre/principal.php
+++ b/lib/connector/sabre/principal.php
@@ -46,7 +46,7 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
* @return array
*/
public function getPrincipalByPath($path) {
- list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($path);
+ list($prefix,$name) = explode('/', $path);
if ($prefix == 'principals' && OC_User::userExists($name)) {
return array(
@@ -115,4 +115,6 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
public function setGroupMemberSet($principal, array $members) {
throw new Sabre_DAV_Exception('Setting members of the group is not supported yet');
}
+ function updatePrincipal($path, $mutations){return 0;}
+ function searchPrincipals($prefixPath, array $searchProperties){return 0;}
}
diff --git a/lib/db.php b/lib/db.php
index 9364b9e0015..2f74cc6dd95 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -36,8 +36,26 @@ class OC_DB {
static private $affected=0;
static private $result=false;
static private $inTransaction=false;
+ static private $prefix=null;
+ static private $type=null;
/**
+ * check which backend we should use
+ * @return BACKEND_MDB2 or BACKEND_PDO
+ */
+ private static function getDBBackend(){
+ $backend=self::BACKEND_MDB2;
+ if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2)
+ $type = OC_Config::getValue( "dbtype", "sqlite" );
+ if($type=='sqlite3') $type='sqlite';
+ $drivers=PDO::getAvailableDrivers();
+ if(array_search($type,$drivers)!==false){
+ $backend=self::BACKEND_PDO;
+ }
+ }
+ }
+
+ /**
* @brief connects to the database
* @returns true if connection can be established or nothing (die())
*
@@ -48,15 +66,7 @@ class OC_DB {
return;
}
if(is_null($backend)){
- $backend=self::BACKEND_MDB2;
- if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2)
- $type = OC_Config::getValue( "dbtype", "sqlite" );
- if($type=='sqlite3') $type='sqlite';
- $drivers=PDO::getAvailableDrivers();
- if(array_search($type,$drivers)!==false){
- $backend=self::BACKEND_PDO;
- }
- }
+ $backend=self::getDBBackend();
}
if($backend==self::BACKEND_PDO){
self::connectPDO();
@@ -423,8 +433,14 @@ class OC_DB {
private static function processQuery( $query ){
self::connect();
// We need Database type and table prefix
- $type = OC_Config::getValue( "dbtype", "sqlite" );
- $prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
+ if(is_null(self::$type)){
+ self::$type=OC_Config::getValue( "dbtype", "sqlite" );
+ }
+ $type = self::$type;
+ if(is_null(self::$prefix)){
+ self::$prefix=OC_Config::getValue( "dbtableprefix", "oc_" );
+ }
+ $prefix = self::$prefix;
// differences in escaping of table names ('`' for mysql) and getting the current timestamp
if( $type == 'sqlite' || $type == 'sqlite3' ){
@@ -485,7 +501,7 @@ class OC_DB {
}
/**
- * @breif replaces the owncloud tables with a new set
+ * @brief replaces the owncloud tables with a new set
* @param $file string path to the MDB2 xml db export file
*/
public static function replaceDB( $file ){
diff --git a/lib/filecache.php b/lib/filecache.php
index cdd91dcbfa4..091a7939e1a 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -64,7 +64,7 @@ class OC_FileCache{
if(is_array($result)){
return $result;
}else{
- OC_Log::write('get(): file not found in cache ('.$path.')','core',OC_Log::DEBUG);
+ OC_Log::write('files','get(): file not found in cache ('.$path.')',OC_Log::DEBUG);
return false;
}
}
@@ -110,8 +110,13 @@ class OC_FileCache{
$data['versioned']=false;
}
$mimePart=dirname($data['mimetype']);
+ $data['size']=(int)$data['size'];
+ $data['ctime']=(int)$data['mtime'];
+ $data['writable']=(int)$data['writable'];
+ $data['encrypted']=(int)$data['encrypted'];
+ $data['versioned']=(int)$data['versioned'];
$user=OC_User::getUser();
- $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, path_hash, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)');
+ $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, path_hash, size, mtime, ctime, mimetype, mimepart,`user`,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)');
$result=$query->execute(array($parent,basename($path),$path,md5($path),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned']));
if(OC_DB::isError($result)){
OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR);
@@ -208,9 +213,9 @@ class OC_FileCache{
}
$rootLen=strlen($root);
if(!$returnData){
- $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE name LIKE ? AND user=?');
+ $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE name LIKE ? AND `user`=?');
}else{
- $query=OC_DB::prepare('SELECT * FROM *PREFIX*fscache WHERE name LIKE ? AND user=?');
+ $query=OC_DB::prepare('SELECT * FROM *PREFIX*fscache WHERE name LIKE ? AND `user`=?');
}
$result=$query->execute(array("%$search%",OC_User::getUser()));
$names=array();
@@ -257,7 +262,7 @@ class OC_FileCache{
if(is_array($result)){
return $result;
}else{
- OC_Log::write('getFolderContent(): file not found in cache ('.$path.')','core',OC_Log::DEBUG);
+ OC_Log::write('files','getFolderContent(): file not found in cache ('.$path.')',OC_Log::DEBUG);
return false;
}
}
@@ -281,6 +286,7 @@ class OC_FileCache{
/**
* get the file id as used in the cache
+ * unlike the public getId, full paths are used here (/usename/files/foo instead of /foo)
* @param string $path
* @return int
*/
@@ -299,10 +305,48 @@ class OC_FileCache{
if(is_array($result)){
return $result['id'];
}else{
- OC_Log::write('getFileId(): file not found in cache ('.$path.')','core',OC_Log::DEBUG);
+ OC_Log::write('files','getFileId(): file not found in cache ('.$path.')',OC_Log::DEBUG);
return -1;
}
}
+
+ /**
+ * get the file id as used in the cache
+ * @param string path
+ * @param string root (optional)
+ * @return int
+ */
+ public static function getId($path,$root=''){
+ if(!$root){
+ $root=OC_Filesystem::getRoot();
+ }
+ if($root=='/'){
+ $root='';
+ }
+ $path=$root.$path;
+ return self::getFileId($path);
+ }
+
+ /**
+ * get the file path from the id, relative to the home folder of the user
+ * @param int id
+ * @param string user (optional)
+ * @return string
+ */
+ public static function getPath($id,$user=''){
+ if(!$user){
+ $user=OC_User::getUser();
+ }
+ $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id=? AND `user`=?');
+ $result=$query->execute(array($id,$user));
+ $row=$result->fetchRow();
+ $path=$row['path'];
+ $root='/'.$user.'/files';
+ if(substr($path,0,strlen($root))!=$root){
+ return false;
+ }
+ return substr($path,strlen($root));
+ }
/**
* get the file id of the parent folder, taking into account '/' has no parent
@@ -375,8 +419,12 @@ class OC_FileCache{
}
return $result;
}else{
- OC_Log::write('get(): file not found in cache ('.$path.')','core',OC_Log::DEBUG);
- return false;
+ OC_Log::write('files','getChached(): file not found in cache ('.$path.')',OC_Log::DEBUG);
+ if(isset(self::$savedData[$path])){
+ return self::$savedData[$path];
+ }else{
+ return array();
+ }
}
}
@@ -441,7 +489,7 @@ class OC_FileCache{
}else{
return;
}
- $size=OC_Filesystem::filesize($oldPath);
+ $size=OC_Filesystem::filesize($newPath);
self::increaseSize(dirname($fullOldPath),-$oldSize);
self::increaseSize(dirname($fullNewPath),$oldSize);
self::move($oldPath,$newPath);
@@ -498,6 +546,7 @@ class OC_FileCache{
}
}
}
+ self::cleanFolder($path,$root);
self::increaseSize($view->getRoot().$path,$totalSize);
}
@@ -514,6 +563,7 @@ class OC_FileCache{
$view=new OC_FilesystemView(($root=='/')?'':$root);
}
if(!$view->is_readable($path)) return; //cant read, nothing we can do
+ clearstatcache();
$stat=$view->stat($path);
$mimetype=$view->getMimeType($path);
$writable=$view->is_writable($path);
@@ -549,10 +599,10 @@ class OC_FileCache{
$root .= '%';
$user=OC_User::getUser();
if(!$part2){
- $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimepart=? AND user=? AND path LIKE ?');
+ $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimepart=? AND `user`=? AND path LIKE ?');
$result=$query->execute(array($part1,$user, $root));
}else{
- $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimetype=? AND user=? AND path LIKE ? ');
+ $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimetype=? AND `user`=? AND path LIKE ? ');
$result=$query->execute(array($part1.'/'.$part2,$user, $root));
}
$names=array();
@@ -620,7 +670,26 @@ class OC_FileCache{
}
}
}
+
+ self::cleanFolder($path,$root);
+
+ //update the folder last, so we can calculate the size correctly
+ if(!$root){//filesystem hooks are only valid for the default root
+ OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path));
+ }else{
+ self::fileSystemWatcherWrite(array('path'=>$path),$root);
+ }
+ }
+ /**
+ * delete non existing files from the cache
+ */
+ private static function cleanFolder($path,$root=''){
+ if(!$root){
+ $view=OC_Filesystem::getView();
+ }else{
+ $view=new OC_FilesystemView(($root=='/')?'':$root);
+ }
//check for removed files, not using getFolderContent to prevent loops
$parent=self::getFileId($view->getRoot().$path);
$query=OC_DB::prepare('SELECT name FROM *PREFIX*fscache WHERE parent=?');
@@ -635,12 +704,6 @@ class OC_FileCache{
}
}
}
- //update the folder last, so we can calculate the size correctly
- if(!$root){//filesystem hooks are only valid for the default root
- OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path));
- }else{
- self::fileSystemWatcherWrite(array('path'=>$path),$root);
- }
}
/**
diff --git a/lib/files.php b/lib/files.php
index 01558a68588..107605fc34e 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -104,22 +104,29 @@ class OC_Files {
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($filename));
}else{
- header('Content-Type: ' . OC_Filesystem::getMimeType($filename));
- header('Content-Length: ' . OC_Filesystem::filesize($filename));
+ $fileData=OC_FileCache::get($filename);
+ header('Content-Type: ' . $fileData['mimetype']);
+ header('Content-Length: ' . $fileData['size']);
}
}elseif($zip or !OC_Filesystem::file_exists($filename)){
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template( '', '404', 'guest' );
$tmpl->assign('file',$filename);
$tmpl->printPage();
-// die('404 Not Found');
}else{
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
}
@ob_end_clean();
if($zip){
- readfile($filename);
+ $handle=fopen($filename,'r');
+ if ($handle) {
+ $chunkSize = 8*1024;// 1 MB chunks
+ while (!feof($handle)) {
+ echo fread($handle, $chunkSize);
+ flush();
+ }
+ }
unlink($filename);
}else{
OC_Filesystem::readfile($filename);
@@ -225,7 +232,7 @@ class OC_Files {
*/
static function validateZipDownload($dir, $files) {
if(!OC_Config::getValue('allowZipDownload', true)) {
- $l = new OC_L10N('files');
+ $l = OC_L10N::get('files');
header("HTTP/1.0 409 Conflict");
$tmpl = new OC_Template( '', 'error', 'user' );
$errors = array(
@@ -250,7 +257,7 @@ class OC_Files {
$totalsize += OC_Filesystem::filesize($dir.'/'.$files);
}
if($totalsize > $zipLimit) {
- $l = new OC_L10N('files');
+ $l = OC_L10N::get('files');
header("HTTP/1.0 409 Conflict");
$tmpl = new OC_Template( '', 'error', 'user' );
$errors = array(
diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php
index f632474df01..f0bfc064cb5 100644
--- a/lib/filestorage/common.php
+++ b/lib/filestorage/common.php
@@ -100,11 +100,11 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
}
$head=fread($source,8192);//8kb should suffice to determine a mimetype
if($pos=strrpos($path,'.')){
- $extention=substr($path,$pos);
+ $extension=substr($path,$pos);
}else{
- $extention='';
+ $extension='';
}
- $tmpFile=OC_Helper::tmpFile($extention);
+ $tmpFile=OC_Helper::tmpFile($extension);
file_put_contents($tmpFile,$head);
$mime=OC_Helper::getMimeType($tmpFile);
unlink($tmpFile);
@@ -129,11 +129,11 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
return false;
}
if($pos=strrpos($path,'.')){
- $extention=substr($path,$pos);
+ $extension=substr($path,$pos);
}else{
- $extention='';
+ $extension='';
}
- $tmpFile=OC_Helper::tmpFile($extention);
+ $tmpFile=OC_Helper::tmpFile($extension);
$target=fopen($tmpFile,'w');
$count=OC_Helper::streamCopy($source,$target);
return $tmpFile;
diff --git a/lib/filesystem.php b/lib/filesystem.php
index dc678fba74c..cac7e8648ef 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -196,10 +196,58 @@ class OC_Filesystem{
return false;
}
self::$defaultInstance=new OC_FilesystemView($root);
+
+ //load custom mount config
+ if(is_file(OC::$SERVERROOT.'/config/mount.php')){
+ $mountConfig=include(OC::$SERVERROOT.'/config/mount.php');
+ if(isset($mountConfig['global'])){
+ foreach($mountConfig['global'] as $mountPoint=>$options){
+ self::mount($options['class'],$options['options'],$mountPoint);
+ }
+ }
+
+ if(isset($mountConfig['group'])){
+ foreach($mountConfig['group'] as $group=>$mounts){
+ if(OC_Group::inGroup(OC_User::getUser(),$group)){
+ foreach($mounts as $mountPoint=>$options){
+ $mountPoint=self::setUserVars($mountPoint);
+ foreach($options as &$option){
+ $option=self::setUserVars($option);
+ }
+ self::mount($options['class'],$options['options'],$mountPoint);
+ }
+ }
+ }
+ }
+
+ if(isset($mountConfig['user'])){
+ foreach($mountConfig['user'] as $user=>$mounts){
+ if($user==='all' or strtolower($user)===strtolower(OC_User::getUser())){
+ foreach($mounts as $mountPoint=>$options){
+ $mountPoint=self::setUserVars($mountPoint);
+ foreach($options as &$option){
+ $option=self::setUserVars($option);
+ }
+ self::mount($options['class'],$options['options'],$mountPoint);
+ }
+ }
+ }
+ }
+ }
+
self::$loaded=true;
}
/**
+ * fill in the correct values for $user, and $password placeholders
+ * @param string intput
+ * @return string
+ */
+ private static function setUserVars($input){
+ return str_replace('$user',OC_User::getUser(),$input);
+ }
+
+ /**
* get the default filesystem view
* @return OC_FilesystemView
*/
@@ -227,6 +275,7 @@ class OC_Filesystem{
if(class_exists($class)){
return new $class($arguments);
}else{
+ OC_Log::write('core','storage backend '.$class.' not found',OC_Log::ERROR);
return false;
}
}
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index 95873bd87cf..ac5a0a3bff5 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -136,15 +136,16 @@ class OC_FilesystemView {
return $this->basicOperation('filesize',$path);
}
public function readfile($path){
+ @ob_end_clean();
$handle=$this->fopen($path,'r');
if ($handle) {
- $chunkSize = 1024*1024;// 1 MB chunks
+ $chunkSize = 8*1024;// 1 MB chunks
while (!feof($handle)) {
echo fread($handle, $chunkSize);
- @ob_flush();
flush();
}
- return $this->filesize($path);
+ $size=$this->filesize($path);
+ return $size;
}
return false;
}
@@ -174,11 +175,23 @@ class OC_FilesystemView {
}
public function file_put_contents($path,$data){
if(is_resource($data)){//not having to deal with streams in file_put_contents makes life easier
+ $exists=$this->file_exists($path);
+ $run=true;
+ if(!$exists){
+ OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
+ }
+ OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
+ if(!$run){
+ return false;
+ }
$target=$this->fopen($path,'w');
if($target){
$count=OC_Helper::streamCopy($data,$target);
fclose($target);
fclose($data);
+ if(!$exists){
+ OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array( OC_Filesystem::signal_param_path => $path));
+ }
OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path));
return $count>0;
}else{
diff --git a/lib/group.php b/lib/group.php
index 4ae9302f78b..9b2959d1f73 100644
--- a/lib/group.php
+++ b/lib/group.php
@@ -255,7 +255,12 @@ class OC_Group {
* @return bool
*/
public static function groupExists($gid){
- return in_array( $gid, self::getGroups());
+ foreach(self::$_usedBackends as $backend){
+ if ($backend->groupExists($gid)){
+ return true;
+ }
+ }
+ return false;
}
/**
diff --git a/lib/group/backend.php b/lib/group/backend.php
index b3fc06ac9a8..af6c53c8035 100644
--- a/lib/group/backend.php
+++ b/lib/group/backend.php
@@ -82,4 +82,16 @@ abstract class OC_Group_Backend {
public function implementsActions($actions){
return (bool)($this->getSupportedActions() & $actions);
}
+
+ /**
+ * check if a group exists
+ * @param string $gid
+ * @return bool
+ */
+ public function groupExists($gid){
+ if(!$this->implementsActions(OC_GROUP_BACKEND_GET_GROUPS)){
+ return false;
+ }
+ return in_array($gid, $this->getGroups());
+ }
}
diff --git a/lib/helper.php b/lib/helper.php
index 2026286352a..82d1017debd 100755..100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -41,7 +41,15 @@ class OC_Helper {
$app .= '/';
// Check if the app is in the app folder
if( file_exists( OC::$APPSROOT . '/apps/'. $app.$file )){
- $urlLinkTo = OC::$APPSWEBROOT . '/apps/' . $app . $file;
+ if(substr($file, -3) == 'php' || substr($file, -3) == 'css'){
+ if(substr($app, -1, 1) == '/'){
+ $app = substr($app, 0, strlen($app) - 1);
+ }
+ $urlLinkTo = OC::$WEBROOT . '/?app=' . $app;
+ $urlLinkTo .= ($file!='index.php')?'&getfile=' . urlencode($file):'';
+ }else{
+ $urlLinkTo = OC::$APPSWEBROOT . '/apps/' . $app . $file;
+ }
}
else{
$urlLinkTo = OC::$WEBROOT . '/' . $app . $file;
@@ -310,9 +318,9 @@ class OC_Helper {
$mimeType='application/octet-stream';
if ($mimeType=='application/octet-stream') {
self::$mimetypes = include('mimetypes.fixlist.php');
- $extention=strtolower(strrchr(basename($path), "."));
- $extention=substr($extention,1);//remove leading .
- $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';
+ $extension=strtolower(strrchr(basename($path), "."));
+ $extension=substr($extension,1);//remove leading .
+ $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
}
if (@is_dir($path)) {
@@ -346,14 +354,34 @@ class OC_Helper {
if(!self::$mimetypes || self::$mimetypes != include('mimetypes.list.php')){
self::$mimetypes=include('mimetypes.list.php');
}
- $extention=strtolower(strrchr(basename($path), "."));
- $extention=substr($extention,1);//remove leading .
- $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';
+ $extension=strtolower(strrchr(basename($path), "."));
+ $extension=substr($extension,1);//remove leading .
+ $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
}
return $mimeType;
}
/**
+ * get the mimetype form a data string
+ * @param string data
+ * @return string
+ */
+ static function getStringMimeType($data){
+ if(function_exists('finfo_open') and function_exists('finfo_file')){
+ $finfo=finfo_open(FILEINFO_MIME);
+ return finfo_buffer($finfo, $data);
+ }else{
+ $tmpFile=OC_Helper::tmpFile();
+ $fh=fopen($tmpFile,'wb');
+ fwrite($fh,$data,8024);
+ fclose($fh);
+ $mime=self::getMimeType($tmpFile);
+ unset($tmpFile);
+ return $mime;
+ }
+ }
+
+ /**
* @brief Checks $_REQUEST contains a var for the $s key. If so, returns the html-escaped value of this var; otherwise returns the default value provided by $d.
* @param $s name of the var to escape, if set.
* @param $d default value.
@@ -492,4 +520,70 @@ class OC_Helper {
}
}
}
+
+ /**
+ * Adds a suffix to the name in case the file exists
+ *
+ * @param $path
+ * @param $filename
+ * @return string
+ */
+ public static function buildNotExistingFileName($path, $filename){
+ if($path==='/'){
+ $path='';
+ }
+ if ($pos = strrpos($filename, '.')) {
+ $name = substr($filename, 0, $pos);
+ $ext = substr($filename, $pos);
+ } else {
+ $name = $filename;
+ }
+
+ $newpath = $path . '/' . $filename;
+ $newname = $filename;
+ $counter = 2;
+ while (OC_Filesystem::file_exists($newpath)) {
+ $newname = $name . ' (' . $counter . ')' . $ext;
+ $newpath = $path . '/' . $newname;
+ $counter++;
+ }
+
+ return $newpath;
+ }
+
+ /*
+ * checks if $sub is a subdirectory of $parent
+ *
+ * @param $sub
+ * @param $parent
+ * @return bool
+ */
+ public static function issubdirectory($sub, $parent){
+ if($sub == null || $sub == '' || $parent == null || $parent == ''){
+ return false;
+ }
+ $realpath_sub = realpath($sub);
+ $realpath_parent = realpath($parent);
+ if(($realpath_sub == false && substr_count($realpath_sub, './') != 0) || ($realpath_parent == false && substr_count($realpath_parent, './') != 0)){ //it checks for both ./ and ../
+ return false;
+ }
+ if($realpath_sub && $realpath_sub != '' && $realpath_parent && $realpath_parent != ''){
+ if(substr($realpath_sub, 0, strlen($realpath_parent)) == $realpath_parent){
+ return true;
+ }
+ }else{
+ if(substr($sub, 0, strlen($parent)) == $parent){
+ return true;
+ }
+ }
+ /*
+ echo 'SUB: ' . $sub . "\n";
+ echo 'PAR: ' . $parent . "\n";
+ echo 'REALSUB: ' . $realpath_sub . "\n";
+ echo 'REALPAR: ' . $realpath_parent . "\n";
+ echo substr($realpath_sub, 0, strlen($realpath_parent));
+ exit;
+ */
+ return false;
+ }
}
diff --git a/lib/installer.php b/lib/installer.php
index 38e17130e3c..b75c009c8f0 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -47,6 +47,7 @@ class OC_Installer{
* This function works as follows
* -# fetching the file
* -# unzipping it
+ * -# check the code
* -# installing the database at appinfo/database.xml
* -# including appinfo/install.php
* -# setting the installed version
@@ -91,6 +92,7 @@ class OC_Installer{
//extract the archive in a temporary folder
$extractDir=OC_Helper::tmpFolder();
+ OC_Helper::rmdirr($extractDir);
mkdir($extractDir);
if($archive=OC_Archive::open($path)){
$archive->extract($extractDir);
@@ -102,7 +104,7 @@ class OC_Installer{
}
return false;
}
-
+
//load the info.xml file of the app
if(!is_file($extractDir.'/appinfo/info.xml')){
//try to find it in a subdir
@@ -125,6 +127,12 @@ class OC_Installer{
}
$info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml',true);
$basedir=OC::$APPSROOT.'/apps/'.$info['id'];
+
+ // check the code for not allowed calls
+ if(!OC_Installer::checkCode($info['id'],$extractDir)){
+ OC_Helper::rmdirr($extractDir);
+ return false;
+ }
//check if an app with the same id is already installed
if(self::isInstalled( $info['id'] )){
@@ -151,8 +159,8 @@ class OC_Installer{
}
//copy the app to the correct place
- if(!mkdir($basedir)){
- OC_Log::write('core','Can\'t create app folder ('.$basedir.')',OC_Log::ERROR);
+ if(@!mkdir($basedir)){
+ OC_Log::write('core','Can\'t create app folder. Please fix permissions. ('.$basedir.')',OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);
if($data['source']=='http'){
unlink($path);
@@ -175,7 +183,7 @@ class OC_Installer{
}
//set the installed version
- OC_Appconfig::setValue($info['id'],'installed_version',$info['version']);
+ OC_Appconfig::setValue($info['id'],'installed_version',OC_App::getAppVersion($info['id']));
OC_Appconfig::setValue($info['id'],'enabled','no');
return $info['id'];
}
@@ -255,11 +263,8 @@ class OC_Installer{
/**
* @brief Installs shipped apps
- * @param $enabled
*
- * This function installs all apps found in the 'apps' directory;
- * If $enabled is true, apps are installed as enabled.
- * If $enabled is false, apps are installed as disabled.
+ * This function installs all apps found in the 'apps' directory that should be enabled by default;
*/
public static function installShippedApps(){
$dir = opendir( OC::$APPSROOT."/apps" );
@@ -267,12 +272,11 @@ class OC_Installer{
if( substr( $filename, 0, 1 ) != '.' and is_dir(OC::$APPSROOT."/apps/$filename") ){
if( file_exists( OC::$APPSROOT."/apps/$filename/appinfo/app.php" )){
if(!OC_Installer::isInstalled($filename)){
- $info = OC_Installer::installShippedApp($filename);
+ $info=OC_App::getAppInfo($filename);
$enabled = isset($info['default_enable']);
if( $enabled ){
+ OC_Installer::installShippedApp($filename);
OC_Appconfig::setValue($filename,'enabled','yes');
- }else{
- OC_Appconfig::setValue($filename,'enabled','no');
}
}
}
@@ -297,7 +301,52 @@ class OC_Installer{
include(OC::$APPSROOT."/apps/$app/appinfo/install.php");
}
$info=OC_App::getAppInfo($app);
- OC_Appconfig::setValue($app,'installed_version',$info['version']);
+ OC_Appconfig::setValue($app,'installed_version',OC_App::getAppVersion($app));
return $info;
}
+
+
+ /**
+ * check the code of an app with some static code checks
+ * @param string $folder the folder of the app to check
+ * @returns true for app is o.k. and false for app is not o.k.
+ */
+ public static function checkCode($appname,$folder){
+
+ $blacklist=array(
+ 'fopen(',
+ 'eval('
+ // more evil pattern will go here later
+ // will will also check if an app is using private api once the public api is in place
+
+ );
+
+ // is the code checker enabled?
+ if(OC_Config::getValue('appcodechecker', false)){
+
+ // check if grep is installed
+ $grep = exec('which grep');
+ if($grep=='') {
+ OC_Log::write('core','grep not installed. So checking the code of the app "'.$appname.'" was not possible',OC_Log::ERROR);
+ return true;
+ }
+
+ // iterate the bad patterns
+ foreach($blacklist as $bl) {
+ $cmd = 'grep -ri '.escapeshellarg($bl).' '.$folder.'';
+ $result = exec($cmd);
+ // bad pattern found
+ if($result<>'') {
+ OC_Log::write('core','App "'.$appname.'" is using a not allowed call "'.$bl.'". Installation refused.',OC_Log::ERROR);
+ return false;
+ }
+ }
+ return true;
+
+ }else{
+ return true;
+ }
+ }
+
+
}
diff --git a/lib/json.php b/lib/json.php
index cedf79fd7c3..0d208ce12a2 100644
--- a/lib/json.php
+++ b/lib/json.php
@@ -24,7 +24,7 @@ class OC_JSON{
*/
public static function checkAppEnabled($app){
if( !OC_App::isEnabled($app)){
- $l = new OC_L10N('core');
+ $l = OC_L10N::get('core');
self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled') )));
exit();
}
@@ -35,7 +35,7 @@ class OC_JSON{
*/
public static function checkLoggedIn(){
if( !OC_User::isLoggedIn()){
- $l = new OC_L10N('core');
+ $l = OC_L10N::get('core');
self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
exit();
}
@@ -47,7 +47,7 @@ class OC_JSON{
public static function checkAdminUser(){
self::checkLoggedIn();
if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
- $l = new OC_L10N('core');
+ $l = OC_L10N::get('core');
self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
exit();
}
diff --git a/lib/l10n.php b/lib/l10n.php
index 636326f9864..c0ecdbd1b70 100644
--- a/lib/l10n.php
+++ b/lib/l10n.php
@@ -25,6 +25,11 @@
*/
class OC_L10N{
/**
+ * cached instances
+ */
+ protected static $instances=array();
+
+ /**
* cache
*/
protected static $cache = array();
@@ -46,6 +51,21 @@ class OC_L10N{
'date' => 'd.m.Y',
'datetime' => 'd.m.Y H:i:s',
'time' => 'H:i:s');
+
+ /**
+ * get an L10N instance
+ * @return OC_L10N
+ */
+ public static function get($app,$lang=null){
+ if(is_null($lang)){
+ if(!isset(self::$instances[$app])){
+ self::$instances[$app]=new OC_L10N($app);
+ }
+ return self::$instances[$app];
+ }else{
+ return new OC_L10N($app,$lang);
+ }
+ }
/**
* @brief The constructor
@@ -261,17 +281,14 @@ class OC_L10N{
public static function findAvailableLanguages($app=null){
$available=array('en');//english is always available
$dir = self::findI18nDir($app);
- if(file_exists($dir)){
- $dh = opendir($dir);
- while(($file = readdir($dh)) !== false){
- if(substr($file, -4, 4) == '.php' and (strlen($file) == 6 || strlen($file) == 9)){
+ if(is_dir($dir)){
+ $files=scandir($dir);
+ foreach($files as $file){
+ if(substr($file, -4, 4) == '.php'){
$i = substr($file, 0, -4);
- if($i != ''){
- $available[] = $i;
- }
+ $available[] = $i;
}
}
- closedir($dh);
}
return $available;
}
diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php
index 0ed30510134..0b7a231d304 100644
--- a/lib/log/owncloud.php
+++ b/lib/log/owncloud.php
@@ -44,7 +44,7 @@ class OC_Log_Owncloud {
* @param int level
*/
public static function write($app, $message, $level) {
- $minLevel=OC_Config::getValue( "loglevel", 2 );
+ $minLevel=min(OC_Config::getValue( "loglevel", OC_Log::WARN ),OC_Log::ERROR);
if($level>=$minLevel){
$entry=array('app'=>$app, 'message'=>$message, 'level'=>$level,'time'=>time());
$fh=fopen(self::$logFile, 'a');
@@ -61,6 +61,7 @@ class OC_Log_Owncloud {
*/
public static function getEntries($limit=50, $offset=0){
self::init();
+ $minLevel=OC_Config::getValue( "loglevel", OC_Log::WARN );
$entries=array();
if(!file_exists(self::$logFile)) {
return array();
@@ -71,8 +72,13 @@ class OC_Log_Owncloud {
}
$end=max(count($contents)-$offset-1, 0);
$start=max($end-$limit,0);
- for($i=$end;$i>$start;$i--) {
- $entries[]=json_decode($contents[$i]);
+ $i=$end;
+ while($i>$start){
+ $entry=json_decode($contents[$i]);
+ if($entry->level>=$minLevel){
+ $entries[]=$entry;
+ }
+ $i--;
}
return $entries;
}
diff --git a/lib/mail.php b/lib/mail.php
new file mode 100644
index 00000000000..0045f8de6da
--- /dev/null
+++ b/lib/mail.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * Copyright (c) 2012 Frank Karlitschek <frank@owncloud.org>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * OC_Mail
+ *
+ * A class to handle mail sending.
+ */
+
+require_once('class.phpmailer.php');
+
+class OC_Mail {
+
+ /**
+ * send an email
+ *
+ * @param string $toaddress
+ * @param string $toname
+ * @param string $subject
+ * @param string $mailtext
+ * @param string $fromaddress
+ * @param string $fromname
+ * @param bool $html
+ */
+ public static function send($toaddress,$toname,$subject,$mailtext,$fromaddress,$fromname,$html=0,$altbody='',$ccaddress='',$ccname='',$bcc='') {
+
+ $SMTPMODE = OC_Config::getValue( 'mail_smtpmode', 'sendmail' );
+ $SMTPHOST = OC_Config::getValue( 'mail_smtphost', '127.0.0.1' );
+ $SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', 'false' );
+ $SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' );
+ $SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' );
+
+
+ $mailo = new PHPMailer();
+ if($SMTPMODE=='sendmail') {
+ $mailo->IsSendmail();
+ }elseif($SMTPMODE=='smtp'){
+ $mailo->IsSMTP();
+ }elseif($SMTPMODE=='qmail'){
+ $mailo->IsQmail();
+ }else{
+ $mailo->IsMail();
+ }
+
+
+ $mailo->Host = $SMTPHOST;
+ $mailo->SMTPAuth = $SMTPAUTH;
+ $mailo->Username = $SMTPUSERNAME;
+ $mailo->Password = $SMTPPASSWORD;
+
+ $mailo->From =$fromaddress;
+ $mailo->FromName = $fromname;;
+ $a=explode(' ',$toaddress);
+ foreach($a as $ad) {
+ $mailo->AddAddress($ad,$toname);
+ }
+
+ if($ccaddress<>'') $mailo->AddCC($ccaddress,$ccname);
+ if($bcc<>'') $mailo->AddBCC($bcc);
+
+ $mailo->AddReplyTo($fromaddress, $fromname);
+
+ $mailo->WordWrap = 50;
+ if($html==1) $mailo->IsHTML(true); else $mailo->IsHTML(false);
+
+ $mailo->Subject = $subject;
+ if($altbody=='') {
+ $mailo->Body = $mailtext.OC_MAIL::getfooter();
+ $mailo->AltBody = '';
+ }else{
+ $mailo->Body = $mailtext;
+ $mailo->AltBody = $altbody;
+ }
+ $mailo->CharSet = 'UTF-8';
+
+ $mailo->Send();
+ unset($mailo);
+
+ OC_Log::write('Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject,'mail',OC_Log::DEBUG);
+
+ }
+
+
+
+ /**
+ * sending a mail based on a template
+ *
+ * @param texttemplate $texttemplate
+ * @param htmltemplate $htmltemplate
+ * @param data $data
+ * @param To $toaddress
+ * @param ToName $toname
+ * @param Subject $subject
+ * @param From $fromaddress
+ * @param FromName $fromname
+ * @param ccaddress $ccaddress
+ * @param ccname $ccname
+ * @param bcc $bcc
+ */
+ public static function getfooter() {
+
+ $txt="\n--\n";
+ $txt.="ownCloud\n";
+ $txt.="Your Cloud, Your Data, Your Way!\n";
+ return($txt);
+
+ }
+
+
+
+}
diff --git a/lib/migrate.php b/lib/migrate.php
index dff3abe9e93..f46d860e806 100644
--- a/lib/migrate.php
+++ b/lib/migrate.php
@@ -25,8 +25,8 @@
* provides an interface to migrate users and whole ownclouds
*/
class OC_Migrate{
-
-
+
+
// Array of OC_Migration_Provider objects
static private $providers=array();
// User id of the user to import/export
@@ -47,7 +47,7 @@ class OC_Migrate{
static private $zippath=false;
// Holds the OC_Migration_Content object
static private $content=false;
-
+
/**
* register a new migration provider
* @param OC_Migrate_Provider $provider
@@ -55,28 +55,28 @@ class OC_Migrate{
public static function registerProvider($provider){
self::$providers[]=$provider;
}
-
- /**
- * @breif finds and loads the providers
+
+ /**
+ * @brief finds and loads the providers
*/
static private function findProviders(){
// Find the providers
$apps = OC_App::getAllApps();
-
+
foreach($apps as $app){
$path = OC::$SERVERROOT . '/apps/' . $app . '/appinfo/migrate.php';
if( file_exists( $path ) ){
- include( $path );
- }
- }
+ include( $path );
+ }
+ }
}
-
+
/**
- * @breif exports a user, or owncloud instance
+ * @brief exports a user, or owncloud instance
* @param optional $uid string user id of user to export if export type is user, defaults to current
* @param ootional $type string type of export, defualts to user
* @param otional $path string path to zip output folder
- * @return false on error, path to zip on success
+ * @return false on error, path to zip on success
*/
public static function export( $uid=null, $type='user', $path=null ){
$datadir = OC_Config::getValue( 'datadirectory' );
@@ -84,47 +84,48 @@ class OC_Migrate{
$types = array( 'user', 'instance', 'system', 'userfiles' );
if( !in_array( $type, $types ) ){
OC_Log::write( 'migration', 'Invalid export type', OC_Log::ERROR );
- return json_encode( array( array( 'success' => false ) ) );
+ return json_encode( array( array( 'success' => false ) ) );
}
self::$exporttype = $type;
// Userid?
if( self::$exporttype == 'user' ){
// Check user exists
- if( !is_null($uid) ){
- if( !OC_User_Database::userExists( $uid ) ){
+ if( !is_null($uid) ){
+ $db = new OC_User_Database;
+ if( !$db->userExists( $uid ) ){
OC_Log::write('migration', 'User: '.$uid.' is not in the database and so cannot be exported.', OC_Log::ERROR);
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
self::$uid = $uid;
} else {
- self::$uid = OC_User::getUser();
- }
+ self::$uid = OC_User::getUser();
+ }
}
// Calculate zipname
if( self::$exporttype == 'user' ){
- $zipname = 'oc_export_' . self::$uid . '_' . date("y-m-d_H-i-s") . '.zip';
+ $zipname = 'oc_export_' . self::$uid . '_' . date("y-m-d_H-i-s") . '.zip';
} else {
$zipname = 'oc_export_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '.zip';
}
// Calculate path
if( self::$exporttype == 'user' ){
- self::$zippath = $datadir . '/' . self::$uid . '/' . $zipname;
+ self::$zippath = $datadir . '/' . self::$uid . '/' . $zipname;
} else {
if( !is_null( $path ) ){
// Validate custom path
if( !file_exists( $path ) || !is_writeable( $path ) ){
OC_Log::write( 'migration', 'Path supplied is invalid.', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
- self::$zippath = $path . $zipname;
+ self::$zippath = $path . $zipname;
} else {
// Default path
- self::$zippath = get_temp_dir() . '/' . $zipname;
+ self::$zippath = get_temp_dir() . '/' . $zipname;
}
}
// Create the zip object
if( !self::createZip() ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
// Do the export
self::findProviders();
@@ -134,20 +135,20 @@ class OC_Migrate{
// Connect to the db
self::$dbpath = $datadir . '/' . self::$uid . '/migration.db';
if( !self::connectDB() ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
self::$content = new OC_Migration_Content( self::$zip, self::$MDB2 );
// Export the app info
- $exportdata = self::exportAppData();
+ $exportdata = self::exportAppData();
// Add the data dir to the zip
self::$content->addDir( $datadir . '/' . self::$uid, true, '/' );
- break;
+ break;
case 'instance':
self::$content = new OC_Migration_Content( self::$zip );
// Creates a zip that is compatable with the import function
$dbfile = tempnam( "/tmp", "owncloud_export_data_" );
OC_DB::getDbStructure( $dbfile, 'MDB2_SCHEMA_DUMP_ALL');
-
+
// Now add in *dbname* and *dbprefix*
$dbexport = file_get_contents( $dbfile );
$dbnamestring = "<database>\n\n <name>" . OC_Config::getValue( "dbname", "owncloud" );
@@ -158,14 +159,14 @@ class OC_Migrate{
self::$content->addFromString( $dbexport, "dbexport.xml" );
// Add user data
foreach(OC_User::getUsers() as $user){
- self::$content->addDir( $datadir . '/' . $user . '/', true, "/userdata/" );
+ self::$content->addDir( $datadir . '/' . $user . '/', true, "/userdata/" );
}
break;
case 'userfiles':
self::$content = new OC_Migration_Content( self::$zip );
// Creates a zip with all of the users files
foreach(OC_User::getUsers() as $user){
- self::$content->addDir( $datadir . '/' . $user . '/', true, "/" );
+ self::$content->addDir( $datadir . '/' . $user . '/', true, "/" );
}
break;
case 'system':
@@ -178,70 +179,70 @@ class OC_Migrate{
break;
}
if( !$info = self::getExportInfo( $exportdata ) ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
// Add the export info json to the export zip
self::$content->addFromString( $info, 'export_info.json' );
if( !self::$content->finish() ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
- return json_encode( array( 'success' => true, 'data' => self::$zippath ) );
+ return json_encode( array( 'success' => true, 'data' => self::$zippath ) );
}
-
+
/**
- * @breif imports a user, or owncloud instance
+ * @brief imports a user, or owncloud instance
* @param $path string path to zip
* @param optional $type type of import (user or instance)
- * @param optional $uid userid of new user
+ * @param optional $uid userid of new user
*/
public static function import( $path, $type='user', $uid=null ){
OC_Util::checkAdminUser();
$datadir = OC_Config::getValue( 'datadirectory' );
// Extract the zip
if( !$extractpath = self::extractZip( $path ) ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
// Get export_info.json
$scan = scandir( $extractpath );
// Check for export_info.json
if( !in_array( 'export_info.json', $scan ) ){
OC_Log::write( 'migration', 'Invalid import file, export_info.json note found', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
$json = json_decode( file_get_contents( $extractpath . 'export_info.json' ) );
if( $json->exporttype != $type ){
OC_Log::write( 'migration', 'Invalid import file', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
self::$exporttype = $type;
-
+
// Have we got a user if type is user
if( self::$exporttype == 'user' ){
if( !$uid ){
self::$uid = $json->exporteduser;
- } else {
+ } else {
self::$uid = $uid;
}
}
-
+
// Handle export types
switch( self::$exporttype ){
case 'user':
// Check user availability
if( OC_User::userExists( self::$uid ) ){
OC_Log::write( 'migration', 'User already exists', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
$run = true;
OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => self::$uid, "password" => $json->hash ));
if( !$run ){
// Something stopped the user creation
OC_Log::write( 'migration', 'User creation failed', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
// Create the user
if( !self::createUser( self::$uid, $json->hash ) ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
// Emit the post_createUser hook (password is already hashed, will cause problems
OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => self::$uid, "password" => $json->hash ));
@@ -249,19 +250,19 @@ class OC_Migrate{
$path = $datadir . '/' . self::$uid;
if( !mkdir( $path, 0755, true ) ){
OC_Log::write( 'migration', 'Failed to create users data dir: '.$path, OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
// Copy data
if( !self::copy_r( $extractpath . $json->exporteduser, $datadir . '/' . self::$uid ) ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
- // Import user app data
+ // Import user app data
if( !$appsimported = self::importAppData( $extractpath . $json->exporteduser . '/migration.db', $json, self::$uid ) ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
// All done!
if( !self::unlink_r( $extractpath ) ){
- OC_Log::write( 'migration', 'Failed to delete the extracted zip', OC_Log::ERROR );
+ OC_Log::write( 'migration', 'Failed to delete the extracted zip', OC_Log::ERROR );
}
return json_encode( array( 'success' => true, 'data' => $appsimported ) );
break;
@@ -270,59 +271,59 @@ class OC_Migrate{
* EXPERIMENTAL
// Check for new data dir and dbexport before doing anything
// TODO
-
+
// Delete current data folder.
OC_Log::write( 'migration', "Deleting current data dir", OC_Log::INFO );
if( !self::unlink_r( $datadir, false ) ){
OC_Log::write( 'migration', 'Failed to delete the current data dir', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
-
+
// Copy over data
if( !self::copy_r( $extractpath . 'userdata', $datadir ) ){
OC_Log::write( 'migration', 'Failed to copy over data directory', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
-
+
// Import the db
if( !OC_DB::replaceDB( $extractpath . 'dbexport.xml' ) ){
- return json_encode( array( 'success' => false ) );
+ return json_encode( array( 'success' => false ) );
}
// Done
- return json_encode( 'success' => true );
+ return json_encode( 'success' => true );
*/
- break;
+ break;
}
-
+
}
-
+
/**
- * @breif recursively deletes a directory
+ * @brief recursively deletes a directory
* @param $dir string path of dir to delete
* $param optional $deleteRootToo bool delete the root directory
* @return bool
*/
- private static function unlink_r( $dir, $deleteRootToo=true ){
- if( !$dh = @opendir( $dir ) ){
- return false;
- }
+ private static function unlink_r( $dir, $deleteRootToo=true ){
+ if( !$dh = @opendir( $dir ) ){
+ return false;
+ }
while (false !== ($obj = readdir($dh))){
- if($obj == '.' || $obj == '..') {
- continue;
- }
- if (!@unlink($dir . '/' . $obj)){
- self::unlink_r($dir.'/'.$obj, true);
- }
- }
- closedir($dh);
- if ( $deleteRootToo ) {
- @rmdir($dir);
- }
- return true;
- }
-
+ if($obj == '.' || $obj == '..') {
+ continue;
+ }
+ if (!@unlink($dir . '/' . $obj)){
+ self::unlink_r($dir.'/'.$obj, true);
+ }
+ }
+ closedir($dh);
+ if ( $deleteRootToo ) {
+ @rmdir($dir);
+ }
+ return true;
+ }
+
/**
- * @breif copies recursively
+ * @brief copies recursively
* @param $path string path to source folder
* @param $dest string path to destination
* @return bool
@@ -349,12 +350,12 @@ class OC_Migrate{
return copy( $path, $dest );
} else {
return false;
- }
+ }
}
-
+
/**
- * @breif tries to extract the import zip
- * @param $path string path to the zip
+ * @brief tries to extract the import zip
+ * @param $path string path to the zip
* @return string path to extract location (with a trailing slash) or false on failure
*/
static private function extractZip( $path ){
@@ -362,20 +363,20 @@ class OC_Migrate{
// Validate path
if( !file_exists( $path ) ){
OC_Log::write( 'migration', 'Zip not found', OC_Log::ERROR );
- return false;
+ return false;
}
if ( self::$zip->open( $path ) != TRUE ) {
OC_Log::write( 'migration', "Failed to open zip file", OC_Log::ERROR );
return false;
}
- $to = get_temp_dir() . '/oc_import_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '/';
+ $to = get_temp_dir() . '/oc_import_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '/';
if( !self::$zip->extractTo( $to ) ){
- return false;
+ return false;
}
- self::$zip->close();
+ self::$zip->close();
return $to;
}
-
+
/**
* @brief connects to a MDB2 database scheme
* @returns bool
@@ -393,16 +394,16 @@ class OC_Migrate{
return true;
}
-
+
/**
- * @breif creates a migration.db in the users data dir with their app data in
+ * @brief creates a migration.db in the users data dir with their app data in
* @return bool whether operation was successfull
*/
private static function exportAppData( ){
-
+
$success = true;
$return = array();
-
+
// Foreach provider
foreach( self::$providers as $provider ){
$success = true;
@@ -413,37 +414,37 @@ class OC_Migrate{
if( is_array( $tables ) ){
// Save the table names
foreach($tables as $table){
- $return['apps'][$provider->getID()]['tables'][] = $table;
- }
+ $return['apps'][$provider->getID()]['tables'][] = $table;
+ }
} else {
// It failed to create the tables
$success = false;
- }
+ }
}
-
+
// Run the export function?
if( $success ){
// Set the provider properties
$provider->setData( self::$uid, self::$content );
- $return['apps'][$provider->getID()]['success'] = $provider->export();
+ $return['apps'][$provider->getID()]['success'] = $provider->export();
} else {
- $return['apps'][$provider->getID()]['success'] = false;
- $return['apps'][$provider->getID()]['message'] = 'failed to create the app tables';
+ $return['apps'][$provider->getID()]['success'] = false;
+ $return['apps'][$provider->getID()]['message'] = 'failed to create the app tables';
}
-
+
// Now add some app info the the return array
$appinfo = OC_App::getAppInfo( $provider->getID() );
- $return['apps'][$provider->getID()]['version'] = $appinfo['version'];
-
+ $return['apps'][$provider->getID()]['version'] = OC_App::getAppVersion($provider->getID());
+
}
-
+
return $return;
-
+
}
-
-
+
+
/**
- * @breif generates json containing export info, and merges any data supplied
+ * @brief generates json containing export info, and merges any data supplied
* @param optional $array array of data to include in the returned json
* @return bool
*/
@@ -464,11 +465,11 @@ class OC_Migrate{
OC_Log::write( 'migration', 'Failed to get the users password hash', OC_log::ERROR);
return false;
}
- $info['hash'] = $hash;
- $info['exporteduser'] = self::$uid;
+ $info['hash'] = $hash;
+ $info['exporteduser'] = self::$uid;
}
if( !is_array( $array ) ){
- OC_Log::write( 'migration', 'Supplied $array was not an array in getExportInfo()', OC_Log::ERROR );
+ OC_Log::write( 'migration', 'Supplied $array was not an array in getExportInfo()', OC_Log::ERROR );
}
// Merge in other data
$info = array_merge( $info, (array)$array );
@@ -476,9 +477,9 @@ class OC_Migrate{
$json = json_encode( $info );
return $json;
}
-
+
/**
- * @breif connects to migration.db, or creates if not found
+ * @brief connects to migration.db, or creates if not found
* @param $db optional path to migration.db, defaults to user data dir
* @return bool whether the operation was successful
*/
@@ -487,19 +488,19 @@ class OC_Migrate{
self::$dbpath = !is_null( $path ) ? $path : self::$dbpath;
if( !self::$dbpath ){
OC_Log::write( 'migration', 'connectDB() was called without dbpath being set', OC_Log::ERROR );
- return false;
+ return false;
}
// Already connected
if(!self::$MDB2){
require_once('MDB2.php');
-
+
$datadir = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
-
+
// DB type
if( class_exists( 'SQLite3' ) ){
$dbtype = 'sqlite3';
} else if( is_callable( 'sqlite_open' ) ){
- $dbtype = 'sqlite';
+ $dbtype = 'sqlite';
} else {
OC_Log::write( 'migration', 'SQLite not found', OC_Log::ERROR );
return false;
@@ -533,53 +534,53 @@ class OC_Migrate{
self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC);
}
return true;
-
+
}
-
+
/**
- * @breif creates the tables in migration.db from an apps database.xml
+ * @brief creates the tables in migration.db from an apps database.xml
* @param $appid string id of the app
* @return bool whether the operation was successful
*/
static private function createAppTables( $appid ){
-
+
if( !self::connectScheme() ){
- return false;
+ return false;
}
-
- // There is a database.xml file
+
+ // There is a database.xml file
$content = file_get_contents( OC::$SERVERROOT . '/apps/' . $appid . '/appinfo/database.xml' );
-
+
$file2 = 'static://db_scheme';
// TODO get the relative path to migration.db from the data dir
// For now just cheat
$path = pathinfo( self::$dbpath );
$content = str_replace( '*dbname*', self::$uid.'/migration', $content );
$content = str_replace( '*dbprefix*', '', $content );
-
+
$xml = new SimpleXMLElement($content);
foreach($xml->table as $table){
- $tables[] = (string)$table->name;
- }
-
+ $tables[] = (string)$table->name;
+ }
+
file_put_contents( $file2, $content );
-
+
// Try to create tables
$definition = self::$schema->parseDatabaseDefinitionFile( $file2 );
unlink( $file2 );
-
+
// Die in case something went wrong
if( $definition instanceof MDB2_Schema_Error ){
OC_Log::write( 'migration', 'Failed to parse database.xml for: '.$appid, OC_Log::FATAL );
OC_Log::write( 'migration', $definition->getMessage().': '.$definition->getUserInfo(), OC_Log::FATAL );
return false;
}
-
+
$definition['overwrite'] = true;
-
+
$ret = self::$schema->createDatabase( $definition );
-
+
// Die in case something went wrong
if( $ret instanceof MDB2_Error ){
OC_Log::write( 'migration', 'Failed to create tables for: '.$appid, OC_Log::FATAL );
@@ -591,7 +592,7 @@ class OC_Migrate{
}
/**
- * @breif tries to create the zip
+ * @brief tries to create the zip
* @param $path string path to zip destination
* @return bool
*/
@@ -600,18 +601,18 @@ class OC_Migrate{
// Check if properties are set
if( !self::$zippath ){
OC_Log::write('migration', 'createZip() called but $zip and/or $zippath have not been set', OC_Log::ERROR);
- return false;
+ return false;
}
if ( self::$zip->open( self::$zippath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ) !== TRUE ) {
OC_Log::write('migration', 'Failed to create the zip with error: '.self::$zip->getStatusString(), OC_Log::ERROR);
return false;
} else {
- return true;
- }
+ return true;
+ }
}
-
+
/**
- * @breif returns an array of apps that support migration
+ * @brief returns an array of apps that support migration
* @return array
*/
static public function getApps(){
@@ -620,13 +621,13 @@ class OC_Migrate{
$path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php';
if( file_exists( $path ) ){
$supportsmigration[] = $app;
- }
+ }
}
- return $supportsmigration;
+ return $supportsmigration;
}
-
+
/**
- * @breif imports a new user
+ * @brief imports a new user
* @param $db string path to migration.db
* @param $info object of migration info
* @param $uid optional uid to use
@@ -639,76 +640,76 @@ class OC_Migrate{
if(!self::connectDB( $db )){
OC_Log::write('migration','Failed to connect to migration.db',OC_Log::ERROR);
return false;
- }
+ }
} else {
- OC_Log::write('migration','Migration.db not found at: '.$db, OC_Log::FATAL );
+ OC_Log::write('migration','Migration.db not found at: '.$db, OC_Log::FATAL );
return false;
}
-
+
// Find providers
self::findProviders();
// Generate importinfo array
- $importinfo = array(
+ $importinfo = array(
'olduid' => $info->exporteduser,
'newuid' => self::$uid
);
-
+
foreach( self::$providers as $provider){
// Is the app in the export?
$id = $provider->getID();
if( isset( $info->apps->$id ) ){
// Is the app installed
if( !OC_App::isEnabled( $id ) ){
- OC_Log::write( 'migration', 'App: ' . $id . ' is not installed, can\'t import data.', OC_Log::INFO );
- $appsstatus[$id] = 'notsupported';
+ OC_Log::write( 'migration', 'App: ' . $id . ' is not installed, can\'t import data.', OC_Log::INFO );
+ $appsstatus[$id] = 'notsupported';
} else {
// Did it succeed on export?
if( $info->apps->$id->success ){
// Give the provider the content object
if( !self::connectDB( $db ) ){
- return false;
+ return false;
}
$content = new OC_Migration_Content( self::$zip, self::$MDB2 );
$provider->setData( self::$uid, $content, $info );
// Then do the import
if( !$appsstatus[$id] = $provider->import( $info->apps->$id, $importinfo ) ){
// Failed to import app
- OC_Log::write( 'migration', 'Failed to import app data for user: ' . self::$uid . ' for app: ' . $id, OC_Log::ERROR );
+ OC_Log::write( 'migration', 'Failed to import app data for user: ' . self::$uid . ' for app: ' . $id, OC_Log::ERROR );
}
} else {
// Add to failed list
- $appsstatus[$id] = false;
+ $appsstatus[$id] = false;
}
- }
- }
+ }
+ }
}
-
+
return $appsstatus;
-
+
}
-
+
/*
- * @breif creates a new user in the database
+ * @brief creates a new user in the database
* @param $uid string user_id of the user to be created
* @param $hash string hash of the user to be created
* @return bool result of user creation
*/
public static function createUser( $uid, $hash ){
-
+
// Check if userid exists
if(OC_User::userExists( $uid )){
return false;
}
-
+
// Create the user
$query = OC_DB::prepare( "INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )" );
$result = $query->execute( array( $uid, $hash));
if( !$result ){
- OC_Log::write('migration', 'Failed to create the new user "'.$uid."");
+ OC_Log::write('migration', 'Failed to create the new user "'.$uid."");
}
return $result ? true : false;
-
+
}
}
diff --git a/lib/migration/content.php b/lib/migration/content.php
index d304051f3e6..7ef88f36e43 100644
--- a/lib/migration/content.php
+++ b/lib/migration/content.php
@@ -33,7 +33,7 @@ class OC_Migration_Content{
private $tmpfiles=false;
/**
- * @breif sets up the
+ * @brief sets up the
* @param $zip ZipArchive object
* @param optional $db a MDB2 database object (required for exporttype user)
* @return bool
@@ -51,7 +51,7 @@ class OC_Migration_Content{
}
- // @breif prepares the db
+ // @brief prepares the db
// @param $query the sql query to prepare
public function prepare( $query ){
@@ -74,7 +74,7 @@ class OC_Migration_Content{
}
/**
- * @breif processes the db query
+ * @brief processes the db query
* @param $query the query to process
* @return string of processed query
*/
@@ -130,7 +130,7 @@ class OC_Migration_Content{
}
/**
- * @breif saves a sql data set into migration.db
+ * @brief saves a sql data set into migration.db
* @param $data a sql data set returned from self::prepare()->query()
* @param $options array of copyRows options
* @return void
@@ -175,7 +175,7 @@ class OC_Migration_Content{
}
/**
- * @breif adds a directory to the zip object
+ * @brief adds a directory to the zip object
* @param $dir string path of the directory to add
* @param $recursive bool
* @param $internaldir string path of folder to add dir to in zip
@@ -209,7 +209,7 @@ class OC_Migration_Content{
}
/**
- * @breif adds a file to the zip from a given string
+ * @brief adds a file to the zip from a given string
* @param $data string of data to add
* @param $path the relative path inside of the zip to save the file to
* @return bool
@@ -228,7 +228,7 @@ class OC_Migration_Content{
}
/**
- * @breif closes the zip, removes temp files
+ * @brief closes the zip, removes temp files
* @return bool
*/
public function finish(){
@@ -241,7 +241,7 @@ class OC_Migration_Content{
}
/**
- * @breif cleans up after the zip
+ * @brief cleans up after the zip
*/
private function cleanup(){
// Delete tmp files
@@ -249,4 +249,4 @@ class OC_Migration_Content{
unlink( $i );
}
}
-} \ No newline at end of file
+}
diff --git a/lib/migration/provider.php b/lib/migration/provider.php
index feae29f1354..91336f3019d 100644
--- a/lib/migration/provider.php
+++ b/lib/migration/provider.php
@@ -17,19 +17,19 @@ abstract class OC_Migration_Provider{
}
/**
- * @breif exports data for apps
+ * @brief exports data for apps
* @return array appdata to be exported
*/
abstract function export( );
/**
- * @breif imports data for the app
+ * @brief imports data for the app
* @return void
*/
abstract function import( );
/**
- * @breif sets the OC_Migration_Content object to $this->content
+ * @brief sets the OC_Migration_Content object to $this->content
* @param $content a OC_Migration_Content object
*/
public function setData( $uid, $content, $info=null ){
@@ -43,7 +43,7 @@ abstract class OC_Migration_Provider{
}
/**
- * @breif returns the appid of the provider
+ * @brief returns the appid of the provider
* @return string
*/
public function getID(){
diff --git a/lib/mimetypes.list.php b/lib/mimetypes.list.php
index e0570e84ea5..ccf47999b1c 100644
--- a/lib/mimetypes.list.php
+++ b/lib/mimetypes.list.php
@@ -21,7 +21,7 @@
*/
/**
- * list of mimetypes by extention
+ * list of mimetypes by extension
*/
return array(
diff --git a/lib/ocsclient.php b/lib/ocsclient.php
index d830a4f3e7e..aef51f38fb7 100755..100644
--- a/lib/ocsclient.php
+++ b/lib/ocsclient.php
@@ -162,6 +162,7 @@ class OC_OCSClient{
$app['preview3']=$tmp->smallpreviewpic3;
$app['changed']=strtotime($tmp->changed);
$app['description']=$tmp->description;
+ $app['detailpage']=$tmp->detailpage;
return $app;
}
@@ -199,7 +200,7 @@ class OC_OCSClient{
*
* This function returns a list of all the knowledgebase entries from the OCS server
*/
- public static function getKnownledgebaseEntries($page,$pagesize){
+ public static function getKnownledgebaseEntries($page,$pagesize,$search=''){
if(OC_Config::getValue('knowledgebaseenabled', true)==false){
$kbe=array();
$kbe['totalitems']=0;
@@ -208,7 +209,8 @@ class OC_OCSClient{
$p= (int) $page;
$s= (int) $pagesize;
- $url=OC_OCSClient::getKBURL().'/knowledgebase/data?type=150&page='.$p.'&pagesize='.$s;
+ if($search<>'') $searchcmd='&search='.urlencode($search); else $searchcmd='';
+ $url=OC_OCSClient::getKBURL().'/knowledgebase/data?type=150&page='.$p.'&pagesize='.$s.$searchcmd;
$kbe=array();
$xml=@file_get_contents($url);
diff --git a/lib/public/app.php b/lib/public/app.php
new file mode 100644
index 00000000000..80d0fd22b6b
--- /dev/null
+++ b/lib/public/app.php
@@ -0,0 +1,169 @@
+<?php
+/**
+* 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 <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * App Class.
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class App {
+
+
+ /**
+ * @brief get the user id of the user currently logged in.
+ * @return string uid or false
+ */
+ public static function getUser(){
+ return \OC_USER::getUser();
+ }
+
+
+ /**
+ * @brief makes owncloud aware of this app
+ * @param $data array with all information
+ * @returns true/false
+ *
+ * This function registers the application. $data is an associative array.
+ * 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
+ * a list of applications. Lower values come first.
+ *
+ */
+ public static function register( $data ){
+ return \OC_App::register( $data );
+ }
+
+
+ /**
+ * register an admin form to be shown
+ */
+ public static function registerAdmin($app,$page){
+ return \OC_App::registerAdmin($app,$page);
+ }
+
+
+ /**
+ * @brief adds an entry to the navigation
+ * @param $data array containing the data
+ * @returns true/false
+ *
+ * This function adds a new entry to the navigation visible to users. $data
+ * is an associative array.
+ * The following keys are required:
+ * - id: unique id for this entry ('addressbook_index')
+ * - href: link to the page
+ * - name: Human readable name ('Addressbook')
+ *
+ * The following keys are optional:
+ * - icon: path to the icon of the app
+ * - order: integer, that influences the position of your application in
+ * the navigation. Lower values come first.
+ */
+ public static function addNavigationEntry( $data ){
+ return \OC_App::addNavigationEntry($data);
+ }
+
+
+ /**
+ * @brief Read app metadata from the info.xml file
+ * @param string $appid id of the app or the path of the info.xml file
+ * @param boolean path (optional)
+ * @returns array
+ */
+ public static function getAppInfo($appid,$path=false){
+ return \OC_App::getAppInfo($appid,$path);
+ }
+
+
+ /**
+ * register a personal form to be shown
+ */
+ public static function registerPersonal($app,$page){
+ return \OC_App::registerPersonal($app,$page);
+ }
+
+
+ /**
+ * @brief marks a navigation entry as active
+ * @param $id id of the entry
+ * @returns true/false
+ *
+ * This function sets a navigation entry as active and removes the 'active'
+ * property from all other entries. The templates can use this for
+ * highlighting the current position of the user.
+ */
+ public static function setActiveNavigationEntry($id){
+ return \OC_App::setActiveNavigationEntry($id);
+ }
+
+
+ /**
+ * @brief checks whether or not an app is enabled
+ * @param $app app
+ * @returns true/false
+ *
+ * This function checks whether or not an app is enabled.
+ */
+ public static function isEnabled( $app ){
+ return \OC_App::isEnabled( $app );
+ }
+
+
+ /**
+ * Check if the app is enabled, redirects to home if not
+ */
+ public static function checkAppEnabled($app){
+ return \OC_Util::checkAppEnabled( $app );
+ }
+
+
+ /**
+ * get the last version of the app, either from appinfo/version or from appinfo/info.xml
+ */
+ public static function getAppVersion($appid){
+ return \OC_App::getAppVersion( $appid );
+ }
+
+
+ /**
+ * @param string appid
+ * @return OC_FilesystemView
+ */
+ public static function getStorage($appid){
+ return \OC_App::getStorage( $appid );
+ }
+
+
+}
+
+
+?>
diff --git a/lib/public/config.php b/lib/public/config.php
new file mode 100644
index 00000000000..5681f20e3b3
--- /dev/null
+++ b/lib/public/config.php
@@ -0,0 +1,133 @@
+<?php
+/**
+* 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 <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * Config Class
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class Config {
+
+
+
+
+ /**
+ * @brief Gets a value from config.php
+ * @param $key key
+ * @param $default = null default value
+ * @returns the value or $default
+ *
+ * This function gets the value from config.php. If it does not exist,
+ * $default will be returned.
+ */
+ public static function getSystemValue( $key, $default = null ){
+ return(\OC_Config::getValue( $key, $default ));
+ }
+
+
+ /**
+ * @brief Sets a value
+ * @param $key key
+ * @param $value value
+ * @returns true/false
+ *
+ * This function sets the value and writes the config.php. If the file can
+ * not be written, false will be returned.
+ */
+ public static function setSystemValue( $key, $value ){
+ return(\OC_Config::setValue( $key, $value ));
+ }
+
+
+ /**
+ * @brief Gets the config value
+ * @param $app app
+ * @param $key key
+ * @param $default = null, default value if the key does not exist
+ * @returns the value or $default
+ *
+ * This function gets a value from the appconfig table. If the key does
+ * not exist the default value will be returnes
+ */
+ public static function getAppValue( $app, $key, $default = null ){
+ return(\OC_Appconfig::getValue( $app, $key, $default ));
+ }
+
+
+ /**
+ * @brief sets a value in the appconfig
+ * @param $app app
+ * @param $key key
+ * @param $value value
+ * @returns true/false
+ *
+ * Sets a value. If the key did not exist before it will be created.
+ */
+ public static function setAppValue( $app, $key, $value ){
+ return(\OC_Appconfig::setValue( $app, $key, $value ));
+ }
+
+
+ /**
+ * @brief Gets the preference
+ * @param $user user
+ * @param $app app
+ * @param $key key
+ * @param $default = null, default value if the key does not exist
+ * @returns the value or $default
+ *
+ * This function gets a value from the prefernces table. If the key does
+ * not exist the default value will be returnes
+ */
+ public static function getUserValue( $user, $app, $key, $default = null ){
+ return(\OC_Preferences::getValue( $user, $app, $key, $default ));
+ }
+
+
+ /**
+ * @brief sets a value in the preferences
+ * @param $user user
+ * @param $app app
+ * @param $key key
+ * @param $value value
+ * @returns true/false
+ *
+ * Adds a value to the preferences. If the key did not exist before, it
+ * will be added automagically.
+ */
+ public static function setUserValue( $user, $app, $key, $value ){
+ return(\OC_Preferences::setValue( $user, $app, $key, $value ));
+ }
+
+
+
+
+
+
+}
+
+?>
diff --git a/lib/public/db.php b/lib/public/db.php
new file mode 100644
index 00000000000..b534756a5a0
--- /dev/null
+++ b/lib/public/db.php
@@ -0,0 +1,92 @@
+<?php
+/**
+* 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 <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * DB Class
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class DB {
+
+
+ /**
+ * @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 ){
+ return(\OC_DB::prepare($query));
+ }
+
+ /**
+ * @brief gets last value of autoincrement
+ * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix
+ * @returns id
+ *
+ * MDB2 lastInsertID()
+ *
+ * Call this method right after the insert command or other functions may
+ * cause trouble!
+ */
+ public static function insertid($table=null){
+ return(\OC_DB::insertid($table));
+ }
+
+
+
+ /**
+ * Start a transaction
+ */
+ public static function beginTransaction(){
+ return(\OC_DB::beginTransaction());
+ }
+
+
+ /**
+ * Commit the database changes done during a transaction that is in progress
+ */
+ public static function commit(){
+ return(\OC_DB::commit());
+ }
+
+
+ /**
+ * check if a result is an error, works with MDB2 and PDOException
+ * @param mixed $result
+ * @return bool
+ */
+ public static function isError($result){
+ return(\OC_DB::isError($result));
+ }
+
+
+
+}
+
+?>
diff --git a/lib/public/files.php b/lib/public/files.php
new file mode 100644
index 00000000000..f2153f33b90
--- /dev/null
+++ b/lib/public/files.php
@@ -0,0 +1,114 @@
+<?php
+/**
+* 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 <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * Files Class
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class Files {
+
+
+ /**
+ * @brief Recusive deletion of folders
+ * @param string $dir path to the folder
+ *
+ */
+ static function rmdirr($dir) {
+ \OC_Helper::rmdirr( $dir );
+ }
+
+
+ /**
+ * get the mimetype form a local file
+ * @param string path
+ * @return string
+ * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
+ */
+ static function getMimeType($path){
+ return(\OC_Helper::getMimeType( $path ));
+ }
+
+ /**
+ * copy the contents of one stream to another
+ * @param resource source
+ * @param resource target
+ * @return int the number of bytes copied
+ */
+ public static function streamCopy($source,$target){
+ return(\OC_Helper::streamCopy($source,$target));
+ }
+
+
+ /**
+ * create a temporary file with an unique filename
+ * @param string postfix
+ * @return string
+ *
+ * temporary files are automatically cleaned up after the script is finished
+ */
+ public static function tmpFile($postfix=''){
+ return(\OC_Helper::tmpFile($postfix));
+ }
+
+ /**
+ * create a temporary folder with an unique filename
+ * @return string
+ *
+ * temporary files are automatically cleaned up after the script is finished
+ */
+ public static function tmpFolder(){
+ return(\OC_Helper::tmpFolder());
+ }
+
+ /**
+ * Adds a suffix to the name in case the file exists
+ *
+ * @param $path
+ * @param $filename
+ * @return string
+ */
+ public static function buildNotExistingFileName($path, $filename){
+ return(\OC_Helper::buildNotExistingFileName($path, $filename));
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+
+?>
diff --git a/lib/public/json.php b/lib/public/json.php
new file mode 100644
index 00000000000..36d3bed807f
--- /dev/null
+++ b/lib/public/json.php
@@ -0,0 +1,94 @@
+<?php
+/**
+* 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 <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * JSON Class
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class JSON {
+
+
+
+ /**
+ * Encode and print $data in JSON format
+ */
+ public static function encodedPrint($data,$setContentType=true){
+ return(\OC_JSON::encodedPrint($data,$setContentType));
+ }
+
+ /**
+ * Check if the user is logged in, send json error msg if not
+ */
+ public static function checkLoggedIn(){
+ return(\OC_JSON::checkLoggedIn());
+ }
+
+
+
+ /**
+ * Send json success msg
+ */
+ public static function success($data = array()){
+ return(\OC_JSON::success($data));
+ }
+
+
+ /**
+ * Send json error msg
+ */
+ public static function error($data = array()){
+ return(\OC_JSON::error($data));
+ }
+
+
+ /**
+ * set Content-Type header to jsonrequest
+ */
+ public static function setContentTypeHeader($type='application/json'){
+ return(\OC_JSON::setContentTypeHeader($type));
+ }
+
+
+ /**
+ * Check if the app is enabled, send json error msg if not
+ */
+ public static function checkAppEnabled($app){
+ return(\OC_JSON::checkAppEnabled($app));
+ }
+
+
+ /**
+ * Check if the user is a admin, send json error msg if not
+ */
+ public static function checkAdminUser(){
+ return(\OC_JSON::checkAdminUser());
+ }
+
+}
+
+?>
diff --git a/lib/public/response.php b/lib/public/response.php
new file mode 100644
index 00000000000..2efa74ef840
--- /dev/null
+++ b/lib/public/response.php
@@ -0,0 +1,106 @@
+<?php
+/**
+* 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 <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * Response Class.
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class Response {
+
+
+ /**
+ * @brief Enable response caching by sending correct HTTP headers
+ * @param $cache_time time to cache the response
+ * >0 cache time in seconds
+ * 0 and <0 enable default browser caching
+ * null cache indefinitly
+ */
+ static public function enableCaching($cache_time = null) {
+ return(\OC_Response::enableCaching($cache_time));
+ }
+
+
+ /**
+ * Checks and set Last-Modified header, when the request matches sends a
+ * 'not modified' response
+ * @param $lastModified time when the reponse was last modified
+ */
+ static public function setLastModifiedHeader($lastModified) {
+ return(\OC_Response::setLastModifiedHeader($lastModified));
+ }
+
+
+ /**
+ * @brief disable browser caching
+ * @see enableCaching with cache_time = 0
+ */
+ static public function disableCaching() {
+ return(\OC_Response::disableCaching());
+ }
+
+
+ /**
+ * Checks and set ETag header, when the request matches sends a
+ * 'not modified' response
+ * @param $etag token to use for modification check
+ */
+ static public function setETagHeader($etag) {
+ return(\OC_Response::setETagHeader($etag));
+ }
+
+
+ /**
+ * @brief Send file as response, checking and setting caching headers
+ * @param $filepath of file to send
+ */
+ static public function sendFile($filepath) {
+ return(\OC_Response::sendFile($filepath));
+ }
+
+ /**
+ * @brief Set reponse expire time
+ * @param $expires date-time when the response expires
+ * string for DateInterval from now
+ * DateTime object when to expire response
+ */
+ static public function setExpiresHeader($expires) {
+ return(\OC_Response::setExpiresHeader($expires));
+ }
+
+ /**
+ * @brief Send redirect response
+ * @param $location to redirect to
+ */
+ static public function redirect($location) {
+ return(\OC_Response::redirect($location));
+ }
+
+
+}
+
+?>
diff --git a/lib/public/user.php b/lib/public/user.php
new file mode 100644
index 00000000000..b39235bb965
--- /dev/null
+++ b/lib/public/user.php
@@ -0,0 +1,106 @@
+<?php
+/**
+* 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 <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * User Class.
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class User {
+
+
+ /**
+ * @brief get the user id of the user currently logged in.
+ * @return string uid or false
+ */
+ public static function getUser(){
+ return \OC_USER::getUser();
+ }
+
+
+
+ /**
+ * @brief Check if the user is logged in
+ * @returns true/false
+ *
+ * Checks if the user is logged in
+ */
+ public static function isLoggedIn(){
+ return \OC_USER::isLoggedIn();
+ }
+
+ /**
+ * @brief check if a user exists
+ * @param string $uid the username
+ * @return boolean
+ */
+ public static function userExists($uid){
+ return \OC_USER::userExists($uid);
+ }
+
+ /**
+ * @brief Loggs the user out including all the session data
+ * @returns true
+ *
+ * Logout, destroys session
+ */
+ public static function logout(){
+ return \OC_USER::logout();
+ }
+
+ /**
+ * @brief Check if the password is correct
+ * @param $uid The username
+ * @param $password The password
+ * @returns true/false
+ *
+ * Check if the password is correct without logging in the user
+ */
+ public static function checkPassword( $uid, $password ){
+ return \OC_USER::checkPassword($uid, $password);
+ }
+
+ /**
+ * Check if the user is a admin, redirects to home if not
+ */
+ public static function checkAdminUser(){
+ \OC_Util::checkAdminUser();
+ }
+
+ /**
+ * Check if the user is logged in, redirects to home if not. With
+ * redirect URL parameter to the request URI.
+ */
+ public static function checkLoggedIn(){
+ \OC_Util::checkLoggedIn();
+ }
+
+
+}
+
+
+?>
diff --git a/lib/public/util.php b/lib/public/util.php
new file mode 100644
index 00000000000..a65b9aa2627
--- /dev/null
+++ b/lib/public/util.php
@@ -0,0 +1,200 @@
+<?php
+/**
+* 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 <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * Utility Class.
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class Util {
+
+ // consts for Logging
+ const DEBUG=0;
+ const INFO=1;
+ const WARN=2;
+ const ERROR=3;
+ const FATAL=4;
+
+ /**
+ * get the current installed version of ownCloud
+ * @return array
+ */
+ public static function getVersion(){
+ return(\OC_Util::getVersion());
+ }
+
+
+ /**
+ * send an email
+ *
+ * @param string $toaddress
+ * @param string $toname
+ * @param string $subject
+ * @param string $mailtext
+ * @param string $fromaddress
+ * @param string $fromname
+ * @param bool $html
+ */
+ public static function sendMail($toaddress,$toname,$subject,$mailtext,$fromaddress,$fromname,$html=0,$altbody='',$ccaddress='',$ccname='',$bcc='') {
+ // call the internal mail class
+ \OC_MAIL::send($toaddress,$toname,$subject,$mailtext,$fromaddress,$fromname,$html=0,$altbody='',$ccaddress='',$ccname='',$bcc='');
+ }
+
+ /**
+ * write a message in the log
+ *
+ * @param string $app
+ * @param string $message
+ * @param int level
+ */
+ public static function writeLog($app, $message, $level) {
+ // call the internal log class
+ \OC_LOG::write($app, $message, $level);
+ }
+
+
+ /**
+ * add a css file
+ *
+ * @param url $url
+ */
+ public static function addStyle( $application, $file = null ){
+ \OC_Util::addStyle($application, $file);
+ }
+
+ /**
+ * add a javascript file
+ *
+ * @param appid $application
+ * @param filename $file
+ */
+ public static function addScript( $application, $file = null ){
+ \OC_Util::addScript($application, $file);
+ }
+
+ /**
+ * @brief Add a custom element to the header
+ * @param string tag tag name of the element
+ * @param array $attributes array of attributes for the element
+ * @param string $text the text content for the element
+ */
+ public static function addHeader( $tag, $attributes, $text=''){
+ \OC_Util::addHeader($tag, $attribute, $text);
+ }
+
+ /**
+ * formats a timestamp in the "right" way
+ *
+ * @param int timestamp $timestamp
+ * @param bool dateOnly option to ommit time from the result
+ */
+ public static function formatDate( $timestamp,$dateOnly=false){
+ return(\OC_Util::formatDate($timestamp,$dateOnly));
+ }
+
+
+
+ /**
+ * @brief Creates an absolute url
+ * @param $app app
+ * @param $file file
+ * @returns the url
+ *
+ * Returns a absolute url to the given app and file.
+ */
+ public static function linkToAbsolute( $app, $file ) {
+ return(\OC_Helper::linkToAbsolute( $app, $file ));
+ }
+
+
+ /**
+ * @brief Creates an url
+ * @param $app app
+ * @param $file file
+ * @returns the url
+ *
+ * Returns a url to the given app and file.
+ */
+ public static function linkTo( $app, $file ){
+ return(\OC_Helper::linkTo( $app, $file ));
+ }
+
+ /**
+ * @brief Returns the server host
+ * @returns the server host
+ *
+ * Returns the server host, even if the website uses one or more
+ * reverse proxies
+ */
+ public static function getServerHost() {
+ return(\OC_Helper::severHost());
+ }
+
+ /**
+ * @brief Creates path to an image
+ * @param $app app
+ * @param $image image name
+ * @returns the url
+ *
+ * Returns the path to the image.
+ */
+ public static function imagePath( $app, $image ){
+ return(\OC_Helper::imagePath( $app, $image ));
+ }
+
+
+ /**
+ * @brief Make a human file size
+ * @param $bytes file size in bytes
+ * @returns a human readable file size
+ *
+ * Makes 2048 to 2 kB.
+ */
+ public static function humanFileSize( $bytes ){
+ return(\OC_Helper::humanFileSize( $bytes ));
+ }
+
+ /**
+ * @brief Make a computer file size
+ * @param $str file size in a fancy format
+ * @returns a file size in bytes
+ *
+ * Makes 2kB to 2048.
+ *
+ * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
+ */
+ public static function computerFileSize( $str ){
+ return(\OC_Helper::computerFileSize( $str ));
+ }
+
+
+
+
+
+}
+
+?>
diff --git a/lib/setup.php b/lib/setup.php
index 3e46a3dcc9a..3dca3c50918 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -296,15 +296,21 @@ class OC_Setup {
* create .htaccess files for apache hosts
*/
private static function createHtaccess() {
+ $content = "ErrorDocument 403 ".OC::$WEBROOT."/core/templates/403.php\n";//custom 403 error page
$content = "ErrorDocument 404 ".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page
$content.= "<IfModule mod_php5.c>\n";
$content.= "php_value upload_max_filesize 512M\n";//upload limit
$content.= "php_value post_max_size 512M\n";
- $content.= "SetEnv htaccessWorking true\n";
+ $content.= "php_value memory_limit 512M\n";
+ $content.= "<IfModule env_module>\n";
+ $content.= " SetEnv htaccessWorking true\n";
+ $content.= "</IfModule>\n";
$content.= "</IfModule>\n";
$content.= "<IfModule mod_rewrite.c>\n";
$content.= "RewriteEngine on\n";
$content.= "RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]\n";
+ $content.= "RewriteRule ^.well-known/carddav /apps/contacts/carddav.php [R]\n";
+ $content.= "RewriteRule ^.well-known/caldav /apps/calendar/caldav.php [R]\n";
$content.= "</IfModule>\n";
$content.= "Options -Indexes\n";
@file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
diff --git a/lib/template.php b/lib/template.php
index 5bcf52b9321..57e9c15f5e6 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -76,7 +76,7 @@ function simple_file_size($bytes) {
}
function relative_modified_date($timestamp) {
- $l=new OC_L10N('template');
+ $l=OC_L10N::get('template');
$timediff = time() - $timestamp;
$diffminutes = round($timediff/60);
$diffhours = round($diffminutes/60);
@@ -155,13 +155,13 @@ class OC_Template{
$this->renderas = $renderas;
$this->application = $app;
$this->vars = array();
- $this->l10n = new OC_L10N($app);
+ $this->l10n = OC_L10N::get($app);
$this->findTemplate($name);
}
/**
- * @brief Returns the formfactor extention for current formfactor
+ * @brief Returns the formfactor extension for current formfactor
*/
protected function getFormFactorExtension()
{
@@ -323,7 +323,16 @@ class OC_Template{
*/
public function appendIfExist($type, $root, $web, $file) {
if (is_file($root.'/'.$file)) {
- $this->append( $type, $web.'/'.$file);
+ $pathes = explode('/', $file);
+ if($type == 'cssfiles' && $root == OC::$APPSROOT && $pathes[0] == 'apps'){
+ $app = $pathes[1];
+ unset($pathes[0]);
+ unset($pathes[1]);
+ $path = implode('/', $pathes);
+ $this->append( $type, OC_Helper::linkTo($app, $path));
+ }else{
+ $this->append( $type, $web.'/'.$file);
+ }
return true;
}
return false;
diff --git a/lib/updater.php b/lib/updater.php
index 196822ac35d..deb0f05945e 100644
--- a/lib/updater.php
+++ b/lib/updater.php
@@ -59,9 +59,9 @@ class OC_Updater{
public static function ShowUpdatingHint(){
$data=OC_Updater::check();
if(isset($data['version']) and $data['version']<>'') {
- $txt='<span style="color:#AA0000; font-weight:bold;">'.$data['versionstring'].' is available. Please click <a href="'.$data['web'].'">here</a> for more information</span>';
+ $txt='<span style="color:#AA0000; font-weight:bold;">'.$data['versionstring'].' is available. Get <a href="'.$data['web'].'">more information</a></span>';
}else{
- $txt='Your ownCloud is up to date';
+ $txt='up to date';
}
return($txt);
}
diff --git a/lib/user.php b/lib/user.php
index 8c27ec30cc2..8b887559df3 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -215,7 +215,7 @@ class OC_User {
}
/**
- * @brief Kick the user
+ * @brief Logs the current user out and kills all the session data
* @returns true
*
* Logout, destroys session
@@ -244,7 +244,7 @@ class OC_User {
}
/**
- * @brief get the user idea of the user currently logged in.
+ * @brief get the user id of the user currently logged in.
* @return string uid or false
*/
public static function getUser(){
@@ -279,15 +279,16 @@ class OC_User {
OC_Hook::emit( "OC_User", "pre_setPassword", array( "run" => &$run, "uid" => $uid, "password" => $password ));
if( $run ){
+ $success = false;
foreach(self::$_usedBackends as $backend){
if($backend->implementsActions(OC_USER_BACKEND_SET_PASSWORD)){
if($backend->userExists($uid)){
- $backend->setPassword($uid,$password);
+ $success |= $backend->setPassword($uid,$password);
}
}
}
OC_Hook::emit( "OC_User", "post_setPassword", array( "uid" => $uid, "password" => $password ));
- return true;
+ return $success;
}
else{
return false;
diff --git a/lib/user/database.php b/lib/user/database.php
index 3eade276dd9..c1bac1bb0b5 100644
--- a/lib/user/database.php
+++ b/lib/user/database.php
@@ -172,7 +172,7 @@ class OC_User_Database extends OC_User_Backend {
* @return boolean
*/
public function userExists($uid){
- $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*users` WHERE uid = ?" );
+ $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*users` WHERE uid LIKE ?" );
$result = $query->execute( array( $uid ));
return $result->numRows() > 0;
diff --git a/lib/util.php b/lib/util.php
index 34f535d2d5c..d22d8710867 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -20,12 +20,20 @@ class OC_Util {
$CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
$CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" );
- // Create root dir
+ // Check if config folder is writable.
+ if(!is_writable(OC::$SERVERROOT."/config/")) {
+ $tmpl = new OC_Template( '', 'error', 'guest' );
+ $tmpl->assign('errors',array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud")));
+ $tmpl->printPage();
+ exit;
+ }
+
+ // Create root dir.
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
$success=@mkdir($CONFIG_DATADIRECTORY_ROOT);
- if(!$success) {
+ if(!$success) {
$tmpl = new OC_Template( '', 'error', 'guest' );
- $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' ")));
+ $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' ")));
$tmpl->printPage();
exit;
}
@@ -88,7 +96,8 @@ class OC_Util {
/**
* add a javascript file
*
- * @param url $url
+ * @param appid $application
+ * @param filename $file
*/
public static function addScript( $application, $file = null ){
if( is_null( $file )){
@@ -105,7 +114,8 @@ class OC_Util {
/**
* add a css file
*
- * @param url $url
+ * @param appid $application
+ * @param filename $file
*/
public static function addStyle( $application, $file = null ){
if( is_null( $file )){
@@ -129,23 +139,23 @@ class OC_Util {
self::$headers[]=array('tag'=>$tag,'attributes'=>$attributes,'text'=>$text);
}
- /**
- * formats a timestamp in the "right" way
- *
- * @param int timestamp $timestamp
- * @param bool dateOnly option to ommit time from the result
- */
- public static function formatDate( $timestamp,$dateOnly=false){
- if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it
- $systemTimeZone = intval(date('O'));
- $systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100);
- $clientTimeZone=$_SESSION['timezone']*60;
- $offset=$clientTimeZone-$systemTimeZone;
- $timestamp=$timestamp+$offset*60;
- }
- $timeformat=$dateOnly?'F j, Y':'F j, Y, H:i';
- return date($timeformat,$timestamp);
- }
+ /**
+ * formats a timestamp in the "right" way
+ *
+ * @param int timestamp $timestamp
+ * @param bool dateOnly option to ommit time from the result
+ */
+ public static function formatDate( $timestamp,$dateOnly=false){
+ if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it
+ $systemTimeZone = intval(date('O'));
+ $systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100);
+ $clientTimeZone=$_SESSION['timezone']*60;
+ $offset=$clientTimeZone-$systemTimeZone;
+ $timestamp=$timestamp+$offset*60;
+ }
+ $timeformat=$dateOnly?'F j, Y':'F j, Y, H:i';
+ return date($timeformat,$timestamp);
+ }
/**
* Shows a pagenavi widget where you can jump to different pages.
@@ -237,6 +247,15 @@ class OC_Util {
if(!function_exists('ctype_digit')){
$errors[]=array('error'=>'PHP module ctype is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.');
}
+ if(!function_exists('json_encode')){
+ $errors[]=array('error'=>'PHP module JSON is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.');
+ }
+ if(!function_exists('imagepng')){
+ $errors[]=array('error'=>'PHP module GD is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.');
+ }
+ if(floatval(phpversion())<5.3){
+ $errors[]=array('error'=>'PHP 5.3 is required.<br/>','hint'=>'Please ask your server administrator to update PHP to version 5.3 or higher. PHP 5.2 is no longer supported by ownCloud and the PHP community.');
+ }
return $errors;
}
@@ -247,6 +266,9 @@ class OC_Util {
} else {
$parameters["username"] = '';
}
+ $sectoken=rand(1000000,9999999);
+ $_SESSION['sectoken']=$sectoken;
+ $parameters["sectoken"] = $sectoken;
OC_Template::printGuestPage("", "login", $parameters);
}
@@ -292,7 +314,7 @@ class OC_Util {
if(isset($_REQUEST['redirect_url'])) {
header( 'Location: '.$_REQUEST['redirect_url']);
} else {
- header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', 'files/index.php'));
+ header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', '?app=files'));
}
exit();
}
diff --git a/lib/vobject.php b/lib/vobject.php
index e3479fc6d36..ec80e1d605a 100644
--- a/lib/vobject.php
+++ b/lib/vobject.php
@@ -41,7 +41,7 @@ class OC_VObject{
*/
public static function parse($data){
try {
- Sabre_VObject_Reader::$elementMap['LAST-MODIFIED'] = 'Sabre_VObject_Element_DateTime';
+ Sabre_VObject_Property::$classMap['LAST-MODIFIED'] = 'Sabre_VObject_Property_DateTime';
$vobject = Sabre_VObject_Reader::read($data);
if ($vobject instanceof Sabre_VObject_Component){
$vobject = new OC_VObject($vobject);
@@ -150,12 +150,12 @@ class OC_VObject{
* @param int $dateType
* @return void
*/
- public function setDateTime($name, $datetime, $dateType=Sabre_VObject_Element_DateTime::LOCALTZ){
+ public function setDateTime($name, $datetime, $dateType=Sabre_VObject_Property_DateTime::LOCALTZ){
if ($datetime == 'now'){
$datetime = new DateTime();
}
if ($datetime instanceof DateTime){
- $datetime_element = new Sabre_VObject_Element_DateTime($name);
+ $datetime_element = new Sabre_VObject_Property_DateTime($name);
$datetime_element->setDateTime($datetime, $dateType);
$this->vobject->__set($name, $datetime_element);
}else{