コード例 #1
0
ファイル: util.php プロジェクト: pombredanne/ArcherSys
	/**
	 * 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);
		$availableDatabases = $setup->getSupportedDatabases();
		if (empty($availableDatabases)) {
			$errors[] = array(
				'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
				'hint' => '' //TODO: sane hint
			);
			$webServerRestart = true;
		}

		//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>'));

		// 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)) {
				$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
		// If the dependency is not found the missing module name is shown to the EndUser
		$dependencies = array(
			'classes' => array(
				'ZipArchive' => 'zip',
				'DOMDocument' => 'dom',
				'XMLWriter' => 'XMLWriter'
			),
			'functions' => array(
				'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'
			),
			'defined' => array(
				'PDO::ATTR_DRIVER_NAME' => 'PDO'
			)
		);
		$missingDependencies = array();
		$moduleHint = $l->t('Please ask your server administrator to install the module.');

		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($missingDependencies as $missingDependency) {
			$errors[] = array(
				'error' => $l->t('PHP module %s not installed.', array($missingDependency)),
				'hint' => $moduleHint
			);
			$webServerRestart = true;
		}

		if (version_compare(phpversion(), '5.4.0', '<')) {
			$errors[] = array(
				'error' => $l->t('PHP %s or higher is required.', '5.4.0'),
				'hint' => $l->t('Please ask your server administrator to update PHP to the latest version.'
					. ' Your PHP version is no longer supported by ownCloud and the PHP community.')
			);
			$webServerRestart = true;
		}

		/**
		 * PHP 5.6 ships with a PHP setting which throws notices by default for a
		 * lot of endpoints. Thus we need to ensure that the value is set to -1
		 *
		 * FIXME: Due to https://github.com/owncloud/core/pull/13593#issuecomment-71178078
		 * this check is disabled for HHVM at the moment. This should get re-evaluated
		 * at a later point.
		 *
		 * @link https://github.com/owncloud/core/issues/13592
		 */
		if(version_compare(phpversion(), '5.6.0', '>=') &&
			!self::runningOnHhvm() &&
			\OC::$server->getIniWrapper()->getNumeric('always_populate_raw_post_data') !== -1) {
			$errors[] = array(
				'error' => $l->t('PHP is configured to populate raw post data. Since PHP 5.6 this will lead to PHP throwing notices for perfectly valid code.'),
				'hint' => $l->t('To fix this issue set <code>always_populate_raw_post_data</code> to <code>-1</code> in your php.ini')
			);
		}

		if (!self::isAnnotationsWorking()) {
			$errors[] = array(
				'error' => $l->t('PHP is apparently setup 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 ($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;
	}
コード例 #2
0
 /**
  * Gathers system information like database type and does
  * a few system checks.
  *
  * @return array of system info, including an "errors" value
  * in case of errors/warnings
  */
 public function getSystemInfo()
 {
     $setup = new \OC_Setup($this->config);
     $databases = $setup->getSupportedDatabases();
     $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
     $vulnerableToNullByte = false;
     if (@file_exists(__FILE__ . "Nullbyte")) {
         // Check if the used PHP version is vulnerable to the NULL Byte attack (CVE-2006-7243)
         $vulnerableToNullByte = true;
     }
     $errors = array();
     // Create data directory to test whether the .htaccess works
     // Notice that this is not necessarily the same data directory as the one
     // that will effectively be used.
     @mkdir($dataDir);
     $htAccessWorking = true;
     if (is_dir($dataDir) && is_writable($dataDir)) {
         // Protect data directory here, so we can test if the protection is working
         \OC_Setup::protectDataDirectory();
         try {
             $htAccessWorking = \OC_Util::isHtaccessWorking();
         } catch (\OC\HintException $e) {
             $errors[] = array('error' => $e->getMessage(), 'hint' => $e->getHint());
             $htAccessWorking = false;
         }
     }
     if (\OC_Util::runningOnMac()) {
         $errors[] = array('error' => $this->l10n->t('Mac OS X is not supported and %s will not work properly on this platform. ' . 'Use it at your own risk! ', $this->defaults->getName()), 'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.'));
     }
     if ($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
         $errors[] = array('error' => $this->l10n->t('It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' . 'This will lead to problems with files over 4GB and is highly discouraged.', $this->defaults->getName()), 'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.'));
     }
     if (!function_exists('curl_init') && PHP_INT_SIZE === 4) {
         $errors[] = array('error' => $this->l10n->t('It seems that this %s instance is running on a 32-bit PHP environment and cURL is not installed. ' . 'This will lead to problems with files over 4GB and is highly discouraged.', $this->defaults->getName()), 'hint' => $this->l10n->t('Please install the cURL extension and restart your webserver.'));
     }
     return array('hasSQLite' => isset($databases['sqlite']), 'hasMySQL' => isset($databases['mysql']), 'hasPostgreSQL' => isset($databases['pgsql']), 'hasOracle' => isset($databases['oci']), 'hasMSSQL' => isset($databases['mssql']), 'databases' => $databases, 'directory' => $dataDir, 'htaccessWorking' => $htAccessWorking, 'vulnerableToNullByte' => $vulnerableToNullByte, 'errors' => $errors);
 }
