function fail2ban_syslog in Fail2ban Firewall Integration 6
Same name and namespace in other branches
- 7.2 fail2ban.module \fail2ban_syslog()
- 7 fail2ban.module \fail2ban_syslog()
The function that does the actual work, writing a log message.
Parameters
$address: String - An IP address or net/mask.
1 call to fail2ban_syslog()
- fail2ban_comment_admin_overview_submit in ./
fail2ban.module - Form submit handler to mass-report and unpublish or delete comments.
File
- ./
fail2ban.module, line 75
Code
function fail2ban_syslog($address) {
if (empty($address) || !is_string($address)) {
return;
}
// Check if the address is in the whitelist. If so, just return.
if (fail2ban_whitelist($address)) {
drupal_set_message(t('The address !address is !whitelisted and will not be submitted to the firewall', array(
'!address' => $address,
'!whitelisted' => l('whitelisted', 'admin/settings/fail2ban'),
)));
return;
}
// Get the log identifier
//
$identifier = variable_get('fail2ban_identifier', 'drupal');
// Turn on all the right log options.
//
$options = 0;
foreach (variable_get('fail2ban_options', array(
LOG_ODELAY,
)) as $option) {
$options = $options | $option;
}
// Get the facility.
//
$facility = variable_get('fail2ban_facility', LOG_USER);
// Get the priority.
//
$priority = 0;
foreach (variable_get('fail2ban_priority', array(
LOG_NOTICE,
)) as $option) {
$priority = $priority | $option;
}
// Get the log string.
//
$message = strtr(variable_get('fail2ban_logstring', 'Submitting address [!address] to the firewall'), array(
'!address' => $address,
));
// Open the log stream.
//
if (openlog($identifier, $options, $facility) == FALSE) {
watchdog('fail2ban', 'Unable to connect to the syslog daemon', NULL, WATCHDOG_ERROR);
drupal_set_message(t('Unable to connect to the syslog daemon'), 'error');
return;
}
if (syslog($priority, $message) == FALSE) {
watchdog('fail2ban', 'Cannot write message to the syslog daemon', NULL, WATCHDOG_ERROR);
drupal_set_message(t('Cannot write message to the syslog daemon'), 'error');
}
else {
drupal_set_message(t('The address !address has been submitted to the firewall', array(
'!address' => $address,
)));
}
if (closelog() == FALSE) {
watchdog('fail2ban', 'Cannot close connection to the syslog daemon', NULL, WATCHDOG_ERROR);
}
}