function fail2ban_syslog in Fail2ban Firewall Integration 7
Same name and namespace in other branches
- 6 fail2ban.module \fail2ban_syslog()
- 7.2 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 87
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;
}
// Load all settings.
$settings = variable_get('fail2ban', fail2ban_defaults());
// Turn on all the right log options.
//
$options = 0;
foreach ($settings['logopt']['options'] as $option) {
$options = $options | $option;
}
// Get the priority.
//
$priority = 0;
foreach ($settings['logopt']['priority'] as $option) {
$priority = $priority | $option;
}
// Get the log string and replace the placeholder.
//
$message = strtr($settings['logstring'], array(
'!address' => $address,
));
// Open the log stream.
//
if (openlog($settings['identifier'], $options, $settings['logopt']['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);
}
}