Plugin Directory

Changeset 1406697 for querywall


Ignore:
Timestamp:
04/28/2016 05:57:12 PM (10 years ago)
Author:
4ley
Message:

Settings page added

Location:
querywall/trunk
Files:
3 added
8 edited

Legend:

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

    r1402118 r1406697  
    1616
    1717    /**
    18      * Enqueue actions to build the admin pages.
     18     * Magic starts here.
    1919     *
    20      * Calls all the needed actions to build any given admin page.
     20     * All custom functionality will be hooked into the "init" action.
     21     *
     22     * @since 1.0.7
     23     * @return void
     24     */
     25    public function __construct() {
     26        add_action( 'init', array( $this, 'init' ), 30 );
     27    }
     28
     29    /**
     30     * Conditionally hook into WordPress.
     31     *
     32     * @since 1.0.7
     33     * @return void
     34     */
     35    public function init() {
     36
     37        add_action( 'admin_menu', array( $this, 'cb_admin_menu' ) );
     38        add_filter( 'plugin_row_meta', array( $this, 'cb_plugin_meta' ), 10, 2 );
     39        add_action( 'qwall_purge_logs', array( $this, 'purge_logs' ) );
     40    }
     41
     42    /**
     43     * Enqueue actions to build the admin menu.
     44     *
     45     * Calls all the needed actions to build the admin menu.
    2146     *
    2247     * @since 1.0.1
    2348     * @return void
    2449     */
    25     public static function build_admin() {
     50    public function cb_admin_menu() {
    2651
    27         global $plugin_file;
    28 
     52        // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
    2953        add_menu_page(
    3054            __( 'Firewall Request Monitor', 'querywall' ),
     
    3256            'manage_options',
    3357            'querywall',
    34             array( __CLASS__, 'render_page' ),
     58            array( $this, 'display_monitor_page' ),
    3559            'dashicons-shield'
     60        );
     61
     62        // add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
     63        add_submenu_page(
     64            'querywall',
     65            __( 'Firewall Request Monitor', 'querywall' ),
     66            __( 'Monitor', 'querywall' ),
     67            'manage_options',
     68            'querywall',
     69            array( $this, 'display_monitor_page' )
    3670        );
    3771    }
    3872
    3973    /**
    40      * Displays firewall logs table
     74     * Displays firewall request monitor page
    4175     *
    4276     * @since 1.0.1
    4377     * @return void
    4478     */
    45     public static function render_page() {
     79    public function display_monitor_page() {
    4680
    4781        require( dirname( __FILE__ ) . '/class-qwall-monitor.php' );
     
    124158
    125159    /**
    126      * Displays admin notice on success, error, warning, etc.
    127      *
    128      * @since 1.0.5
    129      * @return void
    130      */
    131     public static function render_admin_notice( $message, $css_classes = 'notice-success is-dismissible' ) {
    132         ?>
    133         <div class="notice <?php echo $css_classes; ?>">
    134             <p><?php echo $message; ?></p>
    135         </div>
    136         <?php
    137     }
    138 
    139     /**
    140160     * Purge blocked request logs.
    141161     *
     
    143163     * @return int|boolen
    144164     */
    145     public static function purge_logs( $older_than_hours = 0 ) {
     165    public function purge_logs( $older_than_hours = 0 ) {
    146166
    147167        global $wpdb;
     
    159179     * Add rating link to plugin page.
    160180     *
    161      * @since 1.0.1
     181     * @since 1.0.7
    162182     * @return array
    163183     */
    164     public static function rate( $links, $file ) {
     184    public function cb_plugin_meta( $links, $file ) {
     185
    165186        if ( strpos( $file, 'querywall.php' ) !== false ) {
    166             $wp_url = 'https://wordpress.org/support/view/plugin-reviews/querywall?rate=5#postform';
    167             $fb_url = 'https://www.facebook.com/querywall';
    168             $links[] = '<a target="_blank" href="' . $wp_url . '" title="Rate and review QueryWall on WordPress.org">Rate this plugin</a>';
    169             $links[] = '<a target="_blank" href="' . $fb_url . '" title="Visit QueryWall on Facebook" style="padding:0 5px;color:#fff;vertical-align:middle;border-radius:2px;background:#f5c140;">Visit on Facebook</a>';
     187            // style="padding:0 2px;color:#fff;vertical-align:middle;border-radius:2px;background:#00b9eb;"
     188            $links[] = '<a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/querywall?rate=5#postform" title="Rate and review QueryWall on WordPress.org">Rate on WordPress.org</a>';
     189            $links[] = '<a target="_blank" href="https://github.com/4ley/querywall" title="Contribute to QueryWall on GitHub">Contribute on GitHub</a>';
     190            $links[] = '<a target="_blank" href="https://www.facebook.com/querywall" title="Visit QueryWall on Facebook">Visit on Facebook</a>';
    170191        }
     192
    171193        return $links;
    172194    }
    173195}
    174196
     197QWall_DIC::set( 'admin', new QWall_Admin() );
     198
    175199endif;
  • querywall/trunk/core/class-qwall-core.php

    r1402118 r1406697  
    3030    public static function init( $plugin_file ) {
    3131
    32         $dirname = dirname( __FILE__ );
    33 
    3432        self::$settings = array(
    3533            'plugin_file' => $plugin_file,
     
    3735        );
    3836
    39         require_once( $dirname . '/class-qwall-firewall.php' );
    40         QWall_Firewall::init();
     37        $dirname = dirname( self::$settings['plugin_file'] );
     38
     39        require_once( $dirname . '/core/class-qwall-dic.php' );
     40        require_once( $dirname . '/core/class-qwall-settings.php' );
     41        require_once( $dirname . '/core/class-qwall-firewall.php' );
    4142
    4243        if ( is_admin() ) {
     
    5960        require_once( $dirname . '/core/class-qwall-notice.php' );
    6061        require_once( $dirname . '/core/class-qwall-admin.php' );
     62
    6163        register_activation_hook( self::$settings['plugin_file'], array( 'QWall_Setup', 'on_activate' ) );
    6264        register_deactivation_hook( self::$settings['plugin_file'], array( 'QWall_Setup', 'on_deactivate' ) );
    6365        register_uninstall_hook( self::$settings['plugin_file'], array( 'QWall_Setup', 'on_uninstall' ) );
    6466        add_action( 'activated_plugin', array( 'QWall_Setup', 'on_activated_plugin' ) );
    65         add_action( 'admin_menu', array( 'QWall_Admin', 'build_admin' ) );
    66         add_filter( 'plugin_row_meta', array( 'QWall_Admin', 'rate' ), 10, 2 );
    67         add_action( 'qwall_purge_logs', array( 'QWall_Admin', 'purge_logs' ) );
    6867
    6968        if ( isset( $_POST['qwall_purge_logs_now'] ) ) {
     
    7372            if ( wp_verify_nonce( $_POST['qwall_purge_logs_nonce'], 'qwall_purge_logs' ) ) {
    7473               
    75                 $affected_rows = QWall_Admin::purge_logs( ( int ) $_POST['qwall_purge_logs_older_than'] );
     74                $affected_rows = QWall_DIC::get( 'admin' )->purge_logs( ( int ) $_POST['qwall_purge_logs_older_than'] );
    7675               
    7776                if ( false === $affected_rows ) {
  • querywall/trunk/core/class-qwall-firewall.php

    r1278466 r1406697  
    3030
    3131    /**
    32      * Magic starts here
     32     * Magic starts here.
    3333     *
    34      * @since 1.0.1
     34     * All custom functionality will be hooked into the "plugins_loaded" action.
     35     *
     36     * @since 1.0.7
    3537     * @return void
    3638     */
    37     public static function init() {
     39    public function __construct() {
     40        add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
     41    }
     42
     43    /**
     44     * Conditionally hook into WordPress.
     45     *
     46     * @since 1.0.7
     47     * @return void
     48     */
     49    public function plugins_loaded() {
     50
     51        if ( is_user_logged_in() && QWall_DIC::get( 'settings' )->get( 'settings', 'disable_loggedin_users' ) ) {
     52            return null;
     53        }
     54
     55        self::analyze();
     56    }
     57
     58    /**
     59     * Analyze request
     60     *
     61     * @since 1.0.7
     62     * @return void
     63     */
     64    private static function analyze() {
    3865
    3966        // Analyze server variable
     
    85112
    86113    /**
    87      * You shall not pass
     114     * You shall not pass!
    88115     *
    89116     * @since 1.0.1
     
    92119    private static function close() {
    93120
    94         header('HTTP/1.1 403 Forbidden');
    95         header('Status: 403 Forbidden');
    96         header('Connection: Close');
     121        $qwall_settings   = QWall_DIC::get( 'settings' );
     122        $redirect_url     = $qwall_settings->get( 'settings', 'redirect_url' );
     123        $http_status_code = $qwall_settings->get( 'settings', 'http_status_code' );
     124        $server_response  = $qwall_settings->get( 'settings', 'server_response' );
     125
     126        if ( empty( $redirect_url ) ) {
     127
     128            if( ! isset( $_SERVER['SERVER_PROTOCOL'] ) || empty( $_SERVER['SERVER_PROTOCOL'] ) ) {
     129                $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
     130            }
     131
     132            $http_status_code_message = QWall_DIC::get( 'settings' )->get_http_status_codes( $http_status_code );
     133
     134            header( $_SERVER['SERVER_PROTOCOL'] . ' ' . $http_status_code_message, true, $http_status_code);
     135            header( 'Connection: Close' );
     136        } else {
     137            header('Location: ' . $redirect_url, true, $http_status_code);
     138        }
     139
     140        if( ! empty( $server_response ) ) {
     141            exit( $server_response );
     142        }
     143
    97144        exit;
    98145    }
     
    112159        global $wpdb;
    113160
     161        if( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
     162            $user_agent = $_SERVER['HTTP_USER_AGENT'];
     163        } else {
     164            $user_agent = '';
     165        }
     166
     167        if ( QWall_DIC::get( 'settings' )->get( 'settings', 'anonymize_ip' ) ) {
     168            $ipv4 = long2ip( ip2long( $_SERVER['REMOTE_ADDR'] ) & 0xFFFFFF00 );
     169        } else {
     170            $ipv4 = $_SERVER['REMOTE_ADDR'];
     171        }
     172
    114173        $wpdb->insert(
    115174            $wpdb->base_prefix . 'qwall_monitor',
     
    117176                'date_time'     => current_time( 'mysql' ),
    118177                'date_time_gmt' => current_time( 'mysql', 1 ),
    119                 'ipv4'          => sprintf( '%u', ip2long( $_SERVER['REMOTE_ADDR'] ) ),
    120                 'agent'         => $_SERVER['HTTP_USER_AGENT'],
     178                'ipv4'          => sprintf( '%u', ip2long( $ipv4 ) ),
     179                'agent'         => $user_agent,
    121180                'filter_group'  => $filter_group,
    122181                'filter_match'  => $filter_match,
     
    127186}
    128187
     188QWall_DIC::set( 'firewall', new QWall_Firewall() );
     189
    129190endif;
  • querywall/trunk/core/class-qwall-monitor.php

    r1400300 r1406697  
    8585                return '<span title="' . $item['date_time'] . '">' . human_time_diff( $item['time_stamp'], current_time( 'timestamp' ) ) . ' ago';
    8686            case 'ipv4':
    87                 return long2ip( $item[ $column_name ] );
     87
     88                $ipv4 = long2ip( $item[ $column_name ] );
     89               
     90                if ( substr( $ipv4, -2 ) == '.0' ) {
     91                    $ipv4 = substr_replace( $ipv4, '***', -1 );
     92                }
     93
     94                return $ipv4;
     95
    8896            case 'filter_input':
    8997                return preg_replace( '/' . preg_quote( $item['filter_match'], '/' ) . '/i', '<strong>\\0</strong>', $item['filter_input'] );
  • querywall/trunk/core/class-qwall-notice.php

    r1402118 r1406697  
    4242        }
    4343
    44         add_action( 'admin_notices', array( $this, 'render_admin_notice' ) );
     44        add_action( 'admin_notices', array( $this, 'display_admin_notice' ) );
    4545    }
    4646
     
    5151     * @return void
    5252     */
    53     public function render_admin_notice() {
     53    public function display_admin_notice() {
    5454        ?>
    5555        <div class="<?php echo implode( ' ', $this->css_classes ); ?>">
  • querywall/trunk/core/class-qwall-setup.php

    r1400300 r1406697  
    4141     */
    4242    public static function on_uninstall() {
     43
     44        self::remove_options();
    4345        self::remove_database_tables();
    4446        self::remove_scheduled_events();
     
    119121
    120122    /**
     123     * Remove plugin options
     124     *
     125     * @since 1.0.7
     126     * @return void
     127     */
     128    private static function remove_options() {
     129
     130        QWall_DIC::get( 'settings' )->delete( 'settings' );
     131    }
     132
     133    /**
    121134     * Make sure plugin loads first
    122135     *
  • querywall/trunk/querywall.php

    r1402118 r1406697  
    66 * Tags: firewall, security, protect, block, antivirus, defender, malicious, request, query, blacklist, url, eval, base64, hack, attack, brute force, infection, injection, malware, botnet, backdoor, web application firewall, xss, website security, wordpress security, secure, prevention, protection, trojan, virus, xss, waf, security audit, querywall, bbq, block bad queries, ninjafirewall, wordfence, bulletproof security, ithemes security, better wp security, sucuri, vaultpress, simple firewall
    77 * Usage: No configuration needed, just activate it.
    8  * Version: 1.0.6
     8 * Version: 1.0.7
    99 * Author: 4ley
    1010 * Author URI: https://github.com/4ley/querywall
  • querywall/trunk/readme.txt

    r1402118 r1406697  
    2525* Upload, activate, ready and done
    2626* Works in background
    27 * Identifies and forbids a wide range of malicious queries including [5G/6G Blacklist](https://perishablepress.com/6g-beta/)
     27* Identifies and forbids a wide range of malicious queries
    2828
    2929**Contribution / Social**
     
    4646
    4747== Changelog ==
     48
     49= 1.0.7 =
     50
     51* Options added: Disable for logged in users, Anonymize IP addresses, Server status code, Redirect URL, Server response
     52
     53= 1.0.6 =
     54
     55* Minor fixes
    4856
    4957= 1.0.5 =
Note: See TracChangeset for help on using the changeset viewer.