function filelog_requirements in File Log 6
Same name and namespace in other branches
- 6.2 filelog.install \filelog_requirements()
- 7 filelog.install \filelog_requirements()
Implementation of hook_requirements().
File
- ./
filelog.install, line 6
Code
function filelog_requirements($phase) {
drupal_load('module', 'filelog');
$f = _filelog_get_conf();
$mode = isset($f['dir']) ? FILE_MODIFY_PERMISSIONS : ($phase == 'install' ? FILE_CREATE_DIRECTORY : FILE_MODIFY_PERMISSIONS);
$dir = filelog_directory(FALSE, TRUE);
$exists = file_check_directory($dir, $mode);
$requirements = array();
$t = get_t();
$requirements['filelog_directory'] = array(
'title' => $t('Log directory'),
'value' => $dir,
'severity' => $exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
'description' => $exists ? $t('Directory exists and writable.') : $t('Directory does not exist or writable.'),
);
if ($exists) {
$htaccess = "{$dir}/.htaccess";
$htaccess_lines = "Order Allow,Deny\nDeny from all\n";
if ($phase == 'install') {
if (($fp = fopen($htaccess, 'wb')) && fwrite($fp, $htaccess_lines)) {
fclose($fp);
chmod($dir . '/.htaccess', 0664);
$htaccess = FALSE;
}
}
else {
$htaccess = !file_exists($htaccess);
}
$requirements['filelog_protection'] = array(
'title' => $t('Log directory protection'),
'value' => $htaccess ? $t('NOT PROTECTED') : $t('Protected'),
'severity' => $htaccess ? REQUIREMENT_WARNING : REQUIREMENT_OK,
);
if ($htaccess) {
$variables = array(
'%directory' => $dir,
'!htaccess' => '<br />' . nl2br(check_plain($htaccess_lines)),
);
$requirements['filelog_protection']['description'] = $t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables);
}
}
return $requirements;
}