/** * check if the current server configuration is suitable for ownCloud * @return array arrays with error messages and hints */ public static function checkServer() { $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data"); $CONFIG_BACKUPDIRECTORY = OC_Config::getValue("backupdirectory", OC::$SERVERROOT . "/backup"); $CONFIG_INSTALLED = OC_Config::getValue("installed", false); $errors = array(); //check for database drivers if (!is_callable('sqlite_open') and !is_callable('mysql_connect')) { $errors[] = array('error' => 'No database drivers (sqlite or mysql) installed.<br/>', 'hint' => ''); //TODO: sane hint } $CONFIG_DBTYPE = OC_Config::getValue("dbtype", "sqlite"); $CONFIG_DBNAME = OC_Config::getValue("dbname", "owncloud"); $serverUser = OC_Util::checkWebserverUser(); //common hint for all file permissons error messages $permissionsHint = "Permissions can usually be fixed by setting the owner of the file or directory to the user the web server runs as ({$serverUser})"; //check for correct file permissions if (!stristr(PHP_OS, 'WIN')) { $permissionsModHint = "Please change the permissions to 0770 so that the directory cannot be listed by other users."; $prems = substr(decoct(@fileperms($CONFIG_DATADIRECTORY_ROOT)), -3); if (substr($prems, -1) != '0') { OC_Helper::chmodr($CONFIG_DATADIRECTORY_ROOT, 0770); clearstatcache(); $prems = substr(decoct(@fileperms($CONFIG_DATADIRECTORY_ROOT)), -3); if (substr($prems, 2, 1) != '0') { $errors[] = array('error' => 'Data directory (' . $CONFIG_DATADIRECTORY_ROOT . ') is readable for other users<br/>', 'hint' => $permissionsModHint); } } if (OC_Config::getValue("enablebackup", false)) { $prems = substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)), -3); if (substr($prems, -1) != '0') { OC_Helper::chmodr($CONFIG_BACKUPDIRECTORY, 0770); clearstatcache(); $prems = substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)), -3); if (substr($prems, 2, 1) != '0') { $errors[] = array('error' => 'Data directory (' . $CONFIG_BACKUPDIRECTORY . ') is readable for other users<br/>', 'hint' => $permissionsModHint); } } } } else { //TODO: permissions checks for windows hosts } if (is_dir($CONFIG_DATADIRECTORY_ROOT) and !is_writable($CONFIG_DATADIRECTORY_ROOT)) { $errors[] = array('error' => 'Data directory (' . $CONFIG_DATADIRECTORY_ROOT . ') not writable by ownCloud<br/>', 'hint' => $permissionsHint); } // check if all required php modules are present if (!class_exists('ZipArchive')) { $errors[] = array('error' => 'PHP module zip not installed.<br/>', 'hint' => 'Please ask your server administrator to install the module.'); } if (!function_exists('mb_detect_encoding')) { $errors[] = array('error' => 'PHP module mb multibyte not installed.<br/>', 'hint' => 'Please ask your server administrator to install the module.'); } if (!function_exists('ctype_digit')) { $errors[] = array('error' => 'PHP module ctype is not installed.<br/>', 'hint' => 'Please ask your server administrator to install the module.'); } return $errors; }
/** * @brief Writes the config file * @returns true/false * * Saves the config to the config file. * * Known flaws: Strings are not escaped properly */ public static function writeData() { // Create a php file ... $content = "<?php\n\$CONFIG = array(\n"; foreach (self::$cache as $key => $value) { if (is_bool($value)) { $value = $value ? 'true' : 'false'; $content .= "\"{$key}\" => {$value},\n"; } else { $value = str_replace("'", "\\'", $value); $content .= "\"{$key}\" => '{$value}',\n"; } } $content .= ");\n?>\n"; // Write the file $result = @file_put_contents(OC::$SERVERROOT . "/config/config.php", $content); if (!$result) { $tmpl = new OC_Template('', 'error', 'guest'); $tmpl->assign('errors', array(1 => array('error' => "Can't write into config directory 'config'", 'hint' => "You can usually fix this by setting the owner of 'config' to the user that the web server uses (" . OC_Util::checkWebserverUser() . ")"))); $tmpl->printPage(); exit; } return true; }