diff options
author | Tom Needham <needham.thomas@gmail.com> | 2012-12-31 15:47:15 +0000 |
---|---|---|
committer | Tom Needham <needham.thomas@gmail.com> | 2012-12-31 15:47:15 +0000 |
commit | 6eb194b70284d527a182756f2c7a21f3d7dc1fe8 (patch) | |
tree | e70635e44cc4fccbbde34bed1a01fd50fcd183cf /lib | |
parent | 218a5ea89014322592bd8c4789d8500d42029b9f (diff) | |
parent | 329bddab481129b480ca187b694e507eff7fb125 (diff) | |
download | nextcloud-server-6eb194b70284d527a182756f2c7a21f3d7dc1fe8.tar.gz nextcloud-server-6eb194b70284d527a182756f2c7a21f3d7dc1fe8.zip |
Merge branch 'master' into ocs_api
Conflicts:
l10n/templates/core.pot
l10n/templates/files.pot
l10n/templates/files_encryption.pot
l10n/templates/files_external.pot
l10n/templates/files_sharing.pot
l10n/templates/files_versions.pot
l10n/templates/lib.pot
l10n/templates/settings.pot
l10n/templates/user_ldap.pot
l10n/templates/user_webdavauth.pot
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MDB2/Driver/sqlite3.php | 3 | ||||
-rw-r--r-- | lib/api.php | 78 | ||||
-rw-r--r-- | lib/base.php | 1411 | ||||
-rw-r--r-- | lib/files.php | 10 | ||||
-rw-r--r-- | lib/l10n/ar.php | 5 | ||||
-rw-r--r-- | lib/l10n/da.php | 7 | ||||
-rw-r--r-- | lib/l10n/hu_HU.php | 28 | ||||
-rw-r--r-- | lib/l10n/is.php | 34 | ||||
-rw-r--r-- | lib/l10n/mk.php | 28 | ||||
-rw-r--r-- | lib/l10n/nb_NO.php | 8 | ||||
-rw-r--r-- | lib/l10n/ro.php | 7 | ||||
-rw-r--r-- | lib/l10n/tr.php | 27 | ||||
-rw-r--r-- | lib/ocs/activity.php | 20 | ||||
-rw-r--r-- | lib/ocs/cloud.php | 80 | ||||
-rw-r--r-- | lib/ocs/person.php | 32 | ||||
-rw-r--r-- | lib/ocs/privatedata.php | 34 | ||||
-rw-r--r-- | lib/ocs/result.php | 44 | ||||
-rw-r--r-- | lib/public/api.php | 22 | ||||
-rw-r--r-- | lib/public/util.php | 36 | ||||
-rwxr-xr-x | lib/util.php | 102 |
20 files changed, 1142 insertions, 874 deletions
diff --git a/lib/MDB2/Driver/sqlite3.php b/lib/MDB2/Driver/sqlite3.php index fa4c91c1269..9839dafbce1 100644 --- a/lib/MDB2/Driver/sqlite3.php +++ b/lib/MDB2/Driver/sqlite3.php @@ -98,8 +98,7 @@ class MDB2_Driver_sqlite3 extends MDB2_Driver_Common if ($this->connection) { $native_code = $this->connection->lastErrorCode(); } - $native_msg = $this->_lasterror - ? html_entity_decode($this->_lasterror) : $this->connection->lastErrorMsg(); + $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 6c6c351b292..cb67e0c2a89 100644 --- a/lib/api.php +++ b/lib/api.php @@ -44,51 +44,51 @@ class OC_API { } /** - * api actions - */ + * api actions + */ protected static $actions = array(); /** - * registers an api call - * @param string $method the http method - * @param string $url the url to match - * @param callable $action the function to run - * @param string $app the id of the app registering the call - * @param int $authlevel the level of authentication required for the call - * @param array $defaults - * @param array $requirements - */ + * registers an api call + * @param string $method the http method + * @param string $url the url to match + * @param callable $action the function to run + * @param string $app the id of the app registering the call + * @param int $authLevel the level of authentication required for the call + * @param array $defaults + * @param array $requirements + */ public static function register($method, $url, $action, $app, - $authlevel = OC_API::USER_AUTH, + $authLevel = OC_API::USER_AUTH, $defaults = array(), - $requirements = array()){ + $requirements = array()) { $name = strtolower($method).$url; $name = str_replace(array('/', '{', '}'), '_', $name); - if(!isset(self::$actions[$name])){ + if(!isset(self::$actions[$name])) { OC::getRouter()->useCollection('ocs'); OC::getRouter()->create($name, $url) ->method($method) ->action('OC_API', 'call'); self::$actions[$name] = array(); } - self::$actions[$name] = array('app' => $app, 'action' => $action, 'authlevel' => $authlevel); + self::$actions[$name] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel); } /** - * handles an api call - * @param array $parameters - */ - public static function call($parameters){ + * handles an api call + * @param array $parameters + */ + public static function call($parameters) { // Prepare the request variables - if($_SERVER['REQUEST_METHOD'] == 'PUT'){ + if($_SERVER['REQUEST_METHOD'] == 'PUT') { parse_str(file_get_contents("php://input"), $parameters['_put']); } else if($_SERVER['REQUEST_METHOD'] == 'DELETE'){ parse_str(file_get_contents("php://input"), $parameters['_delete']); } $name = $parameters['_route']; // Check authentication and availability - if(self::isAuthorised(self::$actions[$name])){ - if(is_callable(self::$actions[$name]['action'])){ + if(self::isAuthorised(self::$actions[$name])) { + if(is_callable(self::$actions[$name]['action'])) { $response = call_user_func(self::$actions[$name]['action'], $parameters); } else { $response = new OC_OCS_Result(null, 998, 'Api method not found'); @@ -109,9 +109,9 @@ class OC_API { * @param array $action the action details as supplied to OC_API::register() * @return bool */ - private static function isAuthorised($action){ + private static function isAuthorised($action) { $level = $action['authlevel']; - switch($level){ + switch($level) { case OC_API::GUEST_AUTH: // Anyone can access return true; @@ -123,12 +123,12 @@ class OC_API { case OC_API::SUBADMIN_AUTH: // Check for subadmin $user = self::loginUser(); - if(!$user){ + if(!$user) { return false; } else { - $subadmin = OC_SubAdmin::isSubAdmin($user); + $subAdmin = OC_SubAdmin::isSubAdmin($user); $admin = OC_Group::inGroup($user, 'admin'); - if($subadmin || $admin){ + if($subAdmin || $admin) { return true; } else { return false; @@ -138,7 +138,7 @@ class OC_API { case OC_API::ADMIN_AUTH: // Check for admin $user = self::loginUser(); - if(!$user){ + if(!$user) { return false; } else { return OC_Group::inGroup($user, 'admin'); @@ -155,18 +155,18 @@ class OC_API { * http basic auth * @return string|false (username, or false on failure) */ - 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; + 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 - * @param string $format the format xml|json - */ - private static function respond($result, $format='xml'){ + * respond to a call + * @param int|array $result the result from the api method + * @param string $format the format xml|json + */ + private static function respond($result, $format='xml') { $response = array('ocs' => $result->getResult()); if ($format == 'json') { OC_JSON::encodedPrint($response); @@ -179,12 +179,10 @@ class OC_API { self::toXML($response, $writer); $writer->endDocument(); echo $writer->outputMemory(true); - } else { - var_dump($format, $response); } } - private static function toXML($array, $writer){ + private static function toXML($array, $writer) { foreach($array as $k => $v) { if (is_numeric($k)) { $k = 'element'; diff --git a/lib/base.php b/lib/base.php index 0b75f6f085e..94fb7979620 100644 --- a/lib/base.php +++ b/lib/base.php @@ -27,704 +27,731 @@ require_once 'public/constants.php'; * No, we can not put this class in its own file because it is used by * OC_autoload! */ -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 - ); - } - - 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 checkUpgrade() { - if(OC_Config::getValue('installed', false)) { - $installedVersion=OC_Config::getValue('version', '0.0.0'); - $currentVersion=implode('.', OC_Util::getVersion()); - if (version_compare($currentVersion, $installedVersion, '>')) { - // Check if the .htaccess is existing - this is needed for upgrades from really old ownCloud versions - if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { - if(!OC_Util::ishtaccessworking()) { - if(!file_exists(OC::$SERVERROOT.'/data/.htaccess')) { - OC_Setup::protectDataDirectory(); - } - } - } - OC_Log::write('core', 'starting upgrade from '.$installedVersion.' to '.$currentVersion, OC_Log::DEBUG); - $result=OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/db_structure.xml'); - if(!$result) { - echo 'Error while upgrading the database'; - die(); - } - if(file_exists(OC::$SERVERROOT."/config/config.php") and !is_writable(OC::$SERVERROOT."/config/config.php")) { - $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors', array(1=>array('error'=>"Can't write into config directory 'config'", 'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"))); - $tmpl->printPage(); - exit; - } - $minimizerCSS = new OC_Minimizer_CSS(); - $minimizerCSS->clearCache(); - $minimizerJS = new OC_Minimizer_JS(); - $minimizerJS->clearCache(); - OC_Config::setValue('version', implode('.', OC_Util::getVersion())); - OC_App::checkAppsRequirements(); - // load all apps to also upgrade enabled apps - OC_App::loadApps(); - } - } - } - - 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'); - - if( OC_Config::getValue( 'installed', false )) { - if( OC_Appconfig::getValue( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax' ) { - OC_Util::addScript( 'backgroundjobs' ); - } - } - - 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::checkInstalled(); - self::checkSSL(); - self::initSession(); - self::initTemplateEngine(); - 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; - } - } - } - - /** - * 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"])) { - 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"])) { - 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; - } +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 + ); + } + + 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 checkUpgrade() + { + if (OC_Config::getValue('installed', false)) { + $installedVersion = OC_Config::getValue('version', '0.0.0'); + $currentVersion = implode('.', OC_Util::getVersion()); + if (version_compare($currentVersion, $installedVersion, '>')) { + // Check if the .htaccess is existing - this is needed for upgrades from really old ownCloud versions + if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { + if (!OC_Util::ishtaccessworking()) { + if (!file_exists(OC::$SERVERROOT . '/data/.htaccess')) { + OC_Setup::protectDataDirectory(); + } + } + } + OC_Log::write('core', 'starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG); + $result = OC_DB::updateDbFromStructure(OC::$SERVERROOT . '/db_structure.xml'); + if (!$result) { + echo 'Error while upgrading the database'; + die(); + } + if (file_exists(OC::$SERVERROOT . "/config/config.php") and !is_writable(OC::$SERVERROOT . "/config/config.php")) { + $tmpl = new OC_Template('', 'error', 'guest'); + $tmpl->assign('errors', array(1 => array('error' => "Can't write into config directory 'config'", 'hint' => "You can usually fix this by giving the webserver user write access to the config directory in owncloud"))); + $tmpl->printPage(); + exit; + } + $minimizerCSS = new OC_Minimizer_CSS(); + $minimizerCSS->clearCache(); + $minimizerJS = new OC_Minimizer_JS(); + $minimizerJS->clearCache(); + OC_Config::setValue('version', implode('.', OC_Util::getVersion())); + OC_App::checkAppsRequirements(); + // load all apps to also upgrade enabled apps + OC_App::loadApps(); + } + } + } + + 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'); + + if (OC_Config::getValue('installed', false)) { + if (OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') { + OC_Util::addScript('backgroundjobs'); + } + } + + 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::checkInstalled(); + self::checkSSL(); + self::initSession(); + self::initTemplateEngine(); + 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); + } + } + + /** + * 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"])) { + 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; +if (!isset($RUNTIME_NOAPPS)) { + $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; - } +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; + } } OC::init(); diff --git a/lib/files.php b/lib/files.php index 152ed8f34a7..69097e41074 100644 --- a/lib/files.php +++ b/lib/files.php @@ -197,7 +197,12 @@ class OC_Files { } OC_Util::obEnd(); if($zip or OC_Filesystem::is_readable($filename)) { - header('Content-Disposition: attachment; filename="'.basename($filename).'"'); + if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { + header( 'Content-Disposition: attachment; filename="' . rawurlencode( basename($filename) ) . '"' ); + } else { + header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode( basename($filename) ) + . '; filename="' . rawurlencode( basename($filename) ) . '"' ); + } header('Content-Transfer-Encoding: binary'); OC_Response::disableCaching(); if($zip) { @@ -207,6 +212,7 @@ class OC_Files { self::addSendfileHeader($filename); }else{ header('Content-Type: '.OC_Filesystem::getMimeType($filename)); + header("Content-Length: ".OC_Filesystem::filesize($filename)); $storage = OC_Filesystem::getStorage($filename); if ($storage instanceof OC_Filestorage_Local) { self::addSendfileHeader(OC_Filesystem::getLocalFile($filename)); @@ -222,8 +228,6 @@ class OC_Files { die('403 Forbidden'); } if($only_header) { - if(!$zip) - header("Content-Length: ".OC_Filesystem::filesize($filename)); return ; } if($zip) { diff --git a/lib/l10n/ar.php b/lib/l10n/ar.php index 3ae226f04fd..77e02dd77b1 100644 --- a/lib/l10n/ar.php +++ b/lib/l10n/ar.php @@ -5,5 +5,8 @@ "Users" => "المستخدمين", "Authentication error" => "لم يتم التأكد من الشخصية بنجاح", "Files" => "الملفات", -"Text" => "معلومات إضافية" +"Text" => "معلومات إضافية", +"seconds ago" => "منذ ثواني", +"1 minute ago" => "منذ دقيقة", +"today" => "اليوم" ); diff --git a/lib/l10n/da.php b/lib/l10n/da.php index 7458b329782..a0ab1f17014 100644 --- a/lib/l10n/da.php +++ b/lib/l10n/da.php @@ -14,16 +14,21 @@ "Token expired. Please reload page." => "Adgang er udløbet. Genindlæs siden.", "Files" => "Filer", "Text" => "SMS", +"Images" => "Billeder", "seconds ago" => "sekunder siden", "1 minute ago" => "1 minut siden", "%d minutes ago" => "%d minutter siden", +"1 hour ago" => "1 time siden", +"%d hours ago" => "%d timer siden", "today" => "I dag", "yesterday" => "I går", "%d days ago" => "%d dage siden", "last month" => "Sidste måned", +"%d months ago" => "%d måneder siden", "last year" => "Sidste år", "years ago" => "år siden", "%s is available. Get <a href=\"%s\">more information</a>" => "%s er tilgængelig. Få <a href=\"%s\">mere information</a>", "up to date" => "opdateret", -"updates check is disabled" => "Check for opdateringer er deaktiveret" +"updates check is disabled" => "Check for opdateringer er deaktiveret", +"Could not find category \"%s\"" => "Kunne ikke finde kategorien \"%s\"" ); diff --git a/lib/l10n/hu_HU.php b/lib/l10n/hu_HU.php index 63704a978c5..3dcf0646d06 100644 --- a/lib/l10n/hu_HU.php +++ b/lib/l10n/hu_HU.php @@ -5,22 +5,30 @@ "Users" => "Felhasználók", "Apps" => "Alkalmazások", "Admin" => "Admin", -"ZIP download is turned off." => "ZIP-letöltés letiltva", -"Files need to be downloaded one by one." => "A file-okat egyenként kell letölteni", -"Back to Files" => "Vissza a File-okhoz", -"Selected files too large to generate zip file." => "Túl nagy file-ok a zip-generáláshoz", +"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.", "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ítsd az oldalt.", +"Token expired. Please reload page." => "A token lejárt. Frissítse az oldalt.", "Files" => "Fájlok", "Text" => "Szöveg", -"seconds ago" => "másodperccel ezelőtt", -"1 minute ago" => "1 perccel ezelőtt", -"%d minutes ago" => "%d perccel ezelőtt", +"Images" => "Képek", +"seconds ago" => "másodperce", +"1 minute ago" => "1 perce", +"%d minutes ago" => "%d perce", +"1 hour ago" => "1 órája", +"%d hours ago" => "%d órája", "today" => "ma", "yesterday" => "tegnap", -"%d days ago" => "%d évvel ezelőtt", +"%d days ago" => "%d napja", "last month" => "múlt hónapban", +"%d months ago" => "%d hónapja", "last year" => "tavaly", -"years ago" => "évvel ezelőtt" +"years ago" => "éve", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s elérhető. <a href=\"%s\">További információ</a>.", +"up to date" => "a legfrissebb változat", +"updates check is disabled" => "A frissitések ellenőrzése nincs engedélyezve.", +"Could not find category \"%s\"" => "Ez a kategória nem található: \"%s\"" ); diff --git a/lib/l10n/is.php b/lib/l10n/is.php new file mode 100644 index 00000000000..8fdb45a05cd --- /dev/null +++ b/lib/l10n/is.php @@ -0,0 +1,34 @@ +<?php $TRANSLATIONS = array( +"Help" => "Hjálp", +"Personal" => "Um mig", +"Settings" => "Stillingar", +"Users" => "Notendur", +"Apps" => "Forrit", +"Admin" => "Stjórnun", +"ZIP download is turned off." => "Slökkt á ZIP niðurhali.", +"Files need to be downloaded one by one." => "Skrárnar verður að sækja eina og eina", +"Back to Files" => "Aftur í skrár", +"Selected files too large to generate zip file." => "Valdar skrár eru of stórar til að búa til ZIP skrá.", +"Application is not enabled" => "Forrit ekki virkt", +"Authentication error" => "Villa við auðkenningu", +"Token expired. Please reload page." => "Auðkenning útrunnin. Vinsamlegast skráðu þig aftur inn.", +"Files" => "Skrár", +"Text" => "Texti", +"Images" => "Myndir", +"seconds ago" => "sek.", +"1 minute ago" => "Fyrir 1 mínútu", +"%d minutes ago" => "fyrir %d mínútum", +"1 hour ago" => "Fyrir 1 klst.", +"%d hours ago" => "fyrir %d klst.", +"today" => "í dag", +"yesterday" => "í gær", +"%d days ago" => "fyrir %d dögum", +"last month" => "síðasta mánuði", +"%d months ago" => "fyrir %d mánuðum", +"last year" => "síðasta ári", +"years ago" => "einhverjum árum", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s er í boði. Sækja <a href=\"%s\">meiri upplýsingar</a>", +"up to date" => "nýjasta útgáfa", +"updates check is disabled" => "uppfærslupróf er ekki virkjað", +"Could not find category \"%s\"" => "Fann ekki flokkinn \"%s\"" +); diff --git a/lib/l10n/mk.php b/lib/l10n/mk.php index a06073e808a..5b3efffb22a 100644 --- a/lib/l10n/mk.php +++ b/lib/l10n/mk.php @@ -3,6 +3,32 @@ "Personal" => "Лично", "Settings" => "Параметри", "Users" => "Корисници", +"Apps" => "Аппликации", +"Admin" => "Админ", +"ZIP download is turned off." => "Преземање во ZIP е исклучено", +"Files need to be downloaded one by one." => "Датотеките треба да се симнат една по една.", +"Back to Files" => "Назад кон датотеки", +"Selected files too large to generate zip file." => "Избраните датотеки се преголеми за да се генерира zip.", +"Application is not enabled" => "Апликацијата не е овозможена", +"Authentication error" => "Грешка во автентикација", +"Token expired. Please reload page." => "Жетонот е истечен. Ве молам превчитајте ја страницата.", "Files" => "Датотеки", -"Text" => "Текст" +"Text" => "Текст", +"Images" => "Слики", +"seconds ago" => "пред секунди", +"1 minute ago" => "пред 1 минута", +"%d minutes ago" => "пред %d минути", +"1 hour ago" => "пред 1 час", +"%d hours ago" => "пред %d часови", +"today" => "денеска", +"yesterday" => "вчера", +"%d days ago" => "пред %d денови", +"last month" => "минатиот месец", +"%d months ago" => "пред %d месеци", +"last year" => "минатата година", +"years ago" => "пред години", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s е достапно. Земи <a href=\"%s\">повеќе информации</a>", +"up to date" => "ажурно", +"updates check is disabled" => "проверката за ажурирања е оневозможена", +"Could not find category \"%s\"" => "Не можам да најдам категорија „%s“" ); diff --git a/lib/l10n/nb_NO.php b/lib/l10n/nb_NO.php index b01e0979889..01144672caa 100644 --- a/lib/l10n/nb_NO.php +++ b/lib/l10n/nb_NO.php @@ -16,15 +16,19 @@ "Text" => "Tekst", "Images" => "Bilder", "seconds ago" => "sekunder siden", -"1 minute ago" => "1 minuitt siden", +"1 minute ago" => "1 minutt siden", "%d minutes ago" => "%d minutter siden", +"1 hour ago" => "1 time siden", +"%d hours ago" => "%d timer siden", "today" => "i dag", "yesterday" => "i går", "%d days ago" => "%d dager siden", "last month" => "forrige måned", +"%d months ago" => "%d måneder siden", "last year" => "i fjor", "years ago" => "år siden", "%s is available. Get <a href=\"%s\">more information</a>" => "%s er tilgjengelig. Få <a href=\"%s\">mer informasjon</a>", "up to date" => "oppdatert", -"updates check is disabled" => "versjonssjekk er avslått" +"updates check is disabled" => "versjonssjekk er avslått", +"Could not find category \"%s\"" => "Kunne ikke finne kategori \"%s\"" ); diff --git a/lib/l10n/ro.php b/lib/l10n/ro.php index 27912550e17..d3ce066c8c1 100644 --- a/lib/l10n/ro.php +++ b/lib/l10n/ro.php @@ -14,16 +14,21 @@ "Token expired. Please reload page." => "Token expirat. Te rugăm să reîncarci pagina.", "Files" => "Fișiere", "Text" => "Text", +"Images" => "Imagini", "seconds ago" => "secunde în urmă", "1 minute ago" => "1 minut în urmă", "%d minutes ago" => "%d minute în urmă", +"1 hour ago" => "Acum o ora", +"%d hours ago" => "%d ore in urma", "today" => "astăzi", "yesterday" => "ieri", "%d days ago" => "%d zile în urmă", "last month" => "ultima lună", +"%d months ago" => "%d luni in urma", "last year" => "ultimul an", "years ago" => "ani în urmă", "%s is available. Get <a href=\"%s\">more information</a>" => "%s este disponibil. Vezi <a href=\"%s\">mai multe informații</a>", "up to date" => "la zi", -"updates check is disabled" => "verificarea după actualizări este dezactivată" +"updates check is disabled" => "verificarea după actualizări este dezactivată", +"Could not find category \"%s\"" => "Cloud nu a gasit categoria \"%s\"" ); diff --git a/lib/l10n/tr.php b/lib/l10n/tr.php index 69067d7ec57..9b7f1815fa3 100644 --- a/lib/l10n/tr.php +++ b/lib/l10n/tr.php @@ -3,7 +3,32 @@ "Personal" => "Kişisel", "Settings" => "Ayarlar", "Users" => "Kullanıcılar", +"Apps" => "Uygulamalar", +"Admin" => "Yönetici", +"ZIP download is turned off." => "ZIP indirmeleri kapatılmıştır.", +"Files need to be downloaded one by one." => "Dosyaların birer birer indirilmesi gerekmektedir.", +"Back to Files" => "Dosyalara dön", +"Selected files too large to generate zip file." => "Seçilen dosyalar bir zip dosyası oluşturmak için fazla büyüktür.", +"Application is not enabled" => "Uygulama etkinleştirilmedi", "Authentication error" => "Kimlik doğrulama hatası", +"Token expired. Please reload page." => "Jetonun süresi geçti. Lütfen sayfayı yenileyin.", "Files" => "Dosyalar", -"Text" => "Metin" +"Text" => "Metin", +"Images" => "Resimler", +"seconds ago" => "saniye önce", +"1 minute ago" => "1 dakika önce", +"%d minutes ago" => "%d dakika önce", +"1 hour ago" => "1 saat önce", +"%d hours ago" => "%d saat önce", +"today" => "bugün", +"yesterday" => "dün", +"%d days ago" => "%d gün önce", +"last month" => "geçen ay", +"%d months ago" => "%d ay önce", +"last year" => "geçen yıl", +"years ago" => "yıl önce", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s kullanılabilir durumda. <a href=\"%s\">Daha fazla bilgi</a> alın", +"up to date" => "güncel", +"updates check is disabled" => "güncelleme kontrolü kapalı", +"Could not find category \"%s\"" => "\"%s\" kategorisi bulunamadı" ); diff --git a/lib/ocs/activity.php b/lib/ocs/activity.php index 07b571665ec..c30e21018d3 100644 --- a/lib/ocs/activity.php +++ b/lib/ocs/activity.php @@ -1,4 +1,24 @@ <?php +/** +* ownCloud +* +* @author Frank Karlitschek +* @copyright 2012 Frank Karlitschek frank@owncloud.org +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ class OC_OCS_Activity { diff --git a/lib/ocs/cloud.php b/lib/ocs/cloud.php index b5cfbc295e8..21095ec91e9 100644 --- a/lib/ocs/cloud.php +++ b/lib/ocs/cloud.php @@ -1,75 +1,97 @@ <?php +/** +* ownCloud +* +* @author Frank Karlitschek +* @author Tom Needham +* @copyright 2012 Frank Karlitschek frank@owncloud.org +* @copyright 2012 Tom Needham tom@owncloud.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ class OC_OCS_Cloud { - public static function getSystemWebApps($parameters){ + public static function getSystemWebApps($parameters) { OC_Util::checkLoggedIn(); $apps = OC_App::getEnabledApps(); $values = array(); foreach($apps as $app) { $info = OC_App::getAppInfo($app); if(isset($info['standalone'])) { - $newvalue = array('name'=>$info['name'],'url'=>OC_Helper::linkToAbsolute($app,''),'icon'=>''); - $values[] = $newvalue; + $newValue = array('name'=>$info['name'],'url'=>OC_Helper::linkToAbsolute($app,''),'icon'=>''); + $values[] = $newValue; } } return new OC_OCS_Result($values); } - public static function getUserQuota($parameters){ + public static function getUserQuota($parameters) { $user = OC_User::getUser(); if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) { - if(OC_User::userExists($parameters['user'])){ + if(OC_User::userExists($parameters['user'])) { // calculate the disc space - $user_dir = '/'.$parameters['user'].'/files'; - OC_Filesystem::init($user_dir); - $rootInfo=OC_FileCache::get(''); - $sharedInfo=OC_FileCache::get('/Shared'); - $used=$rootInfo['size']-$sharedInfo['size']; - $free=OC_Filesystem::free_space(); - $total=$free+$used; - if($total==0) $total=1; // prevent division by zero - $relative=round(($used/$total)*10000)/100; + $userDir = '/'.$parameters['user'].'/files'; + OC_Filesystem::init($useDir); + $rootInfo = OC_FileCache::get(''); + $sharedInfo = OC_FileCache::get('/Shared'); + $used = $rootInfo['size'] - $sharedInfo['size']; + $free = OC_Filesystem::free_space(); + $total = $free + $used; + if($total===0) $total = 1; // prevent division by zero + $relative = round(($used/$total)*10000)/100; - $xml=array(); - $xml['quota']=$total; - $xml['free']=$free; - $xml['used']=$used; - $xml['relative']=$relative; + $xml = array(); + $xml['quota'] = $total; + $xml['free'] = $free; + $xml['used'] = $used; + $xml['relative'] = $relative; return new OC_OCS_Result($xml); - }else{ + } else { return new OC_OCS_Result(null, 300); } - }else{ + } else { return new OC_OCS_Result(null, 300); } } - public static function getUserPublickey($parameters){ + public static function getUserPublickey($parameters) { - if(OC_User::userExists($parameters['user'])){ + if(OC_User::userExists($parameters['user'])) { // calculate the disc space // TODO return new OC_OCS_Result(array()); - }else{ + } else { return new OC_OCS_Result(null, 300); } } - public static function getUserPrivatekey($parameters){ + public static function getUserPrivatekey($parameters) { $user = OC_User::getUser(); if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) { - if(OC_User::userExists($user)){ + if(OC_User::userExists($user)) { // calculate the disc space - $txt='this is the private key of '.$parameters['user']; + $txt = 'this is the private key of '.$parameters['user']; echo($txt); - }else{ + } else { return new OC_OCS_Result(null, 300, 'User does not exist'); } - }else{ + } else { return new OC_OCS_Result('null', 300, 'You don´t have permission to access this ressource.'); } } diff --git a/lib/ocs/person.php b/lib/ocs/person.php index b5f07d88ae1..169cc8211db 100644 --- a/lib/ocs/person.php +++ b/lib/ocs/person.php @@ -1,18 +1,40 @@ <?php +/** +* ownCloud +* +* @author Frank Karlitschek +* @author Tom Needham +* @copyright 2012 Frank Karlitschek frank@owncloud.org +* @copyright 2012 Tom Needham tom@owncloud.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ class OC_OCS_Person { - public static function check($parameters){ + public static function check($parameters) { $login = isset($_POST['login']) ? $_POST['login'] : false; $password = isset($_POST['password']) ? $_POST['password'] : false; - if($login && $password){ - if(OC_User::checkPassword($login,$password)){ + if($login && $password) { + if(OC_User::checkPassword($login, $password)) { $xml['person']['personid'] = $login; return new OC_OCS_Result($xml); - }else{ + } else { return new OC_OCS_Result(null, 102); } - }else{ + } else { return new OC_OCS_Result(null, 101); } } diff --git a/lib/ocs/privatedata.php b/lib/ocs/privatedata.php index 09d636bd733..e01ed5e8b07 100644 --- a/lib/ocs/privatedata.php +++ b/lib/ocs/privatedata.php @@ -1,8 +1,30 @@ <?php +/** +* ownCloud +* +* @author Frank Karlitschek +* @author Tom Needham +* @copyright 2012 Frank Karlitschek frank@owncloud.org +* @copyright 2012 Tom Needham tom@owncloud.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ class OC_OCS_Privatedata { - public static function get($parameters){ + public static function get($parameters) { OC_Util::checkLoggedIn(); $user = OC_User::getUser(); $app = addslashes(strip_tags($parameters['app'])); @@ -18,26 +40,26 @@ class OC_OCS_Privatedata { //TODO: replace 'privatedata' with 'attribute' once a new libattice has been released that works with it } - public static function set($parameters){ + public static function set($parameters) { OC_Util::checkLoggedIn(); $user = OC_User::getUser(); $app = addslashes(strip_tags($parameters['app'])); $key = addslashes(strip_tags($parameters['key'])); $value = OC_OCS::readData('post', 'value', 'text'); - if(OC_Preferences::setValue($user,$app,$key,$value)){ + if(OC_Preferences::setValue($user, $app, $key, $value)){ return new OC_OCS_Result(null, 100); } } - public static function delete($parameters){ + public static function delete($parameters) { OC_Util::checkLoggedIn(); $user = OC_User::getUser(); $app = addslashes(strip_tags($parameters['app'])); $key = addslashes(strip_tags($parameters['key'])); - if($key=="" or $app==""){ + if($key==="" or $app==="") { return new OC_OCS_Result(null, 101); //key and app are NOT optional here } - if(OC_Preferences::deleteKey($user,$app,$key)){ + if(OC_Preferences::deleteKey($user, $app, $key)) { return new OC_OCS_Result(null, 100); } } diff --git a/lib/ocs/result.php b/lib/ocs/result.php index 4531da5ae0d..b08d911f785 100644 --- a/lib/ocs/result.php +++ b/lib/ocs/result.php @@ -1,16 +1,36 @@ <?php +/** +* ownCloud +* +* @author Tom Needham +* @copyright 2012 Tom Needham tom@owncloud.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ class OC_OCS_Result{ - private $data, $message, $statuscode, $items, $perpage; + private $data, $message, $statusCode, $items, $perPage; /** * create the OCS_Result object * @param $data mixed the data to return */ - public function __construct($data=null, $code=100, $message=null){ + public function __construct($data=null, $code=100, $message=null) { $this->data = $data; - $this->statuscode = $code; + $this->statusCode = $code; $this->message = $message; } @@ -18,7 +38,7 @@ class OC_OCS_Result{ * optionally set the total number of items available * @param $items int */ - public function setTotalItems(int $items){ + public function setTotalItems(int $items) { $this->items = $items; } @@ -26,25 +46,25 @@ class OC_OCS_Result{ * optionally set the the number of items per page * @param $items int */ - public function setItemsPerPage(int $items){ - $this->perpage = $items; + public function setItemsPerPage(int $items) { + $this->perPage = $items; } /** * returns the data associated with the api result * @return array */ - public function getResult(){ + public function getResult() { $return = array(); $return['meta'] = array(); - $return['meta']['status'] = ($this->statuscode === 100) ? 'ok' : 'failure'; - $return['meta']['statuscode'] = $this->statuscode; + $return['meta']['status'] = ($this->statusCode === 100) ? 'ok' : 'failure'; + $return['meta']['statuscode'] = $this->statusCode; $return['meta']['message'] = $this->message; - if(isset($this->items)){ + if(isset($this->items)) { $return['meta']['totalitems'] = $this->items; } - if(isset($this->perpage)){ - $return['meta']['itemsperpage'] = $this->perpage; + if(isset($this->perPage)) { + $return['meta']['itemsperpage'] = $this->perPage; } $return['data'] = $this->data; // Return the result data. diff --git a/lib/public/api.php b/lib/public/api.php index 9d6d1153e6c..a85daa1935c 100644 --- a/lib/public/api.php +++ b/lib/public/api.php @@ -28,17 +28,17 @@ namespace OCP; class API { /** - * registers an api call - * @param string $method the http method - * @param string $url the url to match - * @param callable $action the function to run - * @param string $app the id of the app registering the call - * @param int $authlevel the level of authentication required for the call (See OC_API constants) - * @param array $defaults - * @param array $requirements - */ - 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); + * registers an api call + * @param string $method the http method + * @param string $url the url to match + * @param callable $action the function to run + * @param string $app the id of the app registering the call + * @param int $authLevel the level of authentication required for the call (See OC_API constants) + * @param array $defaults + * @param array $requirements + */ + 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/util.php b/lib/public/util.php index 7b5b1abbded..af782b01483 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -173,6 +173,42 @@ class Util { } /** + * @brief returns the server hostname + * @returns the server hostname + * + * Returns the server host name without an eventual port number + */ + public static function getServerHostName() { + $host_name = self::getServerHost(); + // strip away port number (if existing) + $colon_pos = strpos($host_name, ':'); + if ($colon_pos != FALSE) { + $host_name = substr($host_name, 0, $colon_pos); + } + return $host_name; + } + + /** + * @brief Returns the default email address + * @param $user_part the user part of the address + * @returns the default email address + * + * Assembles a default email address (using the server hostname + * and the given user part, and returns it + * Example: when given lostpassword-noreply as $user_part param, + * and is currently accessed via http(s)://example.com/, + * it would return 'lostpassword-noreply@example.com' + */ + public static function getDefaultEmailAddress($user_part) { + $host_name = self::getServerHostName(); + // handle localhost installations + if ($host_name === 'localhost') { + $host_name = "example.com"; + } + return $user_part.'@'.$host_name; + } + + /** * @brief Returns the server protocol * @returns the server protocol * diff --git a/lib/util.php b/lib/util.php index fc50123b4fe..4170de2125a 100755 --- a/lib/util.php +++ b/lib/util.php @@ -166,7 +166,7 @@ class OC_Util { * @param int timestamp $timestamp * @param bool dateOnly option to ommit time from the result */ - public static function formatDate( $timestamp, $dateOnly=false) { + public static function formatDate( $timestamp, $dateOnly=false) { if(isset($_SESSION['timezone'])) {//adjust to clients timezone if we know it $systemTimeZone = intval(date('O')); $systemTimeZone=(round($systemTimeZone/100, 0)*60)+($systemTimeZone%100); @@ -176,37 +176,8 @@ class OC_Util { } $l=OC_L10N::get('lib'); return $l->l($dateOnly ? 'date' : 'datetime', $timestamp); - } - - /** - * Shows a pagenavi widget where you can jump to different pages. - * - * @param int $pagecount - * @param int $page - * @param string $url - * @return OC_Template - */ - public static function getPageNavi($pagecount, $page, $url) { - - $pagelinkcount=8; - if ($pagecount>1) { - $pagestart=$page-$pagelinkcount; - if($pagestart<0) $pagestart=0; - $pagestop=$page+$pagelinkcount; - if($pagestop>$pagecount) $pagestop=$pagecount; - - $tmpl = new OC_Template( '', 'part.pagenavi', '' ); - $tmpl->assign('page', $page); - $tmpl->assign('pagecount', $pagecount); - $tmpl->assign('pagestart', $pagestart); - $tmpl->assign('pagestop', $pagestop); - $tmpl->assign('url', $url); - return $tmpl; - } } - - /** * check if the current server configuration is suitable for ownCloud * @return array arrays with error messages and hints @@ -583,6 +554,18 @@ class OC_Util { /** + * Check if the setlocal call doesn't work. This can happen if the right local packages are not available on the server. + */ + public static function issetlocaleworking() { + $result=setlocale(LC_ALL, 'en_US.UTF-8'); + if($result==false) { + return(false); + }else{ + return(true); + } + } + + /** * Check if the ownCloud server can connect to the internet */ public static function isinternetconnectionworking() { @@ -684,34 +667,39 @@ class OC_Util { * If not, file_get_element is used. */ - public static function getUrlContent($url){ + public static function getUrlContent($url){ - if (function_exists('curl_init')) { - - $curl = curl_init(); - - curl_setopt($curl, CURLOPT_HEADER, 0); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); - $data = curl_exec($curl); - curl_close($curl); - - } else { - - $ctx = stream_context_create( - array( - 'http' => array( - 'timeout' => 10 - ) - ) - ); - $data=@file_get_contents($url, 0, $ctx); - - } - - return $data; + if (function_exists('curl_init')) { + + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_HEADER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); + if(OC_Config::getValue('proxy','')<>'') { + curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy')); + } + if(OC_Config::getValue('proxyuserpwd','')<>'') { + curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd')); + } + $data = curl_exec($curl); + curl_close($curl); + + } else { + + $ctx = stream_context_create( + array( + 'http' => array( + 'timeout' => 10 + ) + ) + ); + $data=@file_get_contents($url, 0, $ctx); + + } + return $data; } } |