コード例 #1
0
ファイル: dashboard.php プロジェクト: sdellenb/wp-cerber
function cerber_show_lockouts($per_page = 50)
{
    global $wpdb;
    cerber_block_garbage_collector();
    $per_page = absint($per_page);
    $limit = (cerber_get_pn() - 1) * $per_page . ',' . $per_page;
    if ($rows = $wpdb->get_results('SELECT * FROM ' . CERBER_BLOCKS_TABLE . ' ORDER BY block_until DESC LIMIT ' . $limit)) {
        $list = array();
        $base_url = admin_url(cerber_get_opage('activity'));
        $assets_url = plugin_dir_url(CERBER_FILE) . 'assets/';
        foreach ($rows as $row) {
            $ip = '<a href="' . $base_url . '&filter_ip=' . $row->ip . '">' . $row->ip . '</a>';
            $ip_id = str_replace('.', '-', $row->ip);
            $ip_id = str_replace(':', '_', $ip_id);
            // IPv6
            if (($ip_info = unserialize(get_transient($ip_id))) && isset($ip_info['hostname'])) {
                $hostname = $ip_info['hostname'];
            } else {
                $hostname = '<img data-ip-id="' . $ip_id . '" class="crb-no-hn" src="' . $assets_url . 'ajax-loader-ip.gif" />' . "\n";
            }
            $list[] = '<td>' . $ip . '</td><td>' . $hostname . '</td><td>' . cerber_date($row->block_until) . '</td><td><a href="' . wp_nonce_url(add_query_arg(array('lockdelete' => $row->ip)), 'control', 'cerber_nonce') . '">' . __('Remove', 'cerber') . '</a></td>';
        }
        $titles = '<tr><th>' . __('IP', 'cerber') . '</th><th>' . __('Hostname', 'cerber') . '</th><th>' . __('Expires', 'cerber') . '</th><th></th></tr>';
        $table = '<table class="widefat crb-table"><thead>' . $titles . '</thead><tfoot>' . $titles . '</tfoot>' . implode('</tr><tr>', $list) . '</tr></table>';
        $total = $wpdb->get_var('SELECT count(ip) FROM ' . CERBER_BLOCKS_TABLE);
        echo '<h3>' . sprintf(__('Showing last %d records from %d', 'cerber'), count($rows), $total) . '</h3>';
        echo $table;
        cerber_page_navi($total, $per_page);
        $msg = '<p><b>' . __('Hint', 'cerber') . ':</b> ' . __('To view activity, click on the IP', 'cerber') . '</p>';
    } else {
        $msg = '<p>' . sprintf(__('No lockouts at the moment. The sky is clear.', 'cerber')) . '</p>';
    }
    echo '<div class="cerber-margin">' . $msg . '</div>';
}
コード例 #2
0
ファイル: wp-cerber.php プロジェクト: sdellenb/wp-cerber
function cerber_get_block($ip = '')
{
    global $wpdb;
    if (!$ip) {
        $ip = cerber_get_ip();
    }
    cerber_block_garbage_collector();
    if ($ret = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . CERBER_BLOCKS_TABLE . ' WHERE ip = %s', $ip))) {
        return $ret;
    } else {
        $subnet = cerber_get_subnet($ip);
        // try subnet
        if ($ret = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . CERBER_BLOCKS_TABLE . ' WHERE ip = %s', $subnet))) {
            return $ret;
        }
    }
    return false;
}