diff options
author | Frank Karlitschek <karlitschek@kde.org> | 2011-04-16 17:40:07 +0200 |
---|---|---|
committer | Frank Karlitschek <karlitschek@kde.org> | 2011-04-16 17:40:07 +0200 |
commit | 26985721624ac578f42c2b66a308b84273b3adfe (patch) | |
tree | 2a4ca3b0ea9aeb3c5c86d388d3933d28cc837759 | |
parent | e440e733fd0b20d6ca5bef8a3097c6e40346dcc7 (diff) | |
parent | 6c51974174f8a78045216567474c380525f77ce9 (diff) | |
download | nextcloud-server-26985721624ac578f42c2b66a308b84273b3adfe.tar.gz nextcloud-server-26985721624ac578f42c2b66a308b84273b3adfe.zip |
Merge branch 'refactoring' of git.kde.org:owncloud into refactoring
-rw-r--r-- | admin/appinfo/app.php | 8 | ||||
-rw-r--r-- | admin/index.php | 14 | ||||
-rw-r--r-- | admin/templates/index.php | 9 | ||||
-rw-r--r-- | admin/templates/users.php | 67 | ||||
-rw-r--r-- | admin/users.php | 11 | ||||
-rw-r--r-- | docs/owncloud.sql | 10 | ||||
-rw-r--r-- | files/templates/index.php | 2 | ||||
-rw-r--r-- | index.php | 12 | ||||
-rw-r--r-- | lib/Group/database.php | 2 | ||||
-rw-r--r-- | lib/base.php | 36 | ||||
-rw-r--r-- | lib/files.php | 1 | ||||
-rw-r--r-- | lib/filestorage.php | 70 | ||||
-rw-r--r-- | templates/error.php | 15 |
13 files changed, 208 insertions, 49 deletions
diff --git a/admin/appinfo/app.php b/admin/appinfo/app.php index a0ee0a0e55b..9e39a052443 100644 --- a/admin/appinfo/app.php +++ b/admin/appinfo/app.php @@ -5,8 +5,10 @@ if( OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )) { OC_APP::addNavigationEntry( array( "id" => "admin_index", "order" => 1, "href" => OC_HELPER::linkTo( "admin", "index.php" ), "icon" => OC_HELPER::imagePath( "admin", "navicon.png" ), "name" => "Administration" )); } -OC_APP::addAdminPage( array( "order" => 1, "href" => OC_HELPER::linkTo( "admin", "system.php" ), "name" => "System settings" )); -OC_APP::addAdminPage( array( "order" => 2, "href" => OC_HELPER::linkTo( "admin", "users.php" ), "name" => "Users" )); -OC_APP::addAdminPage( array( "order" => 3, "href" => OC_HELPER::linkTo( "admin", "plugins.php" ), "name" => "Plugins" )); +OC_APP::addAdminPage( array( "id" => "core_basic", "order" => 1, "href" => OC_HELPER::linkTo( "admin", "basic.php" ), "name" => "Basic Settings" )); +OC_APP::addAdminPage( array( "id" => "core_system", "order" => 2, "href" => OC_HELPER::linkTo( "admin", "system.php" ), "name" => "System settings" )); +OC_APP::addAdminPage( array( "id" => "core_users", "order" => 3, "href" => OC_HELPER::linkTo( "admin", "users.php" ), "name" => "Users" )); +OC_APP::addAdminPage( array( "id" => "core_apps", "order" => 4, "href" => OC_HELPER::linkTo( "admin", "apps.php" ), "name" => "Apps" )); +OC_APP::addAdminPage( array( "id" => "core_plugins", "order" => 5, "href" => OC_HELPER::linkTo( "admin", "plugins.php" ), "name" => "Plugins" )); ?> diff --git a/admin/index.php b/admin/index.php index 8abef287098..2446ebc50aa 100644 --- a/admin/index.php +++ b/admin/index.php @@ -28,15 +28,21 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' exit(); } -$adminpages = array(); +$apppages = array(); +$syspages = array(); foreach( OC_APP::getAdminPages() as $i ){ - // Do some more work here soon - $adminpages[] = $i; + if( substr( $i["id"], 0, 5 ) == "core_" ){ + $syspages[] = $i; + } + else{ + $apppages[] = $i; + } } $tmpl = new OC_TEMPLATE( "admin", "index", "admin" ); -$tmpl->assign( "adminpages", $adminpages ); +$tmpl->assign( "apppages", $apppages ); +$tmpl->assign( "syspages", $syspages ); $tmpl->printPage(); ?> diff --git a/admin/templates/index.php b/admin/templates/index.php index 9d0ffd84c61..fa32a67eadb 100644 --- a/admin/templates/index.php +++ b/admin/templates/index.php @@ -5,8 +5,15 @@ ?> <h1>Administration</h1> +<h2>System</h2> <ul> - <?php foreach($_["adminpages"] as $i): ?> + <?php foreach($_["syspages"] as $i): ?> + <li><a href="<?php echo $i["href"]; ?>"><?php echo $i["name"]; ?></a></li> + <?php endforeach; ?> +</ul> +<h2>Applications</h2> +<ul> + <?php foreach($_["apppages"] as $i): ?> <li><a href="<?php echo $i["href"]; ?>"><?php echo $i["name"]; ?></a></li> <?php endforeach; ?> </ul> diff --git a/admin/templates/users.php b/admin/templates/users.php index 7aa93baf496..88edc01aef2 100644 --- a/admin/templates/users.php +++ b/admin/templates/users.php @@ -9,36 +9,71 @@ <table> <thead> <tr> - <th></th> <th>Name</th> <th>Groups</th> + <th></th> </tr> <thead> <tbody> <?php foreach($_["users"] as $user): ?> <tr> - <td><input type="checkbox"></td> <td><?php echo $user["name"]; ?></td> <td><?php echo $user["groups"]; ?></td> + <td><a href="" class="edituser-button">edit</a> | <a class="removeuser-button" href="">remove</a></td> </tr> <?php endforeach; ?> </tbody> </table> +<a id="adduser-button" href="">New user</a> + <h2>Groups</h2> -<table> - <thead> - <tr> - <th>Name</th> - <th></th> - </tr> - <thead> - <tbody> - <?php foreach($_["groups"] as $group): ?> +<form> + <table> + <thead> <tr> - <td><?php echo $group["name"]; ?></td> - <td>remove</td> + <th>Name</th> + <th></th> </tr> - <?php endforeach; ?> - </tbody> -</table> + <thead> + <tbody> + <?php foreach($_["groups"] as $group): ?> + <tr> + <td><?php echo $group["name"] ?></td> + <td><a class="removegroup-button" href="">remove</a></td> + </tr> + <?php endforeach; ?> + <tr> + <td><input type="text" name="name" /></td> + <td><input type="submit" /></td> + </tr> + </tbody> + </table> +</form> + +<a id="addgroup-button" href="">Add group</a> + + +<div id="adduser-form" title="Add user"> + <form> + User name<br> + <input type="text" name="name" /><br> + Password<br> + <input type="password" name="password" /> + </form> +</div> + +<div id="edituser-form" title="Force new password"> + <form> + New password for $user<br> + <input type="password" name="password" /> + </form> +</div> + +<div id="removeuser-form" title="Remove user"> + Do you really want to delete user $user? +</div> + +<div id="removegroup-form" title="Remove Group"> + Do you really want to delete group $group? +</div> diff --git a/admin/users.php b/admin/users.php index 4d14c791c3c..312bfba2c52 100644 --- a/admin/users.php +++ b/admin/users.php @@ -28,21 +28,24 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' exit(); } +// We have some javascript foo! +OC_UTIL::addScript( "admin", "users" ); + $users = array(); $groups = array(); foreach( OC_USER::getUsers() as $i ){ // Do some more work here soon $ingroups = array(); - foreach( OC_USER::getUserGroups( $i ) as $userGroup){ - $ingroup[] = OC_USER::getGroupName( $userGroup ); + foreach( OC_GROUP::getUserGroups( $i ) as $userGroup ){ + $ingroups[] = $userGroup; } $users[] = array( "name" => $i, "groups" => join( ",", $ingroups )); } -foreach( OC_USER::getGroups() as $i ){ +foreach( OC_GROUP::getGroups() as $i ){ // Do some more work here soon - $groups[] = array( "name" => $i ); + $groups[] = array( "name" => $i["gid"] ); } $tmpl = new OC_TEMPLATE( "admin", "users", "admin" ); diff --git a/docs/owncloud.sql b/docs/owncloud.sql index 3f96a4540eb..75812ad3c7e 100644 --- a/docs/owncloud.sql +++ b/docs/owncloud.sql @@ -173,3 +173,13 @@ CREATE TABLE IF NOT EXISTS `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 diff --git a/files/templates/index.php b/files/templates/index.php index 695a3c45a9d..f1fdafc27cc 100644 --- a/files/templates/index.php +++ b/files/templates/index.php @@ -33,7 +33,7 @@ <tr> <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="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="fileaction"><a href="" title=""><img src="images/drop-arrow.png" alt="+" /></a></td> </tr> diff --git a/index.php b/index.php index 89c24cac52f..105a04ad76e 100644 --- a/index.php +++ b/index.php @@ -24,9 +24,12 @@ require_once( 'lib/base.php' ); require_once( 'appconfig.php' ); require_once( 'template.php' ); -var_dump( $_SESSION ); -//exit; -if( OC_USER::isLoggedIn()){ + +// check if the server is correctly configured for ownCloud +$errors=OC_UTIL::checkServer(); +if(count($errors)>0){ + OC_TEMPLATE::printGuestPage( "", "error", array( "errors" => $errors )); +}elseif( OC_USER::isLoggedIn()){ if( $_GET["logout"] ){ OC_USER::logout(); header( "Location: $WEBROOT"); @@ -36,8 +39,7 @@ if( OC_USER::isLoggedIn()){ header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); exit(); } -} -else{ +}else{ if( OC_USER::login( $_POST["user"], $_POST["password"] )){ header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); exit(); diff --git a/lib/Group/database.php b/lib/Group/database.php index bdf5bbc5c55..e3e6c825b9f 100644 --- a/lib/Group/database.php +++ b/lib/Group/database.php @@ -119,7 +119,7 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { $groups = array(); while( $row = $result->fetchRow()){ - $groups[] = $row; + $groups[] = $row["gid"]; } return $groups; diff --git a/lib/base.php b/lib/base.php index 6b3ca59e6be..31d4142900f 100644 --- a/lib/base.php +++ b/lib/base.php @@ -89,13 +89,17 @@ require_once('connect.php'); require_once('remotestorage.php'); require_once('plugin.php'); -OC_PLUGIN::loadPlugins( "" ); +$error=(count(OC_UTIL::checkServer())>0); + +if(!$error){ + OC_PLUGIN::loadPlugins( "" ); +} OC_USER::setBackend( OC_CONFIG::getValue( "userbackend", "database" )); OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" )); // Set up file system unless forbidden -if( !$RUNTIME_NOSETUPFS ){ +if(!$error and !$RUNTIME_NOSETUPFS ){ OC_UTIL::setupFS(); } @@ -108,12 +112,10 @@ OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" ); OC_UTIL::addStyle( "styles" ); // Load Apps -if( !$RUNTIME_NOAPPS ){ +if(!$error and !$RUNTIME_NOAPPS ){ OC_APP::loadApps(); } -// check if the server is correctly configured for ownCloud -OC_UTIL::checkserver(); /** * Class for utility functions * @@ -221,7 +223,7 @@ class OC_UTIL { /** * check if the current server configuration is suitable for ownCloud - * + * @return array with error messages */ public static function checkServer(){ global $SERVERROOT; @@ -230,12 +232,16 @@ class OC_UTIL { $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );; $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" ); $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); - $error=''; + $errors=array(); + + //check for database drivers if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ - $error.='No database drivers (sqlite or mysql) installed.<br/>'; + $errors[]='No database drivers (sqlite or mysql) installed.<br/>'; } $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); + + //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ if($CONFIG_DBTYPE=='sqlite'){ $file=$SERVERROOT.'/'.$CONFIG_DBNAME; @@ -246,7 +252,7 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($file)),-3); if(substr($prems,2,1)!='0'){ - $error.='SQLite database file ('.$file.') is readable from the web<br/>'; + $errors[]='SQLite database file ('.$file.') is readable from the web<br/>'; } } } @@ -257,7 +263,7 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); if(substr($prems,2,1)!='0'){ - $error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>'; + $errors[]='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>'; } } if( OC_CONFIG::getValue( "enablebackup", false )){ @@ -267,16 +273,20 @@ class OC_UTIL { clearstatcache(); $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); if(substr($prems,2,1)!='0'){ - $error.='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>'; + $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>'; } } } }else{ //TODO: premisions checks for windows hosts } - if($error){ - die($error); + if(!is_writable($CONFIG_DATADIRECTORY_ROOT)){ + $errors[]='Data directory ('.$CONFIG_BACKUPDIRECTORY.') not writable by ownCloud<br/>'; } + + //TODO: check for php modules + + return $errors; } } diff --git a/lib/files.php b/lib/files.php index a1f983b6b2f..642a7e72049 100644 --- a/lib/files.php +++ b/lib/files.php @@ -64,6 +64,7 @@ class OC_FILES { $file['directory']=$directory; $stat=OC_FILESYSTEM::stat($directory.'/'.$filename); $file=array_merge($file,$stat); + $file['size']=OC_FILESYSTEM::filesize($directory.'/'.$filename); $file['mime']=OC_FILES::getMimeType($directory .'/'. $filename); $file['readable']=OC_FILESYSTEM::is_readable($directory .'/'. $filename); $file['writeable']=OC_FILESYSTEM::is_writeable($directory .'/'. $filename); diff --git a/lib/filestorage.php b/lib/filestorage.php index 68f232d3a60..e7fb9e9d270 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -124,7 +124,11 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ return $filetype; } 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){ return is_readable($this->datadir.$path); @@ -159,6 +163,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ public function file_put_contents($path,$data){ if($return=file_put_contents($this->datadir.$path,$data)){ $this->notifyObservers($path,OC_FILEACTION_WRITE); + $this->clearFolderSizeCache($path); } } public function unlink($path){ @@ -197,11 +202,13 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ case 'x+': case 'a+': $this->notifyObservers($path,OC_FILEACTION_READ | OC_FILEACTION_WRITE); + $this->clearFolderSizeCache($path); break; case 'w': case 'x': case 'a': $this->notifyObservers($path,OC_FILEACTION_WRITE); + $this->clearFolderSizeCache($path); break; } } @@ -440,5 +447,66 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } 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 diff --git a/templates/error.php b/templates/error.php new file mode 100644 index 00000000000..e8f56d63bd1 --- /dev/null +++ b/templates/error.php @@ -0,0 +1,15 @@ +<?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> + |