diff options
author | Sam Tuke <samtuke@owncloud.com> | 2013-01-22 17:31:05 +0000 |
---|---|---|
committer | Sam Tuke <samtuke@owncloud.com> | 2013-01-22 17:31:05 +0000 |
commit | aa648fca75539448c1437092108e21d6a3dc542e (patch) | |
tree | fed53fd5a704ec7433d82dfb08e8d56d471ca4b3 /lib | |
parent | ca454f0228a9d915ac56ac41f65ee865a7141ddc (diff) | |
parent | dd40b691eee34d313a5894afbc7ccf217968fd94 (diff) | |
download | nextcloud-server-aa648fca75539448c1437092108e21d6a3dc542e.tar.gz nextcloud-server-aa648fca75539448c1437092108e21d6a3dc542e.zip |
Merge branch 'master' into files_encryption
Conflicts:
apps/files_encryption/templates/settings.php
Diffstat (limited to 'lib')
60 files changed, 984 insertions, 935 deletions
diff --git a/lib/MDB2/Driver/sqlite3.php b/lib/MDB2/Driver/sqlite3.php index 9839dafbce1..8f057cfb6e8 100644 --- a/lib/MDB2/Driver/sqlite3.php +++ b/lib/MDB2/Driver/sqlite3.php @@ -98,7 +98,7 @@ class MDB2_Driver_sqlite3 extends MDB2_Driver_Common if ($this->connection) { $native_code = $this->connection->lastErrorCode(); } - $native_msg = html_entity_decode($this->_lasterror); + $native_msg = html_entity_decode($this->_lasterror); // PHP 5.2+ prepends the function name to $php_errormsg, so we need // this hack to work around it, per bug #9599. diff --git a/lib/api.php b/lib/api.php index cb67e0c2a89..0fce109a423 100644 --- a/lib/api.php +++ b/lib/api.php @@ -42,12 +42,12 @@ class OC_API { private static function init() { self::$server = new OC_OAuth_Server(new OC_OAuth_Store()); } - + /** * api actions */ protected static $actions = array(); - + /** * registers an api call * @param string $method the http method @@ -58,7 +58,7 @@ class OC_API { * @param array $defaults * @param array $requirements */ - public static function register($method, $url, $action, $app, + public static function register($method, $url, $action, $app, $authLevel = OC_API::USER_AUTH, $defaults = array(), $requirements = array()) { @@ -73,7 +73,7 @@ class OC_API { } self::$actions[$name] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel); } - + /** * handles an api call * @param array $parameters @@ -92,8 +92,10 @@ class OC_API { $response = call_user_func(self::$actions[$name]['action'], $parameters); } else { $response = new OC_OCS_Result(null, 998, 'Api method not found'); - } + } } else { + header('WWW-Authenticate: Basic realm="Authorization Required"'); + header('HTTP/1.0 401 Unauthorized'); $response = new OC_OCS_Result(null, 997, 'Unauthorised'); } // Send the response @@ -103,7 +105,7 @@ class OC_API { // logout the user to be stateless OC_User::logout(); } - + /** * authenticate the api call * @param array $action the action details as supplied to OC_API::register() @@ -127,8 +129,7 @@ class OC_API { return false; } else { $subAdmin = OC_SubAdmin::isSubAdmin($user); - $admin = OC_Group::inGroup($user, 'admin'); - if($subAdmin || $admin) { + if($subAdmin) { return true; } else { return false; @@ -141,7 +142,7 @@ class OC_API { if(!$user) { return false; } else { - return OC_Group::inGroup($user, 'admin'); + return OC_User::isAdminUser($user); } break; default: @@ -149,18 +150,18 @@ class OC_API { return false; break; } - } - + } + /** * http basic auth * @return string|false (username, or false on failure) */ - private static function loginUser(){ + private static function loginUser(){ $authUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : ''; $authPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; return OC_User::login($authUser, $authPw) ? $authUser : false; } - + /** * respond to a call * @param int|array $result the result from the api method @@ -196,5 +197,5 @@ class OC_API { } } } - + } diff --git a/lib/app.php b/lib/app.php index e60bce2a201..662af56d258 100644 --- a/lib/app.php +++ b/lib/app.php @@ -137,7 +137,7 @@ class OC_App{ OC_Appconfig::setValue($app, 'types', $appTypes); } - + /** * check if app is shipped * @param string $appid the id of the app to check @@ -313,14 +313,14 @@ class OC_App{ $settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkToRoute( "settings_settings" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" )); //SubAdmins are also allowed to access user management - if(OC_SubAdmin::isSubAdmin($_SESSION["user_id"]) || OC_Group::inGroup( $_SESSION["user_id"], "admin" )) { + if(OC_SubAdmin::isSubAdmin(OC_User::getUser())) { // admin users menu $settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkToRoute( "settings_users" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" )); } // if the user is an admin - if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) { + if(OC_User::isAdminUser(OC_User::getUser())) { // admin apps menu $settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkToRoute( "settings_apps" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" )); @@ -748,7 +748,7 @@ class OC_App{ } 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); + OC_Log::write('core', 'Can\'t get app storage, app '.$appid.', user not logged in', OC_Log::ERROR); return false; } }else{ diff --git a/lib/backgroundjob.php b/lib/backgroundjob.php index 28b5ce3af20..9619dcb732c 100644 --- a/lib/backgroundjob.php +++ b/lib/backgroundjob.php @@ -34,7 +34,7 @@ class OC_BackgroundJob{ public static function getExecutionType() { return OC_Appconfig::getValue( 'core', 'backgroundjobs_mode', 'ajax' ); } - + /** * @brief sets the background jobs execution type * @param $type execution type diff --git a/lib/base.php b/lib/base.php index 3d3e7d59f90..4b198c4f784 100644 --- a/lib/base.php +++ b/lib/base.php @@ -29,169 +29,169 @@ require_once 'public/constants.php'; */ class OC { - /** - * Assoziative array for autoloading. classname => filename - */ - public static $CLASSPATH = array(); - /** - * The installation path for owncloud on the server (e.g. /srv/http/owncloud) - */ - public static $SERVERROOT = ''; - /** - * the current request path relative to the owncloud root (e.g. files/index.php) - */ - private static $SUBURI = ''; - /** - * the owncloud root path for http requests (e.g. owncloud/) - */ - public static $WEBROOT = ''; - /** - * The installation path of the 3rdparty folder on the server (e.g. /srv/http/owncloud/3rdparty) - */ - public static $THIRDPARTYROOT = ''; - /** - * the root path of the 3rdparty folder for http requests (e.g. owncloud/3rdparty) - */ - public static $THIRDPARTYWEBROOT = ''; - /** - * The installation path array of the apps folder on the server (e.g. /srv/http/owncloud) 'path' and - * web path in 'url' - */ - public static $APPSROOTS = array(); - /* - * requested app - */ - public static $REQUESTEDAPP = ''; - /* - * requested file of app - */ - public static $REQUESTEDFILE = ''; - /** - * check if owncloud runs in cli mode - */ - public static $CLI = false; - /* - * OC router - */ - protected static $router = null; - - /** - * SPL autoload - */ - public static function autoload($className) - { - if (array_key_exists($className, OC::$CLASSPATH)) { - $path = OC::$CLASSPATH[$className]; - /** @TODO: Remove this when necessary - Remove "apps/" from inclusion path for smooth migration to mutli app dir - */ - if (strpos($path, 'apps/') === 0) { - OC_Log::write('core', 'include path for class "' . $className . '" starts with "apps/"', OC_Log::DEBUG); - $path = str_replace('apps/', '', $path); - } - } elseif (strpos($className, 'OC_') === 0) { - $path = strtolower(str_replace('_', '/', substr($className, 3)) . '.php'); - } elseif (strpos($className, 'OC\\') === 0) { - $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); - } elseif (strpos($className, 'OCP\\') === 0) { - $path = 'public/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); - } elseif (strpos($className, 'OCA\\') === 0) { - $path = 'apps/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); - } elseif (strpos($className, 'Sabre_') === 0) { - $path = str_replace('_', '/', $className) . '.php'; - } elseif (strpos($className, 'Symfony\\Component\\Routing\\') === 0) { - $path = 'symfony/routing/' . str_replace('\\', '/', $className) . '.php'; - } elseif (strpos($className, 'Sabre\\VObject') === 0) { - $path = str_replace('\\', '/', $className) . '.php'; - } elseif (strpos($className, 'Test_') === 0) { - $path = 'tests/lib/' . strtolower(str_replace('_', '/', substr($className, 5)) . '.php'); - } else { - return false; - } - - if ($fullPath = stream_resolve_include_path($path)) { - require_once $fullPath; - } - return false; - } - - public static function initPaths() - { - // calculate the root directories - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); - $scriptName = $_SERVER["SCRIPT_NAME"]; - if (substr($scriptName, -1) == '/') { - $scriptName .= 'index.php'; - //make sure suburi follows the same rules as scriptName - if (substr(OC::$SUBURI, -9) != 'index.php') { - if (substr(OC::$SUBURI, -1) != '/') { - OC::$SUBURI = OC::$SUBURI . '/'; - } - OC::$SUBURI = OC::$SUBURI . 'index.php'; - } - } - - OC::$WEBROOT = substr($scriptName, 0, strlen($scriptName) - strlen(OC::$SUBURI)); - - if (OC::$WEBROOT != '' and OC::$WEBROOT[0] !== '/') { - OC::$WEBROOT = '/' . OC::$WEBROOT; - } - - // ensure we can find OC_Config - set_include_path( - OC::$SERVERROOT . '/lib' . PATH_SEPARATOR . - get_include_path() - ); - - // search the 3rdparty folder - if (OC_Config::getValue('3rdpartyroot', '') <> '' and OC_Config::getValue('3rdpartyurl', '') <> '') { - OC::$THIRDPARTYROOT = OC_Config::getValue('3rdpartyroot', ''); - OC::$THIRDPARTYWEBROOT = OC_Config::getValue('3rdpartyurl', ''); - } elseif (file_exists(OC::$SERVERROOT . '/3rdparty')) { - OC::$THIRDPARTYROOT = OC::$SERVERROOT; - OC::$THIRDPARTYWEBROOT = OC::$WEBROOT; - } elseif (file_exists(OC::$SERVERROOT . '/../3rdparty')) { - OC::$THIRDPARTYWEBROOT = rtrim(dirname(OC::$WEBROOT), '/'); - OC::$THIRDPARTYROOT = rtrim(dirname(OC::$SERVERROOT), '/'); - } else { - echo("3rdparty directory not found! Please put the ownCloud 3rdparty folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file."); - exit; - } - // search the apps folder - $config_paths = OC_Config::getValue('apps_paths', array()); - if (!empty($config_paths)) { - foreach ($config_paths as $paths) { - if (isset($paths['url']) && isset($paths['path'])) { - $paths['url'] = rtrim($paths['url'], '/'); - $paths['path'] = rtrim($paths['path'], '/'); - OC::$APPSROOTS[] = $paths; - } - } - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { - OC::$APPSROOTS[] = array('path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', 'url' => '/apps', 'writable' => true); - } - - if (empty(OC::$APPSROOTS)) { - 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; - } - $paths = array(); - foreach (OC::$APPSROOTS as $path) - $paths[] = $path['path']; - - // set the right include path - set_include_path( - OC::$SERVERROOT . '/lib' . PATH_SEPARATOR . - OC::$SERVERROOT . '/config' . PATH_SEPARATOR . - OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR . - implode($paths, PATH_SEPARATOR) . PATH_SEPARATOR . - get_include_path() . PATH_SEPARATOR . - OC::$SERVERROOT - ); - } + /** + * Associative array for autoloading. classname => filename + */ + public static $CLASSPATH = array(); + /** + * The installation path for owncloud on the server (e.g. /srv/http/owncloud) + */ + public static $SERVERROOT = ''; + /** + * the current request path relative to the owncloud root (e.g. files/index.php) + */ + private static $SUBURI = ''; + /** + * the owncloud root path for http requests (e.g. owncloud/) + */ + public static $WEBROOT = ''; + /** + * The installation path of the 3rdparty folder on the server (e.g. /srv/http/owncloud/3rdparty) + */ + public static $THIRDPARTYROOT = ''; + /** + * the root path of the 3rdparty folder for http requests (e.g. owncloud/3rdparty) + */ + public static $THIRDPARTYWEBROOT = ''; + /** + * The installation path array of the apps folder on the server (e.g. /srv/http/owncloud) 'path' and + * web path in 'url' + */ + public static $APPSROOTS = array(); + /* + * requested app + */ + public static $REQUESTEDAPP = ''; + /* + * requested file of app + */ + public static $REQUESTEDFILE = ''; + /** + * check if owncloud runs in cli mode + */ + public static $CLI = false; + /* + * OC router + */ + protected static $router = null; + + /** + * SPL autoload + */ + public static function autoload($className) + { + if (array_key_exists($className, OC::$CLASSPATH)) { + $path = OC::$CLASSPATH[$className]; + /** @TODO: Remove this when necessary + Remove "apps/" from inclusion path for smooth migration to mutli app dir + */ + if (strpos($path, 'apps/') === 0) { + OC_Log::write('core', 'include path for class "' . $className . '" starts with "apps/"', OC_Log::DEBUG); + $path = str_replace('apps/', '', $path); + } + } elseif (strpos($className, 'OC_') === 0) { + $path = strtolower(str_replace('_', '/', substr($className, 3)) . '.php'); + } elseif (strpos($className, 'OC\\') === 0) { + $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); + } elseif (strpos($className, 'OCP\\') === 0) { + $path = 'public/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); + } elseif (strpos($className, 'OCA\\') === 0) { + $path = 'apps/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); + } elseif (strpos($className, 'Sabre_') === 0) { + $path = str_replace('_', '/', $className) . '.php'; + } elseif (strpos($className, 'Symfony\\Component\\Routing\\') === 0) { + $path = 'symfony/routing/' . str_replace('\\', '/', $className) . '.php'; + } elseif (strpos($className, 'Sabre\\VObject') === 0) { + $path = str_replace('\\', '/', $className) . '.php'; + } elseif (strpos($className, 'Test_') === 0) { + $path = 'tests/lib/' . strtolower(str_replace('_', '/', substr($className, 5)) . '.php'); + } else { + return false; + } + + if ($fullPath = stream_resolve_include_path($path)) { + require_once $fullPath; + } + return false; + } + + public static function initPaths() + { + // calculate the root directories + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); + $scriptName = $_SERVER["SCRIPT_NAME"]; + if (substr($scriptName, -1) == '/') { + $scriptName .= 'index.php'; + //make sure suburi follows the same rules as scriptName + if (substr(OC::$SUBURI, -9) != 'index.php') { + if (substr(OC::$SUBURI, -1) != '/') { + OC::$SUBURI = OC::$SUBURI . '/'; + } + OC::$SUBURI = OC::$SUBURI . 'index.php'; + } + } + + OC::$WEBROOT = substr($scriptName, 0, strlen($scriptName) - strlen(OC::$SUBURI)); + + if (OC::$WEBROOT != '' and OC::$WEBROOT[0] !== '/') { + OC::$WEBROOT = '/' . OC::$WEBROOT; + } + + // ensure we can find OC_Config + set_include_path( + OC::$SERVERROOT . '/lib' . PATH_SEPARATOR . + get_include_path() + ); + + // search the 3rdparty folder + if (OC_Config::getValue('3rdpartyroot', '') <> '' and OC_Config::getValue('3rdpartyurl', '') <> '') { + OC::$THIRDPARTYROOT = OC_Config::getValue('3rdpartyroot', ''); + OC::$THIRDPARTYWEBROOT = OC_Config::getValue('3rdpartyurl', ''); + } elseif (file_exists(OC::$SERVERROOT . '/3rdparty')) { + OC::$THIRDPARTYROOT = OC::$SERVERROOT; + OC::$THIRDPARTYWEBROOT = OC::$WEBROOT; + } elseif (file_exists(OC::$SERVERROOT . '/../3rdparty')) { + OC::$THIRDPARTYWEBROOT = rtrim(dirname(OC::$WEBROOT), '/'); + OC::$THIRDPARTYROOT = rtrim(dirname(OC::$SERVERROOT), '/'); + } else { + echo("3rdparty directory not found! Please put the ownCloud 3rdparty folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file."); + exit; + } + // search the apps folder + $config_paths = OC_Config::getValue('apps_paths', array()); + if (!empty($config_paths)) { + foreach ($config_paths as $paths) { + if (isset($paths['url']) && isset($paths['path'])) { + $paths['url'] = rtrim($paths['url'], '/'); + $paths['path'] = rtrim($paths['path'], '/'); + OC::$APPSROOTS[] = $paths; + } + } + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { + OC::$APPSROOTS[] = array('path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', 'url' => '/apps', 'writable' => true); + } + + if (empty(OC::$APPSROOTS)) { + 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; + } + $paths = array(); + foreach (OC::$APPSROOTS as $path) + $paths[] = $path['path']; + + // set the right include path + set_include_path( + OC::$SERVERROOT . '/lib' . PATH_SEPARATOR . + OC::$SERVERROOT . '/config' . PATH_SEPARATOR . + OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR . + implode($paths, PATH_SEPARATOR) . PATH_SEPARATOR . + get_include_path() . PATH_SEPARATOR . + OC::$SERVERROOT + ); + } public static function checkConfig() { if (file_exists(OC::$SERVERROOT . "/config/config.php") and !is_writable(OC::$SERVERROOT . "/config/config.php")) { @@ -202,35 +202,41 @@ class OC } } - public static function checkInstalled() - { - // Redirect to installer if not installed - if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') { - if (!OC::$CLI) { - $url = 'http://' . $_SERVER['SERVER_NAME'] . OC::$WEBROOT . '/index.php'; - header("Location: $url"); - } - exit(); - } - } - - public static function checkSSL() - { - // redirect to https site if configured - if (OC_Config::getValue("forcessl", false)) { - header('Strict-Transport-Security: max-age=31536000'); - ini_set("session.cookie_secure", "on"); - if (OC_Request::serverProtocol() <> 'https' and !OC::$CLI) { - $url = "https://" . OC_Request::serverHost() . $_SERVER['REQUEST_URI']; - header("Location: $url"); - exit(); - } - } - } + public static function checkInstalled() + { + // Redirect to installer if not installed + if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') { + if (!OC::$CLI) { + $url = 'http://' . $_SERVER['SERVER_NAME'] . OC::$WEBROOT . '/index.php'; + header("Location: $url"); + } + exit(); + } + } + + public static function checkSSL() + { + // redirect to https site if configured + if (OC_Config::getValue("forcessl", false)) { + header('Strict-Transport-Security: max-age=31536000'); + ini_set("session.cookie_secure", "on"); + if (OC_Request::serverProtocol() <> 'https' and !OC::$CLI) { + $url = "https://" . OC_Request::serverHost() . $_SERVER['REQUEST_URI']; + header("Location: $url"); + exit(); + } + } + } public static function checkMaintenanceMode() { // Allow ajax update script to execute without being stopped if (OC_Config::getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { + // send http status 503 + header('HTTP/1.1 503 Service Temporarily Unavailable'); + header('Status: 503 Service Temporarily Unavailable'); + header('Retry-After: 120'); + + // render error page $tmpl = new OC_Template('', 'error', 'guest'); $tmpl->assign('errors', array(1 => array('error' => 'ownCloud is in maintenance mode'))); $tmpl->printPage(); @@ -258,504 +264,521 @@ class OC } } - public static function initTemplateEngine() - { - // Add the stuff we need always - OC_Util::addScript("jquery-1.7.2.min"); - OC_Util::addScript("jquery-ui-1.8.16.custom.min"); - OC_Util::addScript("jquery-showpassword"); - OC_Util::addScript("jquery.infieldlabel"); - OC_Util::addScript("jquery-tipsy"); - OC_Util::addScript("oc-dialogs"); - OC_Util::addScript("js"); - OC_Util::addScript("eventsource"); - OC_Util::addScript("config"); - //OC_Util::addScript( "multiselect" ); - OC_Util::addScript('search', 'result'); - OC_Util::addScript('router'); - - OC_Util::addStyle("styles"); - OC_Util::addStyle("multiselect"); - OC_Util::addStyle("jquery-ui-1.8.16.custom"); - OC_Util::addStyle("jquery-tipsy"); - } - - public static function initSession() - { - // prevents javascript from accessing php session cookies - ini_set('session.cookie_httponly', '1;'); - - // set the session name to the instance id - which is unique - session_name(OC_Util::getInstanceId()); - - // (re)-initialize session - session_start(); - - // regenerate session id periodically to avoid session fixation - if (!isset($_SESSION['SID_CREATED'])) { - $_SESSION['SID_CREATED'] = time(); - } else if (time() - $_SESSION['SID_CREATED'] > 900) { - session_regenerate_id(true); - $_SESSION['SID_CREATED'] = time(); - } - - // session timeout - if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 3600)) { - if (isset($_COOKIE[session_name()])) { - setcookie(session_name(), '', time() - 42000, '/'); - } - session_unset(); - session_destroy(); - session_start(); - } - $_SESSION['LAST_ACTIVITY'] = time(); - } - - public static function getRouter() - { - if (!isset(OC::$router)) { - OC::$router = new OC_Router(); - OC::$router->loadRoutes(); - } - - return OC::$router; - } - - public static function init() - { - // register autoloader - spl_autoload_register(array('OC', 'autoload')); - setlocale(LC_ALL, 'en_US.UTF-8'); - - // set some stuff - //ob_start(); - error_reporting(E_ALL | E_STRICT); - if (defined('DEBUG') && DEBUG) { - ini_set('display_errors', 1); - } - self::$CLI = (php_sapi_name() == 'cli'); - - date_default_timezone_set('UTC'); - ini_set('arg_separator.output', '&'); - - // try to switch magic quotes off. - if (get_magic_quotes_gpc()) { - @set_magic_quotes_runtime(false); - } - - //try to configure php to enable big file uploads. - //this doesn´t work always depending on the webserver and php configuration. - //Let´s try to overwrite some defaults anyways - - //try to set the maximum execution time to 60min - @set_time_limit(3600); - @ini_set('max_execution_time', 3600); - @ini_set('max_input_time', 3600); - - //try to set the maximum filesize to 10G - @ini_set('upload_max_filesize', '10G'); - @ini_set('post_max_size', '10G'); - @ini_set('file_uploads', '50'); - - //try to set the session lifetime to 60min - @ini_set('gc_maxlifetime', '3600'); - - //copy http auth headers for apache+php-fcgid work around - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; - } - - //set http auth headers for apache+php-cgi work around - if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) { - list($name, $password) = explode(':', base64_decode($matches[1]), 2); - $_SERVER['PHP_AUTH_USER'] = strip_tags($name); - $_SERVER['PHP_AUTH_PW'] = strip_tags($password); - } - - //set http auth headers for apache+php-cgi work around if variable gets renamed by apache - if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) { - list($name, $password) = explode(':', base64_decode($matches[1]), 2); - $_SERVER['PHP_AUTH_USER'] = strip_tags($name); - $_SERVER['PHP_AUTH_PW'] = strip_tags($password); - } - - self::initPaths(); - - register_shutdown_function(array('OC_Log', 'onShutdown')); - set_error_handler(array('OC_Log', 'onError')); - set_exception_handler(array('OC_Log', 'onException')); - - // set debug mode if an xdebug session is active - if (!defined('DEBUG') || !DEBUG) { - if (isset($_COOKIE['XDEBUG_SESSION'])) { - define('DEBUG', true); - } - } - - // register the stream wrappers - require_once 'streamwrappers.php'; - stream_wrapper_register("fakedir", "OC_FakeDirStream"); - stream_wrapper_register('static', 'OC_StaticStreamWrapper'); - stream_wrapper_register('close', 'OC_CloseStreamWrapper'); - - self::checkConfig(); - self::checkInstalled(); - self::checkSSL(); - self::initSession(); - self::initTemplateEngine(); - self::checkMaintenanceMode(); - self::checkUpgrade(); - - $errors = OC_Util::checkServer(); - if (count($errors) > 0) { - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); - exit; - } - - // User and Groups - if (!OC_Config::getValue("installed", false)) { - $_SESSION['user_id'] = ''; - } - - OC_User::useBackend(new OC_User_Database()); - OC_Group::useBackend(new OC_Group_Database()); - - if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SESSION['user_id']) && $_SERVER['PHP_AUTH_USER'] != $_SESSION['user_id']) { - OC_User::logout(); - } - - // Load Apps - // This includes plugins for users and filesystems as well - global $RUNTIME_NOAPPS; - global $RUNTIME_APPTYPES; - if (!$RUNTIME_NOAPPS) { - if ($RUNTIME_APPTYPES) { - OC_App::loadApps($RUNTIME_APPTYPES); - } else { - OC_App::loadApps(); - } - } - - //setup extra user backends - OC_User::setupBackends(); - - self::registerCacheHooks(); - self::registerFilesystemHooks(); - self::registerShareHooks(); - - //make sure temporary files are cleaned up - register_shutdown_function(array('OC_Helper', 'cleanTmp')); - - //parse the given parameters - self::$REQUESTEDAPP = (isset($_GET['app']) && trim($_GET['app']) != '' && !is_null($_GET['app']) ? str_replace(array('\0', '/', '\\', '..'), '', strip_tags($_GET['app'])) : OC_Config::getValue('defaultapp', 'files')); - if (substr_count(self::$REQUESTEDAPP, '?') != 0) { - $app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?')); - $param = substr($_GET['app'], strpos($_GET['app'], '?') + 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_App::getAppPath(OC::$REQUESTEDAPP) . '/' . self::$REQUESTEDFILE; - $parent = OC_App::getAppPath(OC::$REQUESTEDAPP); - if (!OC_Helper::issubdirectory($subdir, $parent)) { - self::$REQUESTEDFILE = null; - header('HTTP/1.0 404 Not Found'); - exit; - } - } - - // write error into log if locale can't be set - if (OC_Util::issetlocaleworking() == false) { - OC_Log::write('core', 'setting locate to en_US.UTF-8 failed. Support is probably not installed on your system', OC_Log::ERROR); - } - if (OC_Config::getValue('installed', false)) { - if (OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') { - OC_Util::addScript('backgroundjobs'); + public static function initTemplateEngine() + { + // Add the stuff we need always + OC_Util::addScript("jquery-1.7.2.min"); + OC_Util::addScript("jquery-ui-1.8.16.custom.min"); + OC_Util::addScript("jquery-showpassword"); + OC_Util::addScript("jquery.infieldlabel"); + OC_Util::addScript("jquery-tipsy"); + OC_Util::addScript("oc-dialogs"); + OC_Util::addScript("js"); + OC_Util::addScript("eventsource"); + OC_Util::addScript("config"); + //OC_Util::addScript( "multiselect" ); + OC_Util::addScript('search', 'result'); + OC_Util::addScript('router'); + + OC_Util::addStyle("styles"); + OC_Util::addStyle("multiselect"); + OC_Util::addStyle("jquery-ui-1.8.16.custom"); + OC_Util::addStyle("jquery-tipsy"); + } + + public static function initSession() + { + // prevents javascript from accessing php session cookies + ini_set('session.cookie_httponly', '1;'); + + // set the session name to the instance id - which is unique + session_name(OC_Util::getInstanceId()); + + // (re)-initialize session + session_start(); + + // regenerate session id periodically to avoid session fixation + if (!isset($_SESSION['SID_CREATED'])) { + $_SESSION['SID_CREATED'] = time(); + } else if (time() - $_SESSION['SID_CREATED'] > 900) { + session_regenerate_id(true); + $_SESSION['SID_CREATED'] = time(); + } + + // session timeout + if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 3600)) { + if (isset($_COOKIE[session_name()])) { + setcookie(session_name(), '', time() - 42000, '/'); + } + session_unset(); + session_destroy(); + session_start(); + } + $_SESSION['LAST_ACTIVITY'] = time(); + } + + public static function getRouter() + { + if (!isset(OC::$router)) { + OC::$router = new OC_Router(); + OC::$router->loadRoutes(); + } + + return OC::$router; + } + + + public static function loadAppClassPaths() + { + foreach(OC_APP::getEnabledApps() as $app) { + $file = OC_App::getAppPath($app).'/appinfo/classpath.php'; + if(file_exists($file)) { + require_once $file; + } } } - } - - /** - * register hooks for the cache - */ - public static function registerCacheHooks() - { - // register cache cleanup jobs - OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc'); - OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener'); - } - - /** - * register hooks for the filesystem - */ - public static function registerFilesystemHooks() - { - // Check for blacklisted files - OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted'); - OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted'); - } - - /** - * register hooks for sharing - */ - public static function registerShareHooks() - { - OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\Share', 'post_deleteUser'); - OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\Share', 'post_addToGroup'); - OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\Share', 'post_removeFromGroup'); - OC_Hook::connect('OC_User', 'post_deleteGroup', 'OCP\Share', 'post_deleteGroup'); - } - - /** - * @brief Handle the request - */ - public static function handleRequest() - { - if (!OC_Config::getValue('installed', false)) { - require_once 'core/setup.php'; - exit(); - } - // Handle redirect URL for logged in users - if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) { - $location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url'])); - header('Location: ' . $location); - return; - } - // Handle WebDAV - if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { - header('location: ' . OC_Helper::linkToRemote('webdav')); - return; - } - try { - OC::getRouter()->match(OC_Request::getPathInfo()); - return; - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { - //header('HTTP/1.0 404 Not Found'); - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { - OC_Response::setStatus(405); - return; - } - $app = OC::$REQUESTEDAPP; - $file = OC::$REQUESTEDFILE; - $param = array('app' => $app, 'file' => $file); - // Handle app css files - if (substr($file, -3) == 'css') { - self::loadCSSFile($param); - return; - } - // Someone is logged in : - if (OC_User::isLoggedIn()) { - OC_App::loadApps(); - OC_User::setupBackends(); - if (isset($_GET["logout"]) and ($_GET["logout"])) { - if (isset($_COOKIE['oc_token'])) { - OC_Preferences::deleteKey(OC_User::getUser(), 'login_token', $_COOKIE['oc_token']); - } - OC_User::logout(); - header("Location: " . OC::$WEBROOT . '/'); - } else { - if (is_null($file)) { - $param['file'] = 'index.php'; - } - $file_ext = substr($param['file'], -3); - if ($file_ext != 'php' - || !self::loadAppScriptFile($param) - ) { - header('HTTP/1.0 404 Not Found'); - } - } - return; - } - // Not handled and not logged in - self::handleLogin(); - } - - public static function loadAppScriptFile($param) - { - OC_App::loadApps(); - $app = $param['app']; - $file = $param['file']; - $app_path = OC_App::getAppPath($app); - $file = $app_path . '/' . $file; - unset($app, $app_path); - if (file_exists($file)) { - require_once $file; - return true; - } - return false; - } - - public static function loadCSSFile($param) - { - $app = $param['app']; - $file = $param['file']; - $app_path = OC_App::getAppPath($app); - if (file_exists($app_path . '/' . $file)) { - $app_web_path = OC_App::getAppWebPath($app); - $filepath = $app_web_path . '/' . $file; - $minimizer = new OC_Minimizer_CSS(); - $info = array($app_path, $app_web_path, $file); - $minimizer->output(array($info), $filepath); - } - } - - protected static function handleLogin() - { - OC_App::loadApps(array('prelogin')); - $error = array(); - // remember was checked after last login - if (OC::tryRememberLogin()) { - $error[] = 'invalidcookie'; - - // Someone wants to log in : - } elseif (OC::tryFormLogin()) { - $error[] = 'invalidpassword'; - - // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP - } elseif (OC::tryBasicAuthLogin()) { - $error[] = 'invalidpassword'; - } - OC_Util::displayLoginPage(array_unique($error)); - } - - protected static function cleanupLoginTokens($user) - { - $cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); - $tokens = OC_Preferences::getKeys($user, 'login_token'); - foreach ($tokens as $token) { - $time = OC_Preferences::getValue($user, 'login_token', $token); - if ($time < $cutoff) { - OC_Preferences::deleteKey($user, 'login_token', $token); - } - } - } - - protected static function tryRememberLogin() - { - if (!isset($_COOKIE["oc_remember_login"]) - || !isset($_COOKIE["oc_token"]) - || !isset($_COOKIE["oc_username"]) - || !$_COOKIE["oc_remember_login"] - ) { - return false; - } - OC_App::loadApps(array('authentication')); - if (defined("DEBUG") && DEBUG) { - OC_Log::write('core', 'Trying to login from cookie', OC_Log::DEBUG); - } - // confirm credentials in cookie - if (isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username'])) { - // delete outdated cookies - self::cleanupLoginTokens($_COOKIE['oc_username']); - // get stored tokens - $tokens = OC_Preferences::getKeys($_COOKIE['oc_username'], 'login_token'); - // test cookies token against stored tokens - if (in_array($_COOKIE['oc_token'], $tokens, true)) { - // replace successfully used token with a new one - OC_Preferences::deleteKey($_COOKIE['oc_username'], 'login_token', $_COOKIE['oc_token']); - $token = OC_Util::generate_random_bytes(32); - OC_Preferences::setValue($_COOKIE['oc_username'], 'login_token', $token, time()); - OC_User::setMagicInCookie($_COOKIE['oc_username'], $token); - // login - OC_User::setUserId($_COOKIE['oc_username']); - OC_Util::redirectToDefaultPage(); - // doesn't return - } - // if you reach this point you have changed your password - // or you are an attacker - // we can not delete tokens here because users may reach - // this point multiple times after a password change - OC_Log::write('core', 'Authentication cookie rejected for user ' . $_COOKIE['oc_username'], OC_Log::WARN); - } - OC_User::unsetMagicInCookie(); - return true; - } - - protected static function tryFormLogin() - { - if (!isset($_POST["user"]) || !isset($_POST['password'])) { - return false; - } - - OC_App::loadApps(); - - //setup extra user backends - OC_User::setupBackends(); - - if (OC_User::login($_POST["user"], $_POST["password"])) { - // setting up the time zone - if (isset($_POST['timezone-offset'])) { - $_SESSION['timezone'] = $_POST['timezone-offset']; - } - - self::cleanupLoginTokens($_POST['user']); - if (!empty($_POST["remember_login"])) { - if (defined("DEBUG") && DEBUG) { - OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG); - } - $token = OC_Util::generate_random_bytes(32); - OC_Preferences::setValue($_POST['user'], 'login_token', $token, time()); - OC_User::setMagicInCookie($_POST["user"], $token); - } else { - OC_User::unsetMagicInCookie(); - } - OC_Util::redirectToDefaultPage(); - exit(); - } - return true; - } - - protected static function tryBasicAuthLogin() - { - if (!isset($_SERVER["PHP_AUTH_USER"]) - || !isset($_SERVER["PHP_AUTH_PW"]) - ) { - return false; - } - OC_App::loadApps(array('authentication')); - if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) { - //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG); - OC_User::unsetMagicInCookie(); - $_REQUEST['redirect_url'] = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''); - OC_Util::redirectToDefaultPage(); - } - return true; - } + + + public static function init() + { + // register autoloader + spl_autoload_register(array('OC', 'autoload')); + setlocale(LC_ALL, 'en_US.UTF-8'); + + // set some stuff + //ob_start(); + error_reporting(E_ALL | E_STRICT); + if (defined('DEBUG') && DEBUG) { + ini_set('display_errors', 1); + } + self::$CLI = (php_sapi_name() == 'cli'); + + date_default_timezone_set('UTC'); + ini_set('arg_separator.output', '&'); + + // try to switch magic quotes off. + if (get_magic_quotes_gpc()) { + @set_magic_quotes_runtime(false); + } + + //try to configure php to enable big file uploads. + //this doesn´t work always depending on the webserver and php configuration. + //Let´s try to overwrite some defaults anyways + + //try to set the maximum execution time to 60min + @set_time_limit(3600); + @ini_set('max_execution_time', 3600); + @ini_set('max_input_time', 3600); + + //try to set the maximum filesize to 10G + @ini_set('upload_max_filesize', '10G'); + @ini_set('post_max_size', '10G'); + @ini_set('file_uploads', '50'); + + //try to set the session lifetime to 60min + @ini_set('gc_maxlifetime', '3600'); + + //copy http auth headers for apache+php-fcgid work around + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; + } + + //set http auth headers for apache+php-cgi work around + if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) { + list($name, $password) = explode(':', base64_decode($matches[1]), 2); + $_SERVER['PHP_AUTH_USER'] = strip_tags($name); + $_SERVER['PHP_AUTH_PW'] = strip_tags($password); + } + + //set http auth headers for apache+php-cgi work around if variable gets renamed by apache + if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) { + list($name, $password) = explode(':', base64_decode($matches[1]), 2); + $_SERVER['PHP_AUTH_USER'] = strip_tags($name); + $_SERVER['PHP_AUTH_PW'] = strip_tags($password); + } + + self::initPaths(); + + register_shutdown_function(array('OC_Log', 'onShutdown')); + set_error_handler(array('OC_Log', 'onError')); + set_exception_handler(array('OC_Log', 'onException')); + + // set debug mode if an xdebug session is active + if (!defined('DEBUG') || !DEBUG) { + if (isset($_COOKIE['XDEBUG_SESSION'])) { + define('DEBUG', true); + } + } + + // register the stream wrappers + require_once 'streamwrappers.php'; + stream_wrapper_register("fakedir", "OC_FakeDirStream"); + stream_wrapper_register('static', 'OC_StaticStreamWrapper'); + stream_wrapper_register('close', 'OC_CloseStreamWrapper'); + + self::checkConfig(); + self::checkInstalled(); + self::checkSSL(); + self::initSession(); + self::initTemplateEngine(); + self::checkMaintenanceMode(); + self::checkUpgrade(); + + $errors = OC_Util::checkServer(); + if (count($errors) > 0) { + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); + exit; + } + + // User and Groups + if (!OC_Config::getValue("installed", false)) { + $_SESSION['user_id'] = ''; + } + + OC_User::useBackend(new OC_User_Database()); + OC_Group::useBackend(new OC_Group_Database()); + + if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SESSION['user_id']) && $_SERVER['PHP_AUTH_USER'] != $_SESSION['user_id']) { + OC_User::logout(); + } + + // Load Apps + // This includes plugins for users and filesystems as well + global $RUNTIME_NOAPPS; + global $RUNTIME_APPTYPES; + if (!$RUNTIME_NOAPPS) { + if ($RUNTIME_APPTYPES) { + OC_App::loadApps($RUNTIME_APPTYPES); + } else { + OC_App::loadApps(); + } + } + + //setup extra user backends + OC_User::setupBackends(); + + self::registerCacheHooks(); + self::registerFilesystemHooks(); + self::registerShareHooks(); + + //make sure temporary files are cleaned up + register_shutdown_function(array('OC_Helper', 'cleanTmp')); + + //parse the given parameters + self::$REQUESTEDAPP = (isset($_GET['app']) && trim($_GET['app']) != '' && !is_null($_GET['app']) ? str_replace(array('\0', '/', '\\', '..'), '', strip_tags($_GET['app'])) : OC_Config::getValue('defaultapp', 'files')); + if (substr_count(self::$REQUESTEDAPP, '?') != 0) { + $app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?')); + $param = substr($_GET['app'], strpos($_GET['app'], '?') + 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_App::getAppPath(OC::$REQUESTEDAPP) . '/' . self::$REQUESTEDFILE; + $parent = OC_App::getAppPath(OC::$REQUESTEDAPP); + if (!OC_Helper::issubdirectory($subdir, $parent)) { + self::$REQUESTEDFILE = null; + header('HTTP/1.0 404 Not Found'); + exit; + } + } + + // write error into log if locale can't be set + if (OC_Util::issetlocaleworking() == false) { + OC_Log::write('core', 'setting locate to en_US.UTF-8 failed. Support is probably not installed on your system', OC_Log::ERROR); + } + if (OC_Config::getValue('installed', false)) { + if (OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') { + OC_Util::addScript('backgroundjobs'); + } + } + } + + /** + * register hooks for the cache + */ + public static function registerCacheHooks() + { + // register cache cleanup jobs + OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc'); + OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener'); + } + + /** + * register hooks for the filesystem + */ + public static function registerFilesystemHooks() + { + // Check for blacklisted files + OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted'); + OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted'); + } + + /** + * register hooks for sharing + */ + public static function registerShareHooks() + { + OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\Share', 'post_deleteUser'); + OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\Share', 'post_addToGroup'); + OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\Share', 'post_removeFromGroup'); + OC_Hook::connect('OC_User', 'post_deleteGroup', 'OCP\Share', 'post_deleteGroup'); + } + + /** + * @brief Handle the request + */ + public static function handleRequest() + { + if (!OC_Config::getValue('installed', false)) { + require_once 'core/setup.php'; + exit(); + } + // Handle redirect URL for logged in users + if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) { + $location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url'])); + header('Location: ' . $location); + return; + } + // Handle WebDAV + if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { + header('location: ' . OC_Helper::linkToRemote('webdav')); + return; + } + + // load all the classpaths from the enabled apps so they are available + // in the routing files of each app + OC::loadAppClassPaths(); + + try { + OC::getRouter()->match(OC_Request::getPathInfo()); + return; + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { + //header('HTTP/1.0 404 Not Found'); + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { + OC_Response::setStatus(405); + return; + } + $app = OC::$REQUESTEDAPP; + $file = OC::$REQUESTEDFILE; + $param = array('app' => $app, 'file' => $file); + // Handle app css files + if (substr($file, -3) == 'css') { + self::loadCSSFile($param); + return; + } + // Someone is logged in : + if (OC_User::isLoggedIn()) { + OC_App::loadApps(); + OC_User::setupBackends(); + if (isset($_GET["logout"]) and ($_GET["logout"])) { + if (isset($_COOKIE['oc_token'])) { + OC_Preferences::deleteKey(OC_User::getUser(), 'login_token', $_COOKIE['oc_token']); + } + OC_User::logout(); + header("Location: " . OC::$WEBROOT . '/'); + } else { + if (is_null($file)) { + $param['file'] = 'index.php'; + } + $file_ext = substr($param['file'], -3); + if ($file_ext != 'php' + || !self::loadAppScriptFile($param) + ) { + header('HTTP/1.0 404 Not Found'); + } + } + return; + } + // Not handled and not logged in + self::handleLogin(); + } + + public static function loadAppScriptFile($param) + { + OC_App::loadApps(); + $app = $param['app']; + $file = $param['file']; + $app_path = OC_App::getAppPath($app); + $file = $app_path . '/' . $file; + unset($app, $app_path); + if (file_exists($file)) { + require_once $file; + return true; + } + return false; + } + + public static function loadCSSFile($param) + { + $app = $param['app']; + $file = $param['file']; + $app_path = OC_App::getAppPath($app); + if (file_exists($app_path . '/' . $file)) { + $app_web_path = OC_App::getAppWebPath($app); + $filepath = $app_web_path . '/' . $file; + $minimizer = new OC_Minimizer_CSS(); + $info = array($app_path, $app_web_path, $file); + $minimizer->output(array($info), $filepath); + } + } + + protected static function handleLogin() + { + OC_App::loadApps(array('prelogin')); + $error = array(); + // remember was checked after last login + if (OC::tryRememberLogin()) { + $error[] = 'invalidcookie'; + + // Someone wants to log in : + } elseif (OC::tryFormLogin()) { + $error[] = 'invalidpassword'; + + // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP + } elseif (OC::tryBasicAuthLogin()) { + $error[] = 'invalidpassword'; + } + OC_Util::displayLoginPage(array_unique($error)); + } + + protected static function cleanupLoginTokens($user) + { + $cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); + $tokens = OC_Preferences::getKeys($user, 'login_token'); + foreach ($tokens as $token) { + $time = OC_Preferences::getValue($user, 'login_token', $token); + if ($time < $cutoff) { + OC_Preferences::deleteKey($user, 'login_token', $token); + } + } + } + + protected static function tryRememberLogin() + { + if (!isset($_COOKIE["oc_remember_login"]) + || !isset($_COOKIE["oc_token"]) + || !isset($_COOKIE["oc_username"]) + || !$_COOKIE["oc_remember_login"] + ) { + return false; + } + OC_App::loadApps(array('authentication')); + if (defined("DEBUG") && DEBUG) { + OC_Log::write('core', 'Trying to login from cookie', OC_Log::DEBUG); + } + // confirm credentials in cookie + if (isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username'])) { + // delete outdated cookies + self::cleanupLoginTokens($_COOKIE['oc_username']); + // get stored tokens + $tokens = OC_Preferences::getKeys($_COOKIE['oc_username'], 'login_token'); + // test cookies token against stored tokens + if (in_array($_COOKIE['oc_token'], $tokens, true)) { + // replace successfully used token with a new one + OC_Preferences::deleteKey($_COOKIE['oc_username'], 'login_token', $_COOKIE['oc_token']); + $token = OC_Util::generate_random_bytes(32); + OC_Preferences::setValue($_COOKIE['oc_username'], 'login_token', $token, time()); + OC_User::setMagicInCookie($_COOKIE['oc_username'], $token); + // login + OC_User::setUserId($_COOKIE['oc_username']); + OC_Util::redirectToDefaultPage(); + // doesn't return + } + // if you reach this point you have changed your password + // or you are an attacker + // we can not delete tokens here because users may reach + // this point multiple times after a password change + OC_Log::write('core', 'Authentication cookie rejected for user ' . $_COOKIE['oc_username'], OC_Log::WARN); + } + OC_User::unsetMagicInCookie(); + return true; + } + + protected static function tryFormLogin() + { + if (!isset($_POST["user"]) || !isset($_POST['password'])) { + return false; + } + + OC_App::loadApps(); + + //setup extra user backends + OC_User::setupBackends(); + + if (OC_User::login($_POST["user"], $_POST["password"])) { + // setting up the time zone + if (isset($_POST['timezone-offset'])) { + $_SESSION['timezone'] = $_POST['timezone-offset']; + } + + self::cleanupLoginTokens($_POST['user']); + if (!empty($_POST["remember_login"])) { + if (defined("DEBUG") && DEBUG) { + OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG); + } + $token = OC_Util::generate_random_bytes(32); + OC_Preferences::setValue($_POST['user'], 'login_token', $token, time()); + OC_User::setMagicInCookie($_POST["user"], $token); + } else { + OC_User::unsetMagicInCookie(); + } + OC_Util::redirectToDefaultPage(); + exit(); + } + return true; + } + + protected static function tryBasicAuthLogin() + { + if (!isset($_SERVER["PHP_AUTH_USER"]) + || !isset($_SERVER["PHP_AUTH_PW"]) + ) { + return false; + } + OC_App::loadApps(array('authentication')); + if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) { + //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG); + OC_User::unsetMagicInCookie(); + $_REQUEST['redirect_url'] = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''); + OC_Util::redirectToDefaultPage(); + } + return true; + } } // define runtime variables - unless this already has been done if (!isset($RUNTIME_NOAPPS)) { - $RUNTIME_NOAPPS = false; + $RUNTIME_NOAPPS = false; } if (!function_exists('get_temp_dir')) { - function get_temp_dir() - { - if ($temp = ini_get('upload_tmp_dir')) return $temp; - if ($temp = getenv('TMP')) return $temp; - if ($temp = getenv('TEMP')) return $temp; - if ($temp = getenv('TMPDIR')) return $temp; - $temp = tempnam(__FILE__, ''); - if (file_exists($temp)) { - unlink($temp); - return dirname($temp); - } - if ($temp = sys_get_temp_dir()) return $temp; - - return null; - } + function get_temp_dir() + { + if ($temp = ini_get('upload_tmp_dir')) return $temp; + if ($temp = getenv('TMP')) return $temp; + if ($temp = getenv('TEMP')) return $temp; + if ($temp = getenv('TMPDIR')) return $temp; + $temp = tempnam(__FILE__, ''); + if (file_exists($temp)) { + unlink($temp); + return dirname($temp); + } + if ($temp = sys_get_temp_dir()) return $temp; + + return null; + } } OC::init(); diff --git a/lib/cache/apc.php b/lib/cache/apc.php index 6dda0a0ff8c..895d307ea26 100644 --- a/lib/cache/apc.php +++ b/lib/cache/apc.php @@ -57,7 +57,7 @@ class OC_Cache_APC { if(!function_exists('apc_exists')) { function apc_exists($keys) { - $result; + $result=false; apc_fetch($keys, $result); return $result; } diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index 52350072fb2..026ec9f7ec5 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -176,9 +176,9 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @brief Returns a list of properties for this nodes.; * @param array $properties * @return array - * @note The properties list is a list of propertynames the client - * requested, encoded as xmlnamespace#tagName, for example: - * http://www.example.org/namespace#author If the array is empty, all + * @note The properties list is a list of propertynames the client + * requested, encoded as xmlnamespace#tagName, for example: + * http://www.example.org/namespace#author If the array is empty, all * properties should be returned */ public function getProperties($properties) { diff --git a/lib/db.php b/lib/db.php index 74e7ca5b0e0..7cc65673d10 100644 --- a/lib/db.php +++ b/lib/db.php @@ -41,6 +41,8 @@ class OC_DB { const BACKEND_PDO=0; const BACKEND_MDB2=1; + static private $preparedQueries = array(); + /** * @var MDB2_Driver_Common */ @@ -121,6 +123,7 @@ class OC_DB { return true; } } + self::$preparedQueries = array(); // The global data we need $name = OC_Config::getValue( "dbname", "owncloud" ); $host = OC_Config::getValue( "dbhost", "" ); @@ -201,6 +204,7 @@ class OC_DB { return true; } } + self::$preparedQueries = array(); // The global data we need $name = OC_Config::getValue( "dbname", "owncloud" ); $host = OC_Config::getValue( "dbhost", "" ); @@ -321,7 +325,12 @@ class OC_DB { $query.=$limitsql; } } + } else { + if (isset(self::$preparedQueries[$query])) { + return self::$preparedQueries[$query]; + } } + $rawQuery = $query; // Optimize the query $query = self::processQuery( $query ); @@ -343,6 +352,9 @@ class OC_DB { } $result=new PDOStatementWrapper($result); } + if (is_null($limit) || $limit == -1) { + self::$preparedQueries[$rawQuery] = $result; + } return $result; } @@ -428,6 +440,9 @@ class OC_DB { $CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" ); $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); + // cleanup the cached queries + self::$preparedQueries = array(); + self::connectScheme(); // read file @@ -588,7 +603,7 @@ class OC_DB { error_log('DB error: '.$entry); OC_Template::printErrorPage( $entry ); } - + if($result->numRows() == 0) { $query = 'INSERT INTO "' . $table . '" ("' . implode('","', array_keys($input)) . '") VALUES("' @@ -623,7 +638,7 @@ class OC_DB { return $result->execute(); } - + /** * @brief does minor changes to query * @param string $query Query string diff --git a/lib/filecache.php b/lib/filecache.php index aa58a8ef12f..7764890ef1a 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -64,7 +64,7 @@ class OC_FileCache{ * @param string $path * @param array data * @param string root (optional) - * @note $data is an associative array in the same format as returned + * @note $data is an associative array in the same format as returned * by get */ public static function put($path, $data, $root=false) { @@ -211,7 +211,7 @@ class OC_FileCache{ OC_Cache::remove('fileid/'.$root.$path); } - + /** * return array of filenames matching the querty * @param string $query @@ -359,7 +359,7 @@ class OC_FileCache{ public static function increaseSize($path, $sizeDiff, $root=false) { if($sizeDiff==0) return; $item = OC_FileCache_Cached::get($path); - //stop walking up the filetree if we hit a non-folder or reached to root folder + //stop walking up the filetree if we hit a non-folder or reached the root folder if($path == '/' || $path=='' || $item['mimetype'] !== 'httpd/unix-directory') { return; } diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php index 742e02d471b..503288142aa 100644 --- a/lib/fileproxy/quota.php +++ b/lib/fileproxy/quota.php @@ -76,7 +76,7 @@ class OC_FileProxy_Quota extends OC_FileProxy{ $usedSpace=isset($sharedInfo['size'])?$usedSpace-$sharedInfo['size']:$usedSpace; return $totalSpace-$usedSpace; } - + public function postFree_space($path, $space) { $free=$this->getFreeSpace($path); if($free==-1) { diff --git a/lib/files.php b/lib/files.php index 69097e41074..f4e0f140a44 100644 --- a/lib/files.php +++ b/lib/files.php @@ -141,7 +141,7 @@ class OC_Files { */ public static function get($dir, $files, $only_header = false) { $xsendfile = false; - if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || + if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { $xsendfile = true; } diff --git a/lib/filesystem.php b/lib/filesystem.php index aa03593908d..f185d777def 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -179,11 +179,11 @@ class OC_Filesystem{ $internalPath=substr($path, strlen($mountPoint)); return $internalPath; } - + static private function mountPointsLoaded($user) { return in_array($user, self::$loadedUsers); } - + /** * get the storage object for a path * @param string path @@ -216,7 +216,7 @@ class OC_Filesystem{ self::mount($options['class'], $options['options'], $mountPoint); } } - + if(isset($mountConfig['group'])) { foreach($mountConfig['group'] as $group=>$mounts) { if(OC_Group::inGroup($user, $group)) { @@ -230,7 +230,7 @@ class OC_Filesystem{ } } } - + if(isset($mountConfig['user'])) { foreach($mountConfig['user'] as $mountUser=>$mounts) { if($user==='all' or strtolower($mountUser)===strtolower($user)) { @@ -244,16 +244,16 @@ class OC_Filesystem{ } } } - + $mtime=filemtime(OC::$SERVERROOT.'/config/mount.php'); $previousMTime=OC_Appconfig::getValue('files', 'mountconfigmtime', 0); if($mtime>$previousMTime) {//mount config has changed, filecache needs to be updated OC_FileCache::triggerUpdate(); OC_Appconfig::setValue('files', 'mountconfigmtime', $mtime); } - } + } } - + static public function init($root, $user = '') { if(self::$defaultInstance) { return false; diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 98895e0ba1f..1fc8e83d68f 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -434,10 +434,10 @@ class OC_FilesystemView { $target = $this->fopen($path2.$postFix2, 'w'); $result = OC_Helper::streamCopy($source, $target); } - if( $this->fakeRoot==OC_Filesystem::getRoot() ) { - // If the file to be copied originates within + if( $this->fakeRoot==OC_Filesystem::getRoot() ) { + // If the file to be copied originates within // the user's data directory - + OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, @@ -458,33 +458,33 @@ class OC_FilesystemView { OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path2) ); - - } else { - // If this is not a normal file copy operation - // and the file originates somewhere else - // (e.g. a version rollback operation), do not + + } else { + // If this is not a normal file copy operation + // and the file originates somewhere else + // (e.g. a version rollback operation), do not // perform all the other post_write actions - + // Update webdav properties OC_Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot); - + $splitPath2 = explode( '/', $path2 ); - - // Only cache information about files - // that are being copied from within - // the user files directory. Caching + + // Only cache information about files + // that are being copied from within + // the user files directory. Caching // other files, like VCS backup files, // serves no purpose if ( $splitPath2[1] == 'files' ) { - + OC_FileCache_Update::update($path2, $this->fakeRoot); - + } - + } - + return $result; - + } } } diff --git a/lib/helper.php b/lib/helper.php index 1aba2a38100..a7b2a429952 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -193,8 +193,9 @@ class OC_Helper { if(isset($alias[$mimetype])) { $mimetype=$alias[$mimetype]; } - // Replace slash with a minus + // Replace slash and backslash with a minus $mimetype = str_replace( "/", "-", $mimetype ); + $mimetype = str_replace( "\\", "-", $mimetype ); // Is it a dir? if( $mimetype == "dir" ) { @@ -223,6 +224,10 @@ class OC_Helper { * Makes 2048 to 2 kB. */ public static function humanFileSize( $bytes ) { + if( $bytes < 0 ) { + $l = OC_L10N::get('lib'); + return $l->t("couldn't be determined"); + } if( $bytes < 1024 ) { return "$bytes B"; } @@ -549,7 +554,7 @@ class OC_Helper { fclose($fh); return $file; } - + /** * create a temporary folder with an unique filename * @return string @@ -625,37 +630,17 @@ class OC_Helper { return $newpath; } - /* - * checks if $sub is a subdirectory of $parent + /** + * @brief Checks if $sub is a subdirectory of $parent * * @param string $sub * @param string $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; - } + if (strpos(realpath($sub), realpath($parent)) === 0) { + 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; } @@ -695,8 +680,8 @@ class OC_Helper { $start = intval($start); $length = intval($length); $string = mb_substr($string, 0, $start, $encoding) . - $replacement . - mb_substr($string, $start+$length, mb_strlen($string, 'UTF-8')-$start, $encoding); + $replacement . + mb_substr($string, $start+$length, mb_strlen($string, 'UTF-8')-$start, $encoding); return $string; } @@ -765,6 +750,23 @@ class OC_Helper { } /** + * @brief calculates the maximum upload size respecting system settings, free space and user quota + * + * @param $dir the current folder where the user currently operates + * @return number of bytes representing + */ + public static function maxUploadFilesize($dir) { + $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); + $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); + $maxUploadFilesize = min($upload_max_filesize, $post_max_size); + + $freeSpace = OC_Filesystem::free_space($dir); + $freeSpace = max($freeSpace, 0); + + return min($maxUploadFilesize, $freeSpace); + } + + /** * Checks if a function is available * @param string $function_name * @return bool diff --git a/lib/image.php b/lib/image.php index 2043a452541..cfc6d477395 100644 --- a/lib/image.php +++ b/lib/image.php @@ -646,7 +646,7 @@ class OC_Image { fclose($fh); return $im; } - + /** * @brief Resizes the image preserving ratio. * @param $maxsize The maximum size of either the width or height. diff --git a/lib/json.php b/lib/json.php index 204430411c0..f929e958957 100644 --- a/lib/json.php +++ b/lib/json.php @@ -57,9 +57,7 @@ class OC_JSON{ * Check if the user is a admin, send json error msg if not */ public static function checkAdminUser() { - self::checkLoggedIn(); - self::verifyUser(); - if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )) { + if( !OC_User::isAdminUser(OC_User::getUser())) { $l = OC_L10N::get('lib'); self::error(array( 'data' => array( 'message' => $l->t('Authentication error') ))); exit(); @@ -70,9 +68,7 @@ class OC_JSON{ * Check if the user is a subadmin, send json error msg if not */ public static function checkSubAdminUser() { - self::checkLoggedIn(); - self::verifyUser(); - if(!OC_Group::inGroup(OC_User::getUser(), 'admin') && !OC_SubAdmin::isSubAdmin(OC_User::getUser())) { + if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) { $l = OC_L10N::get('lib'); self::error(array( 'data' => array( 'message' => $l->t('Authentication error') ))); exit(); @@ -80,19 +76,6 @@ class OC_JSON{ } /** - * Check if the user verified the login with his password - */ - public static function verifyUser() { - if(OC_Config::getValue('enhancedauth', false) === true) { - if(!isset($_SESSION['verifiedLogin']) OR $_SESSION['verifiedLogin'] < time()) { - $l = OC_L10N::get('lib'); - self::error(array( 'data' => array( 'message' => $l->t('Authentication error') ))); - exit(); - } - } - } - - /** * Send json error msg */ public static function error($data = array()) { diff --git a/lib/l10n.php b/lib/l10n.php index f70dfa5e34e..ca53b3cf65c 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -141,15 +141,15 @@ class OC_L10N{ } } - /** - * @brief Translating - * @param $text String The text we need a translation for - * @param array $parameters default:array() Parameters for sprintf - * @return \OC_L10N_String Translation or the same text - * - * Returns the translation. If no translation is found, $text will be - * returned. - */ + /** + * @brief Translating + * @param $text String The text we need a translation for + * @param array $parameters default:array() Parameters for sprintf + * @return \OC_L10N_String Translation or the same text + * + * Returns the translation. If no translation is found, $text will be + * returned. + */ public function t($text, $parameters = array()) { return new OC_L10N_String($this, $text, $parameters); } diff --git a/lib/l10n/ca.php b/lib/l10n/ca.php index b3321ef82e1..f6401fa39b6 100644 --- a/lib/l10n/ca.php +++ b/lib/l10n/ca.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Els fitxers s'han de baixar d'un en un.", "Back to Files" => "Torna a Fitxers", "Selected files too large to generate zip file." => "Els fitxers seleccionats son massa grans per generar un fitxer zip.", +"couldn't be determined" => "no s'ha pogut determinar", "Application is not enabled" => "L'aplicació no està habilitada", "Authentication error" => "Error d'autenticació", "Token expired. Please reload page." => "El testimoni ha expirat. Torneu a carregar la pàgina.", diff --git a/lib/l10n/cs_CZ.php b/lib/l10n/cs_CZ.php index fa11e886774..2c823194b96 100644 --- a/lib/l10n/cs_CZ.php +++ b/lib/l10n/cs_CZ.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Soubory musí být stahovány jednotlivě.", "Back to Files" => "Zpět k souborům", "Selected files too large to generate zip file." => "Vybrané soubory jsou příliš velké pro vytvoření zip souboru.", +"couldn't be determined" => "nelze zjistit", "Application is not enabled" => "Aplikace není povolena", "Authentication error" => "Chyba ověření", "Token expired. Please reload page." => "Token vypršel. Obnovte prosím stránku.", diff --git a/lib/l10n/de.php b/lib/l10n/de.php index 4b77bf7210d..c285a07f63a 100644 --- a/lib/l10n/de.php +++ b/lib/l10n/de.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Die Dateien müssen einzeln heruntergeladen werden.", "Back to Files" => "Zurück zu \"Dateien\"", "Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine ZIP-Datei zu erstellen.", +"couldn't be determined" => "Konnte nicht festgestellt werden", "Application is not enabled" => "Die Anwendung ist nicht aktiviert", "Authentication error" => "Authentifizierungs-Fehler", "Token expired. Please reload page." => "Token abgelaufen. Bitte lade die Seite neu.", diff --git a/lib/l10n/de_DE.php b/lib/l10n/de_DE.php index e9f0f34a0e1..625ba2ecf20 100644 --- a/lib/l10n/de_DE.php +++ b/lib/l10n/de_DE.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Die Dateien müssen einzeln heruntergeladen werden.", "Back to Files" => "Zurück zu \"Dateien\"", "Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine ZIP-Datei zu erstellen.", +"couldn't be determined" => "konnte nicht ermittelt werden", "Application is not enabled" => "Die Anwendung ist nicht aktiviert", "Authentication error" => "Authentifizierungs-Fehler", "Token expired. Please reload page." => "Token abgelaufen. Bitte laden Sie die Seite neu.", diff --git a/lib/l10n/el.php b/lib/l10n/el.php index 315b995ecc9..cf0be24b432 100644 --- a/lib/l10n/el.php +++ b/lib/l10n/el.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Τα αρχεία πρέπει να ληφθούν ένα-ένα.", "Back to Files" => "Πίσω στα Αρχεία", "Selected files too large to generate zip file." => "Τα επιλεγμένα αρχεία είναι μεγάλα ώστε να δημιουργηθεί αρχείο zip.", +"couldn't be determined" => "δεν μπορούσε να προσδιορισθεί", "Application is not enabled" => "Δεν ενεργοποιήθηκε η εφαρμογή", "Authentication error" => "Σφάλμα πιστοποίησης", "Token expired. Please reload page." => "Το αναγνωριστικό έληξε. Παρακαλώ φορτώστε ξανά την σελίδα.", diff --git a/lib/l10n/es.php b/lib/l10n/es.php index f843c42dfd3..8bbc8a8f7b4 100644 --- a/lib/l10n/es.php +++ b/lib/l10n/es.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Los archivos deben ser descargados uno por uno.", "Back to Files" => "Volver a Archivos", "Selected files too large to generate zip file." => "Los archivos seleccionados son demasiado grandes para generar el archivo zip.", +"couldn't be determined" => "no pudo ser determinado", "Application is not enabled" => "La aplicación no está habilitada", "Authentication error" => "Error de autenticación", "Token expired. Please reload page." => "Token expirado. Por favor, recarga la página.", diff --git a/lib/l10n/es_AR.php b/lib/l10n/es_AR.php index 2bbffd39e9e..c32017a10f8 100644 --- a/lib/l10n/es_AR.php +++ b/lib/l10n/es_AR.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Los archivos deben ser descargados de a uno.", "Back to Files" => "Volver a archivos", "Selected files too large to generate zip file." => "Los archivos seleccionados son demasiado grandes para generar el archivo zip.", +"couldn't be determined" => "no pudo ser determinado", "Application is not enabled" => "La aplicación no está habilitada", "Authentication error" => "Error de autenticación", "Token expired. Please reload page." => "Token expirado. Por favor, recargá la página.", diff --git a/lib/l10n/eu.php b/lib/l10n/eu.php index 5d47ecbda23..1941551b176 100644 --- a/lib/l10n/eu.php +++ b/lib/l10n/eu.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Fitxategiak banan-banan deskargatu behar dira.", "Back to Files" => "Itzuli fitxategietara", "Selected files too large to generate zip file." => "Hautatuko fitxategiak oso handiak dira zip fitxategia sortzeko.", +"couldn't be determined" => "ezin izan da zehaztu", "Application is not enabled" => "Aplikazioa ez dago gaituta", "Authentication error" => "Autentikazio errorea", "Token expired. Please reload page." => "Tokena iraungitu da. Mesedez birkargatu orria.", diff --git a/lib/l10n/fi_FI.php b/lib/l10n/fi_FI.php index 6a5734e978d..b8d4b137431 100644 --- a/lib/l10n/fi_FI.php +++ b/lib/l10n/fi_FI.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Tiedostot on ladattava yksittäin.", "Back to Files" => "Takaisin tiedostoihin", "Selected files too large to generate zip file." => "Valitut tiedostot ovat liian suurikokoisia mahtuakseen zip-tiedostoon.", +"couldn't be determined" => "ei voitu määrittää", "Application is not enabled" => "Sovellusta ei ole otettu käyttöön", "Authentication error" => "Todennusvirhe", "Token expired. Please reload page." => "Valtuutus vanheni. Lataa sivu uudelleen.", diff --git a/lib/l10n/hu_HU.php b/lib/l10n/hu_HU.php index 3dcf0646d06..c95358011f0 100644 --- a/lib/l10n/hu_HU.php +++ b/lib/l10n/hu_HU.php @@ -8,7 +8,8 @@ "ZIP download is turned off." => "A ZIP-letöltés nem engedélyezett.", "Files need to be downloaded one by one." => "A fájlokat egyenként kell letölteni", "Back to Files" => "Vissza a Fájlokhoz", -"Selected files too large to generate zip file." => "A kiválasztott fájlok túl nagy a zip tömörítéshez.", +"Selected files too large to generate zip file." => "A kiválasztott fájlok túl nagyok a zip tömörítéshez.", +"couldn't be determined" => "nem sikerült azonosítani", "Application is not enabled" => "Az alkalmazás nincs engedélyezve", "Authentication error" => "Hitelesítési hiba", "Token expired. Please reload page." => "A token lejárt. Frissítse az oldalt.", diff --git a/lib/l10n/it.php b/lib/l10n/it.php index c0fb0babfb3..eb404db7fb5 100644 --- a/lib/l10n/it.php +++ b/lib/l10n/it.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "I file devono essere scaricati uno alla volta.", "Back to Files" => "Torna ai file", "Selected files too large to generate zip file." => "I file selezionati sono troppo grandi per generare un file zip.", +"couldn't be determined" => "non può essere determinato", "Application is not enabled" => "L'applicazione non è abilitata", "Authentication error" => "Errore di autenticazione", "Token expired. Please reload page." => "Token scaduto. Ricarica la pagina.", diff --git a/lib/l10n/ja_JP.php b/lib/l10n/ja_JP.php index 854734c9764..11cefe900c2 100644 --- a/lib/l10n/ja_JP.php +++ b/lib/l10n/ja_JP.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "ファイルは1つずつダウンロードする必要があります。", "Back to Files" => "ファイルに戻る", "Selected files too large to generate zip file." => "選択したファイルはZIPファイルの生成には大きすぎます。", +"couldn't be determined" => "測定できませんでした", "Application is not enabled" => "アプリケーションは無効です", "Authentication error" => "認証エラー", "Token expired. Please reload page." => "トークンが無効になりました。ページを再読込してください。", diff --git a/lib/l10n/lb.php b/lib/l10n/lb.php index baee630e897..a5a9adca187 100644 --- a/lib/l10n/lb.php +++ b/lib/l10n/lb.php @@ -1,6 +1,8 @@ <?php $TRANSLATIONS = array( +"Help" => "Hëllef", "Personal" => "Perséinlech", "Settings" => "Astellungen", "Authentication error" => "Authentifikatioun's Fehler", +"Files" => "Dateien", "Text" => "SMS" ); diff --git a/lib/l10n/ms_MY.php b/lib/l10n/ms_MY.php index 86c7e51b486..5afee1cb5a8 100644 --- a/lib/l10n/ms_MY.php +++ b/lib/l10n/ms_MY.php @@ -1,4 +1,5 @@ <?php $TRANSLATIONS = array( +"Help" => "Bantuan", "Personal" => "Peribadi", "Settings" => "Tetapan", "Users" => "Pengguna", diff --git a/lib/l10n/nl.php b/lib/l10n/nl.php index 087cf23a627..7ce134e3621 100644 --- a/lib/l10n/nl.php +++ b/lib/l10n/nl.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Bestanden moeten één voor één worden gedownload.", "Back to Files" => "Terug naar bestanden", "Selected files too large to generate zip file." => "De geselecteerde bestanden zijn te groot om een zip bestand te maken.", +"couldn't be determined" => "kon niet worden vastgesteld", "Application is not enabled" => "De applicatie is niet actief", "Authentication error" => "Authenticatie fout", "Token expired. Please reload page." => "Token verlopen. Herlaad de pagina.", diff --git a/lib/l10n/pt_PT.php b/lib/l10n/pt_PT.php index 84867c4c37c..e35bb489c49 100644 --- a/lib/l10n/pt_PT.php +++ b/lib/l10n/pt_PT.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Os ficheiros precisam de ser descarregados um por um.", "Back to Files" => "Voltar a Ficheiros", "Selected files too large to generate zip file." => "Os ficheiros seleccionados são grandes demais para gerar um ficheiro zip.", +"couldn't be determined" => "Não foi possível determinar", "Application is not enabled" => "A aplicação não está activada", "Authentication error" => "Erro na autenticação", "Token expired. Please reload page." => "O token expirou. Por favor recarregue a página.", diff --git a/lib/l10n/uk.php b/lib/l10n/uk.php index f5d52f8682d..053644ddede 100644 --- a/lib/l10n/uk.php +++ b/lib/l10n/uk.php @@ -9,6 +9,7 @@ "Files need to be downloaded one by one." => "Файли повинні бути завантаженні послідовно.", "Back to Files" => "Повернутися до файлів", "Selected files too large to generate zip file." => "Вибрані фали завеликі для генерування zip файлу.", +"couldn't be determined" => "не може бути визначено", "Application is not enabled" => "Додаток не увімкнений", "Authentication error" => "Помилка автентифікації", "Token expired. Please reload page." => "Строк дії токена скінчився. Будь ласка, перезавантажте сторінку.", diff --git a/lib/log.php b/lib/log.php index e9cededa5c0..e869282e88c 100644 --- a/lib/log.php +++ b/lib/log.php @@ -39,7 +39,7 @@ class OC_Log { $log_class::write($app, $message, $level); } } - + //Fatal errors handler public static function onShutdown() { $error = error_get_last(); @@ -50,7 +50,7 @@ class OC_Log { return true; } } - + // Uncaught exception handler public static function onException($exception) { self::write('PHP', $exception->getMessage() . ' at ' . $exception->getFile() . '#' . $exception->getLine(), self::FATAL); diff --git a/lib/migrate.php b/lib/migrate.php index 5ff8e338a44..87bdd016fe4 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -219,7 +219,7 @@ class OC_Migrate{ // We need to be an admin if we are not importing our own data if(($type == 'user' && self::$uid != $currentuser) || $type != 'user' ) { - if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )) { + if( !OC_User::isAdminUser($currentuser)) { // Naughty. OC_Log::write( 'migration', 'Import not permitted.', OC_Log::ERROR ); return json_encode( array( 'success' => false ) ); @@ -655,7 +655,7 @@ class OC_Migrate{ $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."", OC_Log::ERROR); } return $result ? true : false; diff --git a/lib/migration/content.php b/lib/migration/content.php index 00df62f0c7f..e81c8f217ff 100644 --- a/lib/migration/content.php +++ b/lib/migration/content.php @@ -66,7 +66,7 @@ class OC_Migration_Content{ // Die if we have an error (error means: bad query, not 0 results!) if( PEAR::isError( $query ) ) { - $entry = 'DB Error: "'.$result->getMessage().'"<br />'; + $entry = 'DB Error: "'.$query->getMessage().'"<br />'; $entry .= 'Offending command was: '.$query.'<br />'; OC_Log::write( 'migration', $entry, OC_Log::FATAL ); return false; diff --git a/lib/ocs/cloud.php b/lib/ocs/cloud.php index 21095ec91e9..2d18b1db3f2 100644 --- a/lib/ocs/cloud.php +++ b/lib/ocs/cloud.php @@ -24,7 +24,7 @@ class OC_OCS_Cloud { - public static function getSystemWebApps($parameters) { + public static function getSystemWebApps() { OC_Util::checkLoggedIn(); $apps = OC_App::getEnabledApps(); $values = array(); @@ -37,15 +37,15 @@ class OC_OCS_Cloud { } return new OC_OCS_Result($values); } - + public static function getUserQuota($parameters) { $user = OC_User::getUser(); - if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) { + if(OC_User::isAdminUser($user) or ($user==$parameters['user'])) { if(OC_User::userExists($parameters['user'])) { // calculate the disc space $userDir = '/'.$parameters['user'].'/files'; - OC_Filesystem::init($useDir); + OC_Filesystem::init($userDir); $rootInfo = OC_FileCache::get(''); $sharedInfo = OC_FileCache::get('/Shared'); $used = $rootInfo['size'] - $sharedInfo['size']; @@ -68,7 +68,7 @@ class OC_OCS_Cloud { return new OC_OCS_Result(null, 300); } } - + public static function getUserPublickey($parameters) { if(OC_User::userExists($parameters['user'])) { @@ -79,10 +79,10 @@ class OC_OCS_Cloud { return new OC_OCS_Result(null, 300); } } - + public static function getUserPrivatekey($parameters) { $user = OC_User::getUser(); - if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) { + if(OC_User::isAdminUser($user) or ($user==$parameters['user'])) { if(OC_User::userExists($user)) { // calculate the disc space diff --git a/lib/ocs/config.php b/lib/ocs/config.php index 03c54aa2314..f19121f4b2b 100644 --- a/lib/ocs/config.php +++ b/lib/ocs/config.php @@ -23,7 +23,7 @@ */ class OC_OCS_Config { - + public static function apiConfig($parameters) { $xml['version'] = '1.7'; $xml['website'] = 'ownCloud'; @@ -32,5 +32,5 @@ class OC_OCS_Config { $xml['ssl'] = 'false'; return new OC_OCS_Result($xml); } - + } diff --git a/lib/ocs/person.php b/lib/ocs/person.php index 169cc8211db..1c8210d0825 100644 --- a/lib/ocs/person.php +++ b/lib/ocs/person.php @@ -38,5 +38,5 @@ class OC_OCS_Person { return new OC_OCS_Result(null, 101); } } - + } diff --git a/lib/ocs/privatedata.php b/lib/ocs/privatedata.php index e01ed5e8b07..311b24269dd 100644 --- a/lib/ocs/privatedata.php +++ b/lib/ocs/privatedata.php @@ -39,7 +39,7 @@ class OC_OCS_Privatedata { return new OC_OCS_Result($xml); //TODO: replace 'privatedata' with 'attribute' once a new libattice has been released that works with it } - + public static function set($parameters) { OC_Util::checkLoggedIn(); $user = OC_User::getUser(); @@ -50,7 +50,7 @@ class OC_OCS_Privatedata { return new OC_OCS_Result(null, 100); } } - + public static function delete($parameters) { OC_Util::checkLoggedIn(); $user = OC_User::getUser(); diff --git a/lib/ocs/result.php b/lib/ocs/result.php index b08d911f785..65b2067fc3f 100644 --- a/lib/ocs/result.php +++ b/lib/ocs/result.php @@ -21,9 +21,9 @@ */ class OC_OCS_Result{ - + private $data, $message, $statusCode, $items, $perPage; - + /** * create the OCS_Result object * @param $data mixed the data to return @@ -33,7 +33,7 @@ class OC_OCS_Result{ $this->statusCode = $code; $this->message = $message; } - + /** * optionally set the total number of items available * @param $items int @@ -41,7 +41,7 @@ class OC_OCS_Result{ public function setTotalItems(int $items) { $this->items = $items; } - + /** * optionally set the the number of items per page * @param $items int @@ -49,7 +49,7 @@ class OC_OCS_Result{ public function setItemsPerPage(int $items) { $this->perPage = $items; } - + /** * returns the data associated with the api result * @return array @@ -70,6 +70,6 @@ class OC_OCS_Result{ // Return the result data. return $return; } - - + + }
\ No newline at end of file diff --git a/lib/ocsclient.php b/lib/ocsclient.php index 24081425f1e..ca0665da436 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -39,11 +39,11 @@ class OC_OCSClient{ return($url); } - /** - * @brief Get the url of the OCS KB server. - * @returns string of the KB server - * This function returns the url of the OCS knowledge base server. It´s possible to set it in the config file or it will fallback to the default - */ + /** + * @brief Get the url of the OCS KB server. + * @returns string of the KB server + * This function returns the url of the OCS knowledge base server. It´s possible to set it in the config file or it will fallback to the default + */ private static function getKBURL() { $url = OC_Config::getValue('knowledgebaseurl', 'http://api.apps.owncloud.com/v1'); return($url); @@ -59,7 +59,7 @@ class OC_OCSClient{ return($data); } - /** + /** * @brief Get all the categories from the OCS server * @returns array with category ids * @note returns NULL if config value appstoreenabled is set to false @@ -242,7 +242,7 @@ class OC_OCSClient{ } $kbe['totalitems'] = $data->meta->totalitems; } - return $kbe; + return $kbe; } diff --git a/lib/public/api.php b/lib/public/api.php index a85daa1935c..95d333f2165 100644 --- a/lib/public/api.php +++ b/lib/public/api.php @@ -26,7 +26,7 @@ namespace OCP; * This class provides functions to manage apps in ownCloud */ class API { - + /** * registers an api call * @param string $method the http method @@ -40,5 +40,5 @@ class API { public static function register($method, $url, $action, $app, $authLevel = OC_API::USER_AUTH, $defaults = array(), $requirements = array()){ \OC_API::register($method, $url, $action, $app, $authLevel, $defaults, $requirements); } - + } diff --git a/lib/public/app.php b/lib/public/app.php index 809a656f17f..a1ecf524cc8 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -89,7 +89,7 @@ class App { * @param $page string page to be included */ public static function registerPersonal( $app, $page ) { - return \OC_App::registerPersonal( $app, $page ); + \OC_App::registerPersonal( $app, $page ); } /** @@ -98,7 +98,7 @@ class App { * @param $page string page to be included */ public static function registerAdmin( $app, $page ) { - return \OC_App::registerAdmin( $app, $page ); + \OC_App::registerAdmin( $app, $page ); } /** @@ -125,10 +125,9 @@ class App { /** * @brief Check if the app is enabled, redirects to home if not * @param $app app - * @returns true/false */ public static function checkAppEnabled( $app ) { - return \OC_Util::checkAppEnabled( $app ); + \OC_Util::checkAppEnabled( $app ); } /** diff --git a/lib/public/constants.php b/lib/public/constants.php index bc979c9031f..1495c620dc9 100644 --- a/lib/public/constants.php +++ b/lib/public/constants.php @@ -35,4 +35,3 @@ const PERMISSION_UPDATE = 2; const PERMISSION_DELETE = 8; const PERMISSION_SHARE = 16; const PERMISSION_ALL = 31; - diff --git a/lib/public/db.php b/lib/public/db.php index 5d4aadd22ae..932e79d9ef1 100644 --- a/lib/public/db.php +++ b/lib/public/db.php @@ -49,9 +49,9 @@ class DB { * @brief Insert a row if a matching row doesn't exists. * @param $table string The table name (will replace *PREFIX*) to perform the replace on. * @param $input array - * + * * The input array if in the form: - * + * * array ( 'id' => array ( 'value' => 6, * 'key' => true * ), @@ -65,7 +65,7 @@ class DB { public static function insertIfNotExist($table, $input) { return(\OC_DB::insertIfNotExist($table, $input)); } - + /** * @brief gets last value of autoincrement * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix diff --git a/lib/public/files.php b/lib/public/files.php index 90889c59ad8..75e1d2fbbc1 100644 --- a/lib/public/files.php +++ b/lib/public/files.php @@ -38,9 +38,10 @@ class Files { * @brief Recusive deletion of folders * @param string $dir path to the folder * + * @return bool */ static function rmdirr( $dir ) { - \OC_Helper::rmdirr( $dir ); + return \OC_Helper::rmdirr( $dir ); } /** diff --git a/lib/public/response.php b/lib/public/response.php index bfb84eda5d1..de0c3f25347 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -42,7 +42,7 @@ class Response { * null cache indefinitly */ static public function enableCaching( $cache_time = null ) { - return(\OC_Response::enableCaching( $cache_time )); + \OC_Response::enableCaching( $cache_time ); } /** @@ -51,7 +51,7 @@ class Response { * @param string $lastModified time when the reponse was last modified */ static public function setLastModifiedHeader( $lastModified ) { - return(\OC_Response::setLastModifiedHeader( $lastModified )); + \OC_Response::setLastModifiedHeader( $lastModified ); } /** @@ -59,7 +59,7 @@ class Response { * @see enableCaching with cache_time = 0 */ static public function disableCaching() { - return(\OC_Response::disableCaching()); + \OC_Response::disableCaching(); } /** @@ -68,7 +68,7 @@ class Response { * @param string $etag token to use for modification check */ static public function setETagHeader( $etag ) { - return(\OC_Response::setETagHeader( $etag )); + \OC_Response::setETagHeader( $etag ); } /** @@ -76,7 +76,7 @@ class Response { * @param string $filepath of file to send */ static public function sendFile( $filepath ) { - return(\OC_Response::sendFile( $filepath )); + \OC_Response::sendFile( $filepath ); } /** @@ -86,7 +86,7 @@ class Response { * DateTime object when to expire response */ static public function setExpiresHeader( $expires ) { - return(\OC_Response::setExpiresHeader( $expires )); + \OC_Response::setExpiresHeader( $expires ); } /** @@ -94,6 +94,6 @@ class Response { * @param string $location to redirect to */ static public function redirect( $location ) { - return(\OC_Response::redirect( $location )); + \OC_Response::redirect( $location ); } } diff --git a/lib/public/share.php b/lib/public/share.php index 8c0cfc16b4e..cda583aa073 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -351,14 +351,14 @@ class Share { //delete the old share self::delete($checkExists['id']); } - + // Generate hash of password - same method as user passwords if (isset($shareWith)) { $forcePortable = (CRYPT_BLOWFISH != 1); $hasher = new \PasswordHash(8, $forcePortable); $shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', '')); } - + // Generate token if (isset($oldToken)) { $token = $oldToken; @@ -415,7 +415,7 @@ class Share { if ($parentFolder && $files = \OC_Files::getDirectoryContent($itemSource)) { for ($i = 0; $i < count($files); $i++) { $name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource)); - if ($files[$i]['mimetype'] == 'httpd/unix-directory' + if ($files[$i]['mimetype'] == 'httpd/unix-directory' && $children = \OC_Files::getDirectoryContent($name, '/') ) { // Continue scanning into child folders @@ -748,7 +748,7 @@ class Share { $itemTypes = $collectionTypes; } $placeholders = join(',', array_fill(0, count($itemTypes), '?')); - $where .= ' WHERE `item_type` IN ('.$placeholders.'))'; + $where = ' WHERE `item_type` IN ('.$placeholders.'))'; $queryArgs = $itemTypes; } else { $where = ' WHERE `item_type` = ?'; @@ -864,7 +864,7 @@ class Share { } } else { if ($fileDependent) { - if (($itemType == 'file' || $itemType == 'folder') + if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT ) { diff --git a/lib/public/user.php b/lib/public/user.php index 9e50115ab70..204d8e4c0f1 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -65,7 +65,7 @@ class User { /** * @brief check if a user exists * @param string $uid the username - * @param string $excludingBackend (default none) + * @param string $excludingBackend (default none) * @return boolean */ public static function userExists( $uid, $excludingBackend = null ) { @@ -73,12 +73,10 @@ class User { } /** * @brief Loggs the user out including all the session data - * @returns true - * * Logout, destroys session */ public static function logout() { - return \OC_USER::logout(); + \OC_USER::logout(); } /** diff --git a/lib/public/util.php b/lib/public/util.php index df09ea81ae1..413dbcccd28 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -203,7 +203,7 @@ class Util { $host_name = self::getServerHostName(); // handle localhost installations if ($host_name === 'localhost') { - $host_name = "example.com"; + $host_name = "example.com"; } return $user_part.'@'.$host_name; } @@ -298,7 +298,7 @@ class Util { * Todo: Write howto */ public static function callCheck() { - return(\OC_Util::callCheck()); + \OC_Util::callCheck(); } /** @@ -367,4 +367,14 @@ class Util { public static function recursiveArraySearch($haystack, $needle, $index = null) { return(\OC_Helper::recursiveArraySearch($haystack, $needle, $index)); } + + /** + * @brief calculates the maximum upload size respecting system settings, free space and user quota + * + * @param $dir the current folder where the user currently operates + * @return number of bytes representing + */ + public static function maxUploadFilesize($dir) { + return \OC_Helper::maxUploadFilesize($dir); + } } diff --git a/lib/request.php b/lib/request.php index 99a77e1b59e..f2f15c21103 100755 --- a/lib/request.php +++ b/lib/request.php @@ -19,7 +19,7 @@ class OC_Request { return 'localhost'; } if(OC_Config::getValue('overwritehost', '')<>'') { - return OC_Config::getValue('overwritehost'); + return OC_Config::getValue('overwritehost'); } if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ",") !== false) { @@ -44,7 +44,7 @@ class OC_Request { */ public static function serverProtocol() { if(OC_Config::getValue('overwriteprotocol', '')<>'') { - return OC_Config::getValue('overwriteprotocol'); + return OC_Config::getValue('overwriteprotocol'); } if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { $proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']); diff --git a/lib/router.php b/lib/router.php index 27e14c38abf..746b68c2c0c 100644 --- a/lib/router.php +++ b/lib/router.php @@ -49,6 +49,7 @@ class OC_Router { $files = $this->getRoutingFiles(); $files[] = 'settings/routes.php'; $files[] = 'core/routes.php'; + $files[] = 'ocs/routes.php'; $this->cache_key = OC_Cache::generateCacheKeyFromFiles($files); } return $this->cache_key; @@ -58,23 +59,6 @@ class OC_Router { * loads the api routes */ public function loadRoutes() { - - // TODO cache - $this->root = $this->getCollection('root'); - foreach(OC_APP::getEnabledApps() as $app){ - $file = OC_App::getAppPath($app).'/appinfo/routes.php'; - if(file_exists($file)){ - $this->useCollection($app); - require_once($file); - $collection = $this->getCollection($app); - $this->root->addCollection($collection, '/apps/'.$app); - } - } - // include ocs routes - require_once(OC::$SERVERROOT.'/ocs/routes.php'); - $collection = $this->getCollection('ocs'); - $this->root->addCollection($collection, '/ocs'); - foreach($this->getRoutingFiles() as $app => $file) { $this->useCollection($app); require_once $file; @@ -85,6 +69,10 @@ class OC_Router { require_once 'settings/routes.php'; require_once 'core/routes.php'; + // include ocs routes + require_once 'ocs/routes.php'; + $collection = $this->getCollection('ocs'); + $this->root->addCollection($collection, '/ocs'); } protected function getCollection($name) { diff --git a/lib/setup.php b/lib/setup.php index fdd10be6824..28882b6bede 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -1,5 +1,23 @@ <?php +class DatabaseSetupException extends Exception +{ + private $hint; + + public function __construct($message, $hint, $code = 0, Exception $previous = null) { + $this->hint = $hint; + parent::__construct($message, $code, $previous); + } + + public function __toString() { + return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; + } + + public function getHint() { + return $this->hint; + } +} + class OC_Setup { public static function install($options) { $error = array(); @@ -19,9 +37,9 @@ class OC_Setup { if($dbtype=='mysql') $dbprettyname = 'MySQL'; else if($dbtype=='pgsql') - $dbprettyname = 'PostgreSQL'; + $dbprettyname = 'PostgreSQL'; else - $dbprettyname = 'Oracle'; + $dbprettyname = 'Oracle'; if(empty($options['dbuser'])) { @@ -69,10 +87,16 @@ class OC_Setup { try { self::setupMySQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username); + } catch (DatabaseSetupException $e) { + $error[] = array( + 'error' => $e->getMessage(), + 'hint' => $e->getHint() + ); + return($error); } catch (Exception $e) { $error[] = array( - 'error' => 'MySQL username and/or password not valid', - 'hint' => 'You need to enter either an existing account or the administrator.' + 'error' => $e->getMessage(), + 'hint' => '' ); return($error); } @@ -153,7 +177,7 @@ class OC_Setup { if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); } - + //and we are done OC_Config::setValue('installed', true); } @@ -166,7 +190,7 @@ class OC_Setup { //check if the database user has admin right $connection = @mysql_connect($dbhost, $dbuser, $dbpass); if(!$connection) { - throw new Exception('MySQL username and/or password not valid'); + throw new DatabaseSetupException('MySQL username and/or password not valid','You need to enter either an existing account or the administrator.'); } $oldUser=OC_Config::getValue('dbuser', false); @@ -229,8 +253,14 @@ class OC_Setup { // the anonymous user would take precedence when there is one. $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); + if (!$result) { + throw new DatabaseSetupException("MySQL user '" . "$name" . "'@'localhost' already exists","Delete this user from MySQL."); + } $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); + if (!$result) { + throw new DatabaseSetupException("MySQL user '" . "$name" . "'@'%' already exists","Delete this user from MySQL."); + } } private static function setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username) { diff --git a/lib/subadmin.php b/lib/subadmin.php index 9e83e6da430..8cda7240ac9 100644 --- a/lib/subadmin.php +++ b/lib/subadmin.php @@ -122,6 +122,11 @@ class OC_SubAdmin{ * @return bool */ public static function isSubAdmin($uid) { + // Check if the user is already an admin + if(OC_Group::inGroup($uid, 'admin' )) { + return true; + } + $stmt = OC_DB::prepare('SELECT COUNT(*) AS `count` FROM `*PREFIX*group_admin` WHERE `uid` = ?'); $result = $stmt->execute(array($uid)); $result = $result->fetchRow(); @@ -141,7 +146,7 @@ class OC_SubAdmin{ if(!self::isSubAdmin($subadmin)) { return false; } - if(OC_Group::inGroup($user, 'admin')) { + if(OC_User::isAdminUser($user)) { return false; } $accessiblegroups = self::getSubAdminsGroups($subadmin); diff --git a/lib/template.php b/lib/template.php index 04667d73a2c..f7124ebc09c 100644 --- a/lib/template.php +++ b/lib/template.php @@ -85,15 +85,25 @@ function human_file_size( $bytes ) { } function simple_file_size($bytes) { - $mbytes = round($bytes/(1024*1024), 1); - if($bytes == 0) { return '0'; } - else if($mbytes < 0.1) { return '< 0.1'; } - else if($mbytes > 1000) { return '> 1000'; } - else { return number_format($mbytes, 1); } + if ($bytes < 0) { + return '?'; + } + $mbytes = round($bytes / (1024 * 1024), 1); + if ($bytes == 0) { + return '0'; + } + if ($mbytes < 0.1) { + return '< 0.1'; + } + if ($mbytes > 1000) { + return '> 1000'; + } else { + return number_format($mbytes, 1); + } } function relative_modified_date($timestamp) { - $l=OC_L10N::get('lib'); + $l=OC_L10N::get('lib'); $timediff = time() - $timestamp; $diffminutes = round($timediff/60); $diffhours = round($diffminutes/60); diff --git a/lib/user.php b/lib/user.php index 80f88ca7052..fd0ed6ecd3a 100644 --- a/lib/user.php +++ b/lib/user.php @@ -260,17 +260,13 @@ class OC_User { /** * @brief Sets user id for session and triggers emit - * @returns true - * */ public static function setUserId($uid) { $_SESSION['user_id'] = $uid; - return true; } /** * @brief Logs the current user out and kills all the session data - * @returns true * * Logout, destroys session */ @@ -279,7 +275,6 @@ class OC_User { session_unset(); session_destroy(); OC_User::unsetMagicInCookie(); - return true; } /** @@ -300,6 +295,19 @@ class OC_User { } /** + * @brief Check if the user is an admin user + * @param $uid uid of the admin + * @returns bool + */ + public static function isAdminUser($uid) { + if(OC_Group::inGroup($uid, 'admin' )) { + return true; + } + return false; + } + + + /** * @brief get the user id of the user currently logged in. * @return string uid or false */ diff --git a/lib/util.php b/lib/util.php index 7b1de094ead..374baa43dbe 100755 --- a/lib/util.php +++ b/lib/util.php @@ -342,10 +342,7 @@ class OC_Util { * Check if the user is a admin, redirects to home if not */ public static function checkAdminUser() { - // Check if we are a user - self::checkLoggedIn(); - self::verifyUser(); - if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )) { + if( !OC_User::isAdminUser(OC_User::getUser())) { header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); exit(); } @@ -356,12 +353,6 @@ class OC_Util { * @return array $groups where the current user is subadmin */ public static function checkSubAdminUser() { - // Check if we are a user - self::checkLoggedIn(); - self::verifyUser(); - if(OC_Group::inGroup(OC_User::getUser(), 'admin')) { - return true; - } if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) { header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); exit(); @@ -370,40 +361,6 @@ class OC_Util { } /** - * Check if the user verified the login with his password in the last 15 minutes - * If not, the user will be shown a password verification page - */ - public static function verifyUser() { - if(OC_Config::getValue('enhancedauth', false) === true) { - // Check password to set session - if(isset($_POST['password'])) { - if (OC_User::login(OC_User::getUser(), $_POST["password"] ) === true) { - $_SESSION['verifiedLogin']=time() + OC_Config::getValue('enhancedauthtime', 15 * 60); - } - } - - // Check if the user verified his password - if(!isset($_SESSION['verifiedLogin']) OR $_SESSION['verifiedLogin'] < time()) { - OC_Template::printGuestPage("", "verify", array('username' => OC_User::getUser())); - exit(); - } - } - } - - /** - * Check if the user verified the login with his password - * @return bool - */ - public static function isUserVerified() { - if(OC_Config::getValue('enhancedauth', false) === true) { - if(!isset($_SESSION['verifiedLogin']) OR $_SESSION['verifiedLogin'] < time()) { - return false; - } - } - return true; - } - - /** * Redirect to the user default page */ public static function redirectToDefaultPage() { @@ -510,8 +467,11 @@ class OC_Util { * @return array with sanitized strings or a single sanitized string, depends on the input parameter. */ public static function sanitizeHTML( &$value ) { - if (is_array($value) || is_object($value)) array_walk_recursive($value, 'OC_Util::sanitizeHTML'); - else $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 + if (is_array($value) || is_object($value)) { + array_walk_recursive($value, 'OC_Util::sanitizeHTML'); + } else { + $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 + } return $value; } diff --git a/lib/vcategories.php b/lib/vcategories.php index 406a4eb1074..1700870f91f 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -763,4 +763,3 @@ class OC_VCategories { return array_search(strtolower($needle), array_map('strtolower', $haystack)); } } - |