コード例 #3
0
ファイル: util.php プロジェクト: droiter/openwrt-on-android
 /**
  * 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($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::$session->exists('checkServer_succeeded') && \OC::$session->get('checkServer_succeeded')) {
         return $errors;
     }
     $webServerRestart = false;
     $setup = new OC_Setup($config);
     $availableDatabases = $setup->getSupportedDatabases();
     if (empty($availableDatabases)) {
         $errors[] = array('error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), 'hint' => '');
         $webServerRestart = true;
     }
     // 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 theses locales on your system and restart your webserver.'));
     }
     $moduleHint = $l->t('Please ask your server administrator to install the module.');
     // check if all required php modules are present
     if (!class_exists('ZipArchive')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('zip')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!class_exists('XMLWriter')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('XMLWriter')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!class_exists('DOMDocument')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('dom')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!function_exists('xml_parser_create')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('libxml')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!function_exists('mb_detect_encoding')) {
         $errors[] = array('error' => 'PHP module mb multibyte not installed.', 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!function_exists('ctype_digit')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('ctype')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!function_exists('json_encode')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('JSON')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!extension_loaded('gd') || !function_exists('gd_info')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('GD')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!function_exists('gzencode')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('zlib')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!function_exists('iconv')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('iconv')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (!function_exists('simplexml_load_string')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('SimpleXML')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (version_compare(phpversion(), '5.3.3', '<')) {
         $errors[] = array('error' => $l->t('PHP %s or higher is required.', '5.3.3'), 'hint' => $l->t('Please ask your server administrator to update PHP to the latest version.' . ' Your PHP version is no longer supported by ownCloud and the PHP community.'));
         $webServerRestart = true;
     }
     if (!defined('PDO::ATTR_DRIVER_NAME')) {
         $errors[] = array('error' => $l->t('PHP module %s not installed.', array('PDO')), 'hint' => $moduleHint);
         $webServerRestart = true;
     }
     if (strtolower(@ini_get('safe_mode')) == 'on' || strtolower(@ini_get('safe_mode')) == 'yes' || strtolower(@ini_get('safe_mode')) == 'true' || ini_get("safe_mode") == 1) {
         $errors[] = array('error' => $l->t('PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.'), 'hint' => $l->t('PHP Safe Mode is a deprecated and mostly useless setting that should be disabled. ' . 'Please ask your server administrator to disable it in php.ini or in your webserver config.'));
         $webServerRestart = true;
     }
     if (get_magic_quotes_gpc() == 1) {
         $errors[] = array('error' => $l->t('Magic Quotes is enabled. ownCloud requires that it is disabled to work properly.'), 'hint' => $l->t('Magic Quotes is a deprecated and mostly useless setting that should be disabled. ' . 'Please ask your server administrator to disable it in php.ini or in your webserver config.'));
         $webServerRestart = true;
     }
     if (!self::isAnnotationsWorking()) {
         $errors[] = array('error' => 'PHP is apparently setup to strip inline doc blocks. This will make several core apps inaccessible.', 'hint' => 'This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.');
     }
     if ($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::$session->set('checkServer_succeeded', count($errors) == 0);
     return $errors;
 }
コード例 #4
0
ファイル: setup.php プロジェクト: Romua1d/core
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Supported databases are not properly configured.
  */
 public function testGetSupportedDatabaseException()
 {
     $this->config->expects($this->once())->method('getSystemValue')->will($this->returnValue('NotAnArray'));
     $this->setupClass->getSupportedDatabases();
 }
コード例 #5
0
ファイル: controller.php プロジェクト: WYSAC/oregon-owncloud
 /**
  * Gathers system information like database type and does
  * a few system checks.
  *
  * @return array of system info, including an "errors" value
  * in case of errors/warnings
  */
 public function getSystemInfo()
 {
     $setup = new \OC_Setup($this->config);
     $databases = $setup->getSupportedDatabases();
     $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
     $vulnerableToNullByte = false;
     if (@file_exists(__FILE__ . "Nullbyte")) {
         // Check if the used PHP version is vulnerable to the NULL Byte attack (CVE-2006-7243)
         $vulnerableToNullByte = true;
     }
     $errors = array();
     // Create data directory to test whether the .htaccess works
     // Notice that this is not necessarily the same data directory as the one
     // that will effectively be used.
     @mkdir($datadir);
     if (is_dir($datadir) && is_writable($datadir)) {
         // Protect data directory here, so we can test if the protection is working
         \OC_Setup::protectDataDirectory();
         try {
             $htaccessWorking = \OC_Util::isHtaccessWorking();
         } catch (\OC\HintException $e) {
             $errors[] = array('error' => $e->getMessage(), 'hint' => $e->getHint());
             $htaccessWorking = false;
         }
     }
     if (\OC_Util::runningOnMac()) {
         $l10n = \OC_L10N::get('core');
         $themeName = \OC_Util::getTheme();
         $theme = new \OC_Defaults();
         $errors[] = array('error' => $l10n->t('Mac OS X is not supported and %s will not work properly on this platform. ' . 'Use it at your own risk! ', $theme->getName()), 'hint' => $l10n->t('For the best results, please consider using a GNU/Linux server instead.'));
     }
     return array('hasSQLite' => isset($databases['sqlite']), 'hasMySQL' => isset($databases['mysql']), 'hasPostgreSQL' => isset($databases['pgsql']), 'hasOracle' => isset($databases['oci']), 'hasMSSQL' => isset($databases['mssql']), 'databases' => $databases, 'directory' => $datadir, 'secureRNG' => \OC_Util::secureRNGAvailable(), 'htaccessWorking' => $htaccessWorking, 'vulnerableToNullByte' => $vulnerableToNullByte, 'errors' => $errors);
 }