@@ -29,64 +29,64 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | try { |
| 31 | 31 | |
| 32 | - require_once __DIR__ . '/lib/base.php'; |
|
| 33 | - if (\OCP\Util::needUpgrade()) { |
|
| 34 | - // since the behavior of apps or remotes are unpredictable during |
|
| 35 | - // an upgrade, return a 503 directly |
|
| 36 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 37 | - OC_Template::printErrorPage('Service unavailable'); |
|
| 38 | - exit; |
|
| 39 | - } |
|
| 32 | + require_once __DIR__ . '/lib/base.php'; |
|
| 33 | + if (\OCP\Util::needUpgrade()) { |
|
| 34 | + // since the behavior of apps or remotes are unpredictable during |
|
| 35 | + // an upgrade, return a 503 directly |
|
| 36 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 37 | + OC_Template::printErrorPage('Service unavailable'); |
|
| 38 | + exit; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - OC::checkMaintenanceMode(); |
|
| 42 | - $request = \OC::$server->getRequest(); |
|
| 43 | - $pathInfo = $request->getPathInfo(); |
|
| 41 | + OC::checkMaintenanceMode(); |
|
| 42 | + $request = \OC::$server->getRequest(); |
|
| 43 | + $pathInfo = $request->getPathInfo(); |
|
| 44 | 44 | |
| 45 | - if (!$pathInfo && $request->getParam('service', '') === '') { |
|
| 46 | - header('HTTP/1.0 404 Not Found'); |
|
| 47 | - exit; |
|
| 48 | - } elseif ($request->getParam('service', '')) { |
|
| 49 | - $service = $request->getParam('service', ''); |
|
| 50 | - } else { |
|
| 51 | - $pathInfo = trim($pathInfo, '/'); |
|
| 52 | - list($service) = explode('/', $pathInfo); |
|
| 53 | - } |
|
| 54 | - $file = OCP\Config::getAppValue('core', 'public_' . strip_tags($service)); |
|
| 55 | - if (is_null($file)) { |
|
| 56 | - header('HTTP/1.0 404 Not Found'); |
|
| 57 | - exit; |
|
| 58 | - } |
|
| 45 | + if (!$pathInfo && $request->getParam('service', '') === '') { |
|
| 46 | + header('HTTP/1.0 404 Not Found'); |
|
| 47 | + exit; |
|
| 48 | + } elseif ($request->getParam('service', '')) { |
|
| 49 | + $service = $request->getParam('service', ''); |
|
| 50 | + } else { |
|
| 51 | + $pathInfo = trim($pathInfo, '/'); |
|
| 52 | + list($service) = explode('/', $pathInfo); |
|
| 53 | + } |
|
| 54 | + $file = OCP\Config::getAppValue('core', 'public_' . strip_tags($service)); |
|
| 55 | + if (is_null($file)) { |
|
| 56 | + header('HTTP/1.0 404 Not Found'); |
|
| 57 | + exit; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $parts = explode('/', $file, 2); |
|
| 61 | - $app = $parts[0]; |
|
| 60 | + $parts = explode('/', $file, 2); |
|
| 61 | + $app = $parts[0]; |
|
| 62 | 62 | |
| 63 | - // Load all required applications |
|
| 64 | - \OC::$REQUESTEDAPP = $app; |
|
| 65 | - OC_App::loadApps(array('authentication')); |
|
| 66 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
| 63 | + // Load all required applications |
|
| 64 | + \OC::$REQUESTEDAPP = $app; |
|
| 65 | + OC_App::loadApps(array('authentication')); |
|
| 66 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
| 67 | 67 | |
| 68 | - if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
| 69 | - throw new Exception('App not installed: ' . $app); |
|
| 70 | - } |
|
| 71 | - OC_App::loadApp($app); |
|
| 72 | - OC_User::setIncognitoMode(true); |
|
| 68 | + if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
| 69 | + throw new Exception('App not installed: ' . $app); |
|
| 70 | + } |
|
| 71 | + OC_App::loadApp($app); |
|
| 72 | + OC_User::setIncognitoMode(true); |
|
| 73 | 73 | |
| 74 | - $baseuri = OC::$WEBROOT . '/public.php/' . $service . '/'; |
|
| 74 | + $baseuri = OC::$WEBROOT . '/public.php/' . $service . '/'; |
|
| 75 | 75 | |
| 76 | - require_once OC_App::getAppPath($app) . '/' . $parts[1]; |
|
| 76 | + require_once OC_App::getAppPath($app) . '/' . $parts[1]; |
|
| 77 | 77 | |
| 78 | 78 | } catch (Exception $ex) { |
| 79 | - if ($ex instanceof \OC\ServiceUnavailableException) { |
|
| 80 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 81 | - } else { |
|
| 82 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 83 | - } |
|
| 84 | - //show the user a detailed error page |
|
| 85 | - \OC::$server->getLogger()->logException($ex, ['app' => 'public']); |
|
| 86 | - OC_Template::printExceptionErrorPage($ex); |
|
| 79 | + if ($ex instanceof \OC\ServiceUnavailableException) { |
|
| 80 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 81 | + } else { |
|
| 82 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 83 | + } |
|
| 84 | + //show the user a detailed error page |
|
| 85 | + \OC::$server->getLogger()->logException($ex, ['app' => 'public']); |
|
| 86 | + OC_Template::printExceptionErrorPage($ex); |
|
| 87 | 87 | } catch (Error $ex) { |
| 88 | - //show the user a detailed error page |
|
| 89 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 90 | - \OC::$server->getLogger()->logException($ex, ['app' => 'public']); |
|
| 91 | - OC_Template::printExceptionErrorPage($ex); |
|
| 88 | + //show the user a detailed error page |
|
| 89 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 90 | + \OC::$server->getLogger()->logException($ex, ['app' => 'public']); |
|
| 91 | + OC_Template::printExceptionErrorPage($ex); |
|
| 92 | 92 | } |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | require_once __DIR__ . '/../lib/base.php'; |
| 33 | 33 | |
| 34 | 34 | if (\OCP\Util::needUpgrade() |
| 35 | - || \OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 36 | - // since the behavior of apps or remotes are unpredictable during |
|
| 37 | - // an upgrade, return a 503 directly |
|
| 38 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 39 | - $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable'); |
|
| 40 | - OC_API::respond($response, OC_API::requestedFormat()); |
|
| 41 | - exit; |
|
| 35 | + || \OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 36 | + // since the behavior of apps or remotes are unpredictable during |
|
| 37 | + // an upgrade, return a 503 directly |
|
| 38 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 39 | + $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable'); |
|
| 40 | + OC_API::respond($response, OC_API::requestedFormat()); |
|
| 41 | + exit; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
@@ -49,48 +49,48 @@ discard block |
||
| 49 | 49 | * We first try the old routes since the appframework triggers more login stuff. |
| 50 | 50 | */ |
| 51 | 51 | try { |
| 52 | - OC_App::loadApps(['session']); |
|
| 53 | - OC_App::loadApps(['authentication']); |
|
| 54 | - // load all apps to get all api routes properly setup |
|
| 55 | - OC_App::loadApps(); |
|
| 52 | + OC_App::loadApps(['session']); |
|
| 53 | + OC_App::loadApps(['authentication']); |
|
| 54 | + // load all apps to get all api routes properly setup |
|
| 55 | + OC_App::loadApps(); |
|
| 56 | 56 | |
| 57 | - // force language as given in the http request |
|
| 58 | - \OC::$server->getL10NFactory()->setLanguageFromRequest(); |
|
| 57 | + // force language as given in the http request |
|
| 58 | + \OC::$server->getL10NFactory()->setLanguageFromRequest(); |
|
| 59 | 59 | |
| 60 | - OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo()); |
|
| 61 | - return; |
|
| 60 | + OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo()); |
|
| 61 | + return; |
|
| 62 | 62 | } catch (ResourceNotFoundException $e) { |
| 63 | - // Fall through the not found |
|
| 63 | + // Fall through the not found |
|
| 64 | 64 | } catch (MethodNotAllowedException $e) { |
| 65 | - OC_API::setContentType(); |
|
| 66 | - OC_Response::setStatus(405); |
|
| 67 | - exit(); |
|
| 65 | + OC_API::setContentType(); |
|
| 66 | + OC_Response::setStatus(405); |
|
| 67 | + exit(); |
|
| 68 | 68 | } catch (Exception $ex) { |
| 69 | - OC_API::respond($ex->getResult(), OC_API::requestedFormat()); |
|
| 70 | - exit(); |
|
| 69 | + OC_API::respond($ex->getResult(), OC_API::requestedFormat()); |
|
| 70 | + exit(); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /* |
| 74 | 74 | * Try the appframework routes |
| 75 | 75 | */ |
| 76 | 76 | try { |
| 77 | - if(!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 78 | - OC::handleLogin(\OC::$server->getRequest()); |
|
| 79 | - } |
|
| 80 | - OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo()); |
|
| 77 | + if(!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 78 | + OC::handleLogin(\OC::$server->getRequest()); |
|
| 79 | + } |
|
| 80 | + OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo()); |
|
| 81 | 81 | } catch (ResourceNotFoundException $e) { |
| 82 | - OC_API::setContentType(); |
|
| 83 | - OC_OCS::notFound(); |
|
| 82 | + OC_API::setContentType(); |
|
| 83 | + OC_OCS::notFound(); |
|
| 84 | 84 | } catch (MethodNotAllowedException $e) { |
| 85 | - OC_API::setContentType(); |
|
| 86 | - OC_Response::setStatus(405); |
|
| 85 | + OC_API::setContentType(); |
|
| 86 | + OC_Response::setStatus(405); |
|
| 87 | 87 | } catch (\OC\OCS\Exception $ex) { |
| 88 | - OC_API::respond($ex->getResult(), OC_API::requestedFormat()); |
|
| 88 | + OC_API::respond($ex->getResult(), OC_API::requestedFormat()); |
|
| 89 | 89 | } catch (\OC\User\LoginException $e) { |
| 90 | - OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised')); |
|
| 90 | + OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised')); |
|
| 91 | 91 | } catch (\Exception $e) { |
| 92 | - \OC::$server->getLogger()->logException($e); |
|
| 93 | - OC_API::setContentType(); |
|
| 94 | - OC_OCS::notFound(); |
|
| 92 | + \OC::$server->getLogger()->logException($e); |
|
| 93 | + OC_API::setContentType(); |
|
| 94 | + OC_OCS::notFound(); |
|
| 95 | 95 | } |
| 96 | 96 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | */ |
| 31 | 31 | |
| 32 | -require_once __DIR__ . '/../lib/base.php'; |
|
| 32 | +require_once __DIR__.'/../lib/base.php'; |
|
| 33 | 33 | |
| 34 | 34 | if (\OCP\Util::needUpgrade() |
| 35 | 35 | || \OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * Try the appframework routes |
| 75 | 75 | */ |
| 76 | 76 | try { |
| 77 | - if(!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 77 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 78 | 78 | OC::handleLogin(\OC::$server->getRequest()); |
| 79 | 79 | } |
| 80 | 80 | OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo()); |
@@ -59,992 +59,992 @@ |
||
| 59 | 59 | * OC_autoload! |
| 60 | 60 | */ |
| 61 | 61 | class OC { |
| 62 | - /** |
|
| 63 | - * Associative array for autoloading. classname => filename |
|
| 64 | - */ |
|
| 65 | - public static $CLASSPATH = array(); |
|
| 66 | - /** |
|
| 67 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 68 | - */ |
|
| 69 | - public static $SERVERROOT = ''; |
|
| 70 | - /** |
|
| 71 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 72 | - */ |
|
| 73 | - private static $SUBURI = ''; |
|
| 74 | - /** |
|
| 75 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 76 | - */ |
|
| 77 | - public static $WEBROOT = ''; |
|
| 78 | - /** |
|
| 79 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 80 | - * web path in 'url' |
|
| 81 | - */ |
|
| 82 | - public static $APPSROOTS = array(); |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @var string |
|
| 86 | - */ |
|
| 87 | - public static $configDir; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * requested app |
|
| 91 | - */ |
|
| 92 | - public static $REQUESTEDAPP = ''; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * check if Nextcloud runs in cli mode |
|
| 96 | - */ |
|
| 97 | - public static $CLI = false; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @var \OC\Autoloader $loader |
|
| 101 | - */ |
|
| 102 | - public static $loader = null; |
|
| 103 | - |
|
| 104 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 105 | - public static $composerAutoloader = null; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @var \OC\Server |
|
| 109 | - */ |
|
| 110 | - public static $server = null; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @var \OC\Config |
|
| 114 | - */ |
|
| 115 | - private static $config = null; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 119 | - * the app path list is empty or contains an invalid path |
|
| 120 | - */ |
|
| 121 | - public static function initPaths() { |
|
| 122 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 123 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 124 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 125 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 126 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 127 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 128 | - } else { |
|
| 129 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 130 | - } |
|
| 131 | - self::$config = new \OC\Config(self::$configDir); |
|
| 132 | - |
|
| 133 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 134 | - /** |
|
| 135 | - * FIXME: The following lines are required because we can't yet instantiiate |
|
| 136 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 137 | - */ |
|
| 138 | - $params = [ |
|
| 139 | - 'server' => [ |
|
| 140 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 141 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 142 | - ], |
|
| 143 | - ]; |
|
| 144 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 145 | - $scriptName = $fakeRequest->getScriptName(); |
|
| 146 | - if (substr($scriptName, -1) == '/') { |
|
| 147 | - $scriptName .= 'index.php'; |
|
| 148 | - //make sure suburi follows the same rules as scriptName |
|
| 149 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 150 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
| 151 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 152 | - } |
|
| 153 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - if (OC::$CLI) { |
|
| 159 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 160 | - } else { |
|
| 161 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 162 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 163 | - |
|
| 164 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 165 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 166 | - } |
|
| 167 | - } else { |
|
| 168 | - // The scriptName is not ending with OC::$SUBURI |
|
| 169 | - // This most likely means that we are calling from CLI. |
|
| 170 | - // However some cron jobs still need to generate |
|
| 171 | - // a web URL, so we use overwritewebroot as a fallback. |
|
| 172 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 176 | - // slash which is required by URL generation. |
|
| 177 | - if($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 178 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 179 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
| 180 | - exit(); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // search the apps folder |
|
| 185 | - $config_paths = self::$config->getValue('apps_paths', array()); |
|
| 186 | - if (!empty($config_paths)) { |
|
| 187 | - foreach ($config_paths as $paths) { |
|
| 188 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
| 189 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
| 190 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
| 191 | - OC::$APPSROOTS[] = $paths; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 195 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 196 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 197 | - OC::$APPSROOTS[] = array( |
|
| 198 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 199 | - 'url' => '/apps', |
|
| 200 | - 'writable' => true |
|
| 201 | - ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if (empty(OC::$APPSROOTS)) { |
|
| 205 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 206 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
| 207 | - } |
|
| 208 | - $paths = array(); |
|
| 209 | - foreach (OC::$APPSROOTS as $path) { |
|
| 210 | - $paths[] = $path['path']; |
|
| 211 | - if (!is_dir($path['path'])) { |
|
| 212 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 213 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
| 214 | - . ' config.php file.', $path['path'])); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // set the right include path |
|
| 219 | - set_include_path( |
|
| 220 | - implode(PATH_SEPARATOR, $paths) |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - public static function checkConfig() { |
|
| 225 | - $l = \OC::$server->getL10N('lib'); |
|
| 226 | - |
|
| 227 | - // Create config if it does not already exist |
|
| 228 | - $configFilePath = self::$configDir .'/config.php'; |
|
| 229 | - if(!file_exists($configFilePath)) { |
|
| 230 | - @touch($configFilePath); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // Check if config is writable |
|
| 234 | - $configFileWritable = is_writable($configFilePath); |
|
| 235 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 236 | - || !$configFileWritable && self::checkUpgrade(false)) { |
|
| 237 | - |
|
| 238 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 239 | - |
|
| 240 | - if (self::$CLI) { |
|
| 241 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 242 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 243 | - echo "\n"; |
|
| 244 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 245 | - exit; |
|
| 246 | - } else { |
|
| 247 | - OC_Template::printErrorPage( |
|
| 248 | - $l->t('Cannot write into "config" directory!'), |
|
| 249 | - $l->t('This can usually be fixed by ' |
|
| 250 | - . '%sgiving the webserver write access to the config directory%s.', |
|
| 251 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 252 | - ); |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - public static function checkInstalled() { |
|
| 258 | - if (defined('OC_CONSOLE')) { |
|
| 259 | - return; |
|
| 260 | - } |
|
| 261 | - // Redirect to installer if not installed |
|
| 262 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 263 | - if (OC::$CLI) { |
|
| 264 | - throw new Exception('Not installed'); |
|
| 265 | - } else { |
|
| 266 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 267 | - header('Location: ' . $url); |
|
| 268 | - } |
|
| 269 | - exit(); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - public static function checkMaintenanceMode() { |
|
| 274 | - // Allow ajax update script to execute without being stopped |
|
| 275 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 276 | - // send http status 503 |
|
| 277 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 278 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 279 | - header('Retry-After: 120'); |
|
| 280 | - |
|
| 281 | - // render error page |
|
| 282 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
| 283 | - OC_Util::addScript('maintenance-check'); |
|
| 284 | - $template->printPage(); |
|
| 285 | - die(); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Checks if the version requires an update and shows |
|
| 291 | - * @param bool $showTemplate Whether an update screen should get shown |
|
| 292 | - * @return bool|void |
|
| 293 | - */ |
|
| 294 | - public static function checkUpgrade($showTemplate = true) { |
|
| 295 | - if (\OCP\Util::needUpgrade()) { |
|
| 296 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 297 | - if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { |
|
| 298 | - self::printUpgradePage(); |
|
| 299 | - exit(); |
|
| 300 | - } else { |
|
| 301 | - return true; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - return false; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Prints the upgrade page |
|
| 309 | - */ |
|
| 310 | - private static function printUpgradePage() { |
|
| 311 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 312 | - |
|
| 313 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 314 | - $tooBig = false; |
|
| 315 | - if (!$disableWebUpdater) { |
|
| 316 | - $apps = \OC::$server->getAppManager(); |
|
| 317 | - $tooBig = $apps->isInstalled('user_ldap') || $apps->isInstalled('user_shibboleth'); |
|
| 318 | - if (!$tooBig) { |
|
| 319 | - // count users |
|
| 320 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 321 | - $totalUsers = array_sum($stats); |
|
| 322 | - $tooBig = ($totalUsers > 50); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - if ($disableWebUpdater || $tooBig) { |
|
| 326 | - // send http status 503 |
|
| 327 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 328 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 329 | - header('Retry-After: 120'); |
|
| 330 | - |
|
| 331 | - // render error page |
|
| 332 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 333 | - $template->assign('productName', 'nextcloud'); // for now |
|
| 334 | - $template->assign('version', OC_Util::getVersionString()); |
|
| 335 | - $template->assign('tooBig', $tooBig); |
|
| 336 | - |
|
| 337 | - $template->printPage(); |
|
| 338 | - die(); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // check whether this is a core update or apps update |
|
| 342 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 343 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 344 | - |
|
| 345 | - // if not a core upgrade, then it's apps upgrade |
|
| 346 | - $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
| 347 | - |
|
| 348 | - $oldTheme = $systemConfig->getValue('theme'); |
|
| 349 | - $systemConfig->setValue('theme', ''); |
|
| 350 | - OC_Util::addScript('config'); // needed for web root |
|
| 351 | - OC_Util::addScript('update'); |
|
| 352 | - |
|
| 353 | - /** @var \OC\App\AppManager $appManager */ |
|
| 354 | - $appManager = \OC::$server->getAppManager(); |
|
| 355 | - |
|
| 356 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 357 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 358 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 359 | - |
|
| 360 | - // get third party apps |
|
| 361 | - $ocVersion = \OCP\Util::getVersion(); |
|
| 362 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 363 | - $incompatibleShippedApps = []; |
|
| 364 | - foreach ($incompatibleApps as $appInfo) { |
|
| 365 | - if ($appManager->isShipped($appInfo['id'])) { |
|
| 366 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - if (!empty($incompatibleShippedApps)) { |
|
| 371 | - $l = \OC::$server->getL10N('core'); |
|
| 372 | - $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 373 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 377 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 378 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
| 379 | - $tmpl->assign('oldTheme', $oldTheme); |
|
| 380 | - $tmpl->printPage(); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - public static function initSession() { |
|
| 384 | - // prevents javascript from accessing php session cookies |
|
| 385 | - ini_set('session.cookie_httponly', true); |
|
| 386 | - |
|
| 387 | - // set the cookie path to the Nextcloud directory |
|
| 388 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 389 | - ini_set('session.cookie_path', $cookie_path); |
|
| 390 | - |
|
| 391 | - // Let the session name be changed in the initSession Hook |
|
| 392 | - $sessionName = OC_Util::getInstanceId(); |
|
| 393 | - |
|
| 394 | - try { |
|
| 395 | - // Allow session apps to create a custom session object |
|
| 396 | - $useCustomSession = false; |
|
| 397 | - $session = self::$server->getSession(); |
|
| 398 | - OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
| 399 | - if (!$useCustomSession) { |
|
| 400 | - // set the session name to the instance id - which is unique |
|
| 401 | - $session = new \OC\Session\Internal($sessionName); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 405 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 406 | - self::$server->setSession($session); |
|
| 407 | - |
|
| 408 | - // if session can't be started break with http 500 error |
|
| 409 | - } catch (Exception $e) { |
|
| 410 | - \OCP\Util::logException('base', $e); |
|
| 411 | - //show the user a detailed error page |
|
| 412 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 413 | - OC_Template::printExceptionErrorPage($e); |
|
| 414 | - die(); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 418 | - |
|
| 419 | - // session timeout |
|
| 420 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 421 | - if (isset($_COOKIE[session_name()])) { |
|
| 422 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 423 | - } |
|
| 424 | - \OC::$server->getUserSession()->logout(); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - $session->set('LAST_ACTIVITY', time()); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * @return string |
|
| 432 | - */ |
|
| 433 | - private static function getSessionLifeTime() { |
|
| 434 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - public static function loadAppClassPaths() { |
|
| 438 | - foreach (OC_App::getEnabledApps() as $app) { |
|
| 439 | - $appPath = OC_App::getAppPath($app); |
|
| 440 | - if ($appPath === false) { |
|
| 441 | - continue; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - $file = $appPath . '/appinfo/classpath.php'; |
|
| 445 | - if (file_exists($file)) { |
|
| 446 | - require_once $file; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Try to set some values to the required Nextcloud default |
|
| 453 | - */ |
|
| 454 | - public static function setRequiredIniValues() { |
|
| 455 | - @ini_set('default_charset', 'UTF-8'); |
|
| 456 | - @ini_set('gd.jpeg_ignore_warning', 1); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Send the same site cookies |
|
| 461 | - */ |
|
| 462 | - private static function sendSameSiteCookies() { |
|
| 463 | - $cookieParams = session_get_cookie_params(); |
|
| 464 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 465 | - $policies = [ |
|
| 466 | - 'lax', |
|
| 467 | - 'strict', |
|
| 468 | - ]; |
|
| 469 | - |
|
| 470 | - // Append __Host to the cookie if it meets the requirements |
|
| 471 | - $cookiePrefix = ''; |
|
| 472 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 473 | - $cookiePrefix = '__Host-'; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - foreach($policies as $policy) { |
|
| 477 | - header( |
|
| 478 | - sprintf( |
|
| 479 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 480 | - $cookiePrefix, |
|
| 481 | - $policy, |
|
| 482 | - $cookieParams['path'], |
|
| 483 | - $policy |
|
| 484 | - ), |
|
| 485 | - false |
|
| 486 | - ); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 492 | - * be set in every request if cookies are sent to add a second level of |
|
| 493 | - * defense against CSRF. |
|
| 494 | - * |
|
| 495 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
| 496 | - * We use an additional cookie since we want to protect logout CSRF and |
|
| 497 | - * also we can't directly interfere with PHP's session mechanism. |
|
| 498 | - */ |
|
| 499 | - private static function performSameSiteCookieProtection() { |
|
| 500 | - $request = \OC::$server->getRequest(); |
|
| 501 | - |
|
| 502 | - // Some user agents are notorious and don't really properly follow HTTP |
|
| 503 | - // specifications. For those, have an automated opt-out. Since the protection |
|
| 504 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
| 505 | - // here. |
|
| 506 | - $incompatibleUserAgents = [ |
|
| 507 | - // OS X Finder |
|
| 508 | - '/^WebDAVFS/', |
|
| 509 | - ]; |
|
| 510 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 511 | - return; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - if(count($_COOKIE) > 0) { |
|
| 515 | - $requestUri = $request->getScriptName(); |
|
| 516 | - $processingScript = explode('/', $requestUri); |
|
| 517 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
| 518 | - // FIXME: In a SAML scenario we don't get any strict or lax cookie |
|
| 519 | - // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
|
| 520 | - // (direct PHP files) the enforcement of lax cookies is performed here |
|
| 521 | - // instead of the middleware. |
|
| 522 | - // |
|
| 523 | - // This means we cannot exclude some routes from the cookie validation, |
|
| 524 | - // which normally is not a problem but is a little bit cumbersome for |
|
| 525 | - // this use-case. |
|
| 526 | - // Once the old legacy PHP endpoints have been removed we can move |
|
| 527 | - // the verification into a middleware and also adds some exemptions. |
|
| 528 | - // |
|
| 529 | - // Questions about this code? Ask Lukas ;-) |
|
| 530 | - $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
| 531 | - if($currentUrl === '/index.php/apps/user_saml/saml/acs') { |
|
| 532 | - return; |
|
| 533 | - } |
|
| 534 | - // For the "index.php" endpoint only a lax cookie is required. |
|
| 535 | - if($processingScript === 'index.php') { |
|
| 536 | - if(!$request->passesLaxCookieCheck()) { |
|
| 537 | - self::sendSameSiteCookies(); |
|
| 538 | - header('Location: '.$_SERVER['REQUEST_URI']); |
|
| 539 | - exit(); |
|
| 540 | - } |
|
| 541 | - } else { |
|
| 542 | - // All other endpoints require the lax and the strict cookie |
|
| 543 | - if(!$request->passesStrictCookieCheck()) { |
|
| 544 | - self::sendSameSiteCookies(); |
|
| 545 | - // Debug mode gets access to the resources without strict cookie |
|
| 546 | - // due to the fact that the SabreDAV browser also lives there. |
|
| 547 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 548 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 549 | - exit(); |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 554 | - self::sendSameSiteCookies(); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - public static function init() { |
|
| 559 | - // calculate the root directories |
|
| 560 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 561 | - |
|
| 562 | - // register autoloader |
|
| 563 | - $loaderStart = microtime(true); |
|
| 564 | - require_once __DIR__ . '/autoloader.php'; |
|
| 565 | - self::$loader = new \OC\Autoloader([ |
|
| 566 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
| 567 | - ]); |
|
| 568 | - if (defined('PHPUNIT_RUN')) { |
|
| 569 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 570 | - } |
|
| 571 | - spl_autoload_register(array(self::$loader, 'load')); |
|
| 572 | - $loaderEnd = microtime(true); |
|
| 573 | - |
|
| 574 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
| 575 | - |
|
| 576 | - // Add default composer PSR-4 autoloader |
|
| 577 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 578 | - |
|
| 579 | - try { |
|
| 580 | - self::initPaths(); |
|
| 581 | - // setup 3rdparty autoloader |
|
| 582 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 583 | - if (!file_exists($vendorAutoLoad)) { |
|
| 584 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 585 | - } |
|
| 586 | - require_once $vendorAutoLoad; |
|
| 587 | - |
|
| 588 | - } catch (\RuntimeException $e) { |
|
| 589 | - if (!self::$CLI) { |
|
| 590 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 591 | - $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
| 592 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 593 | - } |
|
| 594 | - // we can't use the template error page here, because this needs the |
|
| 595 | - // DI container which isn't available yet |
|
| 596 | - print($e->getMessage()); |
|
| 597 | - exit(); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - // setup the basic server |
|
| 601 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 602 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 603 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
| 604 | - |
|
| 605 | - // Don't display errors and log them |
|
| 606 | - error_reporting(E_ALL | E_STRICT); |
|
| 607 | - @ini_set('display_errors', 0); |
|
| 608 | - @ini_set('log_errors', 1); |
|
| 609 | - |
|
| 610 | - if(!date_default_timezone_set('UTC')) { |
|
| 611 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 612 | - }; |
|
| 613 | - |
|
| 614 | - //try to configure php to enable big file uploads. |
|
| 615 | - //this doesn´t work always depending on the webserver and php configuration. |
|
| 616 | - //Let´s try to overwrite some defaults anyway |
|
| 617 | - |
|
| 618 | - //try to set the maximum execution time to 60min |
|
| 619 | - @set_time_limit(3600); |
|
| 620 | - @ini_set('max_execution_time', 3600); |
|
| 621 | - @ini_set('max_input_time', 3600); |
|
| 622 | - |
|
| 623 | - //try to set the maximum filesize to 10G |
|
| 624 | - @ini_set('upload_max_filesize', '10G'); |
|
| 625 | - @ini_set('post_max_size', '10G'); |
|
| 626 | - @ini_set('file_uploads', '50'); |
|
| 627 | - |
|
| 628 | - self::setRequiredIniValues(); |
|
| 629 | - self::handleAuthHeaders(); |
|
| 630 | - self::registerAutoloaderCache(); |
|
| 631 | - |
|
| 632 | - // initialize intl fallback is necessary |
|
| 633 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
| 634 | - OC_Util::isSetLocaleWorking(); |
|
| 635 | - |
|
| 636 | - if (!defined('PHPUNIT_RUN')) { |
|
| 637 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 638 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
| 639 | - OC\Log\ErrorHandler::register($debug); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
| 643 | - OC_App::loadApps(array('session')); |
|
| 644 | - if (!self::$CLI) { |
|
| 645 | - self::initSession(); |
|
| 646 | - } |
|
| 647 | - \OC::$server->getEventLogger()->end('init_session'); |
|
| 648 | - self::checkConfig(); |
|
| 649 | - self::checkInstalled(); |
|
| 650 | - |
|
| 651 | - OC_Response::addSecurityHeaders(); |
|
| 652 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 653 | - ini_set('session.cookie_secure', true); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - self::performSameSiteCookieProtection(); |
|
| 657 | - |
|
| 658 | - if (!defined('OC_CONSOLE')) { |
|
| 659 | - $errors = OC_Util::checkServer(\OC::$server->getConfig()); |
|
| 660 | - if (count($errors) > 0) { |
|
| 661 | - if (self::$CLI) { |
|
| 662 | - // Convert l10n string into regular string for usage in database |
|
| 663 | - $staticErrors = []; |
|
| 664 | - foreach ($errors as $error) { |
|
| 665 | - echo $error['error'] . "\n"; |
|
| 666 | - echo $error['hint'] . "\n\n"; |
|
| 667 | - $staticErrors[] = [ |
|
| 668 | - 'error' => (string)$error['error'], |
|
| 669 | - 'hint' => (string)$error['hint'], |
|
| 670 | - ]; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - try { |
|
| 674 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 675 | - } catch (\Exception $e) { |
|
| 676 | - echo('Writing to database failed'); |
|
| 677 | - } |
|
| 678 | - exit(1); |
|
| 679 | - } else { |
|
| 680 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 681 | - OC_Util::addStyle('guest'); |
|
| 682 | - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
| 683 | - exit; |
|
| 684 | - } |
|
| 685 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
| 686 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - //try to set the session lifetime |
|
| 690 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 691 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 692 | - |
|
| 693 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 694 | - |
|
| 695 | - // User and Groups |
|
| 696 | - if (!$systemConfig->getValue("installed", false)) { |
|
| 697 | - self::$server->getSession()->set('user_id', ''); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - OC_User::useBackend(new \OC\User\Database()); |
|
| 701 | - OC_Group::useBackend(new \OC\Group\Database()); |
|
| 702 | - |
|
| 703 | - // Subscribe to the hook |
|
| 704 | - \OCP\Util::connectHook( |
|
| 705 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 706 | - 'preLoginNameUsedAsUserName', |
|
| 707 | - '\OC\User\Database', |
|
| 708 | - 'preLoginNameUsedAsUserName' |
|
| 709 | - ); |
|
| 710 | - |
|
| 711 | - //setup extra user backends |
|
| 712 | - if (!self::checkUpgrade(false)) { |
|
| 713 | - OC_User::setupBackends(); |
|
| 714 | - } else { |
|
| 715 | - // Run upgrades in incognito mode |
|
| 716 | - OC_User::setIncognitoMode(true); |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - self::registerCacheHooks(); |
|
| 720 | - self::registerFilesystemHooks(); |
|
| 721 | - self::registerShareHooks(); |
|
| 722 | - self::registerLogRotate(); |
|
| 723 | - self::registerEncryptionWrapper(); |
|
| 724 | - self::registerEncryptionHooks(); |
|
| 725 | - self::registerAccountHooks(); |
|
| 726 | - self::registerSettingsHooks(); |
|
| 727 | - |
|
| 728 | - //make sure temporary files are cleaned up |
|
| 729 | - $tmpManager = \OC::$server->getTempManager(); |
|
| 730 | - register_shutdown_function(array($tmpManager, 'clean')); |
|
| 731 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
| 732 | - register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
| 733 | - |
|
| 734 | - // Check whether the sample configuration has been copied |
|
| 735 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 736 | - $l = \OC::$server->getL10N('lib'); |
|
| 737 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 738 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 739 | - OC_Template::printErrorPage( |
|
| 740 | - $l->t('Sample configuration detected'), |
|
| 741 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
| 742 | - ); |
|
| 743 | - return; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - $request = \OC::$server->getRequest(); |
|
| 747 | - $host = $request->getInsecureServerHost(); |
|
| 748 | - /** |
|
| 749 | - * if the host passed in headers isn't trusted |
|
| 750 | - * FIXME: Should not be in here at all :see_no_evil: |
|
| 751 | - */ |
|
| 752 | - if (!OC::$CLI |
|
| 753 | - // overwritehost is always trusted, workaround to not have to make |
|
| 754 | - // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
| 755 | - && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
| 756 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 757 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
| 758 | - ) { |
|
| 759 | - // Allow access to CSS resources |
|
| 760 | - $isScssRequest = false; |
|
| 761 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 762 | - $isScssRequest = true; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - if (!$isScssRequest) { |
|
| 766 | - header('HTTP/1.1 400 Bad Request'); |
|
| 767 | - header('Status: 400 Bad Request'); |
|
| 768 | - |
|
| 769 | - \OC::$server->getLogger()->warning( |
|
| 770 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 771 | - [ |
|
| 772 | - 'app' => 'core', |
|
| 773 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
| 774 | - 'host' => $host, |
|
| 775 | - ] |
|
| 776 | - ); |
|
| 777 | - |
|
| 778 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 779 | - $tmpl->assign('domain', $host); |
|
| 780 | - $tmpl->printPage(); |
|
| 781 | - |
|
| 782 | - exit(); |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - \OC::$server->getEventLogger()->end('boot'); |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * register hooks for the cache |
|
| 790 | - */ |
|
| 791 | - public static function registerCacheHooks() { |
|
| 792 | - //don't try to do this before we are properly setup |
|
| 793 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { |
|
| 794 | - |
|
| 795 | - // NOTE: This will be replaced to use OCP |
|
| 796 | - $userSession = self::$server->getUserSession(); |
|
| 797 | - $userSession->listen('\OC\User', 'postLogin', function () { |
|
| 798 | - try { |
|
| 799 | - $cache = new \OC\Cache\File(); |
|
| 800 | - $cache->gc(); |
|
| 801 | - } catch (\OC\ServerNotAvailableException $e) { |
|
| 802 | - // not a GC exception, pass it on |
|
| 803 | - throw $e; |
|
| 804 | - } catch (\Exception $e) { |
|
| 805 | - // a GC exception should not prevent users from using OC, |
|
| 806 | - // so log the exception |
|
| 807 | - \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
| 808 | - } |
|
| 809 | - }); |
|
| 810 | - } |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - public static function registerSettingsHooks() { |
|
| 814 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 815 | - $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { |
|
| 816 | - /** @var \OCP\App\ManagerEvent $event */ |
|
| 817 | - \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); |
|
| 818 | - }); |
|
| 819 | - $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { |
|
| 820 | - /** @var \OCP\App\ManagerEvent $event */ |
|
| 821 | - $jobList = \OC::$server->getJobList(); |
|
| 822 | - $job = 'OC\\Settings\\RemoveOrphaned'; |
|
| 823 | - if(!($jobList->has($job, null))) { |
|
| 824 | - $jobList->add($job); |
|
| 825 | - } |
|
| 826 | - }); |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - private static function registerEncryptionWrapper() { |
|
| 830 | - $manager = self::$server->getEncryptionManager(); |
|
| 831 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - private static function registerEncryptionHooks() { |
|
| 835 | - $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
| 836 | - if ($enabled) { |
|
| 837 | - \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
| 838 | - \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
| 839 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
| 840 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - private static function registerAccountHooks() { |
|
| 845 | - $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
| 846 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * register hooks for the cache |
|
| 851 | - */ |
|
| 852 | - public static function registerLogRotate() { |
|
| 853 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 854 | - if ($systemConfig->getValue('installed', false) && $systemConfig->getValue('log_rotate_size', false) && !self::checkUpgrade(false)) { |
|
| 855 | - //don't try to do this before we are properly setup |
|
| 856 | - //use custom logfile path if defined, otherwise use default of nextcloud.log in data directory |
|
| 857 | - \OC::$server->getJobList()->add('OC\Log\Rotate'); |
|
| 858 | - } |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - /** |
|
| 862 | - * register hooks for the filesystem |
|
| 863 | - */ |
|
| 864 | - public static function registerFilesystemHooks() { |
|
| 865 | - // Check for blacklisted files |
|
| 866 | - OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
| 867 | - OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * register hooks for sharing |
|
| 872 | - */ |
|
| 873 | - public static function registerShareHooks() { |
|
| 874 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
| 875 | - OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
| 876 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
| 877 | - OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - protected static function registerAutoloaderCache() { |
|
| 882 | - // The class loader takes an optional low-latency cache, which MUST be |
|
| 883 | - // namespaced. The instanceid is used for namespacing, but might be |
|
| 884 | - // unavailable at this point. Furthermore, it might not be possible to |
|
| 885 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 886 | - // config file may not be writable. As such, we only register a class |
|
| 887 | - // loader cache if instanceid is available without trying to create one. |
|
| 888 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 889 | - if ($instanceId) { |
|
| 890 | - try { |
|
| 891 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 892 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 893 | - } catch (\Exception $ex) { |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * Handle the request |
|
| 900 | - */ |
|
| 901 | - public static function handleRequest() { |
|
| 902 | - |
|
| 903 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 904 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 905 | - // load all the classpaths from the enabled apps so they are available |
|
| 906 | - // in the routing files of each app |
|
| 907 | - OC::loadAppClassPaths(); |
|
| 908 | - |
|
| 909 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 910 | - if (!$systemConfig->getValue('installed', false)) { |
|
| 911 | - \OC::$server->getSession()->clear(); |
|
| 912 | - $setupHelper = new OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), |
|
| 913 | - \OC::$server->getL10N('lib'), \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), |
|
| 914 | - \OC::$server->getSecureRandom()); |
|
| 915 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 916 | - $controller->run($_POST); |
|
| 917 | - exit(); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - $request = \OC::$server->getRequest(); |
|
| 921 | - $requestPath = $request->getRawPathInfo(); |
|
| 922 | - if ($requestPath === '/heartbeat') { |
|
| 923 | - return; |
|
| 924 | - } |
|
| 925 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 926 | - self::checkMaintenanceMode(); |
|
| 927 | - self::checkUpgrade(); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - // emergency app disabling |
|
| 931 | - if ($requestPath === '/disableapp' |
|
| 932 | - && $request->getMethod() === 'POST' |
|
| 933 | - && ((string)$request->getParam('appid')) !== '' |
|
| 934 | - ) { |
|
| 935 | - \OCP\JSON::callCheck(); |
|
| 936 | - \OCP\JSON::checkAdminUser(); |
|
| 937 | - $appId = (string)$request->getParam('appid'); |
|
| 938 | - $appId = \OC_App::cleanAppId($appId); |
|
| 939 | - |
|
| 940 | - \OC_App::disable($appId); |
|
| 941 | - \OC_JSON::success(); |
|
| 942 | - exit(); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - // Always load authentication apps |
|
| 946 | - OC_App::loadApps(['authentication']); |
|
| 947 | - |
|
| 948 | - // Load minimum set of apps |
|
| 949 | - if (!self::checkUpgrade(false) |
|
| 950 | - && !$systemConfig->getValue('maintenance', false)) { |
|
| 951 | - // For logged-in users: Load everything |
|
| 952 | - if(OC_User::isLoggedIn()) { |
|
| 953 | - OC_App::loadApps(); |
|
| 954 | - } else { |
|
| 955 | - // For guests: Load only filesystem and logging |
|
| 956 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
| 957 | - self::handleLogin($request); |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - if (!self::$CLI) { |
|
| 962 | - try { |
|
| 963 | - if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) { |
|
| 964 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
| 965 | - OC_App::loadApps(); |
|
| 966 | - } |
|
| 967 | - OC_Util::setupFS(); |
|
| 968 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
| 969 | - return; |
|
| 970 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 971 | - //header('HTTP/1.0 404 Not Found'); |
|
| 972 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 973 | - OC_Response::setStatus(405); |
|
| 974 | - return; |
|
| 975 | - } |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - // Handle WebDAV |
|
| 979 | - if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { |
|
| 980 | - // not allowed any more to prevent people |
|
| 981 | - // mounting this root directly. |
|
| 982 | - // Users need to mount remote.php/webdav instead. |
|
| 983 | - header('HTTP/1.1 405 Method Not Allowed'); |
|
| 984 | - header('Status: 405 Method Not Allowed'); |
|
| 985 | - return; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - // Someone is logged in |
|
| 989 | - if (OC_User::isLoggedIn()) { |
|
| 990 | - OC_App::loadApps(); |
|
| 991 | - OC_User::setupBackends(); |
|
| 992 | - OC_Util::setupFS(); |
|
| 993 | - // FIXME |
|
| 994 | - // Redirect to default application |
|
| 995 | - OC_Util::redirectToDefaultPage(); |
|
| 996 | - } else { |
|
| 997 | - // Not handled and not logged in |
|
| 998 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 999 | - } |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - /** |
|
| 1003 | - * Check login: apache auth, auth token, basic auth |
|
| 1004 | - * |
|
| 1005 | - * @param OCP\IRequest $request |
|
| 1006 | - * @return boolean |
|
| 1007 | - */ |
|
| 1008 | - static function handleLogin(OCP\IRequest $request) { |
|
| 1009 | - $userSession = self::$server->getUserSession(); |
|
| 1010 | - if (OC_User::handleApacheAuth()) { |
|
| 1011 | - return true; |
|
| 1012 | - } |
|
| 1013 | - if ($userSession->tryTokenLogin($request)) { |
|
| 1014 | - return true; |
|
| 1015 | - } |
|
| 1016 | - if (isset($_COOKIE['nc_username']) |
|
| 1017 | - && isset($_COOKIE['nc_token']) |
|
| 1018 | - && isset($_COOKIE['nc_session_id']) |
|
| 1019 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1020 | - return true; |
|
| 1021 | - } |
|
| 1022 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1023 | - return true; |
|
| 1024 | - } |
|
| 1025 | - return false; |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - protected static function handleAuthHeaders() { |
|
| 1029 | - //copy http auth headers for apache+php-fcgid work around |
|
| 1030 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1031 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1035 | - $vars = array( |
|
| 1036 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1037 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1038 | - ); |
|
| 1039 | - foreach ($vars as $var) { |
|
| 1040 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1041 | - list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
| 1042 | - $_SERVER['PHP_AUTH_USER'] = $name; |
|
| 1043 | - $_SERVER['PHP_AUTH_PW'] = $password; |
|
| 1044 | - break; |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 62 | + /** |
|
| 63 | + * Associative array for autoloading. classname => filename |
|
| 64 | + */ |
|
| 65 | + public static $CLASSPATH = array(); |
|
| 66 | + /** |
|
| 67 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 68 | + */ |
|
| 69 | + public static $SERVERROOT = ''; |
|
| 70 | + /** |
|
| 71 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 72 | + */ |
|
| 73 | + private static $SUBURI = ''; |
|
| 74 | + /** |
|
| 75 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 76 | + */ |
|
| 77 | + public static $WEBROOT = ''; |
|
| 78 | + /** |
|
| 79 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 80 | + * web path in 'url' |
|
| 81 | + */ |
|
| 82 | + public static $APPSROOTS = array(); |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @var string |
|
| 86 | + */ |
|
| 87 | + public static $configDir; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * requested app |
|
| 91 | + */ |
|
| 92 | + public static $REQUESTEDAPP = ''; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * check if Nextcloud runs in cli mode |
|
| 96 | + */ |
|
| 97 | + public static $CLI = false; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @var \OC\Autoloader $loader |
|
| 101 | + */ |
|
| 102 | + public static $loader = null; |
|
| 103 | + |
|
| 104 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 105 | + public static $composerAutoloader = null; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @var \OC\Server |
|
| 109 | + */ |
|
| 110 | + public static $server = null; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @var \OC\Config |
|
| 114 | + */ |
|
| 115 | + private static $config = null; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 119 | + * the app path list is empty or contains an invalid path |
|
| 120 | + */ |
|
| 121 | + public static function initPaths() { |
|
| 122 | + if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 123 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 124 | + } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 125 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 126 | + } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 127 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
| 128 | + } else { |
|
| 129 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 130 | + } |
|
| 131 | + self::$config = new \OC\Config(self::$configDir); |
|
| 132 | + |
|
| 133 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 134 | + /** |
|
| 135 | + * FIXME: The following lines are required because we can't yet instantiiate |
|
| 136 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 137 | + */ |
|
| 138 | + $params = [ |
|
| 139 | + 'server' => [ |
|
| 140 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 141 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 142 | + ], |
|
| 143 | + ]; |
|
| 144 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 145 | + $scriptName = $fakeRequest->getScriptName(); |
|
| 146 | + if (substr($scriptName, -1) == '/') { |
|
| 147 | + $scriptName .= 'index.php'; |
|
| 148 | + //make sure suburi follows the same rules as scriptName |
|
| 149 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 150 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
| 151 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 152 | + } |
|
| 153 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + if (OC::$CLI) { |
|
| 159 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 160 | + } else { |
|
| 161 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 162 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 163 | + |
|
| 164 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 165 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 166 | + } |
|
| 167 | + } else { |
|
| 168 | + // The scriptName is not ending with OC::$SUBURI |
|
| 169 | + // This most likely means that we are calling from CLI. |
|
| 170 | + // However some cron jobs still need to generate |
|
| 171 | + // a web URL, so we use overwritewebroot as a fallback. |
|
| 172 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 176 | + // slash which is required by URL generation. |
|
| 177 | + if($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 178 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 179 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
| 180 | + exit(); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // search the apps folder |
|
| 185 | + $config_paths = self::$config->getValue('apps_paths', array()); |
|
| 186 | + if (!empty($config_paths)) { |
|
| 187 | + foreach ($config_paths as $paths) { |
|
| 188 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
| 189 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
| 190 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
| 191 | + OC::$APPSROOTS[] = $paths; |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 195 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 196 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 197 | + OC::$APPSROOTS[] = array( |
|
| 198 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 199 | + 'url' => '/apps', |
|
| 200 | + 'writable' => true |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if (empty(OC::$APPSROOTS)) { |
|
| 205 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 206 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
| 207 | + } |
|
| 208 | + $paths = array(); |
|
| 209 | + foreach (OC::$APPSROOTS as $path) { |
|
| 210 | + $paths[] = $path['path']; |
|
| 211 | + if (!is_dir($path['path'])) { |
|
| 212 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 213 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
| 214 | + . ' config.php file.', $path['path'])); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // set the right include path |
|
| 219 | + set_include_path( |
|
| 220 | + implode(PATH_SEPARATOR, $paths) |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + public static function checkConfig() { |
|
| 225 | + $l = \OC::$server->getL10N('lib'); |
|
| 226 | + |
|
| 227 | + // Create config if it does not already exist |
|
| 228 | + $configFilePath = self::$configDir .'/config.php'; |
|
| 229 | + if(!file_exists($configFilePath)) { |
|
| 230 | + @touch($configFilePath); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // Check if config is writable |
|
| 234 | + $configFileWritable = is_writable($configFilePath); |
|
| 235 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 236 | + || !$configFileWritable && self::checkUpgrade(false)) { |
|
| 237 | + |
|
| 238 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 239 | + |
|
| 240 | + if (self::$CLI) { |
|
| 241 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 242 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 243 | + echo "\n"; |
|
| 244 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 245 | + exit; |
|
| 246 | + } else { |
|
| 247 | + OC_Template::printErrorPage( |
|
| 248 | + $l->t('Cannot write into "config" directory!'), |
|
| 249 | + $l->t('This can usually be fixed by ' |
|
| 250 | + . '%sgiving the webserver write access to the config directory%s.', |
|
| 251 | + array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 252 | + ); |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + public static function checkInstalled() { |
|
| 258 | + if (defined('OC_CONSOLE')) { |
|
| 259 | + return; |
|
| 260 | + } |
|
| 261 | + // Redirect to installer if not installed |
|
| 262 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 263 | + if (OC::$CLI) { |
|
| 264 | + throw new Exception('Not installed'); |
|
| 265 | + } else { |
|
| 266 | + $url = OC::$WEBROOT . '/index.php'; |
|
| 267 | + header('Location: ' . $url); |
|
| 268 | + } |
|
| 269 | + exit(); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + public static function checkMaintenanceMode() { |
|
| 274 | + // Allow ajax update script to execute without being stopped |
|
| 275 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 276 | + // send http status 503 |
|
| 277 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 278 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 279 | + header('Retry-After: 120'); |
|
| 280 | + |
|
| 281 | + // render error page |
|
| 282 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
| 283 | + OC_Util::addScript('maintenance-check'); |
|
| 284 | + $template->printPage(); |
|
| 285 | + die(); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Checks if the version requires an update and shows |
|
| 291 | + * @param bool $showTemplate Whether an update screen should get shown |
|
| 292 | + * @return bool|void |
|
| 293 | + */ |
|
| 294 | + public static function checkUpgrade($showTemplate = true) { |
|
| 295 | + if (\OCP\Util::needUpgrade()) { |
|
| 296 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 297 | + if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { |
|
| 298 | + self::printUpgradePage(); |
|
| 299 | + exit(); |
|
| 300 | + } else { |
|
| 301 | + return true; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + return false; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Prints the upgrade page |
|
| 309 | + */ |
|
| 310 | + private static function printUpgradePage() { |
|
| 311 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 312 | + |
|
| 313 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 314 | + $tooBig = false; |
|
| 315 | + if (!$disableWebUpdater) { |
|
| 316 | + $apps = \OC::$server->getAppManager(); |
|
| 317 | + $tooBig = $apps->isInstalled('user_ldap') || $apps->isInstalled('user_shibboleth'); |
|
| 318 | + if (!$tooBig) { |
|
| 319 | + // count users |
|
| 320 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 321 | + $totalUsers = array_sum($stats); |
|
| 322 | + $tooBig = ($totalUsers > 50); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + if ($disableWebUpdater || $tooBig) { |
|
| 326 | + // send http status 503 |
|
| 327 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 328 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 329 | + header('Retry-After: 120'); |
|
| 330 | + |
|
| 331 | + // render error page |
|
| 332 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 333 | + $template->assign('productName', 'nextcloud'); // for now |
|
| 334 | + $template->assign('version', OC_Util::getVersionString()); |
|
| 335 | + $template->assign('tooBig', $tooBig); |
|
| 336 | + |
|
| 337 | + $template->printPage(); |
|
| 338 | + die(); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // check whether this is a core update or apps update |
|
| 342 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 343 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 344 | + |
|
| 345 | + // if not a core upgrade, then it's apps upgrade |
|
| 346 | + $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
| 347 | + |
|
| 348 | + $oldTheme = $systemConfig->getValue('theme'); |
|
| 349 | + $systemConfig->setValue('theme', ''); |
|
| 350 | + OC_Util::addScript('config'); // needed for web root |
|
| 351 | + OC_Util::addScript('update'); |
|
| 352 | + |
|
| 353 | + /** @var \OC\App\AppManager $appManager */ |
|
| 354 | + $appManager = \OC::$server->getAppManager(); |
|
| 355 | + |
|
| 356 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 357 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 358 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 359 | + |
|
| 360 | + // get third party apps |
|
| 361 | + $ocVersion = \OCP\Util::getVersion(); |
|
| 362 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 363 | + $incompatibleShippedApps = []; |
|
| 364 | + foreach ($incompatibleApps as $appInfo) { |
|
| 365 | + if ($appManager->isShipped($appInfo['id'])) { |
|
| 366 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + if (!empty($incompatibleShippedApps)) { |
|
| 371 | + $l = \OC::$server->getL10N('core'); |
|
| 372 | + $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 373 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 377 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 378 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
| 379 | + $tmpl->assign('oldTheme', $oldTheme); |
|
| 380 | + $tmpl->printPage(); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + public static function initSession() { |
|
| 384 | + // prevents javascript from accessing php session cookies |
|
| 385 | + ini_set('session.cookie_httponly', true); |
|
| 386 | + |
|
| 387 | + // set the cookie path to the Nextcloud directory |
|
| 388 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 389 | + ini_set('session.cookie_path', $cookie_path); |
|
| 390 | + |
|
| 391 | + // Let the session name be changed in the initSession Hook |
|
| 392 | + $sessionName = OC_Util::getInstanceId(); |
|
| 393 | + |
|
| 394 | + try { |
|
| 395 | + // Allow session apps to create a custom session object |
|
| 396 | + $useCustomSession = false; |
|
| 397 | + $session = self::$server->getSession(); |
|
| 398 | + OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
| 399 | + if (!$useCustomSession) { |
|
| 400 | + // set the session name to the instance id - which is unique |
|
| 401 | + $session = new \OC\Session\Internal($sessionName); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 405 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 406 | + self::$server->setSession($session); |
|
| 407 | + |
|
| 408 | + // if session can't be started break with http 500 error |
|
| 409 | + } catch (Exception $e) { |
|
| 410 | + \OCP\Util::logException('base', $e); |
|
| 411 | + //show the user a detailed error page |
|
| 412 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 413 | + OC_Template::printExceptionErrorPage($e); |
|
| 414 | + die(); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 418 | + |
|
| 419 | + // session timeout |
|
| 420 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 421 | + if (isset($_COOKIE[session_name()])) { |
|
| 422 | + setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 423 | + } |
|
| 424 | + \OC::$server->getUserSession()->logout(); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + $session->set('LAST_ACTIVITY', time()); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * @return string |
|
| 432 | + */ |
|
| 433 | + private static function getSessionLifeTime() { |
|
| 434 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + public static function loadAppClassPaths() { |
|
| 438 | + foreach (OC_App::getEnabledApps() as $app) { |
|
| 439 | + $appPath = OC_App::getAppPath($app); |
|
| 440 | + if ($appPath === false) { |
|
| 441 | + continue; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + $file = $appPath . '/appinfo/classpath.php'; |
|
| 445 | + if (file_exists($file)) { |
|
| 446 | + require_once $file; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Try to set some values to the required Nextcloud default |
|
| 453 | + */ |
|
| 454 | + public static function setRequiredIniValues() { |
|
| 455 | + @ini_set('default_charset', 'UTF-8'); |
|
| 456 | + @ini_set('gd.jpeg_ignore_warning', 1); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Send the same site cookies |
|
| 461 | + */ |
|
| 462 | + private static function sendSameSiteCookies() { |
|
| 463 | + $cookieParams = session_get_cookie_params(); |
|
| 464 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 465 | + $policies = [ |
|
| 466 | + 'lax', |
|
| 467 | + 'strict', |
|
| 468 | + ]; |
|
| 469 | + |
|
| 470 | + // Append __Host to the cookie if it meets the requirements |
|
| 471 | + $cookiePrefix = ''; |
|
| 472 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 473 | + $cookiePrefix = '__Host-'; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + foreach($policies as $policy) { |
|
| 477 | + header( |
|
| 478 | + sprintf( |
|
| 479 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 480 | + $cookiePrefix, |
|
| 481 | + $policy, |
|
| 482 | + $cookieParams['path'], |
|
| 483 | + $policy |
|
| 484 | + ), |
|
| 485 | + false |
|
| 486 | + ); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 492 | + * be set in every request if cookies are sent to add a second level of |
|
| 493 | + * defense against CSRF. |
|
| 494 | + * |
|
| 495 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
| 496 | + * We use an additional cookie since we want to protect logout CSRF and |
|
| 497 | + * also we can't directly interfere with PHP's session mechanism. |
|
| 498 | + */ |
|
| 499 | + private static function performSameSiteCookieProtection() { |
|
| 500 | + $request = \OC::$server->getRequest(); |
|
| 501 | + |
|
| 502 | + // Some user agents are notorious and don't really properly follow HTTP |
|
| 503 | + // specifications. For those, have an automated opt-out. Since the protection |
|
| 504 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
| 505 | + // here. |
|
| 506 | + $incompatibleUserAgents = [ |
|
| 507 | + // OS X Finder |
|
| 508 | + '/^WebDAVFS/', |
|
| 509 | + ]; |
|
| 510 | + if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 511 | + return; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + if(count($_COOKIE) > 0) { |
|
| 515 | + $requestUri = $request->getScriptName(); |
|
| 516 | + $processingScript = explode('/', $requestUri); |
|
| 517 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
| 518 | + // FIXME: In a SAML scenario we don't get any strict or lax cookie |
|
| 519 | + // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
|
| 520 | + // (direct PHP files) the enforcement of lax cookies is performed here |
|
| 521 | + // instead of the middleware. |
|
| 522 | + // |
|
| 523 | + // This means we cannot exclude some routes from the cookie validation, |
|
| 524 | + // which normally is not a problem but is a little bit cumbersome for |
|
| 525 | + // this use-case. |
|
| 526 | + // Once the old legacy PHP endpoints have been removed we can move |
|
| 527 | + // the verification into a middleware and also adds some exemptions. |
|
| 528 | + // |
|
| 529 | + // Questions about this code? Ask Lukas ;-) |
|
| 530 | + $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
| 531 | + if($currentUrl === '/index.php/apps/user_saml/saml/acs') { |
|
| 532 | + return; |
|
| 533 | + } |
|
| 534 | + // For the "index.php" endpoint only a lax cookie is required. |
|
| 535 | + if($processingScript === 'index.php') { |
|
| 536 | + if(!$request->passesLaxCookieCheck()) { |
|
| 537 | + self::sendSameSiteCookies(); |
|
| 538 | + header('Location: '.$_SERVER['REQUEST_URI']); |
|
| 539 | + exit(); |
|
| 540 | + } |
|
| 541 | + } else { |
|
| 542 | + // All other endpoints require the lax and the strict cookie |
|
| 543 | + if(!$request->passesStrictCookieCheck()) { |
|
| 544 | + self::sendSameSiteCookies(); |
|
| 545 | + // Debug mode gets access to the resources without strict cookie |
|
| 546 | + // due to the fact that the SabreDAV browser also lives there. |
|
| 547 | + if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 548 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 549 | + exit(); |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 554 | + self::sendSameSiteCookies(); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + public static function init() { |
|
| 559 | + // calculate the root directories |
|
| 560 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 561 | + |
|
| 562 | + // register autoloader |
|
| 563 | + $loaderStart = microtime(true); |
|
| 564 | + require_once __DIR__ . '/autoloader.php'; |
|
| 565 | + self::$loader = new \OC\Autoloader([ |
|
| 566 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
| 567 | + ]); |
|
| 568 | + if (defined('PHPUNIT_RUN')) { |
|
| 569 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 570 | + } |
|
| 571 | + spl_autoload_register(array(self::$loader, 'load')); |
|
| 572 | + $loaderEnd = microtime(true); |
|
| 573 | + |
|
| 574 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
| 575 | + |
|
| 576 | + // Add default composer PSR-4 autoloader |
|
| 577 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 578 | + |
|
| 579 | + try { |
|
| 580 | + self::initPaths(); |
|
| 581 | + // setup 3rdparty autoloader |
|
| 582 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 583 | + if (!file_exists($vendorAutoLoad)) { |
|
| 584 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 585 | + } |
|
| 586 | + require_once $vendorAutoLoad; |
|
| 587 | + |
|
| 588 | + } catch (\RuntimeException $e) { |
|
| 589 | + if (!self::$CLI) { |
|
| 590 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 591 | + $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
| 592 | + header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 593 | + } |
|
| 594 | + // we can't use the template error page here, because this needs the |
|
| 595 | + // DI container which isn't available yet |
|
| 596 | + print($e->getMessage()); |
|
| 597 | + exit(); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + // setup the basic server |
|
| 601 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 602 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 603 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
| 604 | + |
|
| 605 | + // Don't display errors and log them |
|
| 606 | + error_reporting(E_ALL | E_STRICT); |
|
| 607 | + @ini_set('display_errors', 0); |
|
| 608 | + @ini_set('log_errors', 1); |
|
| 609 | + |
|
| 610 | + if(!date_default_timezone_set('UTC')) { |
|
| 611 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 612 | + }; |
|
| 613 | + |
|
| 614 | + //try to configure php to enable big file uploads. |
|
| 615 | + //this doesn´t work always depending on the webserver and php configuration. |
|
| 616 | + //Let´s try to overwrite some defaults anyway |
|
| 617 | + |
|
| 618 | + //try to set the maximum execution time to 60min |
|
| 619 | + @set_time_limit(3600); |
|
| 620 | + @ini_set('max_execution_time', 3600); |
|
| 621 | + @ini_set('max_input_time', 3600); |
|
| 622 | + |
|
| 623 | + //try to set the maximum filesize to 10G |
|
| 624 | + @ini_set('upload_max_filesize', '10G'); |
|
| 625 | + @ini_set('post_max_size', '10G'); |
|
| 626 | + @ini_set('file_uploads', '50'); |
|
| 627 | + |
|
| 628 | + self::setRequiredIniValues(); |
|
| 629 | + self::handleAuthHeaders(); |
|
| 630 | + self::registerAutoloaderCache(); |
|
| 631 | + |
|
| 632 | + // initialize intl fallback is necessary |
|
| 633 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
| 634 | + OC_Util::isSetLocaleWorking(); |
|
| 635 | + |
|
| 636 | + if (!defined('PHPUNIT_RUN')) { |
|
| 637 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 638 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
| 639 | + OC\Log\ErrorHandler::register($debug); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
| 643 | + OC_App::loadApps(array('session')); |
|
| 644 | + if (!self::$CLI) { |
|
| 645 | + self::initSession(); |
|
| 646 | + } |
|
| 647 | + \OC::$server->getEventLogger()->end('init_session'); |
|
| 648 | + self::checkConfig(); |
|
| 649 | + self::checkInstalled(); |
|
| 650 | + |
|
| 651 | + OC_Response::addSecurityHeaders(); |
|
| 652 | + if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 653 | + ini_set('session.cookie_secure', true); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + self::performSameSiteCookieProtection(); |
|
| 657 | + |
|
| 658 | + if (!defined('OC_CONSOLE')) { |
|
| 659 | + $errors = OC_Util::checkServer(\OC::$server->getConfig()); |
|
| 660 | + if (count($errors) > 0) { |
|
| 661 | + if (self::$CLI) { |
|
| 662 | + // Convert l10n string into regular string for usage in database |
|
| 663 | + $staticErrors = []; |
|
| 664 | + foreach ($errors as $error) { |
|
| 665 | + echo $error['error'] . "\n"; |
|
| 666 | + echo $error['hint'] . "\n\n"; |
|
| 667 | + $staticErrors[] = [ |
|
| 668 | + 'error' => (string)$error['error'], |
|
| 669 | + 'hint' => (string)$error['hint'], |
|
| 670 | + ]; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + try { |
|
| 674 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 675 | + } catch (\Exception $e) { |
|
| 676 | + echo('Writing to database failed'); |
|
| 677 | + } |
|
| 678 | + exit(1); |
|
| 679 | + } else { |
|
| 680 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 681 | + OC_Util::addStyle('guest'); |
|
| 682 | + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
| 683 | + exit; |
|
| 684 | + } |
|
| 685 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
| 686 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + //try to set the session lifetime |
|
| 690 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 691 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 692 | + |
|
| 693 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 694 | + |
|
| 695 | + // User and Groups |
|
| 696 | + if (!$systemConfig->getValue("installed", false)) { |
|
| 697 | + self::$server->getSession()->set('user_id', ''); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + OC_User::useBackend(new \OC\User\Database()); |
|
| 701 | + OC_Group::useBackend(new \OC\Group\Database()); |
|
| 702 | + |
|
| 703 | + // Subscribe to the hook |
|
| 704 | + \OCP\Util::connectHook( |
|
| 705 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 706 | + 'preLoginNameUsedAsUserName', |
|
| 707 | + '\OC\User\Database', |
|
| 708 | + 'preLoginNameUsedAsUserName' |
|
| 709 | + ); |
|
| 710 | + |
|
| 711 | + //setup extra user backends |
|
| 712 | + if (!self::checkUpgrade(false)) { |
|
| 713 | + OC_User::setupBackends(); |
|
| 714 | + } else { |
|
| 715 | + // Run upgrades in incognito mode |
|
| 716 | + OC_User::setIncognitoMode(true); |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + self::registerCacheHooks(); |
|
| 720 | + self::registerFilesystemHooks(); |
|
| 721 | + self::registerShareHooks(); |
|
| 722 | + self::registerLogRotate(); |
|
| 723 | + self::registerEncryptionWrapper(); |
|
| 724 | + self::registerEncryptionHooks(); |
|
| 725 | + self::registerAccountHooks(); |
|
| 726 | + self::registerSettingsHooks(); |
|
| 727 | + |
|
| 728 | + //make sure temporary files are cleaned up |
|
| 729 | + $tmpManager = \OC::$server->getTempManager(); |
|
| 730 | + register_shutdown_function(array($tmpManager, 'clean')); |
|
| 731 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
| 732 | + register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
| 733 | + |
|
| 734 | + // Check whether the sample configuration has been copied |
|
| 735 | + if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 736 | + $l = \OC::$server->getL10N('lib'); |
|
| 737 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 738 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 739 | + OC_Template::printErrorPage( |
|
| 740 | + $l->t('Sample configuration detected'), |
|
| 741 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
| 742 | + ); |
|
| 743 | + return; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + $request = \OC::$server->getRequest(); |
|
| 747 | + $host = $request->getInsecureServerHost(); |
|
| 748 | + /** |
|
| 749 | + * if the host passed in headers isn't trusted |
|
| 750 | + * FIXME: Should not be in here at all :see_no_evil: |
|
| 751 | + */ |
|
| 752 | + if (!OC::$CLI |
|
| 753 | + // overwritehost is always trusted, workaround to not have to make |
|
| 754 | + // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
| 755 | + && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
| 756 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 757 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
| 758 | + ) { |
|
| 759 | + // Allow access to CSS resources |
|
| 760 | + $isScssRequest = false; |
|
| 761 | + if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 762 | + $isScssRequest = true; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + if (!$isScssRequest) { |
|
| 766 | + header('HTTP/1.1 400 Bad Request'); |
|
| 767 | + header('Status: 400 Bad Request'); |
|
| 768 | + |
|
| 769 | + \OC::$server->getLogger()->warning( |
|
| 770 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 771 | + [ |
|
| 772 | + 'app' => 'core', |
|
| 773 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
| 774 | + 'host' => $host, |
|
| 775 | + ] |
|
| 776 | + ); |
|
| 777 | + |
|
| 778 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 779 | + $tmpl->assign('domain', $host); |
|
| 780 | + $tmpl->printPage(); |
|
| 781 | + |
|
| 782 | + exit(); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + \OC::$server->getEventLogger()->end('boot'); |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * register hooks for the cache |
|
| 790 | + */ |
|
| 791 | + public static function registerCacheHooks() { |
|
| 792 | + //don't try to do this before we are properly setup |
|
| 793 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { |
|
| 794 | + |
|
| 795 | + // NOTE: This will be replaced to use OCP |
|
| 796 | + $userSession = self::$server->getUserSession(); |
|
| 797 | + $userSession->listen('\OC\User', 'postLogin', function () { |
|
| 798 | + try { |
|
| 799 | + $cache = new \OC\Cache\File(); |
|
| 800 | + $cache->gc(); |
|
| 801 | + } catch (\OC\ServerNotAvailableException $e) { |
|
| 802 | + // not a GC exception, pass it on |
|
| 803 | + throw $e; |
|
| 804 | + } catch (\Exception $e) { |
|
| 805 | + // a GC exception should not prevent users from using OC, |
|
| 806 | + // so log the exception |
|
| 807 | + \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
| 808 | + } |
|
| 809 | + }); |
|
| 810 | + } |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + public static function registerSettingsHooks() { |
|
| 814 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 815 | + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { |
|
| 816 | + /** @var \OCP\App\ManagerEvent $event */ |
|
| 817 | + \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); |
|
| 818 | + }); |
|
| 819 | + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { |
|
| 820 | + /** @var \OCP\App\ManagerEvent $event */ |
|
| 821 | + $jobList = \OC::$server->getJobList(); |
|
| 822 | + $job = 'OC\\Settings\\RemoveOrphaned'; |
|
| 823 | + if(!($jobList->has($job, null))) { |
|
| 824 | + $jobList->add($job); |
|
| 825 | + } |
|
| 826 | + }); |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + private static function registerEncryptionWrapper() { |
|
| 830 | + $manager = self::$server->getEncryptionManager(); |
|
| 831 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + private static function registerEncryptionHooks() { |
|
| 835 | + $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
| 836 | + if ($enabled) { |
|
| 837 | + \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
| 838 | + \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
| 839 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
| 840 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + private static function registerAccountHooks() { |
|
| 845 | + $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
| 846 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * register hooks for the cache |
|
| 851 | + */ |
|
| 852 | + public static function registerLogRotate() { |
|
| 853 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 854 | + if ($systemConfig->getValue('installed', false) && $systemConfig->getValue('log_rotate_size', false) && !self::checkUpgrade(false)) { |
|
| 855 | + //don't try to do this before we are properly setup |
|
| 856 | + //use custom logfile path if defined, otherwise use default of nextcloud.log in data directory |
|
| 857 | + \OC::$server->getJobList()->add('OC\Log\Rotate'); |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + /** |
|
| 862 | + * register hooks for the filesystem |
|
| 863 | + */ |
|
| 864 | + public static function registerFilesystemHooks() { |
|
| 865 | + // Check for blacklisted files |
|
| 866 | + OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
| 867 | + OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * register hooks for sharing |
|
| 872 | + */ |
|
| 873 | + public static function registerShareHooks() { |
|
| 874 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
| 875 | + OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
| 876 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
| 877 | + OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + protected static function registerAutoloaderCache() { |
|
| 882 | + // The class loader takes an optional low-latency cache, which MUST be |
|
| 883 | + // namespaced. The instanceid is used for namespacing, but might be |
|
| 884 | + // unavailable at this point. Furthermore, it might not be possible to |
|
| 885 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 886 | + // config file may not be writable. As such, we only register a class |
|
| 887 | + // loader cache if instanceid is available without trying to create one. |
|
| 888 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 889 | + if ($instanceId) { |
|
| 890 | + try { |
|
| 891 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 892 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 893 | + } catch (\Exception $ex) { |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * Handle the request |
|
| 900 | + */ |
|
| 901 | + public static function handleRequest() { |
|
| 902 | + |
|
| 903 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 904 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 905 | + // load all the classpaths from the enabled apps so they are available |
|
| 906 | + // in the routing files of each app |
|
| 907 | + OC::loadAppClassPaths(); |
|
| 908 | + |
|
| 909 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 910 | + if (!$systemConfig->getValue('installed', false)) { |
|
| 911 | + \OC::$server->getSession()->clear(); |
|
| 912 | + $setupHelper = new OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), |
|
| 913 | + \OC::$server->getL10N('lib'), \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), |
|
| 914 | + \OC::$server->getSecureRandom()); |
|
| 915 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 916 | + $controller->run($_POST); |
|
| 917 | + exit(); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + $request = \OC::$server->getRequest(); |
|
| 921 | + $requestPath = $request->getRawPathInfo(); |
|
| 922 | + if ($requestPath === '/heartbeat') { |
|
| 923 | + return; |
|
| 924 | + } |
|
| 925 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 926 | + self::checkMaintenanceMode(); |
|
| 927 | + self::checkUpgrade(); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + // emergency app disabling |
|
| 931 | + if ($requestPath === '/disableapp' |
|
| 932 | + && $request->getMethod() === 'POST' |
|
| 933 | + && ((string)$request->getParam('appid')) !== '' |
|
| 934 | + ) { |
|
| 935 | + \OCP\JSON::callCheck(); |
|
| 936 | + \OCP\JSON::checkAdminUser(); |
|
| 937 | + $appId = (string)$request->getParam('appid'); |
|
| 938 | + $appId = \OC_App::cleanAppId($appId); |
|
| 939 | + |
|
| 940 | + \OC_App::disable($appId); |
|
| 941 | + \OC_JSON::success(); |
|
| 942 | + exit(); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + // Always load authentication apps |
|
| 946 | + OC_App::loadApps(['authentication']); |
|
| 947 | + |
|
| 948 | + // Load minimum set of apps |
|
| 949 | + if (!self::checkUpgrade(false) |
|
| 950 | + && !$systemConfig->getValue('maintenance', false)) { |
|
| 951 | + // For logged-in users: Load everything |
|
| 952 | + if(OC_User::isLoggedIn()) { |
|
| 953 | + OC_App::loadApps(); |
|
| 954 | + } else { |
|
| 955 | + // For guests: Load only filesystem and logging |
|
| 956 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
| 957 | + self::handleLogin($request); |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + if (!self::$CLI) { |
|
| 962 | + try { |
|
| 963 | + if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) { |
|
| 964 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
| 965 | + OC_App::loadApps(); |
|
| 966 | + } |
|
| 967 | + OC_Util::setupFS(); |
|
| 968 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
| 969 | + return; |
|
| 970 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 971 | + //header('HTTP/1.0 404 Not Found'); |
|
| 972 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 973 | + OC_Response::setStatus(405); |
|
| 974 | + return; |
|
| 975 | + } |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + // Handle WebDAV |
|
| 979 | + if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { |
|
| 980 | + // not allowed any more to prevent people |
|
| 981 | + // mounting this root directly. |
|
| 982 | + // Users need to mount remote.php/webdav instead. |
|
| 983 | + header('HTTP/1.1 405 Method Not Allowed'); |
|
| 984 | + header('Status: 405 Method Not Allowed'); |
|
| 985 | + return; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + // Someone is logged in |
|
| 989 | + if (OC_User::isLoggedIn()) { |
|
| 990 | + OC_App::loadApps(); |
|
| 991 | + OC_User::setupBackends(); |
|
| 992 | + OC_Util::setupFS(); |
|
| 993 | + // FIXME |
|
| 994 | + // Redirect to default application |
|
| 995 | + OC_Util::redirectToDefaultPage(); |
|
| 996 | + } else { |
|
| 997 | + // Not handled and not logged in |
|
| 998 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 999 | + } |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + /** |
|
| 1003 | + * Check login: apache auth, auth token, basic auth |
|
| 1004 | + * |
|
| 1005 | + * @param OCP\IRequest $request |
|
| 1006 | + * @return boolean |
|
| 1007 | + */ |
|
| 1008 | + static function handleLogin(OCP\IRequest $request) { |
|
| 1009 | + $userSession = self::$server->getUserSession(); |
|
| 1010 | + if (OC_User::handleApacheAuth()) { |
|
| 1011 | + return true; |
|
| 1012 | + } |
|
| 1013 | + if ($userSession->tryTokenLogin($request)) { |
|
| 1014 | + return true; |
|
| 1015 | + } |
|
| 1016 | + if (isset($_COOKIE['nc_username']) |
|
| 1017 | + && isset($_COOKIE['nc_token']) |
|
| 1018 | + && isset($_COOKIE['nc_session_id']) |
|
| 1019 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1020 | + return true; |
|
| 1021 | + } |
|
| 1022 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1023 | + return true; |
|
| 1024 | + } |
|
| 1025 | + return false; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + protected static function handleAuthHeaders() { |
|
| 1029 | + //copy http auth headers for apache+php-fcgid work around |
|
| 1030 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1031 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1035 | + $vars = array( |
|
| 1036 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1037 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1038 | + ); |
|
| 1039 | + foreach ($vars as $var) { |
|
| 1040 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1041 | + list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
| 1042 | + $_SERVER['PHP_AUTH_USER'] = $name; |
|
| 1043 | + $_SERVER['PHP_AUTH_PW'] = $password; |
|
| 1044 | + break; |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | OC::init(); |
@@ -119,14 +119,14 @@ discard block |
||
| 119 | 119 | * the app path list is empty or contains an invalid path |
| 120 | 120 | */ |
| 121 | 121 | public static function initPaths() { |
| 122 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 123 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 124 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 125 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 126 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 127 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 122 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 123 | + self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/'; |
|
| 124 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) { |
|
| 125 | + self::$configDir = OC::$SERVERROOT.'/tests/config/'; |
|
| 126 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 127 | + self::$configDir = rtrim($dir, '/').'/'; |
|
| 128 | 128 | } else { |
| 129 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 129 | + self::$configDir = OC::$SERVERROOT.'/config/'; |
|
| 130 | 130 | } |
| 131 | 131 | self::$config = new \OC\Config(self::$configDir); |
| 132 | 132 | |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | //make sure suburi follows the same rules as scriptName |
| 149 | 149 | if (substr(OC::$SUBURI, -9) != 'index.php') { |
| 150 | 150 | if (substr(OC::$SUBURI, -1) != '/') { |
| 151 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 151 | + OC::$SUBURI = OC::$SUBURI.'/'; |
|
| 152 | 152 | } |
| 153 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 153 | + OC::$SUBURI = OC::$SUBURI.'index.php'; |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
| 163 | 163 | |
| 164 | 164 | if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
| 165 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 165 | + OC::$WEBROOT = '/'.OC::$WEBROOT; |
|
| 166 | 166 | } |
| 167 | 167 | } else { |
| 168 | 168 | // The scriptName is not ending with OC::$SUBURI |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
| 176 | 176 | // slash which is required by URL generation. |
| 177 | - if($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 177 | + if ($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 178 | 178 | substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
| 179 | 179 | header('Location: '.\OC::$WEBROOT.'/'); |
| 180 | 180 | exit(); |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | OC::$APPSROOTS[] = $paths; |
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 195 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 196 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 194 | + } elseif (file_exists(OC::$SERVERROOT.'/apps')) { |
|
| 195 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true); |
|
| 196 | + } elseif (file_exists(OC::$SERVERROOT.'/../apps')) { |
|
| 197 | 197 | OC::$APPSROOTS[] = array( |
| 198 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 198 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps', |
|
| 199 | 199 | 'url' => '/apps', |
| 200 | 200 | 'writable' => true |
| 201 | 201 | ); |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | $l = \OC::$server->getL10N('lib'); |
| 226 | 226 | |
| 227 | 227 | // Create config if it does not already exist |
| 228 | - $configFilePath = self::$configDir .'/config.php'; |
|
| 229 | - if(!file_exists($configFilePath)) { |
|
| 228 | + $configFilePath = self::$configDir.'/config.php'; |
|
| 229 | + if (!file_exists($configFilePath)) { |
|
| 230 | 230 | @touch($configFilePath); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -241,14 +241,14 @@ discard block |
||
| 241 | 241 | echo $l->t('Cannot write into "config" directory!')."\n"; |
| 242 | 242 | echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
| 243 | 243 | echo "\n"; |
| 244 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 244 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n"; |
|
| 245 | 245 | exit; |
| 246 | 246 | } else { |
| 247 | 247 | OC_Template::printErrorPage( |
| 248 | 248 | $l->t('Cannot write into "config" directory!'), |
| 249 | 249 | $l->t('This can usually be fixed by ' |
| 250 | 250 | . '%sgiving the webserver write access to the config directory%s.', |
| 251 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 251 | + array('<a href="'.$urlGenerator->linkToDocs('admin-dir_permissions').'" target="_blank" rel="noreferrer">', '</a>')) |
|
| 252 | 252 | ); |
| 253 | 253 | } |
| 254 | 254 | } |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | if (OC::$CLI) { |
| 264 | 264 | throw new Exception('Not installed'); |
| 265 | 265 | } else { |
| 266 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 267 | - header('Location: ' . $url); |
|
| 266 | + $url = OC::$WEBROOT.'/index.php'; |
|
| 267 | + header('Location: '.$url); |
|
| 268 | 268 | } |
| 269 | 269 | exit(); |
| 270 | 270 | } |
@@ -363,14 +363,14 @@ discard block |
||
| 363 | 363 | $incompatibleShippedApps = []; |
| 364 | 364 | foreach ($incompatibleApps as $appInfo) { |
| 365 | 365 | if ($appManager->isShipped($appInfo['id'])) { |
| 366 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 366 | + $incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')'; |
|
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | if (!empty($incompatibleShippedApps)) { |
| 371 | 371 | $l = \OC::$server->getL10N('core'); |
| 372 | 372 | $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
| 373 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 373 | + throw new \OC\HintException('The files of the app '.implode(', ', $incompatibleShippedApps).' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | ini_set('session.cookie_httponly', true); |
| 386 | 386 | |
| 387 | 387 | // set the cookie path to the Nextcloud directory |
| 388 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 388 | + $cookie_path = OC::$WEBROOT ?: '/'; |
|
| 389 | 389 | ini_set('session.cookie_path', $cookie_path); |
| 390 | 390 | |
| 391 | 391 | // Let the session name be changed in the initSession Hook |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | // session timeout |
| 420 | 420 | if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
| 421 | 421 | if (isset($_COOKIE[session_name()])) { |
| 422 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 422 | + setcookie(session_name(), null, -1, self::$WEBROOT ?: '/'); |
|
| 423 | 423 | } |
| 424 | 424 | \OC::$server->getUserSession()->logout(); |
| 425 | 425 | } |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | continue; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - $file = $appPath . '/appinfo/classpath.php'; |
|
| 444 | + $file = $appPath.'/appinfo/classpath.php'; |
|
| 445 | 445 | if (file_exists($file)) { |
| 446 | 446 | require_once $file; |
| 447 | 447 | } |
@@ -469,14 +469,14 @@ discard block |
||
| 469 | 469 | |
| 470 | 470 | // Append __Host to the cookie if it meets the requirements |
| 471 | 471 | $cookiePrefix = ''; |
| 472 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 472 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 473 | 473 | $cookiePrefix = '__Host-'; |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - foreach($policies as $policy) { |
|
| 476 | + foreach ($policies as $policy) { |
|
| 477 | 477 | header( |
| 478 | 478 | sprintf( |
| 479 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 479 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 480 | 480 | $cookiePrefix, |
| 481 | 481 | $policy, |
| 482 | 482 | $cookieParams['path'], |
@@ -507,14 +507,14 @@ discard block |
||
| 507 | 507 | // OS X Finder |
| 508 | 508 | '/^WebDAVFS/', |
| 509 | 509 | ]; |
| 510 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 510 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 511 | 511 | return; |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if(count($_COOKIE) > 0) { |
|
| 514 | + if (count($_COOKIE) > 0) { |
|
| 515 | 515 | $requestUri = $request->getScriptName(); |
| 516 | 516 | $processingScript = explode('/', $requestUri); |
| 517 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
| 517 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 518 | 518 | // FIXME: In a SAML scenario we don't get any strict or lax cookie |
| 519 | 519 | // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
| 520 | 520 | // (direct PHP files) the enforcement of lax cookies is performed here |
@@ -527,30 +527,30 @@ discard block |
||
| 527 | 527 | // the verification into a middleware and also adds some exemptions. |
| 528 | 528 | // |
| 529 | 529 | // Questions about this code? Ask Lukas ;-) |
| 530 | - $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
| 531 | - if($currentUrl === '/index.php/apps/user_saml/saml/acs') { |
|
| 530 | + $currentUrl = substr(explode('?', $request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
| 531 | + if ($currentUrl === '/index.php/apps/user_saml/saml/acs') { |
|
| 532 | 532 | return; |
| 533 | 533 | } |
| 534 | 534 | // For the "index.php" endpoint only a lax cookie is required. |
| 535 | - if($processingScript === 'index.php') { |
|
| 536 | - if(!$request->passesLaxCookieCheck()) { |
|
| 535 | + if ($processingScript === 'index.php') { |
|
| 536 | + if (!$request->passesLaxCookieCheck()) { |
|
| 537 | 537 | self::sendSameSiteCookies(); |
| 538 | 538 | header('Location: '.$_SERVER['REQUEST_URI']); |
| 539 | 539 | exit(); |
| 540 | 540 | } |
| 541 | 541 | } else { |
| 542 | 542 | // All other endpoints require the lax and the strict cookie |
| 543 | - if(!$request->passesStrictCookieCheck()) { |
|
| 543 | + if (!$request->passesStrictCookieCheck()) { |
|
| 544 | 544 | self::sendSameSiteCookies(); |
| 545 | 545 | // Debug mode gets access to the resources without strict cookie |
| 546 | 546 | // due to the fact that the SabreDAV browser also lives there. |
| 547 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 547 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 548 | 548 | http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
| 549 | 549 | exit(); |
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | } |
| 553 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 553 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 554 | 554 | self::sendSameSiteCookies(); |
| 555 | 555 | } |
| 556 | 556 | } |
@@ -561,12 +561,12 @@ discard block |
||
| 561 | 561 | |
| 562 | 562 | // register autoloader |
| 563 | 563 | $loaderStart = microtime(true); |
| 564 | - require_once __DIR__ . '/autoloader.php'; |
|
| 564 | + require_once __DIR__.'/autoloader.php'; |
|
| 565 | 565 | self::$loader = new \OC\Autoloader([ |
| 566 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
| 566 | + OC::$SERVERROOT.'/lib/private/legacy', |
|
| 567 | 567 | ]); |
| 568 | 568 | if (defined('PHPUNIT_RUN')) { |
| 569 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 569 | + self::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
| 570 | 570 | } |
| 571 | 571 | spl_autoload_register(array(self::$loader, 'load')); |
| 572 | 572 | $loaderEnd = microtime(true); |
@@ -574,12 +574,12 @@ discard block |
||
| 574 | 574 | self::$CLI = (php_sapi_name() == 'cli'); |
| 575 | 575 | |
| 576 | 576 | // Add default composer PSR-4 autoloader |
| 577 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 577 | + self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php'; |
|
| 578 | 578 | |
| 579 | 579 | try { |
| 580 | 580 | self::initPaths(); |
| 581 | 581 | // setup 3rdparty autoloader |
| 582 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 582 | + $vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php'; |
|
| 583 | 583 | if (!file_exists($vendorAutoLoad)) { |
| 584 | 584 | throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
| 585 | 585 | } |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | if (!self::$CLI) { |
| 590 | 590 | $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
| 591 | 591 | $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
| 592 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 592 | + header($protocol.' '.OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 593 | 593 | } |
| 594 | 594 | // we can't use the template error page here, because this needs the |
| 595 | 595 | // DI container which isn't available yet |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | @ini_set('display_errors', 0); |
| 608 | 608 | @ini_set('log_errors', 1); |
| 609 | 609 | |
| 610 | - if(!date_default_timezone_set('UTC')) { |
|
| 610 | + if (!date_default_timezone_set('UTC')) { |
|
| 611 | 611 | throw new \RuntimeException('Could not set timezone to UTC'); |
| 612 | 612 | }; |
| 613 | 613 | |
@@ -649,7 +649,7 @@ discard block |
||
| 649 | 649 | self::checkInstalled(); |
| 650 | 650 | |
| 651 | 651 | OC_Response::addSecurityHeaders(); |
| 652 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 652 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 653 | 653 | ini_set('session.cookie_secure', true); |
| 654 | 654 | } |
| 655 | 655 | |
@@ -662,11 +662,11 @@ discard block |
||
| 662 | 662 | // Convert l10n string into regular string for usage in database |
| 663 | 663 | $staticErrors = []; |
| 664 | 664 | foreach ($errors as $error) { |
| 665 | - echo $error['error'] . "\n"; |
|
| 666 | - echo $error['hint'] . "\n\n"; |
|
| 665 | + echo $error['error']."\n"; |
|
| 666 | + echo $error['hint']."\n\n"; |
|
| 667 | 667 | $staticErrors[] = [ |
| 668 | - 'error' => (string)$error['error'], |
|
| 669 | - 'hint' => (string)$error['hint'], |
|
| 668 | + 'error' => (string) $error['error'], |
|
| 669 | + 'hint' => (string) $error['hint'], |
|
| 670 | 670 | ]; |
| 671 | 671 | } |
| 672 | 672 | |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | } |
| 689 | 689 | //try to set the session lifetime |
| 690 | 690 | $sessionLifeTime = self::getSessionLifeTime(); |
| 691 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 691 | + @ini_set('gc_maxlifetime', (string) $sessionLifeTime); |
|
| 692 | 692 | |
| 693 | 693 | $systemConfig = \OC::$server->getSystemConfig(); |
| 694 | 694 | |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | register_shutdown_function(array($lockProvider, 'releaseAll')); |
| 733 | 733 | |
| 734 | 734 | // Check whether the sample configuration has been copied |
| 735 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 735 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 736 | 736 | $l = \OC::$server->getL10N('lib'); |
| 737 | 737 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
| 738 | 738 | header('Status: 503 Service Temporarily Unavailable'); |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | ) { |
| 759 | 759 | // Allow access to CSS resources |
| 760 | 760 | $isScssRequest = false; |
| 761 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 761 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 762 | 762 | $isScssRequest = true; |
| 763 | 763 | } |
| 764 | 764 | |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | |
| 795 | 795 | // NOTE: This will be replaced to use OCP |
| 796 | 796 | $userSession = self::$server->getUserSession(); |
| 797 | - $userSession->listen('\OC\User', 'postLogin', function () { |
|
| 797 | + $userSession->listen('\OC\User', 'postLogin', function() { |
|
| 798 | 798 | try { |
| 799 | 799 | $cache = new \OC\Cache\File(); |
| 800 | 800 | $cache->gc(); |
@@ -804,7 +804,7 @@ discard block |
||
| 804 | 804 | } catch (\Exception $e) { |
| 805 | 805 | // a GC exception should not prevent users from using OC, |
| 806 | 806 | // so log the exception |
| 807 | - \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
| 807 | + \OC::$server->getLogger()->warning('Exception when running cache gc: '.$e->getMessage(), array('app' => 'core')); |
|
| 808 | 808 | } |
| 809 | 809 | }); |
| 810 | 810 | } |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | /** @var \OCP\App\ManagerEvent $event */ |
| 821 | 821 | $jobList = \OC::$server->getJobList(); |
| 822 | 822 | $job = 'OC\\Settings\\RemoveOrphaned'; |
| 823 | - if(!($jobList->has($job, null))) { |
|
| 823 | + if (!($jobList->has($job, null))) { |
|
| 824 | 824 | $jobList->add($job); |
| 825 | 825 | } |
| 826 | 826 | }); |
@@ -930,11 +930,11 @@ discard block |
||
| 930 | 930 | // emergency app disabling |
| 931 | 931 | if ($requestPath === '/disableapp' |
| 932 | 932 | && $request->getMethod() === 'POST' |
| 933 | - && ((string)$request->getParam('appid')) !== '' |
|
| 933 | + && ((string) $request->getParam('appid')) !== '' |
|
| 934 | 934 | ) { |
| 935 | 935 | \OCP\JSON::callCheck(); |
| 936 | 936 | \OCP\JSON::checkAdminUser(); |
| 937 | - $appId = (string)$request->getParam('appid'); |
|
| 937 | + $appId = (string) $request->getParam('appid'); |
|
| 938 | 938 | $appId = \OC_App::cleanAppId($appId); |
| 939 | 939 | |
| 940 | 940 | \OC_App::disable($appId); |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | if (!self::checkUpgrade(false) |
| 950 | 950 | && !$systemConfig->getValue('maintenance', false)) { |
| 951 | 951 | // For logged-in users: Load everything |
| 952 | - if(OC_User::isLoggedIn()) { |
|
| 952 | + if (OC_User::isLoggedIn()) { |
|
| 953 | 953 | OC_App::loadApps(); |
| 954 | 954 | } else { |
| 955 | 955 | // For guests: Load only filesystem and logging |
@@ -33,58 +33,58 @@ |
||
| 33 | 33 | |
| 34 | 34 | class MaintenancePlugin extends ServerPlugin { |
| 35 | 35 | |
| 36 | - /** @var IConfig */ |
|
| 37 | - private $config; |
|
| 36 | + /** @var IConfig */ |
|
| 37 | + private $config; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Reference to main server object |
|
| 41 | - * |
|
| 42 | - * @var Server |
|
| 43 | - */ |
|
| 44 | - private $server; |
|
| 39 | + /** |
|
| 40 | + * Reference to main server object |
|
| 41 | + * |
|
| 42 | + * @var Server |
|
| 43 | + */ |
|
| 44 | + private $server; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param IConfig $config |
|
| 48 | - */ |
|
| 49 | - public function __construct(IConfig $config = null) { |
|
| 50 | - $this->config = $config; |
|
| 51 | - if (is_null($config)) { |
|
| 52 | - $this->config = \OC::$server->getConfig(); |
|
| 53 | - } |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * @param IConfig $config |
|
| 48 | + */ |
|
| 49 | + public function __construct(IConfig $config = null) { |
|
| 50 | + $this->config = $config; |
|
| 51 | + if (is_null($config)) { |
|
| 52 | + $this->config = \OC::$server->getConfig(); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * This initializes the plugin. |
|
| 59 | - * |
|
| 60 | - * This function is called by \Sabre\DAV\Server, after |
|
| 61 | - * addPlugin is called. |
|
| 62 | - * |
|
| 63 | - * This method should set up the required event subscriptions. |
|
| 64 | - * |
|
| 65 | - * @param \Sabre\DAV\Server $server |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 69 | - $this->server = $server; |
|
| 70 | - $this->server->on('beforeMethod', array($this, 'checkMaintenanceMode'), 1); |
|
| 71 | - } |
|
| 57 | + /** |
|
| 58 | + * This initializes the plugin. |
|
| 59 | + * |
|
| 60 | + * This function is called by \Sabre\DAV\Server, after |
|
| 61 | + * addPlugin is called. |
|
| 62 | + * |
|
| 63 | + * This method should set up the required event subscriptions. |
|
| 64 | + * |
|
| 65 | + * @param \Sabre\DAV\Server $server |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 69 | + $this->server = $server; |
|
| 70 | + $this->server->on('beforeMethod', array($this, 'checkMaintenanceMode'), 1); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * This method is called before any HTTP method and returns http status code 503 |
|
| 75 | - * in case the system is in maintenance mode. |
|
| 76 | - * |
|
| 77 | - * @throws ServiceUnavailable |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public function checkMaintenanceMode() { |
|
| 81 | - if ($this->config->getSystemValue('maintenance', false)) { |
|
| 82 | - throw new ServiceUnavailable('System in maintenance mode.'); |
|
| 83 | - } |
|
| 84 | - if (\OC::checkUpgrade(false)) { |
|
| 85 | - throw new ServiceUnavailable('Upgrade needed'); |
|
| 86 | - } |
|
| 73 | + /** |
|
| 74 | + * This method is called before any HTTP method and returns http status code 503 |
|
| 75 | + * in case the system is in maintenance mode. |
|
| 76 | + * |
|
| 77 | + * @throws ServiceUnavailable |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public function checkMaintenanceMode() { |
|
| 81 | + if ($this->config->getSystemValue('maintenance', false)) { |
|
| 82 | + throw new ServiceUnavailable('System in maintenance mode.'); |
|
| 83 | + } |
|
| 84 | + if (\OC::checkUpgrade(false)) { |
|
| 85 | + throw new ServiceUnavailable('Upgrade needed'); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - return true; |
|
| 89 | - } |
|
| 88 | + return true; |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -32,133 +32,133 @@ |
||
| 32 | 32 | |
| 33 | 33 | // Show warning if a PHP version below 5.6.0 is used |
| 34 | 34 | if (version_compare(PHP_VERSION, '5.6.0') === -1) { |
| 35 | - echo 'This version of Nextcloud requires at least PHP 5.6.0<br/>'; |
|
| 36 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 37 | - return; |
|
| 35 | + echo 'This version of Nextcloud requires at least PHP 5.6.0<br/>'; |
|
| 36 | + echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 37 | + return; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | try { |
| 41 | 41 | |
| 42 | - require_once __DIR__ . '/lib/base.php'; |
|
| 43 | - |
|
| 44 | - if (\OCP\Util::needUpgrade()) { |
|
| 45 | - \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG); |
|
| 46 | - exit; |
|
| 47 | - } |
|
| 48 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 49 | - \OCP\Util::writeLog('cron', 'We are in maintenance mode, skipping cron', \OCP\Util::DEBUG); |
|
| 50 | - exit; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // load all apps to get all api routes properly setup |
|
| 54 | - OC_App::loadApps(); |
|
| 55 | - |
|
| 56 | - \OC::$server->getSession()->close(); |
|
| 57 | - |
|
| 58 | - // initialize a dummy memory session |
|
| 59 | - $session = new \OC\Session\Memory(''); |
|
| 60 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 61 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 62 | - \OC::$server->setSession($session); |
|
| 63 | - |
|
| 64 | - $logger = \OC::$server->getLogger(); |
|
| 65 | - $config = \OC::$server->getConfig(); |
|
| 66 | - |
|
| 67 | - // Don't do anything if ownCloud has not been installed |
|
| 68 | - if (!$config->getSystemValue('installed', false)) { |
|
| 69 | - exit(0); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - \OC::$server->getTempManager()->cleanOld(); |
|
| 73 | - |
|
| 74 | - // Exit if background jobs are disabled! |
|
| 75 | - $appMode = \OCP\BackgroundJob::getExecutionType(); |
|
| 76 | - if ($appMode == 'none') { |
|
| 77 | - if (OC::$CLI) { |
|
| 78 | - echo 'Background Jobs are disabled!' . PHP_EOL; |
|
| 79 | - } else { |
|
| 80 | - OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); |
|
| 81 | - } |
|
| 82 | - exit(1); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (OC::$CLI) { |
|
| 86 | - // set to run indefinitely if needed |
|
| 87 | - set_time_limit(0); |
|
| 88 | - |
|
| 89 | - // the cron job must be executed with the right user |
|
| 90 | - if (!function_exists('posix_getuid')) { |
|
| 91 | - echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 92 | - exit(0); |
|
| 93 | - } |
|
| 94 | - $user = posix_getpwuid(posix_getuid()); |
|
| 95 | - $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 96 | - if ($user['name'] !== $configUser['name']) { |
|
| 97 | - echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL; |
|
| 98 | - echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 99 | - echo "Web server user: " . $configUser['name'] . PHP_EOL; |
|
| 100 | - exit(0); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // We call ownCloud from the CLI (aka cron) |
|
| 104 | - if ($appMode != 'cron') { |
|
| 105 | - \OCP\BackgroundJob::setExecutionType('cron'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // Work |
|
| 109 | - $jobList = \OC::$server->getJobList(); |
|
| 110 | - |
|
| 111 | - // We only ask for jobs for 14 minutes, because after 15 minutes the next |
|
| 112 | - // system cron task should spawn. |
|
| 113 | - $endTime = time() + 14 * 60; |
|
| 114 | - |
|
| 115 | - $executedJobs = []; |
|
| 116 | - while ($job = $jobList->getNext()) { |
|
| 117 | - if (isset($executedJobs[$job->getId()])) { |
|
| 118 | - $jobList->unlockJob($job); |
|
| 119 | - break; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $logger->debug('Run ' . get_class($job) . ' job with ID ' . $job->getId(), ['app' => 'cron']); |
|
| 123 | - $job->execute($jobList, $logger); |
|
| 124 | - // clean up after unclean jobs |
|
| 125 | - \OC_Util::tearDownFS(); |
|
| 126 | - $logger->debug('Finished ' . get_class($job) . ' job with ID ' . $job->getId(), ['app' => 'cron']); |
|
| 127 | - |
|
| 128 | - $jobList->setLastJob($job); |
|
| 129 | - $executedJobs[$job->getId()] = true; |
|
| 130 | - unset($job); |
|
| 131 | - |
|
| 132 | - if (time() > $endTime) { |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - } else { |
|
| 138 | - // We call cron.php from some website |
|
| 139 | - if ($appMode == 'cron') { |
|
| 140 | - // Cron is cron :-P |
|
| 141 | - OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); |
|
| 142 | - } else { |
|
| 143 | - // Work and success :-) |
|
| 144 | - $jobList = \OC::$server->getJobList(); |
|
| 145 | - $job = $jobList->getNext(); |
|
| 146 | - if ($job != null) { |
|
| 147 | - $job->execute($jobList, $logger); |
|
| 148 | - $jobList->setLastJob($job); |
|
| 149 | - } |
|
| 150 | - OC_JSON::success(); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // Log the successful cron execution |
|
| 155 | - if (\OC::$server->getConfig()->getSystemValue('cron_log', true)) { |
|
| 156 | - \OC::$server->getConfig()->setAppValue('core', 'lastcron', time()); |
|
| 157 | - } |
|
| 158 | - exit(); |
|
| 42 | + require_once __DIR__ . '/lib/base.php'; |
|
| 43 | + |
|
| 44 | + if (\OCP\Util::needUpgrade()) { |
|
| 45 | + \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG); |
|
| 46 | + exit; |
|
| 47 | + } |
|
| 48 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 49 | + \OCP\Util::writeLog('cron', 'We are in maintenance mode, skipping cron', \OCP\Util::DEBUG); |
|
| 50 | + exit; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // load all apps to get all api routes properly setup |
|
| 54 | + OC_App::loadApps(); |
|
| 55 | + |
|
| 56 | + \OC::$server->getSession()->close(); |
|
| 57 | + |
|
| 58 | + // initialize a dummy memory session |
|
| 59 | + $session = new \OC\Session\Memory(''); |
|
| 60 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 61 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 62 | + \OC::$server->setSession($session); |
|
| 63 | + |
|
| 64 | + $logger = \OC::$server->getLogger(); |
|
| 65 | + $config = \OC::$server->getConfig(); |
|
| 66 | + |
|
| 67 | + // Don't do anything if ownCloud has not been installed |
|
| 68 | + if (!$config->getSystemValue('installed', false)) { |
|
| 69 | + exit(0); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + \OC::$server->getTempManager()->cleanOld(); |
|
| 73 | + |
|
| 74 | + // Exit if background jobs are disabled! |
|
| 75 | + $appMode = \OCP\BackgroundJob::getExecutionType(); |
|
| 76 | + if ($appMode == 'none') { |
|
| 77 | + if (OC::$CLI) { |
|
| 78 | + echo 'Background Jobs are disabled!' . PHP_EOL; |
|
| 79 | + } else { |
|
| 80 | + OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); |
|
| 81 | + } |
|
| 82 | + exit(1); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (OC::$CLI) { |
|
| 86 | + // set to run indefinitely if needed |
|
| 87 | + set_time_limit(0); |
|
| 88 | + |
|
| 89 | + // the cron job must be executed with the right user |
|
| 90 | + if (!function_exists('posix_getuid')) { |
|
| 91 | + echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 92 | + exit(0); |
|
| 93 | + } |
|
| 94 | + $user = posix_getpwuid(posix_getuid()); |
|
| 95 | + $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 96 | + if ($user['name'] !== $configUser['name']) { |
|
| 97 | + echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL; |
|
| 98 | + echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 99 | + echo "Web server user: " . $configUser['name'] . PHP_EOL; |
|
| 100 | + exit(0); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // We call ownCloud from the CLI (aka cron) |
|
| 104 | + if ($appMode != 'cron') { |
|
| 105 | + \OCP\BackgroundJob::setExecutionType('cron'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // Work |
|
| 109 | + $jobList = \OC::$server->getJobList(); |
|
| 110 | + |
|
| 111 | + // We only ask for jobs for 14 minutes, because after 15 minutes the next |
|
| 112 | + // system cron task should spawn. |
|
| 113 | + $endTime = time() + 14 * 60; |
|
| 114 | + |
|
| 115 | + $executedJobs = []; |
|
| 116 | + while ($job = $jobList->getNext()) { |
|
| 117 | + if (isset($executedJobs[$job->getId()])) { |
|
| 118 | + $jobList->unlockJob($job); |
|
| 119 | + break; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $logger->debug('Run ' . get_class($job) . ' job with ID ' . $job->getId(), ['app' => 'cron']); |
|
| 123 | + $job->execute($jobList, $logger); |
|
| 124 | + // clean up after unclean jobs |
|
| 125 | + \OC_Util::tearDownFS(); |
|
| 126 | + $logger->debug('Finished ' . get_class($job) . ' job with ID ' . $job->getId(), ['app' => 'cron']); |
|
| 127 | + |
|
| 128 | + $jobList->setLastJob($job); |
|
| 129 | + $executedJobs[$job->getId()] = true; |
|
| 130 | + unset($job); |
|
| 131 | + |
|
| 132 | + if (time() > $endTime) { |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + } else { |
|
| 138 | + // We call cron.php from some website |
|
| 139 | + if ($appMode == 'cron') { |
|
| 140 | + // Cron is cron :-P |
|
| 141 | + OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); |
|
| 142 | + } else { |
|
| 143 | + // Work and success :-) |
|
| 144 | + $jobList = \OC::$server->getJobList(); |
|
| 145 | + $job = $jobList->getNext(); |
|
| 146 | + if ($job != null) { |
|
| 147 | + $job->execute($jobList, $logger); |
|
| 148 | + $jobList->setLastJob($job); |
|
| 149 | + } |
|
| 150 | + OC_JSON::success(); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // Log the successful cron execution |
|
| 155 | + if (\OC::$server->getConfig()->getSystemValue('cron_log', true)) { |
|
| 156 | + \OC::$server->getConfig()->setAppValue('core', 'lastcron', time()); |
|
| 157 | + } |
|
| 158 | + exit(); |
|
| 159 | 159 | |
| 160 | 160 | } catch (Exception $ex) { |
| 161 | - \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 161 | + \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 162 | 162 | } catch (Error $ex) { |
| 163 | - \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 163 | + \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 164 | 164 | } |
@@ -38,139 +38,139 @@ |
||
| 38 | 38 | |
| 39 | 39 | class DecryptAll extends Command { |
| 40 | 40 | |
| 41 | - /** @var IManager */ |
|
| 42 | - protected $encryptionManager; |
|
| 43 | - |
|
| 44 | - /** @var IAppManager */ |
|
| 45 | - protected $appManager; |
|
| 46 | - |
|
| 47 | - /** @var IConfig */ |
|
| 48 | - protected $config; |
|
| 49 | - |
|
| 50 | - /** @var QuestionHelper */ |
|
| 51 | - protected $questionHelper; |
|
| 52 | - |
|
| 53 | - /** @var bool */ |
|
| 54 | - protected $wasTrashbinEnabled; |
|
| 55 | - |
|
| 56 | - /** @var bool */ |
|
| 57 | - protected $wasMaintenanceModeEnabled; |
|
| 58 | - |
|
| 59 | - /** @var \OC\Encryption\DecryptAll */ |
|
| 60 | - protected $decryptAll; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param IManager $encryptionManager |
|
| 64 | - * @param IAppManager $appManager |
|
| 65 | - * @param IConfig $config |
|
| 66 | - * @param \OC\Encryption\DecryptAll $decryptAll |
|
| 67 | - * @param QuestionHelper $questionHelper |
|
| 68 | - */ |
|
| 69 | - public function __construct( |
|
| 70 | - IManager $encryptionManager, |
|
| 71 | - IAppManager $appManager, |
|
| 72 | - IConfig $config, |
|
| 73 | - \OC\Encryption\DecryptAll $decryptAll, |
|
| 74 | - QuestionHelper $questionHelper |
|
| 75 | - ) { |
|
| 76 | - parent::__construct(); |
|
| 77 | - |
|
| 78 | - $this->appManager = $appManager; |
|
| 79 | - $this->encryptionManager = $encryptionManager; |
|
| 80 | - $this->config = $config; |
|
| 81 | - $this->decryptAll = $decryptAll; |
|
| 82 | - $this->questionHelper = $questionHelper; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Set maintenance mode and disable the trashbin app |
|
| 87 | - */ |
|
| 88 | - protected function forceMaintenanceAndTrashbin() { |
|
| 89 | - $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
| 90 | - $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
| 91 | - $this->config->setSystemValue('maintenance', true); |
|
| 92 | - $this->appManager->disableApp('files_trashbin'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Reset the maintenance mode and re-enable the trashbin app |
|
| 97 | - */ |
|
| 98 | - protected function resetMaintenanceAndTrashbin() { |
|
| 99 | - $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
| 100 | - if ($this->wasTrashbinEnabled) { |
|
| 101 | - $this->appManager->enableApp('files_trashbin'); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - protected function configure() { |
|
| 106 | - parent::configure(); |
|
| 107 | - |
|
| 108 | - $this->setName('encryption:decrypt-all'); |
|
| 109 | - $this->setDescription('Disable server-side encryption and decrypt all files'); |
|
| 110 | - $this->setHelp( |
|
| 111 | - 'This will disable server-side encryption and decrypt all files for ' |
|
| 112 | - . 'all users if it is supported by your encryption module. ' |
|
| 113 | - . 'Please make sure that no user access his files during this process!' |
|
| 114 | - ); |
|
| 115 | - $this->addArgument( |
|
| 116 | - 'user', |
|
| 117 | - InputArgument::OPTIONAL, |
|
| 118 | - 'user for which you want to decrypt all files (optional)', |
|
| 119 | - '' |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 124 | - |
|
| 125 | - try { |
|
| 126 | - if ($this->encryptionManager->isEnabled() === true) { |
|
| 127 | - $output->write('Disable server side encryption... '); |
|
| 128 | - $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
| 129 | - $output->writeln('done.'); |
|
| 130 | - } else { |
|
| 131 | - $output->writeln('Server side encryption not enabled. Nothing to do.'); |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $uid = $input->getArgument('user'); |
|
| 136 | - if ($uid === '') { |
|
| 137 | - $message = 'your Nextcloud'; |
|
| 138 | - } else { |
|
| 139 | - $message = "$uid's account"; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $output->writeln("\n"); |
|
| 143 | - $output->writeln("You are about to start to decrypt all files stored in $message."); |
|
| 144 | - $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
|
| 145 | - $output->writeln('Depending on the number and size of your files this can take some time'); |
|
| 146 | - $output->writeln('Please make sure that no user access his files during this process!'); |
|
| 147 | - $output->writeln(''); |
|
| 148 | - $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
| 149 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 150 | - $this->forceMaintenanceAndTrashbin(); |
|
| 151 | - $user = $input->getArgument('user'); |
|
| 152 | - $result = $this->decryptAll->decryptAll($input, $output, $user); |
|
| 153 | - if ($result === false) { |
|
| 154 | - $output->writeln(' aborted.'); |
|
| 155 | - $output->writeln('Server side encryption remains enabled'); |
|
| 156 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
| 157 | - } else if ($uid !== '') { |
|
| 158 | - $output->writeln('Server side encryption remains enabled'); |
|
| 159 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
| 160 | - } |
|
| 161 | - $this->resetMaintenanceAndTrashbin(); |
|
| 162 | - } else { |
|
| 163 | - $output->write('Enable server side encryption... '); |
|
| 164 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
| 165 | - $output->writeln('done.'); |
|
| 166 | - $output->writeln('aborted'); |
|
| 167 | - } |
|
| 168 | - } catch (\Exception $e) { |
|
| 169 | - // enable server side encryption again if something went wrong |
|
| 170 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
| 171 | - $this->resetMaintenanceAndTrashbin(); |
|
| 172 | - throw $e; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - } |
|
| 41 | + /** @var IManager */ |
|
| 42 | + protected $encryptionManager; |
|
| 43 | + |
|
| 44 | + /** @var IAppManager */ |
|
| 45 | + protected $appManager; |
|
| 46 | + |
|
| 47 | + /** @var IConfig */ |
|
| 48 | + protected $config; |
|
| 49 | + |
|
| 50 | + /** @var QuestionHelper */ |
|
| 51 | + protected $questionHelper; |
|
| 52 | + |
|
| 53 | + /** @var bool */ |
|
| 54 | + protected $wasTrashbinEnabled; |
|
| 55 | + |
|
| 56 | + /** @var bool */ |
|
| 57 | + protected $wasMaintenanceModeEnabled; |
|
| 58 | + |
|
| 59 | + /** @var \OC\Encryption\DecryptAll */ |
|
| 60 | + protected $decryptAll; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param IManager $encryptionManager |
|
| 64 | + * @param IAppManager $appManager |
|
| 65 | + * @param IConfig $config |
|
| 66 | + * @param \OC\Encryption\DecryptAll $decryptAll |
|
| 67 | + * @param QuestionHelper $questionHelper |
|
| 68 | + */ |
|
| 69 | + public function __construct( |
|
| 70 | + IManager $encryptionManager, |
|
| 71 | + IAppManager $appManager, |
|
| 72 | + IConfig $config, |
|
| 73 | + \OC\Encryption\DecryptAll $decryptAll, |
|
| 74 | + QuestionHelper $questionHelper |
|
| 75 | + ) { |
|
| 76 | + parent::__construct(); |
|
| 77 | + |
|
| 78 | + $this->appManager = $appManager; |
|
| 79 | + $this->encryptionManager = $encryptionManager; |
|
| 80 | + $this->config = $config; |
|
| 81 | + $this->decryptAll = $decryptAll; |
|
| 82 | + $this->questionHelper = $questionHelper; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Set maintenance mode and disable the trashbin app |
|
| 87 | + */ |
|
| 88 | + protected function forceMaintenanceAndTrashbin() { |
|
| 89 | + $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
| 90 | + $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
| 91 | + $this->config->setSystemValue('maintenance', true); |
|
| 92 | + $this->appManager->disableApp('files_trashbin'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Reset the maintenance mode and re-enable the trashbin app |
|
| 97 | + */ |
|
| 98 | + protected function resetMaintenanceAndTrashbin() { |
|
| 99 | + $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
| 100 | + if ($this->wasTrashbinEnabled) { |
|
| 101 | + $this->appManager->enableApp('files_trashbin'); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + protected function configure() { |
|
| 106 | + parent::configure(); |
|
| 107 | + |
|
| 108 | + $this->setName('encryption:decrypt-all'); |
|
| 109 | + $this->setDescription('Disable server-side encryption and decrypt all files'); |
|
| 110 | + $this->setHelp( |
|
| 111 | + 'This will disable server-side encryption and decrypt all files for ' |
|
| 112 | + . 'all users if it is supported by your encryption module. ' |
|
| 113 | + . 'Please make sure that no user access his files during this process!' |
|
| 114 | + ); |
|
| 115 | + $this->addArgument( |
|
| 116 | + 'user', |
|
| 117 | + InputArgument::OPTIONAL, |
|
| 118 | + 'user for which you want to decrypt all files (optional)', |
|
| 119 | + '' |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 124 | + |
|
| 125 | + try { |
|
| 126 | + if ($this->encryptionManager->isEnabled() === true) { |
|
| 127 | + $output->write('Disable server side encryption... '); |
|
| 128 | + $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
| 129 | + $output->writeln('done.'); |
|
| 130 | + } else { |
|
| 131 | + $output->writeln('Server side encryption not enabled. Nothing to do.'); |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + $uid = $input->getArgument('user'); |
|
| 136 | + if ($uid === '') { |
|
| 137 | + $message = 'your Nextcloud'; |
|
| 138 | + } else { |
|
| 139 | + $message = "$uid's account"; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $output->writeln("\n"); |
|
| 143 | + $output->writeln("You are about to start to decrypt all files stored in $message."); |
|
| 144 | + $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
|
| 145 | + $output->writeln('Depending on the number and size of your files this can take some time'); |
|
| 146 | + $output->writeln('Please make sure that no user access his files during this process!'); |
|
| 147 | + $output->writeln(''); |
|
| 148 | + $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
| 149 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 150 | + $this->forceMaintenanceAndTrashbin(); |
|
| 151 | + $user = $input->getArgument('user'); |
|
| 152 | + $result = $this->decryptAll->decryptAll($input, $output, $user); |
|
| 153 | + if ($result === false) { |
|
| 154 | + $output->writeln(' aborted.'); |
|
| 155 | + $output->writeln('Server side encryption remains enabled'); |
|
| 156 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
| 157 | + } else if ($uid !== '') { |
|
| 158 | + $output->writeln('Server side encryption remains enabled'); |
|
| 159 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
| 160 | + } |
|
| 161 | + $this->resetMaintenanceAndTrashbin(); |
|
| 162 | + } else { |
|
| 163 | + $output->write('Enable server side encryption... '); |
|
| 164 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
| 165 | + $output->writeln('done.'); |
|
| 166 | + $output->writeln('aborted'); |
|
| 167 | + } |
|
| 168 | + } catch (\Exception $e) { |
|
| 169 | + // enable server side encryption again if something went wrong |
|
| 170 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
| 171 | + $this->resetMaintenanceAndTrashbin(); |
|
| 172 | + throw $e; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + } |
|
| 176 | 176 | } |
@@ -34,102 +34,102 @@ |
||
| 34 | 34 | |
| 35 | 35 | class EncryptAll extends Command { |
| 36 | 36 | |
| 37 | - /** @var IManager */ |
|
| 38 | - protected $encryptionManager; |
|
| 39 | - |
|
| 40 | - /** @var IAppManager */ |
|
| 41 | - protected $appManager; |
|
| 42 | - |
|
| 43 | - /** @var IConfig */ |
|
| 44 | - protected $config; |
|
| 45 | - |
|
| 46 | - /** @var QuestionHelper */ |
|
| 47 | - protected $questionHelper; |
|
| 48 | - |
|
| 49 | - /** @var bool */ |
|
| 50 | - protected $wasTrashbinEnabled; |
|
| 51 | - |
|
| 52 | - /** @var bool */ |
|
| 53 | - protected $wasMaintenanceModeEnabled; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param IManager $encryptionManager |
|
| 57 | - * @param IAppManager $appManager |
|
| 58 | - * @param IConfig $config |
|
| 59 | - * @param QuestionHelper $questionHelper |
|
| 60 | - */ |
|
| 61 | - public function __construct( |
|
| 62 | - IManager $encryptionManager, |
|
| 63 | - IAppManager $appManager, |
|
| 64 | - IConfig $config, |
|
| 65 | - QuestionHelper $questionHelper |
|
| 66 | - ) { |
|
| 67 | - parent::__construct(); |
|
| 68 | - $this->appManager = $appManager; |
|
| 69 | - $this->encryptionManager = $encryptionManager; |
|
| 70 | - $this->config = $config; |
|
| 71 | - $this->questionHelper = $questionHelper; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Set maintenance mode and disable the trashbin app |
|
| 76 | - */ |
|
| 77 | - protected function forceMaintenanceAndTrashbin() { |
|
| 78 | - $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
| 79 | - $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
| 80 | - $this->config->setSystemValue('maintenance', true); |
|
| 81 | - $this->appManager->disableApp('files_trashbin'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Reset the maintenance mode and re-enable the trashbin app |
|
| 86 | - */ |
|
| 87 | - protected function resetMaintenanceAndTrashbin() { |
|
| 88 | - $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
| 89 | - if ($this->wasTrashbinEnabled) { |
|
| 90 | - $this->appManager->enableApp('files_trashbin'); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - protected function configure() { |
|
| 95 | - parent::configure(); |
|
| 96 | - |
|
| 97 | - $this->setName('encryption:encrypt-all'); |
|
| 98 | - $this->setDescription('Encrypt all files for all users'); |
|
| 99 | - $this->setHelp( |
|
| 100 | - 'This will encrypt all files for all users. ' |
|
| 101 | - . 'Please make sure that no user access his files during this process!' |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 106 | - |
|
| 107 | - if ($this->encryptionManager->isEnabled() === false) { |
|
| 108 | - throw new \Exception('Server side encryption is not enabled'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $output->writeln("\n"); |
|
| 112 | - $output->writeln('You are about to start to encrypt all files stored in your ownCloud.'); |
|
| 113 | - $output->writeln('It will depend on the encryption module you use which files get encrypted.'); |
|
| 114 | - $output->writeln('Depending on the number and size of your files this can take some time'); |
|
| 115 | - $output->writeln('Please make sure that no user access his files during this process!'); |
|
| 116 | - $output->writeln(''); |
|
| 117 | - $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
| 118 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 119 | - $this->forceMaintenanceAndTrashbin(); |
|
| 120 | - |
|
| 121 | - try { |
|
| 122 | - $defaultModule = $this->encryptionManager->getEncryptionModule(); |
|
| 123 | - $defaultModule->encryptAll($input, $output); |
|
| 124 | - } catch (\Exception $ex) { |
|
| 125 | - $this->resetMaintenanceAndTrashbin(); |
|
| 126 | - throw $ex; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $this->resetMaintenanceAndTrashbin(); |
|
| 130 | - } else { |
|
| 131 | - $output->writeln('aborted'); |
|
| 132 | - } |
|
| 133 | - } |
|
| 37 | + /** @var IManager */ |
|
| 38 | + protected $encryptionManager; |
|
| 39 | + |
|
| 40 | + /** @var IAppManager */ |
|
| 41 | + protected $appManager; |
|
| 42 | + |
|
| 43 | + /** @var IConfig */ |
|
| 44 | + protected $config; |
|
| 45 | + |
|
| 46 | + /** @var QuestionHelper */ |
|
| 47 | + protected $questionHelper; |
|
| 48 | + |
|
| 49 | + /** @var bool */ |
|
| 50 | + protected $wasTrashbinEnabled; |
|
| 51 | + |
|
| 52 | + /** @var bool */ |
|
| 53 | + protected $wasMaintenanceModeEnabled; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param IManager $encryptionManager |
|
| 57 | + * @param IAppManager $appManager |
|
| 58 | + * @param IConfig $config |
|
| 59 | + * @param QuestionHelper $questionHelper |
|
| 60 | + */ |
|
| 61 | + public function __construct( |
|
| 62 | + IManager $encryptionManager, |
|
| 63 | + IAppManager $appManager, |
|
| 64 | + IConfig $config, |
|
| 65 | + QuestionHelper $questionHelper |
|
| 66 | + ) { |
|
| 67 | + parent::__construct(); |
|
| 68 | + $this->appManager = $appManager; |
|
| 69 | + $this->encryptionManager = $encryptionManager; |
|
| 70 | + $this->config = $config; |
|
| 71 | + $this->questionHelper = $questionHelper; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Set maintenance mode and disable the trashbin app |
|
| 76 | + */ |
|
| 77 | + protected function forceMaintenanceAndTrashbin() { |
|
| 78 | + $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
| 79 | + $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
| 80 | + $this->config->setSystemValue('maintenance', true); |
|
| 81 | + $this->appManager->disableApp('files_trashbin'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Reset the maintenance mode and re-enable the trashbin app |
|
| 86 | + */ |
|
| 87 | + protected function resetMaintenanceAndTrashbin() { |
|
| 88 | + $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
| 89 | + if ($this->wasTrashbinEnabled) { |
|
| 90 | + $this->appManager->enableApp('files_trashbin'); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + protected function configure() { |
|
| 95 | + parent::configure(); |
|
| 96 | + |
|
| 97 | + $this->setName('encryption:encrypt-all'); |
|
| 98 | + $this->setDescription('Encrypt all files for all users'); |
|
| 99 | + $this->setHelp( |
|
| 100 | + 'This will encrypt all files for all users. ' |
|
| 101 | + . 'Please make sure that no user access his files during this process!' |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 106 | + |
|
| 107 | + if ($this->encryptionManager->isEnabled() === false) { |
|
| 108 | + throw new \Exception('Server side encryption is not enabled'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $output->writeln("\n"); |
|
| 112 | + $output->writeln('You are about to start to encrypt all files stored in your ownCloud.'); |
|
| 113 | + $output->writeln('It will depend on the encryption module you use which files get encrypted.'); |
|
| 114 | + $output->writeln('Depending on the number and size of your files this can take some time'); |
|
| 115 | + $output->writeln('Please make sure that no user access his files during this process!'); |
|
| 116 | + $output->writeln(''); |
|
| 117 | + $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
| 118 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 119 | + $this->forceMaintenanceAndTrashbin(); |
|
| 120 | + |
|
| 121 | + try { |
|
| 122 | + $defaultModule = $this->encryptionManager->getEncryptionModule(); |
|
| 123 | + $defaultModule->encryptAll($input, $output); |
|
| 124 | + } catch (\Exception $ex) { |
|
| 125 | + $this->resetMaintenanceAndTrashbin(); |
|
| 126 | + throw $ex; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $this->resetMaintenanceAndTrashbin(); |
|
| 130 | + } else { |
|
| 131 | + $output->writeln('aborted'); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | } |
@@ -40,114 +40,114 @@ |
||
| 40 | 40 | $application->add(new OC\Core\Command\App\CheckCode($infoParser)); |
| 41 | 41 | $application->add(new OC\Core\Command\L10n\CreateJs()); |
| 42 | 42 | $application->add(new \OC\Core\Command\Integrity\SignApp( |
| 43 | - \OC::$server->getIntegrityCodeChecker(), |
|
| 44 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
| 45 | - \OC::$server->getURLGenerator() |
|
| 43 | + \OC::$server->getIntegrityCodeChecker(), |
|
| 44 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
| 45 | + \OC::$server->getURLGenerator() |
|
| 46 | 46 | )); |
| 47 | 47 | $application->add(new \OC\Core\Command\Integrity\SignCore( |
| 48 | - \OC::$server->getIntegrityCodeChecker(), |
|
| 49 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
| 48 | + \OC::$server->getIntegrityCodeChecker(), |
|
| 49 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
| 50 | 50 | )); |
| 51 | 51 | $application->add(new \OC\Core\Command\Integrity\CheckApp( |
| 52 | - \OC::$server->getIntegrityCodeChecker() |
|
| 52 | + \OC::$server->getIntegrityCodeChecker() |
|
| 53 | 53 | )); |
| 54 | 54 | $application->add(new \OC\Core\Command\Integrity\CheckCore( |
| 55 | - \OC::$server->getIntegrityCodeChecker() |
|
| 55 | + \OC::$server->getIntegrityCodeChecker() |
|
| 56 | 56 | )); |
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | if (\OC::$server->getConfig()->getSystemValue('installed', false)) { |
| 60 | - $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
| 61 | - $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); |
|
| 62 | - $application->add(new OC\Core\Command\App\GetPath()); |
|
| 63 | - $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
| 60 | + $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
| 61 | + $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); |
|
| 62 | + $application->add(new OC\Core\Command\App\GetPath()); |
|
| 63 | + $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
| 64 | 64 | |
| 65 | - $application->add(new OC\Core\Command\TwoFactorAuth\Enable( |
|
| 66 | - \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
| 67 | - )); |
|
| 68 | - $application->add(new OC\Core\Command\TwoFactorAuth\Disable( |
|
| 69 | - \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
| 70 | - )); |
|
| 65 | + $application->add(new OC\Core\Command\TwoFactorAuth\Enable( |
|
| 66 | + \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
| 67 | + )); |
|
| 68 | + $application->add(new OC\Core\Command\TwoFactorAuth\Disable( |
|
| 69 | + \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
| 70 | + )); |
|
| 71 | 71 | |
| 72 | - $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
| 73 | - $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
| 74 | - $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
| 72 | + $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
| 73 | + $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
| 74 | + $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
| 75 | 75 | |
| 76 | - $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
| 77 | - $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
| 78 | - $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
| 79 | - $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
| 80 | - $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
| 81 | - $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
| 82 | - $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
| 83 | - $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
| 76 | + $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
| 77 | + $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
| 78 | + $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
| 79 | + $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
| 80 | + $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
| 81 | + $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
| 82 | + $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
| 83 | + $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
| 84 | 84 | |
| 85 | - $application->add(new OC\Core\Command\Db\GenerateChangeScript()); |
|
| 86 | - $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getConfig()))); |
|
| 85 | + $application->add(new OC\Core\Command\Db\GenerateChangeScript()); |
|
| 86 | + $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getConfig()))); |
|
| 87 | 87 | |
| 88 | - $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
| 89 | - $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
| 90 | - $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); |
|
| 91 | - $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); |
|
| 92 | - $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
| 93 | - $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
| 94 | - $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
| 95 | - \OC::$server->getEncryptionManager(), |
|
| 96 | - \OC::$server->getAppManager(), |
|
| 97 | - \OC::$server->getConfig(), |
|
| 98 | - new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
| 99 | - new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
| 100 | - ); |
|
| 88 | + $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
| 89 | + $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
| 90 | + $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); |
|
| 91 | + $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); |
|
| 92 | + $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
| 93 | + $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
| 94 | + $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
| 95 | + \OC::$server->getEncryptionManager(), |
|
| 96 | + \OC::$server->getAppManager(), |
|
| 97 | + \OC::$server->getConfig(), |
|
| 98 | + new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
| 99 | + new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
| 103 | - $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
| 102 | + $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
| 103 | + $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
| 104 | 104 | |
| 105 | - $view = new \OC\Files\View(); |
|
| 106 | - $util = new \OC\Encryption\Util( |
|
| 107 | - $view, |
|
| 108 | - \OC::$server->getUserManager(), |
|
| 109 | - \OC::$server->getGroupManager(), |
|
| 110 | - \OC::$server->getConfig() |
|
| 111 | - ); |
|
| 112 | - $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
| 113 | - $view, |
|
| 114 | - \OC::$server->getUserManager(), |
|
| 115 | - \OC::$server->getConfig(), |
|
| 116 | - $util, |
|
| 117 | - new \Symfony\Component\Console\Helper\QuestionHelper() |
|
| 118 | - ) |
|
| 119 | - ); |
|
| 120 | - $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
| 105 | + $view = new \OC\Files\View(); |
|
| 106 | + $util = new \OC\Encryption\Util( |
|
| 107 | + $view, |
|
| 108 | + \OC::$server->getUserManager(), |
|
| 109 | + \OC::$server->getGroupManager(), |
|
| 110 | + \OC::$server->getConfig() |
|
| 111 | + ); |
|
| 112 | + $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
| 113 | + $view, |
|
| 114 | + \OC::$server->getUserManager(), |
|
| 115 | + \OC::$server->getConfig(), |
|
| 116 | + $util, |
|
| 117 | + new \Symfony\Component\Console\Helper\QuestionHelper() |
|
| 118 | + ) |
|
| 119 | + ); |
|
| 120 | + $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
| 121 | 121 | |
| 122 | - $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
| 123 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
| 124 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
| 125 | - $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
| 126 | - $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
| 122 | + $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
| 123 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
| 124 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
| 125 | + $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
| 126 | + $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
| 127 | 127 | |
| 128 | - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
| 129 | - $application->add(new OC\Core\Command\Maintenance\Repair( |
|
| 130 | - new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), |
|
| 131 | - \OC::$server->getEventDispatcher())); |
|
| 128 | + $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
| 129 | + $application->add(new OC\Core\Command\Maintenance\Repair( |
|
| 130 | + new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), |
|
| 131 | + \OC::$server->getEventDispatcher())); |
|
| 132 | 132 | |
| 133 | - $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 134 | - $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
| 135 | - $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
| 136 | - $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
| 137 | - $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
| 138 | - $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager())); |
|
| 139 | - $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
| 140 | - $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
| 141 | - $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager())); |
|
| 142 | - $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 133 | + $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 134 | + $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
| 135 | + $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
| 136 | + $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
| 137 | + $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
| 138 | + $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager())); |
|
| 139 | + $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
| 140 | + $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
| 141 | + $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager())); |
|
| 142 | + $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 143 | 143 | |
| 144 | - $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
| 145 | - $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 146 | - $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 144 | + $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
| 145 | + $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 146 | + $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 147 | 147 | |
| 148 | - $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); |
|
| 149 | - $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); |
|
| 150 | - $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); |
|
| 148 | + $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); |
|
| 149 | + $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); |
|
| 150 | + $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); |
|
| 151 | 151 | } else { |
| 152 | - $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getConfig())); |
|
| 152 | + $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getConfig())); |
|
| 153 | 153 | } |