diff --git a/apps/user_ldap/group_ldap.php b/apps/user_ldap/group_ldap.php index 2c16bf312f..baca1d32ba 100644 --- a/apps/user_ldap/group_ldap.php +++ b/apps/user_ldap/group_ldap.php @@ -31,8 +31,8 @@ class OC_GROUP_LDAP extends OC_Group_Backend { $this->ldapGroupFilter = OCP\Config::getAppValue('user_ldap', 'ldap_group_filter', '(objectClass=posixGroup)'); $this->ldapGroupMemberAssocAttr = OCP\Config::getAppValue('user_ldap', 'ldap_group_member_assoc_attribute', 'uniqueMember'); - if(empty($this->ldapGroupFilter) || empty($this->ldapGroupMemberAssocAttr)) { - $this->configured = false; + if(!empty($this->ldapGroupFilter) && !empty($this->ldapGroupMemberAssocAttr)) { + $this->configured = true; } } diff --git a/lib/filecache.php b/lib/filecache.php index a94349e19c..a29e29928a 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -419,7 +419,7 @@ class OC_FileCache{ } return $result; }else{ - OC_Log::write('files','getChached(): file not found in cache ('.$path.')',OC_Log::DEBUG); + OC_Log::write('files','getCached(): file not found in cache ('.$path.')',OC_Log::DEBUG); if(isset(self::$savedData[$path])){ return self::$savedData[$path]; }else{ diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php index 0b7a231d30..5913d8b5b8 100644 --- a/lib/log/owncloud.php +++ b/lib/log/owncloud.php @@ -62,23 +62,26 @@ 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(); - } - $contents=file(self::$logFile); - if(!$contents) {//error while reading log - return array(); - } - $end=max(count($contents)-$offset-1, 0); - $start=max($end-$limit,0); - $i=$end; - while($i>$start){ - $entry=json_decode($contents[$i]); - if($entry->level>=$minLevel){ - $entries[]=$entry; + $entries = array(); + $handle = fopen(self::$logFile, 'r'); + if ($handle) { + // Just a guess to set the file pointer to the right spot + $maxLineLength = 150; + fseek($handle, -($limit * $maxLineLength + $offset * $maxLineLength), SEEK_END); + // Skip first line, because it is most likely a partial line + fgets($handle); + while (!feof($handle)) { + $line = fgets($handle); + if (!empty($line)) { + $entry = json_decode($line); + if ($entry->level >= $minLevel) { + $entries[] = $entry; + } + } } - $i--; + fclose($handle); + // Extract the needed entries and reverse the order + $entries = array_reverse(array_slice($entries, -($limit + $offset), $limit)); } return $entries; } diff --git a/lib/setup.php b/lib/setup.php index 8c2d523121..a096fdbb4c 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -94,6 +94,7 @@ class OC_Setup { 'error' => 'MySQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.' ); + return($error); } else { $oldUser=OC_Config::getValue('dbuser', false); diff --git a/lib/user.php b/lib/user.php index d7e9bf1a64..17c11322b8 100644 --- a/lib/user.php +++ b/lib/user.php @@ -21,7 +21,9 @@ */ /** - * This class provides all methods for user management. + * This class provides wrapper methods for user management. Multiple backends are + * supported. User management operations are delegated to the configured backend for + * execution. * * Hooks provided: * pre_createUser(&run, uid, password) @@ -240,7 +242,7 @@ class OC_User { * Checks if the user is logged in */ public static function isLoggedIn(){ - if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ){ + if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] AND self::userExists($_SESSION['user_id']) ){ return true; } else{ diff --git a/lib/user/backend.php b/lib/user/backend.php index 3df907226c..c31d4b5785 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -40,8 +40,10 @@ define('OC_USER_BACKEND_USER_EXISTS', 0x100000); /** - * abstract base class for user management - * subclass this for your own backends and see OC_User_Example for descriptions + * Abstract base class for user management. Provides methods for querying backend + * capabilities. + * + * Subclass this for your own backends, and see OC_User_Example for descriptions */ abstract class OC_User_Backend { diff --git a/lib/user/http.php b/lib/user/http.php new file mode 100644 index 0000000000..009aa30c6f --- /dev/null +++ b/lib/user/http.php @@ -0,0 +1,93 @@ +. +* +*/ + +/** + * user backend using http auth requests + */ +class OC_User_HTTP extends OC_User_Backend { + /** + * split http://user@host/path into a user and url part + * @param string path + * @return array + */ + private function parseUrl($url){ + $parts=parse_url($url); + $url=$parts['scheme'].'://'.$parts['host']; + if(isset($parts['port'])){ + $url.=':'.$parts['port']; + } + $url.=$parts['path']; + if(isset($parts['query'])){ + $url.='?'.$parts['query']; + } + return array($parts['user'],$url); + + } + + /** + * check if an url is a valid login + * @param string url + * @return boolean + */ + private function matchUrl($url){ + return ! is_null(parse_url($url,PHP_URL_USER)); + } + + /** + * @brief Check if the password is correct + * @param $uid The username + * @param $password The password + * @returns string + * + * Check if the password is correct without logging in the user + * returns the user id or false + */ + public function checkPassword($uid, $password){ + if(!$this->matchUrl($uid)){ + return false; + } + list($user,$url)=$this->parseUrl($uid); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + curl_exec($ch); + + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + return $status==200; + } + + /** + * @brief check if a user exists + * @param string $uid the username + * @return boolean + */ + public function userExists($uid){ + return $this->matchUrl($uid); + } +} \ No newline at end of file diff --git a/lib/util.php b/lib/util.php index be7fc00da8..fda60587b8 100644 --- a/lib/util.php +++ b/lib/util.php @@ -28,6 +28,14 @@ class OC_Util { exit; } + // Check if apps folder is writable. + if(!is_writable(OC::$SERVERROOT."/apps/")) { + $tmpl = new OC_Template( '', 'error', 'guest' ); + $tmpl->assign('errors',array(1=>array('error'=>"Can't write into apps directory 'apps'",'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); @@ -256,6 +264,9 @@ class OC_Util { if(floatval(phpversion())<5.3){ $errors[]=array('error'=>'PHP 5.3 is required.
','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.'); } + if(!defined('PDO::ATTR_DRIVER_NAME')){ + $errors[]=array('error'=>'PHP PDO module is not installed.
','hint'=>'Please ask your server administrator to install the module.'); + } return $errors; } diff --git a/settings/personal.php b/settings/personal.php index 41499657ac..64e08be89e 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -20,6 +20,7 @@ $rootInfo=OC_FileCache::get(''); $used=$rootInfo['size']; $free=OC_Filesystem::free_space(); $total=$free+$used; +if($total==0) $total=1; // prevent division by zero $relative=round(($used/$total)*10000)/100; $email=OC_Preferences::getValue(OC_User::getUser(), 'settings','email',''); diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php index 5dab5afb18..984249e84e 100644 --- a/tests/lib/user/backend.php +++ b/tests/lib/user/backend.php @@ -20,6 +20,16 @@ * */ +/** + * Abstract class to provide the basis of backend-specific unit test classes. + * + * All subclasses MUST assign a backend property in setUp() which implements + * user operations (add, remove, etc.). Test methods in this class will then be + * run on each separate subclass and backend therein. + * + * For an example see /tests/lib/user/dummy.php + */ + abstract class Test_User_Backend extends UnitTestCase { /** * @var OC_User_Backend $backend