Skip to content
Snippets Groups Projects
Commit 5d23b60c authored by Jakob Sack's avatar Jakob Sack
Browse files

Merge branch 'refactoring' of git://anongit.kde.org/owncloud into refactoring

parents af1e48df 6c519741
No related branches found
No related tags found
No related merge requests found
...@@ -173,3 +173,13 @@ CREATE TABLE IF NOT EXISTS `users` ( ...@@ -173,3 +173,13 @@ CREATE TABLE IF NOT EXISTS `users` (
-- --
-- Daten für Tabelle `users` -- Daten für Tabelle `users`
-- --
--
-- Table structure for table `foldersize`
--
CREATE TABLE IF NOT EXISTS `foldersize` (
`path` varchar(512) NOT NULL,
`size` int(11) NOT NULL,
PRIMARY KEY (`path`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
\ No newline at end of file
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<tr> <tr>
<td class="selection"><input type="checkbox" /></td> <td class="selection"><input type="checkbox" /></td>
<td class="filename"><a style="background-image:url(<?php if($file["type"] == "dir") echo mimetype_icon("dir"); else echo mimetype_icon($file["mime"]); ?>)" href="<?php if($file["type"] == "dir") echo link_to("files", "index.php?dir=".$file["directory"]."/".$file["name"]); else echo link_to("files", "download.php?file=".$file["directory"]."/".$file["name"]); ?>" title=""><?php echo $file["name"]; ?></a></td> <td class="filename"><a style="background-image:url(<?php if($file["type"] == "dir") echo mimetype_icon("dir"); else echo mimetype_icon($file["mime"]); ?>)" href="<?php if($file["type"] == "dir") echo link_to("files", "index.php?dir=".$file["directory"]."/".$file["name"]); else echo link_to("files", "download.php?file=".$file["directory"]."/".$file["name"]); ?>" title=""><?php echo $file["name"]; ?></a></td>
<td class="filesize"><?php if($file["type"] != "dir" ) echo human_file_size($file["size"]); ?></td> <td class="filesize"><?php echo human_file_size($file["size"]); ?></td>
<td class="date"><?php if($file["type"] != "dir") echo $file["date"]; ?></td> <td class="date"><?php if($file["type"] != "dir") echo $file["date"]; ?></td>
<td class="fileaction"><a href="" title=""><img src="images/drop-arrow.png" alt="+" /></a></td> <td class="fileaction"><a href="" title=""><img src="images/drop-arrow.png" alt="+" /></a></td>
</tr> </tr>
......
...@@ -24,7 +24,12 @@ ...@@ -24,7 +24,12 @@
require_once( 'lib/base.php' ); require_once( 'lib/base.php' );
require_once( 'appconfig.php' ); require_once( 'appconfig.php' );
require_once( 'template.php' ); require_once( 'template.php' );
if( OC_USER::isLoggedIn()){
// check if the server is correctly configured for ownCloud
$errors=OC_UTIL::checkServer();
if(count($errors)>0){
OC_TEMPLATE::printGuestPage( "", "error", array( "errors" => $errors ));
}elseif( OC_USER::isLoggedIn()){
if( $_GET["logout"] ){ if( $_GET["logout"] ){
OC_USER::logout(); OC_USER::logout();
header( "Location: $WEBROOT"); header( "Location: $WEBROOT");
...@@ -34,8 +39,7 @@ if( OC_USER::isLoggedIn()){ ...@@ -34,8 +39,7 @@ if( OC_USER::isLoggedIn()){
header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" ));
exit(); exit();
} }
} }else{
else{
if( OC_USER::login( $_POST["user"], $_POST["password"] )){ if( OC_USER::login( $_POST["user"], $_POST["password"] )){
header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" ));
exit(); exit();
......
...@@ -89,13 +89,17 @@ require_once('connect.php'); ...@@ -89,13 +89,17 @@ require_once('connect.php');
require_once('remotestorage.php'); require_once('remotestorage.php');
require_once('plugin.php'); require_once('plugin.php');
OC_PLUGIN::loadPlugins( "" ); $error=(count(OC_UTIL::checkServer())>0);
if(!$error){
OC_PLUGIN::loadPlugins( "" );
}
OC_USER::setBackend( OC_CONFIG::getValue( "userbackend", "database" )); OC_USER::setBackend( OC_CONFIG::getValue( "userbackend", "database" ));
OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" )); OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" ));
// Set up file system unless forbidden // Set up file system unless forbidden
if( !$RUNTIME_NOSETUPFS ){ if(!$error and !$RUNTIME_NOSETUPFS ){
OC_UTIL::setupFS(); OC_UTIL::setupFS();
} }
...@@ -108,12 +112,10 @@ OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); ...@@ -108,12 +112,10 @@ OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" );
OC_UTIL::addStyle( "styles" ); OC_UTIL::addStyle( "styles" );
// Load Apps // Load Apps
if( !$RUNTIME_NOAPPS ){ if(!$error and !$RUNTIME_NOAPPS ){
OC_APP::loadApps(); OC_APP::loadApps();
} }
// check if the server is correctly configured for ownCloud
OC_UTIL::checkserver();
/** /**
* Class for utility functions * Class for utility functions
* *
...@@ -221,7 +223,7 @@ class OC_UTIL { ...@@ -221,7 +223,7 @@ class OC_UTIL {
/** /**
* check if the current server configuration is suitable for ownCloud * check if the current server configuration is suitable for ownCloud
* * @return array with error messages
*/ */
public static function checkServer(){ public static function checkServer(){
global $SERVERROOT; global $SERVERROOT;
...@@ -230,12 +232,16 @@ class OC_UTIL { ...@@ -230,12 +232,16 @@ class OC_UTIL {
$CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );; $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );;
$CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" ); $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" );
$CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false );
$error=''; $errors=array();
//check for database drivers
if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){
$error.='No database drivers (sqlite or mysql) installed.<br/>'; $errors[]='No database drivers (sqlite or mysql) installed.<br/>';
} }
$CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" );
$CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" );
//check for correct file permissions
if(!stristr(PHP_OS, 'WIN')){ if(!stristr(PHP_OS, 'WIN')){
if($CONFIG_DBTYPE=='sqlite'){ if($CONFIG_DBTYPE=='sqlite'){
$file=$SERVERROOT.'/'.$CONFIG_DBNAME; $file=$SERVERROOT.'/'.$CONFIG_DBNAME;
...@@ -246,7 +252,7 @@ class OC_UTIL { ...@@ -246,7 +252,7 @@ class OC_UTIL {
clearstatcache(); clearstatcache();
$prems=substr(decoct(fileperms($file)),-3); $prems=substr(decoct(fileperms($file)),-3);
if(substr($prems,2,1)!='0'){ if(substr($prems,2,1)!='0'){
$error.='SQLite database file ('.$file.') is readable from the web<br/>'; $errors[]='SQLite database file ('.$file.') is readable from the web<br/>';
} }
} }
} }
...@@ -257,7 +263,7 @@ class OC_UTIL { ...@@ -257,7 +263,7 @@ class OC_UTIL {
clearstatcache(); clearstatcache();
$prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
if(substr($prems,2,1)!='0'){ if(substr($prems,2,1)!='0'){
$error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>'; $errors[]='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>';
} }
} }
if( OC_CONFIG::getValue( "enablebackup", false )){ if( OC_CONFIG::getValue( "enablebackup", false )){
...@@ -267,16 +273,20 @@ class OC_UTIL { ...@@ -267,16 +273,20 @@ class OC_UTIL {
clearstatcache(); clearstatcache();
$prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
if(substr($prems,2,1)!='0'){ if(substr($prems,2,1)!='0'){
$error.='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>'; $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>';
} }
} }
} }
}else{ }else{
//TODO: premisions checks for windows hosts //TODO: premisions checks for windows hosts
} }
if($error){ if(!is_writable($CONFIG_DATADIRECTORY_ROOT)){
die($error); $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') not writable by ownCloud<br/>';
} }
//TODO: check for php modules
return $errors;
} }
} }
......
...@@ -64,6 +64,7 @@ class OC_FILES { ...@@ -64,6 +64,7 @@ class OC_FILES {
$file['directory']=$directory; $file['directory']=$directory;
$stat=OC_FILESYSTEM::stat($directory.'/'.$filename); $stat=OC_FILESYSTEM::stat($directory.'/'.$filename);
$file=array_merge($file,$stat); $file=array_merge($file,$stat);
$file['size']=OC_FILESYSTEM::filesize($directory.'/'.$filename);
$file['mime']=OC_FILES::getMimeType($directory .'/'. $filename); $file['mime']=OC_FILES::getMimeType($directory .'/'. $filename);
$file['readable']=OC_FILESYSTEM::is_readable($directory .'/'. $filename); $file['readable']=OC_FILESYSTEM::is_readable($directory .'/'. $filename);
$file['writeable']=OC_FILESYSTEM::is_writeable($directory .'/'. $filename); $file['writeable']=OC_FILESYSTEM::is_writeable($directory .'/'. $filename);
......
...@@ -124,7 +124,11 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ ...@@ -124,7 +124,11 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
return $filetype; return $filetype;
} }
public function filesize($path){ public function filesize($path){
return filesize($this->datadir.$path); if($this->is_dir($path)){
return $this->getFolderSize($path);
}else{
return filesize($this->datadir.$path);
}
} }
public function is_readable($path){ public function is_readable($path){
return is_readable($this->datadir.$path); return is_readable($this->datadir.$path);
...@@ -159,6 +163,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ ...@@ -159,6 +163,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
public function file_put_contents($path,$data){ public function file_put_contents($path,$data){
if($return=file_put_contents($this->datadir.$path,$data)){ if($return=file_put_contents($this->datadir.$path,$data)){
$this->notifyObservers($path,OC_FILEACTION_WRITE); $this->notifyObservers($path,OC_FILEACTION_WRITE);
$this->clearFolderSizeCache($path);
} }
} }
public function unlink($path){ public function unlink($path){
...@@ -197,11 +202,13 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ ...@@ -197,11 +202,13 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
case 'x+': case 'x+':
case 'a+': case 'a+':
$this->notifyObservers($path,OC_FILEACTION_READ | OC_FILEACTION_WRITE); $this->notifyObservers($path,OC_FILEACTION_READ | OC_FILEACTION_WRITE);
$this->clearFolderSizeCache($path);
break; break;
case 'w': case 'w':
case 'x': case 'x':
case 'a': case 'a':
$this->notifyObservers($path,OC_FILEACTION_WRITE); $this->notifyObservers($path,OC_FILEACTION_WRITE);
$this->clearFolderSizeCache($path);
break; break;
} }
} }
...@@ -440,5 +447,66 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ ...@@ -440,5 +447,66 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
} }
return $return; return $return;
} }
/**
* @brief get the size of folder and it's content
* @param string $path file path
* @return int size of folder and it's content
*/
public function getFolderSize($path){
$query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
$size=$query->execute(array($path))->fetchAll();
if(count($size)>0){// we already the size, just return it
return $size[0]['size'];
}else{//the size of the folder isn't know, calulate it
return $this->calculateFolderSize($path);
}
}
/**
* @brief calulate the size of folder and it's content and cache it
* @param string $path file path
* @return int size of folder and it's content
*/
public function calculateFolderSize($path){
$size=0;
if ($dh = $this->opendir($path)) {
while (($filename = readdir($dh)) !== false) {
if($filename!='.' and $filename!='..'){
$subFile=$path.'/'.$filename;
if($this->is_file($subFile)){
$size+=$this->filesize($subFile);
}else{
$size+=$this->calculateFolderSize($subFile);
}
}
}
$query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
$hasSize=$query->execute(array($path))->fetchAll();
if(count($hasSize)>0){// yes, update it
$query=OC_DB::prepare("UPDATE *PREFIX*foldersize SET size=? WHERE path=?");
$result=$query->execute(array($size,$path));
}else{// no insert it
$query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
$result=$query->execute(array($path,$size));
}
}
return $size;
}
/**
* @brief clear the folder size cache of folders containing a file
* @param string $path
*/
public function clearFolderSizeCache($path){
$path=dirname($path);
$query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
$result=$query->execute(array($path));
if($path!='/'){
$parts=explode('/');
array_pop($parts);
$parent=implode('/',$parts);
}
}
} }
?> ?>
\ No newline at end of file
<?php
/*
* Template for error page
*/
?>
<div id="login">
<img src="<?php echo image_path("", "owncloud-logo-medium-white.png"); ?>" alt="ownCloud" />
<br/><br/><br/><br/>
<ul>
<?php foreach($_["errors"] as $error):?>
<li><?php echo $error ?></li>
<?php endforeach ?>
</ul>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment