function autoban_insert_banned_table in Automatic IP ban (Autoban) 7
Insert IP to table for banned IP.
Parameters
string $ip: IP for insert.
int $ip_type: Single IP or range.
Return value
bool Insert success: TRUE or FALSE.
2 calls to autoban_insert_banned_table()
- autoban_ban in ./
autoban.module - Ban IP's for rules.
- autoban_ban_manual in ./
autoban.module - Ban IP manually.
File
- ./
autoban.module, line 308 - Main file for autoban module.
Code
function autoban_insert_banned_table($ip, $ip_type) {
$ip_type = _autoban_ip_type_verification($ip_type);
switch ($ip_type) {
case AUTOBAN_SINGLE_IP:
if (!autoban_is_banned($ip, $ip_type)) {
$iid = db_insert('blocked_ips')
->fields(array(
'ip' => $ip,
))
->execute();
if (_autoban_blocked_ips_expire_enable()) {
$default_duration = variable_get('blocked_ips_expire_default_time', '+2 years');
$default_expiry_date = new DateTime($default_duration);
$expiry_date = $default_expiry_date
->getTimestamp();
db_merge('blocked_ips_expire')
->key(array(
'iid' => $iid,
))
->fields(array(
'expiry_date' => $expiry_date,
))
->execute();
}
return TRUE;
}
break;
case AUTOBAN_RANGE_IP:
if (!autoban_is_banned($ip, $ip_type)) {
$ip = str_replace(' - ', '-', $ip);
db_insert('ip_ranges')
->fields(array(
'ip' => $ip,
'type' => 'blacklist',
))
->execute();
return TRUE;
}
}
return FALSE;
}