Plugin Directory

Changeset 1400300


Ignore:
Timestamp:
04/20/2016 12:27:44 PM (10 years ago)
Author:
4ley
Message:

Clear logs now and periodically added

Location:
querywall/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • querywall/trunk/core/class-qwall-admin.php

    r1262571 r1400300  
    2323     * @return array
    2424     */
    25     public function build_admin() {
     25    public static function build_admin() {
    2626
    2727        global $plugin_file;
     
    4343     * @return array
    4444     */
    45     public function render_page() {
     45    public static function render_page() {
    4646
    4747        require( dirname( __FILE__ ) . '/class-qwall-monitor.php' );
     48
     49        if ( $event_purge_next_run = wp_next_scheduled( 'qwall_purge_logs', 24 ) ) {
     50            $event_purge_older_than = __( '24 hours', 'querywall' );
     51        } else if ( $event_purge_next_run = wp_next_scheduled( 'qwall_purge_logs', 48 ) ) {
     52            $event_purge_older_than = __( '48 hours', 'querywall' );
     53        } else if ( $event_purge_next_run = wp_next_scheduled( 'qwall_purge_logs', 72 ) ) {
     54            $event_purge_older_than = __( '72 hours', 'querywall' );
     55        } else if ( $event_purge_next_run = wp_next_scheduled( 'qwall_purge_logs', 0 ) ) {
     56            $event_purge_older_than = '"' . __( 'the big bank', 'querywall' ) . '"';
     57        } else {
     58            $event_purge_next_run   = false;
     59            $event_purge_older_than = false;
     60        }
    4861
    4962        $fw_monitor = new QWall_Monitor();
     
    5164        ?>
    5265            <style type="text/css">
    53                 .wp-list-table .column-date_time { width: 10%; }
    54                 .wp-list-table .column-date_time span { cursor: help; border-bottom: 1px dotted #aaa; }
    55                 .wp-list-table .column-ipv4 { width: 10%; }
    56                 .wp-list-table .column-filter_group { width: 10%; }
    57                 .wp-list-table .column-filter_input { width: 70%; }
     66                .wp-list-table .column-date_time { width: 10%; }
     67                .wp-list-table .column-date_time span { cursor: help; border-bottom: 1px dotted #aaa; }
     68                .wp-list-table .column-ipv4 { width: 10%; }
     69                .wp-list-table .column-filter_group { width: 10%; }
     70                .wp-list-table .column-filter_input { width: 70%; }
    5871                .wp-list-table .column-filter_input strong {
    5972                    padding: 0 2px;
     
    6275                    background-color: #ffff8c;
    6376                }
    64                 .qwall-subtitle { margin: 5px 0 0; color: #666; }
     77                #poststuff > p { margin: 5px 0 -20px; color: #666; }
     78                #poststuff form > p { margin-bottom: 0; }
     79                #poststuff form > p > span { cursor: help; border-bottom: 1px dotted #aaa; }
     80                #poststuff input,
     81                #poststuff select { vertical-align: baseline; }
    6582            </style>
    66             <div class="wrap">
     83            <div id="poststuff" class="wrap">
    6784                <h2><?php echo get_admin_page_title(); ?></h2>
    68                 <p class="qwall-subtitle">Blocked requests will be shown in the list below.</p>
     85                <div class="postbox">
     86                    <h3>Options</h3>
     87                    <div class="inside">
     88                        <form method="post" action="">
     89                            <?php wp_nonce_field( 'qwall_purge_logs', 'qwall_purge_logs_nonce' ); ?>
     90                            <?php _e( 'Clear logs older than', 'querywall' ); ?>
     91                            <select name="qwall_purge_logs_older_than">
     92                                <option value="24"><?php _e( '24 hours', 'querywall' ); ?></option>
     93                                <option value="48"><?php _e( '48 hours', 'querywall' ); ?></option>
     94                                <option value="72"><?php _e( '72 hours', 'querywall' ); ?></option>
     95                                <option value="0"><?php _e( 'the big bang', 'querywall' ); ?></option>
     96                            </select> |
     97                            <input class="button-primary" type="submit" name="qwall_purge_logs_now" value="<?php _e( 'Clear now', 'querywall' ); ?>">
     98                            <?php if ( $event_purge_next_run ) { ?>
     99                                <input class="button-primary" type="submit" name="qwall_purge_logs_unschedule" value="<?php _e( 'Unschedule', 'querywall' ); ?>">
     100                            <?php } else { ?>
     101                                <input class="button-primary" type="submit" name="qwall_purge_logs_daily" value="<?php _e( 'Clear daily', 'querywall' ); ?>">
     102                            <?php } ?>
     103                            <?php if ( $event_purge_next_run ) { ?>
     104                                <p><?php printf( __( 'Logs older than %s are scheduled to be purged in <span title="%s">%s</span>.', 'querywall' ), $event_purge_older_than, get_date_from_gmt( date( 'Y-m-d H:i:s', $event_purge_next_run ) ), human_time_diff( $event_purge_next_run, current_time( 'timestamp', 1 ) ) ); ?></p>
     105                            <?php } ?>
     106                        </form>
     107                    </div>
     108                </div>
     109                <p><?php _e( 'Blocked requests are shown in the list below.', 'querywall' ); ?></p>
    69110                <?php $fw_monitor->display(); ?>
    70111            </div>
    71112        <?php
     113    }
     114
     115    /**
     116     * Displays admin notice on success, error, warning, etc.
     117     *
     118     * @since 1.0.5
     119     * @return array
     120     */
     121    public static function render_admin_notice() {
     122        ?>
     123        <div class="notice notice-success is-dismissible">
     124            <p><?php _e( 'Success!', 'querywall' ); ?></p>
     125        </div>
     126        <?php
     127    }
     128
     129    /**
     130     * Purge blocked request logs.
     131     *
     132     * @since 1.0.5
     133     * @return array
     134     */
     135    public static function purge_logs( $older_than_hours = 0 ) {
     136
     137        global $wpdb;
     138
     139        if ( $older_than_hours == 0 ) {
     140            $wpdb->query( "DELETE FROM `" . $wpdb->base_prefix . "qwall_monitor`;" );
     141        } else if( in_array( $older_than_hours, array( 24, 48, 72 ) ) ) {
     142            $wpdb->query( "DELETE FROM `" . $wpdb->base_prefix . "qwall_monitor` WHERE `date_time_gmt` < '" . current_time( 'mysql', 1 ) . "' - INTERVAL " . esc_sql( ( int ) $older_than_hours ) . " HOUR;" );
     143        }
    72144    }
    73145
  • querywall/trunk/core/class-qwall-core.php

    r1275328 r1400300  
    4141
    4242        if ( is_admin() ) {
    43             require_once( $dirname . '/class-qwall-setup.php' );
    44             require_once( $dirname . '/class-qwall-admin.php' );
    45             register_activation_hook( $plugin_file, array( 'QWall_Setup', 'on_activate' ) );
    46             register_deactivation_hook( $plugin_file, array( 'QWall_Setup', 'on_deactivate' ) );
    47             register_uninstall_hook( $plugin_file, array( 'QWall_Setup', 'on_uninstall' ) );
    48             add_action( 'activated_plugin', array( 'QWall_Setup', 'on_activated_plugin' ) );
    49             add_action( 'admin_menu', array( 'QWall_Admin', 'build_admin' ) );
    50             add_filter( 'plugin_row_meta', array( 'QWall_Admin', 'rate' ), 10, 2 );
     43            self::admin_init();
     44        }
     45    }
     46
     47    /**
     48     * Admin magic starts here.
     49     *
     50     * @since 1.0.5
     51     * @return void
     52     */
     53    public static function admin_init() {
     54
     55        $dirname = dirname( self::$settings['plugin_file'] );
     56
     57        require_once( $dirname . '/core/class-qwall-util.php' );
     58        require_once( $dirname . '/core/class-qwall-setup.php' );
     59        require_once( $dirname . '/core/class-qwall-admin.php' );
     60        register_activation_hook( self::$settings['plugin_file'], array( 'QWall_Setup', 'on_activate' ) );
     61        register_deactivation_hook( self::$settings['plugin_file'], array( 'QWall_Setup', 'on_deactivate' ) );
     62        register_uninstall_hook( self::$settings['plugin_file'], array( 'QWall_Setup', 'on_uninstall' ) );
     63        add_action( 'activated_plugin', array( 'QWall_Setup', 'on_activated_plugin' ) );
     64        add_action( 'admin_menu', array( 'QWall_Admin', 'build_admin' ) );
     65        add_filter( 'plugin_row_meta', array( 'QWall_Admin', 'rate' ), 10, 2 );
     66        add_action( 'qwall_purge_logs', array( 'QWall_Admin', 'purge_logs' ) );
     67
     68        if ( isset( $_POST['qwall_purge_logs_now'] ) ) {
     69           
     70            require_once( ABSPATH . 'wp-includes/pluggable.php' );
     71           
     72            if ( wp_verify_nonce( $_POST['qwall_purge_logs_nonce'], 'qwall_purge_logs' ) ) {
     73               
     74                do_action( 'qwall_purge_logs', ( int ) $_POST['qwall_purge_logs_older_than'] );
     75                add_action( 'admin_notices', array( 'QWall_Admin', 'render_admin_notice' ) );
     76            }
     77        }
     78
     79        if ( isset( $_POST['qwall_purge_logs_daily'] ) || isset( $_POST['qwall_purge_logs_unschedule'] ) ) {
     80           
     81            require_once( ABSPATH . 'wp-includes/pluggable.php' );
     82           
     83            if ( wp_verify_nonce( $_POST['qwall_purge_logs_nonce'], 'qwall_purge_logs' ) ) {
     84
     85                QWall_Util::unschedule_event( 'qwall_purge_logs' );
     86
     87                if( isset( $_POST['qwall_purge_logs_daily'] ) ) {
     88                    wp_schedule_event( current_time( 'timestamp' ), 'daily', 'qwall_purge_logs', ( int ) $_POST['qwall_purge_logs_older_than'] );
     89                }
     90
     91                add_action( 'admin_notices', array( 'QWall_Admin', 'render_admin_notice' ) );
     92            }
    5193        }
    5294    }
  • querywall/trunk/core/class-qwall-monitor.php

    r1263584 r1400300  
    8383        switch( $column_name ) {
    8484            case 'date_time':
    85                 return '<span title="' .$item[ 'date_time' ]. '">' . human_time_diff( $item[ 'time_stamp' ], current_time( 'timestamp' ) ) . ' ago';
     85                return '<span title="' . $item['date_time'] . '">' . human_time_diff( $item['time_stamp'], current_time( 'timestamp' ) ) . ' ago';
    8686            case 'ipv4':
    8787                return long2ip( $item[ $column_name ] );
    8888            case 'filter_input':
    89                 return preg_replace( '/'. preg_quote( $item[ 'filter_match' ], '/' ) .'/i', '<strong>\\0</strong>', $item[ 'filter_input' ] );
    90  
     89                return preg_replace( '/' . preg_quote( $item['filter_match'], '/' ) . '/i', '<strong>\\0</strong>', $item['filter_input'] );
    9190            default:
    9291                return $item[ $column_name ];
     
    113112
    114113        $count = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->base_prefix . "qwall_monitor` " . $extra_sql . ";" );
    115         $items = $wpdb->get_results("SELECT date_time, UNIX_TIMESTAMP(date_time) AS time_stamp, ipv4, filter_group, filter_match, filter_input FROM `" . $wpdb->base_prefix . "qwall_monitor` " . $extra_sql . " LIMIT " . absint( $offset ) . ", " . absint( $limit ) . ";", ARRAY_A );
     114        $items = $wpdb->get_results( "SELECT date_time, UNIX_TIMESTAMP(date_time) AS time_stamp, ipv4, filter_group, filter_match, filter_input FROM `" . $wpdb->base_prefix . "qwall_monitor` " . $extra_sql . " LIMIT " . absint( $offset ) . ", " . absint( $limit ) . ";", ARRAY_A );
    116115
    117116        return $items;
  • querywall/trunk/core/class-qwall-setup.php

    r1275328 r1400300  
    4242    public static function on_uninstall() {
    4343        self::remove_database_tables();
     44        self::remove_scheduled_events();
    4445    }
    4546
     
    107108
    108109    /**
     110     * Unschedule all events
     111     *
     112     * @since 1.0.5
     113     * @return void
     114     */
     115    private static function remove_scheduled_events() {
     116
     117        QWall_Util::unschedule_event( 'qwall_purge_logs' );
     118    }
     119
     120    /**
    109121     * Make sure plugin loads first
    110122     *
  • querywall/trunk/querywall.php

    r1382896 r1400300  
    66 * Tags: Tags: firewall, security, protect, block, antivirus, defender, malicious, request, query, blacklist, url, eval, base64, hack, attack, brute force, infection, injection, malware, prevention, protection, trojan, virus, xss, waf
    77 * Usage: No configuration needed, just activate it.
    8  * Version: 1.0.4
     8 * Version: 1.0.5
    99 * Author: 4ley
    1010 * Author URI: https://github.com/4ley/querywall
  • querywall/trunk/readme.txt

    r1382896 r1400300  
    4747== Changelog ==
    4848
     49= 1.0.5 =
     50
     51* Clear logs now and periodically added
     52
     53= 1.0.4 =
     54
     55* WordPress compatibility test
     56
    4957= 1.0.3 =
    5058
Note: See TracChangeset for help on using the changeset viewer.