/** * Append the correct ErrorDocument path for Apache hosts */ public static function updateHtaccess() { // From CLI we don't know the defined web root. Thus we can't write any // directives into the .htaccess file. if (\OC::$CLI) { return; } $setupHelper = new \OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); $content = ''; if (strpos($htaccessContent, 'ErrorDocument 403') === false) { //custom 403 error page $content .= "\nErrorDocument 403 " . \OC::$WEBROOT . "/core/templates/403.php"; } if (strpos($htaccessContent, 'ErrorDocument 404') === false) { //custom 404 error page $content .= "\nErrorDocument 404 " . \OC::$WEBROOT . "/core/templates/404.php"; } // Add rewrite base $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; $content .= "\n<IfModule mod_rewrite.c>"; $content .= "\n RewriteBase " . $webRoot; $content .= "\n <IfModule mod_env.c>"; $content .= "\n SetEnv front_controller_active true"; $content .= "\n <IfModule mod_dir.c>"; $content .= "\n DirectorySlash off"; $content .= "\n </IfModule>"; $content .= "\n </IfModule>"; $content .= "\n</IfModule>"; if ($content !== '') { //suppress errors in case we don't have permissions for it @file_put_contents($setupHelper->pathToHtaccess(), $content . "\n", FILE_APPEND); } }
/** * Append the correct ErrorDocument path for Apache hosts */ public static function updateHtaccess() { $config = \OC::$server->getConfig(); // For CLI read the value from overwrite.cli.url if (\OC::$CLI) { $webRoot = $config->getSystemValue('overwrite.cli.url', ''); if ($webRoot === '') { return; } $webRoot = parse_url($webRoot, PHP_URL_PATH); $webRoot = rtrim($webRoot, '/'); } else { $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; } $setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n"; $htaccessContent = explode($content, $htaccessContent, 2)[0]; //custom 403 error page $content .= "\nErrorDocument 403 " . $webRoot . "/core/templates/403.php"; //custom 404 error page $content .= "\nErrorDocument 404 " . $webRoot . "/core/templates/404.php"; // Add rewrite rules if the RewriteBase is configured $rewriteBase = $config->getSystemValue('htaccess.RewriteBase', ''); if ($rewriteBase !== '') { $content .= "\n<IfModule mod_rewrite.c>"; $content .= "\n Options -MultiViews"; $content .= "\n RewriteRule ^core/js/oc.js\$ index.php [PT,E=PATH_INFO:\$1]"; $content .= "\n RewriteRule ^core/preview.png\$ index.php [PT,E=PATH_INFO:\$1]"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !\\.(css|js|svg|gif|png|html|ttf|woff|ico|jpg|jpeg)\$"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico\$"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/remote.php"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/public.php"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/cron.php"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/status.php"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/updater/"; $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs-provider/"; $content .= "\n RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*"; $content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:\$1]"; $content .= "\n RewriteBase " . $rewriteBase; $content .= "\n <IfModule mod_env.c>"; $content .= "\n SetEnv front_controller_active true"; $content .= "\n <IfModule mod_dir.c>"; $content .= "\n DirectorySlash off"; $content .= "\n </IfModule>"; $content .= "\n </IfModule>"; $content .= "\n</IfModule>"; } if ($content !== '') { //suppress errors in case we don't have permissions for it @file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n"); } }
/** * Append the correct ErrorDocument path for Apache hosts * * @throws \OC\HintException If .htaccess does not include the current version */ public static function updateHtaccess() { $setupHelper = new \OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults()); if (!$setupHelper->isCurrentHtaccess()) { throw new \OC\HintException('.htaccess file has the wrong version. Please upload the correct version. Maybe you forgot to replace it after updating?'); } $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); $content = ''; if (strpos($htaccessContent, 'ErrorDocument 403') === false) { //custom 403 error page $content .= "\nErrorDocument 403 " . \OC::$WEBROOT . "/core/templates/403.php"; } if (strpos($htaccessContent, 'ErrorDocument 404') === false) { //custom 404 error page $content .= "\nErrorDocument 404 " . \OC::$WEBROOT . "/core/templates/404.php"; } if ($content !== '') { //suppress errors in case we don't have permissions for it @file_put_contents($setupHelper->pathToHtaccess(), $content . "\n", FILE_APPEND); } }
/** * check if the current server configuration is suitable for ownCloud * * @param \OCP\IConfig $config * @return array arrays with error messages and hints */ public static function checkServer(\OCP\IConfig $config) { $l = \OC::$server->getL10N('lib'); $errors = array(); $CONFIG_DATADIRECTORY = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data'); if (!self::needUpgrade($config) && $config->getSystemValue('installed', false)) { // this check needs to be done every time $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); } // Assume that if checkServer() succeeded before in this session, then all is fine. if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { return $errors; } $webServerRestart = false; $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); $availableDatabases = $setup->getSupportedDatabases(); if (empty($availableDatabases)) { $errors[] = array('error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), 'hint' => ''); $webServerRestart = true; } // Check if server running on Windows platform if (OC_Util::runningOnWindows()) { $errors[] = ['error' => $l->t('Microsoft Windows Platform is not supported'), 'hint' => $l->t('Running ownCloud Server on the Microsoft Windows platform is not supported. We suggest you ' . 'use a Linux server in a virtual machine if you have no option for migrating the server itself. ' . 'Find Linux packages as well as easy to deploy virtual machine images on <a href="%s">%s</a>. ' . 'For migrating existing installations to Linux you can find some tips and a migration script ' . 'in <a href="%s">our documentation</a>.', ['https://owncloud.org/install/', 'owncloud.org/install/', 'https://owncloud.org/?p=8045'])]; } // Check if config folder is writable. if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { $errors[] = array('error' => $l->t('Cannot write into "config" directory'), 'hint' => $l->t('This can usually be fixed by ' . '%sgiving the webserver write access to the config directory%s.', array('<a href="' . \OC_Helper::linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'))); } // Check if there is a writable install folder. if ($config->getSystemValue('appstoreenabled', true)) { if (OC_App::getInstallPath() === null || !is_writable(OC_App::getInstallPath()) || !is_readable(OC_App::getInstallPath())) { $errors[] = array('error' => $l->t('Cannot write into "apps" directory'), 'hint' => $l->t('This can usually be fixed by ' . '%sgiving the webserver write access to the apps directory%s' . ' or disabling the appstore in the config file.', array('<a href="' . \OC_Helper::linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'))); } } // Create root dir. if ($config->getSystemValue('installed', false)) { if (!is_dir($CONFIG_DATADIRECTORY)) { $success = @mkdir($CONFIG_DATADIRECTORY); if ($success) { $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); } else { $errors[] = array('error' => $l->t('Cannot create "data" directory (%s)', array($CONFIG_DATADIRECTORY)), 'hint' => $l->t('This can usually be fixed by ' . '<a href="%s" target="_blank">giving the webserver write access to the root directory</a>.', array(OC_Helper::linkToDocs('admin-dir_permissions')))); } } else { if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { //common hint for all file permissions error messages $permissionsHint = $l->t('Permissions can usually be fixed by ' . '%sgiving the webserver write access to the root directory%s.', array('<a href="' . \OC_Helper::linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>')); $errors[] = array('error' => 'Data directory (' . $CONFIG_DATADIRECTORY . ') not writable by ownCloud', 'hint' => $permissionsHint); } else { $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); } } } if (!OC_Util::isSetLocaleWorking()) { $errors[] = array('error' => $l->t('Setting locale to %s failed', array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.')); } // Contains the dependencies that should be checked against // classes = class_exists // functions = function_exists // defined = defined // ini = ini_get // If the dependency is not found the missing module name is shown to the EndUser // When adding new checks always verify that they pass on Travis as well // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini $dependencies = array('classes' => array('ZipArchive' => 'zip', 'DOMDocument' => 'dom', 'XMLWriter' => 'XMLWriter'), 'functions' => ['xml_parser_create' => 'libxml', 'mb_detect_encoding' => 'mb multibyte', 'ctype_digit' => 'ctype', 'json_encode' => 'JSON', 'gd_info' => 'GD', 'gzencode' => 'zlib', 'iconv' => 'iconv', 'simplexml_load_string' => 'SimpleXML', 'hash' => 'HASH Message Digest Framework', 'curl_init' => 'cURL'], 'defined' => array('PDO::ATTR_DRIVER_NAME' => 'PDO'), 'ini' => ['default_charset' => 'UTF-8']); $missingDependencies = array(); $invalidIniSettings = []; $moduleHint = $l->t('Please ask your server administrator to install the module.'); /** * FIXME: The dependency check does not work properly on HHVM on the moment * and prevents installation. Once HHVM is more compatible with our * approach to check for these values we should re-enable those * checks. */ $iniWrapper = \OC::$server->getIniWrapper(); if (!self::runningOnHhvm()) { foreach ($dependencies['classes'] as $class => $module) { if (!class_exists($class)) { $missingDependencies[] = $module; } } foreach ($dependencies['functions'] as $function => $module) { if (!function_exists($function)) { $missingDependencies[] = $module; } } foreach ($dependencies['defined'] as $defined => $module) { if (!defined($defined)) { $missingDependencies[] = $module; } } foreach ($dependencies['ini'] as $setting => $expected) { if (is_bool($expected)) { if ($iniWrapper->getBool($setting) !== $expected) { $invalidIniSettings[] = [$setting, $expected]; } } if (is_int($expected)) { if ($iniWrapper->getNumeric($setting) !== $expected) { $invalidIniSettings[] = [$setting, $expected]; } } if (is_string($expected)) { if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { $invalidIniSettings[] = [$setting, $expected]; } } } } foreach ($missingDependencies as $missingDependency) { $errors[] = array('error' => $l->t('PHP module %s not installed.', array($missingDependency)), 'hint' => $moduleHint); $webServerRestart = true; } foreach ($invalidIniSettings as $setting) { if (is_bool($setting[1])) { $setting[1] = $setting[1] ? 'on' : 'off'; } $errors[] = ['error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), 'hint' => $l->t('Adjusting this setting in php.ini will make ownCloud run again')]; $webServerRestart = true; } /** * The mbstring.func_overload check can only be performed if the mbstring * module is installed as it will return null if the checking setting is * not available and thus a check on the boolean value fails. * * TODO: Should probably be implemented in the above generic dependency * check somehow in the long-term. */ if ($iniWrapper->getBool('mbstring.func_overload') !== null && $iniWrapper->getBool('mbstring.func_overload') === true) { $errors[] = array('error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini')); } if (!self::isAnnotationsWorking()) { $errors[] = array('error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')); } if (!\OC::$CLI && $webServerRestart) { $errors[] = array('error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), 'hint' => $l->t('Please ask your server administrator to restart the web server.')); } $errors = array_merge($errors, self::checkDatabaseVersion()); // Cache the result of this function \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); return $errors; }
/** * Append the correct ErrorDocument path for Apache hosts */ public static function updateHtaccess() { $config = \OC::$server->getConfig(); // For CLI read the value from overwrite.cli.url if (\OC::$CLI) { $webRoot = $config->getSystemValue('overwrite.cli.url', ''); if ($webRoot === '') { return; } $webRoot = parse_url($webRoot, PHP_URL_PATH); $webRoot = rtrim($webRoot, '/'); } else { $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; } $setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n"; if (strpos($htaccessContent, $content) === false) { //custom 403 error page $content .= "\nErrorDocument 403 " . $webRoot . "/core/templates/403.php"; //custom 404 error page $content .= "\nErrorDocument 404 " . $webRoot . "/core/templates/404.php"; // ownCloud may be configured to live at the root folder without a // trailing slash being specified. In this case manually set the // rewrite base to `/` $rewriteBase = $webRoot; if ($webRoot === '') { $rewriteBase = '/'; } // Add rewrite base $content .= "\n<IfModule mod_rewrite.c>"; $content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:\$1]"; $content .= "\n RewriteBase " . $rewriteBase; $content .= "\n <IfModule mod_env.c>"; $content .= "\n SetEnv front_controller_active true"; $content .= "\n <IfModule mod_dir.c>"; $content .= "\n DirectorySlash off"; $content .= "\n </IfModule>"; $content .= "\n </IfModule>"; $content .= "\n</IfModule>"; if ($content !== '') { //suppress errors in case we don't have permissions for it @file_put_contents($setupHelper->pathToHtaccess(), $content . "\n", FILE_APPEND); } } }
/** * Append the correct ErrorDocument path for Apache hosts * * @throws \OC\HintException If .htaccess does not include the current version */ public static function updateHtaccess() { $setupHelper = new \OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); if (!$setupHelper->isCurrentHtaccess()) { throw new \OC\HintException('.htaccess file has the wrong version. Please upload the correct version. Maybe you forgot to replace it after updating?'); } $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); $content = ''; if (strpos($htaccessContent, 'ErrorDocument 403') === false) { //custom 403 error page $content .= "\nErrorDocument 403 " . \OC::$WEBROOT . "/core/templates/403.php"; } if (strpos($htaccessContent, 'ErrorDocument 404') === false) { //custom 404 error page $content .= "\nErrorDocument 404 " . \OC::$WEBROOT . "/core/templates/404.php"; } // Add rewrite base $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; $content .= "\n<IfModule mod_rewrite.c>"; $content .= "\n RewriteBase " . $webRoot; $content .= "\n <IfModule mod_env.c>"; $content .= "\n SetEnv front_controller_active true"; $content .= "\n </IfModule>"; $content .= "\n</IfModule>"; if ($content !== '') { //suppress errors in case we don't have permissions for it @file_put_contents($setupHelper->pathToHtaccess(), $content . "\n", FILE_APPEND); } }