Exemple #1
0
/**
 * Check if IP address deserved to get listed in blacklist, if deserved then blacklist_addip()
 *
 * @param string $label
 *        single label, can be $username or $uid, its up to the implementator
 * @param string $ip
 *        single IP address
 * @return boolean TRUE on checked (not necessarily added)
 */
function firewall_hook_blacklist_checkip($label, $ip)
{
    global $plugin_config;
    $ret = FALSE;
    $hash = md5($label . $ip);
    $data = registry_search(0, 'feature', 'firewall');
    $login_attempt = $data['feature']['firewall'][$hash];
    if ($login_attempt > $plugin_config['firewall']['login_attempt_limit']) {
        blacklist_addip($label, $ip);
    }
    $items[$hash] = $login_attempt ? $login_attempt + 1 : 1;
    if (registry_update(0, 'feature', 'firewall', $items)) {
        $ret = TRUE;
    }
    return $ret;
}
Exemple #2
0
                    $conditions = array('id' => $item);
                    dba_remove(_DB_PREF_ . '_featureFirewall', $conditions);
                }
                break;
        }
        $search = themes_search_session();
        $nav = themes_nav_session();
        $_SESSION['error_string'] = _('IP addreses has been deleted');
        $ref = $search['url'] . '&search_keyword=' . $search['keyword'] . '&search_category=' . $search['category'] . '&page=' . $nav['page'] . '&nav=' . $nav['nav'];
        header("Location: " . _u($ref));
        exit;
        break;
    case "firewall_add":
        $content = _err_display() . "\n\t\t\t<h2>" . _('Manage firewall') . "</h2>\n\t\t\t<h3>" . _('Add blocked IP addresses') . " " . _hint(_('Multiple IP addresses must be comma seperated')) . "</h3>\n\t\t\t<form action='index.php?app=main&inc=feature_firewall&op=firewall_add_yes' method='post'>\n\t\t\t" . _CSRF_FORM_ . "\n\t\t\t<table class=playsms-table>\n\t\t\t<tr>\n\t\t\t\t<td class=label-sizer>" . _mandatory(_('Select username')) . "</td>\n\t\t\t\t<td>" . themes_select_users_single('add_username') . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class=label-sizer>" . _mandatory(_('IP addresses')) . "</td>\n\t\t\t\t<td><textarea name='add_ip_address' required></textarea></td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p><input type='submit' class='button' value='" . _('Save') . "'></p>\n\t\t\t</form>\n\t\t\t" . _back('index.php?app=main&inc=feature_firewall&op=firewall_list');
        _p($content);
        break;
    case "firewall_add_yes":
        $add_username = user_uid2username($_POST['add_username']);
        $add_ip_address = $_POST['add_ip_address'];
        if ($add_username && $add_ip_address) {
            foreach (explode(',', str_replace(' ', '', $add_ip_address)) as $ip) {
                blacklist_addip($add_username, $ip);
            }
            $_SESSION['error_string'] = _('IP addresses have been blocked');
        } else {
            $_SESSION['error_string'] = _('You must fill all fields');
        }
        header("Location: " . _u('index.php?app=main&inc=feature_firewall&op=firewall_add'));
        exit;
        break;
}