Skip to content

Commit

Permalink
Imporve performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrylinooo committed Sep 4, 2019
1 parent eadb34e commit 44b1b61
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 95 deletions.
84 changes: 42 additions & 42 deletions src/class-wpso-admin-ip-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public function get_fields() {
),

array(
'name' => 'ip_global_whitelist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
'name' => 'ip_global_whitelist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
),

array(
Expand All @@ -114,11 +114,11 @@ public function get_fields() {
),

array(
'name' => 'ip_global_blacklist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
'name' => 'ip_global_blacklist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
),
),

Expand All @@ -130,11 +130,11 @@ public function get_fields() {
),

array(
'name' => 'ip_login_whitelist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
'name' => 'ip_login_whitelist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
),

array(
Expand All @@ -150,8 +150,8 @@ public function get_fields() {
'name' => 'deny_all_passcode',
'label' => __( 'Passcode', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager-login-pass' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_captcha_google',
Expand All @@ -164,11 +164,11 @@ public function get_fields() {
),

array(
'name' => 'ip_login_blacklist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
'name' => 'ip_login_blacklist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
),
),

Expand All @@ -181,11 +181,11 @@ public function get_fields() {
),

array(
'name' => 'ip_signup_whitelist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
'name' => 'ip_signup_whitelist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
),

array(
Expand All @@ -204,11 +204,11 @@ public function get_fields() {
),

array(
'name' => 'ip_signup_blacklist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
'name' => 'ip_signup_blacklist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
),
),

Expand All @@ -220,11 +220,11 @@ public function get_fields() {
),

array(
'name' => 'ip_xmlrpc_whitelist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
'name' => 'ip_xmlrpc_whitelist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
),

array(
Expand All @@ -243,11 +243,11 @@ public function get_fields() {
),

array(
'name' => 'ip_xmlrpc_blacklist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
'name' => 'ip_xmlrpc_blacklist',
'label' => __( 'IP List', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/ip-manager' ),
'placeholder' => '',
'type' => 'textarea'
),
),
);
Expand Down
8 changes: 4 additions & 4 deletions src/class-wpso-admin-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class WPSO_Admin_Menu {
* Constructer.
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ) );
}

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ public function admin_enqueue_scripts( $hook_suffix ) {
* Register the plugin page.
*/
public function setting_admin_menu() {
global $admin_settings, $admin_ip_manager;
global $admin_settings, $admin_ip_manager;

add_menu_page(
__( 'WP Shieldon', 'wp-shieldon' ),
Expand All @@ -65,7 +65,7 @@ public function setting_admin_menu() {
'manage_options',
'shieldon-settings',
array( $admin_settings, 'setting_plugin_page' )
);
);

add_submenu_page(
'shieldon-settings',
Expand Down
69 changes: 34 additions & 35 deletions src/class-wpso-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public function get_sections() {
*/
public function get_fields() {


return array(

'shieldon_daemon' => array(
Expand Down Expand Up @@ -178,24 +177,24 @@ public function get_fields() {
),

array(
'name' => 'session_limit_count',
'name' => 'session_limit_count',
'label' => __( 'Online Limit', 'wp-shieldon' ),
'desc' => __( 'The maximum online user limit.', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '100',
'sanitize_callback' => 'sanitize_text_field',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_online_session_limit',
),

array(
'name' => 'session_limit_period',
'name' => 'session_limit_period',
'label' => __( 'Keep Alive Period', 'wp-shieldon' ),
'desc' => __( 'Unit: minute', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '5',
'sanitize_callback' => 'sanitize_text_field',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_online_session_limit',
),

Expand All @@ -219,44 +218,44 @@ public function get_fields() {
),

array(
'name' => 'time_unit_quota_s',
'name' => 'time_unit_quota_s',
'label' => __( 'Secondly Limit', 'wp-shieldon' ),
'desc' => __( 'Page views per vistor per second.', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '2',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_filter_frequency',
),

array(
'name' => 'time_unit_quota_m',
'name' => 'time_unit_quota_m',
'label' => __( 'Minutely Limit', 'wp-shieldon' ),
'desc' => __( 'Page views per vistor per minute.', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '10',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_filter_frequency',
),

array(
'name' => 'time_unit_quota_h',
'name' => 'time_unit_quota_h',
'label' => __( 'Hourly Limit', 'wp-shieldon' ),
'desc' => __( 'Page views per vistor per hour.', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '30',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_filter_frequency',
),

array(
'name' => 'time_unit_quota_d',
'name' => 'time_unit_quota_d',
'label' => __( 'Daily Limit', 'wp-shieldon' ),
'desc' => __( 'Page views per vistor per day.', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '60',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_filter_frequency',
Expand Down Expand Up @@ -520,33 +519,33 @@ public function get_fields() {
),

array(
'name' => 'google_recaptcha_key',
'name' => 'google_recaptcha_key',
'label' => __( 'Site Key', 'wp-shieldon' ),
'desc' => __( 'Enter Google reCaptcha site key for your webiste.', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_captcha_google',
),

array(
'name' => 'google_recaptcha_secret',
'name' => 'google_recaptcha_secret',
'label' => __( 'Secret Key', 'wp-shieldon' ),
'desc' => __( 'Enter Google reCahptcha secret key for your webiste.', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_captcha_google',
),

array(
'name' => 'google_recaptcha_lang',
'name' => 'google_recaptcha_lang',
'label' => __( 'Language Code', 'wp-shieldon' ),
'desc' => __( 'ISO 639 - ISO 3166 code. For example, <strong>zh-TW</strong> stands for Tranditional Chinese of <strong>Taiwan</strong>', 'wp-shieldon' ),
'placeholder' => '',
'type' => 'text',
'placeholder' => '',
'type' => 'text',
'default' => str_replace('_', '-', get_locale()),
'sanitize_callback' => 'sanitize_text_field',
'parent' => 'enable_captcha_google',
Expand Down Expand Up @@ -610,11 +609,11 @@ public function get_fields() {
),

array(
'name' => 'excluded_urls',
'label' => __( 'Excluded URLs', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/excluded-urls' ),
'placeholder' => '/example-post-type/',
'type' => 'textarea'
'name' => 'excluded_urls',
'label' => __( 'Excluded URLs', 'wp-shieldon' ),
'desc' => wpso_load_view( 'setting/excluded-urls' ),
'placeholder' => '/example-post-type/',
'type' => 'textarea'
),

array(
Expand Down
14 changes: 13 additions & 1 deletion src/class-wpso-shieldon.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,22 @@ public function init() {
return null;
}

$is_driver_reset = get_option( 'wpso_driver_reset' );

if ( 'no' === $is_driver_reset ) {
$this->shieldon->createDatabase( false );
}

// Start protecting your website!
$result = $this->shieldon->run();

if ($result !== $this->shieldon::RESPONSE_ALLOW) {

// The first time initializing has created the database automatically, so we don't need to check it every time.
if ( 'yes' === $is_driver_reset ) {
update_option( 'wpso_driver_reset', 'no' );
}

if ($this->shieldon->captchaResponse()) {

// Unban current session.
Expand Down Expand Up @@ -323,7 +335,7 @@ private function set_component() {
$component_rdns = new \Shieldon\Component\Rdns();

// Visitors with empty Rdns record will be blocked.
// IP resolved hostname (Rdns) and IP address must conform with each other.
// IP resolved hostname (Rdns) and IP address must conform with each other.
if ( 'yes' === wpso_get_option( 'rdns_strict_mode', 'shieldon_component' ) ) {
$component_rdns->setStrict( true );
}
Expand Down
4 changes: 2 additions & 2 deletions src/wpso-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function wpso_set_driver_hash() {
$wpso_driver_hash = wp_hash( date( 'ymdhis' ) . wp_rand( 1, 86400 ) );
$wpso_driver_hash = substr( $wpso_driver_hash, 0, 8);

update_option( 'wpso_driver_hash', $wpso_driver_hash, '', 'yes' );
update_option( 'wpso_driver_hash', $wpso_driver_hash );

return $wpso_driver_hash;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ function wpso_get_logs_dir() {
* @return void
*/
function wpso_set_channel_id() {
update_option( 'wpso_channel_id', get_current_blog_id(), '', 'yes' );
update_option( 'wpso_channel_id', get_current_blog_id() );
}

/**
Expand Down
Loading

0 comments on commit 44b1b61

Please sign in to comment.