SiteGuard WP Plugin - Version 1.7.2

Version Description

  • Reviewed and modified source code related to security
Download this release

Release Info

Developer jp-secure
Plugin Icon 128x128 SiteGuard WP Plugin
Version 1.7.2
Comparing to
See all releases

Code changes from version 1.7.1 to 1.7.2

Files changed (36) hide show
  1. admin/siteguard-login-history-table.php +76 -72
  2. admin/siteguard-menu-admin-filter.php +25 -25
  3. admin/siteguard-menu-author-query.php +45 -45
  4. admin/siteguard-menu-captcha.php +65 -65
  5. admin/siteguard-menu-dashboard.php +41 -41
  6. admin/siteguard-menu-fail-once.php +22 -22
  7. admin/siteguard-menu-init.php +146 -68
  8. admin/siteguard-menu-login-alert.php +43 -40
  9. admin/siteguard-menu-login-history.php +29 -29
  10. admin/siteguard-menu-login-lock.php +47 -47
  11. admin/siteguard-menu-protect-xmlrpc.php +45 -45
  12. admin/siteguard-menu-rename-login.php +46 -46
  13. admin/siteguard-menu-same-error.php +20 -20
  14. admin/siteguard-menu-updates-notify.php +50 -50
  15. admin/siteguard-menu-waf-tuning-support.php +91 -82
  16. admin/siteguard-waf-exclude-rule-table.php +47 -42
  17. classes/siteguard-admin-filter.php +20 -20
  18. classes/siteguard-base.php +58 -62
  19. classes/siteguard-captcha.php +67 -67
  20. classes/siteguard-config.php +1 -1
  21. classes/siteguard-disable-author-query.php +16 -11
  22. classes/siteguard-disable-pingback.php +4 -4
  23. classes/siteguard-disable-xmlrpc.php +12 -12
  24. classes/siteguard-htaccess.php +34 -34
  25. classes/siteguard-login-alert.php +16 -16
  26. classes/siteguard-login-history.php +27 -27
  27. classes/siteguard-login-lock.php +32 -32
  28. classes/siteguard-rename-login.php +61 -62
  29. classes/siteguard-updates-notify.php +53 -45
  30. classes/siteguard-waf-exclude-rule.php +39 -39
  31. css/siteguard-menu.css +0 -1
  32. readme.txt +4 -2
  33. really-simple-captcha/siteguard-really-simple-captcha.php +77 -74
  34. siteguard.php +100 -99
  35. test/siteguard-dummy.php +1 -1
  36. uninstall.php +5 -5
admin/siteguard-login-history-table.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  if ( ! class_exists( 'WP_List_Table' ) ) {
3
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
  }
5
 
6
  class SiteGuard_LoginHistory_Table extends WP_List_Table {
@@ -11,16 +11,18 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
11
  protected $filter_login_name_not;
12
  protected $filter_ip_address_not;
13
 
14
- function __construct( ) {
15
  global $status, $page;
16
 
17
- //Set parent defaults
18
- parent::__construct( array(
19
- 'singular' => 'event', //singular name of the listed records
20
- 'plural' => 'events', //plural name of the listed records
21
- 'ajax' => false, //does this table support ajax?
22
- ) );
23
- $referer = wp_get_referer( );
 
 
24
  if ( false === strpos( $referer, 'siteguard_login_history' ) ) {
25
  unset( $_COOKIE['siteguard_log_filter_operation'] );
26
  unset( $_COOKIE['siteguard_log_filter_type'] );
@@ -37,12 +39,12 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
37
  $this->filter_login_name_not = false;
38
  $this->filter_ip_address_not = false;
39
  } else {
40
- $this->filter_operation = $this->get_filter_operation( );
41
- $this->filter_type = $this->get_filter_type( );
42
- $this->filter_login_name = $this->get_filter_login_name( );
43
- $this->filter_ip_address = $this->get_filter_ip_address( );
44
- $this->filter_login_name_not = $this->get_filter_login_name_not( );
45
- $this->filter_ip_address_not = $this->get_filter_ip_address_not( );
46
  }
47
  if ( '' === $this->filter_login_name ) {
48
  $this->filter_login_name_not = false;
@@ -63,15 +65,15 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
63
  case 'ip_address':
64
  return $item[ $column_name ];
65
  default:
66
- return print_r( $item, true ); //Show the whole array for troubleshooting purposes
67
  }
68
  }
69
 
70
- function get_columns( ) {
71
  $columns = array(
72
- #'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
73
- 'time' => esc_html__( 'Date Time', 'siteguard' ),
74
- 'operation' => esc_html__( 'Operation', 'siteguard' ),
75
  'login_name' => esc_html__( 'Login Name', 'siteguard' ),
76
  'ip_address' => esc_html__( 'IP Address', 'siteguard' ),
77
  'type' => esc_html__( 'Type', 'siteguard' ),
@@ -79,10 +81,10 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
79
  return $columns;
80
  }
81
 
82
- function get_sortable_columns( ) {
83
  $sortable_columns = array(
84
- 'time' => array( 'id', true ), //true means it's already sorted
85
- 'operation' => array( 'operation', false ), //true means it's already sorted
86
  'login_name' => array( 'login_name', false ),
87
  'ip_address' => array( 'ip_address', false ),
88
  'type' => array( 'type', false ),
@@ -90,41 +92,41 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
90
  return $sortable_columns;
91
  }
92
 
93
- function get_bulk_actions( ) {
94
- #$actions = array(
95
- # 'delete' => __( 'Delete' ),
96
- #);
97
  $actions = array();
98
  return $actions;
99
  }
100
 
101
 
102
- function process_bulk_action( ) {
103
  return;
104
  }
105
 
106
  function usort_reorder( $a, $b ) {
107
  $orderby_values = array( 'id', 'operation', 'time', 'login_name', 'ip_address', 'type' );
108
- $order_values = array( 'asc', 'desc' );
109
- $orderby = ( ! empty( $_REQUEST['orderby'] ) ) ? ( in_array( $_REQUEST['orderby'], $orderby_values ) ? $_REQUEST['orderby'] : 'id' ) : 'id'; //If no sort, default to id
110
- $order = ( ! empty( $_REQUEST['order'] ) ) ? ( in_array( $_REQUEST['order'], $order_values ) ? $_REQUEST['order'] : 'desc' ) : 'desc'; //If no order, default to desc
111
  if ( 'id' == $orderby ) {
112
  $result = ( $a > $b ? 1 : ( $a < $b ? -1 : 0 ) );
113
  } else {
114
- $result = strcmp( $a[ $orderby ], $b[ $orderby ] ); //Determine sort order
115
  }
116
- return ( 'asc' == $order ) ? $result : -$result; //Send final sort direction to usort
117
  }
118
  function get_filter_param_normal( $name, $default ) {
119
  $result = $default;
120
  if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
121
  if ( isset( $_POST[ $name ] ) ) {
122
- $result = $_POST[ $name ];
123
  }
124
  } else {
125
  $cookie_name = 'siteguard_log_' . $name;
126
  if ( isset( $_COOKIE[ $cookie_name ] ) ) {
127
- $result = $_COOKIE[ $cookie_name ];
128
  }
129
  }
130
  return $result;
@@ -149,7 +151,7 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
149
  }
150
  return $result;
151
  }
152
- function get_filter_operation( ) {
153
  global $siteguard_login_history;
154
  $result = $this->get_filter_param_normal( 'filter_operation', SITEGUARD_LOGIN_NOSELECT );
155
  if ( ! $siteguard_login_history->check_operation( $result ) ) {
@@ -157,7 +159,7 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
157
  }
158
  return $result;
159
  }
160
- function get_filter_type( ) {
161
  global $siteguard_login_history;
162
  $result = $this->get_filter_param_normal( 'filter_type', SITEGUARD_LOGIN_TYPE_NOSELECT );
163
  if ( ! $siteguard_login_history->check_type( $result ) ) {
@@ -165,49 +167,49 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
165
  }
166
  return $result;
167
  }
168
- function get_filter_login_name( ) {
169
  return $this->get_filter_param_normal( 'filter_login_name', '' );
170
  }
171
- function get_filter_ip_address( ) {
172
  return $this->get_filter_param_normal( 'filter_ip_address', '' );
173
  }
174
- function get_filter_login_name_not( ) {
175
  return $this->get_filter_param_checkbox( 'filter_login_name_not', false );
176
  }
177
- function get_filter_ip_address_not( ) {
178
  return $this->get_filter_param_checkbox( 'filter_ip_address_not', false );
179
  }
180
- function operation_dropdown( ) {
181
  ?>
182
  <select name="filter_operation" id="filter-by-operation">
183
- <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_NOSELECT ); ?> value="<?php echo SITEGUARD_LOGIN_NOSELECT ?>"><?php echo esc_html__( 'All Operations', 'siteguard' ); ?></option>
184
- <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_SUCCESS ); ?> value="<?php echo SITEGUARD_LOGIN_SUCCESS ?>"><?php echo esc_html__( 'Success', 'siteguard' ); ?></option>
185
- <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_FAILED ); ?> value="<?php echo SITEGUARD_LOGIN_FAILED ?>"><?php echo esc_html__( 'Failed', 'siteguard' ); ?></option>
186
- <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_FAIL_ONCE ); ?> value="<?php echo SITEGUARD_LOGIN_FAIL_ONCE ?>"><?php echo esc_html__( 'Fail once', 'siteguard' ); ?></option>
187
- <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_LOCKED ); ?> value="<?php echo SITEGUARD_LOGIN_LOCKED ?>"><?php echo esc_html__( 'Locked', 'siteguard' ); ?></option>
188
  </select>
189
  <?php
190
  }
191
- function login_name_input( ) {
192
  ?>
193
  <input type="text" name="filter_login_name" id="filter-login-name" size="15" value="<?php echo esc_attr( $this->filter_login_name ); ?>">
194
  <input type="checkbox" name="filter_login_name_not" id="filter-login-name-not" <?php checked( $this->filter_login_name_not, true ); ?> >
195
- <label for="filter-login-name-not" ><?php echo esc_html__( 'Other', 'siteguard'); ?></label>
196
  <?php
197
  }
198
- function ip_address_input( ) {
199
  ?>
200
  <input type="text" name="filter_ip_address" id="filter-ip-address" size="15" value="<?php echo esc_attr( $this->filter_ip_address ); ?>">
201
  <input type="checkbox" name="filter_ip_address_not" id="filter-ip-address-not" <?php checked( $this->filter_ip_address_not, true ); ?> >
202
- <label for="filter-ip-address-not" ><?php echo esc_html__( 'Other', 'siteguard'); ?></label>
203
  <?php
204
  }
205
- function type_dropdown( ) {
206
  ?>
207
  <select name="filter_type" id="filter-type">
208
- <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_NOSELECT ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_NOSELECT ?>"><?php echo esc_html__( 'All Types', 'siteguard' ); ?></option>
209
- <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_NORMAL ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_NORMAL ?>"><?php echo esc_html__( 'Login Page', 'siteguard' ); ?></option>
210
- <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_XMLRPC ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_XMLRPC ?>"><?php echo esc_html__( 'XMLRPC', 'siteguard' ); ?></option>
211
  </select>
212
  <?php
213
  }
@@ -219,17 +221,17 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
219
  <div class="alignleft actions bulkactions">
220
  <table>
221
  <tr>
222
- <td><label for="filter-operation"><?php echo esc_html__( 'Operation', 'siteguard') . ':'; ?></label></td>
223
- <td><?php $this->operation_dropdown( ); ?></td>
224
  <td width="30px"></td>
225
  <td><label for="filter-login-name" ><?php echo esc_html__( 'Login Name', 'siteguard' ) . ':'; ?></label></td>
226
- <td><?php $this->login_name_input( ); ?></td>
227
  </tr><tr>
228
- <td><label for="filter-type" ><?php echo esc_html__( 'Type', 'siteguard') . ':'; ?></label></td>
229
- <td><?php $this->type_dropdown( ); ?></td>
230
  <td></td>
231
  <td><label for="filter-ip-address" ><?php echo esc_html__( 'IP Address', 'siteguard' ) . ':'; ?></label></td>
232
- <td><?php $this->ip_address_input( ); ?></td>
233
  </tr>
234
  </table>
235
  <input type="submit" name="filter_action" id="post-query-submit" class="button" value="<?php echo esc_attr__( 'Filter' ); ?>">
@@ -238,23 +240,23 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
238
  <?php
239
  }
240
 
241
- function prepare_items( ) {
242
  global $siteguard_login_history;
243
 
244
  $per_page = 10;
245
 
246
- $columns = $this->get_columns( );
247
  $hidden = array();
248
- $sortable = $this->get_sortable_columns( );
249
 
250
  $this->_column_headers = array( $columns, $hidden, $sortable );
251
 
252
- $this->process_bulk_action( );
253
 
254
  $data = $siteguard_login_history->get_history( $this->filter_operation, $this->filter_login_name, $this->filter_ip_address, $this->filter_type, $this->filter_login_name_not, $this->filter_ip_address_not );
255
 
256
- $total_items = count( $data );
257
- $current_page = $this->get_pagenum( );
258
 
259
  if ( $total_items <= ( ( $current_page - 1 ) * $per_page ) ) {
260
  $current_page = 1;
@@ -266,10 +268,12 @@ class SiteGuard_LoginHistory_Table extends WP_List_Table {
266
 
267
  $this->items = $data;
268
 
269
- $this->set_pagination_args( array(
270
- 'total_items' => $total_items, //WE have to calculate the total number of items
271
- 'per_page' => $per_page, //WE have to determine how many items to show on a page
272
- 'total_pages' => ceil( $total_items / $per_page ), //WE have to calculate the total number of pages
273
- ) );
 
 
274
  }
275
  }
1
  <?php
2
  if ( ! class_exists( 'WP_List_Table' ) ) {
3
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
4
  }
5
 
6
  class SiteGuard_LoginHistory_Table extends WP_List_Table {
11
  protected $filter_login_name_not;
12
  protected $filter_ip_address_not;
13
 
14
+ function __construct() {
15
  global $status, $page;
16
 
17
+ // Set parent defaults
18
+ parent::__construct(
19
+ array(
20
+ 'singular' => 'event', // singular name of the listed records
21
+ 'plural' => 'events', // plural name of the listed records
22
+ 'ajax' => false, // does this table support ajax?
23
+ )
24
+ );
25
+ $referer = wp_get_referer();
26
  if ( false === strpos( $referer, 'siteguard_login_history' ) ) {
27
  unset( $_COOKIE['siteguard_log_filter_operation'] );
28
  unset( $_COOKIE['siteguard_log_filter_type'] );
39
  $this->filter_login_name_not = false;
40
  $this->filter_ip_address_not = false;
41
  } else {
42
+ $this->filter_operation = $this->get_filter_operation();
43
+ $this->filter_type = $this->get_filter_type();
44
+ $this->filter_login_name = $this->get_filter_login_name();
45
+ $this->filter_ip_address = $this->get_filter_ip_address();
46
+ $this->filter_login_name_not = $this->get_filter_login_name_not();
47
+ $this->filter_ip_address_not = $this->get_filter_ip_address_not();
48
  }
49
  if ( '' === $this->filter_login_name ) {
50
  $this->filter_login_name_not = false;
65
  case 'ip_address':
66
  return $item[ $column_name ];
67
  default:
68
+ return print_r( $item, true ); // Show the whole array for troubleshooting purposes
69
  }
70
  }
71
 
72
+ function get_columns() {
73
  $columns = array(
74
+ // 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
75
+ 'time' => esc_html__( 'Date Time', 'siteguard' ),
76
+ 'operation' => esc_html__( 'Operation', 'siteguard' ),
77
  'login_name' => esc_html__( 'Login Name', 'siteguard' ),
78
  'ip_address' => esc_html__( 'IP Address', 'siteguard' ),
79
  'type' => esc_html__( 'Type', 'siteguard' ),
81
  return $columns;
82
  }
83
 
84
+ function get_sortable_columns() {
85
  $sortable_columns = array(
86
+ 'time' => array( 'id', true ), // true means it's already sorted
87
+ 'operation' => array( 'operation', false ), // true means it's already sorted
88
  'login_name' => array( 'login_name', false ),
89
  'ip_address' => array( 'ip_address', false ),
90
  'type' => array( 'type', false ),
92
  return $sortable_columns;
93
  }
94
 
95
+ function get_bulk_actions() {
96
+ // $actions = array(
97
+ // 'delete' => __( 'Delete' ),
98
+ // );
99
  $actions = array();
100
  return $actions;
101
  }
102
 
103
 
104
+ function process_bulk_action() {
105
  return;
106
  }
107
 
108
  function usort_reorder( $a, $b ) {
109
  $orderby_values = array( 'id', 'operation', 'time', 'login_name', 'ip_address', 'type' );
110
+ $order_values = array( 'asc', 'desc' );
111
+ $orderby = ( ! empty( $_REQUEST['orderby'] ) ) ? ( in_array( $_REQUEST['orderby'], $orderby_values ) ? sanitize_key( $_REQUEST['orderby'] ) : 'id' ) : 'id'; // If no sort, default to id
112
+ $order = ( ! empty( $_REQUEST['order'] ) ) ? ( in_array( $_REQUEST['order'], $order_values ) ? sanitize_key( $_REQUEST['order'] ) : 'desc' ) : 'desc'; // If no order, default to desc
113
  if ( 'id' == $orderby ) {
114
  $result = ( $a > $b ? 1 : ( $a < $b ? -1 : 0 ) );
115
  } else {
116
+ $result = strcmp( $a[ $orderby ], $b[ $orderby ] ); // Determine sort order
117
  }
118
+ return ( 'asc' == $order ) ? $result : -$result; // Send final sort direction to usort
119
  }
120
  function get_filter_param_normal( $name, $default ) {
121
  $result = $default;
122
  if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
123
  if ( isset( $_POST[ $name ] ) ) {
124
+ $result = sanitize_text_field( $_POST[ $name ] );
125
  }
126
  } else {
127
  $cookie_name = 'siteguard_log_' . $name;
128
  if ( isset( $_COOKIE[ $cookie_name ] ) ) {
129
+ $result = sanitize_text_field( $_COOKIE[ $cookie_name ] );
130
  }
131
  }
132
  return $result;
151
  }
152
  return $result;
153
  }
154
+ function get_filter_operation() {
155
  global $siteguard_login_history;
156
  $result = $this->get_filter_param_normal( 'filter_operation', SITEGUARD_LOGIN_NOSELECT );
157
  if ( ! $siteguard_login_history->check_operation( $result ) ) {
159
  }
160
  return $result;
161
  }
162
+ function get_filter_type() {
163
  global $siteguard_login_history;
164
  $result = $this->get_filter_param_normal( 'filter_type', SITEGUARD_LOGIN_TYPE_NOSELECT );
165
  if ( ! $siteguard_login_history->check_type( $result ) ) {
167
  }
168
  return $result;
169
  }
170
+ function get_filter_login_name() {
171
  return $this->get_filter_param_normal( 'filter_login_name', '' );
172
  }
173
+ function get_filter_ip_address() {
174
  return $this->get_filter_param_normal( 'filter_ip_address', '' );
175
  }
176
+ function get_filter_login_name_not() {
177
  return $this->get_filter_param_checkbox( 'filter_login_name_not', false );
178
  }
179
+ function get_filter_ip_address_not() {
180
  return $this->get_filter_param_checkbox( 'filter_ip_address_not', false );
181
  }
182
+ function operation_dropdown() {
183
  ?>
184
  <select name="filter_operation" id="filter-by-operation">
185
+ <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_NOSELECT ); ?> value="<?php echo SITEGUARD_LOGIN_NOSELECT; ?>"><?php echo esc_html__( 'All Operations', 'siteguard' ); ?></option>
186
+ <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_SUCCESS ); ?> value="<?php echo SITEGUARD_LOGIN_SUCCESS; ?>"><?php echo esc_html__( 'Success', 'siteguard' ); ?></option>
187
+ <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_FAILED ); ?> value="<?php echo SITEGUARD_LOGIN_FAILED; ?>"><?php echo esc_html__( 'Failed', 'siteguard' ); ?></option>
188
+ <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_FAIL_ONCE ); ?> value="<?php echo SITEGUARD_LOGIN_FAIL_ONCE; ?>"><?php echo esc_html__( 'Fail once', 'siteguard' ); ?></option>
189
+ <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_LOCKED ); ?> value="<?php echo SITEGUARD_LOGIN_LOCKED; ?>"><?php echo esc_html__( 'Locked', 'siteguard' ); ?></option>
190
  </select>
191
  <?php
192
  }
193
+ function login_name_input() {
194
  ?>
195
  <input type="text" name="filter_login_name" id="filter-login-name" size="15" value="<?php echo esc_attr( $this->filter_login_name ); ?>">
196
  <input type="checkbox" name="filter_login_name_not" id="filter-login-name-not" <?php checked( $this->filter_login_name_not, true ); ?> >
197
+ <label for="filter-login-name-not" ><?php echo esc_html__( 'Other', 'siteguard' ); ?></label>
198
  <?php
199
  }
200
+ function ip_address_input() {
201
  ?>
202
  <input type="text" name="filter_ip_address" id="filter-ip-address" size="15" value="<?php echo esc_attr( $this->filter_ip_address ); ?>">
203
  <input type="checkbox" name="filter_ip_address_not" id="filter-ip-address-not" <?php checked( $this->filter_ip_address_not, true ); ?> >
204
+ <label for="filter-ip-address-not" ><?php echo esc_html__( 'Other', 'siteguard' ); ?></label>
205
  <?php
206
  }
207
+ function type_dropdown() {
208
  ?>
209
  <select name="filter_type" id="filter-type">
210
+ <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_NOSELECT ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_NOSELECT; ?>"><?php echo esc_html__( 'All Types', 'siteguard' ); ?></option>
211
+ <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_NORMAL ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_NORMAL; ?>"><?php echo esc_html__( 'Login Page', 'siteguard' ); ?></option>
212
+ <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_XMLRPC ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_XMLRPC; ?>"><?php echo esc_html__( 'XMLRPC', 'siteguard' ); ?></option>
213
  </select>
214
  <?php
215
  }
221
  <div class="alignleft actions bulkactions">
222
  <table>
223
  <tr>
224
+ <td><label for="filter-operation"><?php echo esc_html__( 'Operation', 'siteguard' ) . ':'; ?></label></td>
225
+ <td><?php $this->operation_dropdown(); ?></td>
226
  <td width="30px"></td>
227
  <td><label for="filter-login-name" ><?php echo esc_html__( 'Login Name', 'siteguard' ) . ':'; ?></label></td>
228
+ <td><?php $this->login_name_input(); ?></td>
229
  </tr><tr>
230
+ <td><label for="filter-type" ><?php echo esc_html__( 'Type', 'siteguard' ) . ':'; ?></label></td>
231
+ <td><?php $this->type_dropdown(); ?></td>
232
  <td></td>
233
  <td><label for="filter-ip-address" ><?php echo esc_html__( 'IP Address', 'siteguard' ) . ':'; ?></label></td>
234
+ <td><?php $this->ip_address_input(); ?></td>
235
  </tr>
236
  </table>
237
  <input type="submit" name="filter_action" id="post-query-submit" class="button" value="<?php echo esc_attr__( 'Filter' ); ?>">
240
  <?php
241
  }
242
 
243
+ function prepare_items() {
244
  global $siteguard_login_history;
245
 
246
  $per_page = 10;
247
 
248
+ $columns = $this->get_columns();
249
  $hidden = array();
250
+ $sortable = $this->get_sortable_columns();
251
 
252
  $this->_column_headers = array( $columns, $hidden, $sortable );
253
 
254
+ $this->process_bulk_action();
255
 
256
  $data = $siteguard_login_history->get_history( $this->filter_operation, $this->filter_login_name, $this->filter_ip_address, $this->filter_type, $this->filter_login_name_not, $this->filter_ip_address_not );
257
 
258
+ $total_items = count( $data );
259
+ $current_page = $this->get_pagenum();
260
 
261
  if ( $total_items <= ( ( $current_page - 1 ) * $per_page ) ) {
262
  $current_page = 1;
268
 
269
  $this->items = $data;
270
 
271
+ $this->set_pagination_args(
272
+ array(
273
+ 'total_items' => $total_items, // WE have to calculate the total number of items
274
+ 'per_page' => $per_page, // WE have to determine how many items to show on a page
275
+ 'total_pages' => ceil( $total_items / $per_page ), // WE have to calculate the total number of pages
276
+ )
277
+ );
278
  }
279
  }
admin/siteguard-menu-admin-filter.php CHANGED
@@ -4,20 +4,20 @@ class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base {
4
  const OPT_NAME_FEATURE = 'admin_filter_enable';
5
  const OPT_NAME_EXCLUDE = 'admin_filter_exclude_path';
6
 
7
- function __construct( ) {
8
- $this->render_page( );
9
  }
10
- function render_page( ) {
11
  global $siteguard_admin_filter, $siteguard_config;
12
 
13
  $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE );
14
  $opt_val_exclude = $this->cvt_camma2ret( $siteguard_config->get( self::OPT_NAME_EXCLUDE ) );
15
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-admin-filter-submit' ) ) {
16
- $error = false;
17
- $errors = siteguard_check_multisite( );
18
  if ( is_wp_error( $errors ) ) {
19
  echo '<div class="error settings-error"><p><strong>';
20
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
21
  echo '</strong></p></div>';
22
  $error = true;
23
  }
@@ -27,8 +27,8 @@ class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base {
27
  echo '</strong></p></div>';
28
  $error = true;
29
  $siteguard_config->set( self::OPT_NAME_FEATURE, '0' );
30
- $siteguard_config->update( );
31
- $siteguard_admin_filter->feature_off( );
32
  $opt_val_feature = '0';
33
  }
34
  if ( false === $error && false === $this->is_switch_value( $_POST[ self::OPT_NAME_FEATURE ] ) ) {
@@ -37,7 +37,7 @@ class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base {
37
  echo '</strong></p></div>';
38
  $error = true;
39
  }
40
- if ( false === $error && '1' === $_POST[ self::OPT_NAME_FEATURE ] && false === SiteGuard_Htaccess::test_htaccess( ) ) {
41
  echo '<div class="error settings-error"><p><strong>';
42
  esc_html_e( 'mod_rewrite of .htaccess can not be used', 'siteguard' );
43
  echo '</strong></p></div>';
@@ -46,16 +46,16 @@ class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base {
46
  if ( false === $error ) {
47
  $old_opt_val_feature = $opt_val_feature;
48
  $old_opt_val_exclude = $opt_val_exclude;
49
- $opt_val_feature = $_POST[ self::OPT_NAME_FEATURE ];
50
- $opt_val_exclude = stripslashes( $_POST[ self::OPT_NAME_EXCLUDE ] );
51
  $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
52
  $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) );
53
- $siteguard_config->update( );
54
  $result = true;
55
  if ( '0' === $opt_val_feature ) {
56
- $result = $siteguard_admin_filter->feature_off( );
57
  } else {
58
- $result = $siteguard_admin_filter->feature_on( $this->get_ip( ) );
59
  }
60
  if ( true === $result ) {
61
  $opt_val_exclude = $this->cvt_camma2ret( $opt_val_exclude );
@@ -67,7 +67,7 @@ class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base {
67
  $opt_val_exclude = $old_opt_val_exclude;
68
  $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
69
  $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) );
70
- $siteguard_config->update( );
71
  echo '<div class="error settings-error"><p><strong>';
72
  esc_html_e( 'ERROR: Failed to .htaccess update.', 'siteguard' );
73
  echo '</strong></p></div>';
@@ -93,19 +93,19 @@ class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base {
93
  <th scope="row" colspan="2">
94
  <ul class="siteguard-radios">
95
  <li>
96
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE . '_on' ?>" value="1" <?php checked( $opt_val_feature, '1' ) ?> >
97
- <label for="<?php echo self::OPT_NAME_FEATURE.'_on' ?>" ><?php echo esc_html_e( 'ON', 'siteguard' ) ?></label>
98
  </li>
99
  <li>
100
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE . '_off' ?>" value="0" <?php checked( $opt_val_feature, '0' ) ?> >
101
- <label for="<?php echo self::OPT_NAME_FEATURE.'_off' ?>" ><?php echo esc_html_e( 'OFF', 'siteguard' ) ?></label>
102
  </li>
103
  </ul>
104
  <?php
105
- $error = siteguard_check_multisite( );
106
  if ( is_wp_error( $error ) ) {
107
  echo '<p class="description">';
108
- echo $error->get_error_message( );
109
  echo '</p>';
110
  }
111
  echo '<p class="description">';
@@ -114,9 +114,9 @@ class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base {
114
  ?>
115
  </th>
116
  </tr><tr>
117
- <th scope="row"><label for="<?php echo self::OPT_NAME_EXCLUDE ?>"><?php echo esc_html_e( 'Exclude Path', 'siteguard' ) ?></label></th>
118
- <td><textarea name="<?php echo self::OPT_NAME_EXCLUDE ?>" id="<?php echo self::OPT_NAME_EXCLUDE ?>" cols=40 rows=5 ><?php echo esc_textarea( $opt_val_exclude ) ?></textarea>
119
- <p class="description"><?php esc_html_e( 'The path of /wp-admin/ henceforth is specified. To specify more than one, separate them with new line. ', 'siteguard' ) ?></p></td>
120
  </tr>
121
  </table>
122
  <input type="hidden" name="update" value="Y">
@@ -126,7 +126,7 @@ class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base {
126
  <hr />
127
  <?php
128
  wp_nonce_field( 'siteguard-menu-admin-filter-submit' );
129
- submit_button( );
130
  ?>
131
  </form>
132
  </div>
4
  const OPT_NAME_FEATURE = 'admin_filter_enable';
5
  const OPT_NAME_EXCLUDE = 'admin_filter_exclude_path';
6
 
7
+ function __construct() {
8
+ $this->render_page();
9
  }
10
+ function render_page() {
11
  global $siteguard_admin_filter, $siteguard_config;
12
 
13
  $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE );
14
  $opt_val_exclude = $this->cvt_camma2ret( $siteguard_config->get( self::OPT_NAME_EXCLUDE ) );
15
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-admin-filter-submit' ) ) {
16
+ $error = false;
17
+ $errors = siteguard_check_multisite();
18
  if ( is_wp_error( $errors ) ) {
19
  echo '<div class="error settings-error"><p><strong>';
20
+ echo esc_html( $errors->get_error_message() );
21
  echo '</strong></p></div>';
22
  $error = true;
23
  }
27
  echo '</strong></p></div>';
28
  $error = true;
29
  $siteguard_config->set( self::OPT_NAME_FEATURE, '0' );
30
+ $siteguard_config->update();
31
+ $siteguard_admin_filter->feature_off();
32
  $opt_val_feature = '0';
33
  }
34
  if ( false === $error && false === $this->is_switch_value( $_POST[ self::OPT_NAME_FEATURE ] ) ) {
37
  echo '</strong></p></div>';
38
  $error = true;
39
  }
40
+ if ( false === $error && '1' === $_POST[ self::OPT_NAME_FEATURE ] && false === SiteGuard_Htaccess::test_htaccess() ) {
41
  echo '<div class="error settings-error"><p><strong>';
42
  esc_html_e( 'mod_rewrite of .htaccess can not be used', 'siteguard' );
43
  echo '</strong></p></div>';
46
  if ( false === $error ) {
47
  $old_opt_val_feature = $opt_val_feature;
48
  $old_opt_val_exclude = $opt_val_exclude;
49
+ $opt_val_feature = sanitize_text_field( $_POST[ self::OPT_NAME_FEATURE ] );
50
+ $opt_val_exclude = stripslashes( sanitize_textarea_field( $_POST[ self::OPT_NAME_EXCLUDE ] ) );
51
  $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
52
  $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) );
53
+ $siteguard_config->update();
54
  $result = true;
55
  if ( '0' === $opt_val_feature ) {
56
+ $result = $siteguard_admin_filter->feature_off();
57
  } else {
58
+ $result = $siteguard_admin_filter->feature_on( $this->get_ip() );
59
  }
60
  if ( true === $result ) {
61
  $opt_val_exclude = $this->cvt_camma2ret( $opt_val_exclude );
67
  $opt_val_exclude = $old_opt_val_exclude;
68
  $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
69
  $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) );
70
+ $siteguard_config->update();
71
  echo '<div class="error settings-error"><p><strong>';
72
  esc_html_e( 'ERROR: Failed to .htaccess update.', 'siteguard' );
73
  echo '</strong></p></div>';
93
  <th scope="row" colspan="2">
94
  <ul class="siteguard-radios">
95
  <li>
96
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>" value="1" <?php checked( $opt_val_feature, '1' ); ?> >
97
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>" ><?php echo esc_html_e( 'ON', 'siteguard' ); ?></label>
98
  </li>
99
  <li>
100
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>" value="0" <?php checked( $opt_val_feature, '0' ); ?> >
101
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>" ><?php echo esc_html_e( 'OFF', 'siteguard' ); ?></label>
102
  </li>
103
  </ul>
104
  <?php
105
+ $error = siteguard_check_multisite();
106
  if ( is_wp_error( $error ) ) {
107
  echo '<p class="description">';
108
+ echo esc_html( $error->get_error_message() );
109
  echo '</p>';
110
  }
111
  echo '<p class="description">';
114
  ?>
115
  </th>
116
  </tr><tr>
117
+ <th scope="row"><label for="<?php echo self::OPT_NAME_EXCLUDE; ?>"><?php echo esc_html_e( 'Exclude Path', 'siteguard' ); ?></label></th>
118
+ <td><textarea name="<?php echo self::OPT_NAME_EXCLUDE; ?>" id="<?php echo self::OPT_NAME_EXCLUDE; ?>" cols=40 rows=5 ><?php echo esc_textarea( $opt_val_exclude ); ?></textarea>
119
+ <p class="description"><?php esc_html_e( 'The path of /wp-admin/ henceforth is specified. To specify more than one, separate them with new line. ', 'siteguard' ); ?></p></td>
120
  </tr>
121
  </table>
122
  <input type="hidden" name="update" value="Y">
126
  <hr />
127
  <?php
128
  wp_nonce_field( 'siteguard-menu-admin-filter-submit' );
129
+ submit_button();
130
  ?>
131
  </form>
132
  </div>
admin/siteguard-menu-author-query.php CHANGED
@@ -1,25 +1,25 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Author_Query extends SiteGuard_Base {
4
- const OPT_NAME_FEATURE = 'block_author_query_enable';
5
- const OPT_NAME_RESTAPI = 'disable_restapi_enable';
6
- const OPT_NAME_EXCLUDE = 'disable_restapi_exclude';
7
 
8
- function __construct( ) {
9
- $this->render_page( );
10
  }
11
- function render_page( ) {
12
  global $siteguard_config, $siteguard_author_query;
13
 
14
  $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE );
15
  $opt_val_restapi = $siteguard_config->get( self::OPT_NAME_RESTAPI );
16
  $opt_val_exclude = $this->cvt_camma2ret( $siteguard_config->get( self::OPT_NAME_EXCLUDE ) );
17
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-block-author-query-submit' ) ) {
18
- $error = false;
19
- $errors = siteguard_check_multisite( );
20
  if ( is_wp_error( $errors ) ) {
21
  echo '<div class="error settings-error"><p><strong>';
22
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
23
  echo '</strong></p></div>';
24
  $error = true;
25
  }
@@ -33,17 +33,17 @@ class SiteGuard_Menu_Author_Query extends SiteGuard_Base {
33
  $old_opt_val_feature = $opt_val_feature;
34
  $old_opt_val_restapi = $opt_val_restapi;
35
  $old_opt_val_exclude = $opt_val_exclude;
36
- $opt_val_feature = $_POST[ self::OPT_NAME_FEATURE ];
37
  if ( isset( $_POST[ self::OPT_NAME_RESTAPI ] ) ) {
38
- $opt_val_restapi = $_POST[ self::OPT_NAME_RESTAPI ];
39
  } else {
40
  $opt_val_restapi = '0';
41
  }
42
- $opt_val_exclude = stripslashes( $_POST[ self::OPT_NAME_EXCLUDE ] );
43
  $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
44
  $siteguard_config->set( self::OPT_NAME_RESTAPI, $opt_val_restapi );
45
  $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) );
46
- $siteguard_config->update( );
47
  $result = true;
48
  if ( true === $result ) {
49
  $opt_val_exclude = $this->cvt_camma2ret( $opt_val_exclude );
@@ -57,7 +57,7 @@ class SiteGuard_Menu_Author_Query extends SiteGuard_Base {
57
  $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
58
  $siteguard_config->set( self::OPT_NAME_RESTAPI, $opt_val_restapi );
59
  $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) );
60
- $siteguard_config->update( );
61
  echo '<div class="error settings-error"><p><strong>';
62
  esc_html_e( 'ERROR: Failed to .htaccess update.', 'siteguard' );
63
  echo '</strong></p></div>';
@@ -84,34 +84,34 @@ class SiteGuard_Menu_Author_Query extends SiteGuard_Base {
84
  <th scope="row" colspan="2">
85
  <ul class="siteguard-radios">
86
  <li>
87
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE.'_on' ?>" value="1" <?php checked( $opt_val_feature, '1' ) ?> >
88
- <label for="<?php echo self::OPT_NAME_FEATURE.'_on' ?>"><?php echo esc_html_e( 'ON', 'siteguard' ) ?></label>
89
  </li><li>
90
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE.'_off' ?>" value="0" <?php checked( $opt_val_feature, '0' ) ?> >
91
- <label for="<?php echo self::OPT_NAME_FEATURE.'_off' ?>"><?php echo esc_html_e( 'OFF', 'siteguard' ) ?></label>
92
  </li>
93
  </ul>
94
  <?php
95
- $error = siteguard_check_multisite( );
96
  if ( is_wp_error( $error ) ) {
97
  echo '<p class="description">';
98
- echo $error->get_error_message( );
99
  echo '</p>';
100
  }
101
  ?>
102
  </th>
103
  </tr><tr>
104
- <th scope="row"><?php esc_html_e( 'Option', 'siteguard' ) ?></th>
105
- <td>
106
- <input type="checkbox" name="<?php echo self::OPT_NAME_RESTAPI ?>" id="<?php echo self::OPT_NAME_RESTAPI ?>" value="1" <?php checked( $opt_val_restapi, '1' ) ?> >
107
- <label for="<?php echo self::OPT_NAME_RESTAPI ?>"><?php esc_html_e( 'Disable REST API', 'siteguard' ) ?></label>
108
- </td>
109
 
110
  </tr>
111
  </tr><tr>
112
- <th scope="row"><label for="<?php echo self::OPT_NAME_EXCLUDE ?>"><?php echo esc_html_e( 'Exclude Plugins', 'siteguard' ) ?></label></th>
113
- <td><textarea name="<?php echo self::OPT_NAME_EXCLUDE ?>" id="<?php echo self::OPT_NAME_EXCLUDE ?>" class="siteguard-box-300" cols=40 rows=10 ><?php echo esc_textarea( $opt_val_exclude ) ?></textarea>
114
- <p class="description"><?php esc_html_e( 'Please specify the plugin. To specify more than one, separate them with new line. ', 'siteguard' ) ?></p></br>
115
  <script>
116
  function add_value(){
117
  const crlf = String.fromCharCode(13) + String.fromCharCode(10)
@@ -126,38 +126,38 @@ class SiteGuard_Menu_Author_Query extends SiteGuard_Base {
126
  }
127
  }
128
  </script>
129
- <select name="plugins" class="siteguard-box-300" size="15">
130
- <?php
131
- $val_excludes = explode( "\r\n", $opt_val_exclude );
132
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
133
- $plugins = get_plugins( );
134
- if ( ! empty( $plugins ) ) {
135
- foreach ( $plugins as $path => $plugin ) {
136
- if ( is_plugin_active( $path ) ) {
137
- $text_domain = $plugin['TextDomain'];
138
- if ( ! in_array( $text_domain, $val_excludes ) && 'siteguard' != $text_domain ) {
139
- ?>
140
- <option value="<?php esc_attr_e( $text_domain ); ?>"><?php echo esc_html( $text_domain );?></option>
141
  <?php
142
- }
 
 
 
 
 
 
 
 
 
 
143
  }
144
  }
145
  }
 
146
  ?>
147
  </select>
148
- <input type="button" value="<?php esc_html_e( 'Add Exclude Plugin', 'siteguard' ) ?>" onclick="add_value()" />
149
- <p class="description"><?php esc_html_e( 'This is a list of valid plugins. You can select it and add it to the exclude plugins.', 'siteguard' ) ?></p></br>
150
  </td>
151
  </tr>
152
  </table>
153
  <input type="hidden" name="update" value="Y">
154
  <div class="siteguard-description">
155
- <?php esc_html_e( 'Prevents leakage of user names due to "/?author=<number>" access. You can also disable the REST API to prevent username leaks via the REST API. If there are plugins that do not work due to the REST API being disabled, please add the plugin name to the excluded plugins. You can add the plugin name from the list of enabled plugin names.', 'siteguard' ) ?>
156
  </div>
157
  <hr />
158
  <?php
159
  wp_nonce_field( 'siteguard-menu-block-author-query-submit' );
160
- submit_button( );
161
  ?>
162
  </form>
163
  </div>
1
  <?php
2
 
3
  class SiteGuard_Menu_Author_Query extends SiteGuard_Base {
4
+ const OPT_NAME_FEATURE = 'block_author_query_enable';
5
+ const OPT_NAME_RESTAPI = 'disable_restapi_enable';
6
+ const OPT_NAME_EXCLUDE = 'disable_restapi_exclude';
7
 
8
+ function __construct() {
9
+ $this->render_page();
10
  }
11
+ function render_page() {
12
  global $siteguard_config, $siteguard_author_query;
13
 
14
  $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE );
15
  $opt_val_restapi = $siteguard_config->get( self::OPT_NAME_RESTAPI );
16
  $opt_val_exclude = $this->cvt_camma2ret( $siteguard_config->get( self::OPT_NAME_EXCLUDE ) );
17
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-block-author-query-submit' ) ) {
18
+ $error = false;
19
+ $errors = siteguard_check_multisite();
20
  if ( is_wp_error( $errors ) ) {
21
  echo '<div class="error settings-error"><p><strong>';
22
+ echo esc_html( $errors->get_error_message() );
23
  echo '</strong></p></div>';
24
  $error = true;
25
  }
33
  $old_opt_val_feature = $opt_val_feature;
34
  $old_opt_val_restapi = $opt_val_restapi;
35
  $old_opt_val_exclude = $opt_val_exclude;
36
+ $opt_val_feature = sanitize_text_field( $_POST[ self::OPT_NAME_FEATURE ] );
37
  if ( isset( $_POST[ self::OPT_NAME_RESTAPI ] ) ) {
38
+ $opt_val_restapi = '1';
39
  } else {
40
  $opt_val_restapi = '0';
41
  }
42
+ $opt_val_exclude = stripslashes( sanitize_textarea_field( $_POST[ self::OPT_NAME_EXCLUDE ] ) );
43
  $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
44
  $siteguard_config->set( self::OPT_NAME_RESTAPI, $opt_val_restapi );
45
  $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) );
46
+ $siteguard_config->update();
47
  $result = true;
48
  if ( true === $result ) {
49
  $opt_val_exclude = $this->cvt_camma2ret( $opt_val_exclude );
57
  $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
58
  $siteguard_config->set( self::OPT_NAME_RESTAPI, $opt_val_restapi );
59
  $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) );
60
+ $siteguard_config->update();
61
  echo '<div class="error settings-error"><p><strong>';
62
  esc_html_e( 'ERROR: Failed to .htaccess update.', 'siteguard' );
63
  echo '</strong></p></div>';
84
  <th scope="row" colspan="2">
85
  <ul class="siteguard-radios">
86
  <li>
87
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>" value="1" <?php checked( $opt_val_feature, '1' ); ?> >
88
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>"><?php echo esc_html_e( 'ON', 'siteguard' ); ?></label>
89
  </li><li>
90
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>" value="0" <?php checked( $opt_val_feature, '0' ); ?> >
91
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>"><?php echo esc_html_e( 'OFF', 'siteguard' ); ?></label>
92
  </li>
93
  </ul>
94
  <?php
95
+ $error = siteguard_check_multisite();
96
  if ( is_wp_error( $error ) ) {
97
  echo '<p class="description">';
98
+ echo esc_html( $error->get_error_message() );
99
  echo '</p>';
100
  }
101
  ?>
102
  </th>
103
  </tr><tr>
104
+ <th scope="row"><?php esc_html_e( 'Option', 'siteguard' ); ?></th>
105
+ <td>
106
+ <input type="checkbox" name="<?php echo self::OPT_NAME_RESTAPI; ?>" id="<?php echo self::OPT_NAME_RESTAPI; ?>" value="1" <?php checked( $opt_val_restapi, '1' ); ?> >
107
+ <label for="<?php echo self::OPT_NAME_RESTAPI; ?>"><?php esc_html_e( 'Disable REST API', 'siteguard' ); ?></label>
108
+ </td>
109
 
110
  </tr>
111
  </tr><tr>
112
+ <th scope="row"><label for="<?php echo self::OPT_NAME_EXCLUDE; ?>"><?php echo esc_html_e( 'Exclude Plugins', 'siteguard' ); ?></label></th>
113
+ <td><textarea name="<?php echo self::OPT_NAME_EXCLUDE; ?>" id="<?php echo self::OPT_NAME_EXCLUDE; ?>" class="siteguard-box-300" cols=40 rows=10 ><?php echo esc_textarea( $opt_val_exclude ); ?></textarea>
114
+ <p class="description"><?php esc_html_e( 'Please specify the plugin. To specify more than one, separate them with new line. ', 'siteguard' ); ?></p></br>
115
  <script>
116
  function add_value(){
117
  const crlf = String.fromCharCode(13) + String.fromCharCode(10)
126
  }
127
  }
128
  </script>
129
+ <select name="plugins" class="siteguard-box-300" size="15">
 
 
 
 
 
 
 
 
 
 
 
130
  <?php
131
+ $val_excludes = explode( "\r\n", $opt_val_exclude );
132
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
133
+ $plugins = get_plugins();
134
+ if ( ! empty( $plugins ) ) {
135
+ foreach ( $plugins as $path => $plugin ) {
136
+ if ( is_plugin_active( $path ) ) {
137
+ $text_domain = $plugin['TextDomain'];
138
+ if ( ! in_array( $text_domain, $val_excludes ) && 'siteguard' != $text_domain ) {
139
+ ?>
140
+ <option value="<?php esc_attr_e( $text_domain ); ?>"><?php echo esc_html( $text_domain ); ?></option>
141
+ <?php
142
  }
143
  }
144
  }
145
+ }
146
  ?>
147
  </select>
148
+ <input type="button" value="<?php esc_html_e( 'Add Exclude Plugin', 'siteguard' ); ?>" onclick="add_value()" />
149
+ <p class="description"><?php esc_html_e( 'This is a list of valid plugins. You can select it and add it to the exclude plugins.', 'siteguard' ); ?></p></br>
150
  </td>
151
  </tr>
152
  </table>
153
  <input type="hidden" name="update" value="Y">
154
  <div class="siteguard-description">
155
+ <?php esc_html_e( 'Prevents leakage of user names due to "/?author=<number>" access. You can also disable the REST API to prevent username leaks via the REST API. If there are plugins that do not work due to the REST API being disabled, please add the plugin name to the excluded plugins. You can add the plugin name from the list of enabled plugin names.', 'siteguard' ); ?>
156
  </div>
157
  <hr />
158
  <?php
159
  wp_nonce_field( 'siteguard-menu-block-author-query-submit' );
160
+ submit_button();
161
  ?>
162
  </form>
163
  </div>
admin/siteguard-menu-captcha.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_CAPTCHA extends SiteGuard_Base {
4
- const OPT_NAME_ENABLE = 'captcha_enable';
5
- const OPT_NAME_LOGIN = 'captcha_login';
6
- const OPT_NAME_COMMENT = 'captcha_comment';
7
- const OPT_NAME_LOSTPASSWORD = 'captcha_lostpasswd';
8
- const OPT_NAME_REGISTUSER = 'captcha_registuser';
9
 
10
- function __construct( ) {
11
- $this->render_page( );
12
  }
13
  function is_captcha_switch_value( $value ) {
14
  $items = array( '0', '1', '2' );
@@ -17,55 +17,55 @@ class SiteGuard_Menu_CAPTCHA extends SiteGuard_Base {
17
  }
18
  return false;
19
  }
20
- function render_page( ) {
21
  global $siteguard_config, $siteguard_captcha;
22
 
23
- $opt_val_enable = $siteguard_config->get( self::OPT_NAME_ENABLE );
24
- $opt_val_login = $siteguard_config->get( self::OPT_NAME_LOGIN );
25
- $opt_val_comment = $siteguard_config->get( self::OPT_NAME_COMMENT );
26
- $opt_val_lostpassword = $siteguard_config->get( self::OPT_NAME_LOSTPASSWORD );
27
- $opt_val_registuser = $siteguard_config->get( self::OPT_NAME_REGISTUSER );
28
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-captcha-submit' ) ) {
29
- $error = false;
30
- $errors = siteguard_check_multisite( );
31
  if ( is_wp_error( $errors ) ) {
32
  echo '<div class="error settings-error"><p><strong>';
33
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
34
  echo '</strong></p></div>';
35
  $error = true;
36
  }
37
  if ( false === $error && '1' == $_POST[ self::OPT_NAME_ENABLE ] ) {
38
- $ret = $siteguard_captcha->check_requirements( );
39
  if ( is_wp_error( $ret ) ) {
40
- echo '<div class="error settings-error"><p><strong>' . $ret->get_error_message( ) . '</strong></p></div>';
41
  $error = true;
42
  $siteguard_config->set( self::OPT_NAME_ENABLE, '0' );
43
- $siteguard_config->update( );
44
  }
45
  }
46
  if ( ( false === $error )
47
  && ( ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_ENABLE ] ) )
48
- || ( false === $this->is_captcha_switch_value( $_POST[ self::OPT_NAME_LOGIN ] ) )
49
- || ( false === $this->is_captcha_switch_value( $_POST[ self::OPT_NAME_COMMENT ] ) )
50
- || ( false === $this->is_captcha_switch_value( $_POST[ self::OPT_NAME_LOSTPASSWORD ] ) )
51
- || ( false === $this->is_captcha_switch_value( $_POST[ self::OPT_NAME_REGISTUSER ] ) ) ) ) {
52
  echo '<div class="error settings-error"><p><strong>';
53
  esc_html_e( 'ERROR: Invalid input value.', 'siteguard' );
54
  echo '</strong></p></div>';
55
  $error = true;
56
  }
57
  if ( false === $error ) {
58
- $opt_val_enable = $_POST[ self::OPT_NAME_ENABLE ];
59
- $opt_val_login = $_POST[ self::OPT_NAME_LOGIN ];
60
- $opt_val_comment = $_POST[ self::OPT_NAME_COMMENT ];
61
- $opt_val_lostpassword = $_POST[ self::OPT_NAME_LOSTPASSWORD ];
62
- $opt_val_registuser = $_POST[ self::OPT_NAME_REGISTUSER ];
63
- $siteguard_config->set( self::OPT_NAME_ENABLE, $opt_val_enable );
64
- $siteguard_config->set( self::OPT_NAME_LOGIN, $opt_val_login );
65
- $siteguard_config->set( self::OPT_NAME_COMMENT, $opt_val_comment );
66
- $siteguard_config->set( self::OPT_NAME_LOSTPASSWORD, $opt_val_lostpassword );
67
- $siteguard_config->set( self::OPT_NAME_REGISTUSER, $opt_val_registuser );
68
- $siteguard_config->update( );
69
  ?>
70
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
71
  <?php
@@ -90,18 +90,18 @@ class SiteGuard_Menu_CAPTCHA extends SiteGuard_Base {
90
  <th scope="row" colspan="2">
91
  <ul class="siteguard-radios">
92
  <li>
93
- <input type="radio" name="<?php echo self::OPT_NAME_ENABLE ?>" id="<?php echo self::OPT_NAME_ENABLE.'_on' ?>" value="1" <?php checked( $opt_val_enable, '1' ) ?> >
94
- <label for="<?php echo self::OPT_NAME_ENABLE.'_on' ?>"><?php esc_html_e( 'ON', 'siteguard' ) ?></label>
95
  </li><li>
96
- <input type="radio" name="<?php echo self::OPT_NAME_ENABLE ?>" id="<?php echo self::OPT_NAME_ENABLE.'_off' ?>" value="0" <?php checked( $opt_val_enable, '0' ) ?> >
97
- <label for="<?php echo self::OPT_NAME_ENABLE.'_off' ?>"><?php esc_html_e( 'OFF', 'siteguard' ) ?></label>
98
  </li>
99
  </ul>
100
  <?php
101
- $error = $siteguard_captcha->check_requirements( );
102
  if ( is_wp_error( $error ) ) {
103
  echo '<p class="description">';
104
- echo $error->get_error_message( );
105
  echo '</p>';
106
  }
107
  ?>
@@ -109,55 +109,55 @@ class SiteGuard_Menu_CAPTCHA extends SiteGuard_Base {
109
  </tr><tr>
110
  <th scope="row"><?php esc_html_e( 'Login page', 'siteguard' ); ?></th>
111
  <td>
112
- <input type="radio" name="<?php echo self::OPT_NAME_LOGIN ?>" id="<?php echo self::OPT_NAME_LOGIN.'_jp' ?>" value="1" <?php checked( $opt_val_login, '1' ) ?> >
113
- <label for="<?php echo self::OPT_NAME_LOGIN.'_jp' ?>"><?php esc_html_e( 'Hiragana (Japanese)', 'siteguard' ) ?></label>
114
  <br />
115
- <input type="radio" name="<?php echo self::OPT_NAME_LOGIN ?>" id="<?php echo self::OPT_NAME_LOGIN.'_en' ?>" value="2" <?php checked( $opt_val_login, '2' ) ?> >
116
- <label for="<?php echo self::OPT_NAME_LOGIN.'_en' ?>"><?php esc_html_e( 'Alphanumeric', 'siteguard' ) ?></label>
117
  <br />
118
- <input type="radio" name="<?php echo self::OPT_NAME_LOGIN ?>" id="<?php echo self::OPT_NAME_LOGIN.'_off' ?>" value="0" <?php checked( $opt_val_login, '0' ) ?> >
119
- <label for="<?php echo self::OPT_NAME_LOGIN.'_off' ?>"><?php esc_html_e( 'Disable', 'siteguard' ) ?></label>
120
  </td>
121
  </tr><tr>
122
  <th scope="row"><?php esc_html_e( 'Comment page', 'siteguard' ); ?></th>
123
  <td>
124
- <input type="radio" name="<?php echo self::OPT_NAME_COMMENT ?>" id="<?php echo self::OPT_NAME_COMMENT.'_jp' ?>" value="1" <?php checked( $opt_val_comment, '1' ) ?> >
125
- <label for="<?php echo self::OPT_NAME_COMMENT.'_jp' ?>"><?php esc_html_e( 'Hiragana (Japanese)', 'siteguard' ) ?></label>
126
  <br />
127
- <input type="radio" name="<?php echo self::OPT_NAME_COMMENT ?>" id="<?php echo self::OPT_NAME_COMMENT.'_en' ?>" value="2" <?php checked( $opt_val_comment, '2' ) ?> >
128
- <label for="<?php echo self::OPT_NAME_COMMENT.'_en' ?>"><?php esc_html_e( 'Alphanumeric', 'siteguard' ) ?></label>
129
  <br />
130
- <input type="radio" name="<?php echo self::OPT_NAME_COMMENT ?>" id="<?php echo self::OPT_NAME_COMMENT.'_off' ?>" value="0" <?php checked( $opt_val_comment, '0' ) ?> >
131
- <label for="<?php echo self::OPT_NAME_COMMENT.'_off' ?>"><?php esc_html_e( 'Disable', 'siteguard' ) ?></label>
132
  </td>
133
  </tr><tr>
134
  <th scope="row"><?php esc_html_e( 'Lost password page', 'siteguard' ); ?></th>
135
  <td>
136
- <input type="radio" name="<?php echo self::OPT_NAME_LOSTPASSWORD ?>" id="<?php echo self::OPT_NAME_LOSTPASSWORD.'_jp' ?>" value="1" <?php checked( $opt_val_lostpassword, '1' ) ?> >
137
- <label for="<?php echo self::OPT_NAME_LOSTPASSWORD.'_jp' ?>"><?php esc_html_e( 'Hiragana (Japanese)', 'siteguard' ) ?></label>
138
  <br />
139
- <input type="radio" name="<?php echo self::OPT_NAME_LOSTPASSWORD ?>" id="<?php echo self::OPT_NAME_LOSTPASSWORD.'_en' ?>" value="2" <?php checked( $opt_val_lostpassword, '2' ) ?> >
140
- <label for="<?php echo self::OPT_NAME_LOSTPASSWORD.'_en' ?>"><?php esc_html_e( 'Alphanumeric', 'siteguard' ) ?></label>
141
  <br />
142
- <input type="radio" name="<?php echo self::OPT_NAME_LOSTPASSWORD ?>" id="<?php echo self::OPT_NAME_LOSTPASSWORD.'_off' ?>" value="0" <?php checked( $opt_val_lostpassword, '0' ) ?> >
143
- <label for="<?php echo self::OPT_NAME_LOSTPASSWORD.'_off' ?>"><?php esc_html_e( 'Disable', 'siteguard' ) ?></label>
144
  </td>
145
  </tr><tr>
146
  <th scope="row"><?php esc_html_e( 'Registration user page', 'siteguard' ); ?></th>
147
  <td>
148
- <input type="radio" name="<?php echo self::OPT_NAME_REGISTUSER ?>" id="<?php echo self::OPT_NAME_REGISTUSER.'_jp' ?>" value="1" <?php checked( $opt_val_registuser, '1' ) ?> >
149
- <label for="<?php echo self::OPT_NAME_REGISTUSER.'_jp' ?>"><?php esc_html_e( 'Hiragana (Japanese)', 'siteguard' ) ?></label>
150
  <br />
151
- <input type="radio" name="<?php echo self::OPT_NAME_REGISTUSER ?>" id="<?php echo self::OPT_NAME_REGISTUSER.'_en' ?>" value="2" <?php checked( $opt_val_registuser, '2' ) ?> >
152
- <label for="<?php echo self::OPT_NAME_REGISTUSER.'_en' ?>"><?php esc_html_e( 'Alphanumeric', 'siteguard' ) ?></label>
153
  <br />
154
- <input type="radio" name="<?php echo self::OPT_NAME_REGISTUSER ?>" id="<?php echo self::OPT_NAME_REGISTUSER.'_off' ?>" value="0" <?php checked( $opt_val_registuser, '0' ) ?> >
155
- <label for="<?php echo self::OPT_NAME_REGISTUSER.'_off' ?>"><?php esc_html_e( 'Disable', 'siteguard' ) ?></label>
156
  </td>
157
  </tr>
158
  </table>
159
  <div class="siteguard-description">
160
- <?php esc_html_e( 'It is the function to decrease the vulnerability against an illegal login attempt attack such as a brute force attack or a password list attack, or to receive less comment spam. For the character of CAPTCHA, hiragana and alphanumeric characters can be selected.', 'siteguard' ) ?>
161
  </div>
162
  <input type="hidden" name="update" value="Y">
163
  <hr />
1
  <?php
2
 
3
  class SiteGuard_Menu_CAPTCHA extends SiteGuard_Base {
4
+ const OPT_NAME_ENABLE = 'captcha_enable';
5
+ const OPT_NAME_LOGIN = 'captcha_login';
6
+ const OPT_NAME_COMMENT = 'captcha_comment';
7
+ const OPT_NAME_LOSTPASSWORD = 'captcha_lostpasswd';
8
+ const OPT_NAME_REGISTUSER = 'captcha_registuser';
9
 
10
+ function __construct() {
11
+ $this->render_page();
12
  }
13
  function is_captcha_switch_value( $value ) {
14
  $items = array( '0', '1', '2' );
17
  }
18
  return false;
19
  }
20
+ function render_page() {
21
  global $siteguard_config, $siteguard_captcha;
22
 
23
+ $opt_val_enable = $siteguard_config->get( self::OPT_NAME_ENABLE );
24
+ $opt_val_login = $siteguard_config->get( self::OPT_NAME_LOGIN );
25
+ $opt_val_comment = $siteguard_config->get( self::OPT_NAME_COMMENT );
26
+ $opt_val_lostpassword = $siteguard_config->get( self::OPT_NAME_LOSTPASSWORD );
27
+ $opt_val_registuser = $siteguard_config->get( self::OPT_NAME_REGISTUSER );
28
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-captcha-submit' ) ) {
29
+ $error = false;
30
+ $errors = siteguard_check_multisite();
31
  if ( is_wp_error( $errors ) ) {
32
  echo '<div class="error settings-error"><p><strong>';
33
+ echo esc_html( $errors->get_error_message() );
34
  echo '</strong></p></div>';
35
  $error = true;
36
  }
37
  if ( false === $error && '1' == $_POST[ self::OPT_NAME_ENABLE ] ) {
38
+ $ret = $siteguard_captcha->check_requirements();
39
  if ( is_wp_error( $ret ) ) {
40
+ echo '<div class="error settings-error"><p><strong>' . esc_html( $ret->get_error_message() ) . '</strong></p></div>';
41
  $error = true;
42
  $siteguard_config->set( self::OPT_NAME_ENABLE, '0' );
43
+ $siteguard_config->update();
44
  }
45
  }
46
  if ( ( false === $error )
47
  && ( ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_ENABLE ] ) )
48
+ || ( false === $this->is_captcha_switch_value( $_POST[ self::OPT_NAME_LOGIN ] ) )
49
+ || ( false === $this->is_captcha_switch_value( $_POST[ self::OPT_NAME_COMMENT ] ) )
50
+ || ( false === $this->is_captcha_switch_value( $_POST[ self::OPT_NAME_LOSTPASSWORD ] ) )
51
+ || ( false === $this->is_captcha_switch_value( $_POST[ self::OPT_NAME_REGISTUSER ] ) ) ) ) {
52
  echo '<div class="error settings-error"><p><strong>';
53
  esc_html_e( 'ERROR: Invalid input value.', 'siteguard' );
54
  echo '</strong></p></div>';
55
  $error = true;
56
  }
57
  if ( false === $error ) {
58
+ $opt_val_enable = sanitize_text_field( $_POST[ self::OPT_NAME_ENABLE ] );
59
+ $opt_val_login = sanitize_text_field( $_POST[ self::OPT_NAME_LOGIN ] );
60
+ $opt_val_comment = sanitize_text_field( $_POST[ self::OPT_NAME_COMMENT ] );
61
+ $opt_val_lostpassword = sanitize_text_field( $_POST[ self::OPT_NAME_LOSTPASSWORD ] );
62
+ $opt_val_registuser = sanitize_text_field( $_POST[ self::OPT_NAME_REGISTUSER ] );
63
+ $siteguard_config->set( self::OPT_NAME_ENABLE, $opt_val_enable );
64
+ $siteguard_config->set( self::OPT_NAME_LOGIN, $opt_val_login );
65
+ $siteguard_config->set( self::OPT_NAME_COMMENT, $opt_val_comment );
66
+ $siteguard_config->set( self::OPT_NAME_LOSTPASSWORD, $opt_val_lostpassword );
67
+ $siteguard_config->set( self::OPT_NAME_REGISTUSER, $opt_val_registuser );
68
+ $siteguard_config->update();
69
  ?>
70
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
71
  <?php
90
  <th scope="row" colspan="2">
91
  <ul class="siteguard-radios">
92
  <li>
93
+ <input type="radio" name="<?php echo self::OPT_NAME_ENABLE; ?>" id="<?php echo self::OPT_NAME_ENABLE . '_on'; ?>" value="1" <?php checked( $opt_val_enable, '1' ); ?> >
94
+ <label for="<?php echo self::OPT_NAME_ENABLE . '_on'; ?>"><?php esc_html_e( 'ON', 'siteguard' ); ?></label>
95
  </li><li>
96
+ <input type="radio" name="<?php echo self::OPT_NAME_ENABLE; ?>" id="<?php echo self::OPT_NAME_ENABLE . '_off'; ?>" value="0" <?php checked( $opt_val_enable, '0' ); ?> >
97
+ <label for="<?php echo self::OPT_NAME_ENABLE . '_off'; ?>"><?php esc_html_e( 'OFF', 'siteguard' ); ?></label>
98
  </li>
99
  </ul>
100
  <?php
101
+ $error = $siteguard_captcha->check_requirements();
102
  if ( is_wp_error( $error ) ) {
103
  echo '<p class="description">';
104
+ echo esc_html( $error->get_error_message() );
105
  echo '</p>';
106
  }
107
  ?>
109
  </tr><tr>
110
  <th scope="row"><?php esc_html_e( 'Login page', 'siteguard' ); ?></th>
111
  <td>
112
+ <input type="radio" name="<?php echo self::OPT_NAME_LOGIN; ?>" id="<?php echo self::OPT_NAME_LOGIN . '_jp'; ?>" value="1" <?php checked( $opt_val_login, '1' ); ?> >
113
+ <label for="<?php echo self::OPT_NAME_LOGIN . '_jp'; ?>"><?php esc_html_e( 'Hiragana (Japanese)', 'siteguard' ); ?></label>
114
  <br />
115
+ <input type="radio" name="<?php echo self::OPT_NAME_LOGIN; ?>" id="<?php echo self::OPT_NAME_LOGIN . '_en'; ?>" value="2" <?php checked( $opt_val_login, '2' ); ?> >
116
+ <label for="<?php echo self::OPT_NAME_LOGIN . '_en'; ?>"><?php esc_html_e( 'Alphanumeric', 'siteguard' ); ?></label>
117
  <br />
118
+ <input type="radio" name="<?php echo self::OPT_NAME_LOGIN; ?>" id="<?php echo self::OPT_NAME_LOGIN . '_off'; ?>" value="0" <?php checked( $opt_val_login, '0' ); ?> >
119
+ <label for="<?php echo self::OPT_NAME_LOGIN . '_off'; ?>"><?php esc_html_e( 'Disable', 'siteguard' ); ?></label>
120
  </td>
121
  </tr><tr>
122
  <th scope="row"><?php esc_html_e( 'Comment page', 'siteguard' ); ?></th>
123
  <td>
124
+ <input type="radio" name="<?php echo self::OPT_NAME_COMMENT; ?>" id="<?php echo self::OPT_NAME_COMMENT . '_jp'; ?>" value="1" <?php checked( $opt_val_comment, '1' ); ?> >
125
+ <label for="<?php echo self::OPT_NAME_COMMENT . '_jp'; ?>"><?php esc_html_e( 'Hiragana (Japanese)', 'siteguard' ); ?></label>
126
  <br />
127
+ <input type="radio" name="<?php echo self::OPT_NAME_COMMENT; ?>" id="<?php echo self::OPT_NAME_COMMENT . '_en'; ?>" value="2" <?php checked( $opt_val_comment, '2' ); ?> >
128
+ <label for="<?php echo self::OPT_NAME_COMMENT . '_en'; ?>"><?php esc_html_e( 'Alphanumeric', 'siteguard' ); ?></label>
129
  <br />
130
+ <input type="radio" name="<?php echo self::OPT_NAME_COMMENT; ?>" id="<?php echo self::OPT_NAME_COMMENT . '_off'; ?>" value="0" <?php checked( $opt_val_comment, '0' ); ?> >
131
+ <label for="<?php echo self::OPT_NAME_COMMENT . '_off'; ?>"><?php esc_html_e( 'Disable', 'siteguard' ); ?></label>
132
  </td>
133
  </tr><tr>
134
  <th scope="row"><?php esc_html_e( 'Lost password page', 'siteguard' ); ?></th>
135
  <td>
136
+ <input type="radio" name="<?php echo self::OPT_NAME_LOSTPASSWORD; ?>" id="<?php echo self::OPT_NAME_LOSTPASSWORD . '_jp'; ?>" value="1" <?php checked( $opt_val_lostpassword, '1' ); ?> >
137
+ <label for="<?php echo self::OPT_NAME_LOSTPASSWORD . '_jp'; ?>"><?php esc_html_e( 'Hiragana (Japanese)', 'siteguard' ); ?></label>
138
  <br />
139
+ <input type="radio" name="<?php echo self::OPT_NAME_LOSTPASSWORD; ?>" id="<?php echo self::OPT_NAME_LOSTPASSWORD . '_en'; ?>" value="2" <?php checked( $opt_val_lostpassword, '2' ); ?> >
140
+ <label for="<?php echo self::OPT_NAME_LOSTPASSWORD . '_en'; ?>"><?php esc_html_e( 'Alphanumeric', 'siteguard' ); ?></label>
141
  <br />
142
+ <input type="radio" name="<?php echo self::OPT_NAME_LOSTPASSWORD; ?>" id="<?php echo self::OPT_NAME_LOSTPASSWORD . '_off'; ?>" value="0" <?php checked( $opt_val_lostpassword, '0' ); ?> >
143
+ <label for="<?php echo self::OPT_NAME_LOSTPASSWORD . '_off'; ?>"><?php esc_html_e( 'Disable', 'siteguard' ); ?></label>
144
  </td>
145
  </tr><tr>
146
  <th scope="row"><?php esc_html_e( 'Registration user page', 'siteguard' ); ?></th>
147
  <td>
148
+ <input type="radio" name="<?php echo self::OPT_NAME_REGISTUSER; ?>" id="<?php echo self::OPT_NAME_REGISTUSER . '_jp'; ?>" value="1" <?php checked( $opt_val_registuser, '1' ); ?> >
149
+ <label for="<?php echo self::OPT_NAME_REGISTUSER . '_jp'; ?>"><?php esc_html_e( 'Hiragana (Japanese)', 'siteguard' ); ?></label>
150
  <br />
151
+ <input type="radio" name="<?php echo self::OPT_NAME_REGISTUSER; ?>" id="<?php echo self::OPT_NAME_REGISTUSER . '_en'; ?>" value="2" <?php checked( $opt_val_registuser, '2' ); ?> >
152
+ <label for="<?php echo self::OPT_NAME_REGISTUSER . '_en'; ?>"><?php esc_html_e( 'Alphanumeric', 'siteguard' ); ?></label>
153
  <br />
154
+ <input type="radio" name="<?php echo self::OPT_NAME_REGISTUSER; ?>" id="<?php echo self::OPT_NAME_REGISTUSER . '_off'; ?>" value="0" <?php checked( $opt_val_registuser, '0' ); ?> >
155
+ <label for="<?php echo self::OPT_NAME_REGISTUSER . '_off'; ?>"><?php esc_html_e( 'Disable', 'siteguard' ); ?></label>
156
  </td>
157
  </tr>
158
  </table>
159
  <div class="siteguard-description">
160
+ <?php esc_html_e( 'It is the function to decrease the vulnerability against an illegal login attempt attack such as a brute force attack or a password list attack, or to receive less comment spam. For the character of CAPTCHA, hiragana and alphanumeric characters can be selected.', 'siteguard' ); ?>
161
  </div>
162
  <input type="hidden" name="update" value="Y">
163
  <hr />
admin/siteguard-menu-dashboard.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Dashboard extends SiteGuard_Base {
4
- function __construct( ) {
5
- $this->render_page( );
6
  }
7
- function render_page( ) {
8
  global $siteguard_config, $siteguard_login_history;
9
- $img_path = SITEGUARD_URL_PATH . 'images/';
10
  $admin_filter_enable = $siteguard_config->get( 'admin_filter_enable' );
11
  $renamelogin_enable = $siteguard_config->get( 'renamelogin_enable' );
12
  $captcha_enable = $siteguard_config->get( 'captcha_enable' );
@@ -26,73 +26,73 @@ class SiteGuard_Menu_Dashboard extends SiteGuard_Base {
26
  . esc_html__( 'You can find docs, FAQ and more detailed information about SiteGuard WP Plugin on ', 'siteguard' )
27
  . '<a href="' . esc_url( __( 'https://www.jp-secure.com/siteguard_wp_plugin_en/', 'siteguard' ) ) . '" target="_blank">' . esc_html__( 'SiteGuard WP Plugin Page', 'siteguard' ) . '</a>' . esc_html__( '.', 'siteguard' ) . '</div>';
28
  echo '<h3>' . esc_html__( 'Setting status', 'siteguard' ) . "</h3>\n";
29
- $error = siteguard_check_multisite( );
30
  if ( is_wp_error( $error ) ) {
31
  echo '<p class="description">';
32
- echo $error->get_error_message( );
33
  echo '</p>';
34
  }
35
  ?>
36
  <table class="siteguard-form-table">
37
  <tr>
38
  <th scope="row">
39
- <img src=<?php echo '"' . $img_path . ( '1' == $admin_filter_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
40
- <a href="?page=siteguard_admin_filter"><?php esc_html_e( 'Admin Page IP Filter', 'siteguard' ) ?></a></th>
41
- <td><?php esc_html_e( 'The management directory (/wp-admin/) is protected against the connection source which does not login.', 'siteguard' ) ?></td>
42
  </tr><tr>
43
  <th scope="row">
44
- <img src=<?php echo '"' . $img_path . ( '1' == $renamelogin_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
45
- <a href="?page=siteguard_rename_login"><?php esc_html_e( 'Rename Login', 'siteguard' ) ?></a></th>
46
- <td><?php esc_html_e( 'The login page name is changed.', 'siteguard' ) ?></td>
47
  </tr><tr>
48
  <th scope="row">
49
- <img src=<?php echo '"' . $img_path . ( '1' == $captcha_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
50
- <a href="?page=siteguard_captcha"><?php esc_html_e( 'CAPTCHA', 'siteguard' ) ?></a></th>
51
- <td><?php esc_html_e( 'CAPTCHA is added to the login page or comment post.', 'siteguard' ) ?></td>
52
  </tr><tr>
53
  <th scope="row">
54
- <img src=<?php echo '"' . $img_path . ( '1' == $same_error_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
55
- <a href="?page=siteguard_same_error"><?php esc_html_e( 'Same Login Error Message', 'siteguard' ) ?></a></th>
56
- <td><?php esc_html_e( 'Instead of the detailed error message at the login error, the single message is returned.', 'siteguard' ) ?></td>
57
  </tr><tr>
58
  <th scope="row">
59
- <img src=<?php echo '"' . $img_path . ( '1' == $loginlock_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
60
- <a href="?page=siteguard_login_lock"><?php esc_html_e( 'Login Lock', 'siteguard' ) ?></a></th>
61
- <td><?php esc_html_e( 'The connection source which repeats login failure is being locked within a certain period.', 'siteguard' ) ?></td>
62
  </tr><tr>
63
  <th scope="row">
64
- <img src=<?php echo '"' . $img_path . ( '1' == $loginalert_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
65
- <a href="?page=siteguard_login_alert"><?php esc_html_e( 'Login Alert', 'siteguard' ) ?></a></th>
66
- <td><?php esc_html_e( 'E-mail notifies that there was login.', 'siteguard' ) ?></td>
67
  </tr><tr>
68
  <th scope="row">
69
- <img src=<?php echo '"' . $img_path . ( '1' == $fail_once_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
70
- <a href="?page=siteguard_fail_once"><?php esc_html_e( 'Fail once', 'siteguard' ) ?></a></th>
71
- <td><?php esc_html_e( 'The first login must fail even if the input is correct.', 'siteguard' ) ?></td>
72
  </tr><tr>
73
  <th scope="row">
74
- <img src=<?php echo '"' . $img_path . ( '1' == $disable_pingback_enable || '1' == $disable_xmlrpc_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
75
- <a href="?page=siteguard_protect_xmlrpc"><?php esc_html_e( 'Protect XMLRPC', 'siteguard' ) ?></a></th>
76
- <td><?php esc_html_e( 'The abuse of XMLRPC is prevented.', 'siteguard' ) ?></td>
77
  </tr><tr>
78
  <th scope="row">
79
- <img src=<?php echo '"' . $img_path . ( '1' == $block_author_query_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
80
- <a href="?page=siteguard_author_query"><?php esc_html_e( 'Block Author Query', 'siteguard' ) ?></a></th>
81
- <td><?php esc_html_e( 'Block author query.', 'siteguard' ) ?></td>
82
  </tr><tr>
83
  <th scope="row">
84
- <img src=<?php echo '"' . $img_path . ( '1' == $updates_notify_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
85
- <a href="?page=siteguard_updates_notify"><?php esc_html_e( 'Updates Notify', 'siteguard' ) ?></a></th>
86
- <td><?php esc_html_e( 'If WordPress core, plugins, and themes updates are needed , sends email to notify administrators.', 'siteguard' ) ?></td>
87
  </tr><tr>
88
  <th scope="row">
89
- <img src=<?php echo '"' . $img_path . ( '1' == $waf_exclude_rule_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ) ?>>
90
- <a href="?page=siteguard_waf_tuning_support"><?php esc_html_e( 'WAF Tuning Support', 'siteguard' ) ?></a></th>
91
- <td><?php esc_html_e( 'The exclude rule for WAF (SiteGuard Lite) is created.', 'siteguard' ) ?></td>
92
  </tr><tr>
93
  <th scope="row">
94
- <a href="?page=siteguard_login_history"><?php echo esc_html__( 'Login history', 'siteguard' ) ?></a>
95
- <td><?php esc_html_e( 'Login history can be referenced.', 'siteguard' ) ?></td>
96
  </tr>
97
  </table>
98
  <hr />
1
  <?php
2
 
3
  class SiteGuard_Menu_Dashboard extends SiteGuard_Base {
4
+ function __construct() {
5
+ $this->render_page();
6
  }
7
+ function render_page() {
8
  global $siteguard_config, $siteguard_login_history;
9
+ $img_path = SITEGUARD_URL_PATH . 'images/';
10
  $admin_filter_enable = $siteguard_config->get( 'admin_filter_enable' );
11
  $renamelogin_enable = $siteguard_config->get( 'renamelogin_enable' );
12
  $captcha_enable = $siteguard_config->get( 'captcha_enable' );
26
  . esc_html__( 'You can find docs, FAQ and more detailed information about SiteGuard WP Plugin on ', 'siteguard' )
27
  . '<a href="' . esc_url( __( 'https://www.jp-secure.com/siteguard_wp_plugin_en/', 'siteguard' ) ) . '" target="_blank">' . esc_html__( 'SiteGuard WP Plugin Page', 'siteguard' ) . '</a>' . esc_html__( '.', 'siteguard' ) . '</div>';
28
  echo '<h3>' . esc_html__( 'Setting status', 'siteguard' ) . "</h3>\n";
29
+ $error = siteguard_check_multisite();
30
  if ( is_wp_error( $error ) ) {
31
  echo '<p class="description">';
32
+ echo esc_html( $error->get_error_message() );
33
  echo '</p>';
34
  }
35
  ?>
36
  <table class="siteguard-form-table">
37
  <tr>
38
  <th scope="row">
39
+ <img src=<?php echo '"' . $img_path . ( '1' == $admin_filter_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
40
+ <a href="?page=siteguard_admin_filter"><?php esc_html_e( 'Admin Page IP Filter', 'siteguard' ); ?></a></th>
41
+ <td><?php esc_html_e( 'The management directory (/wp-admin/) is protected against the connection source which does not login.', 'siteguard' ); ?></td>
42
  </tr><tr>
43
  <th scope="row">
44
+ <img src=<?php echo '"' . $img_path . ( '1' == $renamelogin_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
45
+ <a href="?page=siteguard_rename_login"><?php esc_html_e( 'Rename Login', 'siteguard' ); ?></a></th>
46
+ <td><?php esc_html_e( 'The login page name is changed.', 'siteguard' ); ?></td>
47
  </tr><tr>
48
  <th scope="row">
49
+ <img src=<?php echo '"' . $img_path . ( '1' == $captcha_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
50
+ <a href="?page=siteguard_captcha"><?php esc_html_e( 'CAPTCHA', 'siteguard' ); ?></a></th>
51
+ <td><?php esc_html_e( 'CAPTCHA is added to the login page or comment post.', 'siteguard' ); ?></td>
52
  </tr><tr>
53
  <th scope="row">
54
+ <img src=<?php echo '"' . $img_path . ( '1' == $same_error_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
55
+ <a href="?page=siteguard_same_error"><?php esc_html_e( 'Same Login Error Message', 'siteguard' ); ?></a></th>
56
+ <td><?php esc_html_e( 'Instead of the detailed error message at the login error, the single message is returned.', 'siteguard' ); ?></td>
57
  </tr><tr>
58
  <th scope="row">
59
+ <img src=<?php echo '"' . $img_path . ( '1' == $loginlock_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
60
+ <a href="?page=siteguard_login_lock"><?php esc_html_e( 'Login Lock', 'siteguard' ); ?></a></th>
61
+ <td><?php esc_html_e( 'The connection source which repeats login failure is being locked within a certain period.', 'siteguard' ); ?></td>
62
  </tr><tr>
63
  <th scope="row">
64
+ <img src=<?php echo '"' . $img_path . ( '1' == $loginalert_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
65
+ <a href="?page=siteguard_login_alert"><?php esc_html_e( 'Login Alert', 'siteguard' ); ?></a></th>
66
+ <td><?php esc_html_e( 'E-mail notifies that there was login.', 'siteguard' ); ?></td>
67
  </tr><tr>
68
  <th scope="row">
69
+ <img src=<?php echo '"' . $img_path . ( '1' == $fail_once_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
70
+ <a href="?page=siteguard_fail_once"><?php esc_html_e( 'Fail once', 'siteguard' ); ?></a></th>
71
+ <td><?php esc_html_e( 'The first login must fail even if the input is correct.', 'siteguard' ); ?></td>
72
  </tr><tr>
73
  <th scope="row">
74
+ <img src=<?php echo '"' . $img_path . ( '1' == $disable_pingback_enable || '1' == $disable_xmlrpc_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
75
+ <a href="?page=siteguard_protect_xmlrpc"><?php esc_html_e( 'Protect XMLRPC', 'siteguard' ); ?></a></th>
76
+ <td><?php esc_html_e( 'The abuse of XMLRPC is prevented.', 'siteguard' ); ?></td>
77
  </tr><tr>
78
  <th scope="row">
79
+ <img src=<?php echo '"' . $img_path . ( '1' == $block_author_query_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
80
+ <a href="?page=siteguard_author_query"><?php esc_html_e( 'Block Author Query', 'siteguard' ); ?></a></th>
81
+ <td><?php esc_html_e( 'Block author query.', 'siteguard' ); ?></td>
82
  </tr><tr>
83
  <th scope="row">
84
+ <img src=<?php echo '"' . $img_path . ( '1' == $updates_notify_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
85
+ <a href="?page=siteguard_updates_notify"><?php esc_html_e( 'Updates Notify', 'siteguard' ); ?></a></th>
86
+ <td><?php esc_html_e( 'If WordPress core, plugins, and themes updates are needed , sends email to notify administrators.', 'siteguard' ); ?></td>
87
  </tr><tr>
88
  <th scope="row">
89
+ <img src=<?php echo '"' . $img_path . ( '1' == $waf_exclude_rule_enable ? 'yes.png" alt="yes"' : 'yes_glay.png" alt="no"' ); ?>>
90
+ <a href="?page=siteguard_waf_tuning_support"><?php esc_html_e( 'WAF Tuning Support', 'siteguard' ); ?></a></th>
91
+ <td><?php esc_html_e( 'The exclude rule for WAF (SiteGuard Lite) is created.', 'siteguard' ); ?></td>
92
  </tr><tr>
93
  <th scope="row">
94
+ <a href="?page=siteguard_login_history"><?php echo esc_html__( 'Login history', 'siteguard' ); ?></a>
95
+ <td><?php esc_html_e( 'Login history can be referenced.', 'siteguard' ); ?></td>
96
  </tr>
97
  </table>
98
  <hr />
admin/siteguard-menu-fail-once.php CHANGED
@@ -1,23 +1,23 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Fail_Once extends SiteGuard_Base {
4
- const OPT_NAME_FAIL_ONCE = 'loginlock_fail_once';
5
- const OPT_NAME_ADMIN_ONLY = 'fail_once_admin_only';
6
 
7
- function __construct( ) {
8
- $this->render_page( );
9
  }
10
- function render_page( ) {
11
  global $siteguard_config;
12
 
13
  $opt_val_fail_once = $siteguard_config->get( self::OPT_NAME_FAIL_ONCE );
14
  $opt_val_admin_only = $siteguard_config->get( self::OPT_NAME_ADMIN_ONLY );
15
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-fail-once-submit' ) ) {
16
- $error = false;
17
- $errors = siteguard_check_multisite( );
18
  if ( is_wp_error( $errors ) ) {
19
  echo '<div class="error settings-error"><p><strong>';
20
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
21
  echo '</strong></p></div>';
22
  $error = true;
23
  }
@@ -28,15 +28,15 @@ class SiteGuard_Menu_Fail_Once extends SiteGuard_Base {
28
  $error = true;
29
  }
30
  if ( false === $error ) {
31
- $opt_val_fail_once = $_POST[ self::OPT_NAME_FAIL_ONCE ];
32
  if ( isset( $_POST[ self::OPT_NAME_ADMIN_ONLY ] ) ) {
33
- $opt_val_admin_only = $_POST[ self::OPT_NAME_ADMIN_ONLY ];
34
  } else {
35
  $opt_val_admin_only = '0';
36
  }
37
- $siteguard_config->set( self::OPT_NAME_FAIL_ONCE, $opt_val_fail_once );
38
  $siteguard_config->set( self::OPT_NAME_ADMIN_ONLY, $opt_val_admin_only );
39
- $siteguard_config->update( );
40
  ?>
41
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
42
  <?php
@@ -61,28 +61,28 @@ class SiteGuard_Menu_Fail_Once extends SiteGuard_Base {
61
  <th scope="row" colspan="2">
62
  <ul class="siteguard-radios">
63
  <li>
64
- <input type="radio" name="<?php echo self::OPT_NAME_FAIL_ONCE ?>" id="<?php echo self::OPT_NAME_FAIL_ONCE.'_on' ?>" value="1" <?php checked( $opt_val_fail_once, '1' ) ?> >
65
- <label for="<?php echo self::OPT_NAME_FAIL_ONCE.'_on' ?>"><?php esc_html_e( 'ON', 'siteguard' ) ?></label>
66
  </li><li>
67
- <input type="radio" name="<?php echo self::OPT_NAME_FAIL_ONCE ?>" id="<?php echo self::OPT_NAME_FAIL_ONCE.'_off' ?>" value="0" <?php checked( $opt_val_fail_once, '0' ) ?> >
68
- <label for="<?php echo self::OPT_NAME_FAIL_ONCE.'_off' ?>"><?php esc_html_e( 'OFF', 'siteguard' ) ?></label>
69
  </li>
70
  </ul>
71
  <?php
72
- $error = siteguard_check_multisite( );
73
  if ( is_wp_error( $error ) ) {
74
  echo '<p class="description">';
75
- echo $error->get_error_message( );
76
  echo '</p>';
77
  }
78
  ?>
79
  </th>
80
  <td>
81
  </tr><tr>
82
- <th scope="row"><?php esc_html_e( 'Target user', 'siteguard' ) ?></th>
83
  <td>
84
- <input type="checkbox" name="<?php echo self::OPT_NAME_ADMIN_ONLY ?>" id="<?php echo self::OPT_NAME_ADMIN_ONLY ?>" value="1" <?php checked( $opt_val_admin_only, '1' ) ?> >
85
- <label for="<?php echo self::OPT_NAME_ADMIN_ONLY ?>"><?php esc_html_e( 'Admin only', 'siteguard' ) ?></label>
86
  </td>
87
  </tr>
88
  </table>
@@ -94,7 +94,7 @@ class SiteGuard_Menu_Fail_Once extends SiteGuard_Base {
94
 
95
  <?php
96
  wp_nonce_field( 'siteguard-menu-fail-once-submit' );
97
- submit_button( );
98
  ?>
99
 
100
  </form>
1
  <?php
2
 
3
  class SiteGuard_Menu_Fail_Once extends SiteGuard_Base {
4
+ const OPT_NAME_FAIL_ONCE = 'loginlock_fail_once';
5
+ const OPT_NAME_ADMIN_ONLY = 'fail_once_admin_only';
6
 
7
+ function __construct() {
8
+ $this->render_page();
9
  }
10
+ function render_page() {
11
  global $siteguard_config;
12
 
13
  $opt_val_fail_once = $siteguard_config->get( self::OPT_NAME_FAIL_ONCE );
14
  $opt_val_admin_only = $siteguard_config->get( self::OPT_NAME_ADMIN_ONLY );
15
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-fail-once-submit' ) ) {
16
+ $error = false;
17
+ $errors = siteguard_check_multisite();
18
  if ( is_wp_error( $errors ) ) {
19
  echo '<div class="error settings-error"><p><strong>';
20
+ echo esc_html( $errors->get_error_message() );
21
  echo '</strong></p></div>';
22
  $error = true;
23
  }
28
  $error = true;
29
  }
30
  if ( false === $error ) {
31
+ $opt_val_fail_once = sanitize_text_field( $_POST[ self::OPT_NAME_FAIL_ONCE ] );
32
  if ( isset( $_POST[ self::OPT_NAME_ADMIN_ONLY ] ) ) {
33
+ $opt_val_admin_only = '1';
34
  } else {
35
  $opt_val_admin_only = '0';
36
  }
37
+ $siteguard_config->set( self::OPT_NAME_FAIL_ONCE, $opt_val_fail_once );
38
  $siteguard_config->set( self::OPT_NAME_ADMIN_ONLY, $opt_val_admin_only );
39
+ $siteguard_config->update();
40
  ?>
41
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
42
  <?php
61
  <th scope="row" colspan="2">
62
  <ul class="siteguard-radios">
63
  <li>
64
+ <input type="radio" name="<?php echo self::OPT_NAME_FAIL_ONCE; ?>" id="<?php echo self::OPT_NAME_FAIL_ONCE . '_on'; ?>" value="1" <?php checked( $opt_val_fail_once, '1' ); ?> >
65
+ <label for="<?php echo self::OPT_NAME_FAIL_ONCE . '_on'; ?>"><?php esc_html_e( 'ON', 'siteguard' ); ?></label>
66
  </li><li>
67
+ <input type="radio" name="<?php echo self::OPT_NAME_FAIL_ONCE; ?>" id="<?php echo self::OPT_NAME_FAIL_ONCE . '_off'; ?>" value="0" <?php checked( $opt_val_fail_once, '0' ); ?> >
68
+ <label for="<?php echo self::OPT_NAME_FAIL_ONCE . '_off'; ?>"><?php esc_html_e( 'OFF', 'siteguard' ); ?></label>
69
  </li>
70
  </ul>
71
  <?php
72
+ $error = siteguard_check_multisite();
73
  if ( is_wp_error( $error ) ) {
74
  echo '<p class="description">';
75
+ echo esc_html( $error->get_error_message() );
76
  echo '</p>';
77
  }
78
  ?>
79
  </th>
80
  <td>
81
  </tr><tr>
82
+ <th scope="row"><?php esc_html_e( 'Target user', 'siteguard' ); ?></th>
83
  <td>
84
+ <input type="checkbox" name="<?php echo self::OPT_NAME_ADMIN_ONLY; ?>" id="<?php echo self::OPT_NAME_ADMIN_ONLY; ?>" value="1" <?php checked( $opt_val_admin_only, '1' ); ?> >
85
+ <label for="<?php echo self::OPT_NAME_ADMIN_ONLY; ?>"><?php esc_html_e( 'Admin only', 'siteguard' ); ?></label>
86
  </td>
87
  </tr>
88
  </table>
94
 
95
  <?php
96
  wp_nonce_field( 'siteguard-menu-fail-once-submit' );
97
+ submit_button();
98
  ?>
99
 
100
  </form>
admin/siteguard-menu-init.php CHANGED
@@ -1,119 +1,197 @@
1
  <?php
2
  class SiteGuard_Menu_INIT extends SiteGuard_Base {
3
- function __construct( ) {
4
  add_action( 'admin_menu', array( &$this, 'add_pages' ) );
5
  }
6
- function menu_styles( ) {
7
  wp_enqueue_style( 'siteguard-menu', SITEGUARD_URL_PATH . 'css/siteguard-menu.css' );
8
  }
9
- function add_pages( ) {
10
  $icon_path = SITEGUARD_URL_PATH . 'images/plugin-icon.png';
11
- $page = add_menu_page( esc_html__( 'SiteGuard', 'siteguard' ), esc_html__( 'SiteGuard', 'siteguard' ), 'manage_options', 'siteguard', array( $this, 'menu_dashboard' ), $icon_path );
12
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
13
 
14
- $page = add_submenu_page( 'siteguard', esc_html__( 'Dashboard', 'siteguard' ),
15
- esc_html__( 'Dashboard', 'siteguard' ) , 'manage_options', 'siteguard', array( $this, 'menu_dashboard' ) );
 
 
 
 
 
 
16
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
17
 
18
- $page = add_submenu_page( 'siteguard', esc_html__( 'Admin Page IP Filter', 'siteguard' ),
19
- esc_html__( 'Admin Page IP Filter', 'siteguard' ), 'manage_options', 'siteguard_admin_filter', array( $this, 'menu_admin_filter' ) );
 
 
 
 
 
 
20
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
21
 
22
- $page = add_submenu_page( 'siteguard', esc_html__( 'Rename Login', 'siteguard' ),
23
- esc_html__( 'Rename Login', 'siteguard' ), 'manage_options', 'siteguard_rename_login', array( $this, 'menu_rename_login' ) );
 
 
 
 
 
 
24
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
25
 
26
- $page = add_submenu_page( 'siteguard', esc_html__( 'CAPTCHA', 'siteguard' ),
27
- esc_html__( 'CAPTCHA', 'siteguard' ), 'manage_options', 'siteguard_captcha', array( $this, 'menu_captcha' ) );
 
 
 
 
 
 
28
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
29
 
30
- $page = add_submenu_page( 'siteguard', esc_html__( 'Same Login Error Message', 'siteguard' ),
31
- esc_html__( 'Same Login Error Message', 'siteguard' ), 'manage_options', 'siteguard_same_error', array( $this, 'menu_same_error' ) );
 
 
 
 
 
 
32
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
33
 
34
- $page = add_submenu_page( 'siteguard', esc_html__( 'Login Lock', 'siteguard' ),
35
- esc_html__( 'Login Lock', 'siteguard' ), 'manage_options', 'siteguard_login_lock', array( $this, 'menu_login_lock' ) );
 
 
 
 
 
 
36
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
37
 
38
- $page = add_submenu_page( 'siteguard', esc_html__( 'Login Alert', 'siteguard' ),
39
- esc_html__( 'Login Alert', 'siteguard' ), 'manage_options', 'siteguard_login_alert', array( $this, 'menu_login_alert' ) );
 
 
 
 
 
 
40
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
41
 
42
- $page = add_submenu_page( 'siteguard', esc_html__( 'Fail once', 'siteguard' ),
43
- esc_html__( 'Fail once', 'siteguard' ), 'manage_options', 'siteguard_fail_once', array( $this, 'menu_fail_once' ) );
 
 
 
 
 
 
44
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
45
 
46
- $page = add_submenu_page( 'siteguard', esc_html__( 'Protect XMLRPC', 'siteguard' ),
47
- esc_html__( 'Protect XMLRPC', 'siteguard' ), 'manage_options', 'siteguard_protect_xmlrpc', array( $this, 'menu_protect_xmlrpc' ) );
 
 
 
 
 
 
48
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
49
 
50
- $page = add_submenu_page( 'siteguard', esc_html__( 'Block Author Query', 'siteguard' ),
51
- esc_html__( 'Block Author Query', 'siteguard' ), 'manage_options', 'siteguard_author_query', array( $this, 'menu_block_author_query' ) );
 
 
 
 
 
 
52
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
53
 
54
- $page = add_submenu_page( 'siteguard', esc_html__( 'Updates Notify', 'siteguard' ),
55
- esc_html__( 'Updates Notify', 'siteguard' ), 'manage_options', 'siteguard_updates_notify', array( $this, 'menu_updates_notify' ) );
 
 
 
 
 
 
56
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
57
 
58
- $page = add_submenu_page( 'siteguard', esc_html__( 'WAF Tuning Support', 'siteguard' ),
59
- esc_html__( 'WAF Tuning Support', 'siteguard' ), 'manage_options', 'siteguard_waf_tuning_support', array( $this, 'menu_waf_tuning_support' ) );
 
 
 
 
 
 
60
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
61
 
62
- $page = add_submenu_page( 'siteguard', esc_html__( 'Login history', 'siteguard' ),
63
- esc_html__( 'Login history', 'siteguard' ), 'manage_options', 'siteguard_login_history', array( $this, 'menu_login_history' ) );
 
 
 
 
 
 
64
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
65
  }
66
 
67
- function menu_dashboard( ) {
68
- include( 'siteguard-menu-dashboard.php' );
69
- $dashboard_menu = new SiteGuard_Menu_Dashboard( );
70
  }
71
- function menu_login_history( ) {
72
  // include( 'siteguard-menu-login-history.php' ); -- already included SiteGuard::__construct --
73
- $login_history_menu = new SiteGuard_Menu_Login_History( );
74
  }
75
- function menu_admin_filter( ) {
76
- include( 'siteguard-menu-admin-filter.php' );
77
- $admin_filter_menu = new SiteGuard_Menu_Admin_Filter( );
78
  }
79
- function menu_rename_login( ) {
80
- include( 'siteguard-menu-rename-login.php' );
81
- $rename_login_menu = new SiteGuard_Menu_Rename_Login( );
82
  }
83
- function menu_captcha( ) {
84
- include( 'siteguard-menu-captcha.php' );
85
- $captcha_menu = new SiteGuard_Menu_CAPTCHA( );
86
  }
87
- function menu_same_error( ) {
88
- include( 'siteguard-menu-same-error.php' );
89
- $same_error_menu = new SiteGuard_Menu_Same_Error( );
90
  }
91
- function menu_login_lock( ) {
92
- include( 'siteguard-menu-login-lock.php' );
93
- $login_lock_menu = new SiteGuard_Menu_Login_Lock( );
94
  }
95
- function menu_login_alert( ) {
96
- include( 'siteguard-menu-login-alert.php' );
97
- $login_alert_menu = new SiteGuard_Menu_Login_Alert( );
98
  }
99
- function menu_fail_once( ) {
100
- include( 'siteguard-menu-fail-once.php' );
101
- $fail_once_menu = new SiteGuard_Menu_Fail_Once( );
102
  }
103
- function menu_protect_xmlrpc( ) {
104
- include( 'siteguard-menu-protect-xmlrpc.php' );
105
- $protect_xmlrpc_menu = new SiteGuard_Menu_Protect_XMLRPC( );
106
  }
107
- function menu_block_author_query( ) {
108
- include( 'siteguard-menu-author-query.php' );
109
- $block_author_query = new SiteGuard_Menu_Author_Query( );
110
  }
111
- function menu_updates_notify( ) {
112
- include( 'siteguard-menu-updates-notify.php' );
113
- $waf_updates_notify_menu = new SiteGuard_Menu_Updates_Notify( );
114
  }
115
- function menu_waf_tuning_support( ) {
116
- include( 'siteguard-menu-waf-tuning-support.php' );
117
- $waf_tuning_support_menu = new SiteGuard_Menu_WAF_Tuning_Support( );
118
  }
119
  }
1
  <?php
2
  class SiteGuard_Menu_INIT extends SiteGuard_Base {
3
+ function __construct() {
4
  add_action( 'admin_menu', array( &$this, 'add_pages' ) );
5
  }
6
+ function menu_styles() {
7
  wp_enqueue_style( 'siteguard-menu', SITEGUARD_URL_PATH . 'css/siteguard-menu.css' );
8
  }
9
+ function add_pages() {
10
  $icon_path = SITEGUARD_URL_PATH . 'images/plugin-icon.png';
11
+ $page = add_menu_page( esc_html__( 'SiteGuard', 'siteguard' ), esc_html__( 'SiteGuard', 'siteguard' ), 'manage_options', 'siteguard', array( $this, 'menu_dashboard' ), $icon_path );
12
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
13
 
14
+ $page = add_submenu_page(
15
+ 'siteguard',
16
+ esc_html__( 'Dashboard', 'siteguard' ),
17
+ esc_html__( 'Dashboard', 'siteguard' ),
18
+ 'manage_options',
19
+ 'siteguard',
20
+ array( $this, 'menu_dashboard' )
21
+ );
22
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
23
 
24
+ $page = add_submenu_page(
25
+ 'siteguard',
26
+ esc_html__( 'Admin Page IP Filter', 'siteguard' ),
27
+ esc_html__( 'Admin Page IP Filter', 'siteguard' ),
28
+ 'manage_options',
29
+ 'siteguard_admin_filter',
30
+ array( $this, 'menu_admin_filter' )
31
+ );
32
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
33
 
34
+ $page = add_submenu_page(
35
+ 'siteguard',
36
+ esc_html__( 'Rename Login', 'siteguard' ),
37
+ esc_html__( 'Rename Login', 'siteguard' ),
38
+ 'manage_options',
39
+ 'siteguard_rename_login',
40
+ array( $this, 'menu_rename_login' )
41
+ );
42
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
43
 
44
+ $page = add_submenu_page(
45
+ 'siteguard',
46
+ esc_html__( 'CAPTCHA', 'siteguard' ),
47
+ esc_html__( 'CAPTCHA', 'siteguard' ),
48
+ 'manage_options',
49
+ 'siteguard_captcha',
50
+ array( $this, 'menu_captcha' )
51
+ );
52
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
53
 
54
+ $page = add_submenu_page(
55
+ 'siteguard',
56
+ esc_html__( 'Same Login Error Message', 'siteguard' ),
57
+ esc_html__( 'Same Login Error Message', 'siteguard' ),
58
+ 'manage_options',
59
+ 'siteguard_same_error',
60
+ array( $this, 'menu_same_error' )
61
+ );
62
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
63
 
64
+ $page = add_submenu_page(
65
+ 'siteguard',
66
+ esc_html__( 'Login Lock', 'siteguard' ),
67
+ esc_html__( 'Login Lock', 'siteguard' ),
68
+ 'manage_options',
69
+ 'siteguard_login_lock',
70
+ array( $this, 'menu_login_lock' )
71
+ );
72
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
73
 
74
+ $page = add_submenu_page(
75
+ 'siteguard',
76
+ esc_html__( 'Login Alert', 'siteguard' ),
77
+ esc_html__( 'Login Alert', 'siteguard' ),
78
+ 'manage_options',
79
+ 'siteguard_login_alert',
80
+ array( $this, 'menu_login_alert' )
81
+ );
82
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
83
 
84
+ $page = add_submenu_page(
85
+ 'siteguard',
86
+ esc_html__( 'Fail once', 'siteguard' ),
87
+ esc_html__( 'Fail once', 'siteguard' ),
88
+ 'manage_options',
89
+ 'siteguard_fail_once',
90
+ array( $this, 'menu_fail_once' )
91
+ );
92
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
93
 
94
+ $page = add_submenu_page(
95
+ 'siteguard',
96
+ esc_html__( 'Protect XMLRPC', 'siteguard' ),
97
+ esc_html__( 'Protect XMLRPC', 'siteguard' ),
98
+ 'manage_options',
99
+ 'siteguard_protect_xmlrpc',
100
+ array( $this, 'menu_protect_xmlrpc' )
101
+ );
102
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
103
 
104
+ $page = add_submenu_page(
105
+ 'siteguard',
106
+ esc_html__( 'Block Author Query', 'siteguard' ),
107
+ esc_html__( 'Block Author Query', 'siteguard' ),
108
+ 'manage_options',
109
+ 'siteguard_author_query',
110
+ array( $this, 'menu_block_author_query' )
111
+ );
112
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
113
 
114
+ $page = add_submenu_page(
115
+ 'siteguard',
116
+ esc_html__( 'Updates Notify', 'siteguard' ),
117
+ esc_html__( 'Updates Notify', 'siteguard' ),
118
+ 'manage_options',
119
+ 'siteguard_updates_notify',
120
+ array( $this, 'menu_updates_notify' )
121
+ );
122
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
123
 
124
+ $page = add_submenu_page(
125
+ 'siteguard',
126
+ esc_html__( 'WAF Tuning Support', 'siteguard' ),
127
+ esc_html__( 'WAF Tuning Support', 'siteguard' ),
128
+ 'manage_options',
129
+ 'siteguard_waf_tuning_support',
130
+ array( $this, 'menu_waf_tuning_support' )
131
+ );
132
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
133
 
134
+ $page = add_submenu_page(
135
+ 'siteguard',
136
+ esc_html__( 'Login history', 'siteguard' ),
137
+ esc_html__( 'Login history', 'siteguard' ),
138
+ 'manage_options',
139
+ 'siteguard_login_history',
140
+ array( $this, 'menu_login_history' )
141
+ );
142
  add_action( 'admin_print_styles-' . $page, array( $this, 'menu_styles' ) );
143
  }
144
 
145
+ function menu_dashboard() {
146
+ include 'siteguard-menu-dashboard.php';
147
+ $dashboard_menu = new SiteGuard_Menu_Dashboard();
148
  }
149
+ function menu_login_history() {
150
  // include( 'siteguard-menu-login-history.php' ); -- already included SiteGuard::__construct --
151
+ $login_history_menu = new SiteGuard_Menu_Login_History();
152
  }
153
+ function menu_admin_filter() {
154
+ include 'siteguard-menu-admin-filter.php';
155
+ $admin_filter_menu = new SiteGuard_Menu_Admin_Filter();
156
  }
157
+ function menu_rename_login() {
158
+ include 'siteguard-menu-rename-login.php';
159
+ $rename_login_menu = new SiteGuard_Menu_Rename_Login();
160
  }
161
+ function menu_captcha() {
162
+ include 'siteguard-menu-captcha.php';
163
+ $captcha_menu = new SiteGuard_Menu_CAPTCHA();
164
  }
165
+ function menu_same_error() {
166
+ include 'siteguard-menu-same-error.php';
167
+ $same_error_menu = new SiteGuard_Menu_Same_Error();
168
  }
169
+ function menu_login_lock() {
170
+ include 'siteguard-menu-login-lock.php';
171
+ $login_lock_menu = new SiteGuard_Menu_Login_Lock();
172
  }
173
+ function menu_login_alert() {
174
+ include 'siteguard-menu-login-alert.php';
175
+ $login_alert_menu = new SiteGuard_Menu_Login_Alert();
176
  }
177
+ function menu_fail_once() {
178
+ include 'siteguard-menu-fail-once.php';
179
+ $fail_once_menu = new SiteGuard_Menu_Fail_Once();
180
  }
181
+ function menu_protect_xmlrpc() {
182
+ include 'siteguard-menu-protect-xmlrpc.php';
183
+ $protect_xmlrpc_menu = new SiteGuard_Menu_Protect_XMLRPC();
184
  }
185
+ function menu_block_author_query() {
186
+ include 'siteguard-menu-author-query.php';
187
+ $block_author_query = new SiteGuard_Menu_Author_Query();
188
  }
189
+ function menu_updates_notify() {
190
+ include 'siteguard-menu-updates-notify.php';
191
+ $waf_updates_notify_menu = new SiteGuard_Menu_Updates_Notify();
192
  }
193
+ function menu_waf_tuning_support() {
194
+ include 'siteguard-menu-waf-tuning-support.php';
195
+ $waf_tuning_support_menu = new SiteGuard_Menu_WAF_Tuning_Support();
196
  }
197
  }
admin/siteguard-menu-login-alert.php CHANGED
@@ -1,27 +1,27 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Login_Alert extends SiteGuard_Base {
4
- const OPT_NAME_FEATURE = 'loginalert_enable';
5
- const OPT_NAME_SUBJECT = 'loginalert_subject';
6
- const OPT_NAME_BODY = 'loginalert_body';
7
- const OPT_NAME_ADMIN = 'loginalert_admin_only';
8
 
9
- function __construct( ) {
10
- $this->render_page( );
11
  }
12
- function render_page( ) {
13
  global $siteguard_config;
14
 
15
- $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE );
16
- $opt_val_subject = $siteguard_config->get( self::OPT_NAME_SUBJECT );
17
- $opt_val_body = $siteguard_config->get( self::OPT_NAME_BODY );
18
- $opt_val_admin = $siteguard_config->get( self::OPT_NAME_ADMIN );
19
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-login-alert-submit' ) ) {
20
- $error = false;
21
- $errors = siteguard_check_multisite( );
22
  if ( is_wp_error( $errors ) ) {
23
  echo '<div class="error settings-error"><p><strong>';
24
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
25
  echo '</strong></p></div>';
26
  $error = true;
27
  }
@@ -32,19 +32,22 @@ class SiteGuard_Menu_Login_Alert extends SiteGuard_Base {
32
  $error = true;
33
  }
34
  if ( false === $error ) {
35
- $opt_val_feature = $_POST[ self::OPT_NAME_FEATURE ];
36
- $opt_val_subject = $_POST[ self::OPT_NAME_SUBJECT ];
37
- $opt_val_body = $_POST[ self::OPT_NAME_BODY ];
 
 
 
38
  if ( isset( $_POST[ self::OPT_NAME_ADMIN ] ) ) {
39
- $opt_val_admin = $_POST[ self::OPT_NAME_ADMIN ];
40
  } else {
41
  $opt_val_admin = '0';
42
  }
43
- $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
44
- $siteguard_config->set( self::OPT_NAME_SUBJECT, $opt_val_subject );
45
- $siteguard_config->set( self::OPT_NAME_BODY, $opt_val_body );
46
- $siteguard_config->set( self::OPT_NAME_ADMIN, $opt_val_admin );
47
- $siteguard_config->update( );
48
  ?>
49
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
50
  <?php
@@ -69,48 +72,48 @@ class SiteGuard_Menu_Login_Alert extends SiteGuard_Base {
69
  <th scope="row" colspan="2">
70
  <ul class="siteguard-radios">
71
  <li>
72
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE.'_on' ?>" value="1" <?php checked( $opt_val_feature, '1' ) ?> >
73
- <label for="<?php echo self::OPT_NAME_FEATURE.'_on' ?>"><?php echo esc_html_e( 'ON', 'siteguard' ) ?></label>
74
  </li><li>
75
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE.'_off' ?>" value="0" <?php checked( $opt_val_feature, '0' ) ?> >
76
- <label for="<?php echo self::OPT_NAME_FEATURE.'_off' ?>"><?php echo esc_html_e( 'OFF', 'siteguard' ) ?></label>
77
  </li>
78
  </ul>
79
  <?php
80
- $error = siteguard_check_multisite( );
81
  if ( is_wp_error( $error ) ) {
82
  echo '<p class="description">';
83
- echo $error->get_error_message( );
84
  echo '</p>';
85
  }
86
  ?>
87
  </th>
88
  </tr><tr>
89
- <th scope="row"><label for="<?php echo self::OPT_NAME_SUBJECT ?>"><?php esc_html_e( 'Subject', 'siteguard' ); ?></label></th>
90
  <td>
91
- <input type="text" name="<?php echo self::OPT_NAME_SUBJECT ?>" id="<?php echo self::OPT_NAME_SUBJECT ?>" size="50" value="<?php echo esc_attr( $opt_val_subject ) ?>" >
92
  </td>
93
  </tr><tr>
94
- <th scope="row"><label for="<?php echo self::OPT_NAME_BODY ?>"><?php esc_html_e( 'Body', 'siteguard' ); ?></label></th>
95
  <td>
96
- <textarea name="<?php echo self::OPT_NAME_BODY ?>" id="<?php echo self::OPT_NAME_BODY ?>" cols="50" rows="5" ><?php echo esc_textarea( $opt_val_body ) ?></textarea>
97
  </td>
98
  </tr><tr>
99
- <th scope="row"><?php esc_html_e( 'Recipients', 'siteguard' ) ?></th>
100
- <td>
101
- <input type="checkbox" name="<?php echo self::OPT_NAME_ADMIN ?>" id="<?php echo self::OPT_NAME_ADMIN ?>" value="1" <?php checked( $opt_val_admin, '1' ) ?> >
102
- <label for="<?php echo self::OPT_NAME_ADMIN ?>"><?php esc_html_e( 'Admin only', 'siteguard' ) ?></label>
103
- </td>
104
  </tr>
105
  </table>
106
  <input type="hidden" name="update" value="Y">
107
  <div class="siteguard-description">
108
- <?php esc_html_e( 'It is the function to make it easier to notice unauthorized login. E-mail will be sent to a login user when logged in. If you receive an e-mail to there is no logged-in idea, please suspect unauthorized login. The subject and the mail body, the following variables can be used. (Site Name:%SITENAME%, User Name:%USERNAME%, DATE:%DATE%, Time:%TIME%, IP Address:%IPADDRESS%, User-Agent:%USERAGENT%, Referer:%REFERER%) Access by the XML-RPC will not be notified.', 'siteguard' ) ?>
109
  </div>
110
  <hr />
111
  <?php
112
  wp_nonce_field( 'siteguard-menu-login-alert-submit' );
113
- submit_button( );
114
  ?>
115
  </form>
116
  </div>
1
  <?php
2
 
3
  class SiteGuard_Menu_Login_Alert extends SiteGuard_Base {
4
+ const OPT_NAME_FEATURE = 'loginalert_enable';
5
+ const OPT_NAME_SUBJECT = 'loginalert_subject';
6
+ const OPT_NAME_BODY = 'loginalert_body';
7
+ const OPT_NAME_ADMIN = 'loginalert_admin_only';
8
 
9
+ function __construct() {
10
+ $this->render_page();
11
  }
12
+ function render_page() {
13
  global $siteguard_config;
14
 
15
+ $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE );
16
+ $opt_val_subject = $siteguard_config->get( self::OPT_NAME_SUBJECT );
17
+ $opt_val_body = $siteguard_config->get( self::OPT_NAME_BODY );
18
+ $opt_val_admin = $siteguard_config->get( self::OPT_NAME_ADMIN );
19
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-login-alert-submit' ) ) {
20
+ $error = false;
21
+ $errors = siteguard_check_multisite();
22
  if ( is_wp_error( $errors ) ) {
23
  echo '<div class="error settings-error"><p><strong>';
24
+ echo esc_html( $errors->get_error_message() );
25
  echo '</strong></p></div>';
26
  $error = true;
27
  }
32
  $error = true;
33
  }
34
  if ( false === $error ) {
35
+ $opt_val_feature = sanitize_text_field( $_POST[ self::OPT_NAME_FEATURE ] );
36
+ $opt_val_subject = sanitize_text_field( $_POST[ self::OPT_NAME_SUBJECT ] );
37
+ $opt_val_body = $_POST[ self::OPT_NAME_BODY ];
38
+ $opt_val_body = str_replace( '%DA', 'PERCENT_DA', $opt_val_body );
39
+ $opt_val_body = sanitize_textarea_field( $opt_val_body );
40
+ $opt_val_body = str_replace( 'PERCENT_DA', '%DA', $opt_val_body );
41
  if ( isset( $_POST[ self::OPT_NAME_ADMIN ] ) ) {
42
+ $opt_val_admin = '1';
43
  } else {
44
  $opt_val_admin = '0';
45
  }
46
+ $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
47
+ $siteguard_config->set( self::OPT_NAME_SUBJECT, $opt_val_subject );
48
+ $siteguard_config->set( self::OPT_NAME_BODY, $opt_val_body );
49
+ $siteguard_config->set( self::OPT_NAME_ADMIN, $opt_val_admin );
50
+ $siteguard_config->update();
51
  ?>
52
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
53
  <?php
72
  <th scope="row" colspan="2">
73
  <ul class="siteguard-radios">
74
  <li>
75
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>" value="1" <?php checked( $opt_val_feature, '1' ); ?> >
76
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>"><?php echo esc_html_e( 'ON', 'siteguard' ); ?></label>
77
  </li><li>
78
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>" value="0" <?php checked( $opt_val_feature, '0' ); ?> >
79
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>"><?php echo esc_html_e( 'OFF', 'siteguard' ); ?></label>
80
  </li>
81
  </ul>
82
  <?php
83
+ $error = siteguard_check_multisite();
84
  if ( is_wp_error( $error ) ) {
85
  echo '<p class="description">';
86
+ echo esc_html( $error->get_error_message() );
87
  echo '</p>';
88
  }
89
  ?>
90
  </th>
91
  </tr><tr>
92
+ <th scope="row"><label for="<?php echo self::OPT_NAME_SUBJECT; ?>"><?php esc_html_e( 'Subject', 'siteguard' ); ?></label></th>
93
  <td>
94
+ <input type="text" name="<?php echo self::OPT_NAME_SUBJECT; ?>" id="<?php echo self::OPT_NAME_SUBJECT; ?>" size="50" value="<?php echo esc_attr( $opt_val_subject ); ?>" >
95
  </td>
96
  </tr><tr>
97
+ <th scope="row"><label for="<?php echo self::OPT_NAME_BODY; ?>"><?php esc_html_e( 'Body', 'siteguard' ); ?></label></th>
98
  <td>
99
+ <textarea name="<?php echo self::OPT_NAME_BODY; ?>" id="<?php echo self::OPT_NAME_BODY; ?>" cols="50" rows="5" ><?php echo esc_textarea( $opt_val_body ); ?></textarea>
100
  </td>
101
  </tr><tr>
102
+ <th scope="row"><?php esc_html_e( 'Recipients', 'siteguard' ); ?></th>
103
+ <td>
104
+ <input type="checkbox" name="<?php echo self::OPT_NAME_ADMIN; ?>" id="<?php echo self::OPT_NAME_ADMIN; ?>" value="1" <?php checked( $opt_val_admin, '1' ); ?> >
105
+ <label for="<?php echo self::OPT_NAME_ADMIN; ?>"><?php esc_html_e( 'Admin only', 'siteguard' ); ?></label>
106
+ </td>
107
  </tr>
108
  </table>
109
  <input type="hidden" name="update" value="Y">
110
  <div class="siteguard-description">
111
+ <?php esc_html_e( 'It is the function to make it easier to notice unauthorized login. E-mail will be sent to a login user when logged in. If you receive an e-mail to there is no logged-in idea, please suspect unauthorized login. The subject and the mail body, the following variables can be used. (Site Name:%SITENAME%, User Name:%USERNAME%, DATE:%DATE%, Time:%TIME%, IP Address:%IPADDRESS%, User-Agent:%USERAGENT%, Referer:%REFERER%) Access by the XML-RPC will not be notified.', 'siteguard' ); ?>
112
  </div>
113
  <hr />
114
  <?php
115
  wp_nonce_field( 'siteguard-menu-login-alert-submit' );
116
+ submit_button();
117
  ?>
118
  </form>
119
  </div>
admin/siteguard-menu-login-history.php CHANGED
@@ -1,15 +1,15 @@
1
  <?php
2
 
3
- require_once( 'siteguard-login-history-table.php' );
4
 
5
  class SiteGuard_Menu_Login_History extends SiteGuard_Base {
6
  protected $wp_list_table;
7
- function __construct( ) {
8
- $this->wp_list_table = new SiteGuard_LoginHistory_Table( );
9
- $this->wp_list_table->prepare_items( );
10
- $this->render_page( );
11
  }
12
- function render_page( ) {
13
  global $siteguard_config, $siteguard_login_history;
14
  $img_path = SITEGUARD_URL_PATH . 'images/';
15
  echo '<div class="wrap">';
@@ -18,32 +18,32 @@ class SiteGuard_Menu_Login_History extends SiteGuard_Base {
18
  echo '<div class="siteguard-description">'
19
  . esc_html__( 'You can find docs about this function on ', 'siteguard' )
20
  . '<a href="' . esc_url( __( 'https://www.jp-secure.com/siteguard_wp_plugin_en/howto/login_history/', 'siteguard' ) ) . '" target="_blank">' . esc_html__( 'SiteGuard WP Plugin Page', 'siteguard' ) . '</a>' . esc_html__( '.', 'siteguard' ) . '</div>';
21
- $error = siteguard_check_multisite( );
22
  if ( is_wp_error( $error ) ) {
23
  echo '<p class="description">';
24
- echo $error->get_error_message( );
25
  echo '</p>';
26
  }
27
  ?>
28
  <form name="form1" method="post" action="">
29
- <?php $this->wp_list_table->display( ) ?>
30
  <div class="siteguard-description">
31
- <?php esc_html_e( 'Login history can be referenced. Let\'s see if there are any suspicious history. History, registered 10,000 maximum, will be removed from those old and more than 10,000.', 'siteguard' ) ?>
32
  </div>
33
- <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ) ?>">
34
  </form>
35
  </div>
36
  <?php
37
  }
38
- static function clear_cookie( ) {
39
- setcookie( 'siteguard_log_filter_operation', '', time( ) - 1800, '/' );
40
- setcookie( 'siteguard_log_filter_type', '', time( ) - 1800, '/' );
41
- setcookie( 'siteguard_log_filter_login_name', '', time( ) - 1800, '/' );
42
- setcookie( 'siteguard_log_filter_ip_address', '', time( ) - 1800, '/' );
43
- setcookie( 'siteguard_log_filter_login_name_not', '', time( ) - 1800, '/' );
44
- setcookie( 'siteguard_log_filter_ip_address_not', '', time( ) - 1800, '/' );
45
  }
46
- static function set_cookie( ) {
47
  if ( ! isset( $_GET['page'] ) ) {
48
  return;
49
  }
@@ -52,34 +52,34 @@ class SiteGuard_Menu_Login_History extends SiteGuard_Base {
52
  }
53
 
54
  if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
55
- $referer = wp_get_referer( );
56
  if ( false === strpos( $referer, 'siteguard_login_history' ) ) {
57
- SiteGuard_Menu_Login_History::clear_cookie( );
58
  }
59
  return;
60
  }
61
  if ( isset( $_POST['filter_reset'] ) ) {
62
- SiteGuard_Menu_Login_History::clear_cookie( );
63
  } else {
64
  if ( isset( $_POST['filter_operation'] ) ) {
65
- setcookie( 'siteguard_log_filter_operation', $_POST['filter_operation'], time( ) + 60 * 60, '/' );
66
  }
67
  if ( isset( $_POST['filter_type'] ) ) {
68
- setcookie( 'siteguard_log_filter_type', $_POST['filter_type'], time( ) + 60 * 60, '/' );
69
  }
70
  if ( isset( $_POST['filter_login_name'] ) ) {
71
- setcookie( 'siteguard_log_filter_login_name', $_POST['filter_login_name'], time( ) + 60 * 60, '/' );
72
  }
73
  if ( isset( $_POST['filter_ip_address'] ) ) {
74
- setcookie( 'siteguard_log_filter_ip_address', $_POST['filter_ip_address'], time( ) + 60 * 60, '/' );
75
  }
76
  if ( isset( $_POST['filter_login_name_not'] ) ) {
77
- setcookie( 'siteguard_log_filter_login_name_not', $_POST['filter_login_name_not'], time( ) + 60 * 60, '/' );
78
  }
79
  if ( isset( $_POST['filter_ip_address_not'] ) ) {
80
- setcookie( 'siteguard_log_filter_ip_address_not', $_POST['filter_ip_address_not'], time( ) + 60 * 60, '/' );
81
  }
82
  }
83
-
84
  }
85
  }
1
  <?php
2
 
3
+ require_once 'siteguard-login-history-table.php';
4
 
5
  class SiteGuard_Menu_Login_History extends SiteGuard_Base {
6
  protected $wp_list_table;
7
+ function __construct() {
8
+ $this->wp_list_table = new SiteGuard_LoginHistory_Table();
9
+ $this->wp_list_table->prepare_items();
10
+ $this->render_page();
11
  }
12
+ function render_page() {
13
  global $siteguard_config, $siteguard_login_history;
14
  $img_path = SITEGUARD_URL_PATH . 'images/';
15
  echo '<div class="wrap">';
18
  echo '<div class="siteguard-description">'
19
  . esc_html__( 'You can find docs about this function on ', 'siteguard' )
20
  . '<a href="' . esc_url( __( 'https://www.jp-secure.com/siteguard_wp_plugin_en/howto/login_history/', 'siteguard' ) ) . '" target="_blank">' . esc_html__( 'SiteGuard WP Plugin Page', 'siteguard' ) . '</a>' . esc_html__( '.', 'siteguard' ) . '</div>';
21
+ $error = siteguard_check_multisite();
22
  if ( is_wp_error( $error ) ) {
23
  echo '<p class="description">';
24
+ echo esc_html( $error->get_error_message() );
25
  echo '</p>';
26
  }
27
  ?>
28
  <form name="form1" method="post" action="">
29
+ <?php $this->wp_list_table->display(); ?>
30
  <div class="siteguard-description">
31
+ <?php esc_html_e( 'Login history can be referenced. Let\'s see if there are any suspicious history. History, registered 10,000 maximum, will be removed from those old and more than 10,000.', 'siteguard' ); ?>
32
  </div>
33
+ <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>">
34
  </form>
35
  </div>
36
  <?php
37
  }
38
+ static function clear_cookie() {
39
+ setcookie( 'siteguard_log_filter_operation', '', time() - 1800, '/' );
40
+ setcookie( 'siteguard_log_filter_type', '', time() - 1800, '/' );
41
+ setcookie( 'siteguard_log_filter_login_name', '', time() - 1800, '/' );
42
+ setcookie( 'siteguard_log_filter_ip_address', '', time() - 1800, '/' );
43
+ setcookie( 'siteguard_log_filter_login_name_not', '', time() - 1800, '/' );
44
+ setcookie( 'siteguard_log_filter_ip_address_not', '', time() - 1800, '/' );
45
  }
46
+ static function set_cookie() {
47
  if ( ! isset( $_GET['page'] ) ) {
48
  return;
49
  }
52
  }
53
 
54
  if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
55
+ $referer = wp_get_referer();
56
  if ( false === strpos( $referer, 'siteguard_login_history' ) ) {
57
+ self::clear_cookie();
58
  }
59
  return;
60
  }
61
  if ( isset( $_POST['filter_reset'] ) ) {
62
+ self::clear_cookie();
63
  } else {
64
  if ( isset( $_POST['filter_operation'] ) ) {
65
+ setcookie( 'siteguard_log_filter_operation', $_POST['filter_operation'], time() + 60 * 60, '/' );
66
  }
67
  if ( isset( $_POST['filter_type'] ) ) {
68
+ setcookie( 'siteguard_log_filter_type', $_POST['filter_type'], time() + 60 * 60, '/' );
69
  }
70
  if ( isset( $_POST['filter_login_name'] ) ) {
71
+ setcookie( 'siteguard_log_filter_login_name', $_POST['filter_login_name'], time() + 60 * 60, '/' );
72
  }
73
  if ( isset( $_POST['filter_ip_address'] ) ) {
74
+ setcookie( 'siteguard_log_filter_ip_address', $_POST['filter_ip_address'], time() + 60 * 60, '/' );
75
  }
76
  if ( isset( $_POST['filter_login_name_not'] ) ) {
77
+ setcookie( 'siteguard_log_filter_login_name_not', $_POST['filter_login_name_not'], time() + 60 * 60, '/' );
78
  }
79
  if ( isset( $_POST['filter_ip_address_not'] ) ) {
80
+ setcookie( 'siteguard_log_filter_ip_address_not', $_POST['filter_ip_address_not'], time() + 60 * 60, '/' );
81
  }
82
  }
83
+
84
  }
85
  }
admin/siteguard-menu-login-lock.php CHANGED
@@ -1,13 +1,13 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Login_Lock extends SiteGuard_Base {
4
- const OPT_NAME_ENABLE = 'loginlock_enable';
5
- const OPT_NAME_INTERVAL = 'loginlock_interval';
6
- const OPT_NAME_THRESHOLD = 'loginlock_threshold';
7
- const OPT_NAME_LOCKSEC = 'loginlock_locksec';
8
 
9
- function __construct( ) {
10
- $this->render_page( );
11
  }
12
  function is_interval_value( $value ) {
13
  $items = array( '1', '5', '30' );
@@ -30,7 +30,7 @@ class SiteGuard_Menu_Login_Lock extends SiteGuard_Base {
30
  }
31
  return false;
32
  }
33
- function render_page( ) {
34
  global $siteguard_config;
35
 
36
  $opt_val_enable = $siteguard_config->get( self::OPT_NAME_ENABLE );
@@ -38,34 +38,34 @@ class SiteGuard_Menu_Login_Lock extends SiteGuard_Base {
38
  $opt_val_threshold = $siteguard_config->get( self::OPT_NAME_THRESHOLD );
39
  $opt_val_locksec = $siteguard_config->get( self::OPT_NAME_LOCKSEC );
40
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-login-lock-submit' ) ) {
41
- $error = false;
42
- $errors = siteguard_check_multisite( );
43
  if ( is_wp_error( $errors ) ) {
44
  echo '<div class="error settings-error"><p><strong>';
45
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
46
  echo '</strong></p></div>';
47
  $error = true;
48
  }
49
  if ( ( false === $error )
50
  && ( ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_ENABLE ] ) )
51
- || ( false === $this->is_interval_value( $_POST[ self::OPT_NAME_INTERVAL ] ) )
52
- || ( false === $this->is_threshold_value( $_POST[ self::OPT_NAME_THRESHOLD ] ) )
53
- || ( false === $this->is_locksec_value( $_POST[ self::OPT_NAME_LOCKSEC ] ) ) ) ) {
54
  echo '<div class="error settings-error"><p><strong>';
55
  esc_html_e( 'ERROR: Invalid input value.', 'siteguard' );
56
  echo '</strong></p></div>';
57
  $error = true;
58
  }
59
  if ( false === $error ) {
60
- $opt_val_enable = $_POST[ self::OPT_NAME_ENABLE ];
61
- $opt_val_interval = $_POST[ self::OPT_NAME_INTERVAL ];
62
- $opt_val_threshold = $_POST[ self::OPT_NAME_THRESHOLD ];
63
- $opt_val_locksec = $_POST[ self::OPT_NAME_LOCKSEC ];
64
- $siteguard_config->set( self::OPT_NAME_ENABLE, $opt_val_enable );
65
- $siteguard_config->set( self::OPT_NAME_INTERVAL, $opt_val_interval );
66
  $siteguard_config->set( self::OPT_NAME_THRESHOLD, $opt_val_threshold );
67
- $siteguard_config->set( self::OPT_NAME_LOCKSEC, $opt_val_locksec );
68
- $siteguard_config->update( );
69
  ?>
70
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
71
  <?php
@@ -90,18 +90,18 @@ class SiteGuard_Menu_Login_Lock extends SiteGuard_Base {
90
  <th scope="row" colspan="2">
91
  <ul class="siteguard-radios">
92
  <li>
93
- <input type="radio" name="<?php echo self::OPT_NAME_ENABLE ?>" id="<?php echo self::OPT_NAME_ENABLE.'_on' ?>" value="1" <?php checked( $opt_val_enable, '1' ) ?> >
94
- <label for="<?php echo self::OPT_NAME_ENABLE.'_on' ?>"><?php esc_html_e( 'ON', 'siteguard' ) ?></label>
95
  </li><li>
96
- <input type="radio" name="<?php echo self::OPT_NAME_ENABLE ?>" id="<?php echo self::OPT_NAME_ENABLE.'_off' ?>" value="0" <?php checked( $opt_val_enable, '0' ) ?> >
97
- <label for="<?php echo self::OPT_NAME_ENABLE.'_off' ?>"><?php esc_html_e( 'OFF', 'siteguard' ) ?></label>
98
  </li>
99
  </ul>
100
  <?php
101
- $error = siteguard_check_multisite( );
102
  if ( is_wp_error( $error ) ) {
103
  echo '<p class="description">';
104
- echo $error->get_error_message( );
105
  echo '</p>';
106
  }
107
  ?>
@@ -109,50 +109,50 @@ class SiteGuard_Menu_Login_Lock extends SiteGuard_Base {
109
  </tr><tr>
110
  <th scope="row"><?php esc_html_e( 'Interval', 'siteguard' ); ?></th>
111
  <td>
112
- <input type="radio" name="<?php echo self::OPT_NAME_INTERVAL ?>" id="<?php echo self::OPT_NAME_INTERVAL.'_1' ?>" value="1" <?php checked( $opt_val_interval, '1' ) ?> >
113
- <label for="<?php echo self::OPT_NAME_INTERVAL.'_1' ?>"><?php esc_html_e( '1 second', 'siteguard' ) ?></label>
114
  <br />
115
- <input type="radio" name="<?php echo self::OPT_NAME_INTERVAL ?>" id="<?php echo self::OPT_NAME_INTERVAL.'_5' ?>" value="5" <?php checked( $opt_val_interval, '5' ) ?> >
116
- <label for="<?php echo self::OPT_NAME_INTERVAL.'_5' ?>"><?php esc_html_e( '5 seconds', 'siteguard' ) ?></label>
117
  <br />
118
- <input type="radio" name="<?php echo self::OPT_NAME_INTERVAL ?>" id="<?php echo self::OPT_NAME_INTERVAL.'_30' ?>" value="30" <?php checked( $opt_val_interval, '30' ) ?> >
119
- <label for="<?php echo self::OPT_NAME_INTERVAL.'_30' ?>"><?php esc_html_e( '30 seconds', 'siteguard' ) ?></label>
120
  </td>
121
  </tr><tr>
122
  <th scope="row"><?php esc_html_e( 'Threshold', 'siteguard' ); ?></th>
123
  <td>
124
- <input type="radio" name="<?php echo self::OPT_NAME_THRESHOLD ?>" id="<?php echo self::OPT_NAME_THRESHOLD.'_3' ?>" value="3" <?php checked( $opt_val_threshold, '3' ) ?> >
125
- <label for="<?php echo self::OPT_NAME_THRESHOLD.'_3' ?>"><?php esc_html_e( '3 times', 'siteguard' ) ?></label>
126
  <br />
127
- <input type="radio" name="<?php echo self::OPT_NAME_THRESHOLD ?>" id="<?php echo self::OPT_NAME_THRESHOLD.'_10' ?>" value="10" <?php checked( $opt_val_threshold, '10' ) ?> >
128
- <label for="<?php echo self::OPT_NAME_THRESHOLD.'_10' ?>"><?php esc_html_e( '10 times', 'siteguard' ) ?></label>
129
  <br />
130
- <input type="radio" name="<?php echo self::OPT_NAME_THRESHOLD ?>" id="<?php echo self::OPT_NAME_THRESHOLD.'_100' ?>" value="100" <?php checked( $opt_val_threshold, '100' ) ?> >
131
- <label for="<?php echo self::OPT_NAME_THRESHOLD.'_100' ?>"><?php esc_html_e( '100 times', 'siteguard' ) ?></label>
132
  </td>
133
  </tr><tr>
134
  <th scope="row"><?php esc_html_e( 'Lock Time', 'siteguard' ); ?></th>
135
  <td>
136
- <input type="radio" name="<?php echo self::OPT_NAME_LOCKSEC ?>" id="<?php echo self::OPT_NAME_LOCKSEC.'_30' ?>" value="30" <?php checked( $opt_val_locksec, '30' ) ?> >
137
- <label for="<?php echo self::OPT_NAME_LOCKSEC.'_30' ?>"><?php esc_html_e( '30 seconds', 'siteguard' ) ?></label>
138
  <br />
139
- <input type="radio" name="<?php echo self::OPT_NAME_LOCKSEC ?>" id="<?php echo self::OPT_NAME_LOCKSEC.'_60' ?>" value="60" <?php checked( $opt_val_locksec, '60' ) ?> >
140
- <label for="<?php echo self::OPT_NAME_LOCKSEC.'_60' ?>"><?php esc_html_e( '1 minute', 'siteguard' ) ?></label>
141
  <br />
142
- <input type="radio" name="<?php echo self::OPT_NAME_LOCKSEC ?>" id="<?php echo self::OPT_NAME_LOCKSEC.'_300' ?>" value="300" <?php checked( $opt_val_locksec, '300' ) ?> >
143
- <label for="<?php echo self::OPT_NAME_LOCKSEC.'_300' ?>"><?php esc_html_e( '5 minutes', 'siteguard' ) ?></label>
144
  </td>
145
  </tr>
146
  </table>
147
  <div class="siteguard-description">
148
- <?php esc_html_e( 'It is the function to decrease the vulnerability against an illegal login attempt attack such as a brute force attack or a password list attack. Especially, it is the function to prevent an automated attack. The connection source IP address the number of login failure of which reaches the specified number within the specified period is blocked for the specified time. Each user account is not locked.', 'siteguard' ) ?>
149
  </div>
150
  <hr />
151
  <input type="hidden" name="update" value="Y">
152
 
153
  <?php
154
  wp_nonce_field( 'siteguard-menu-login-lock-submit' );
155
- submit_button( );
156
  ?>
157
 
158
  </form>
1
  <?php
2
 
3
  class SiteGuard_Menu_Login_Lock extends SiteGuard_Base {
4
+ const OPT_NAME_ENABLE = 'loginlock_enable';
5
+ const OPT_NAME_INTERVAL = 'loginlock_interval';
6
+ const OPT_NAME_THRESHOLD = 'loginlock_threshold';
7
+ const OPT_NAME_LOCKSEC = 'loginlock_locksec';
8
 
9
+ function __construct() {
10
+ $this->render_page();
11
  }
12
  function is_interval_value( $value ) {
13
  $items = array( '1', '5', '30' );
30
  }
31
  return false;
32
  }
33
+ function render_page() {
34
  global $siteguard_config;
35
 
36
  $opt_val_enable = $siteguard_config->get( self::OPT_NAME_ENABLE );
38
  $opt_val_threshold = $siteguard_config->get( self::OPT_NAME_THRESHOLD );
39
  $opt_val_locksec = $siteguard_config->get( self::OPT_NAME_LOCKSEC );
40
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-login-lock-submit' ) ) {
41
+ $error = false;
42
+ $errors = siteguard_check_multisite();
43
  if ( is_wp_error( $errors ) ) {
44
  echo '<div class="error settings-error"><p><strong>';
45
+ echo esc_html( $errors->get_error_message() );
46
  echo '</strong></p></div>';
47
  $error = true;
48
  }
49
  if ( ( false === $error )
50
  && ( ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_ENABLE ] ) )
51
+ || ( false === $this->is_interval_value( $_POST[ self::OPT_NAME_INTERVAL ] ) )
52
+ || ( false === $this->is_threshold_value( $_POST[ self::OPT_NAME_THRESHOLD ] ) )
53
+ || ( false === $this->is_locksec_value( $_POST[ self::OPT_NAME_LOCKSEC ] ) ) ) ) {
54
  echo '<div class="error settings-error"><p><strong>';
55
  esc_html_e( 'ERROR: Invalid input value.', 'siteguard' );
56
  echo '</strong></p></div>';
57
  $error = true;
58
  }
59
  if ( false === $error ) {
60
+ $opt_val_enable = sanitize_text_field( $_POST[ self::OPT_NAME_ENABLE ] );
61
+ $opt_val_interval = sanitize_text_field( $_POST[ self::OPT_NAME_INTERVAL ] );
62
+ $opt_val_threshold = sanitize_text_field( $_POST[ self::OPT_NAME_THRESHOLD ] );
63
+ $opt_val_locksec = sanitize_text_field( $_POST[ self::OPT_NAME_LOCKSEC ] );
64
+ $siteguard_config->set( self::OPT_NAME_ENABLE, $opt_val_enable );
65
+ $siteguard_config->set( self::OPT_NAME_INTERVAL, $opt_val_interval );
66
  $siteguard_config->set( self::OPT_NAME_THRESHOLD, $opt_val_threshold );
67
+ $siteguard_config->set( self::OPT_NAME_LOCKSEC, $opt_val_locksec );
68
+ $siteguard_config->update();
69
  ?>
70
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
71
  <?php
90
  <th scope="row" colspan="2">
91
  <ul class="siteguard-radios">
92
  <li>
93
+ <input type="radio" name="<?php echo self::OPT_NAME_ENABLE; ?>" id="<?php echo self::OPT_NAME_ENABLE . '_on'; ?>" value="1" <?php checked( $opt_val_enable, '1' ); ?> >
94
+ <label for="<?php echo self::OPT_NAME_ENABLE . '_on'; ?>"><?php esc_html_e( 'ON', 'siteguard' ); ?></label>
95
  </li><li>
96
+ <input type="radio" name="<?php echo self::OPT_NAME_ENABLE; ?>" id="<?php echo self::OPT_NAME_ENABLE . '_off'; ?>" value="0" <?php checked( $opt_val_enable, '0' ); ?> >
97
+ <label for="<?php echo self::OPT_NAME_ENABLE . '_off'; ?>"><?php esc_html_e( 'OFF', 'siteguard' ); ?></label>
98
  </li>
99
  </ul>
100
  <?php
101
+ $error = siteguard_check_multisite();
102
  if ( is_wp_error( $error ) ) {
103
  echo '<p class="description">';
104
+ echo esc_html( $error->get_error_message() );
105
  echo '</p>';
106
  }
107
  ?>
109
  </tr><tr>
110
  <th scope="row"><?php esc_html_e( 'Interval', 'siteguard' ); ?></th>
111
  <td>
112
+ <input type="radio" name="<?php echo self::OPT_NAME_INTERVAL; ?>" id="<?php echo self::OPT_NAME_INTERVAL . '_1'; ?>" value="1" <?php checked( $opt_val_interval, '1' ); ?> >
113
+ <label for="<?php echo self::OPT_NAME_INTERVAL . '_1'; ?>"><?php esc_html_e( '1 second', 'siteguard' ); ?></label>
114
  <br />
115
+ <input type="radio" name="<?php echo self::OPT_NAME_INTERVAL; ?>" id="<?php echo self::OPT_NAME_INTERVAL . '_5'; ?>" value="5" <?php checked( $opt_val_interval, '5' ); ?> >
116
+ <label for="<?php echo self::OPT_NAME_INTERVAL . '_5'; ?>"><?php esc_html_e( '5 seconds', 'siteguard' ); ?></label>
117
  <br />
118
+ <input type="radio" name="<?php echo self::OPT_NAME_INTERVAL; ?>" id="<?php echo self::OPT_NAME_INTERVAL . '_30'; ?>" value="30" <?php checked( $opt_val_interval, '30' ); ?> >
119
+ <label for="<?php echo self::OPT_NAME_INTERVAL . '_30'; ?>"><?php esc_html_e( '30 seconds', 'siteguard' ); ?></label>
120
  </td>
121
  </tr><tr>
122
  <th scope="row"><?php esc_html_e( 'Threshold', 'siteguard' ); ?></th>
123
  <td>
124
+ <input type="radio" name="<?php echo self::OPT_NAME_THRESHOLD; ?>" id="<?php echo self::OPT_NAME_THRESHOLD . '_3'; ?>" value="3" <?php checked( $opt_val_threshold, '3' ); ?> >
125
+ <label for="<?php echo self::OPT_NAME_THRESHOLD . '_3'; ?>"><?php esc_html_e( '3 times', 'siteguard' ); ?></label>
126
  <br />
127
+ <input type="radio" name="<?php echo self::OPT_NAME_THRESHOLD; ?>" id="<?php echo self::OPT_NAME_THRESHOLD . '_10'; ?>" value="10" <?php checked( $opt_val_threshold, '10' ); ?> >
128
+ <label for="<?php echo self::OPT_NAME_THRESHOLD . '_10'; ?>"><?php esc_html_e( '10 times', 'siteguard' ); ?></label>
129
  <br />
130
+ <input type="radio" name="<?php echo self::OPT_NAME_THRESHOLD; ?>" id="<?php echo self::OPT_NAME_THRESHOLD . '_100'; ?>" value="100" <?php checked( $opt_val_threshold, '100' ); ?> >
131
+ <label for="<?php echo self::OPT_NAME_THRESHOLD . '_100'; ?>"><?php esc_html_e( '100 times', 'siteguard' ); ?></label>
132
  </td>
133
  </tr><tr>
134
  <th scope="row"><?php esc_html_e( 'Lock Time', 'siteguard' ); ?></th>
135
  <td>
136
+ <input type="radio" name="<?php echo self::OPT_NAME_LOCKSEC; ?>" id="<?php echo self::OPT_NAME_LOCKSEC . '_30'; ?>" value="30" <?php checked( $opt_val_locksec, '30' ); ?> >
137
+ <label for="<?php echo self::OPT_NAME_LOCKSEC . '_30'; ?>"><?php esc_html_e( '30 seconds', 'siteguard' ); ?></label>
138
  <br />
139
+ <input type="radio" name="<?php echo self::OPT_NAME_LOCKSEC; ?>" id="<?php echo self::OPT_NAME_LOCKSEC . '_60'; ?>" value="60" <?php checked( $opt_val_locksec, '60' ); ?> >
140
+ <label for="<?php echo self::OPT_NAME_LOCKSEC . '_60'; ?>"><?php esc_html_e( '1 minute', 'siteguard' ); ?></label>
141
  <br />
142
+ <input type="radio" name="<?php echo self::OPT_NAME_LOCKSEC; ?>" id="<?php echo self::OPT_NAME_LOCKSEC . '_300'; ?>" value="300" <?php checked( $opt_val_locksec, '300' ); ?> >
143
+ <label for="<?php echo self::OPT_NAME_LOCKSEC . '_300'; ?>"><?php esc_html_e( '5 minutes', 'siteguard' ); ?></label>
144
  </td>
145
  </tr>
146
  </table>
147
  <div class="siteguard-description">
148
+ <?php esc_html_e( 'It is the function to decrease the vulnerability against an illegal login attempt attack such as a brute force attack or a password list attack. Especially, it is the function to prevent an automated attack. The connection source IP address the number of login failure of which reaches the specified number within the specified period is blocked for the specified time. Each user account is not locked.', 'siteguard' ); ?>
149
  </div>
150
  <hr />
151
  <input type="hidden" name="update" value="Y">
152
 
153
  <?php
154
  wp_nonce_field( 'siteguard-menu-login-lock-submit' );
155
+ submit_button();
156
  ?>
157
 
158
  </form>
admin/siteguard-menu-protect-xmlrpc.php CHANGED
@@ -1,18 +1,18 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Protect_XMLRPC extends SiteGuard_Base {
4
- const OPT_NAME_FEATURE = 'protect_xmlrpc_enable';
5
- const OPT_NAME_TYPE = 'protect_xmlrpc_type';
6
- const OPT_NAME_XMLRPC = 'disable_xmlrpc_enable';
7
- const OPT_NAME_PINGBACK = 'disable_pingback_enable';
8
 
9
  protected $opt_val_xmlrpc;
10
  protected $opt_val_pingback;
11
  protected $opt_val_feature;
12
  protected $opt_val_type;
13
 
14
- function __construct( ) {
15
- $this->render_page( );
16
  }
17
  function is_switch_value( $value ) {
18
  $items = array( '0', '1' );
@@ -21,21 +21,21 @@ class SiteGuard_Menu_Protect_XMLRPC extends SiteGuard_Base {
21
  }
22
  return false;
23
  }
24
- function db_to_page( ) {
25
  if ( '0' === $this->opt_val_xmlrpc ) {
26
  if ( '0' === $this->opt_val_pingback ) {
27
  $this->opt_val_feature = '0';
28
- $this->opt_val_type = '0';
29
  } else {
30
  $this->opt_val_feature = '1';
31
- $this->opt_val_type = '0';
32
  }
33
  } else {
34
  $this->opt_val_feature = '1';
35
- $this->opt_val_type = '1';
36
  }
37
- }
38
- function page_to_db( ) {
39
  if ( '0' === $this->opt_val_feature ) {
40
  $this->opt_val_xmlrpc = '0';
41
  $this->opt_val_pingback = '0';
@@ -49,24 +49,24 @@ class SiteGuard_Menu_Protect_XMLRPC extends SiteGuard_Base {
49
  }
50
  }
51
  }
52
- function render_page( ) {
53
  global $siteguard_config, $siteguard_xmlrpc;
54
 
55
- $this->opt_val_xmlrpc = $siteguard_config->get( self::OPT_NAME_XMLRPC );
56
- $this->opt_val_pingback = $siteguard_config->get( self::OPT_NAME_PINGBACK );
57
 
58
- $this->db_to_page( );
59
 
60
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-protect-xmlrpc-submit' ) ) {
61
- $error = false;
62
- $errors = siteguard_check_multisite( );
63
  if ( is_wp_error( $errors ) ) {
64
  echo '<div class="error settings-error"><p><strong>';
65
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
66
  echo '</strong></p></div>';
67
  $error = true;
68
  }
69
- if ( false === $error
70
  && ( ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_FEATURE ] ) )
71
  || ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_TYPE ] ) ) ) ) {
72
  echo '<div class="error settings-error"><p><strong>';
@@ -77,26 +77,26 @@ class SiteGuard_Menu_Protect_XMLRPC extends SiteGuard_Base {
77
  if ( false === $error
78
  && '1' === $_POST[ self::OPT_NAME_FEATURE ]
79
  && '1' === $_POST[ self::OPT_NAME_TYPE ]
80
- && false === SiteGuard_Htaccess::test_htaccess( ) ) {
81
  echo '<div class="error settings-error"><p><strong>';
82
  esc_html_e( 'mod_rewrite of .htaccess can not be used', 'siteguard' );
83
  echo '</strong></p></div>';
84
  $error = true;
85
  }
86
  if ( false === $error ) {
87
- $old_opt_val_feature = $this->opt_val_feature;
88
- $old_opt_val_type = $this->opt_val_type;
89
- $this->opt_val_feature = $_POST[ self::OPT_NAME_FEATURE ];
90
- $this->opt_val_type = $_POST[ self::OPT_NAME_TYPE ];
91
- $this->page_to_db( );
92
- $siteguard_config->set( self::OPT_NAME_XMLRPC, $this->opt_val_xmlrpc );
93
  $siteguard_config->set( self::OPT_NAME_PINGBACK, $this->opt_val_pingback );
94
- $siteguard_config->update( );
95
  $result = true;
96
  if ( '0' === $this->opt_val_xmlrpc ) {
97
- $result = $siteguard_xmlrpc->feature_off( );
98
  } else {
99
- $result = $siteguard_xmlrpc->feature_on( );
100
  }
101
  if ( true === $result ) {
102
  ?>
@@ -105,10 +105,10 @@ class SiteGuard_Menu_Protect_XMLRPC extends SiteGuard_Base {
105
  } else {
106
  $this->opt_val_feature = $old_opt_val_feature;
107
  $this->opt_val_val_type = $old_opt_val_type;
108
- $this->page_to_db( );
109
- $siteguard_config->set( self::OPT_NAME_XMLRPC, $this->opt_val_xmlrpc );
110
  $siteguard_config->set( self::OPT_NAME_PINGBACK, $this->opt_val_pingback );
111
- $siteguard_config->update( );
112
  echo '<div class="error settings-error"><p><strong>';
113
  esc_html_e( 'ERROR: Failed to .htaccess update.', 'siteguard' );
114
  echo '</strong></p></div>';
@@ -135,18 +135,18 @@ class SiteGuard_Menu_Protect_XMLRPC extends SiteGuard_Base {
135
  <th scope="row" colspan="2">
136
  <ul class="siteguard-radios">
137
  <li>
138
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE.'_on' ?>" value="1" <?php checked( $this->opt_val_feature, '1' ) ?> >
139
- <label for="<?php echo self::OPT_NAME_FEATURE.'_on' ?>"><?php echo esc_html_e( 'ON', 'siteguard' ) ?></label>
140
  </li><li>
141
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE.'_off' ?>" value="0" <?php checked( $this->opt_val_feature, '0' ) ?> >
142
- <label for="<?php echo self::OPT_NAME_FEATURE.'_off' ?>"><?php echo esc_html_e( 'OFF', 'siteguard' ) ?></label>
143
  </li>
144
  </ul>
145
  <?php
146
- $error = siteguard_check_multisite( );
147
  if ( is_wp_error( $error ) ) {
148
  echo '<p class="description">';
149
- echo $error->get_error_message( );
150
  echo '</p>';
151
  }
152
  ?>
@@ -154,22 +154,22 @@ class SiteGuard_Menu_Protect_XMLRPC extends SiteGuard_Base {
154
  </tr><tr>
155
  <th scope="row"><?php esc_html_e( 'Type', 'siteguard' ); ?></th>
156
  <td>
157
- <input type="radio" name="<?php echo self::OPT_NAME_TYPE ?>" id="<?php echo self::OPT_NAME_TYPE.'_0' ?>" value="0" <?php checked( $this->opt_val_type, '0' ) ?> >
158
- <label for="<?php echo self::OPT_NAME_TYPE.'_0' ?>"><?php esc_html_e( 'Disable Pingback', 'siteguard' ) ?></label>
159
  <br />
160
- <input type="radio" name="<?php echo self::OPT_NAME_TYPE ?>" id="<?php echo self::OPT_NAME_TYPE.'_1' ?>" value="1" <?php checked( $this->opt_val_type, '1' ) ?> >
161
- <label for="<?php echo self::OPT_NAME_TYPE.'_1' ?>"><?php esc_html_e( 'Disable XMLRPC', 'siteguard' ) ?></label>
162
  </td>
163
  </tr>
164
  </table>
165
  <input type="hidden" name="update" value="Y">
166
  <div class="siteguard-description">
167
- <?php esc_html_e( 'To disable the Pingback, or disable the entire XMLRPC ( xmlrpc.php ), to prevent abuse. When you disable the whole XMLRPC, you will not be able to use plug-ins and apps that use XMLRPC. If there is trouble, please do not use this function.', 'siteguard' ) ?>
168
  </div>
169
  <hr />
170
  <?php
171
  wp_nonce_field( 'siteguard-menu-protect-xmlrpc-submit' );
172
- submit_button( );
173
  ?>
174
  </form>
175
  </div>
1
  <?php
2
 
3
  class SiteGuard_Menu_Protect_XMLRPC extends SiteGuard_Base {
4
+ const OPT_NAME_FEATURE = 'protect_xmlrpc_enable';
5
+ const OPT_NAME_TYPE = 'protect_xmlrpc_type';
6
+ const OPT_NAME_XMLRPC = 'disable_xmlrpc_enable';
7
+ const OPT_NAME_PINGBACK = 'disable_pingback_enable';
8
 
9
  protected $opt_val_xmlrpc;
10
  protected $opt_val_pingback;
11
  protected $opt_val_feature;
12
  protected $opt_val_type;
13
 
14
+ function __construct() {
15
+ $this->render_page();
16
  }
17
  function is_switch_value( $value ) {
18
  $items = array( '0', '1' );
21
  }
22
  return false;
23
  }
24
+ function db_to_page() {
25
  if ( '0' === $this->opt_val_xmlrpc ) {
26
  if ( '0' === $this->opt_val_pingback ) {
27
  $this->opt_val_feature = '0';
28
+ $this->opt_val_type = '0';
29
  } else {
30
  $this->opt_val_feature = '1';
31
+ $this->opt_val_type = '0';
32
  }
33
  } else {
34
  $this->opt_val_feature = '1';
35
+ $this->opt_val_type = '1';
36
  }
37
+ }
38
+ function page_to_db() {
39
  if ( '0' === $this->opt_val_feature ) {
40
  $this->opt_val_xmlrpc = '0';
41
  $this->opt_val_pingback = '0';
49
  }
50
  }
51
  }
52
+ function render_page() {
53
  global $siteguard_config, $siteguard_xmlrpc;
54
 
55
+ $this->opt_val_xmlrpc = $siteguard_config->get( self::OPT_NAME_XMLRPC );
56
+ $this->opt_val_pingback = $siteguard_config->get( self::OPT_NAME_PINGBACK );
57
 
58
+ $this->db_to_page();
59
 
60
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-protect-xmlrpc-submit' ) ) {
61
+ $error = false;
62
+ $errors = siteguard_check_multisite();
63
  if ( is_wp_error( $errors ) ) {
64
  echo '<div class="error settings-error"><p><strong>';
65
+ echo esc_html( $errors->get_error_message() );
66
  echo '</strong></p></div>';
67
  $error = true;
68
  }
69
+ if ( false === $error
70
  && ( ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_FEATURE ] ) )
71
  || ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_TYPE ] ) ) ) ) {
72
  echo '<div class="error settings-error"><p><strong>';
77
  if ( false === $error
78
  && '1' === $_POST[ self::OPT_NAME_FEATURE ]
79
  && '1' === $_POST[ self::OPT_NAME_TYPE ]
80
+ && false === SiteGuard_Htaccess::test_htaccess() ) {
81
  echo '<div class="error settings-error"><p><strong>';
82
  esc_html_e( 'mod_rewrite of .htaccess can not be used', 'siteguard' );
83
  echo '</strong></p></div>';
84
  $error = true;
85
  }
86
  if ( false === $error ) {
87
+ $old_opt_val_feature = $this->opt_val_feature;
88
+ $old_opt_val_type = $this->opt_val_type;
89
+ $this->opt_val_feature = sanitize_text_field( $_POST[ self::OPT_NAME_FEATURE ] );
90
+ $this->opt_val_type = sanitize_text_field( $_POST[ self::OPT_NAME_TYPE ] );
91
+ $this->page_to_db();
92
+ $siteguard_config->set( self::OPT_NAME_XMLRPC, $this->opt_val_xmlrpc );
93
  $siteguard_config->set( self::OPT_NAME_PINGBACK, $this->opt_val_pingback );
94
+ $siteguard_config->update();
95
  $result = true;
96
  if ( '0' === $this->opt_val_xmlrpc ) {
97
+ $result = $siteguard_xmlrpc->feature_off();
98
  } else {
99
+ $result = $siteguard_xmlrpc->feature_on();
100
  }
101
  if ( true === $result ) {
102
  ?>
105
  } else {
106
  $this->opt_val_feature = $old_opt_val_feature;
107
  $this->opt_val_val_type = $old_opt_val_type;
108
+ $this->page_to_db();
109
+ $siteguard_config->set( self::OPT_NAME_XMLRPC, $this->opt_val_xmlrpc );
110
  $siteguard_config->set( self::OPT_NAME_PINGBACK, $this->opt_val_pingback );
111
+ $siteguard_config->update();
112
  echo '<div class="error settings-error"><p><strong>';
113
  esc_html_e( 'ERROR: Failed to .htaccess update.', 'siteguard' );
114
  echo '</strong></p></div>';
135
  <th scope="row" colspan="2">
136
  <ul class="siteguard-radios">
137
  <li>
138
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>" value="1" <?php checked( $this->opt_val_feature, '1' ); ?> >
139
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>"><?php echo esc_html_e( 'ON', 'siteguard' ); ?></label>
140
  </li><li>
141
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>" value="0" <?php checked( $this->opt_val_feature, '0' ); ?> >
142
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>"><?php echo esc_html_e( 'OFF', 'siteguard' ); ?></label>
143
  </li>
144
  </ul>
145
  <?php
146
+ $error = siteguard_check_multisite();
147
  if ( is_wp_error( $error ) ) {
148
  echo '<p class="description">';
149
+ echo esc_html( $error->get_error_message() );
150
  echo '</p>';
151
  }
152
  ?>
154
  </tr><tr>
155
  <th scope="row"><?php esc_html_e( 'Type', 'siteguard' ); ?></th>
156
  <td>
157
+ <input type="radio" name="<?php echo self::OPT_NAME_TYPE; ?>" id="<?php echo self::OPT_NAME_TYPE . '_0'; ?>" value="0" <?php checked( $this->opt_val_type, '0' ); ?> >
158
+ <label for="<?php echo self::OPT_NAME_TYPE . '_0'; ?>"><?php esc_html_e( 'Disable Pingback', 'siteguard' ); ?></label>
159
  <br />
160
+ <input type="radio" name="<?php echo self::OPT_NAME_TYPE; ?>" id="<?php echo self::OPT_NAME_TYPE . '_1'; ?>" value="1" <?php checked( $this->opt_val_type, '1' ); ?> >
161
+ <label for="<?php echo self::OPT_NAME_TYPE . '_1'; ?>"><?php esc_html_e( 'Disable XMLRPC', 'siteguard' ); ?></label>
162
  </td>
163
  </tr>
164
  </table>
165
  <input type="hidden" name="update" value="Y">
166
  <div class="siteguard-description">
167
+ <?php esc_html_e( 'To disable the Pingback, or disable the entire XMLRPC ( xmlrpc.php ), to prevent abuse. When you disable the whole XMLRPC, you will not be able to use plug-ins and apps that use XMLRPC. If there is trouble, please do not use this function.', 'siteguard' ); ?>
168
  </div>
169
  <hr />
170
  <?php
171
  wp_nonce_field( 'siteguard-menu-protect-xmlrpc-submit' );
172
+ submit_button();
173
  ?>
174
  </form>
175
  </div>
admin/siteguard-menu-rename-login.php CHANGED
@@ -1,25 +1,25 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
4
- const OPT_NAME_FEATURE = 'renamelogin_enable';
5
- const OPT_NAME_FEATURE_REDIRECT = 'redirect_enable';
6
- const OPT_NAME_RENAME_LOGIN_PATH = 'renamelogin_path';
7
 
8
- function __construct( ) {
9
- $this->render_page( );
10
  }
11
- function render_page( ) {
12
  global $siteguard_rename_login, $siteguard_config;
13
 
14
  $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE );
15
  $opt_val_feature_redirect = $siteguard_config->get( self::OPT_NAME_FEATURE_REDIRECT );
16
  $opt_val_rename_login_path = $siteguard_config->get( self::OPT_NAME_RENAME_LOGIN_PATH );
17
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-rename-login-submit' ) ) {
18
- $error = false;
19
- $errors = siteguard_check_multisite( );
20
  if ( is_wp_error( $errors ) ) {
21
  echo '<div class="error settings-error"><p><strong>';
22
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
23
  echo '</strong></p></div>';
24
  $error = true;
25
  }
@@ -29,8 +29,8 @@ class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
29
  echo '</strong></p></div>';
30
  $error = true;
31
  $siteguard_config->set( self::OPT_NAME_FEATURE, '0' );
32
- $siteguard_config->update( );
33
- $siteguard_rename_login->feature_off( );
34
  $opt_val_feature = '0';
35
  }
36
  if ( false === $error && false === $this->is_switch_value( $_POST[ self::OPT_NAME_FEATURE ] ) ) {
@@ -40,34 +40,34 @@ class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
40
  $error = true;
41
  }
42
  if ( false === $error && '1' === $_POST[ self::OPT_NAME_FEATURE ] ) {
43
- $incompatible_plugins = $siteguard_rename_login->get_active_incompatible_plugins( );
44
  if ( null !== $incompatible_plugins ) {
45
  echo '<div class="error settings-error"><p><strong>';
46
  echo esc_html__( 'This function and Plugin "', 'siteguard' ) . esc_html__( implode( ', ', $incompatible_plugins ) ) . esc_html__( '" cannot be used at the same time.', 'siteguard' );
47
  echo '</strong></p></div>';
48
  $error = true;
49
  $siteguard_config->set( self::OPT_NAME_FEATURE, '0' );
50
- $siteguard_config->update( );
51
- $siteguard_rename_login->feature_off( );
52
- $opt_val_feature = '0';
53
- $opt_val_rename_login_path = stripslashes( $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] );
54
  }
55
  }
56
  if ( false === $error && 1 != preg_match( '/^[a-zA-Z0-9_-]+$/', $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] ) ) {
57
  echo '<div class="error settings-error"><p><strong>';
58
  esc_html_e( 'It is only an alphanumeric character, a hyphen, and an underbar that can be used for New Login Path.', 'siteguard' );
59
  echo '</strong></p></div>';
60
- $opt_val_rename_login_path = stripslashes( $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] );
61
- $error = true;
62
  }
63
  if ( false === $error && 1 === preg_match( '/^(wp-admin|wp-content|wp-includes|wp-login$|login$)/', $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ], $matches ) ) {
64
  echo '<div class="error settings-error"><p><strong>';
65
  echo esc_html( $matches[0] ) . esc_html__( ' can not be used for New Login Path.', 'siteguard' );
66
  echo '</strong></p></div>';
67
- $opt_val_rename_login_path = stripslashes( $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] );
68
- $error = true;
69
  }
70
- if ( false === $error && '1' === $_POST[ self::OPT_NAME_FEATURE ] && false === SiteGuard_Htaccess::test_htaccess( ) ) {
71
  echo '<div class="error settings-error"><p><strong>';
72
  esc_html_e( 'mod_rewrite of .htaccess can not be used', 'siteguard' );
73
  echo '</strong></p></div>';
@@ -77,24 +77,24 @@ class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
77
  $old_opt_val_feature = $opt_val_feature;
78
  $old_opt_val_feature_redirect = $opt_val_feature_redirect;
79
  $old_opt_val_rename_login_path = $opt_val_rename_login_path;
80
- $opt_val_feature = $_POST[ self::OPT_NAME_FEATURE ];
81
  if ( isset( $_POST[ self::OPT_NAME_FEATURE_REDIRECT ] ) ) {
82
- $opt_val_feature_redirect = $_POST[ self::OPT_NAME_FEATURE_REDIRECT ];
83
  } else {
84
- $opt_val_feature_redirect = '0';
85
  }
86
- $opt_val_rename_login_path = $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ];
87
- $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
88
- $siteguard_config->set( self::OPT_NAME_FEATURE_REDIRECT, $opt_val_feature_redirect );
89
  $siteguard_config->set( self::OPT_NAME_RENAME_LOGIN_PATH, $opt_val_rename_login_path );
90
- $siteguard_config->update( );
91
  $result = true;
92
  if ( '0' === $opt_val_feature ) {
93
- $result = $siteguard_rename_login->feature_off( );
94
  } else {
95
- $result = $siteguard_rename_login->feature_on( );
96
  if ( true === $result ) {
97
- $siteguard_rename_login->send_notify( );
98
  }
99
  }
100
  if ( true === $result ) {
@@ -102,9 +102,9 @@ class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
102
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
103
  <?php
104
  } else {
105
- $siteguard_config->set( self::OPT_NAME_FEATURE, $old_opt_val_feature );
106
  $siteguard_config->set( self::OPT_NAME_RENAME_LOGIN_PATH, $old_opt_val_rename_login_path );
107
- $siteguard_config->update( );
108
  $opt_val_feature = $old_opt_val_feature;
109
  $opt_val_feature_redirect = $old_opt_val_feature_redirect;
110
  $opt_val_val_rename_login_path = $old_opt_val_rename_login_path;
@@ -133,18 +133,18 @@ class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
133
  <th scope="row" colspan="2">
134
  <ul class="siteguard-radios">
135
  <li>
136
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE.'_on' ?>" value="1" <?php checked( $opt_val_feature, '1' ) ?> >
137
- <label for="<?php echo self::OPT_NAME_FEATURE.'_on' ?>"><?php echo esc_html_e( 'ON', 'siteguard' ) ?></label>
138
  </li><li>
139
- <input type="radio" name="<?php echo self::OPT_NAME_FEATURE ?>" id="<?php echo self::OPT_NAME_FEATURE.'_off' ?>" value="0" <?php checked( $opt_val_feature, '0' ) ?> >
140
- <label for="<?php echo self::OPT_NAME_FEATURE.'_off' ?>"><?php echo esc_html_e( 'OFF', 'siteguard' ) ?></label>
141
  </li>
142
  </ul>
143
  <?php
144
- $error = siteguard_check_multisite( );
145
  if ( is_wp_error( $error ) ) {
146
  echo '<p class="description">';
147
- echo $error->get_error_message( );
148
  echo '</p>';
149
  }
150
  echo '<p class="description">';
@@ -153,9 +153,9 @@ class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
153
  ?>
154
  </th>
155
  </tr><tr>
156
- <th scope="row"><label for="<?php echo self::OPT_NAME_RENAME_LOGIN_PATH ?>"><?php esc_html_e( 'New Login Path', 'siteguard' ); ?></label></th>
157
  <td>
158
- <?php echo site_url() . '/' ?><input type="text" name="<?php echo self::OPT_NAME_RENAME_LOGIN_PATH ?>" id="<?php echo self::OPT_NAME_RENAME_LOGIN_PATH ?>" value="<?php echo esc_attr( $opt_val_rename_login_path ) ?>" >
159
  <?php
160
  echo '<p class="description">';
161
  esc_html_e( 'An alphanumeric character, a hyphen, and an underbar can be used.', 'siteguard' );
@@ -163,21 +163,21 @@ class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
163
  ?>
164
  </td>
165
  </tr><tr>
166
- <th scope="row"><?php esc_html_e( 'Option', 'siteguard' ) ?></th>
167
  <td>
168
- <input type="checkbox" name="<?php echo self::OPT_NAME_FEATURE_REDIRECT ?>" id="<?php echo self::OPT_NAME_FEATURE_REDIRECT ?>" value="1" <?php checked( $opt_val_feature_redirect, '1' ) ?> >
169
- <label for="<?php echo self::OPT_NAME_FEATURE_REDIRECT ?>"><?php esc_html_e( 'Do not redirect from admin page to login page. ', 'siteguard' ) ?></label>
170
  </td>
171
  </tr>
172
  </table>
173
  <input type="hidden" name="update" value="Y">
174
  <div class="siteguard-description">
175
- <?php esc_html_e( 'It is the function to decrease the vulnerability against an illegal login attempt attack such as a brute force attack or a password list attack. The login page name (wp-login.php) is changed. The initial value is “login_&lt;5 random digits&gt;” but it can be changed to a favorite name.', 'siteguard' ) ?>
176
  </div>
177
  <hr />
178
  <?php
179
  wp_nonce_field( 'siteguard-menu-rename-login-submit' );
180
- submit_button( );
181
  ?>
182
  </form>
183
  </div>
1
  <?php
2
 
3
  class SiteGuard_Menu_Rename_Login extends SiteGuard_Base {
4
+ const OPT_NAME_FEATURE = 'renamelogin_enable';
5
+ const OPT_NAME_FEATURE_REDIRECT = 'redirect_enable';
6
+ const OPT_NAME_RENAME_LOGIN_PATH = 'renamelogin_path';
7
 
8
+ function __construct() {
9
+ $this->render_page();
10
  }
11
+ function render_page() {
12
  global $siteguard_rename_login, $siteguard_config;
13
 
14
  $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE );
15
  $opt_val_feature_redirect = $siteguard_config->get( self::OPT_NAME_FEATURE_REDIRECT );
16
  $opt_val_rename_login_path = $siteguard_config->get( self::OPT_NAME_RENAME_LOGIN_PATH );
17
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-rename-login-submit' ) ) {
18
+ $error = false;
19
+ $errors = siteguard_check_multisite();
20
  if ( is_wp_error( $errors ) ) {
21
  echo '<div class="error settings-error"><p><strong>';
22
+ echo esc_html( $errors->get_error_message() );
23
  echo '</strong></p></div>';
24
  $error = true;
25
  }
29
  echo '</strong></p></div>';
30
  $error = true;
31
  $siteguard_config->set( self::OPT_NAME_FEATURE, '0' );
32
+ $siteguard_config->update();
33
+ $siteguard_rename_login->feature_off();
34
  $opt_val_feature = '0';
35
  }
36
  if ( false === $error && false === $this->is_switch_value( $_POST[ self::OPT_NAME_FEATURE ] ) ) {
40
  $error = true;
41
  }
42
  if ( false === $error && '1' === $_POST[ self::OPT_NAME_FEATURE ] ) {
43
+ $incompatible_plugins = $siteguard_rename_login->get_active_incompatible_plugins();
44
  if ( null !== $incompatible_plugins ) {
45
  echo '<div class="error settings-error"><p><strong>';
46
  echo esc_html__( 'This function and Plugin "', 'siteguard' ) . esc_html__( implode( ', ', $incompatible_plugins ) ) . esc_html__( '" cannot be used at the same time.', 'siteguard' );
47
  echo '</strong></p></div>';
48
  $error = true;
49
  $siteguard_config->set( self::OPT_NAME_FEATURE, '0' );
50
+ $siteguard_config->update();
51
+ $siteguard_rename_login->feature_off();
52
+ $opt_val_feature = '0';
53
+ $opt_val_rename_login_path = stripslashes( sanitize_text_field( $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] ) );
54
  }
55
  }
56
  if ( false === $error && 1 != preg_match( '/^[a-zA-Z0-9_-]+$/', $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] ) ) {
57
  echo '<div class="error settings-error"><p><strong>';
58
  esc_html_e( 'It is only an alphanumeric character, a hyphen, and an underbar that can be used for New Login Path.', 'siteguard' );
59
  echo '</strong></p></div>';
60
+ $opt_val_rename_login_path = stripslashes( sanitize_text_field( $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] ) );
61
+ $error = true;
62
  }
63
  if ( false === $error && 1 === preg_match( '/^(wp-admin|wp-content|wp-includes|wp-login$|login$)/', $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ], $matches ) ) {
64
  echo '<div class="error settings-error"><p><strong>';
65
  echo esc_html( $matches[0] ) . esc_html__( ' can not be used for New Login Path.', 'siteguard' );
66
  echo '</strong></p></div>';
67
+ $opt_val_rename_login_path = stripslashes( sanitize_text_field( $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] ) );
68
+ $error = true;
69
  }
70
+ if ( false === $error && '1' === $_POST[ self::OPT_NAME_FEATURE ] && false === SiteGuard_Htaccess::test_htaccess() ) {
71
  echo '<div class="error settings-error"><p><strong>';
72
  esc_html_e( 'mod_rewrite of .htaccess can not be used', 'siteguard' );
73
  echo '</strong></p></div>';
77
  $old_opt_val_feature = $opt_val_feature;
78
  $old_opt_val_feature_redirect = $opt_val_feature_redirect;
79
  $old_opt_val_rename_login_path = $opt_val_rename_login_path;
80
+ $opt_val_feature = sanitize_text_field( $_POST[ self::OPT_NAME_FEATURE ] );
81
  if ( isset( $_POST[ self::OPT_NAME_FEATURE_REDIRECT ] ) ) {
82
+ $opt_val_feature_redirect = '1';
83
  } else {
84
+ $opt_val_feature_redirect = '0';
85
  }
86
+ $opt_val_rename_login_path = sanitize_text_field( $_POST[ self::OPT_NAME_RENAME_LOGIN_PATH ] );
87
+ $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature );
88
+ $siteguard_config->set( self::OPT_NAME_FEATURE_REDIRECT, $opt_val_feature_redirect );
89
  $siteguard_config->set( self::OPT_NAME_RENAME_LOGIN_PATH, $opt_val_rename_login_path );
90
+ $siteguard_config->update();
91
  $result = true;
92
  if ( '0' === $opt_val_feature ) {
93
+ $result = $siteguard_rename_login->feature_off();
94
  } else {
95
+ $result = $siteguard_rename_login->feature_on();
96
  if ( true === $result ) {
97
+ $siteguard_rename_login->send_notify();
98
  }
99
  }
100
  if ( true === $result ) {
102
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
103
  <?php
104
  } else {
105
+ $siteguard_config->set( self::OPT_NAME_FEATURE, $old_opt_val_feature );
106
  $siteguard_config->set( self::OPT_NAME_RENAME_LOGIN_PATH, $old_opt_val_rename_login_path );
107
+ $siteguard_config->update();
108
  $opt_val_feature = $old_opt_val_feature;
109
  $opt_val_feature_redirect = $old_opt_val_feature_redirect;
110
  $opt_val_val_rename_login_path = $old_opt_val_rename_login_path;
133
  <th scope="row" colspan="2">
134
  <ul class="siteguard-radios">
135
  <li>
136
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>" value="1" <?php checked( $opt_val_feature, '1' ); ?> >
137
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>"><?php echo esc_html_e( 'ON', 'siteguard' ); ?></label>
138
  </li><li>
139
+ <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>" value="0" <?php checked( $opt_val_feature, '0' ); ?> >
140
+ <label for="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>"><?php echo esc_html_e( 'OFF', 'siteguard' ); ?></label>
141
  </li>
142
  </ul>
143
  <?php
144
+ $error = siteguard_check_multisite();
145
  if ( is_wp_error( $error ) ) {
146
  echo '<p class="description">';
147
+ echo esc_html( $error->get_error_message() );
148
  echo '</p>';
149
  }
150
  echo '<p class="description">';
153
  ?>
154
  </th>
155
  </tr><tr>
156
+ <th scope="row"><label for="<?php echo self::OPT_NAME_RENAME_LOGIN_PATH; ?>"><?php esc_html_e( 'New Login Path', 'siteguard' ); ?></label></th>
157
  <td>
158
+ <?php echo esc_url( site_url() ) . '/'; ?><input type="text" name="<?php echo self::OPT_NAME_RENAME_LOGIN_PATH; ?>" id="<?php echo self::OPT_NAME_RENAME_LOGIN_PATH; ?>" value="<?php echo esc_attr( $opt_val_rename_login_path ); ?>" >
159
  <?php
160
  echo '<p class="description">';
161
  esc_html_e( 'An alphanumeric character, a hyphen, and an underbar can be used.', 'siteguard' );
163
  ?>
164
  </td>
165
  </tr><tr>
166
+ <th scope="row"><?php esc_html_e( 'Option', 'siteguard' ); ?></th>
167
  <td>
168
+ <input type="checkbox" name="<?php echo self::OPT_NAME_FEATURE_REDIRECT; ?>" id="<?php echo self::OPT_NAME_FEATURE_REDIRECT; ?>" value="1" <?php checked( $opt_val_feature_redirect, '1' ); ?> >
169
+ <label for="<?php echo self::OPT_NAME_FEATURE_REDIRECT; ?>"><?php esc_html_e( 'Do not redirect from admin page to login page. ', 'siteguard' ); ?></label>
170
  </td>
171
  </tr>
172
  </table>
173
  <input type="hidden" name="update" value="Y">
174
  <div class="siteguard-description">
175
+ <?php esc_html_e( 'It is the function to decrease the vulnerability against an illegal login attempt attack such as a brute force attack or a password list attack. The login page name (wp-login.php) is changed. The initial value is “login_&lt;5 random digits&gt;” but it can be changed to a favorite name.', 'siteguard' ); ?>
176
  </div>
177
  <hr />
178
  <?php
179
  wp_nonce_field( 'siteguard-menu-rename-login-submit' );
180
+ submit_button();
181
  ?>
182
  </form>
183
  </div>
admin/siteguard-menu-same-error.php CHANGED
@@ -1,31 +1,31 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Same_Error extends SiteGuard_Base {
4
- const OPT_NAME_ENABLE = 'same_login_error';
5
 
6
- function __construct( ) {
7
- $this->render_page( );
8
  }
9
- function render_page( ) {
10
  global $siteguard_config, $siteguard_captcha;
11
 
12
  $opt_val_enable = $siteguard_config->get( self::OPT_NAME_ENABLE );
13
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-same-error-submit' ) ) {
14
- $error = false;
15
- $errors = siteguard_check_multisite( );
16
  if ( is_wp_error( $errors ) ) {
17
  echo '<div class="error settings-error"><p><strong>';
18
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
19
  echo '</strong></p></div>';
20
  $error = true;
21
  }
22
  if ( false === $error && '1' === $_POST[ self::OPT_NAME_ENABLE ] ) {
23
- $ret = $siteguard_captcha->check_requirements( );
24
  if ( is_wp_error( $ret ) ) {
25
- echo '<div class="error settings-error"><p><strong>' . $ret->get_error_message( ) . '</strong></p></div>';
26
  $error = true;
27
  $siteguard_config->set( self::OPT_NAME_ENABLE, '0' );
28
- $siteguard_config->update( );
29
  }
30
  }
31
  if ( false === $error && false === $this->is_switch_value( $_POST[ self::OPT_NAME_ENABLE ] ) ) {
@@ -35,9 +35,9 @@ class SiteGuard_Menu_Same_Error extends SiteGuard_Base {
35
  $error = true;
36
  }
37
  if ( false === $error ) {
38
- $opt_val_enable = $_POST[ self::OPT_NAME_ENABLE ];
39
- $siteguard_config->set( self::OPT_NAME_ENABLE, $opt_val_enable );
40
- $siteguard_config->update( );
41
  ?>
42
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
43
  <?php
@@ -62,18 +62,18 @@ class SiteGuard_Menu_Same_Error extends SiteGuard_Base {
62
  <th scope="row" colspan="2">
63
  <ul class="siteguard-radios">
64
  <li>
65
- <input type="radio" name="<?php echo self::OPT_NAME_ENABLE ?>" id="<?php echo self::OPT_NAME_ENABLE.'_on' ?>" value="1" <?php checked( $opt_val_enable, '1' ) ?> >
66
- <label for="<?php echo self::OPT_NAME_ENABLE.'_on' ?>"><?php esc_html_e( 'ON', 'siteguard' ) ?></label>
67
  </li><li>
68
- <input type="radio" name="<?php echo self::OPT_NAME_ENABLE ?>" id="<?php echo self::OPT_NAME_ENABLE.'_off' ?>" value="0" <?php checked( $opt_val_enable, '0' ) ?> >
69
- <label for="<?php echo self::OPT_NAME_ENABLE.'_off' ?>"><?php esc_html_e( 'OFF', 'siteguard' ) ?></label>
70
  </li>
71
  </ul>
72
  <?php
73
- $error = siteguard_check_multisite( );
74
  if ( is_wp_error( $error ) ) {
75
  echo '<p class="description">';
76
- echo $error->get_error_message( );
77
  echo '</p>';
78
  }
79
  ?>
@@ -82,7 +82,7 @@ class SiteGuard_Menu_Same_Error extends SiteGuard_Base {
82
  </table>
83
  <input type="hidden" name="update" value="Y">
84
  <div class="siteguard-description">
85
- <?php esc_html_e( 'It is the function to decrease the vulnerability against the attack to examine if a user name exists. All error messages about the login should be equalized. The single error message is displayed even if anyone of a username, password, or CAPTCHA is wrong.', 'siteguard' ) ?>
86
  </div>
87
  <hr />
88
 
1
  <?php
2
 
3
  class SiteGuard_Menu_Same_Error extends SiteGuard_Base {
4
+ const OPT_NAME_ENABLE = 'same_login_error';
5
 
6
+ function __construct() {
7
+ $this->render_page();
8
  }
9
+ function render_page() {
10
  global $siteguard_config, $siteguard_captcha;
11
 
12
  $opt_val_enable = $siteguard_config->get( self::OPT_NAME_ENABLE );
13
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-same-error-submit' ) ) {
14
+ $error = false;
15
+ $errors = siteguard_check_multisite();
16
  if ( is_wp_error( $errors ) ) {
17
  echo '<div class="error settings-error"><p><strong>';
18
+ echo esc_html( $errors->get_error_message() );
19
  echo '</strong></p></div>';
20
  $error = true;
21
  }
22
  if ( false === $error && '1' === $_POST[ self::OPT_NAME_ENABLE ] ) {
23
+ $ret = $siteguard_captcha->check_requirements();
24
  if ( is_wp_error( $ret ) ) {
25
+ echo '<div class="error settings-error"><p><strong>' . esc_html( $ret->get_error_message() ) . '</strong></p></div>';
26
  $error = true;
27
  $siteguard_config->set( self::OPT_NAME_ENABLE, '0' );
28
+ $siteguard_config->update();
29
  }
30
  }
31
  if ( false === $error && false === $this->is_switch_value( $_POST[ self::OPT_NAME_ENABLE ] ) ) {
35
  $error = true;
36
  }
37
  if ( false === $error ) {
38
+ $opt_val_enable = sanitize_text_field( $_POST[ self::OPT_NAME_ENABLE ] );
39
+ $siteguard_config->set( self::OPT_NAME_ENABLE, $opt_val_enable );
40
+ $siteguard_config->update();
41
  ?>
42
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
43
  <?php
62
  <th scope="row" colspan="2">
63
  <ul class="siteguard-radios">
64
  <li>
65
+ <input type="radio" name="<?php echo self::OPT_NAME_ENABLE; ?>" id="<?php echo self::OPT_NAME_ENABLE . '_on'; ?>" value="1" <?php checked( $opt_val_enable, '1' ); ?> >
66
+ <label for="<?php echo self::OPT_NAME_ENABLE . '_on'; ?>"><?php esc_html_e( 'ON', 'siteguard' ); ?></label>
67
  </li><li>
68
+ <input type="radio" name="<?php echo self::OPT_NAME_ENABLE; ?>" id="<?php echo self::OPT_NAME_ENABLE . '_off'; ?>" value="0" <?php checked( $opt_val_enable, '0' ); ?> >
69
+ <label for="<?php echo self::OPT_NAME_ENABLE . '_off'; ?>"><?php esc_html_e( 'OFF', 'siteguard' ); ?></label>
70
  </li>
71
  </ul>
72
  <?php
73
+ $error = siteguard_check_multisite();
74
  if ( is_wp_error( $error ) ) {
75
  echo '<p class="description">';
76
+ echo esc_html( $error->get_error_message() );
77
  echo '</p>';
78
  }
79
  ?>
82
  </table>
83
  <input type="hidden" name="update" value="Y">
84
  <div class="siteguard-description">
85
+ <?php esc_html_e( 'It is the function to decrease the vulnerability against the attack to examine if a user name exists. All error messages about the login should be equalized. The single error message is displayed even if anyone of a username, password, or CAPTCHA is wrong.', 'siteguard' ); ?>
86
  </div>
87
  <hr />
88
 
admin/siteguard-menu-updates-notify.php CHANGED
@@ -1,13 +1,13 @@
1
  <?php
2
 
3
  class SiteGuard_Menu_Updates_Notify extends SiteGuard_Base {
4
- const OPT_NAME_ENABLE = 'updates_notify_enable';
5
- const OPT_NAME_WPCORE = 'notify_wpcore';
6
- const OPT_NAME_PLUGINS = 'notify_plugins';
7
- const OPT_NAME_THEMES = 'notify_themes';
8
 
9
- function __construct( ) {
10
- $this->render_page( );
11
  }
12
  function is_notify_value( $value ) {
13
  $items = array( '0', '1', '2' );
@@ -16,7 +16,7 @@ class SiteGuard_Menu_Updates_Notify extends SiteGuard_Base {
16
  }
17
  return false;
18
  }
19
- function render_page( ) {
20
  global $siteguard_config, $siteguard_updates_notify;
21
 
22
  $opt_val_enable = $siteguard_config->get( self::OPT_NAME_ENABLE );
@@ -24,47 +24,47 @@ class SiteGuard_Menu_Updates_Notify extends SiteGuard_Base {
24
  $opt_val_plugins = $siteguard_config->get( self::OPT_NAME_PLUGINS );
25
  $opt_val_themes = $siteguard_config->get( self::OPT_NAME_THEMES );
26
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-updates-notify-submit' ) ) {
27
- $error = false;
28
- $errors = siteguard_check_multisite( );
29
  if ( is_wp_error( $errors ) ) {
30
  echo '<div class="error settings-error"><p><strong>';
31
- esc_html_e( $errors->get_error_message( ), 'siteguard' );
32
  echo '</strong></p></div>';
33
  $error = true;
34
  }
35
  if ( ( false === $error )
36
  && ( ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_ENABLE ] ) )
37
- || ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_WPCORE ] ) )
38
- || ( false === $this->is_notify_value( $_POST[ self::OPT_NAME_PLUGINS ] ) )
39
- || ( false === $this->is_notify_value( $_POST[ self::OPT_NAME_THEMES ] ) ) ) ) {
40
  echo '<div class="error settings-error"><p><strong>';
41
  esc_html_e( 'ERROR: Invalid input value.', 'siteguard' );
42
  echo '</strong></p></div>';
43
  $error = true;
44
  }
45
  if ( false === $error && '1' === $_POST[ self::OPT_NAME_ENABLE ] ) {
46
- $ret = $siteguard_updates_notify->check_requirements( );
47
  if ( is_wp_error( $ret ) ) {
48
- echo '<div class="error settings-error"><p><strong>' . $ret->get_error_message( ) . '</strong></p></div>';
49
  $error = true;
50
  $siteguard_config->set( self::OPT_NAME_ENABLE, '0' );
51
- $siteguard_config->update( );
52
  }
53
  }
54
  if ( false === $error ) {
55
- $opt_val_enable = $_POST[ self::OPT_NAME_ENABLE ];
56
- $opt_val_wpcore = $_POST[ self::OPT_NAME_WPCORE ];
57
- $opt_val_plugins = $_POST[ self::OPT_NAME_PLUGINS ];
58
- $opt_val_themes = $_POST[ self::OPT_NAME_THEMES ];
59
- $siteguard_config->set( self::OPT_NAME_ENABLE, $opt_val_enable );
60
- $siteguard_config->set( self::OPT_NAME_WPCORE, $opt_val_wpcore );
61
  $siteguard_config->set( self::OPT_NAME_PLUGINS, $opt_val_plugins );
62
- $siteguard_config->set( self::OPT_NAME_THEMES, $opt_val_themes );
63
- $siteguard_config->update( );
64
  if ( '1' === $opt_val_enable ) {
65
- SiteGuard_UpdatesNotify::feature_on( );
66
  } else {
67
- SiteGuard_UpdatesNotify::feature_off( );
68
  }
69
  ?>
70
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
@@ -90,18 +90,18 @@ class SiteGuard_Menu_Updates_Notify extends SiteGuard_Base {
90
  <th scope="row" colspan="2">
91
  <ul class="siteguard-radios">
92
  <li>
93
- <input type="radio" name="<?php echo self::OPT_NAME_ENABLE ?>" id="<?php echo self::OPT_NAME_ENABLE.'_on' ?>" value="1" <?php checked( $opt_val_enable, '1' ) ?> >
94
- <label for="<?php echo self::OPT_NAME_ENABLE.'_on' ?>"><?php esc_html_e( 'ON', 'siteguard' ) ?></label>
95
  </li><li>
96
- <input type="radio" name="<?php echo self::OPT_NAME_ENABLE ?>" id="<?php echo self::OPT_NAME_ENABLE.'_off' ?>" value="0" <?php checked( $opt_val_enable, '0' ) ?> >
97
- <label for="<?php echo self::OPT_NAME_ENABLE.'_off' ?>"><?php esc_html_e( 'OFF', 'siteguard' ) ?></label>
98
  </li>
99
  </ul>
100
  <?php
101
- $error = $siteguard_updates_notify->check_requirements( );
102
  if ( is_wp_error( $error ) ) {
103
  echo '<p class="description">';
104
- echo $error->get_error_message( );
105
  echo '</p>';
106
  }
107
  ?>
@@ -109,47 +109,47 @@ class SiteGuard_Menu_Updates_Notify extends SiteGuard_Base {
109
  </tr><tr>
110
  <th scope="row"><?php esc_html_e( 'WordPress updates', 'siteguard' ); ?></th>
111
  <td>
112
- <input type="radio" name="<?php echo self::OPT_NAME_WPCORE ?>" id="<?php echo self::OPT_NAME_WPCORE.'_0' ?>" value="0" <?php checked( $opt_val_wpcore, '0' ) ?> >
113
- <label for="<?php echo self::OPT_NAME_WPCORE.'_0' ?>"><?php esc_html_e( 'Disable', 'siteguard' ) ?></label>
114
  <br />
115
- <input type="radio" name="<?php echo self::OPT_NAME_WPCORE ?>" id="<?php echo self::OPT_NAME_WPCORE.'_1' ?>" value="1" <?php checked( $opt_val_wpcore, '1' ) ?> >
116
- <label for="<?php echo self::OPT_NAME_WPCORE.'_1' ?>"><?php esc_html_e( 'Enable', 'siteguard' ) ?></label>
117
  </td>
118
  </tr><tr>
119
  <th scope="row"><?php esc_html_e( 'Plugins updates', 'siteguard' ); ?></th>
120
  <td>
121
- <input type="radio" name="<?php echo self::OPT_NAME_PLUGINS ?>" id="<?php echo self::OPT_NAME_PLUGINS.'_0' ?>" value="0" <?php checked( $opt_val_plugins, '0' ) ?> >
122
- <label for="<?php echo self::OPT_NAME_PLUGINS.'_0' ?>"><?php esc_html_e( 'Disable', 'siteguard' ) ?></label>
123
  <br />
124
- <input type="radio" name="<?php echo self::OPT_NAME_PLUGINS ?>" id="<?php echo self::OPT_NAME_PLUGINS.'_1' ?>" value="1" <?php checked( $opt_val_plugins, '1' ) ?> >
125
- <label for="<?php echo self::OPT_NAME_PLUGINS.'_1' ?>"><?php esc_html_e( 'All plugins', 'siteguard' ) ?></label>
126
  <br />
127
- <input type="radio" name="<?php echo self::OPT_NAME_PLUGINS ?>" id="<?php echo self::OPT_NAME_PLUGINS.'_2' ?>" value="2" <?php checked( $opt_val_plugins, '2' ) ?> >
128
- <label for="<?php echo self::OPT_NAME_PLUGINS.'_2' ?>"><?php esc_html_e( 'Active plugins only', 'siteguard' ) ?></label>
129
  </td>
130
  </tr><tr>
131
  <th scope="row"><?php esc_html_e( 'Themes updates', 'siteguard' ); ?></th>
132
  <td>
133
- <input type="radio" name="<?php echo self::OPT_NAME_THEMES ?>" id="<?php echo self::OPT_NAME_THEMES.'_0' ?>" value="0" <?php checked( $opt_val_themes, '0' ) ?> >
134
- <label for="<?php echo self::OPT_NAME_THEMES.'_0' ?>"><?php esc_html_e( 'Disable', 'siteguard' ) ?></label>
135
  <br />
136
- <input type="radio" name="<?php echo self::OPT_NAME_THEMES ?>" id="<?php echo self::OPT_NAME_THEMES.'_1' ?>" value="1" <?php checked( $opt_val_themes, '1' ) ?> >
137
- <label for="<?php echo self::OPT_NAME_THEMES.'_1' ?>"><?php esc_html_e( 'All themes', 'siteguard' ) ?></label>
138
  <br />
139
- <input type="radio" name="<?php echo self::OPT_NAME_THEMES ?>" id="<?php echo self::OPT_NAME_THEMES.'_2' ?>" value="2" <?php checked( $opt_val_themes, '2' ) ?> >
140
- <label for="<?php echo self::OPT_NAME_THEMES.'_2' ?>"><?php esc_html_e( 'Active themes only', 'siteguard' ) ?></label>
141
  </td>
142
  </tr>
143
  </table>
144
  <div class="siteguard-description">
145
- <?php esc_html_e( 'Basic of security is that always you use the latest version. If WordPress core, plugins, and themes updates are needed , sends email to notify administrators. Check for updates will be run every 24 hours.', 'siteguard' ) ?>
146
  </div>
147
  <hr />
148
  <input type="hidden" name="update" value="Y">
149
 
150
  <?php
151
  wp_nonce_field( 'siteguard-menu-updates-notify-submit' );
152
- submit_button( );
153
  ?>
154
 
155
  </form>
1
  <?php
2
 
3
  class SiteGuard_Menu_Updates_Notify extends SiteGuard_Base {
4
+ const OPT_NAME_ENABLE = 'updates_notify_enable';
5
+ const OPT_NAME_WPCORE = 'notify_wpcore';
6
+ const OPT_NAME_PLUGINS = 'notify_plugins';
7
+ const OPT_NAME_THEMES = 'notify_themes';
8
 
9
+ function __construct() {
10
+ $this->render_page();
11
  }
12
  function is_notify_value( $value ) {
13
  $items = array( '0', '1', '2' );
16
  }
17
  return false;
18
  }
19
+ function render_page() {
20
  global $siteguard_config, $siteguard_updates_notify;
21
 
22
  $opt_val_enable = $siteguard_config->get( self::OPT_NAME_ENABLE );
24
  $opt_val_plugins = $siteguard_config->get( self::OPT_NAME_PLUGINS );
25
  $opt_val_themes = $siteguard_config->get( self::OPT_NAME_THEMES );
26
  if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-updates-notify-submit' ) ) {
27
+ $error = false;
28
+ $errors = siteguard_check_multisite();
29
  if ( is_wp_error( $errors ) ) {
30
  echo '<div class="error settings-error"><p><strong>';
31
+ echo esc_html( $errors->get_error_message() );
32
  echo '</strong></p></div>';
33
  $error = true;
34
  }
35
  if ( ( false === $error )
36
  && ( ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_ENABLE ] ) )
37
+ || ( false === $this->is_switch_value( $_POST[ self::OPT_NAME_WPCORE ] ) )
38
+ || ( false === $this->is_notify_value( $_POST[ self::OPT_NAME_PLUGINS ] ) )
39
+ || ( false === $this->is_notify_value( $_POST[ self::OPT_NAME_THEMES ] ) ) ) ) {
40
  echo '<div class="error settings-error"><p><strong>';
41
  esc_html_e( 'ERROR: Invalid input value.', 'siteguard' );
42
  echo '</strong></p></div>';
43
  $error = true;
44
  }
45
  if ( false === $error && '1' === $_POST[ self::OPT_NAME_ENABLE ] ) {
46
+ $ret = $siteguard_updates_notify->check_requirements();
47
  if ( is_wp_error( $ret ) ) {
48
+ echo '<div class="error settings-error"><p><strong>' . esc_html( $ret->get_error_message() ) . '</strong></p></div>';
49
  $error = true;
50
  $siteguard_config->set( self::OPT_NAME_ENABLE, '0' );
51
+ $siteguard_config->update();
52
  }
53
  }
54
  if ( false === $error ) {
55
+ $opt_val_enable = sanitize_text_field( $_POST[ self::OPT_NAME_ENABLE ] );
56
+ $opt_val_wpcore = sanitize_text_field( $_POST[ self::OPT_NAME_WPCORE ] );
57
+ $opt_val_plugins = sanitize_text_field( $_POST[ self::OPT_NAME_PLUGINS ] );
58
+ $opt_val_themes = sanitize_text_field( $_POST[ self::OPT_NAME_THEMES ] );
59
+ $siteguard_config->set( self::OPT_NAME_ENABLE, $opt_val_enable );
60
+ $siteguard_config->set( self::OPT_NAME_WPCORE, $opt_val_wpcore );
61
  $siteguard_config->set( self::OPT_NAME_PLUGINS, $opt_val_plugins );
62
+ $siteguard_config->set( self::OPT_NAME_THEMES, $opt_val_themes );
63
+ $siteguard_config->update();
64
  if ( '1' === $opt_val_enable ) {
65
+ SiteGuard_UpdatesNotify::feature_on();
66
  } else {
67
+ SiteGuard_UpdatesNotify::feature_off();
68
  }
69
  ?>
70
  <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div>
90
  <th scope="row" colspan="2">
91
  <ul class="siteguard-radios">
92
  <li>
93
+ <input type="radio" name="<?php echo self::OPT_NAME_ENABLE; ?>" id="<?php echo self::OPT_NAME_ENABLE . '_on'; ?>" value="1" <?php checked( $opt_val_enable, '1' ); ?> >
94
+ <label for="<?php echo self::OPT_NAME_ENABLE . '_on'; ?>"><?php esc_html_e( 'ON', 'siteguard' ); ?></label>
95
  </li><li>
96
+ <input type="radio" name="<?php echo self::OPT_NAME_ENABLE; ?>" id="<?php echo self::OPT_NAME_ENABLE . '_off'; ?>" value="0" <?php checked( $opt_val_enable, '0' ); ?> >
97
+ <label for="<?php echo self::OPT_NAME_ENABLE . '_off'; ?>"><?php esc_html_e( 'OFF', 'siteguard' ); ?></label>
98
  </li>
99
  </ul>
100
  <?php
101
+ $error = $siteguard_updates_notify->check_requirements();
102
  if ( is_wp_error( $error ) ) {
103
  echo '<p class="description">';
104
+ echo esc_html( $error->get_error_message() );
105
  echo '</p>';
106
  }
107
  ?>
109
  </tr><tr>
110
  <th scope="row"><?php esc_html_e( 'WordPress updates', 'siteguard' ); ?></th>
111
  <td>
112
+ <input type="radio" name="<?php echo self::OPT_NAME_WPCORE; ?>" id="<?php echo self::OPT_NAME_WPCORE . '_0'; ?>" value="0" <?php checked( $opt_val_wpcore, '0' ); ?> >
113
+ <label for="<?php echo self::OPT_NAME_WPCORE . '_0'; ?>"><?php esc_html_e( 'Disable', 'siteguard' ); ?></label>
114
  <br />
115
+ <input type="radio" name="<?php echo self::OPT_NAME_WPCORE; ?>" id="<?php echo self::OPT_NAME_WPCORE . '_1'; ?>" value="1" <?php checked( $opt_val_wpcore, '1' ); ?> >
116
+ <label for="<?php echo self::OPT_NAME_WPCORE . '_1'; ?>"><?php esc_html_e( 'Enable', 'siteguard' ); ?></label>
117
  </td>
118
  </tr><tr>
119
  <th scope="row"><?php esc_html_e( 'Plugins updates', 'siteguard' ); ?></th>
120
  <td>
121
+ <input type="radio" name="<?php echo self::OPT_NAME_PLUGINS; ?>" id="<?php echo self::OPT_NAME_PLUGINS . '_0'; ?>" value="0" <?php checked( $opt_val_plugins, '0' ); ?> >
122
+ <label for="<?php echo self::OPT_NAME_PLUGINS . '_0'; ?>"><?php esc_html_e( 'Disable', 'siteguard' ); ?></label>
123
  <br />
124
+ <input type="radio" name="<?php echo self::OPT_NAME_PLUGINS; ?>" id="<?php echo self::OPT_NAME_PLUGINS . '_1'; ?>" value="1" <?php checked( $opt_val_plugins, '1' ); ?> >
125
+ <label for="<?php echo self::OPT_NAME_PLUGINS . '_1'; ?>"><?php esc_html_e( 'All plugins', 'siteguard' ); ?></label>
126
  <br />
127
+ <input type="radio" name="<?php echo self::OPT_NAME_PLUGINS; ?>" id="<?php echo self::OPT_NAME_PLUGINS . '_2'; ?>" value="2" <?php checked( $opt_val_plugins, '2' ); ?> >
128
+ <label for="<?php echo self::OPT_NAME_PLUGINS . '_2'; ?>"><?php esc_html_e( 'Active plugins only', 'siteguard' ); ?></label>
129
  </td>
130
  </tr><tr>
131
  <th scope="row"><?php esc_html_e( 'Themes updates', 'siteguard' ); ?></th>
132
  <td>
133
+ <input type="radio" name="<?php echo self::OPT_NAME_THEMES; ?>" id="<?php echo self::OPT_NAME_THEMES . '_0'; ?>" value="0" <?php checked( $opt_val_themes, '0' ); ?> >
134
+ <label for="<?php echo self::OPT_NAME_THEMES . '_0'; ?>"><?php esc_html_e( 'Disable', 'siteguard' ); ?></label>
135
  <br />
136
+ <input type="radio" name="<?php echo self::OPT_NAME_THEMES; ?>" id="<?php echo self::OPT_NAME_THEMES . '_1'; ?>" value="1" <?php checked( $opt_val_themes, '1' ); ?> >
137
+ <label for="<?php echo self::OPT_NAME_THEMES . '_1'; ?>"><?php esc_html_e( 'All themes', 'siteguard' ); ?></label>
138
  <br />
139
+ <input type="radio" name="<?php echo self::OPT_NAME_THEMES; ?>" id="<?php echo self::OPT_NAME_THEMES . '_2'; ?>" value="2" <?php checked( $opt_val_themes, '2' ); ?> >
140
+ <label for="<?php echo self::OPT_NAME_THEMES . '_2'; ?>"><?php esc_html_e( 'Active themes only', 'siteguard' ); ?></label>
141
  </td>
142
  </tr>
143
  </table>
144
  <div class="siteguard-description">
145
+ <?php esc_html_e( 'Basic of security is that always you use the latest version. If WordPress core, plugins, and themes updates are needed , sends email to notify administrators. Check for updates will be run every 24 hours.', 'siteguard' ); ?>
146
  </div>
147
  <hr />
148
  <input type="hidden" name="update" value="Y">
149
 
150
  <?php
151
  wp_nonce_field( 'siteguard-menu-updates-notify-submit' );
152
+ submit_button();
153
  ?>
154
 
155
  </form>
admin/siteguard-menu-waf-tuning-support.php CHANGED
@@ -1,77 +1,79 @@
1
  <?php
2
 
3
- require_once( 'siteguard-waf-exclude-rule-table.php' );
4
 
5
  class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
6
  protected $wp_list_table;
7
- function __construct( ) {
8
- $this->wp_list_table = new SiteGuard_WAF_Exclude_Rule_Table( );
9
- $this->wp_list_table->prepare_items( );
10
- $this->render_page( );
11
  }
12
  // convert from URL to PATH
13
  function set_filename( $filename ) {
14
  $base = basename( $filename );
15
  $base = str_replace( '"', '', $base );
16
  $base = trim( $base );
17
- $idx = strpos( $base, '?' );
18
  if ( false !== $idx ) {
19
  return substr( $base, 0, $idx );
20
  } else {
21
  return $base;
22
  }
23
  }
24
- function htaccess_error( ) {
25
  echo '<div class="error settings-error"><p><strong>';
26
  esc_html_e( 'ERROR: Failed to .htaccess update.', 'siteguard' );
27
  echo '</strong></p></div>';
28
  }
29
- function render_page( ) {
30
  global $siteguard_waf_exclude_rule;
31
- isset( $_GET['action'] ) ? $action = $_GET['action'] : $action = 'list';
32
  if ( 'list' == $action && isset( $_POST['action'] ) ) {
33
- $action = $_POST['action'];
34
  }
35
  if ( ! in_array( $action, array( 'list', 'add', 'edit', 'delete' ) ) ) {
36
  $action = 'list';
37
  }
38
 
39
- $waf_exclude_rule_enable = $siteguard_waf_exclude_rule->get_enable( );
40
  if ( 'edit' == $action && isset( $_GET['rule'] ) ) {
41
  $offset = 0;
42
- $id = intval( $_GET['rule'] );
43
- $rule = $siteguard_waf_exclude_rule->get_rule( $id, $offset );
44
  if ( false === $rule ) {
45
- $filename = '';
46
- $sig = '';
47
- $comment = '';
48
  } else {
49
- $filename = $rule['filename'];
50
- $sig = $rule['sig'];
51
- $comment = $rule['comment'];
52
  }
53
- } else if ( 'delete' == $action ) {
54
  if ( isset( $_GET['rule'] ) ) {
55
  $ids = array( $_GET['rule'] );
56
- } else if ( isset( $_POST['rule'] ) ) {
57
- $ids = $_POST['rule'];
 
 
58
  }
59
  } else {
60
- $filename = '';
61
- $sig = '';
62
- $comment = '';
63
  }
64
  if ( isset( $_POST['update'] ) ) {
65
- $update = $_POST['update'];
66
  switch ( $update ) {
67
  case 'add':
68
  if ( check_admin_referer( 'siteguard-menu-waf-tuning-support-add' ) ) {
69
- $error = false;
70
- $errors = siteguard_check_multisite( );
71
  if ( is_wp_error( $errors ) ) {
72
  $error = true;
73
  }
74
- if ( true == $error || ! isset( $_POST['filename'] ) || ! isset( $_POST['sig'] ) || ! isset( $_POST['comment'] ) ) {
75
  // error
76
  if ( true === $error ) {
77
  siteguard_error_log( 'multisite enabled: ' . __FILENAME__ );
@@ -80,20 +82,20 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
80
  siteguard_error_log( 'post value sig not set: ' . __FILENAME__ );
81
  }
82
  } else {
83
- $filename = $this->set_filename( stripslashes( $_POST['filename'] ) );
84
- $sig = stripslashes( $_POST['sig'] );
85
- $comment = stripslashes( $_POST['comment'] );
86
 
87
  $errors = $siteguard_waf_exclude_rule->add_rule( $filename, $sig, $comment );
88
  if ( ! is_wp_error( $errors ) ) {
89
  if ( $waf_exclude_rule_enable ) {
90
- if ( false === $siteguard_waf_exclude_rule->feature_on( ) ) {
91
- $this->htaccess_error( );
92
  }
93
  }
94
  echo '<div class="updated"><p><strong>' . esc_html__( 'New rule created', 'siteguard' ) . '</strong></p></div>';
95
  $action = 'list';
96
- $this->wp_list_table->prepare_items( );
97
  } else {
98
  $action = 'add';
99
  }
@@ -102,23 +104,23 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
102
  break;
103
  case 'edit':
104
  if ( check_admin_referer( 'siteguard-menu-waf-tuning-support-edit' ) ) {
105
- if ( ! isset( $_POST['rule'] ) || ! isset( $_POST['filename'] ) || ! isset( $_POST['sig'] ) || ! isset( $_POST['comment'] ) ) {
106
  // error
107
  } else {
108
- $id = $_POST['rule'];
109
- $filename = $this->set_filename( stripslashes( $_POST['filename'] ) );
110
- $sig = stripslashes( $_POST['sig'] );
111
- $comment = stripslashes( $_POST['comment'] );
112
- $errors = $siteguard_waf_exclude_rule->update_rule( $id, $filename, $sig, $comment );
113
  if ( ! is_wp_error( $errors ) ) {
114
  if ( $waf_exclude_rule_enable ) {
115
- if ( false === $siteguard_waf_exclude_rule->feature_on( ) ) {
116
- $this->htaccess_error( );
117
  }
118
  }
119
  echo '<div class="updated"><p><strong>' . esc_html__( 'Rule updated', 'siteguard' ) . '</strong></p></div>';
120
  $action = 'list';
121
- $this->wp_list_table->prepare_items( );
122
  } else {
123
  $action = 'edit';
124
  }
@@ -133,13 +135,13 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
133
  $ids = $_POST['rule'];
134
  $siteguard_waf_exclude_rule->delete_rule( $ids );
135
  if ( $waf_exclude_rule_enable ) {
136
- if ( false === $siteguard_waf_exclude_rule->feature_on( ) ) {
137
- $this->htaccess_error( );
138
  }
139
  }
140
  echo '<div class="updated"><p><strong>' . esc_html__( 'Rule deleted', 'siteguard' ) . '</strong></p></div>';
141
  $action = 'list';
142
- $this->wp_list_table->prepare_items( );
143
  }
144
  }
145
  break;
@@ -151,8 +153,8 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
151
  if ( ! isset( $_POST['waf_exclude_rule_enable'] ) ) {
152
  // error
153
  } else {
154
- $error = false;
155
- $errors = siteguard_check_multisite( );
156
  if ( is_wp_error( $errors ) ) {
157
  $error = true;
158
  }
@@ -162,8 +164,8 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
162
  echo '</strong></p></div>';
163
  $error = true;
164
  $siteguard_waf_exclude_rule->set_enable( '0' );
165
- if ( false === $siteguard_waf_exclude_rule->feature_off( ) ) {
166
- $this->htaccess_error( );
167
  }
168
  $waf_exclude_rule_enable = '0';
169
  }
@@ -175,15 +177,15 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
175
  }
176
  if ( false === $error ) {
177
  $old_waf_exclude_rule_enable = $waf_exclude_rule_enable;
178
- $waf_exclude_rule_enable = $_POST['waf_exclude_rule_enable'];
179
  $siteguard_waf_exclude_rule->set_enable( $waf_exclude_rule_enable );
180
  if ( '1' == $waf_exclude_rule_enable ) {
181
- $result = $siteguard_waf_exclude_rule->feature_on( );
182
  if ( true === $result ) {
183
  echo '<div class="updated"><p><strong>' . esc_html__( 'Rules applied', 'siteguard' ) . '</strong></p></div>';
184
  }
185
  } else {
186
- $result = $siteguard_waf_exclude_rule->feature_off( );
187
  if ( true === $result ) {
188
  echo '<div class="updated"><p><strong>' . esc_html__( 'Rules unapplied', 'siteguard' ) . '</strong></p></div>';
189
  }
@@ -191,7 +193,7 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
191
  if ( false === $result ) {
192
  $waf_exclude_rule_enable = $old_waf_exclude_rule_enable;
193
  $siteguard_waf_exclude_rule->set_enable( $waf_exclude_rule_enable );
194
- $this->htaccess_error( );
195
  }
196
  }
197
  }
@@ -199,11 +201,13 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
199
  break;
200
  default:
201
  }
202
- } else if ( 'delete' == $action ) {
203
  if ( isset( $_GET['rule'] ) ) {
204
  $ids = array( $_GET['rule'] );
205
- } else if ( isset( $_POST['rule'] ) ) {
206
  $ids = $_POST['rule'];
 
 
207
  }
208
  }
209
 
@@ -212,8 +216,8 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
212
  <div class="error">
213
  <ul>
214
  <?php
215
- foreach ( $errors->get_error_messages( ) as $err ) {
216
- echo "<li>$err</li>\n";
217
  }
218
  ?>
219
  </ul>
@@ -241,18 +245,18 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
241
  <th scope="row" colspan="2">
242
  <ul class="siteguard-radios">
243
  <li>
244
- <input type="radio" name="waf_exclude_rule_enable" id="waf_exclude_rule_enable_on" value="1" <?php checked( $waf_exclude_rule_enable, '1' ) ?> >
245
- <label for="waf_exclude_rule_enable_on"><?php esc_html_e( 'ON', 'siteguard' ) ?></label>
246
  </li><li>
247
- <input type="radio" name="waf_exclude_rule_enable" id="waf_exclude_rule_enable_off" value="0" <?php checked( $waf_exclude_rule_enable, '0' ) ?> >
248
- <label for="waf_exclude_rule_enable_off"><?php esc_html_e( 'OFF', 'siteguard' ) ?></label>
249
  </li>
250
  </ul>
251
  <?php
252
- $error = siteguard_check_multisite( );
253
  if ( is_wp_error( $error ) ) {
254
  echo '<p class="description">';
255
- echo $error->get_error_message( );
256
  echo '</p>';
257
  }
258
  echo '<p class="description">';
@@ -262,11 +266,16 @@ class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
262
  </th>
263
  </table>
264
  <?php
265
- $this->wp_list_table->display( );
266
  ?>
267
  <div class="siteguard-description">
268
- <?php esc_html_e( 'It is the function to create the rule to avoid the false detection in WordPress (including 403 error occurrence with normal access,) if WAF ( SiteGuard Lite ) by JP-Secure is installed on a Web server. WAF prevents the attack from the outside against the Web server, but for some WordPress or plugin functions, WAF may detect the attack which is actually not attack and block the function.
269
- By creating the WAF exclude rule, the WAF protection function can be activated while the false detection for the specified function is prevented.', 'siteguard' ) ?>
 
 
 
 
 
270
  </div>
271
  <hr />
272
  <?php
@@ -285,26 +294,26 @@ By creating the WAF exclude rule, the WAF protection function can be activated w
285
  echo '<h2>' . esc_html__( 'WAF Exclude Rule Edit', 'siteguard' ) . '</h2>';
286
  }
287
  ?>
288
- <form name="form1" method="post" action="<?php echo esc_url( menu_page_url( 'siteguard_waf_tuning_support', false ) ) ?>">
289
  <table class="form-table">
290
  <tr>
291
- <th scope="row"><label for="sig"><?php esc_html_e( 'Signature', 'siteguard' ) ?></label></th>
292
  <td>
293
- <textarea name="sig" id="sig" style="width:350px;" rows="5" ><?php echo esc_html( $sig ) ?></textarea>
294
- <p class="description"><?php esc_html_e( 'The detected signature name or signature ID is specified. To specify more than one, separate them with new line.', 'siteguard' ) ?></p>
295
  </td>
296
  </tr>
297
  <tr>
298
- <th scope="row"><label for="filename"><?php esc_html_e( 'Filename (optional)', 'siteguard' ) ?></label></th>
299
  <td>
300
- <input type="text" name="filename" id="filename" value="<?php echo esc_attr( $filename ) ?>" class="regular-text code" >
301
- <p class="description"><?php esc_html_e( 'The target file name is specified. URL ( the part before ? ) can also be pasted.', 'siteguard' ) ?></p>
302
  </td>
303
  </tr>
304
  <tr>
305
- <th scope="row"><label for="comment"><?php esc_html_e( 'Comment (optional)', 'siteguard' ) ?></label></th>
306
  <td>
307
- <input type="text" name="comment" id="comment" value="<?php echo esc_attr( $comment ) ?>" class="regular-text" >
308
  </td>
309
  </tr>
310
  </table>
@@ -319,20 +328,20 @@ By creating the WAF exclude rule, the WAF protection function can be activated w
319
  echo '<input type="hidden" name="update" id="update" value="edit">';
320
  echo '<input type="hidden" name="rule" id="rule" value="' . esc_attr( $id ) . '">';
321
  wp_nonce_field( 'siteguard-menu-waf-tuning-support-edit' );
322
- submit_button( );
323
  }
324
  echo '</form>';
325
  break;
326
  case 'delete':
327
  echo '<h2>' . esc_html__( 'WAF Exclude Rule Delete', 'siteguard' ) . '</h2>';
328
  ?>
329
- <form name="form1" method="post" action="<?php echo esc_url( menu_page_url( 'siteguard_waf_tuning_support', false ) ) ?>">
330
  <?php
331
- echo '<p>' .esc_html( _n( 'You have specified this rule for deletion:', 'You have specified these rules for deletion:', count( $ids ), 'siteguard' ) ) . '</p>';
332
  $go_delete = 0;
333
  foreach ( $ids as $id ) {
334
  $offset = 0;
335
- $rule = $siteguard_waf_exclude_rule->get_rule( $id, $offset );
336
  echo '<input type="hidden" name="rule[]" value="' . esc_attr( $id ) . '" />' . esc_html__( 'Signature', 'siteguard' ) . ' : ' . esc_html__( 'Filename', 'siteguard' ) . ' : ' . esc_html__( 'Comment', 'siteguard' ) . ' [' . esc_html( $rule['sig'] ) . ' : ' . esc_html( $rule['filename'] ) . ' : ' . esc_html( $rule['comment'] ) . "]<br />\n";
337
  $go_delete = 1;
338
  }
@@ -341,7 +350,7 @@ By creating the WAF exclude rule, the WAF protection function can be activated w
341
  wp_nonce_field( 'siteguard-menu-waf-tuning-support-delete' );
342
  submit_button( esc_attr__( 'Confirm Deletion', 'siteguard' ) );
343
  } else {
344
- echo '<p>' . esc_html__( 'There are no rules selected for deletion.' , 'siteguard' ) . '</p>';
345
  }
346
  echo '</form>';
347
  break;
1
  <?php
2
 
3
+ require_once 'siteguard-waf-exclude-rule-table.php';
4
 
5
  class SiteGuard_Menu_WAF_Tuning_Support extends SiteGuard_Base {
6
  protected $wp_list_table;
7
+ function __construct() {
8
+ $this->wp_list_table = new SiteGuard_WAF_Exclude_Rule_Table();
9
+ $this->wp_list_table->prepare_items();
10
+ $this->render_page();
11
  }
12
  // convert from URL to PATH
13
  function set_filename( $filename ) {
14
  $base = basename( $filename );
15
  $base = str_replace( '"', '', $base );
16
  $base = trim( $base );
17
+ $idx = strpos( $base, '?' );
18
  if ( false !== $idx ) {
19
  return substr( $base, 0, $idx );
20
  } else {
21
  return $base;
22
  }
23
  }
24
+ function htaccess_error() {
25
  echo '<div class="error settings-error"><p><strong>';
26
  esc_html_e( 'ERROR: Failed to .htaccess update.', 'siteguard' );
27
  echo '</strong></p></div>';
28
  }
29
+ function render_page() {
30
  global $siteguard_waf_exclude_rule;
31
+ isset( $_GET['action'] ) ? $action = sanitize_text_field( $_GET['action'] ) : $action = 'list';
32
  if ( 'list' == $action && isset( $_POST['action'] ) ) {
33
+ $action = sanitize_text_field( $_POST['action'] );
34
  }
35
  if ( ! in_array( $action, array( 'list', 'add', 'edit', 'delete' ) ) ) {
36
  $action = 'list';
37
  }
38
 
39
+ $waf_exclude_rule_enable = $siteguard_waf_exclude_rule->get_enable();
40
  if ( 'edit' == $action && isset( $_GET['rule'] ) ) {
41
  $offset = 0;
42
+ $id = intval( sanitize_text_field( $_GET['rule'] ) );
43
+ $rule = $siteguard_waf_exclude_rule->get_rule( $id, $offset );
44
  if ( false === $rule ) {
45
+ $filename = '';
46
+ $sig = '';
47
+ $comment = '';
48
  } else {
49
+ $filename = $rule['filename'];
50
+ $sig = $rule['sig'];
51
+ $comment = $rule['comment'];
52
  }
53
+ } elseif ( 'delete' == $action ) {
54
  if ( isset( $_GET['rule'] ) ) {
55
  $ids = array( $_GET['rule'] );
56
+ } elseif ( isset( $_POST['rule'] ) ) {
57
+ $ids = $_POST['rule'];
58
+ } else {
59
+ $ids = array();
60
  }
61
  } else {
62
+ $filename = '';
63
+ $sig = '';
64
+ $comment = '';
65
  }
66
  if ( isset( $_POST['update'] ) ) {
67
+ $update = sanitize_text_field( $_POST['update'] );
68
  switch ( $update ) {
69
  case 'add':
70
  if ( check_admin_referer( 'siteguard-menu-waf-tuning-support-add' ) ) {
71
+ $error = false;
72
+ $errors = siteguard_check_multisite();
73
  if ( is_wp_error( $errors ) ) {
74
  $error = true;
75
  }
76
+ if ( true == $error || ! isset( $_POST['filename'] ) || ! isset( $_POST['sig'] ) || ! isset( $_POST['comment'] ) ) {
77
  // error
78
  if ( true === $error ) {
79
  siteguard_error_log( 'multisite enabled: ' . __FILENAME__ );
82
  siteguard_error_log( 'post value sig not set: ' . __FILENAME__ );
83
  }
84
  } else {
85
+ $filename = $this->set_filename( stripslashes( sanitize_text_field( $_POST['filename'] ) ) );
86
+ $sig = stripslashes( sanitize_textarea_field( $_POST['sig'] ) );
87
+ $comment = stripslashes( $_POST['comment'] );
88
 
89
  $errors = $siteguard_waf_exclude_rule->add_rule( $filename, $sig, $comment );
90
  if ( ! is_wp_error( $errors ) ) {
91
  if ( $waf_exclude_rule_enable ) {
92
+ if ( false === $siteguard_waf_exclude_rule->feature_on() ) {
93
+ $this->htaccess_error();
94
  }
95
  }
96
  echo '<div class="updated"><p><strong>' . esc_html__( 'New rule created', 'siteguard' ) . '</strong></p></div>';
97
  $action = 'list';
98
+ $this->wp_list_table->prepare_items();
99
  } else {
100
  $action = 'add';
101
  }
104
  break;
105
  case 'edit':
106
  if ( check_admin_referer( 'siteguard-menu-waf-tuning-support-edit' ) ) {
107
+ if ( ! isset( $_POST['rule'] ) || ! isset( $_POST['filename'] ) || ! isset( $_POST['sig'] ) || ! isset( $_POST['comment'] ) ) {
108
  // error
109
  } else {
110
+ $id = sanitize_text_field( $_POST['rule'] );
111
+ $filename = $this->set_filename( stripslashes( sanitize_text_field( $_POST['filename'] ) ) );
112
+ $sig = stripslashes( sanitize_textarea_field( $_POST['sig'] ) );
113
+ $comment = stripslashes( sanitize_text_field( $_POST['comment'] ) );
114
+ $errors = $siteguard_waf_exclude_rule->update_rule( $id, $filename, $sig, $comment );
115
  if ( ! is_wp_error( $errors ) ) {
116
  if ( $waf_exclude_rule_enable ) {
117
+ if ( false === $siteguard_waf_exclude_rule->feature_on() ) {
118
+ $this->htaccess_error();
119
  }
120
  }
121
  echo '<div class="updated"><p><strong>' . esc_html__( 'Rule updated', 'siteguard' ) . '</strong></p></div>';
122
  $action = 'list';
123
+ $this->wp_list_table->prepare_items();
124
  } else {
125
  $action = 'edit';
126
  }
135
  $ids = $_POST['rule'];
136
  $siteguard_waf_exclude_rule->delete_rule( $ids );
137
  if ( $waf_exclude_rule_enable ) {
138
+ if ( false === $siteguard_waf_exclude_rule->feature_on() ) {
139
+ $this->htaccess_error();
140
  }
141
  }
142
  echo '<div class="updated"><p><strong>' . esc_html__( 'Rule deleted', 'siteguard' ) . '</strong></p></div>';
143
  $action = 'list';
144
+ $this->wp_list_table->prepare_items();
145
  }
146
  }
147
  break;
153
  if ( ! isset( $_POST['waf_exclude_rule_enable'] ) ) {
154
  // error
155
  } else {
156
+ $error = false;
157
+ $errors = siteguard_check_multisite();
158
  if ( is_wp_error( $errors ) ) {
159
  $error = true;
160
  }
164
  echo '</strong></p></div>';
165
  $error = true;
166
  $siteguard_waf_exclude_rule->set_enable( '0' );
167
+ if ( false === $siteguard_waf_exclude_rule->feature_off() ) {
168
+ $this->htaccess_error();
169
  }
170
  $waf_exclude_rule_enable = '0';
171
  }
177
  }
178
  if ( false === $error ) {
179
  $old_waf_exclude_rule_enable = $waf_exclude_rule_enable;
180
+ $waf_exclude_rule_enable = sanitize_text_field( $_POST['waf_exclude_rule_enable'] );
181
  $siteguard_waf_exclude_rule->set_enable( $waf_exclude_rule_enable );
182
  if ( '1' == $waf_exclude_rule_enable ) {
183
+ $result = $siteguard_waf_exclude_rule->feature_on();
184
  if ( true === $result ) {
185
  echo '<div class="updated"><p><strong>' . esc_html__( 'Rules applied', 'siteguard' ) . '</strong></p></div>';
186
  }
187
  } else {
188
+ $result = $siteguard_waf_exclude_rule->feature_off();
189
  if ( true === $result ) {
190
  echo '<div class="updated"><p><strong>' . esc_html__( 'Rules unapplied', 'siteguard' ) . '</strong></p></div>';
191
  }
193
  if ( false === $result ) {
194
  $waf_exclude_rule_enable = $old_waf_exclude_rule_enable;
195
  $siteguard_waf_exclude_rule->set_enable( $waf_exclude_rule_enable );
196
+ $this->htaccess_error();
197
  }
198
  }
199
  }
201
  break;
202
  default:
203
  }
204
+ } elseif ( 'delete' == $action ) {
205
  if ( isset( $_GET['rule'] ) ) {
206
  $ids = array( $_GET['rule'] );
207
+ } elseif ( isset( $_POST['rule'] ) ) {
208
  $ids = $_POST['rule'];
209
+ } else {
210
+ $ids = array();
211
  }
212
  }
213
 
216
  <div class="error">
217
  <ul>
218
  <?php
219
+ foreach ( $errors->get_error_messages() as $err ) {
220
+ echo "<li>" . esc_html( $err ) . "</li>\n";
221
  }
222
  ?>
223
  </ul>
245
  <th scope="row" colspan="2">
246
  <ul class="siteguard-radios">
247
  <li>
248
+ <input type="radio" name="waf_exclude_rule_enable" id="waf_exclude_rule_enable_on" value="1" <?php checked( $waf_exclude_rule_enable, '1' ); ?> >
249
+ <label for="waf_exclude_rule_enable_on"><?php esc_html_e( 'ON', 'siteguard' ); ?></label>
250
  </li><li>
251
+ <input type="radio" name="waf_exclude_rule_enable" id="waf_exclude_rule_enable_off" value="0" <?php checked( $waf_exclude_rule_enable, '0' ); ?> >
252
+ <label for="waf_exclude_rule_enable_off"><?php esc_html_e( 'OFF', 'siteguard' ); ?></label>
253
  </li>
254
  </ul>
255
  <?php
256
+ $error = siteguard_check_multisite();
257
  if ( is_wp_error( $error ) ) {
258
  echo '<p class="description">';
259
+ echo esc_html( $error->get_error_message() );
260
  echo '</p>';
261
  }
262
  echo '<p class="description">';
266
  </th>
267
  </table>
268
  <?php
269
+ $this->wp_list_table->display();
270
  ?>
271
  <div class="siteguard-description">
272
+ <?php
273
+ esc_html_e(
274
+ 'It is the function to create the rule to avoid the false detection in WordPress (including 403 error occurrence with normal access,) if WAF ( SiteGuard Lite ) by JP-Secure is installed on a Web server. WAF prevents the attack from the outside against the Web server, but for some WordPress or plugin functions, WAF may detect the attack which is actually not attack and block the function.
275
+ By creating the WAF exclude rule, the WAF protection function can be activated while the false detection for the specified function is prevented.',
276
+ 'siteguard'
277
+ )
278
+ ?>
279
  </div>
280
  <hr />
281
  <?php
294
  echo '<h2>' . esc_html__( 'WAF Exclude Rule Edit', 'siteguard' ) . '</h2>';
295
  }
296
  ?>
297
+ <form name="form1" method="post" action="<?php echo esc_url( menu_page_url( 'siteguard_waf_tuning_support', false ) ); ?>">
298
  <table class="form-table">
299
  <tr>
300
+ <th scope="row"><label for="sig"><?php esc_html_e( 'Signature', 'siteguard' ); ?></label></th>
301
  <td>
302
+ <textarea name="sig" id="sig" style="width:350px;" rows="5" ><?php echo esc_html( $sig ); ?></textarea>
303
+ <p class="description"><?php esc_html_e( 'The detected signature name or signature ID is specified. To specify more than one, separate them with new line.', 'siteguard' ); ?></p>
304
  </td>
305
  </tr>
306
  <tr>
307
+ <th scope="row"><label for="filename"><?php esc_html_e( 'Filename (optional)', 'siteguard' ); ?></label></th>
308
  <td>
309
+ <input type="text" name="filename" id="filename" value="<?php echo esc_attr( $filename ); ?>" class="regular-text code" >
310
+ <p class="description"><?php esc_html_e( 'The target file name is specified. URL ( the part before ? ) can also be pasted.', 'siteguard' ); ?></p>
311
  </td>
312
  </tr>
313
  <tr>
314
+ <th scope="row"><label for="comment"><?php esc_html_e( 'Comment (optional)', 'siteguard' ); ?></label></th>
315
  <td>
316
+ <input type="text" name="comment" id="comment" value="<?php echo esc_attr( $comment ); ?>" class="regular-text" >
317
  </td>
318
  </tr>
319
  </table>
328
  echo '<input type="hidden" name="update" id="update" value="edit">';
329
  echo '<input type="hidden" name="rule" id="rule" value="' . esc_attr( $id ) . '">';
330
  wp_nonce_field( 'siteguard-menu-waf-tuning-support-edit' );
331
+ submit_button();
332
  }
333
  echo '</form>';
334
  break;
335
  case 'delete':
336
  echo '<h2>' . esc_html__( 'WAF Exclude Rule Delete', 'siteguard' ) . '</h2>';
337
  ?>
338
+ <form name="form1" method="post" action="<?php echo esc_url( menu_page_url( 'siteguard_waf_tuning_support', false ) ); ?>">
339
  <?php
340
+ echo '<p>' . esc_html( _n( 'You have specified this rule for deletion:', 'You have specified these rules for deletion:', count( $ids ), 'siteguard' ) ) . '</p>';
341
  $go_delete = 0;
342
  foreach ( $ids as $id ) {
343
  $offset = 0;
344
+ $rule = $siteguard_waf_exclude_rule->get_rule( sanitize_text_field( $id ), $offset );
345
  echo '<input type="hidden" name="rule[]" value="' . esc_attr( $id ) . '" />' . esc_html__( 'Signature', 'siteguard' ) . ' : ' . esc_html__( 'Filename', 'siteguard' ) . ' : ' . esc_html__( 'Comment', 'siteguard' ) . ' [' . esc_html( $rule['sig'] ) . ' : ' . esc_html( $rule['filename'] ) . ' : ' . esc_html( $rule['comment'] ) . "]<br />\n";
346
  $go_delete = 1;
347
  }
350
  wp_nonce_field( 'siteguard-menu-waf-tuning-support-delete' );
351
  submit_button( esc_attr__( 'Confirm Deletion', 'siteguard' ) );
352
  } else {
353
+ echo '<p>' . esc_html__( 'There are no rules selected for deletion.', 'siteguard' ) . '</p>';
354
  }
355
  echo '</form>';
356
  break;
admin/siteguard-waf-exclude-rule-table.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  if ( ! class_exists( 'WP_List_Table' ) ) {
4
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5
  }
6
 
7
  class SiteGuard_WAF_Exclude_Rule_Table extends WP_List_Table {
@@ -9,12 +9,14 @@ class SiteGuard_WAF_Exclude_Rule_Table extends WP_List_Table {
9
  function __construct() {
10
  global $status, $page;
11
 
12
- //Set parent defaults
13
- parent::__construct( array(
14
- 'singular' => 'rule', //singular name of the listed records
15
- 'plural' => 'rules', //plural name of the listed records
16
- 'ajax' => false, //does this table support ajax?
17
- ) );
 
 
18
 
19
  }
20
 
@@ -24,20 +26,21 @@ class SiteGuard_WAF_Exclude_Rule_Table extends WP_List_Table {
24
  case 'comment':
25
  return esc_html( $item[ $column_name ] );
26
  default:
27
- return print_r( $item, true ); //Show the whole array for troubleshooting purposes
28
  }
29
  }
30
 
31
  function column_sig( $item ) {
32
 
33
- //Build row actions
34
  $actions = array(
35
- 'edit' => '<a href="' . esc_url( sprintf( '?page=%s&action=edit&rule=%s', esc_html( $_REQUEST['page'] ), esc_html( $item['ID'] ) ) ) . '">' . esc_html( __( 'Edit' ) ) . '</a>' ,
36
  'delete' => '<a href="' . esc_url( sprintf( '?page=%s&action=delete&rule=%s', esc_html( $_REQUEST['page'] ), esc_html( $item['ID'] ) ) ) . '">' . esc_html( __( 'Delete' ) ) . '</a>',
37
  );
38
 
39
- //Return the target contents
40
- return sprintf( '%1$s%2$s',
 
41
  /*$1%s*/ esc_html( $item['sig'] ),
42
  /*$2%s*/ $this->row_actions( $actions )
43
  );
@@ -47,32 +50,32 @@ class SiteGuard_WAF_Exclude_Rule_Table extends WP_List_Table {
47
  function column_cb( $item ) {
48
  return sprintf(
49
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
50
- /*$1%s*/ esc_attr( $this->_args['singular'] ), //Let's simply repurpose the table's singular label ("rule")
51
- /*$2%s*/ esc_attr( $item['ID'] ) //The value of the checkbox should be the record's id
52
  );
53
  }
54
 
55
 
56
- function get_columns( ) {
57
  $columns = array(
58
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
59
- 'sig' => esc_html__( 'Signature', 'siteguard' ),
60
- 'filename' => esc_html__( 'Filename', 'siteguard' ),
61
- 'comment' => esc_html__( 'Comment', 'siteguard' ),
62
  );
63
  return $columns;
64
  }
65
 
66
- function get_sortable_columns( ) {
67
  $sortable_columns = array(
68
- 'sig' => array( 'sig', false ),
69
- 'filename' => array( 'filename', false ),
70
- 'comment' => array( 'comment', false ),
71
  );
72
  return $sortable_columns;
73
  }
74
 
75
- function get_bulk_actions( ) {
76
  $actions = array(
77
  'delete' => esc_html__( 'Delete' ),
78
  );
@@ -80,37 +83,37 @@ class SiteGuard_WAF_Exclude_Rule_Table extends WP_List_Table {
80
  }
81
 
82
 
83
- function process_bulk_action( ) {
84
 
85
  return;
86
  }
87
 
88
  function usort_reorder( $a, $b ) {
89
  $orderby_values = array( 'sig', 'filename', 'comment' );
90
- $order_values = array( 'asc', 'desc' );
91
- $orderby = ( ! empty( $_REQUEST['orderby'] ) ) ? ( in_array( $_REQUEST['orderby'], $orderby_values ) ? $_REQUEST['orderby'] : 'sig' ) : 'sig'; //If no sort, default to filename
92
- $order = ( ! empty( $_REQUEST['order'] ) ) ? ( in_array( $_REQUEST['order'], $order_values ) ? $_REQUEST['order'] : 'asc' ) : 'asc'; //If no order, default to asc
93
- $result = strcmp( $a[ $orderby ], $b[ $orderby ] ); //Determine sort order
94
- return ( 'asc' === $order ) ? $result : -$result; //Send final sort direction to usort
95
  }
96
 
97
- function prepare_items( ) {
98
  global $siteguard_waf_exclude_rule;
99
 
100
  $per_page = 5;
101
 
102
- $columns = $this->get_columns( );
103
  $hidden = array();
104
- $sortable = $this->get_sortable_columns( );
105
 
106
  $this->_column_headers = array( $columns, $hidden, $sortable );
107
 
108
- $this->process_bulk_action( );
109
 
110
- $data = $siteguard_waf_exclude_rule->get_rules( );
111
 
112
- $total_items = count( $data );
113
- $current_page = $this->get_pagenum( );
114
 
115
  if ( $total_items > 0 ) {
116
  if ( is_array( $data ) ) {
@@ -121,10 +124,12 @@ class SiteGuard_WAF_Exclude_Rule_Table extends WP_List_Table {
121
 
122
  $this->items = $data;
123
 
124
- $this->set_pagination_args( array(
125
- 'total_items' => $total_items, //WE have to calculate the total number of items
126
- 'per_page' => $per_page, //WE have to determine how many items to show on a page
127
- 'total_pages' => ceil( $total_items / $per_page ), //WE have to calculate the total number of pages
128
- ) );
 
 
129
  }
130
  }
1
  <?php
2
 
3
  if ( ! class_exists( 'WP_List_Table' ) ) {
4
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
  }
6
 
7
  class SiteGuard_WAF_Exclude_Rule_Table extends WP_List_Table {
9
  function __construct() {
10
  global $status, $page;
11
 
12
+ // Set parent defaults
13
+ parent::__construct(
14
+ array(
15
+ 'singular' => 'rule', // singular name of the listed records
16
+ 'plural' => 'rules', // plural name of the listed records
17
+ 'ajax' => false, // does this table support ajax?
18
+ )
19
+ );
20
 
21
  }
22
 
26
  case 'comment':
27
  return esc_html( $item[ $column_name ] );
28
  default:
29
+ return print_r( $item, true ); // Show the whole array for troubleshooting purposes
30
  }
31
  }
32
 
33
  function column_sig( $item ) {
34
 
35
+ // Build row actions
36
  $actions = array(
37
+ 'edit' => '<a href="' . esc_url( sprintf( '?page=%s&action=edit&rule=%s', esc_html( $_REQUEST['page'] ), esc_html( $item['ID'] ) ) ) . '">' . esc_html( __( 'Edit' ) ) . '</a>',
38
  'delete' => '<a href="' . esc_url( sprintf( '?page=%s&action=delete&rule=%s', esc_html( $_REQUEST['page'] ), esc_html( $item['ID'] ) ) ) . '">' . esc_html( __( 'Delete' ) ) . '</a>',
39
  );
40
 
41
+ // Return the target contents
42
+ return sprintf(
43
+ '%1$s%2$s',
44
  /*$1%s*/ esc_html( $item['sig'] ),
45
  /*$2%s*/ $this->row_actions( $actions )
46
  );
50
  function column_cb( $item ) {
51
  return sprintf(
52
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
53
+ /*$1%s*/ esc_attr( $this->_args['singular'] ), // Let's simply repurpose the table's singular label ("rule")
54
+ /*$2%s*/ esc_attr( $item['ID'] ) // The value of the checkbox should be the record's id
55
  );
56
  }
57
 
58
 
59
+ function get_columns() {
60
  $columns = array(
61
+ 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text
62
+ 'sig' => esc_html__( 'Signature', 'siteguard' ),
63
+ 'filename' => esc_html__( 'Filename', 'siteguard' ),
64
+ 'comment' => esc_html__( 'Comment', 'siteguard' ),
65
  );
66
  return $columns;
67
  }
68
 
69
+ function get_sortable_columns() {
70
  $sortable_columns = array(
71
+ 'sig' => array( 'sig', false ),
72
+ 'filename' => array( 'filename', false ),
73
+ 'comment' => array( 'comment', false ),
74
  );
75
  return $sortable_columns;
76
  }
77
 
78
+ function get_bulk_actions() {
79
  $actions = array(
80
  'delete' => esc_html__( 'Delete' ),
81
  );
83
  }
84
 
85
 
86
+ function process_bulk_action() {
87
 
88
  return;
89
  }
90
 
91
  function usort_reorder( $a, $b ) {
92
  $orderby_values = array( 'sig', 'filename', 'comment' );
93
+ $order_values = array( 'asc', 'desc' );
94
+ $orderby = ( ! empty( $_REQUEST['orderby'] ) ) ? ( in_array( $_REQUEST['orderby'], $orderby_values ) ? sanitize_text_field( $_REQUEST['orderby'] ) : 'sig' ) : 'sig'; // If no sort, default to filename
95
+ $order = ( ! empty( $_REQUEST['order'] ) ) ? ( in_array( $_REQUEST['order'], $order_values ) ? sanitize_text_field( $_REQUEST['order'] ) : 'asc' ) : 'asc'; // If no order, default to asc
96
+ $result = strcmp( $a[ $orderby ], $b[ $orderby ] ); // Determine sort order
97
+ return ( 'asc' === $order ) ? $result : -$result; // Send final sort direction to usort
98
  }
99
 
100
+ function prepare_items() {
101
  global $siteguard_waf_exclude_rule;
102
 
103
  $per_page = 5;
104
 
105
+ $columns = $this->get_columns();
106
  $hidden = array();
107
+ $sortable = $this->get_sortable_columns();
108
 
109
  $this->_column_headers = array( $columns, $hidden, $sortable );
110
 
111
+ $this->process_bulk_action();
112
 
113
+ $data = $siteguard_waf_exclude_rule->get_rules();
114
 
115
+ $total_items = count( $data );
116
+ $current_page = $this->get_pagenum();
117
 
118
  if ( $total_items > 0 ) {
119
  if ( is_array( $data ) ) {
124
 
125
  $this->items = $data;
126
 
127
+ $this->set_pagination_args(
128
+ array(
129
+ 'total_items' => $total_items, // WE have to calculate the total number of items
130
+ 'per_page' => $per_page, // WE have to determine how many items to show on a page
131
+ 'total_pages' => ceil( $total_items / $per_page ), // WE have to calculate the total number of pages
132
+ )
133
+ );
134
  }
135
  }
classes/siteguard-admin-filter.php CHANGED
@@ -3,17 +3,17 @@
3
  class SiteGuard_AdminFilter extends SiteGuard_Base {
4
  public static $htaccess_mark = '#==== SITEGUARD_ADMIN_FILTER_SETTINGS';
5
 
6
- function __construct( ) {
7
  define( 'SITEGUARD_TABLE_LOGIN', 'siteguard_login' );
8
  add_action( 'wp_login', array( $this, 'handler_wp_login' ), 1, 2 );
9
  }
10
- static function get_mark( ) {
11
- return SiteGuard_AdminFilter::$htaccess_mark;
12
  }
13
- function init( ) {
14
  global $wpdb, $siteguard_config;
15
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_LOGIN;
16
- $sql = 'CREATE TABLE ' . $table_name . " (
17
  ip_address varchar(40) NOT NULL DEFAULT '',
18
  status INT NOT NULL DEFAULT 0,
19
  count INT NOT NULL DEFAULT 0,
@@ -21,11 +21,11 @@ class SiteGuard_AdminFilter extends SiteGuard_Base {
21
  UNIQUE KEY ip_address (ip_address)
22
  )
23
  CHARACTER SET 'utf8';";
24
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
25
  dbDelta( $sql );
26
  $siteguard_config->set( 'admin_filter_exclude_path', 'css,images,admin-ajax.php,load-styles.php,site-health.php' );
27
  $siteguard_config->set( 'admin_filter_enable', '0' );
28
- $siteguard_config->update( );
29
  }
30
  function handler_wp_login( $login, $current_user ) {
31
  global $siteguard_htaccess, $siteguard_config;
@@ -34,7 +34,7 @@ class SiteGuard_AdminFilter extends SiteGuard_Base {
34
  return;
35
  }
36
  if ( 1 == $siteguard_config->get( 'admin_filter_enable' ) ) {
37
- $this->feature_on( $this->get_ip( ) );
38
  }
39
  }
40
  function cvt_exclude( $exclude ) {
@@ -50,8 +50,8 @@ class SiteGuard_AdminFilter extends SiteGuard_Base {
50
  }
51
  function update_settings( $ip_address ) {
52
  global $wpdb, $siteguard_config;
53
- $htaccess_str = '';
54
- $table_name = $wpdb->prefix . SITEGUARD_TABLE_LOGIN;
55
  $exclude_paths = preg_split( '/,/', $siteguard_config->get( 'admin_filter_exclude_path' ) );
56
 
57
  $now_str = current_time( 'mysql' );
@@ -59,10 +59,10 @@ class SiteGuard_AdminFilter extends SiteGuard_Base {
59
 
60
  $wpdb->query( 'START TRANSACTION' );
61
  $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE status = %d AND last_login_time < SYSDATE() - INTERVAL 1 DAY;", SITEGUARD_LOGIN_SUCCESS ) );
62
- $data = array(
63
- 'ip_address' => $ip_address,
64
- 'status' => SITEGUARD_LOGIN_SUCCESS,
65
- 'count' => 0,
66
  'last_login_time' => $now_str,
67
  );
68
  $result = $wpdb->get_row( $wpdb->prepare( "SELECT status from $table_name WHERE ip_address = %s", $ip_address ) );
@@ -71,7 +71,7 @@ class SiteGuard_AdminFilter extends SiteGuard_Base {
71
  } else {
72
  $wpdb->update( $table_name, $data, array( 'ip_address' => $ip_address ) );
73
  }
74
- $parse_url = parse_url( site_url( ) );
75
  if ( false === $parse_url ) {
76
  $base = '/';
77
  } else {
@@ -94,7 +94,7 @@ class SiteGuard_AdminFilter extends SiteGuard_Base {
94
  $htaccess_str .= $this->get_rewrite_cond( $ip );
95
  }
96
  }
97
- $server_ip = $this->get_server_ip( );
98
  if ( false !== $server_ip ) {
99
  $htaccess_str .= $this->get_rewrite_cond( $server_ip );
100
  }
@@ -109,15 +109,15 @@ class SiteGuard_AdminFilter extends SiteGuard_Base {
109
  }
110
  function feature_on( $ip_address ) {
111
  global $siteguard_htaccess, $siteguard_config;
112
- if ( false === SiteGuard_Htaccess::check_permission( ) ) {
113
  return false;
114
  }
115
- $mark = $this->get_mark( );
116
  $data = $this->update_settings( $ip_address );
117
  return $siteguard_htaccess->update_settings( $mark, $data );
118
  }
119
- static function feature_off( ) {
120
- $mark = SiteGuard_AdminFilter::get_mark( );
121
  return SiteGuard_Htaccess::clear_settings( $mark );
122
  }
123
  }
3
  class SiteGuard_AdminFilter extends SiteGuard_Base {
4
  public static $htaccess_mark = '#==== SITEGUARD_ADMIN_FILTER_SETTINGS';
5
 
6
+ function __construct() {
7
  define( 'SITEGUARD_TABLE_LOGIN', 'siteguard_login' );
8
  add_action( 'wp_login', array( $this, 'handler_wp_login' ), 1, 2 );
9
  }
10
+ static function get_mark() {
11
+ return self::$htaccess_mark;
12
  }
13
+ function init() {
14
  global $wpdb, $siteguard_config;
15
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_LOGIN;
16
+ $sql = 'CREATE TABLE ' . $table_name . " (
17
  ip_address varchar(40) NOT NULL DEFAULT '',
18
  status INT NOT NULL DEFAULT 0,
19
  count INT NOT NULL DEFAULT 0,
21
  UNIQUE KEY ip_address (ip_address)
22
  )
23
  CHARACTER SET 'utf8';";
24
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
25
  dbDelta( $sql );
26
  $siteguard_config->set( 'admin_filter_exclude_path', 'css,images,admin-ajax.php,load-styles.php,site-health.php' );
27
  $siteguard_config->set( 'admin_filter_enable', '0' );
28
+ $siteguard_config->update();
29
  }
30
  function handler_wp_login( $login, $current_user ) {
31
  global $siteguard_htaccess, $siteguard_config;
34
  return;
35
  }
36
  if ( 1 == $siteguard_config->get( 'admin_filter_enable' ) ) {
37
+ $this->feature_on( $this->get_ip() );
38
  }
39
  }
40
  function cvt_exclude( $exclude ) {
50
  }
51
  function update_settings( $ip_address ) {
52
  global $wpdb, $siteguard_config;
53
+ $htaccess_str = '';
54
+ $table_name = $wpdb->prefix . SITEGUARD_TABLE_LOGIN;
55
  $exclude_paths = preg_split( '/,/', $siteguard_config->get( 'admin_filter_exclude_path' ) );
56
 
57
  $now_str = current_time( 'mysql' );
59
 
60
  $wpdb->query( 'START TRANSACTION' );
61
  $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE status = %d AND last_login_time < SYSDATE() - INTERVAL 1 DAY;", SITEGUARD_LOGIN_SUCCESS ) );
62
+ $data = array(
63
+ 'ip_address' => $ip_address,
64
+ 'status' => SITEGUARD_LOGIN_SUCCESS,
65
+ 'count' => 0,
66
  'last_login_time' => $now_str,
67
  );
68
  $result = $wpdb->get_row( $wpdb->prepare( "SELECT status from $table_name WHERE ip_address = %s", $ip_address ) );
71
  } else {
72
  $wpdb->update( $table_name, $data, array( 'ip_address' => $ip_address ) );
73
  }
74
+ $parse_url = parse_url( site_url() );
75
  if ( false === $parse_url ) {
76
  $base = '/';
77
  } else {
94
  $htaccess_str .= $this->get_rewrite_cond( $ip );
95
  }
96
  }
97
+ $server_ip = $this->get_server_ip();
98
  if ( false !== $server_ip ) {
99
  $htaccess_str .= $this->get_rewrite_cond( $server_ip );
100
  }
109
  }
110
  function feature_on( $ip_address ) {
111
  global $siteguard_htaccess, $siteguard_config;
112
+ if ( false === SiteGuard_Htaccess::check_permission() ) {
113
  return false;
114
  }
115
+ $mark = $this->get_mark();
116
  $data = $this->update_settings( $ip_address );
117
  return $siteguard_htaccess->update_settings( $mark, $data );
118
  }
119
+ static function feature_off() {
120
+ $mark = self::get_mark();
121
  return SiteGuard_Htaccess::clear_settings( $mark );
122
  }
123
  }
classes/siteguard-base.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  function siteguard_error_log( $message ) {
4
  $logfile = SITEGUARD_PATH . 'error.log';
5
- $f = @fopen( $logfile, 'a+' );
6
  if ( false != $f ) {
7
  fwrite( $f, date_i18n( 'Y/m/d H:i:s:' ) . $message . "\n" );
8
  fclose( $f );
@@ -12,22 +12,21 @@ function siteguard_error_log( $message ) {
12
  function siteguard_error_dump( $title, $obj ) {
13
  ob_start();
14
  var_dump( $obj );
15
- $msg = ob_get_contents( );
16
- ob_end_clean( );
17
  siteguard_error_log( "$title: $msg" );
18
  }
19
 
20
- function siteguard_check_multisite( ) {
21
  if ( ! is_multisite() ) {
22
  return true;
23
  }
24
- $message = esc_html__( 'It does not support the multisite function of WordPress.', 'siteguard' );
25
- $error = new WP_Error( 'siteguard', $message );
26
  return $error;
27
  }
28
 
29
  class SiteGuard_Base {
30
- public static $ip_mode_items = array( '0', '1', '2', '3' );
31
  function __construct() {
32
  }
33
  function is_switch_value( $value ) {
@@ -36,57 +35,57 @@ class SiteGuard_Base {
36
  }
37
  return false;
38
  }
39
- function cvt_camma2ret( $value ) {
40
- $result = str_replace( ' ', '', $value );
41
- return str_replace( ',', "\r\n", $result );
42
- }
43
- function cvt_ret2camma( $exclude ) {
44
- $result = str_replace( ' ', '', $exclude );
45
- $result = str_replace( ',', '', $result );
46
- $result = preg_replace( '/(\r\n){2,}/', "\r\n", $result );
47
- $result = preg_replace( '/\r\n$/', '', $result );
48
- $result = str_replace( "\r\n", ',', $result );
49
- $result = str_replace( "\r", ',', $result );
50
- return str_replace( "\n", ',', $result );
51
- }
52
  function check_module( $name, $default = false ) {
53
  return true;
54
- # It does not work WP-CLI
55
- #if ( isset( $_SERVER['SERVER_SOFTWARE'] ) ) {
56
- # return ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false);
57
- #} else {
58
- # return $default;
59
- #}
60
 
61
- # It does not work in FastCGI well.
62
- #$module = 'mod_' . $name;
63
- #return apache_mod_loaded( $module, $default );
64
- #if ( function_exists('phpinfo') ) {
65
- # ob_start( );
66
- # phpinfo(8);
67
- # $phpinfo = ob_get_clean( );
68
- # if ( false !== strpos( $phpinfo, $module ) ) {
69
- # return true;
70
- # }
71
- #}
72
- #return $default;
73
  }
74
  function is_private_ip( $ip ) {
75
  $private_ips = array(
76
  '10.0.0.0,10.255.255.255',
77
  '172.16.0.0,172.31.255.255',
78
- '192.168.0.0,192.168.255.255'
79
  );
80
 
81
  $long_ip = ip2long( $ip );
82
  if ( -1 !== $long_ip && false !== $long_ip ) {
83
  $long_ip = sprintf( '%u', $long_ip );
84
- foreach( $private_ips as $private_ip ) {
85
  list( $start, $end ) = explode( ',', $private_ip );
86
- $long_start = ip2long( $start );
87
- $long_start = sprintf( '%u', $long_start );
88
- $long_end = ip2long( $end );
89
- $long_end = sprintf( '%u', $long_end );
90
  if ( $long_ip >= $long_start && $long_ip <= $long_end ) {
91
  return true;
92
  }
@@ -94,9 +93,9 @@ class SiteGuard_Base {
94
  }
95
  return false;
96
  }
97
- function get_server_ip( ) {
98
- if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
99
- $ip = $_SERVER['SERVER_ADDR'];
100
  if ( false === $this->is_private_ip( $ip ) ) {
101
  if ( preg_match( '/[0-9.:]+/', $ip ) ) {
102
  return $ip;
@@ -104,21 +103,21 @@ class SiteGuard_Base {
104
  }
105
  }
106
 
107
- $url = 'http://inet-ip.info/ip';
108
  $options = array(
109
  'http' => array(
110
  'method' => 'GET',
111
  'timeout' => 2,
112
- )
113
  );
114
- $ip = file_get_contents( $url, false, stream_context_create( $options ) );
115
  if ( false !== $ip ) {
116
  if ( preg_match( '/[0-9.:]+/', $ip ) ) {
117
  return $ip;
118
  }
119
  }
120
 
121
- $host = parse_url( home_url( ), PHP_URL_HOST );
122
  if ( false !== $host && null !== $host ) {
123
  putenv( 'RES_OPTIONS=retrans:1 retry:1 timeout:2 attempts:1' );
124
  $ip = gethostbyname( $host );
@@ -132,17 +131,14 @@ class SiteGuard_Base {
132
  }
133
  return false;
134
  }
135
- function get_ip( ) {
136
- if (
137
- ! isset($_SERVER['REMOTE_ADDR'])
138
- || ! is_string($_SERVER['REMOTE_ADDR'])
139
  || '' === $_SERVER['REMOTE_ADDR']
140
- ){
141
- throw new MyPluginBrokenEnvironment('Your webserver is misconfigured. REMOTE_ADDR is not set.');
142
- }
143
-
144
- // Don’t bother with validating that $_SERVER['REMOTE_ADDR'] is a valid IP.
145
- // If a user cannot trust his webserver to correctly set the REMOTE_ADDR he is in much bigger problems.
146
- return $_SERVER['REMOTE_ADDR'];
147
  }
148
  }
2
 
3
  function siteguard_error_log( $message ) {
4
  $logfile = SITEGUARD_PATH . 'error.log';
5
+ $f = @fopen( $logfile, 'a+' );
6
  if ( false != $f ) {
7
  fwrite( $f, date_i18n( 'Y/m/d H:i:s:' ) . $message . "\n" );
8
  fclose( $f );
12
  function siteguard_error_dump( $title, $obj ) {
13
  ob_start();
14
  var_dump( $obj );
15
+ $msg = ob_get_contents();
16
+ ob_end_clean();
17
  siteguard_error_log( "$title: $msg" );
18
  }
19
 
20
+ function siteguard_check_multisite() {
21
  if ( ! is_multisite() ) {
22
  return true;
23
  }
24
+ $message = esc_html__( 'It does not support the multisite function of WordPress.', 'siteguard' );
25
+ $error = new WP_Error( 'siteguard', $message );
26
  return $error;
27
  }
28
 
29
  class SiteGuard_Base {
 
30
  function __construct() {
31
  }
32
  function is_switch_value( $value ) {
35
  }
36
  return false;
37
  }
38
+ function cvt_camma2ret( $value ) {
39
+ $result = str_replace( ' ', '', $value );
40
+ return str_replace( ',', "\r\n", $result );
41
+ }
42
+ function cvt_ret2camma( $exclude ) {
43
+ $result = str_replace( ' ', '', $exclude );
44
+ $result = str_replace( ',', '', $result );
45
+ $result = preg_replace( '/(\r\n){2,}/', "\r\n", $result );
46
+ $result = preg_replace( '/\r\n$/', '', $result );
47
+ $result = str_replace( "\r\n", ',', $result );
48
+ $result = str_replace( "\r", ',', $result );
49
+ return str_replace( "\n", ',', $result );
50
+ }
51
  function check_module( $name, $default = false ) {
52
  return true;
53
+ // It does not work WP-CLI
54
+ // if ( isset( $_SERVER['SERVER_SOFTWARE'] ) ) {
55
+ // return ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false);
56
+ // } else {
57
+ // return $default;
58
+ // }
59
 
60
+ // It does not work in FastCGI well.
61
+ // $module = 'mod_' . $name;
62
+ // return apache_mod_loaded( $module, $default );
63
+ // if ( function_exists('phpinfo') ) {
64
+ // ob_start( );
65
+ // phpinfo(8);
66
+ // $phpinfo = ob_get_clean( );
67
+ // if ( false !== strpos( $phpinfo, $module ) ) {
68
+ // return true;
69
+ // }
70
+ // }
71
+ // return $default;
72
  }
73
  function is_private_ip( $ip ) {
74
  $private_ips = array(
75
  '10.0.0.0,10.255.255.255',
76
  '172.16.0.0,172.31.255.255',
77
+ '192.168.0.0,192.168.255.255',
78
  );
79
 
80
  $long_ip = ip2long( $ip );
81
  if ( -1 !== $long_ip && false !== $long_ip ) {
82
  $long_ip = sprintf( '%u', $long_ip );
83
+ foreach ( $private_ips as $private_ip ) {
84
  list( $start, $end ) = explode( ',', $private_ip );
85
+ $long_start = ip2long( $start );
86
+ $long_start = sprintf( '%u', $long_start );
87
+ $long_end = ip2long( $end );
88
+ $long_end = sprintf( '%u', $long_end );
89
  if ( $long_ip >= $long_start && $long_ip <= $long_end ) {
90
  return true;
91
  }
93
  }
94
  return false;
95
  }
96
+ function get_server_ip() {
97
+ if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
98
+ $ip = sanitize_text_field( $_SERVER['SERVER_ADDR'] );
99
  if ( false === $this->is_private_ip( $ip ) ) {
100
  if ( preg_match( '/[0-9.:]+/', $ip ) ) {
101
  return $ip;
103
  }
104
  }
105
 
106
+ $url = 'http://inet-ip.info/ip';
107
  $options = array(
108
  'http' => array(
109
  'method' => 'GET',
110
  'timeout' => 2,
111
+ ),
112
  );
113
+ $ip = file_get_contents( $url, false, stream_context_create( $options ) );
114
  if ( false !== $ip ) {
115
  if ( preg_match( '/[0-9.:]+/', $ip ) ) {
116
  return $ip;
117
  }
118
  }
119
 
120
+ $host = parse_url( home_url(), PHP_URL_HOST );
121
  if ( false !== $host && null !== $host ) {
122
  putenv( 'RES_OPTIONS=retrans:1 retry:1 timeout:2 attempts:1' );
123
  $ip = gethostbyname( $host );
131
  }
132
  return false;
133
  }
134
+ function get_ip() {
135
+ if (
136
+ ! isset( $_SERVER['REMOTE_ADDR'] )
137
+ || ! is_string( $_SERVER['REMOTE_ADDR'] )
138
  || '' === $_SERVER['REMOTE_ADDR']
139
+ ) {
140
+ throw new MyPluginBrokenEnvironment( 'Your webserver is misconfigured. REMOTE_ADDR is not set.' );
141
+ }
142
+ return sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
 
 
 
143
  }
144
  }
classes/siteguard-captcha.php CHANGED
@@ -1,16 +1,16 @@
1
  <?php
2
 
3
- include_once( SITEGUARD_PATH . 'really-simple-captcha/siteguard-really-simple-captcha.php' );
4
 
5
  class SiteGuard_CAPTCHA extends SiteGuard_Base {
6
  protected $captcha;
7
  protected $prefix;
8
  protected $word;
9
 
10
- function __construct( ) {
11
  global $siteguard_config;
12
  if ( '1' == $siteguard_config->get( 'captcha_enable' ) && 'xmlrpc.php' != basename( $_SERVER['SCRIPT_NAME'] ) ) {
13
- $this->captcha = new SiteGuardReallySimpleCaptcha( );
14
 
15
  add_filter( 'shake_error_codes', array( $this, 'handler_shake_error_codes' ) );
16
 
@@ -41,40 +41,40 @@ class SiteGuard_CAPTCHA extends SiteGuard_Base {
41
  add_filter( 'login_errors', array( $this, 'handler_login_errors' ) );
42
  }
43
  }
44
- function check_requirements( ) {
45
- $error = siteguard_check_multisite( );
46
  if ( is_wp_error( $error ) ) {
47
  return $error;
48
  }
49
- $error = $this->check_extensions( );
50
  if ( is_wp_error( $error ) ) {
51
  return $error;
52
  }
53
- $error = $this->check_image_access( );
54
  if ( is_wp_error( $error ) ) {
55
  return $error;
56
  }
57
- $error = $this->check_support_freetype( );
58
  if ( is_wp_error( $error ) ) {
59
  return $error;
60
  }
61
- $error = $this->check_htaccess( );
62
  if ( is_wp_error( $error ) ) {
63
  return $error;
64
  }
65
  return true;
66
  }
67
- function check_htaccess( ) {
68
- if ( false === SiteGuard_Htaccess::test_htaccess( ) ) {
69
  $message = esc_html__( 'mod_rewrite of .htaccess can not be used', 'siteguard' );
70
- $error = new WP_Error( 'siteguard_captcha', $message );
71
  return $error;
72
  }
73
  return true;
74
  }
75
- function check_extensions( ) {
76
  $error_extensions = array();
77
- $extensions = array(
78
  'mbstring',
79
  'gd',
80
  );
@@ -96,40 +96,40 @@ class SiteGuard_CAPTCHA extends SiteGuard_Base {
96
  $error = new WP_Error( 'siteguard_captcha', $message );
97
  return $error;
98
  }
99
- function check_image_access( ) {
100
  if ( is_object( $this->captcha ) ) {
101
- $ret = $this->captcha->make_tmp_dir( );
102
  } else {
103
- $captcha = new SiteGuardReallySimpleCaptcha( );
104
- $ret = $captcha->make_tmp_dir( );
105
  }
106
  if ( false === $ret ) {
107
- $message = esc_html__( 'The image file write failed.', 'siteguard' );
108
- $error = new WP_Error( 'siteguard_captcha', $message );
109
  return $error;
110
  }
111
 
112
  return true;
113
- # $result = wp_remote_get( SITEGUARD_URL_PATH . 'really-simple-captcha/tmp/dummy.png' );
114
- # if ( ! is_wp_error( $result ) && 200 === $result['response']['code'] ) {
115
- # return true;
116
- # }
117
 
118
- # $message = esc_html__( 'The image file access failed.', 'siteguard' );
119
- # if ( is_wp_error( $result ) ) {
120
- # $error_detail = '( Error: ' . $result->get_error_message( ) . ' )';
121
- # } else {
122
- # $error_detail = '( ResponseCode: ' . $result['response']['code'] . ' )';
123
- # }
124
- # $error = new WP_Error( 'siteguard_captcha', $message . $error_detail);
125
- # return $error;
126
  }
127
- function check_support_freetype( ) {
128
  if ( function_exists( 'imagettftext' ) ) {
129
  return true;
130
  }
131
  $message = esc_html__( 'In order to enable this function, php must be compiled with FreeType support enabled.', 'siteguard' );
132
- $error = new WP_Error( 'siteguard_captcha', $message );
133
  return $error;
134
  }
135
  function handler_login_errors( $error ) {
@@ -143,9 +143,9 @@ class SiteGuard_CAPTCHA extends SiteGuard_Base {
143
  return $shake_error_codes;
144
  }
145
 
146
- function init( ) {
147
  global $siteguard_config;
148
- $errors = $this->check_requirements( );
149
  if ( ! is_wp_error( $errors ) ) {
150
  $switch = '1';
151
  } else {
@@ -158,57 +158,57 @@ class SiteGuard_CAPTCHA extends SiteGuard_Base {
158
  } else {
159
  $mode = '2'; // alphanumeric
160
  }
161
- $siteguard_config->set( 'captcha_login', $mode );
162
- $siteguard_config->set( 'captcha_comment', $mode );
163
  $siteguard_config->set( 'captcha_lostpasswd', $mode );
164
  $siteguard_config->set( 'captcha_registuser', $mode );
165
- if ( true === siteguard_check_multisite( ) ) {
166
- $siteguard_config->set( 'same_login_error', '1' );
167
  } else {
168
- $siteguard_config->set( 'same_login_error', '0' );
169
  }
170
- $siteguard_config->update( );
171
  }
172
- function get_captcha( ) {
173
  $result = '<p>';
174
- $result .= '<img src="'. SITEGUARD_URL_PATH . 'really-simple-captcha/tmp/' . $this->prefix . '.png" alt="CAPTCHA">';
175
  $result .= '</p><p>';
176
  $result .= '<label for="siteguard_captcha">' . esc_html__( 'Please input characters displayed above.', 'siteguard' ) . '</label><br />';
177
  $result .= '<input type="text" name="siteguard_captcha" id="siteguard_captcha" class="input" value="" size="10" aria-required="true" />';
178
- $result .= '<input type="hidden" name="siteguard_captcha_prefix" id="siteguard_captcha_prefix" value="'.$this->prefix.'" />';
179
  $result .= '</p>';
180
 
181
  return $result;
182
  }
183
- function put_captcha( ) {
184
- $this->word = $this->captcha->generate_random_word( );
185
- $this->prefix = mt_rand( );
186
  $this->captcha->generate_image( $this->prefix, $this->word );
187
- echo $this->get_captcha( );
188
  }
189
- function handler_login_form( ) {
190
  global $siteguard_config;
191
- ( '2' === $siteguard_config->get( 'captcha_login' ) ) ? $this->captcha->set_lang_mode( 'en' ) : $this->captcha->set_lang_mode( 'jp' );
192
- $this->put_captcha( );
193
  }
194
  function handler_comment_form( $post_id ) {
195
  global $siteguard_config;
196
  if ( defined( 'SITEGUARD_PUT_COMMENT_FORM' ) ) {
197
  return;
198
  }
199
- ( '2' === $siteguard_config->get( 'captcha_comment' ) ) ? $this->captcha->set_lang_mode( 'en' ) : $this->captcha->set_lang_mode( 'jp' );
200
- $this->put_captcha( );
201
  define( 'SITEGUARD_PUT_COMMENT_FORM', '1' );
202
  }
203
- function handler_lostpassword_form( ) {
204
  global $siteguard_config;
205
- ( '2' === $siteguard_config->get( 'captcha_lostpasswd' ) ) ? $this->captcha->set_lang_mode( 'en' ) : $this->captcha->set_lang_mode( 'jp' );
206
- $this->put_captcha( );
207
  }
208
- function handler_register_form( ) {
209
  global $siteguard_config;
210
- ( '2' == $siteguard_config->get( 'captcha_registuser' ) ) ? $this->captcha->set_lang_mode( 'en' ) : $this->captcha->set_lang_mode( 'jp' );
211
- $this->put_captcha( );
212
  }
213
  function handler_wp_authenticate_user( $user, $password ) {
214
  if ( array_key_exists( 'siteguard_captcha', $_POST ) && array_key_exists( 'siteguard_captcha_prefix', $_POST ) ) {
@@ -216,15 +216,15 @@ class SiteGuard_CAPTCHA extends SiteGuard_Base {
216
  return $user;
217
  }
218
  }
219
- $error = new WP_Error( );
220
  $error->add( 'siteguard-captcha-error', esc_html__( 'ERROR: Invalid CAPTCHA.', 'siteguard' ) );
221
  return $error;
222
  }
223
- function add_captcha_error( ) {
224
  return new WP_Error( 'siteguard-captcha-error', esc_html__( 'ERROR: Invalid CAPTCHA.', 'siteguard' ) );
225
  }
226
- function handler_lostpassword_post( ) {
227
- if ( array_key_exists( 'siteguard_captcha', $_POST ) && array_key_exists( 'siteguard_captcha_prefix', $_POST ) ) {
228
  if ( $this->captcha->check( $_POST['siteguard_captcha_prefix'], $_POST['siteguard_captcha'], false ) ) {
229
  return;
230
  }
@@ -232,12 +232,12 @@ class SiteGuard_CAPTCHA extends SiteGuard_Base {
232
  add_filter( 'allow_password_reset', array( $this, 'add_captcha_error' ) );
233
  }
234
  function handler_registration_errors( $errors, $sanitized_user_login, $user_email ) {
235
- if ( array_key_exists( 'siteguard_captcha', $_POST ) && array_key_exists( 'siteguard_captcha_prefix', $_POST ) ) {
236
  if ( $this->captcha->check( $_POST['siteguard_captcha_prefix'], $_POST['siteguard_captcha'], false ) ) {
237
  return $errors;
238
  }
239
  }
240
- $new_errors = new WP_Error( );
241
  $new_errors->add( 'siteguard-captcha-error', esc_html__( 'ERROR: Invalid CAPTCHA.', 'siteguard' ) );
242
  return $new_errors;
243
  }
@@ -245,7 +245,7 @@ class SiteGuard_CAPTCHA extends SiteGuard_Base {
245
  if ( is_admin() ) {
246
  return $comment;
247
  }
248
- if ( array_key_exists( 'siteguard_captcha', $_POST ) && array_key_exists( 'siteguard_captcha_prefix', $_POST ) ) {
249
  if ( ! empty( $_POST['siteguard_captcha'] ) ) {
250
  if ( $this->captcha->check( $_POST['siteguard_captcha_prefix'], $_POST['siteguard_captcha'], false ) ) {
251
  return $comment;
1
  <?php
2
 
3
+ require_once SITEGUARD_PATH . 'really-simple-captcha/siteguard-really-simple-captcha.php';
4
 
5
  class SiteGuard_CAPTCHA extends SiteGuard_Base {
6
  protected $captcha;
7
  protected $prefix;
8
  protected $word;
9
 
10
+ function __construct() {
11
  global $siteguard_config;
12
  if ( '1' == $siteguard_config->get( 'captcha_enable' ) && 'xmlrpc.php' != basename( $_SERVER['SCRIPT_NAME'] ) ) {
13
+ $this->captcha = new SiteGuardReallySimpleCaptcha();
14
 
15
  add_filter( 'shake_error_codes', array( $this, 'handler_shake_error_codes' ) );
16
 
41
  add_filter( 'login_errors', array( $this, 'handler_login_errors' ) );
42
  }
43
  }
44
+ function check_requirements() {
45
+ $error = siteguard_check_multisite();
46
  if ( is_wp_error( $error ) ) {
47
  return $error;
48
  }
49
+ $error = $this->check_extensions();
50
  if ( is_wp_error( $error ) ) {
51
  return $error;
52
  }
53
+ $error = $this->check_image_access();
54
  if ( is_wp_error( $error ) ) {
55
  return $error;
56
  }
57
+ $error = $this->check_support_freetype();
58
  if ( is_wp_error( $error ) ) {
59
  return $error;
60
  }
61
+ $error = $this->check_htaccess();
62
  if ( is_wp_error( $error ) ) {
63
  return $error;
64
  }
65
  return true;
66
  }
67
+ function check_htaccess() {
68
+ if ( false === SiteGuard_Htaccess::test_htaccess() ) {
69
  $message = esc_html__( 'mod_rewrite of .htaccess can not be used', 'siteguard' );
70
+ $error = new WP_Error( 'siteguard_captcha', $message );
71
  return $error;
72
  }
73
  return true;
74
  }
75
+ function check_extensions() {
76
  $error_extensions = array();
77
+ $extensions = array(
78
  'mbstring',
79
  'gd',
80
  );
96
  $error = new WP_Error( 'siteguard_captcha', $message );
97
  return $error;
98
  }
99
+ function check_image_access() {
100
  if ( is_object( $this->captcha ) ) {
101
+ $ret = $this->captcha->make_tmp_dir();
102
  } else {
103
+ $captcha = new SiteGuardReallySimpleCaptcha();
104
+ $ret = $captcha->make_tmp_dir();
105
  }
106
  if ( false === $ret ) {
107
+ $message = esc_html__( 'The image file write failed.', 'siteguard' );
108
+ $error = new WP_Error( 'siteguard_captcha', $message );
109
  return $error;
110
  }
111
 
112
  return true;
113
+ // $result = wp_remote_get( SITEGUARD_URL_PATH . 'really-simple-captcha/tmp/dummy.png' );
114
+ // if ( ! is_wp_error( $result ) && 200 === $result['response']['code'] ) {
115
+ // return true;
116
+ // }
117
 
118
+ // $message = esc_html__( 'The image file access failed.', 'siteguard' );
119
+ // if ( is_wp_error( $result ) ) {
120
+ // $error_detail = '( Error: ' . $result->get_error_message( ) . ' )';
121
+ // } else {
122
+ // $error_detail = '( ResponseCode: ' . $result['response']['code'] . ' )';
123
+ // }
124
+ // $error = new WP_Error( 'siteguard_captcha', $message . $error_detail);
125
+ // return $error;
126
  }
127
+ function check_support_freetype() {
128
  if ( function_exists( 'imagettftext' ) ) {
129
  return true;
130
  }
131
  $message = esc_html__( 'In order to enable this function, php must be compiled with FreeType support enabled.', 'siteguard' );
132
+ $error = new WP_Error( 'siteguard_captcha', $message );
133
  return $error;
134
  }
135
  function handler_login_errors( $error ) {
143
  return $shake_error_codes;
144
  }
145
 
146
+ function init() {
147
  global $siteguard_config;
148
+ $errors = $this->check_requirements();
149
  if ( ! is_wp_error( $errors ) ) {
150
  $switch = '1';
151
  } else {
158
  } else {
159
  $mode = '2'; // alphanumeric
160
  }
161
+ $siteguard_config->set( 'captcha_login', $mode );
162
+ $siteguard_config->set( 'captcha_comment', $mode );
163
  $siteguard_config->set( 'captcha_lostpasswd', $mode );
164
  $siteguard_config->set( 'captcha_registuser', $mode );
165
+ if ( true === siteguard_check_multisite() ) {
166
+ $siteguard_config->set( 'same_login_error', '1' );
167
  } else {
168
+ $siteguard_config->set( 'same_login_error', '0' );
169
  }
170
+ $siteguard_config->update();
171
  }
172
+ function get_captcha() {
173
  $result = '<p>';
174
+ $result .= '<img src="' . SITEGUARD_URL_PATH . 'really-simple-captcha/tmp/' . $this->prefix . '.png" alt="CAPTCHA">';
175
  $result .= '</p><p>';
176
  $result .= '<label for="siteguard_captcha">' . esc_html__( 'Please input characters displayed above.', 'siteguard' ) . '</label><br />';
177
  $result .= '<input type="text" name="siteguard_captcha" id="siteguard_captcha" class="input" value="" size="10" aria-required="true" />';
178
+ $result .= '<input type="hidden" name="siteguard_captcha_prefix" id="siteguard_captcha_prefix" value="' . $this->prefix . '" />';
179
  $result .= '</p>';
180
 
181
  return $result;
182
  }
183
+ function put_captcha() {
184
+ $this->word = $this->captcha->generate_random_word();
185
+ $this->prefix = mt_rand();
186
  $this->captcha->generate_image( $this->prefix, $this->word );
187
+ echo $this->get_captcha();
188
  }
189
+ function handler_login_form() {
190
  global $siteguard_config;
191
+ ( '2' === $siteguard_config->get( 'captcha_login' ) ) ? $this->captcha->set_lang_mode( 'en' ) : $this->captcha->set_lang_mode( 'jp' );
192
+ $this->put_captcha();
193
  }
194
  function handler_comment_form( $post_id ) {
195
  global $siteguard_config;
196
  if ( defined( 'SITEGUARD_PUT_COMMENT_FORM' ) ) {
197
  return;
198
  }
199
+ ( '2' === $siteguard_config->get( 'captcha_comment' ) ) ? $this->captcha->set_lang_mode( 'en' ) : $this->captcha->set_lang_mode( 'jp' );
200
+ $this->put_captcha();
201
  define( 'SITEGUARD_PUT_COMMENT_FORM', '1' );
202
  }
203
+ function handler_lostpassword_form() {
204
  global $siteguard_config;
205
+ ( '2' === $siteguard_config->get( 'captcha_lostpasswd' ) ) ? $this->captcha->set_lang_mode( 'en' ) : $this->captcha->set_lang_mode( 'jp' );
206
+ $this->put_captcha();
207
  }
208
+ function handler_register_form() {
209
  global $siteguard_config;
210
+ ( '2' == $siteguard_config->get( 'captcha_registuser' ) ) ? $this->captcha->set_lang_mode( 'en' ) : $this->captcha->set_lang_mode( 'jp' );
211
+ $this->put_captcha();
212
  }
213
  function handler_wp_authenticate_user( $user, $password ) {
214
  if ( array_key_exists( 'siteguard_captcha', $_POST ) && array_key_exists( 'siteguard_captcha_prefix', $_POST ) ) {
216
  return $user;
217
  }
218
  }
219
+ $error = new WP_Error();
220
  $error->add( 'siteguard-captcha-error', esc_html__( 'ERROR: Invalid CAPTCHA.', 'siteguard' ) );
221
  return $error;
222
  }
223
+ function add_captcha_error() {
224
  return new WP_Error( 'siteguard-captcha-error', esc_html__( 'ERROR: Invalid CAPTCHA.', 'siteguard' ) );
225
  }
226
+ function handler_lostpassword_post() {
227
+ if ( array_key_exists( 'siteguard_captcha', $_POST ) && array_key_exists( 'siteguard_captcha_prefix', $_POST ) ) {
228
  if ( $this->captcha->check( $_POST['siteguard_captcha_prefix'], $_POST['siteguard_captcha'], false ) ) {
229
  return;
230
  }
232
  add_filter( 'allow_password_reset', array( $this, 'add_captcha_error' ) );
233
  }
234
  function handler_registration_errors( $errors, $sanitized_user_login, $user_email ) {
235
+ if ( array_key_exists( 'siteguard_captcha', $_POST ) && array_key_exists( 'siteguard_captcha_prefix', $_POST ) ) {
236
  if ( $this->captcha->check( $_POST['siteguard_captcha_prefix'], $_POST['siteguard_captcha'], false ) ) {
237
  return $errors;
238
  }
239
  }
240
+ $new_errors = new WP_Error();
241
  $new_errors->add( 'siteguard-captcha-error', esc_html__( 'ERROR: Invalid CAPTCHA.', 'siteguard' ) );
242
  return $new_errors;
243
  }
245
  if ( is_admin() ) {
246
  return $comment;
247
  }
248
+ if ( array_key_exists( 'siteguard_captcha', $_POST ) && array_key_exists( 'siteguard_captcha_prefix', $_POST ) ) {
249
  if ( ! empty( $_POST['siteguard_captcha'] ) ) {
250
  if ( $this->captcha->check( $_POST['siteguard_captcha_prefix'], $_POST['siteguard_captcha'], false ) ) {
251
  return $comment;
classes/siteguard-config.php CHANGED
@@ -11,7 +11,7 @@ class SiteGuard_Config {
11
  function get( $key ) {
12
  return isset( $this->config[ $key ] ) ? $this->config[ $key ] : '';
13
  }
14
- function update( ) {
15
  update_option( 'siteguard_config', $this->config );
16
  }
17
  }
11
  function get( $key ) {
12
  return isset( $this->config[ $key ] ) ? $this->config[ $key ] : '';
13
  }
14
+ function update() {
15
  update_option( 'siteguard_config', $this->config );
16
  }
17
  }
classes/siteguard-disable-author-query.php CHANGED
@@ -2,26 +2,26 @@
2
 
3
  class SiteGuard_Disable_Author_Query extends SiteGuard_Base {
4
 
5
- function __construct( ) {
6
  global $siteguard_config;
7
  if ( '1' == $siteguard_config->get( 'block_author_query_enable' ) ) {
8
  add_action( 'init', array( $this, 'handler_author_query' ) );
9
  if ( '1' == $siteguard_config->get( 'disable_restapi_enable' ) ) {
10
- add_filter( 'rest_pre_dispatch', array( $this, 'handler_deny_rest_api' ), 10, 3 );
11
  }
12
  }
13
  }
14
- function init( ) {
15
  global $siteguard_config;
16
  $siteguard_config->set( 'block_author_query_enable', '0' );
17
  $siteguard_config->set( 'disable_restapi_enable', '0' );
18
  $siteguard_config->set( 'disable_restapi_exclude', 'oembed,contact-form-7,akismet' );
19
- $siteguard_config->update( );
20
  }
21
- function handler_author_query( ) {
22
  if ( isset( $_SERVER['REQUEST_URI'] ) ) {
23
- if ( !is_admin( ) && preg_match( '/[?&]author=[0-9]+/i', $_SERVER['REQUEST_URI'] ) ) {
24
- wp_safe_redirect( home_url( ) );
25
  exit;
26
  }
27
  }
@@ -32,12 +32,17 @@ class SiteGuard_Disable_Author_Query extends SiteGuard_Base {
32
 
33
  $route = $request->get_route();
34
  foreach ( $exclude_app as $app ) {
35
- if ( strpos( $route, "/$app/" ) === 0 ) return $result;
 
 
36
  }
37
- if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' )) {
38
  return $result;
39
  }
40
- return new WP_Error( 'rest_disabled', __( 'The REST API on this site has been disabled.' ),
41
- array( 'status' => rest_authorization_required_code() ) );
 
 
 
42
  }
43
  }
2
 
3
  class SiteGuard_Disable_Author_Query extends SiteGuard_Base {
4
 
5
+ function __construct() {
6
  global $siteguard_config;
7
  if ( '1' == $siteguard_config->get( 'block_author_query_enable' ) ) {
8
  add_action( 'init', array( $this, 'handler_author_query' ) );
9
  if ( '1' == $siteguard_config->get( 'disable_restapi_enable' ) ) {
10
+ add_filter( 'rest_pre_dispatch', array( $this, 'handler_deny_rest_api' ), 10, 3 );
11
  }
12
  }
13
  }
14
+ function init() {
15
  global $siteguard_config;
16
  $siteguard_config->set( 'block_author_query_enable', '0' );
17
  $siteguard_config->set( 'disable_restapi_enable', '0' );
18
  $siteguard_config->set( 'disable_restapi_exclude', 'oembed,contact-form-7,akismet' );
19
+ $siteguard_config->update();
20
  }
21
+ function handler_author_query() {
22
  if ( isset( $_SERVER['REQUEST_URI'] ) ) {
23
+ if ( ! is_admin() && preg_match( '/[?&]author=[0-9]+/i', $_SERVER['REQUEST_URI'] ) ) {
24
+ wp_safe_redirect( home_url() );
25
  exit;
26
  }
27
  }
32
 
33
  $route = $request->get_route();
34
  foreach ( $exclude_app as $app ) {
35
+ if ( strpos( $route, "/$app/" ) === 0 ) {
36
+ return $result;
37
+ }
38
  }
39
+ if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
40
  return $result;
41
  }
42
+ return new WP_Error(
43
+ 'rest_disabled',
44
+ __( 'The REST API on this site has been disabled.' ),
45
+ array( 'status' => rest_authorization_required_code() )
46
+ );
47
  }
48
  }
classes/siteguard-disable-pingback.php CHANGED
@@ -2,20 +2,20 @@
2
 
3
  class SiteGuard_Disable_Pingback extends SiteGuard_Base {
4
 
5
- function __construct( ) {
6
  global $siteguard_config;
7
  if ( '1' == $siteguard_config->get( 'disable_pingback_enable' ) ) {
8
  add_filter( 'xmlrpc_methods', array( $this, 'handler_xmlrpc_methods' ) );
9
  }
10
  }
11
- function init( ) {
12
  global $siteguard_config;
13
- if ( true === siteguard_check_multisite( ) ) {
14
  $siteguard_config->set( 'disable_pingback_enable', '1' );
15
  } else {
16
  $siteguard_config->set( 'disable_pingback_enable', '0' );
17
  }
18
- $siteguard_config->update( );
19
  }
20
  function handler_xmlrpc_methods( $methods ) {
21
  unset( $methods['pingback.ping'] );
2
 
3
  class SiteGuard_Disable_Pingback extends SiteGuard_Base {
4
 
5
+ function __construct() {
6
  global $siteguard_config;
7
  if ( '1' == $siteguard_config->get( 'disable_pingback_enable' ) ) {
8
  add_filter( 'xmlrpc_methods', array( $this, 'handler_xmlrpc_methods' ) );
9
  }
10
  }
11
+ function init() {
12
  global $siteguard_config;
13
+ if ( true === siteguard_check_multisite() ) {
14
  $siteguard_config->set( 'disable_pingback_enable', '1' );
15
  } else {
16
  $siteguard_config->set( 'disable_pingback_enable', '0' );
17
  }
18
+ $siteguard_config->update();
19
  }
20
  function handler_xmlrpc_methods( $methods ) {
21
  unset( $methods['pingback.ping'] );
classes/siteguard-disable-xmlrpc.php CHANGED
@@ -3,17 +3,17 @@
3
  class SiteGuard_Disable_XMLRPC extends SiteGuard_Base {
4
  public static $htaccess_mark = '#==== SITEGUARD_DISABLE_XMLRPC_SETTINGS';
5
 
6
- function __construct( ) {
7
  }
8
- static function get_mark( ) {
9
- return SiteGuard_Disable_XMLRPC::$htaccess_mark;
10
  }
11
- function init( ) {
12
  global $siteguard_config;
13
  $siteguard_config->set( 'disable_xmlrpc_enable', '0' );
14
- $siteguard_config->update( );
15
  }
16
- function update_settings( ) {
17
  global $siteguard_config;
18
 
19
  $htaccess_str = "<Files xmlrpc.php>\n";
@@ -28,17 +28,17 @@ class SiteGuard_Disable_XMLRPC extends SiteGuard_Base {
28
 
29
  return $htaccess_str;
30
  }
31
- function feature_on( ) {
32
  global $siteguard_htaccess;
33
- if ( false === SiteGuard_Htaccess::check_permission( ) ) {
34
  return false;
35
  }
36
- $data = $this->update_settings( );
37
- $mark = $this->get_mark( );
38
  return $siteguard_htaccess->update_settings( $mark, $data );
39
  }
40
- static function feature_off( ) {
41
- $mark = SiteGuard_Disable_XMLRPC::get_mark( );
42
  return SiteGuard_Htaccess::clear_settings( $mark );
43
  }
44
  }
3
  class SiteGuard_Disable_XMLRPC extends SiteGuard_Base {
4
  public static $htaccess_mark = '#==== SITEGUARD_DISABLE_XMLRPC_SETTINGS';
5
 
6
+ function __construct() {
7
  }
8
+ static function get_mark() {
9
+ return self::$htaccess_mark;
10
  }
11
+ function init() {
12
  global $siteguard_config;
13
  $siteguard_config->set( 'disable_xmlrpc_enable', '0' );
14
+ $siteguard_config->update();
15
  }
16
+ function update_settings() {
17
  global $siteguard_config;
18
 
19
  $htaccess_str = "<Files xmlrpc.php>\n";
28
 
29
  return $htaccess_str;
30
  }
31
+ function feature_on() {
32
  global $siteguard_htaccess;
33
+ if ( false === SiteGuard_Htaccess::check_permission() ) {
34
  return false;
35
  }
36
+ $data = $this->update_settings();
37
+ $mark = $this->get_mark();
38
  return $siteguard_htaccess->update_settings( $mark, $data );
39
  }
40
+ static function feature_off() {
41
+ $mark = self::get_mark();
42
  return SiteGuard_Htaccess::clear_settings( $mark );
43
  }
44
  }
classes/siteguard-htaccess.php CHANGED
@@ -5,27 +5,27 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
5
  const HTACCESS_MARK_START = '#SITEGUARD_PLUGIN_SETTINGS_START';
6
  const HTACCESS_MARK_END = '#SITEGUARD_PLUGIN_SETTINGS_END';
7
 
8
- function __construct( ) {
9
  }
10
- static function get_htaccess_file( ) {
11
- return ABSPATH.'.htaccess';
12
  }
13
- static function get_tmp_dir( ) {
14
  return SITEGUARD_PATH . 'tmp/';
15
  }
16
- static function test_htaccess( ) {
17
  return true;
18
- # $result = wp_remote_get( SITEGUARD_URL_PATH . 'test/siteguard-test.php' );
19
- # if ( ! is_wp_error( $result ) && 200 === $result['response']['code'] ) {
20
- # return true;
21
- # }
22
- # return false;
23
  }
24
- static function get_htaccess_new_file( ) {
25
- return tempnam( SiteGuard_Htaccess::get_tmp_dir( ), 'htaccess_' );
26
  }
27
- static function make_tmp_dir( ) {
28
- $dir = SiteGuard_Htaccess::get_tmp_dir( );
29
  if ( ! wp_mkdir_p( $dir ) ) {
30
  siteguard_error_log( "make tempdir failed: $dir" );
31
  return false;
@@ -34,7 +34,7 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
34
 
35
  if ( file_exists( $htaccess_file ) ) {
36
  $lines = file( $htaccess_file );
37
- $res = preg_grep( '/IfModule authz_core_module/', $lines );
38
  if ( ! empty( $res ) ) {
39
  return true;
40
  }
@@ -62,7 +62,7 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
62
  $mark_start = $mark . '_START';
63
  $mark_end = $mark . '_END';
64
  }
65
- $current_file = SiteGuard_Htaccess::get_htaccess_file( );
66
  if ( ! file_exists( $current_file ) ) {
67
  return $result;
68
  }
@@ -70,9 +70,9 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
70
  if ( null === $fr ) {
71
  return $result;
72
  }
73
- $line_num = 0;
74
  $start_line = 0;
75
- $end_line = 0;
76
  while ( ! feof( $fr ) ) {
77
  $line = fgets( $fr, 4096 );
78
  $line_num++;
@@ -92,7 +92,7 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
92
  return $result;
93
  }
94
  static function check_permission( $flag_create = true ) {
95
- $file = SiteGuard_Htaccess::get_htaccess_file( );
96
  if ( true === $flag_create ) {
97
  self::get_apply_permission( $file );
98
  }
@@ -112,7 +112,7 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
112
  return true;
113
  }
114
  static function get_apply_permission_itr( $file ) {
115
- clearstatcache( );
116
  $perm = intval( substr( sprintf( '%o', fileperms( $file ) ), -4 ), 8 );
117
  return $perm;
118
  }
@@ -127,7 +127,7 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
127
  return $perm;
128
  }
129
  static function clear_settings( $mark ) {
130
- if ( ! SiteGuard_Htaccess::make_tmp_dir( ) ) {
131
  return false;
132
  }
133
  if ( '' === $mark ) {
@@ -138,8 +138,8 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
138
  $mark_end = $mark . '_END';
139
  }
140
  $flag_settings = false;
141
- $current_file = SiteGuard_Htaccess::get_htaccess_file( );
142
- $perm = self::get_apply_permission( $current_file );
143
  if ( ! self::check_permission( false ) ) {
144
  return false;
145
  }
@@ -148,8 +148,8 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
148
  siteguard_error_log( "fopen failed: $current_file" );
149
  return false;
150
  }
151
- $new_file = SiteGuard_Htaccess::get_htaccess_new_file( );
152
- $fw = @fopen( $new_file, 'w' );
153
  if ( null === $fw ) {
154
  siteguard_error_log( "fopen failed: $new_file" );
155
  return false;
@@ -176,7 +176,7 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
176
  return true;
177
  }
178
  function update_settings( $mark, $data ) {
179
- if ( ! SiteGuard_Htaccess::make_tmp_dir( ) ) {
180
  return false;
181
  }
182
  $flag_write = false;
@@ -188,7 +188,7 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
188
  $mark_end = $mark . '_END';
189
  $mark_wp_start = '# BEGIN WordPress';
190
  $mark_wp_end = '# END WordPress';
191
- $current_file = SiteGuard_Htaccess::get_htaccess_file( );
192
  $perm = self::get_apply_permission( $current_file );
193
  if ( ! self::check_permission( false ) ) {
194
  return false;
@@ -198,7 +198,7 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
198
  siteguard_error_log( "fopen failed: $current_file" );
199
  return false;
200
  }
201
- $new_file = SiteGuard_Htaccess::get_htaccess_new_file( );
202
  if ( ! is_writable( $new_file ) ) {
203
  siteguard_error_log( "file not writable: $new_file" );
204
  return false;
@@ -226,10 +226,10 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
226
  }
227
 
228
  if ( false !== strpos( $line, $mark_start ) ) {
229
- fwrite( $fw, $line , strlen( $line ) );
230
- fwrite( $fw, $data, strlen( $data ) );
231
- $flag_write = true;
232
- $flag_through = false;
233
  continue;
234
  }
235
  if ( false === $flag_write && false !== strpos( $line, self::HTACCESS_MARK_END ) ) {
@@ -259,10 +259,10 @@ class SiteGuard_Htaccess extends SiteGuard_Base {
259
  fwrite( $fw, "\n", 1 );
260
  fwrite( $fw, $wp_settings, strlen( $wp_settings ) );
261
  fwrite( $fw, "\n", 1 );
262
- } else if ( false === $flag_wp ) { // Write empty WordPress Settings
263
  fwrite( $fw, "\n", 1 );
264
  fwrite( $fw, $mark_wp_start . "\n", strlen( $mark_wp_start ) + 1 );
265
- fwrite( $fw, $mark_wp_end . "\n", strlen( $mark_wp_end ) + 1 );
266
  fwrite( $fw, "\n", 1 );
267
  }
268
  fclose( $fr );
5
  const HTACCESS_MARK_START = '#SITEGUARD_PLUGIN_SETTINGS_START';
6
  const HTACCESS_MARK_END = '#SITEGUARD_PLUGIN_SETTINGS_END';
7
 
8
+ function __construct() {
9
  }
10
+ static function get_htaccess_file() {
11
+ return ABSPATH . '.htaccess';
12
  }
13
+ static function get_tmp_dir() {
14
  return SITEGUARD_PATH . 'tmp/';
15
  }
16
+ static function test_htaccess() {
17
  return true;
18
+ // $result = wp_remote_get( SITEGUARD_URL_PATH . 'test/siteguard-test.php' );
19
+ // if ( ! is_wp_error( $result ) && 200 === $result['response']['code'] ) {
20
+ // return true;
21
+ // }
22
+ // return false;
23
  }
24
+ static function get_htaccess_new_file() {
25
+ return tempnam( self::get_tmp_dir(), 'htaccess_' );
26
  }
27
+ static function make_tmp_dir() {
28
+ $dir = self::get_tmp_dir();
29
  if ( ! wp_mkdir_p( $dir ) ) {
30
  siteguard_error_log( "make tempdir failed: $dir" );
31
  return false;
34
 
35
  if ( file_exists( $htaccess_file ) ) {
36
  $lines = file( $htaccess_file );
37
+ $res = preg_grep( '/IfModule authz_core_module/', $lines );
38
  if ( ! empty( $res ) ) {
39
  return true;
40
  }
62
  $mark_start = $mark . '_START';
63
  $mark_end = $mark . '_END';
64
  }
65
+ $current_file = self::get_htaccess_file();
66
  if ( ! file_exists( $current_file ) ) {
67
  return $result;
68
  }
70
  if ( null === $fr ) {
71
  return $result;
72
  }
73
+ $line_num = 0;
74
  $start_line = 0;
75
+ $end_line = 0;
76
  while ( ! feof( $fr ) ) {
77
  $line = fgets( $fr, 4096 );
78
  $line_num++;
92
  return $result;
93
  }
94
  static function check_permission( $flag_create = true ) {
95
+ $file = self::get_htaccess_file();
96
  if ( true === $flag_create ) {
97
  self::get_apply_permission( $file );
98
  }
112
  return true;
113
  }
114
  static function get_apply_permission_itr( $file ) {
115
+ clearstatcache();
116
  $perm = intval( substr( sprintf( '%o', fileperms( $file ) ), -4 ), 8 );
117
  return $perm;
118
  }
127
  return $perm;
128
  }
129
  static function clear_settings( $mark ) {
130
+ if ( ! self::make_tmp_dir() ) {
131
  return false;
132
  }
133
  if ( '' === $mark ) {
138
  $mark_end = $mark . '_END';
139
  }
140
  $flag_settings = false;
141
+ $current_file = self::get_htaccess_file();
142
+ $perm = self::get_apply_permission( $current_file );
143
  if ( ! self::check_permission( false ) ) {
144
  return false;
145
  }
148
  siteguard_error_log( "fopen failed: $current_file" );
149
  return false;
150
  }
151
+ $new_file = self::get_htaccess_new_file();
152
+ $fw = @fopen( $new_file, 'w' );
153
  if ( null === $fw ) {
154
  siteguard_error_log( "fopen failed: $new_file" );
155
  return false;
176
  return true;
177
  }
178
  function update_settings( $mark, $data ) {
179
+ if ( ! self::make_tmp_dir() ) {
180
  return false;
181
  }
182
  $flag_write = false;
188
  $mark_end = $mark . '_END';
189
  $mark_wp_start = '# BEGIN WordPress';
190
  $mark_wp_end = '# END WordPress';
191
+ $current_file = self::get_htaccess_file();
192
  $perm = self::get_apply_permission( $current_file );
193
  if ( ! self::check_permission( false ) ) {
194
  return false;
198
  siteguard_error_log( "fopen failed: $current_file" );
199
  return false;
200
  }
201
+ $new_file = self::get_htaccess_new_file();
202
  if ( ! is_writable( $new_file ) ) {
203
  siteguard_error_log( "file not writable: $new_file" );
204
  return false;
226
  }
227
 
228
  if ( false !== strpos( $line, $mark_start ) ) {
229
+ fwrite( $fw, $line, strlen( $line ) );
230
+ fwrite( $fw, $data, strlen( $data ) );
231
+ $flag_write = true;
232
+ $flag_through = false;
233
  continue;
234
  }
235
  if ( false === $flag_write && false !== strpos( $line, self::HTACCESS_MARK_END ) ) {
259
  fwrite( $fw, "\n", 1 );
260
  fwrite( $fw, $wp_settings, strlen( $wp_settings ) );
261
  fwrite( $fw, "\n", 1 );
262
+ } elseif ( false === $flag_wp ) { // Write empty WordPress Settings
263
  fwrite( $fw, "\n", 1 );
264
  fwrite( $fw, $mark_wp_start . "\n", strlen( $mark_wp_start ) + 1 );
265
+ fwrite( $fw, $mark_wp_end . "\n", strlen( $mark_wp_end ) + 1 );
266
  fwrite( $fw, "\n", 1 );
267
  }
268
  fclose( $fr );
classes/siteguard-login-alert.php CHANGED
@@ -1,35 +1,35 @@
1
  <?php
2
 
3
  class SiteGuard_LoginAlert extends SiteGuard_Base {
4
- function __construct( ) {
5
  global $siteguard_config;
6
  if ( '1' == $siteguard_config->get( 'loginalert_enable' ) ) {
7
  add_action( 'wp_login', array( $this, 'handler_wp_login' ), 10, 2 );
8
  }
9
  }
10
- function init( ) {
11
  global $siteguard_config;
12
- if ( true === siteguard_check_multisite( ) ) {
13
- $siteguard_config->set( 'loginalert_enable', '1' );
14
  } else {
15
- $siteguard_config->set( 'loginalert_enable', '0' );
16
  }
17
- $siteguard_config->set( 'loginalert_admin_only', '1' );
18
  $siteguard_config->set( 'loginalert_subject', __( 'New login at %SITENAME%', 'siteguard' ) );
19
- $siteguard_config->set( 'loginalert_body', __( "%USERNAME% logged in at %DATE% %TIME%\n\n== Login information ==\nIP Address: %IPADDRESS%\nReferer: %REFERER%\nUser-Agent: %USERAGENT%\n\n--\nSiteGuard WP Plugin", 'siteguard' ) );
20
- $siteguard_config->update( );
21
  }
22
  function replace_valuable( $string, $username ) {
23
  $search = array( '%SITENAME%', '%USERNAME%', '%DATE%', '%TIME%', '%IPADDRESS%', '%USERAGENT%', '%REFERER%' );
24
  $replace = array(
25
- get_option( 'blogname' ),
26
- $username,
27
- date( 'Y-m-d', current_time( 'timestamp' ) ),
28
- date( 'H:i:s', current_time( 'timestamp' ) ),
29
- $this->get_ip( ),
30
- isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '-',
31
- isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '-',
32
- );
33
  return str_replace( $search, $replace, $string );
34
  }
35
  function handler_wp_login( $username, $user ) {
1
  <?php
2
 
3
  class SiteGuard_LoginAlert extends SiteGuard_Base {
4
+ function __construct() {
5
  global $siteguard_config;
6
  if ( '1' == $siteguard_config->get( 'loginalert_enable' ) ) {
7
  add_action( 'wp_login', array( $this, 'handler_wp_login' ), 10, 2 );
8
  }
9
  }
10
+ function init() {
11
  global $siteguard_config;
12
+ if ( true === siteguard_check_multisite() ) {
13
+ $siteguard_config->set( 'loginalert_enable', '1' );
14
  } else {
15
+ $siteguard_config->set( 'loginalert_enable', '0' );
16
  }
17
+ $siteguard_config->set( 'loginalert_admin_only', '1' );
18
  $siteguard_config->set( 'loginalert_subject', __( 'New login at %SITENAME%', 'siteguard' ) );
19
+ $siteguard_config->set( 'loginalert_body', __( "%USERNAME% logged in at %DATE% %TIME%\n\n== Login information ==\nIP Address: %IPADDRESS%\nReferer: %REFERER%\nUser-Agent: %USERAGENT%\n\n--\nSiteGuard WP Plugin", 'siteguard' ) );
20
+ $siteguard_config->update();
21
  }
22
  function replace_valuable( $string, $username ) {
23
  $search = array( '%SITENAME%', '%USERNAME%', '%DATE%', '%TIME%', '%IPADDRESS%', '%USERAGENT%', '%REFERER%' );
24
  $replace = array(
25
+ get_option( 'blogname' ),
26
+ $username,
27
+ date( 'Y-m-d', current_time( 'timestamp' ) ),
28
+ date( 'H:i:s', current_time( 'timestamp' ) ),
29
+ $this->get_ip(),
30
+ isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '-',
31
+ isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '-',
32
+ );
33
  return str_replace( $search, $replace, $string );
34
  }
35
  function handler_wp_login( $username, $user ) {
classes/siteguard-login-history.php CHANGED
@@ -2,24 +2,24 @@
2
 
3
  class SiteGuard_LoginHistory extends SiteGuard_Base {
4
 
5
- function __construct( ) {
6
  define( 'SITEGUARD_TABLE_HISTORY', 'siteguard_history' );
7
  add_action( 'wp_login', array( $this, 'handler_wp_login' ), 1, 2 );
8
  add_action( 'wp_login_failed', array( $this, 'handler_wp_login_failed' ), 30 );
9
  add_action( 'xmlrpc_call', array( $this, 'handler_xmlrpc_call' ), 10, 1 );
10
  }
11
- function init( ) {
12
  global $wpdb;
13
- # operation
14
- # 0: Login failure
15
- # 1: Login success
16
- # 2: Fail once
17
- # 3: Login lock
18
- # type
19
- # 0: login page
20
- # 1: xmlrpc
21
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_HISTORY;
22
- $sql = "CREATE TABLE $table_name (
23
  id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
24
  login_name VARCHAR(40) NOT NULL DEFAULT '',
25
  ip_address VARCHAR(40) NOT NULL DEFAULT '',
@@ -29,10 +29,10 @@ class SiteGuard_LoginHistory extends SiteGuard_Base {
29
  UNIQUE KEY id (id)
30
  )
31
  CHARACTER SET 'utf8';";
32
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
33
  dbDelta( $sql );
34
  }
35
- function get_type( ) {
36
  $type = SITEGUARD_LOGIN_TYPE_NORMAL;
37
  if ( basename( $_SERVER['SCRIPT_NAME'] ) == 'xmlrpc.php' ) {
38
  $type = SITEGUARD_LOGIN_TYPE_XMLRPC;
@@ -58,14 +58,14 @@ class SiteGuard_LoginHistory extends SiteGuard_Base {
58
  if ( '' == $current_user->user_login ) {
59
  return;
60
  }
61
- $this->add_operation( SITEGUARD_LOGIN_SUCCESS, $current_user->user_login, $this->get_type( ) );
62
  }
63
  function handler_wp_login_failed( $username ) {
64
  global $siteguard_loginlock;
65
- $this->add_operation( $siteguard_loginlock->get_status( ), $username, $this->get_type( ) );
66
  }
67
  function handler_xmlrpc_call( $method ) {
68
- $current_user = wp_get_current_user( );
69
  if ( '' == $current_user->user_login ) {
70
  return;
71
  }
@@ -79,9 +79,9 @@ class SiteGuard_LoginHistory extends SiteGuard_Base {
79
  }
80
 
81
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_HISTORY;
82
- $ip_address = $this->get_ip( );
83
- $now = current_time( 'mysql' );
84
- $id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $table_name WHERE ip_address = %s AND login_name = %s AND operation = %d AND time BETWEEN %s - INTERVAL %d SECOND AND %s - INTERVAL %d SECOND; ", $ip_address, $user, $operation, $now, $less_sec, $now, $after_sec ) );
85
  if ( null == $id ) {
86
  return false;
87
  }
@@ -105,8 +105,8 @@ class SiteGuard_LoginHistory extends SiteGuard_Base {
105
  if ( null != $id ) {
106
  $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE id <= %d;", $id ) );
107
  }
108
- $ip_address = $this->get_ip( );
109
- $data = array(
110
  'operation' => $operation,
111
  'login_name' => $user,
112
  'ip_address' => $ip_address,
@@ -153,8 +153,8 @@ class SiteGuard_LoginHistory extends SiteGuard_Base {
153
  }
154
  function get_history( $operation, $login_name, $ip_address, $type, $login_name_not, $ip_address_not ) {
155
  global $wpdb;
156
- $where = '';
157
- $values = array( );
158
  if ( true === $this->check_operation( $operation ) ) {
159
  $where = 'operation = %d';
160
  array_push( $values, $operation );
@@ -180,7 +180,7 @@ class SiteGuard_LoginHistory extends SiteGuard_Base {
180
  $where .= 'ip_address = %s';
181
  }
182
  array_push( $values, $ip_address );
183
-
184
  }
185
  if ( true === $this->check_type( $type ) ) {
186
  if ( ! empty( $where ) ) {
@@ -192,12 +192,12 @@ class SiteGuard_LoginHistory extends SiteGuard_Base {
192
  if ( ! empty( $where ) ) {
193
  $where = 'WHERE ' . $where;
194
  } else {
195
- $where = "WHERE operation >= %d";
196
  array_push( $values, '0' );
197
  }
198
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_HISTORY;
199
- $prepare = array( );
200
- $prepare[] = "SELECT id, operation, login_name, ip_address, time, type FROM $table_name $where";
201
  foreach ( $values as $v ) {
202
  $prepare[] = $v;
203
  }
2
 
3
  class SiteGuard_LoginHistory extends SiteGuard_Base {
4
 
5
+ function __construct() {
6
  define( 'SITEGUARD_TABLE_HISTORY', 'siteguard_history' );
7
  add_action( 'wp_login', array( $this, 'handler_wp_login' ), 1, 2 );
8
  add_action( 'wp_login_failed', array( $this, 'handler_wp_login_failed' ), 30 );
9
  add_action( 'xmlrpc_call', array( $this, 'handler_xmlrpc_call' ), 10, 1 );
10
  }
11
+ function init() {
12
  global $wpdb;
13
+ // operation
14
+ // 0: Login failure
15
+ // 1: Login success
16
+ // 2: Fail once
17
+ // 3: Login lock
18
+ // type
19
+ // 0: login page
20
+ // 1: xmlrpc
21
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_HISTORY;
22
+ $sql = "CREATE TABLE $table_name (
23
  id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
24
  login_name VARCHAR(40) NOT NULL DEFAULT '',
25
  ip_address VARCHAR(40) NOT NULL DEFAULT '',
29
  UNIQUE KEY id (id)
30
  )
31
  CHARACTER SET 'utf8';";
32
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
33
  dbDelta( $sql );
34
  }
35
+ function get_type() {
36
  $type = SITEGUARD_LOGIN_TYPE_NORMAL;
37
  if ( basename( $_SERVER['SCRIPT_NAME'] ) == 'xmlrpc.php' ) {
38
  $type = SITEGUARD_LOGIN_TYPE_XMLRPC;
58
  if ( '' == $current_user->user_login ) {
59
  return;
60
  }
61
+ $this->add_operation( SITEGUARD_LOGIN_SUCCESS, $current_user->user_login, $this->get_type() );
62
  }
63
  function handler_wp_login_failed( $username ) {
64
  global $siteguard_loginlock;
65
+ $this->add_operation( $siteguard_loginlock->get_status(), $username, $this->get_type() );
66
  }
67
  function handler_xmlrpc_call( $method ) {
68
+ $current_user = wp_get_current_user();
69
  if ( '' == $current_user->user_login ) {
70
  return;
71
  }
79
  }
80
 
81
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_HISTORY;
82
+ $ip_address = $this->get_ip();
83
+ $now = current_time( 'mysql' );
84
+ $id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $table_name WHERE ip_address = %s AND login_name = %s AND operation = %d AND time BETWEEN %s - INTERVAL %d SECOND AND %s - INTERVAL %d SECOND; ", $ip_address, $user, $operation, $now, $less_sec, $now, $after_sec ) );
85
  if ( null == $id ) {
86
  return false;
87
  }
105
  if ( null != $id ) {
106
  $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE id <= %d;", $id ) );
107
  }
108
+ $ip_address = $this->get_ip();
109
+ $data = array(
110
  'operation' => $operation,
111
  'login_name' => $user,
112
  'ip_address' => $ip_address,
153
  }
154
  function get_history( $operation, $login_name, $ip_address, $type, $login_name_not, $ip_address_not ) {
155
  global $wpdb;
156
+ $where = '';
157
+ $values = array();
158
  if ( true === $this->check_operation( $operation ) ) {
159
  $where = 'operation = %d';
160
  array_push( $values, $operation );
180
  $where .= 'ip_address = %s';
181
  }
182
  array_push( $values, $ip_address );
183
+
184
  }
185
  if ( true === $this->check_type( $type ) ) {
186
  if ( ! empty( $where ) ) {
192
  if ( ! empty( $where ) ) {
193
  $where = 'WHERE ' . $where;
194
  } else {
195
+ $where = 'WHERE operation >= %d';
196
  array_push( $values, '0' );
197
  }
198
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_HISTORY;
199
+ $prepare = array();
200
+ $prepare[] = "SELECT id, operation, login_name, ip_address, time, type FROM $table_name $where";
201
  foreach ( $values as $v ) {
202
  $prepare[] = $v;
203
  }
classes/siteguard-login-lock.php CHANGED
@@ -2,8 +2,8 @@
2
 
3
  class SiteGuard_LoginLock extends SiteGuard_Base {
4
  const SITEGUARD_FAIL_ONCE_ERROR_CODE = 'siteguard-fail-once';
5
- protected $status = SITEGUARD_LOGIN_FAILED;
6
- function __construct( ) {
7
  global $siteguard_config;
8
  if ( '1' == $siteguard_config->get( 'loginlock_enable' ) ) {
9
  add_action( 'wp_login_failed', array( $this, 'handler_wp_login_failed' ) );
@@ -13,36 +13,36 @@ class SiteGuard_LoginLock extends SiteGuard_Base {
13
  add_filter( 'wp_authenticate_user', array( $this, 'handler_wp_authenticate_user' ), 99, 2 );
14
  }
15
  }
16
- function init( ) {
17
  global $siteguard_config;
18
- if ( true === siteguard_check_multisite( ) ) {
19
- $siteguard_config->set( 'loginlock_enable', '1' );
20
  } else {
21
- $siteguard_config->set( 'loginlock_enable', '0' );
22
  }
23
- $siteguard_config->set( 'loginlock_interval', '5' );
24
- $siteguard_config->set( 'loginlock_threshold', '3' );
25
- $siteguard_config->set( 'loginlock_locksec', '60' );
26
- $siteguard_config->set( 'loginlock_fail_once', '0' );
27
  $siteguard_config->set( 'fail_once_admin_only', '1' );
28
- $siteguard_config->update( );
29
  }
30
- function get_status( ) {
31
  return $this->status;
32
  }
33
  function handler_wp_login_failed( $username ) {
34
  global $wpdb, $siteguard_config, $siteguard_login_history;
35
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_LOGIN;
36
 
37
- $ip_address = $this->get_ip( );
38
 
39
  $wpdb->query( 'START TRANSACTION' );
40
  $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE status <> %d AND last_login_time < SYSDATE() - INTERVAL 1 HOUR;", SITEGUARD_LOGIN_SUCCESS ) );
41
- $result = $wpdb->get_row( $wpdb->prepare( "SELECT status, count, last_login_time from $table_name WHERE ip_address = %s", $ip_address ) );
42
- $data = array(
43
- 'ip_address' => $ip_address,
44
- 'status' => SITEGUARD_LOGIN_FAILED,
45
- 'count' => 1,
46
  'last_login_time' => 0,
47
  );
48
  $now_str = current_time( 'mysql' );
@@ -52,27 +52,27 @@ class SiteGuard_LoginLock extends SiteGuard_Base {
52
  $wpdb->insert( $table_name, $data );
53
  } else {
54
  $data['last_login_time'] = $result->last_login_time;
55
- $interval = intval( $siteguard_config->get( 'loginlock_interval' ) );
56
- $limit = strtotime( $result->last_login_time ) + $interval;
57
  if ( SITEGUARD_LOGIN_SUCCESS == $result->status ) {
58
  $data['last_login_time'] = $now_str;
59
  $wpdb->update( $table_name, $data, array( 'ip_address' => $ip_address ) );
60
- } else if ( SITEGUARD_LOGIN_FAILED == $result->status ) {
61
  if ( $now_bin <= $limit ) {
62
  $data['count'] = $result->count + 1;
63
  } else {
64
- $data['count'] = 1;
65
  $data['last_login_time'] = $now_str;
66
  }
67
  if ( $data['count'] >= intval( $siteguard_config->get( 'loginlock_threshold' ) ) ) {
68
- $data['status'] = SITEGUARD_LOGIN_LOCKED;
69
  $data['last_login_time'] = $now_str;
70
- $this->status = SITEGUARD_LOGIN_LOCKED;
71
  }
72
  $wpdb->update( $table_name, $data, array( 'ip_address' => $ip_address ) );
73
- } else if ( SITEGUARD_LOGIN_FAIL_ONCE == $result->status || ( SITEGUARD_LOGIN_LOCKED == $result->status && $now_bin > strtotime( $result->last_login_time ) + intval( $siteguard_config->get( 'loginlock_locksec' ) ) ) ) {
74
- $data['status'] = SITEGUARD_LOGIN_FAILED;
75
- $data['count'] = 1;
76
  $data['last_login_time'] = $now_str;
77
  $wpdb->update( $table_name, $data, array( 'ip_address' => $ip_address ) );
78
  }
@@ -85,9 +85,9 @@ class SiteGuard_LoginLock extends SiteGuard_Base {
85
  function is_locked( $ip_address ) {
86
  global $wpdb, $siteguard_config;
87
 
88
- $now_bin = strtotime( current_time( 'mysql' ) );
89
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_LOGIN;
90
- $result = $wpdb->get_row( $wpdb->prepare( "SELECT status, last_login_time from $table_name WHERE ip_address = %s", $ip_address ) );
91
  if ( null !== $result ) {
92
  if ( SITEGUARD_LOGIN_LOCKED == $result->status && $now_bin <= strtotime( $result->last_login_time ) + intval( $siteguard_config->get( 'loginlock_locksec' ) ) ) {
93
  return true;
@@ -96,8 +96,8 @@ class SiteGuard_LoginLock extends SiteGuard_Base {
96
  return false;
97
  }
98
  function handler_authenticate( $user, $username, $password ) {
99
- if ( $this->is_locked( $this->get_ip( ) ) ) {
100
- $new_errors = new WP_Error( );
101
  $new_errors->add( 'siteguard-error', esc_html__( 'ERROR: LOGIN LOCKED', 'siteguard' ) );
102
  $this->status = SITEGUARD_LOGIN_LOCKED;
103
  return $new_errors;
@@ -133,7 +133,7 @@ class SiteGuard_LoginLock extends SiteGuard_Base {
133
  if ( ! $siteguard_login_history->is_exist( $user_login, SITEGUARD_LOGIN_FAIL_ONCE, 5/* secs after */, 60/* secs less */ ) ) {
134
  $this->status = SITEGUARD_LOGIN_FAIL_ONCE;
135
 
136
- $new_error = new WP_Error( );
137
  $new_error->add( self::SITEGUARD_FAIL_ONCE_ERROR_CODE, esc_html__( 'ERROR: Please login entry again', 'siteguard' ) );
138
  add_filter( 'shake_error_codes', array( $this, 'handler_login_shake' ) );
139
  return $new_error;
2
 
3
  class SiteGuard_LoginLock extends SiteGuard_Base {
4
  const SITEGUARD_FAIL_ONCE_ERROR_CODE = 'siteguard-fail-once';
5
+ protected $status = SITEGUARD_LOGIN_FAILED;
6
+ function __construct() {
7
  global $siteguard_config;
8
  if ( '1' == $siteguard_config->get( 'loginlock_enable' ) ) {
9
  add_action( 'wp_login_failed', array( $this, 'handler_wp_login_failed' ) );
13
  add_filter( 'wp_authenticate_user', array( $this, 'handler_wp_authenticate_user' ), 99, 2 );
14
  }
15
  }
16
+ function init() {
17
  global $siteguard_config;
18
+ if ( true === siteguard_check_multisite() ) {
19
+ $siteguard_config->set( 'loginlock_enable', '1' );
20
  } else {
21
+ $siteguard_config->set( 'loginlock_enable', '0' );
22
  }
23
+ $siteguard_config->set( 'loginlock_interval', '5' );
24
+ $siteguard_config->set( 'loginlock_threshold', '3' );
25
+ $siteguard_config->set( 'loginlock_locksec', '60' );
26
+ $siteguard_config->set( 'loginlock_fail_once', '0' );
27
  $siteguard_config->set( 'fail_once_admin_only', '1' );
28
+ $siteguard_config->update();
29
  }
30
+ function get_status() {
31
  return $this->status;
32
  }
33
  function handler_wp_login_failed( $username ) {
34
  global $wpdb, $siteguard_config, $siteguard_login_history;
35
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_LOGIN;
36
 
37
+ $ip_address = $this->get_ip();
38
 
39
  $wpdb->query( 'START TRANSACTION' );
40
  $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE status <> %d AND last_login_time < SYSDATE() - INTERVAL 1 HOUR;", SITEGUARD_LOGIN_SUCCESS ) );
41
+ $result = $wpdb->get_row( $wpdb->prepare( "SELECT status, count, last_login_time from $table_name WHERE ip_address = %s", $ip_address ) );
42
+ $data = array(
43
+ 'ip_address' => $ip_address,
44
+ 'status' => SITEGUARD_LOGIN_FAILED,
45
+ 'count' => 1,
46
  'last_login_time' => 0,
47
  );
48
  $now_str = current_time( 'mysql' );
52
  $wpdb->insert( $table_name, $data );
53
  } else {
54
  $data['last_login_time'] = $result->last_login_time;
55
+ $interval = intval( $siteguard_config->get( 'loginlock_interval' ) );
56
+ $limit = strtotime( $result->last_login_time ) + $interval;
57
  if ( SITEGUARD_LOGIN_SUCCESS == $result->status ) {
58
  $data['last_login_time'] = $now_str;
59
  $wpdb->update( $table_name, $data, array( 'ip_address' => $ip_address ) );
60
+ } elseif ( SITEGUARD_LOGIN_FAILED == $result->status ) {
61
  if ( $now_bin <= $limit ) {
62
  $data['count'] = $result->count + 1;
63
  } else {
64
+ $data['count'] = 1;
65
  $data['last_login_time'] = $now_str;
66
  }
67
  if ( $data['count'] >= intval( $siteguard_config->get( 'loginlock_threshold' ) ) ) {
68
+ $data['status'] = SITEGUARD_LOGIN_LOCKED;
69
  $data['last_login_time'] = $now_str;
70
+ $this->status = SITEGUARD_LOGIN_LOCKED;
71
  }
72
  $wpdb->update( $table_name, $data, array( 'ip_address' => $ip_address ) );
73
+ } elseif ( SITEGUARD_LOGIN_FAIL_ONCE == $result->status || ( SITEGUARD_LOGIN_LOCKED == $result->status && $now_bin > strtotime( $result->last_login_time ) + intval( $siteguard_config->get( 'loginlock_locksec' ) ) ) ) {
74
+ $data['status'] = SITEGUARD_LOGIN_FAILED;
75
+ $data['count'] = 1;
76
  $data['last_login_time'] = $now_str;
77
  $wpdb->update( $table_name, $data, array( 'ip_address' => $ip_address ) );
78
  }
85
  function is_locked( $ip_address ) {
86
  global $wpdb, $siteguard_config;
87
 
88
+ $now_bin = strtotime( current_time( 'mysql' ) );
89
  $table_name = $wpdb->prefix . SITEGUARD_TABLE_LOGIN;
90
+ $result = $wpdb->get_row( $wpdb->prepare( "SELECT status, last_login_time from $table_name WHERE ip_address = %s", $ip_address ) );
91
  if ( null !== $result ) {
92
  if ( SITEGUARD_LOGIN_LOCKED == $result->status && $now_bin <= strtotime( $result->last_login_time ) + intval( $siteguard_config->get( 'loginlock_locksec' ) ) ) {
93
  return true;
96
  return false;
97
  }
98
  function handler_authenticate( $user, $username, $password ) {
99
+ if ( $this->is_locked( $this->get_ip() ) ) {
100
+ $new_errors = new WP_Error();
101
  $new_errors->add( 'siteguard-error', esc_html__( 'ERROR: LOGIN LOCKED', 'siteguard' ) );
102
  $this->status = SITEGUARD_LOGIN_LOCKED;
103
  return $new_errors;
133
  if ( ! $siteguard_login_history->is_exist( $user_login, SITEGUARD_LOGIN_FAIL_ONCE, 5/* secs after */, 60/* secs less */ ) ) {
134
  $this->status = SITEGUARD_LOGIN_FAIL_ONCE;
135
 
136
+ $new_error = new WP_Error();
137
  $new_error->add( self::SITEGUARD_FAIL_ONCE_ERROR_CODE, esc_html__( 'ERROR: Please login entry again', 'siteguard' ) );
138
  add_filter( 'shake_error_codes', array( $this, 'handler_login_shake' ) );
139
  return $new_error;
classes/siteguard-rename-login.php CHANGED
@@ -1,51 +1,51 @@
1
  <?php
2
 
3
- require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
4
 
5
  class SiteGuard_RenameLogin extends SiteGuard_Base {
6
  protected static $incompatible_plugins = array(
7
  'WordPress HTTPS (SSL)' => 'wordpress-https/wordpress-https.php',
8
- 'qTranslate X' => 'qtranslate-x/qtranslate.php',
9
- );
10
- public static $htaccess_mark = '#==== SITEGUARD_RENAME_LOGIN_SETTINGS';
11
 
12
- function __construct( ) {
13
  global $siteguard_config;
14
  if ( '1' == $siteguard_config->get( 'renamelogin_enable' ) ) {
15
- if ( null !== $this->get_active_incompatible_plugins( ) ) {
16
  $siteguard_config->set( 'renamelogin_enable', '0' );
17
- $siteguard_config->update( );
18
- $this->feature_off( );
19
  return;
20
  }
21
- $this->add_filter( );
22
  }
23
  }
24
- static function get_mark( ) {
25
- return SiteGuard_RenameLogin::$htaccess_mark;
26
  }
27
- function init( ) {
28
  global $siteguard_config;
29
  $siteguard_config->set( 'renamelogin_path', 'login_' . sprintf( '%05d', mt_rand( 1, 99999 ) ) );
30
  $siteguard_config->set( 'redirect_enable', '0' );
31
  $siteguard_config->update();
32
  if ( $this->check_module( 'rewrite' ) &&
33
- null === $this->get_active_incompatible_plugins( ) &&
34
- true === siteguard_check_multisite( ) &&
35
- SiteGuard_Htaccess::test_htaccess( )
36
  ) {
37
  $siteguard_config->set( 'renamelogin_enable', '1' );
38
- $siteguard_config->update( );
39
- if ( false === $this->feature_on( ) ) {
40
  $siteguard_config->set( 'renamelogin_enable', '0' );
41
- $siteguard_config->update( );
42
  }
43
  } else {
44
  $siteguard_config->set( 'renamelogin_enable', '0' );
45
- $siteguard_config->update( );
46
  }
47
  }
48
- function get_active_incompatible_plugins( ) {
49
  $result = array();
50
  foreach ( self::$incompatible_plugins as $name => $path ) {
51
  if ( is_plugin_active( $path ) ) {
@@ -58,27 +58,27 @@ class SiteGuard_RenameLogin extends SiteGuard_Base {
58
  return $result;
59
  }
60
  }
61
- function add_filter( ) {
62
- add_filter( 'login_init', array( $this, 'handler_login_init' ), 10, 2 );
63
- add_filter( 'site_url', array( $this, 'handler_site_url' ), 10, 2 );
64
- add_filter( 'network_site_url', array( $this, 'handler_site_url' ), 10, 2 );
65
- add_filter( 'wp_redirect', array( $this, 'handler_wp_redirect' ), 10, 2 );
66
- add_filter( 'register', array( $this, 'handler_register' ) );
67
- add_filter('auth_redirect_scheme', array( $this, 'handler_stop_redirect' ), 9999 );
68
  remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
69
  }
70
- function handler_login_init( ) {
71
  global $siteguard_config;
72
  $new_login_page = $siteguard_config->get( 'renamelogin_path' );
73
  if ( isset( $_SERVER['REQUEST_URI'] ) ) {
74
- $link = $_SERVER['REQUEST_URI'];
75
  } else {
76
  $link = '';
77
  }
78
  if ( false !== strpos( $link, 'wp-login' ) ) {
79
- $referer = wp_get_referer( );
80
  if ( false === strpos( $referer, $new_login_page ) ) {
81
- $this->set_404( );
82
  } else {
83
  $result = $this->convert_url( $link );
84
  wp_redirect( $result );
@@ -105,8 +105,8 @@ class SiteGuard_RenameLogin extends SiteGuard_Base {
105
  }
106
  function handler_wp_redirect( $link, $status_code ) {
107
  if ( ( ( strlen( $link ) <= 5 || 'http:' !== strtolower( substr( $link, 0, 5 ) ) ) && ( strlen( $link ) <= 6 || 'https:' !== strtolower( substr( $link, 0, 6 ) ) ) )
108
- || ( isset( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) !== 'off' && 'https' === strtolower( substr( $link, 0, strpos( $link, '://') ) ) )
109
- || ( ( ! isset( $_SERVER['HTTPS'] ) || strtolower( $_SERVER['HTTPS'] ) === 'off' ) && 'http' === strtolower( substr( $link, 0, strpos( $link, '://') ) ) ) ) {
110
  $result = $this->convert_url( $link );
111
  } else {
112
  $result = $link;
@@ -115,15 +115,15 @@ class SiteGuard_RenameLogin extends SiteGuard_Base {
115
  }
116
  function insert_rewrite_rules( $rules ) {
117
  global $siteguard_config;
118
- $custom_login_url = $siteguard_config->get( 'renamelogin_path' );
119
- $newrules = array();
120
- $newrules[ $custom_login_url.'(.*)$' ] = 'wp-login.php$1';
121
  return $newrules + $rules;
122
  }
123
- function update_settings( ) {
124
  global $siteguard_config;
125
  $custom_login_url = $siteguard_config->get( 'renamelogin_path' );
126
- $parse_url = parse_url( site_url( ) );
127
  if ( false === $parse_url ) {
128
  $base = '/';
129
  } else {
@@ -134,7 +134,7 @@ class SiteGuard_RenameLogin extends SiteGuard_Base {
134
  }
135
  }
136
 
137
- $htaccess_str = "<IfModule mod_rewrite.c>\n";
138
  $htaccess_str .= " RewriteEngine on\n";
139
  $htaccess_str .= " RewriteBase $base\n";
140
  $htaccess_str .= " RewriteRule ^wp-signup\.php 404-siteguard [L]\n";
@@ -144,33 +144,33 @@ class SiteGuard_RenameLogin extends SiteGuard_Base {
144
 
145
  return $htaccess_str;
146
  }
147
- function feature_on( ) {
148
  global $siteguard_htaccess;
149
- if ( false === SiteGuard_Htaccess::check_permission( ) ) {
150
  return false;
151
  }
152
- $data = $this->update_settings( );
153
- $mark = $this->get_mark( );
154
  return $siteguard_htaccess->update_settings( $mark, $data );
155
  }
156
- static function feature_off( ) {
157
- $mark = SiteGuard_RenameLogin::get_mark( );
158
  return SiteGuard_Htaccess::clear_settings( $mark );
159
  }
160
- function set_404( ) {
161
  global $wp_query;
162
  status_header( 404 );
163
- $wp_query->set_404( );
164
- if ( ( ( $template = get_404_template( ) ) || ( $template = get_index_template( ) ) )
165
  && ( $template = apply_filters( 'template_include', $template ) ) ) {
166
- include( $template );
167
  }
168
  die;
169
  }
170
- function send_notify( ) {
171
  global $siteguard_config;
172
  $subject = esc_html__( 'WordPress: Login page URL was changed', 'siteguard' );
173
- $body = sprintf( esc_html__( "Please bookmark following of the new login URL.\n\n%s\n\n--\nSiteGuard WP Plugin", 'siteguard' ), site_url( ) . '/' . $siteguard_config->get( 'renamelogin_path' ) );
174
 
175
  $user_query = new WP_User_Query( array( 'role' => 'Administrator' ) );
176
  if ( ! empty( $user_query->results ) ) {
@@ -182,16 +182,15 @@ class SiteGuard_RenameLogin extends SiteGuard_Base {
182
  }
183
  }
184
  }
185
- function handler_stop_redirect($scheme)
186
- {
187
- global $siteguard_config;
188
- $redirect_enable = $siteguard_config->get( 'redirect_enable' );
189
- if( $redirect_enable == 1 ){
190
- if ( $user_id = wp_validate_auth_cookie( '', $scheme) ) {
191
- return $scheme;
192
- }
193
- wp_safe_redirect( home_url( ) );
194
- exit;
195
- }
196
  }
197
  }
1
  <?php
2
 
3
+ require_once ABSPATH . '/wp-admin/includes/plugin.php';
4
 
5
  class SiteGuard_RenameLogin extends SiteGuard_Base {
6
  protected static $incompatible_plugins = array(
7
  'WordPress HTTPS (SSL)' => 'wordpress-https/wordpress-https.php',
8
+ 'qTranslate X' => 'qtranslate-x/qtranslate.php',
9
+ );
10
+ public static $htaccess_mark = '#==== SITEGUARD_RENAME_LOGIN_SETTINGS';
11
 
12
+ function __construct() {
13
  global $siteguard_config;
14
  if ( '1' == $siteguard_config->get( 'renamelogin_enable' ) ) {
15
+ if ( null !== $this->get_active_incompatible_plugins() ) {
16
  $siteguard_config->set( 'renamelogin_enable', '0' );
17
+ $siteguard_config->update();
18
+ $this->feature_off();
19
  return;
20
  }
21
+ $this->add_filter();
22
  }
23
  }
24
+ static function get_mark() {
25
+ return self::$htaccess_mark;
26
  }
27
+ function init() {
28
  global $siteguard_config;
29
  $siteguard_config->set( 'renamelogin_path', 'login_' . sprintf( '%05d', mt_rand( 1, 99999 ) ) );
30
  $siteguard_config->set( 'redirect_enable', '0' );
31
  $siteguard_config->update();
32
  if ( $this->check_module( 'rewrite' ) &&
33
+ null === $this->get_active_incompatible_plugins() &&
34
+ true === siteguard_check_multisite() &&
35
+ SiteGuard_Htaccess::test_htaccess()
36
  ) {
37
  $siteguard_config->set( 'renamelogin_enable', '1' );
38
+ $siteguard_config->update();
39
+ if ( false === $this->feature_on() ) {
40
  $siteguard_config->set( 'renamelogin_enable', '0' );
41
+ $siteguard_config->update();
42
  }
43
  } else {
44
  $siteguard_config->set( 'renamelogin_enable', '0' );
45
+ $siteguard_config->update();
46
  }
47
  }
48
+ function get_active_incompatible_plugins() {
49
  $result = array();
50
  foreach ( self::$incompatible_plugins as $name => $path ) {
51
  if ( is_plugin_active( $path ) ) {
58
  return $result;
59
  }
60
  }
61
+ function add_filter() {
62
+ add_filter( 'login_init', array( $this, 'handler_login_init' ), 10, 2 );
63
+ add_filter( 'site_url', array( $this, 'handler_site_url' ), 10, 2 );
64
+ add_filter( 'network_site_url', array( $this, 'handler_site_url' ), 10, 2 );
65
+ add_filter( 'wp_redirect', array( $this, 'handler_wp_redirect' ), 10, 2 );
66
+ add_filter( 'register', array( $this, 'handler_register' ) );
67
+ add_filter( 'auth_redirect_scheme', array( $this, 'handler_stop_redirect' ), 9999 );
68
  remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
69
  }
70
+ function handler_login_init() {
71
  global $siteguard_config;
72
  $new_login_page = $siteguard_config->get( 'renamelogin_path' );
73
  if ( isset( $_SERVER['REQUEST_URI'] ) ) {
74
+ $link = sanitize_url( $_SERVER['REQUEST_URI'] );
75
  } else {
76
  $link = '';
77
  }
78
  if ( false !== strpos( $link, 'wp-login' ) ) {
79
+ $referer = wp_get_referer();
80
  if ( false === strpos( $referer, $new_login_page ) ) {
81
+ $this->set_404();
82
  } else {
83
  $result = $this->convert_url( $link );
84
  wp_redirect( $result );
105
  }
106
  function handler_wp_redirect( $link, $status_code ) {
107
  if ( ( ( strlen( $link ) <= 5 || 'http:' !== strtolower( substr( $link, 0, 5 ) ) ) && ( strlen( $link ) <= 6 || 'https:' !== strtolower( substr( $link, 0, 6 ) ) ) )
108
+ || ( isset( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) !== 'off' && 'https' === strtolower( substr( $link, 0, strpos( $link, '://' ) ) ) )
109
+ || ( ( ! isset( $_SERVER['HTTPS'] ) || strtolower( $_SERVER['HTTPS'] ) === 'off' ) && 'http' === strtolower( substr( $link, 0, strpos( $link, '://' ) ) ) ) ) {
110
  $result = $this->convert_url( $link );
111
  } else {
112
  $result = $link;
115
  }
116
  function insert_rewrite_rules( $rules ) {
117
  global $siteguard_config;
118
+ $custom_login_url = $siteguard_config->get( 'renamelogin_path' );
119
+ $newrules = array();
120
+ $newrules[ $custom_login_url . '(.*)$' ] = 'wp-login.php$1';
121
  return $newrules + $rules;
122
  }
123
+ function update_settings() {
124
  global $siteguard_config;
125
  $custom_login_url = $siteguard_config->get( 'renamelogin_path' );
126
+ $parse_url = parse_url( site_url() );
127
  if ( false === $parse_url ) {
128
  $base = '/';
129
  } else {
134
  }
135
  }
136
 
137
+ $htaccess_str = "<IfModule mod_rewrite.c>\n";
138
  $htaccess_str .= " RewriteEngine on\n";
139
  $htaccess_str .= " RewriteBase $base\n";
140
  $htaccess_str .= " RewriteRule ^wp-signup\.php 404-siteguard [L]\n";
144
 
145
  return $htaccess_str;
146
  }
147
+ function feature_on() {
148
  global $siteguard_htaccess;
149
+ if ( false === SiteGuard_Htaccess::check_permission() ) {
150
  return false;
151
  }
152
+ $data = $this->update_settings();
153
+ $mark = $this->get_mark();
154
  return $siteguard_htaccess->update_settings( $mark, $data );
155
  }
156
+ static function feature_off() {
157
+ $mark = self::get_mark();
158
  return SiteGuard_Htaccess::clear_settings( $mark );
159
  }
160
+ function set_404() {
161
  global $wp_query;
162
  status_header( 404 );
163
+ $wp_query->set_404();
164
+ if ( ( ( $template = get_404_template() ) || ( $template = get_index_template() ) )
165
  && ( $template = apply_filters( 'template_include', $template ) ) ) {
166
+ include $template;
167
  }
168
  die;
169
  }
170
+ function send_notify() {
171
  global $siteguard_config;
172
  $subject = esc_html__( 'WordPress: Login page URL was changed', 'siteguard' );
173
+ $body = sprintf( esc_html__( "Please bookmark following of the new login URL.\n\n%s\n\n--\nSiteGuard WP Plugin", 'siteguard' ), site_url() . '/' . $siteguard_config->get( 'renamelogin_path' ) );
174
 
175
  $user_query = new WP_User_Query( array( 'role' => 'Administrator' ) );
176
  if ( ! empty( $user_query->results ) ) {
182
  }
183
  }
184
  }
185
+ function handler_stop_redirect( $scheme ) {
186
+ global $siteguard_config;
187
+ $redirect_enable = $siteguard_config->get( 'redirect_enable' );
188
+ if ( $redirect_enable == 1 ) {
189
+ if ( $user_id = wp_validate_auth_cookie( '', $scheme ) ) {
190
+ return $scheme;
191
+ }
192
+ wp_safe_redirect( home_url() );
193
+ exit;
194
+ }
 
195
  }
196
  }
classes/siteguard-updates-notify.php CHANGED
@@ -5,61 +5,68 @@
5
  class SiteGuard_UpdatesNotify extends SiteGuard_Base {
6
  const CRON_NAME = 'siteguard_update_check';
7
 
8
- function __construct( ) {
9
  add_action( self::CRON_NAME, array( $this, 'do_update_check' ) ); // action to link cron task to actual task
10
  }
11
 
12
- public function init( ) {
13
  global $siteguard_config;
14
  $siteguard_config->set( 'notify_wpcore', '1' );
15
  $siteguard_config->set( 'notify_plugins', '2' );
16
- $siteguard_config->set( 'notify_themes', '2' );
17
- $siteguard_config->set( 'notified', array( 'core' => '', 'plugin' => array(), 'theme' => array() ) );
 
 
 
 
 
 
 
18
  $siteguard_config->set( 'last_check_time', false );
19
  // We need save the configuration before calling self::check_requirements.
20
- $siteguard_config->update( );
21
- if ( true === self::check_requirements( ) ) {
22
  $siteguard_config->set( 'updates_notify_enable', '1' );
23
- $siteguard_config->update( );
24
- self::feature_on( );
25
  } else {
26
  $siteguard_config->set( 'updates_notify_enable', '0' );
27
- $siteguard_config->update( );
28
  }
29
  }
30
- public static function check_requirements( ) {
31
- $error = siteguard_check_multisite( );
32
  if ( is_wp_error( $error ) ) {
33
  return $error;
34
  }
35
- $error = self::check_disable_wp_cron( );
36
  if ( is_wp_error( $error ) ) {
37
  return $error;
38
  }
39
- $error = self::check_wp_cron_access( );
40
  if ( is_wp_error( $error ) ) {
41
  return $error;
42
  }
43
  return true;
44
  }
45
- static function check_disable_wp_cron( ) {
46
  if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
47
- $message = esc_html__( "DISABLE_WP_CRON is defined true. This function can't be used.", 'siteguard' );
48
- $error = new WP_Error( 'siteguard_updates_notify', $message );
49
  return $error;
50
  }
51
  return true;
52
  }
53
- static function check_wp_cron_access( ) {
54
  $result = wp_remote_post( site_url( '/wp-cron.php' ) );
55
  if ( ! is_wp_error( $result ) && 200 === $result['response']['code'] ) {
56
  return true;
57
  }
58
- $message = esc_html__( 'Please solve the problem that can not be accessed wp-cron.php. Might be access control.', 'siteguard' );
59
- $error = new WP_Error( 'siteguard_updates_notify', $message );
60
  return $error;
61
  }
62
- public function feature_on( ) {
63
  // Already scheduled
64
  if ( false !== wp_get_schedule( self::CRON_NAME ) ) {
65
  return;
@@ -69,7 +76,7 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
69
  wp_schedule_event( time(), 'daily', self::CRON_NAME );
70
  }
71
 
72
- static public function feature_off() {
73
  wp_clear_scheduled_hook( self::CRON_NAME ); // clear cron
74
  }
75
 
@@ -92,7 +99,7 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
92
  $themes_updated = false; // no theme updates
93
  }
94
  if ( $core_updated || $plugins_updated || $themes_updated ) { // Did anything come back as need updating?
95
- $message = esc_html__( 'There are updates available for your WordPress site:', 'siteguard' ) . "\n" . $message . "\n";
96
  $message .= sprintf( esc_html__( 'Please visit %s to update.', 'siteguard' ), admin_url( 'update-core.php' ) ) . "\n\n--\nSiteGuard WP Plugin";
97
  self::send_notify( $message ); // send our notification email.
98
  }
@@ -104,16 +111,16 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
104
  global $siteguard_config, $wp_version;
105
  do_action( 'wp_version_check' ); // force WP to check its core for updates
106
  $update_core = get_site_transient( 'update_core' ); // get information of updates
107
- $notified = $siteguard_config->get( 'notified' );
108
  if ( 'upgrade' == $update_core->updates[0]->response ) { // is WP core update available?
109
  if ( $update_core->updates[0]->current != $notified['core'] ) { // have we already notified about this version?
110
- require_once( ABSPATH . WPINC . '/version.php' ); // Including this because some plugins can mess with the real version stored in the DB.
111
- $new_core_ver = $update_core->updates[0]->current; // The new WP core version
112
- $old_core_ver = $wp_version; // the old WP core version
113
- $message .= "\n" . sprintf( esc_html__( 'WP-Core: WordPress is out of date. Please update from version %s to %s', 'siteguard' ), $old_core_ver, $new_core_ver ) . "\n";
114
  $notified['core'] = $new_core_ver; // set core version we are notifying about
115
  $siteguard_config->set( 'notified', $notified );
116
- $siteguard_config->update( );
117
  return true; // we have updates so return true
118
  } else {
119
  return false; // There are updates but we have already notified in the past.
@@ -121,14 +128,14 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
121
  }
122
  $notified['core'] = ''; // no updates lets set this nothing
123
  $siteguard_config->set( 'notified', $notified );
124
- $siteguard_config->update( );
125
  return false; // no updates return false
126
  }
127
 
128
  private static function plugins_update_check( &$message, $allOrActive ) {
129
  global $siteguard_config, $wp_version;
130
  $cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
131
- $notified = $siteguard_config->get( 'notified' );
132
  do_action( 'wp_update_plugins' ); // force WP to check plugins for updates
133
  $update_plugins = get_site_transient( 'update_plugins' ); // get information of updates
134
  if ( ! empty( $update_plugins->response ) ) { // any plugin updates available?
@@ -139,14 +146,14 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
139
  }
140
  $plugins_need_update = self::check_plugins_against_notified( $plugins_need_update ); // additional filtering of plugins need update
141
  if ( is_array( $plugins_need_update ) && count( $plugins_need_update ) >= 1 ) { // any plugins need updating after all the filtering gone on above?
142
- require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); // Required for plugin API
143
- require_once( ABSPATH . WPINC . '/version.php' ); // Required for WP core version
144
  foreach ( $plugins_need_update as $key => $data ) { // loop through the plugins that need updating
145
  $plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $key ); // get local plugin info
146
  $info = plugins_api( 'plugin_information', array( 'slug' => $data->slug ) ); // get repository plugin info
147
- $message .= "\n" . sprintf( esc_html__( 'Plugin: %s is out of date. Please update from version %s to %s', 'siteguard' ), $plugin_info['Name'], $plugin_info['Version'], $data->new_version ) . "\n";
148
- $message .= "\t" . sprintf( esc_html__( 'Details: %s', 'siteguard' ), $data->url ) . "\n";
149
- $message .= "\t" . sprintf( esc_html__( 'Changelog: %s%s', 'siteguard' ), $data->url, 'changelog/' ) . "\n";
150
  if ( isset( $info->tested ) && version_compare( $info->tested, $wp_version, '>=' ) ) {
151
  $compat = sprintf( esc_html__( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $cur_wp_version );
152
  } elseif ( isset( $info->compatibility[ $wp_version ][ $data->new_version ] ) ) {
@@ -155,18 +162,18 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
155
  } else {
156
  $compat = sprintf( esc_html__( 'Compatibility with WordPress %1$s: Unknown' ), $wp_version );
157
  }
158
- $message .= "\t" . sprintf( esc_html__( 'Compatibility: %s', 'siteguard' ), $compat ) . "\n";
159
  $notified['plugin'][ $key ] = $data->new_version; // set plugin version we are notifying about
160
  }
161
  $siteguard_config->set( 'notified', $notified );
162
- $siteguard_config->update( );
163
  return true; // we have plugin updates return true
164
  }
165
  } else {
166
  if ( 0 != count( $notified['plugin'] ) ) { // is there any plugin notifications?
167
  $notified['plugin'] = array(); // set plugin notifications to empty as all plugins up-to-date
168
  $siteguard_config->set( 'notified', $notified );
169
- $siteguard_config->update( );
170
  }
171
  }
172
  return false; // No plugin updates so return false
@@ -186,19 +193,19 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
186
  $themes_need_update = self::check_themes_against_notified( $themes_need_update ); // additional filtering of themes need update
187
  if ( is_array( $themes_need_update ) && count( $themes_need_update ) >= 1 ) { // any themes need updating after all the filtering gone on above?
188
  foreach ( $themes_need_update as $key => $data ) { // loop through the themes that need updating
189
- $theme_info = wp_get_theme( $key ); // get theme info
190
- $message .= "\n" . sprintf( esc_html__( 'Theme: %s is out of date. Please update from version %s to %s', 'siteguard' ), $theme_info['Name'], $theme_info['Version'], $data['new_version'] ) . "\n";
191
  $notified['theme'][ $key ] = $data['new_version']; // set theme version we are notifying about
192
  }
193
  $siteguard_config->set( 'notified', $notified );
194
- $siteguard_config->update( );
195
  return true; // we have theme updates return true
196
  }
197
  } else {
198
  if ( 0 != count( $notified['theme'] ) ) { // is there any theme notifications?
199
  $notified['theme'] = array(); // set theme notifications to empty as all themes up-to-date
200
  $siteguard_config->set( 'notified', $notified );
201
- $siteguard_config->update( );
202
  }
203
  }
204
  return false; // No theme updates so return false
@@ -242,7 +249,8 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
242
  if ( is_array( $user_query->results ) ) {
243
  foreach ( $user_query->results as $user ) {
244
  $user_email = $user->get( 'user_email' );
245
- if ( true !== @wp_mail( $user_email, $subject, $message ) ) {;
 
246
  siteguard_error_log( 'Failed send mail. To:' . $user_email . ' Subject:' . esc_html( $subject ) );
247
  }
248
  }
@@ -252,7 +260,7 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
252
  private function log_last_check_time() {
253
  global $siteguard_config;
254
  $siteguard_config->set( 'last_check_time', current_time( 'timestamp' ) );
255
- $siteguard_config->update( );
256
  }
257
 
258
  private static function get_schedules() {
@@ -263,7 +271,7 @@ class SiteGuard_UpdatesNotify extends SiteGuard_Base {
263
 
264
 
265
  private static function get_intervals() {
266
- $intervals = array_keys( self::get_schedules() );
267
  return $intervals;
268
  }
269
 
5
  class SiteGuard_UpdatesNotify extends SiteGuard_Base {
6
  const CRON_NAME = 'siteguard_update_check';
7
 
8
+ function __construct() {
9
  add_action( self::CRON_NAME, array( $this, 'do_update_check' ) ); // action to link cron task to actual task
10
  }
11
 
12
+ public function init() {
13
  global $siteguard_config;
14
  $siteguard_config->set( 'notify_wpcore', '1' );
15
  $siteguard_config->set( 'notify_plugins', '2' );
16
+ $siteguard_config->set( 'notify_themes', '2' );
17
+ $siteguard_config->set(
18
+ 'notified',
19
+ array(
20
+ 'core' => '',
21
+ 'plugin' => array(),
22
+ 'theme' => array(),
23
+ )
24
+ );
25
  $siteguard_config->set( 'last_check_time', false );
26
  // We need save the configuration before calling self::check_requirements.
27
+ $siteguard_config->update();
28
+ if ( true === self::check_requirements() ) {
29
  $siteguard_config->set( 'updates_notify_enable', '1' );
30
+ $siteguard_config->update();
31
+ self::feature_on();
32
  } else {
33
  $siteguard_config->set( 'updates_notify_enable', '0' );
34
+ $siteguard_config->update();
35
  }
36
  }
37
+ public static function check_requirements() {
38
+ $error = siteguard_check_multisite();
39
  if ( is_wp_error( $error ) ) {
40
  return $error;
41
  }
42
+ $error = self::check_disable_wp_cron();
43
  if ( is_wp_error( $error ) ) {
44
  return $error;
45
  }
46
+ $error = self::check_wp_cron_access();
47
  if ( is_wp_error( $error ) ) {
48
  return $error;
49
  }
50
  return true;
51
  }
52
+ static function check_disable_wp_cron() {
53
  if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
54
+ $message = esc_html__( "DISABLE_WP_CRON is defined true. This function can't be used.", 'siteguard' );
55
+ $error = new WP_Error( 'siteguard_updates_notify', $message );
56
  return $error;
57
  }
58
  return true;
59
  }
60
+ static function check_wp_cron_access() {
61
  $result = wp_remote_post( site_url( '/wp-cron.php' ) );
62
  if ( ! is_wp_error( $result ) && 200 === $result['response']['code'] ) {
63
  return true;
64
  }
65
+ $message = esc_html__( 'Please solve the problem that can not be accessed wp-cron.php. Might be access control.', 'siteguard' );
66
+ $error = new WP_Error( 'siteguard_updates_notify', $message );
67
  return $error;
68
  }
69
+ public function feature_on() {
70
  // Already scheduled
71
  if ( false !== wp_get_schedule( self::CRON_NAME ) ) {
72
  return;
76
  wp_schedule_event( time(), 'daily', self::CRON_NAME );
77
  }
78
 
79
+ public static function feature_off() {
80
  wp_clear_scheduled_hook( self::CRON_NAME ); // clear cron
81
  }
82
 
99
  $themes_updated = false; // no theme updates
100
  }
101
  if ( $core_updated || $plugins_updated || $themes_updated ) { // Did anything come back as need updating?
102
+ $message = esc_html__( 'There are updates available for your WordPress site:', 'siteguard' ) . "\n" . $message . "\n";
103
  $message .= sprintf( esc_html__( 'Please visit %s to update.', 'siteguard' ), admin_url( 'update-core.php' ) ) . "\n\n--\nSiteGuard WP Plugin";
104
  self::send_notify( $message ); // send our notification email.
105
  }
111
  global $siteguard_config, $wp_version;
112
  do_action( 'wp_version_check' ); // force WP to check its core for updates
113
  $update_core = get_site_transient( 'update_core' ); // get information of updates
114
+ $notified = $siteguard_config->get( 'notified' );
115
  if ( 'upgrade' == $update_core->updates[0]->response ) { // is WP core update available?
116
  if ( $update_core->updates[0]->current != $notified['core'] ) { // have we already notified about this version?
117
+ require_once ABSPATH . WPINC . '/version.php'; // Including this because some plugins can mess with the real version stored in the DB.
118
+ $new_core_ver = $update_core->updates[0]->current; // The new WP core version
119
+ $old_core_ver = $wp_version; // the old WP core version
120
+ $message .= "\n" . sprintf( esc_html__( 'WP-Core: WordPress is out of date. Please update from version %1$s to %2$s', 'siteguard' ), $old_core_ver, $new_core_ver ) . "\n";
121
  $notified['core'] = $new_core_ver; // set core version we are notifying about
122
  $siteguard_config->set( 'notified', $notified );
123
+ $siteguard_config->update();
124
  return true; // we have updates so return true
125
  } else {
126
  return false; // There are updates but we have already notified in the past.
128
  }
129
  $notified['core'] = ''; // no updates lets set this nothing
130
  $siteguard_config->set( 'notified', $notified );
131
+ $siteguard_config->update();
132
  return false; // no updates return false
133
  }
134
 
135
  private static function plugins_update_check( &$message, $allOrActive ) {
136
  global $siteguard_config, $wp_version;
137
  $cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
138
+ $notified = $siteguard_config->get( 'notified' );
139
  do_action( 'wp_update_plugins' ); // force WP to check plugins for updates
140
  $update_plugins = get_site_transient( 'update_plugins' ); // get information of updates
141
  if ( ! empty( $update_plugins->response ) ) { // any plugin updates available?
146
  }
147
  $plugins_need_update = self::check_plugins_against_notified( $plugins_need_update ); // additional filtering of plugins need update
148
  if ( is_array( $plugins_need_update ) && count( $plugins_need_update ) >= 1 ) { // any plugins need updating after all the filtering gone on above?
149
+ require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Required for plugin API
150
+ require_once ABSPATH . WPINC . '/version.php'; // Required for WP core version
151
  foreach ( $plugins_need_update as $key => $data ) { // loop through the plugins that need updating
152
  $plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $key ); // get local plugin info
153
  $info = plugins_api( 'plugin_information', array( 'slug' => $data->slug ) ); // get repository plugin info
154
+ $message .= "\n" . sprintf( esc_html__( 'Plugin: %1$s is out of date. Please update from version %2$s to %3$s', 'siteguard' ), $plugin_info['Name'], $plugin_info['Version'], $data->new_version ) . "\n";
155
+ $message .= "\t" . sprintf( esc_html__( 'Details: %s', 'siteguard' ), $data->url ) . "\n";
156
+ $message .= "\t" . sprintf( esc_html__( 'Changelog: %1$s%2$s', 'siteguard' ), $data->url, 'changelog/' ) . "\n";
157
  if ( isset( $info->tested ) && version_compare( $info->tested, $wp_version, '>=' ) ) {
158
  $compat = sprintf( esc_html__( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $cur_wp_version );
159
  } elseif ( isset( $info->compatibility[ $wp_version ][ $data->new_version ] ) ) {
162
  } else {
163
  $compat = sprintf( esc_html__( 'Compatibility with WordPress %1$s: Unknown' ), $wp_version );
164
  }
165
+ $message .= "\t" . sprintf( esc_html__( 'Compatibility: %s', 'siteguard' ), $compat ) . "\n";
166
  $notified['plugin'][ $key ] = $data->new_version; // set plugin version we are notifying about
167
  }
168
  $siteguard_config->set( 'notified', $notified );
169
+ $siteguard_config->update();
170
  return true; // we have plugin updates return true
171
  }
172
  } else {
173
  if ( 0 != count( $notified['plugin'] ) ) { // is there any plugin notifications?
174
  $notified['plugin'] = array(); // set plugin notifications to empty as all plugins up-to-date
175
  $siteguard_config->set( 'notified', $notified );
176
+ $siteguard_config->update();
177
  }
178
  }
179
  return false; // No plugin updates so return false
193
  $themes_need_update = self::check_themes_against_notified( $themes_need_update ); // additional filtering of themes need update
194
  if ( is_array( $themes_need_update ) && count( $themes_need_update ) >= 1 ) { // any themes need updating after all the filtering gone on above?
195
  foreach ( $themes_need_update as $key => $data ) { // loop through the themes that need updating
196
+ $theme_info = wp_get_theme( $key ); // get theme info
197
+ $message .= "\n" . sprintf( esc_html__( 'Theme: %1$s is out of date. Please update from version %2$s to %3$s', 'siteguard' ), $theme_info['Name'], $theme_info['Version'], $data['new_version'] ) . "\n";
198
  $notified['theme'][ $key ] = $data['new_version']; // set theme version we are notifying about
199
  }
200
  $siteguard_config->set( 'notified', $notified );
201
+ $siteguard_config->update();
202
  return true; // we have theme updates return true
203
  }
204
  } else {
205
  if ( 0 != count( $notified['theme'] ) ) { // is there any theme notifications?
206
  $notified['theme'] = array(); // set theme notifications to empty as all themes up-to-date
207
  $siteguard_config->set( 'notified', $notified );
208
+ $siteguard_config->update();
209
  }
210
  }
211
  return false; // No theme updates so return false
249
  if ( is_array( $user_query->results ) ) {
250
  foreach ( $user_query->results as $user ) {
251
  $user_email = $user->get( 'user_email' );
252
+ if ( true !== @wp_mail( $user_email, $subject, $message ) ) {
253
+ ;
254
  siteguard_error_log( 'Failed send mail. To:' . $user_email . ' Subject:' . esc_html( $subject ) );
255
  }
256
  }
260
  private function log_last_check_time() {
261
  global $siteguard_config;
262
  $siteguard_config->set( 'last_check_time', current_time( 'timestamp' ) );
263
+ $siteguard_config->update();
264
  }
265
 
266
  private static function get_schedules() {
271
 
272
 
273
  private static function get_intervals() {
274
+ $intervals = array_keys( self::get_schedules() );
275
  return $intervals;
276
  }
277
 
classes/siteguard-waf-exclude-rule.php CHANGED
@@ -5,18 +5,18 @@ define( 'SITEGUARD_WAF_EXCLUDE_RULE', 'waf_exclude_rule' );
5
  class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
6
  const HTACCESS_MARK = '#==== SITEGUARD_SG_WHITE_LIST_SETTINGS';
7
 
8
- function __construct( ) {
9
  }
10
- static function get_mark( ) {
11
  return self::HTACCESS_MARK;
12
  }
13
- function init( ) {
14
  global $siteguard_config;
15
  $siteguard_config->set( 'waf_exclude_rule_enable', '0' );
16
- $this->clear_rules( );
17
- $siteguard_config->update( );
18
  }
19
- function get_enable( ) {
20
  global $siteguard_config;
21
  $enable = $siteguard_config->get( 'waf_exclude_rule_enable' );
22
  return $enable;
@@ -28,7 +28,7 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
28
  return false;
29
  }
30
  $siteguard_config->set( 'waf_exclude_rule_enable', $enable );
31
- $siteguard_config->update( );
32
  return true;
33
  }
34
  function cvt_exclude( $exclude ) {
@@ -47,7 +47,7 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
47
  return $result;
48
  }
49
  function input_check( $id, $filename, &$sig, $comment ) {
50
- $errors = new WP_Error( );
51
  if ( ! is_numeric( $id ) ) {
52
  $errors->add( 'white_list_error', esc_html__( 'ERROR: Invalid input value.', 'siteguard' ) );
53
  }
@@ -80,30 +80,30 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
80
  if ( is_wp_error( $errors ) ) {
81
  return $errors;
82
  }
83
- $sig = str_ireplace( 'SiteGuard_User_ExcludeSig', '', $sig );
84
- $sig = str_replace( ' ', '', $sig );
85
  $rules = $siteguard_config->get( SITEGUARD_WAF_EXCLUDE_RULE );
86
- $rule = array(
87
- 'ID' => $this->get_max_id( $rules ) + 1,
88
  'filename' => $filename,
89
- 'sig' => $sig,
90
- 'comment' => $comment,
91
  );
92
  if ( ! is_array( $rules ) ) {
93
  $rules = (array) $rules;
94
  }
95
  array_push( $rules, $rule );
96
  $siteguard_config->set( SITEGUARD_WAF_EXCLUDE_RULE, $rules );
97
- $siteguard_config->update( );
98
  return true;
99
  }
100
- function clear_rules( ) {
101
  global $siteguard_config;
102
  $empty = array();
103
  $siteguard_config->set( SITEGUARD_WAF_EXCLUDE_RULE, $empty );
104
- $siteguard_config->update( );
105
  }
106
- function get_rules( ) {
107
  global $siteguard_config;
108
  $rules = $siteguard_config->get( SITEGUARD_WAF_EXCLUDE_RULE );
109
  return $rules;
@@ -111,7 +111,7 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
111
  function get_rule( $id, &$offset ) {
112
  global $siteguard_config;
113
  $rules = $siteguard_config->get( SITEGUARD_WAF_EXCLUDE_RULE );
114
- $idx = 0;
115
  foreach ( $rules as $rule ) {
116
  if ( isset( $rule['ID'] ) && $rule['ID'] == $id ) {
117
  $offset = $idx;
@@ -130,14 +130,14 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
130
  }
131
  foreach ( $ids as $id ) {
132
  $offset = 0;
133
- $rule = $this->get_rule( $id, $offset );
134
  if ( false === $rule ) {
135
  continue;
136
  }
137
  array_splice( $rules, $offset, 1 );
138
  $siteguard_config->set( SITEGUARD_WAF_EXCLUDE_RULE, $rules );
139
  }
140
- $siteguard_config->update( );
141
  return true;
142
  }
143
  function update_rule_itr( $new_rule ) {
@@ -152,14 +152,14 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
152
  return $errors;
153
  }
154
  $offset = 0;
155
- $rule = $this->get_rule( $id, $offset );
156
  if ( false === $rule ) {
157
  $errors->add( 'white_list_error', esc_html__( 'ERROR: Invalid input value.', 'siteguard' ) );
158
  return $errors;
159
  }
160
  array_splice( $rules, $offset, 1, array( $new_rule ) );
161
  $siteguard_config->set( SITEGUARD_WAF_EXCLUDE_RULE, $rules );
162
- $siteguard_config->update( );
163
  return true;
164
  }
165
  function update_rule( $id, $filename, $sig, $comment ) {
@@ -170,10 +170,10 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
170
  }
171
 
172
  $new_rule = array(
173
- 'ID' => (int) $id,
174
  'filename' => $filename,
175
- 'sig' => $sig,
176
- 'comment' => $comment,
177
  );
178
  return $this->update_rule_itr( $new_rule );
179
  }
@@ -188,24 +188,24 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
188
  // for SiteGuard Lite Ver1.x
189
  function output_exclude_sig_1( $sig_str ) {
190
  $result = '';
191
- $csv = $this->cvt_csrf2comma( $sig_str );
192
- $sigs = preg_split( '/,/', $csv );
193
  foreach ( $sigs as $sig ) {
194
  $sig = str_replace( ' ', '', $sig );
195
  if ( strlen( $sig ) > 0 ) {
196
- $result .= ' SiteGuard_User_ExcludeSig '. $sig . "\n";
197
  }
198
  }
199
  return $result;
200
  }
201
  // for SiteGuard Lite Ver2.x
202
  function output_exclude_sig_2( $sig_str ) {
203
- return ' SiteGuard_User_ExcludeSig '. $this->cvt_csrf2comma( $sig_str ) . "\n";
204
  }
205
- function update_settings( ) {
206
  global $siteguard_config;
207
  $htaccess_str = '';
208
- $rules = $siteguard_config->get( SITEGUARD_WAF_EXCLUDE_RULE );
209
  if ( '' === $rules ) {
210
  return;
211
  }
@@ -214,7 +214,7 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
214
  foreach ( $rules as $rule ) {
215
  if ( isset( $rule['filename'] ) && isset( $rule['sig'] ) ) {
216
  $filename = $rule['filename'];
217
- $sig = $rule['sig'];
218
  if ( ! empty( $filename ) ) {
219
  $htaccess_str .= " <Files \"$filename\" >\n";
220
  $htaccess_str .= $this->output_exclude_sig_1( $sig );
@@ -228,17 +228,17 @@ class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
228
 
229
  return $htaccess_str;
230
  }
231
- function feature_on( ) {
232
  global $siteguard_htaccess;
233
- if ( false === SiteGuard_Htaccess::check_permission( ) ) {
234
  return false;
235
  }
236
- $data = $this->update_settings( );
237
- $mark = $this->get_mark( );
238
  return $siteguard_htaccess->update_settings( $mark, $data );
239
  }
240
- static function feature_off( ) {
241
- $mark = SiteGuard_WAF_Exclude_Rule::get_mark( );
242
  return SiteGuard_Htaccess::clear_settings( $mark );
243
  }
244
  }
5
  class SiteGuard_WAF_Exclude_Rule extends SiteGuard_Base {
6
  const HTACCESS_MARK = '#==== SITEGUARD_SG_WHITE_LIST_SETTINGS';
7
 
8
+ function __construct() {
9
  }
10
+ static function get_mark() {
11
  return self::HTACCESS_MARK;
12
  }
13
+ function init() {
14
  global $siteguard_config;
15
  $siteguard_config->set( 'waf_exclude_rule_enable', '0' );
16
+ $this->clear_rules();
17
+ $siteguard_config->update();
18
  }
19
+ function get_enable() {
20
  global $siteguard_config;
21
  $enable = $siteguard_config->get( 'waf_exclude_rule_enable' );
22
  return $enable;
28
  return false;
29
  }
30
  $siteguard_config->set( 'waf_exclude_rule_enable', $enable );
31
+ $siteguard_config->update();
32
  return true;
33
  }
34
  function cvt_exclude( $exclude ) {
47
  return $result;
48
  }
49
  function input_check( $id, $filename, &$sig, $comment ) {
50
+ $errors = new WP_Error();
51
  if ( ! is_numeric( $id ) ) {
52
  $errors->add( 'white_list_error', esc_html__( 'ERROR: Invalid input value.', 'siteguard' ) );
53
  }
80
  if ( is_wp_error( $errors ) ) {
81
  return $errors;
82
  }
83
+ $sig = str_ireplace( 'SiteGuard_User_ExcludeSig', '', $sig );
84
+ $sig = str_replace( ' ', '', $sig );
85
  $rules = $siteguard_config->get( SITEGUARD_WAF_EXCLUDE_RULE );
86
+ $rule = array(
87
+ 'ID' => $this->get_max_id( $rules ) + 1,
88
  'filename' => $filename,
89
+ 'sig' => $sig,
90
+ 'comment' => $comment,
91
  );
92
  if ( ! is_array( $rules ) ) {
93
  $rules = (array) $rules;
94
  }
95
  array_push( $rules, $rule );
96
  $siteguard_config->set( SITEGUARD_WAF_EXCLUDE_RULE, $rules );
97
+ $siteguard_config->update();
98
  return true;
99
  }
100
+ function clear_rules() {
101
  global $siteguard_config;
102
  $empty = array();
103
  $siteguard_config->set( SITEGUARD_WAF_EXCLUDE_RULE, $empty );
104
+ $siteguard_config->update();
105
  }
106
+ function get_rules() {
107
  global $siteguard_config;
108
  $rules = $siteguard_config->get( SITEGUARD_WAF_EXCLUDE_RULE );
109
  return $rules;
111
  function get_rule( $id, &$offset ) {
112
  global $siteguard_config;
113
  $rules = $siteguard_config->get( SITEGUARD_WAF_EXCLUDE_RULE );
114
+ $idx = 0;
115
  foreach ( $rules as $rule ) {
116
  if ( isset( $rule['ID'] ) && $rule['ID'] == $id ) {
117
  $offset = $idx;
130
  }
131
  foreach ( $ids as $id ) {
132
  $offset = 0;
133
+ $rule = $this->get_rule( sanitize_text_field( $id ), $offset );
134
  if ( false === $rule ) {
135
  continue;
136
  }
137
  array_splice( $rules, $offset, 1 );
138
  $siteguard_config->set( SITEGUARD_WAF_EXCLUDE_RULE, $rules );
139
  }
140
+ $siteguard_config->update();
141
  return true;
142
  }
143
  function update_rule_itr( $new_rule ) {
152
  return $errors;
153
  }
154
  $offset = 0;
155
+ $rule = $this->get_rule( $id, $offset );
156
  if ( false === $rule ) {
157
  $errors->add( 'white_list_error', esc_html__( 'ERROR: Invalid input value.', 'siteguard' ) );
158
  return $errors;
159
  }
160
  array_splice( $rules, $offset, 1, array( $new_rule ) );
161
  $siteguard_config->set( SITEGUARD_WAF_EXCLUDE_RULE, $rules );
162
+ $siteguard_config->update();
163
  return true;
164
  }
165
  function update_rule( $id, $filename, $sig, $comment ) {
170
  }
171
 
172
  $new_rule = array(
173
+ 'ID' => (int) $id,
174
  'filename' => $filename,
175
+ 'sig' => $sig,
176
+ 'comment' => $comment,
177
  );
178
  return $this->update_rule_itr( $new_rule );
179
  }
188
  // for SiteGuard Lite Ver1.x
189
  function output_exclude_sig_1( $sig_str ) {
190
  $result = '';
191
+ $csv = $this->cvt_csrf2comma( $sig_str );
192
+ $sigs = preg_split( '/,/', $csv );
193
  foreach ( $sigs as $sig ) {
194
  $sig = str_replace( ' ', '', $sig );
195
  if ( strlen( $sig ) > 0 ) {
196
+ $result .= ' SiteGuard_User_ExcludeSig ' . $sig . "\n";
197
  }
198
  }
199
  return $result;
200
  }
201
  // for SiteGuard Lite Ver2.x
202
  function output_exclude_sig_2( $sig_str ) {
203
+ return ' SiteGuard_User_ExcludeSig ' . $this->cvt_csrf2comma( $sig_str ) . "\n";
204
  }
205
+ function update_settings() {
206
  global $siteguard_config;
207
  $htaccess_str = '';
208
+ $rules = $siteguard_config->get( SITEGUARD_WAF_EXCLUDE_RULE );
209
  if ( '' === $rules ) {
210
  return;
211
  }
214
  foreach ( $rules as $rule ) {
215
  if ( isset( $rule['filename'] ) && isset( $rule['sig'] ) ) {
216
  $filename = $rule['filename'];
217
+ $sig = $rule['sig'];
218
  if ( ! empty( $filename ) ) {
219
  $htaccess_str .= " <Files \"$filename\" >\n";
220
  $htaccess_str .= $this->output_exclude_sig_1( $sig );
228
 
229
  return $htaccess_str;
230
  }
231
+ function feature_on() {
232
  global $siteguard_htaccess;
233
+ if ( false === SiteGuard_Htaccess::check_permission() ) {
234
  return false;
235
  }
236
+ $data = $this->update_settings();
237
+ $mark = $this->get_mark();
238
  return $siteguard_htaccess->update_settings( $mark, $data );
239
  }
240
+ static function feature_off() {
241
+ $mark = self::get_mark();
242
  return SiteGuard_Htaccess::clear_settings( $mark );
243
  }
244
  }
css/siteguard-menu.css CHANGED
@@ -151,4 +151,3 @@ div.siteguard-description {
151
  border:solid 1px #cccccc;
152
  background-color: #fdfdfd;
153
  }
154
-
151
  border:solid 1px #cccccc;
152
  background-color: #fdfdfd;
153
  }
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: -
4
  Tags: security, waf, brute force, password list, login lock, login alert, captcha, pingback, fail once
5
  Requires at least: 3.9
6
  Tested up to: 6.0
7
- Stable tag: 1.7.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -23,7 +23,7 @@ Notes
23
  * It only supports Apache 1.3, 2.x for Web servers.
24
  * To use the CAPTCHA function, the expansion library “mbstring” and “gd” should be installed on php.
25
  * To use the management page filter function and login page change function, “mod_rewrite” should be loaded on Apache.
26
- * To use the WAF Tuning Support, WAF ( SiteGuard Lite ) should be installed on Apache.
27
 
28
  There are the following functions.
29
 
@@ -106,6 +106,8 @@ If you have created your own language pack, or have an update of an existing one
106
  [Japanese Page](https://www.jp-secure.com/siteguard_wp_plugin/faq/)
107
 
108
  == Changelog ==
 
 
109
  = 1.7.1 =
110
  * Fix the problem that a syntax error occurs in PHP5.6 or earlier
111
  = 1.7.0 =
4
  Tags: security, waf, brute force, password list, login lock, login alert, captcha, pingback, fail once
5
  Requires at least: 3.9
6
  Tested up to: 6.0
7
+ Stable tag: 1.7.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
23
  * It only supports Apache 1.3, 2.x for Web servers.
24
  * To use the CAPTCHA function, the expansion library “mbstring” and “gd” should be installed on php.
25
  * To use the management page filter function and login page change function, “mod_rewrite” should be loaded on Apache.
26
+ * To use the WAF Tuning Support, WAF ( SiteGuard Server Edition ) should be installed on Apache.
27
 
28
  There are the following functions.
29
 
106
  [Japanese Page](https://www.jp-secure.com/siteguard_wp_plugin/faq/)
107
 
108
  == Changelog ==
109
+ = 1.7.2 =
110
+ * Reviewed and modified source code related to security
111
  = 1.7.1 =
112
  * Fix the problem that a syntax error occurs in PHP5.6 or earlier
113
  = 1.7.0 =
really-simple-captcha/siteguard-really-simple-captcha.php CHANGED
@@ -13,21 +13,22 @@ Base-Version: 1.8
13
  Base-Author URI: http://ideasilo.wordpress.com/
14
  */
15
 
16
- /* Copyright 2007-2014 Takayuki Miyoshi (email: takayukister at gmail.com)
 
17
 
18
- This program is free software; you can redistribute it and/or modify
19
- it under the terms of the GNU General Public License as published by
20
- the Free Software Foundation; either version 2 of the License, or
21
- (at your option) any later version.
22
 
23
- This program is distributed in the hope that it will be useful,
24
- but WITHOUT ANY WARRANTY; without even the implied warranty of
25
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
- GNU General Public License for more details.
27
 
28
- You should have received a copy of the GNU General Public License
29
- along with this program; if not, write to the Free Software
30
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
  */
32
 
33
  class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
@@ -62,15 +63,15 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
62
  protected $answer_file_mode;
63
 
64
  public function __construct() {
65
- $this->lang_mode = 'jp';
66
- $this->char_length = 4;
67
- $this->tmp_dir = path_join( dirname( __FILE__ ), 'tmp' );
68
- $this->img_size = array( 72, 24 );
69
- $this->base = array( 6, 18 );
70
- $this->font_size = 14;
71
- $this->font_char_width = 15;
72
- $this->img_type = 'png';
73
- $this->file_mode = 0444;
74
  $this->answer_file_mode = 0440;
75
  }
76
 
@@ -95,8 +96,8 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
95
 
96
  $chars_size = mb_strlen( $this->chars );
97
  for ( $i = 0; $i < $this->char_length; $i++ ) {
98
- $pos = mt_rand( 0, $chars_size - 1 );
99
- $char = mb_substr( $this->chars, $pos, 1 );
100
  $word .= $char;
101
  }
102
 
@@ -111,8 +112,9 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
111
  * @return string|bool The file name of the CAPTCHA image. Return false if temp directory is not available.
112
  */
113
  public function generate_image( $prefix, $word ) {
114
- if ( ! $this->make_tmp_dir() )
115
  return false;
 
116
 
117
  $this->cleanup();
118
 
@@ -120,48 +122,48 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
120
  if ( 'jp' == $this->lang_mode ) {
121
  $this->fonts = array(
122
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-black.ttf',
123
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-bold.ttf',
124
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-heavy.ttf',
125
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-light.ttf',
126
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-medium.ttf',
127
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-regular.ttf',
128
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-thin.ttf',
129
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-bold.ttf',
130
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-light.ttf',
131
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-medium.ttf',
132
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-regular.ttf',
133
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-thin.ttf',
134
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-bold.ttf',
135
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-light.ttf',
136
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-medium.ttf',
137
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-regular.ttf',
138
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-thin.ttf',
139
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-black.ttf',
140
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-bold.ttf',
141
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-heavy.ttf',
142
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-light.ttf',
143
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-medium.ttf',
144
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-regular.ttf',
145
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-thin.ttf',
146
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-black.ttf',
147
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-bold.ttf',
148
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-heavy.ttf',
149
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-light.ttf',
150
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-medium.ttf',
151
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-regular.ttf',
152
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-thin.ttf',
153
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-bold.ttf',
154
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-light.ttf',
155
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-medium.ttf',
156
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-regular.ttf',
157
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-thin.ttf',
158
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-black.ttf',
159
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-bold.ttf',
160
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-heavy.ttf',
161
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-light.ttf',
162
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-medium.ttf',
163
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-regular.ttf',
164
- //dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-thin.ttf',
165
  );
166
  } else {
167
  $this->fonts = array(
@@ -169,10 +171,10 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
169
  dirname( __FILE__ ) . '/gentium/GenBkBasI.ttf',
170
  dirname( __FILE__ ) . '/gentium/GenBkBasBI.ttf',
171
  dirname( __FILE__ ) . '/gentium/GenBkBasB.ttf',
172
- );
173
  }
174
 
175
- $dir = trailingslashit( $this->tmp_dir );
176
  $filename = null;
177
 
178
  if ( $im = imagecreatetruecolor( $this->img_size[0], $this->img_size[1] ) ) {
@@ -183,13 +185,13 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
183
 
184
  // randam lines
185
  for ( $i = 0; $i < 5; $i++ ) {
186
- $color = imagecolorallocate( $im, 196, 196, 196 );
187
  imageline( $im, mt_rand( 0, $this->img_size[0] - 1 ), mt_rand( 0, $this->img_size[1] - 1 ), mt_rand( 0, $this->img_size[0] - 1 ), mt_rand( 0, $this->img_size[1] - 1 ), $color );
188
  }
189
 
190
  $x = $this->base[0] + mt_rand( -2, 2 );
191
 
192
- $gd_info = gd_info( );
193
  $word_size = mb_strlen( $word );
194
  for ( $i = 0; $i < $word_size; $i++ ) {
195
  $font = $this->fonts[ array_rand( $this->fonts ) ];
@@ -206,18 +208,18 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
206
  switch ( $this->img_type ) {
207
  case 'jpeg':
208
  $filename = sanitize_file_name( $prefix . '.jpeg' );
209
- $file = $this->normalize_path( $dir . $filename );
210
  imagejpeg( $im, $file );
211
  break;
212
  case 'gif':
213
  $filename = sanitize_file_name( $prefix . '.gif' );
214
- $file = $this->normalize_path( $dir . $filename );
215
  imagegif( $im, $file );
216
  break;
217
  case 'png':
218
  default:
219
  $filename = sanitize_file_name( $prefix . '.png' );
220
- $file = $this->normalize_path( $dir . $filename );
221
  imagepng( $im, $file );
222
  }
223
 
@@ -237,7 +239,7 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
237
  * @param string $word Random word generated by generate_random_word()
238
  */
239
  public function generate_answer_file( $prefix, $word ) {
240
- $dir = trailingslashit( $this->tmp_dir );
241
  $answer_file = $dir . sanitize_file_name( $prefix . '.txt' );
242
  $answer_file = $this->normalize_path( $answer_file );
243
 
@@ -272,9 +274,9 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
272
  $response = str_replace( array( ' ', "\t" ), '', $response );
273
  $response = strtoupper( $response );
274
 
275
- $dir = trailingslashit( $this->tmp_dir );
276
  $filename = sanitize_file_name( $prefix . '.txt' );
277
- $file = $this->normalize_path( $dir . $filename );
278
 
279
  if ( @is_readable( $file ) && ( $code = file_get_contents( $file ) ) ) {
280
  $code = explode( '|', $code, 2 );
@@ -304,9 +306,9 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
304
  $suffixes = array( '.jpeg', '.gif', '.png', '.php', '.txt' );
305
 
306
  foreach ( $suffixes as $suffix ) {
307
- $dir = trailingslashit( $this->tmp_dir );
308
  $filename = sanitize_file_name( $prefix . $suffix );
309
- $file = $this->normalize_path( $dir . $filename );
310
 
311
  if ( @is_file( $file ) ) {
312
  unlink( $file );
@@ -340,8 +342,9 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
340
 
341
  if ( $handle = @opendir( $dir ) ) {
342
  while ( false !== ( $filename = readdir( $handle ) ) ) {
343
- if ( ! preg_match( '/^[0-9]+\.(php|txt|png|gif|jpeg)$/', $filename ) )
344
  continue;
 
345
 
346
  $file = $this->normalize_path( $dir . $filename );
347
 
@@ -420,7 +423,7 @@ class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
420
  }
421
 
422
  /**
423
- * set $this->lang_mode
424
  */
425
  public function set_lang_mode( $mode ) {
426
  if ( 'jp' === $mode || 'en' === $mode ) {
13
  Base-Author URI: http://ideasilo.wordpress.com/
14
  */
15
 
16
+ /*
17
+ Copyright 2007-2014 Takayuki Miyoshi (email: takayukister at gmail.com)
18
 
19
+ This program is free software; you can redistribute it and/or modify
20
+ it under the terms of the GNU General Public License as published by
21
+ the Free Software Foundation; either version 2 of the License, or
22
+ (at your option) any later version.
23
 
24
+ This program is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ GNU General Public License for more details.
28
 
29
+ You should have received a copy of the GNU General Public License
30
+ along with this program; if not, write to the Free Software
31
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
  */
33
 
34
  class SiteGuardReallySimpleCaptcha extends SiteGuard_Base {
63
  protected $answer_file_mode;
64
 
65
  public function __construct() {
66
+ $this->lang_mode = 'jp';
67
+ $this->char_length = 4;
68
+ $this->tmp_dir = path_join( dirname( __FILE__ ), 'tmp' );
69
+ $this->img_size = array( 72, 24 );
70
+ $this->base = array( 6, 18 );
71
+ $this->font_size = 14;
72
+ $this->font_char_width = 15;
73
+ $this->img_type = 'png';
74
+ $this->file_mode = 0444;
75
  $this->answer_file_mode = 0440;
76
  }
77
 
96
 
97
  $chars_size = mb_strlen( $this->chars );
98
  for ( $i = 0; $i < $this->char_length; $i++ ) {
99
+ $pos = mt_rand( 0, $chars_size - 1 );
100
+ $char = mb_substr( $this->chars, $pos, 1 );
101
  $word .= $char;
102
  }
103
 
112
  * @return string|bool The file name of the CAPTCHA image. Return false if temp directory is not available.
113
  */
114
  public function generate_image( $prefix, $word ) {
115
+ if ( ! $this->make_tmp_dir() ) {
116
  return false;
117
+ }
118
 
119
  $this->cleanup();
120
 
122
  if ( 'jp' == $this->lang_mode ) {
123
  $this->fonts = array(
124
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-black.ttf',
125
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-bold.ttf',
126
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-heavy.ttf',
127
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-light.ttf',
128
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-medium.ttf',
129
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-regular.ttf',
130
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1c-hiragana-thin.ttf',
131
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-bold.ttf',
132
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-light.ttf',
133
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-medium.ttf',
134
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-regular.ttf',
135
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1m-hiragana-thin.ttf',
136
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-bold.ttf',
137
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-light.ttf',
138
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-medium.ttf',
139
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-regular.ttf',
140
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1mn-hiragana-thin.ttf',
141
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-black.ttf',
142
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-bold.ttf',
143
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-heavy.ttf',
144
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-light.ttf',
145
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-medium.ttf',
146
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-regular.ttf',
147
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-1p-hiragana-thin.ttf',
148
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-black.ttf',
149
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-bold.ttf',
150
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-heavy.ttf',
151
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-light.ttf',
152
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-medium.ttf',
153
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-regular.ttf',
154
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2c-hiragana-thin.ttf',
155
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-bold.ttf',
156
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-light.ttf',
157
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-medium.ttf',
158
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-regular.ttf',
159
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2m-hiragana-thin.ttf',
160
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-black.ttf',
161
  dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-bold.ttf',
162
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-heavy.ttf',
163
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-light.ttf',
164
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-medium.ttf',
165
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-regular.ttf',
166
+ // dirname( __FILE__ ) . '/mplus-TESTFLIGHT-058/mplus-2p-hiragana-thin.ttf',
167
  );
168
  } else {
169
  $this->fonts = array(
171
  dirname( __FILE__ ) . '/gentium/GenBkBasI.ttf',
172
  dirname( __FILE__ ) . '/gentium/GenBkBasBI.ttf',
173
  dirname( __FILE__ ) . '/gentium/GenBkBasB.ttf',
174
+ );
175
  }
176
 
177
+ $dir = trailingslashit( $this->tmp_dir );
178
  $filename = null;
179
 
180
  if ( $im = imagecreatetruecolor( $this->img_size[0], $this->img_size[1] ) ) {
185
 
186
  // randam lines
187
  for ( $i = 0; $i < 5; $i++ ) {
188
+ $color = imagecolorallocate( $im, 196, 196, 196 );
189
  imageline( $im, mt_rand( 0, $this->img_size[0] - 1 ), mt_rand( 0, $this->img_size[1] - 1 ), mt_rand( 0, $this->img_size[0] - 1 ), mt_rand( 0, $this->img_size[1] - 1 ), $color );
190
  }
191
 
192
  $x = $this->base[0] + mt_rand( -2, 2 );
193
 
194
+ $gd_info = gd_info();
195
  $word_size = mb_strlen( $word );
196
  for ( $i = 0; $i < $word_size; $i++ ) {
197
  $font = $this->fonts[ array_rand( $this->fonts ) ];
208
  switch ( $this->img_type ) {
209
  case 'jpeg':
210
  $filename = sanitize_file_name( $prefix . '.jpeg' );
211
+ $file = $this->normalize_path( $dir . $filename );
212
  imagejpeg( $im, $file );
213
  break;
214
  case 'gif':
215
  $filename = sanitize_file_name( $prefix . '.gif' );
216
+ $file = $this->normalize_path( $dir . $filename );
217
  imagegif( $im, $file );
218
  break;
219
  case 'png':
220
  default:
221
  $filename = sanitize_file_name( $prefix . '.png' );
222
+ $file = $this->normalize_path( $dir . $filename );
223
  imagepng( $im, $file );
224
  }
225
 
239
  * @param string $word Random word generated by generate_random_word()
240
  */
241
  public function generate_answer_file( $prefix, $word ) {
242
+ $dir = trailingslashit( $this->tmp_dir );
243
  $answer_file = $dir . sanitize_file_name( $prefix . '.txt' );
244
  $answer_file = $this->normalize_path( $answer_file );
245
 
274
  $response = str_replace( array( ' ', "\t" ), '', $response );
275
  $response = strtoupper( $response );
276
 
277
+ $dir = trailingslashit( $this->tmp_dir );
278
  $filename = sanitize_file_name( $prefix . '.txt' );
279
+ $file = $this->normalize_path( $dir . $filename );
280
 
281
  if ( @is_readable( $file ) && ( $code = file_get_contents( $file ) ) ) {
282
  $code = explode( '|', $code, 2 );
306
  $suffixes = array( '.jpeg', '.gif', '.png', '.php', '.txt' );
307
 
308
  foreach ( $suffixes as $suffix ) {
309
+ $dir = trailingslashit( $this->tmp_dir );
310
  $filename = sanitize_file_name( $prefix . $suffix );
311
+ $file = $this->normalize_path( $dir . $filename );
312
 
313
  if ( @is_file( $file ) ) {
314
  unlink( $file );
342
 
343
  if ( $handle = @opendir( $dir ) ) {
344
  while ( false !== ( $filename = readdir( $handle ) ) ) {
345
+ if ( ! preg_match( '/^[0-9]+\.(php|txt|png|gif|jpeg)$/', $filename ) ) {
346
  continue;
347
+ }
348
 
349
  $file = $this->normalize_path( $dir . $filename );
350
 
423
  }
424
 
425
  /**
426
+ * set $this->lang_mode
427
  */
428
  public function set_lang_mode( $mode ) {
429
  if ( 'jp' === $mode || 'en' === $mode ) {
siteguard.php CHANGED
@@ -2,28 +2,29 @@
2
  /*
3
  Plugin Name: SiteGuard WP Plugin
4
  Plugin URI: http://www.jp-secure.com/cont/products/siteguard_wp_plugin/index_en.html
5
- Description: Only installing SiteGuard WP Plugin on WordPress, its security can be improved. SiteGurad WP Plugin is the plugin specialized for the protection against the attack to the management page and login. It also have the function to create the exclude rule for WAF (SiteGuard Lite, to use it, WAF should be installed on the Web server.)
6
  Author: JP-Secure
7
- Author URI: http://www.jp-secure.com/eng/
8
  Text Domain: siteguard
9
  Domain Path: /languages/
10
- Version: 1.7.1
11
  */
12
 
13
- /* Copyright 2014 JP-Secure Inc
 
14
 
15
- This program is free software; you can redistribute it and/or modify
16
- it under the terms of the GNU General Public License, version 2, as
17
  published by the Free Software Foundation.
18
 
19
- This program is distributed in the hope that it will be useful,
20
- but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- GNU General Public License for more details.
23
 
24
- You should have received a copy of the GNU General Public License
25
- along with this program; if not, write to the Free Software
26
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
29
  if ( ! defined( 'ABSPATH' ) ) {
@@ -36,31 +37,31 @@ define( 'SITEGUARD_VERSION', $data['version'] );
36
  define( 'SITEGUARD_PATH', plugin_dir_path( __FILE__ ) );
37
  define( 'SITEGUARD_URL_PATH', plugin_dir_url( __FILE__ ) );
38
 
39
- define( 'SITEGUARD_LOGIN_NOSELECT', 4 );
40
- define( 'SITEGUARD_LOGIN_SUCCESS', 0 );
41
- define( 'SITEGUARD_LOGIN_FAILED', 1 );
42
  define( 'SITEGUARD_LOGIN_FAIL_ONCE', 2 );
43
- define( 'SITEGUARD_LOGIN_LOCKED', 3 );
44
 
45
  define( 'SITEGUARD_LOGIN_TYPE_NOSELECT', 2 );
46
- define( 'SITEGUARD_LOGIN_TYPE_NORMAL', 0 );
47
- define( 'SITEGUARD_LOGIN_TYPE_XMLRPC', 1 );
48
 
49
- require_once( 'classes/siteguard-base.php' );
50
- require_once( 'classes/siteguard-config.php' );
51
- require_once( 'classes/siteguard-htaccess.php' );
52
- require_once( 'classes/siteguard-admin-filter.php' );
53
- require_once( 'classes/siteguard-rename-login.php' );
54
- require_once( 'classes/siteguard-login-history.php' );
55
- require_once( 'classes/siteguard-login-lock.php' );
56
- require_once( 'classes/siteguard-login-alert.php' );
57
- require_once( 'classes/siteguard-captcha.php' );
58
- require_once( 'classes/siteguard-disable-xmlrpc.php' );
59
- require_once( 'classes/siteguard-disable-pingback.php' );
60
- require_once( 'classes/siteguard-disable-author-query.php' );
61
- require_once( 'classes/siteguard-waf-exclude-rule.php' );
62
- require_once( 'classes/siteguard-updates-notify.php' );
63
- require_once( 'admin/siteguard-menu-init.php' );
64
 
65
  global $siteguard_htaccess;
66
  global $siteguard_config;
@@ -76,21 +77,21 @@ global $siteguard_author_query;
76
  global $siteguard_waf_exclude_rule;
77
  global $siteguard_updates_notify;
78
 
79
- $siteguard_htaccess = new SiteGuard_Htaccess( );
80
- $siteguard_config = new SiteGuard_Config( );
81
- $siteguard_admin_filter = new SiteGuard_AdminFilter( );
82
- $siteguard_rename_login = new SiteGuard_RenameLogin( );
83
- $siteguard_loginlock = new SiteGuard_LoginLock( );
84
- $siteguard_loginalert = new SiteGuard_LoginAlert( );
85
- $siteguard_login_history = new SiteGuard_LoginHistory( );
86
- $siteguard_captcha = new SiteGuard_CAPTCHA( );
87
- $siteguard_xmlrpc = new SiteGuard_Disable_XMLRPC( );
88
- $siteguard_pingback = new SiteGuard_Disable_Pingback( );
89
- $siteguard_author_query = new SiteGuard_Disable_Author_Query( );
90
- $siteguard_waf_exclude_rule = new SiteGuard_WAF_Exclude_Rule( );
91
- $siteguard_updates_notify = new SiteGuard_UpdatesNotify( );
92
 
93
- function siteguard_activate( ) {
94
  global $siteguard_config, $siteguard_admin_filter, $siteguard_rename_login, $siteguard_login_history, $siteguard_captcha, $siteguard_loginlock, $siteguard_loginalert, $siteguard_xmlrpc, $siteguard_pingback, $siteguard_author_query, $siteguard_waf_exclude_rule, $siteguard_updates_notify;
95
 
96
  load_plugin_textdomain(
@@ -100,7 +101,7 @@ function siteguard_activate( ) {
100
  );
101
 
102
  $siteguard_config->set( 'show_admin_notices', '0' );
103
- $siteguard_config->update( );
104
  $siteguard_admin_filter->init();
105
  $siteguard_rename_login->init();
106
  $siteguard_login_history->init();
@@ -115,98 +116,98 @@ function siteguard_activate( ) {
115
  }
116
  register_activation_hook( __FILE__, 'siteguard_activate' );
117
 
118
- function siteguard_deactivate( ) {
119
  global $siteguard_config;
120
  $siteguard_config->set( 'show_admin_notices', '0' );
121
- $siteguard_config->update( );
122
- SiteGuard_RenameLogin::feature_off( );
123
- SiteGuard_AdminFilter::feature_off( );
124
- SiteGuard_Disable_XMLRPC::feature_off( );
125
- SiteGuard_WAF_Exclude_Rule::feature_off( );
126
- SiteGuard_UpdatesNotify::feature_off( );
127
  }
128
  register_deactivation_hook( __FILE__, 'siteguard_deactivate' );
129
 
130
 
131
  class SiteGuard extends SiteGuard_Base {
132
  protected $menu_init;
133
- function __construct( ) {
134
  global $siteguard_config;
135
  add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
136
- $this->htaccess_check( );
137
- if ( is_admin( ) ) {
138
- include ( 'admin/siteguard-menu-login-history.php' );
139
- $this->menu_init = new SiteGuard_Menu_Init( );
140
  add_action( 'init', array( $this, 'set_cookie' ) );
141
  add_action( 'admin_init', array( $this, 'upgrade' ) );
142
  if ( '0' === $siteguard_config->get( 'show_admin_notices' ) && '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
143
  add_action( 'admin_notices', array( $this, 'admin_notices' ) );
144
  $siteguard_config->set( 'show_admin_notices', '1' );
145
- $siteguard_config->update( );
146
  }
147
  }
148
  }
149
- function set_cookie( ) {
150
- SiteGuard_Menu_Login_History::set_cookie( );
151
  }
152
- function plugins_loaded( ) {
153
  load_plugin_textdomain(
154
  'siteguard',
155
  false,
156
  dirname( plugin_basename( __FILE__ ) ) . '/languages'
157
  );
158
  }
159
- function htaccess_check( ) {
160
  global $siteguard_config;
161
-
162
  $can_use_htaccess = true;
163
- if ( false === SiteGuard_Htaccess::test_htaccess( ) ) {
164
  $can_use_htaccess = false;
165
  }
166
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
167
- if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_AdminFilter::get_mark( ) ) ) {
168
  $siteguard_config->set( 'admin_filter_enable', '0' );
169
- $siteguard_config->update( );
170
  }
171
  }
172
  if ( '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
173
- if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_RenameLogin::get_mark( ) ) ) {
174
  $siteguard_config->set( 'renamelogin_enable', '0' );
175
- $siteguard_config->update( );
176
  }
177
  }
178
  if ( '1' === $siteguard_config->get( 'disable_xmlrpc_enable' ) ) {
179
- if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_Disable_XMLRPC::get_mark( ) ) ) {
180
  $siteguard_config->set( 'disable_xmlrpc_enable', '0' );
181
- $siteguard_config->update( );
182
  }
183
  }
184
  if ( '1' === $siteguard_config->get( 'waf_exclude_rule_enable' ) ) {
185
- if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_WAF_Exclude_Rule::get_mark( ) ) ) {
186
  $siteguard_config->set( 'waf_exclude_rule_enable', '0' );
187
- $siteguard_config->update( );
188
  }
189
  }
190
  if ( '1' === $siteguard_config->get( 'captcha_enable' ) ) {
191
- if ( false === $can_use_htaccess) {
192
  $siteguard_config->set( 'captcha_enable', '0' );
193
- $siteguard_config->update( );
194
  }
195
  }
196
  }
197
- function admin_notices( ) {
198
  global $siteguard_rename_login;
199
  echo '<div class="updated" style="background-color:#719f1d;"><p><span style="border: 4px solid #def1b8;padding: 4px 4px;color:#fff;font-weight:bold;background-color:#038bc3;">';
200
  echo esc_html__( 'Login page URL was changed.', 'siteguard' ) . '</span>';
201
  echo '<span style="color:#eee;">';
202
- echo esc_html__( ' Please bookmark ', 'siteguard' ) . '<a style="color:#fff;text-decoration:underline;" href="' . esc_url( wp_login_url( ) ) . '">';
203
  echo esc_html__( 'new login URL', 'siteguard' ) . '</a>';
204
- echo esc_html__( '. Setting change is ', 'siteguard' ) . '<a style="color:#fff;text-decoration:underline;" href="' . esc_url( menu_page_url( 'siteguard_rename_login', false ) ) . '">';
205
  echo esc_html__( 'here', 'siteguard' ) . '</a>';
206
  echo '.</span></p></div>';
207
- $siteguard_rename_login->send_notify( );
208
  }
209
- function upgrade( ) {
210
  global $siteguard_config, $siteguard_rename_login, $siteguard_admin_filter, $siteguard_loginalert, $siteguard_updates_notify, $siteguard_login_history, $siteguard_xmlrpc, $siteguard_author_query;
211
  $upgrade_ok = true;
212
  $old_version = $siteguard_config->get( 'version' );
@@ -218,7 +219,7 @@ class SiteGuard extends SiteGuard_Base {
218
  }
219
  if ( version_compare( $old_version, '1.0.6' ) < 0 ) {
220
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
221
- if ( true !== $siteguard_admin_filter->feature_on( $this->get_ip( ) ) ) {
222
  siteguard_error_log( 'Failed to update at admin_filter from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
223
  $upgrade_ok = false;
224
  }
@@ -232,36 +233,36 @@ class SiteGuard extends SiteGuard_Base {
232
  }
233
  if ( version_compare( $old_version, '1.2.5' ) < 0 ) {
234
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
235
- $siteguard_admin_filter->cvt_status_for_1_2_5( $this->get_ip( ) );
236
  }
237
  if ( '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
238
- if ( true !== $siteguard_rename_login->feature_on( ) ) {
239
  siteguard_error_log( 'Failed to update at rename_login from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
240
  $upgrade_ok = false;
241
  }
242
  }
243
  }
244
  if ( version_compare( $old_version, '1.3.0' ) < 0 ) {
245
- $siteguard_login_history->init( );
246
- $siteguard_xmlrpc->init( );
247
  }
248
  if ( version_compare( $old_version, '1.5.0' ) < 0 ) {
249
- $admin_filter_exclude_path = $siteguard_config->get( 'admin_filter_exclude_path' );
250
- if( false === strpos( $admin_filter_exclude_path, 'site-health.php' ) ){
251
- $admin_filter_exclude_path .= ', site-health.php';
252
- $siteguard_config->set( 'admin_filter_exclude_path', $admin_filter_exclude_path );
253
- $siteguard_config->update( );
254
- }
255
  }
256
  if ( version_compare( $old_version, '1.5.1' ) < 0 ) {
257
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
258
- if ( true !== $siteguard_admin_filter->feature_on( $this->get_ip( ) ) ) {
259
  siteguard_error_log( 'Failed to update at admin_filter from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
260
  $upgrade_ok = false;
261
  }
262
  }
263
  if ( '1' === $siteguard_config->get( 'disable_xmlrpc_enable' ) ) {
264
- if ( true !== $siteguard_xmlrpc->feature_on( ) ) {
265
  siteguard_error_log( 'Failed to update at disable_xmlrpc from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
266
  $upgrade_ok = false;
267
  }
@@ -272,7 +273,7 @@ class SiteGuard extends SiteGuard_Base {
272
  }
273
  if ( version_compare( $old_version, '1.7.0' ) < 0 ) {
274
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
275
- if ( true !== $siteguard_admin_filter->feature_on( $this->get_ip( ) ) ) {
276
  siteguard_error_log( 'Failed to update at admin_filter from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
277
  $upgrade_ok = false;
278
  }
@@ -280,8 +281,8 @@ class SiteGuard extends SiteGuard_Base {
280
  }
281
  if ( $upgrade_ok && SITEGUARD_VERSION !== $old_version ) {
282
  $siteguard_config->set( 'version', SITEGUARD_VERSION );
283
- $siteguard_config->update( );
284
  }
285
  }
286
  }
287
- $siteguard = new SiteGuard;
2
  /*
3
  Plugin Name: SiteGuard WP Plugin
4
  Plugin URI: http://www.jp-secure.com/cont/products/siteguard_wp_plugin/index_en.html
5
+ Description: Only installing SiteGuard WP Plugin on WordPress, its security can be improved. SiteGurad WP Plugin is the plugin specialized for the protection against the attack to the management page and login. It also have the function to create the exclude rule for WAF (SiteGuard Server Edition, to use it, WAF should be installed on the Web server.)
6
  Author: JP-Secure
7
+ Author URI: https://www.eg-secure.co.jp/
8
  Text Domain: siteguard
9
  Domain Path: /languages/
10
+ Version: 1.7.2
11
  */
12
 
13
+ /*
14
+ Copyright 2014 EG Secure Solutions Inc (JP-Secure Inc)
15
 
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License, version 2, as
18
  published by the Free Software Foundation.
19
 
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
 
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
  */
29
 
30
  if ( ! defined( 'ABSPATH' ) ) {
37
  define( 'SITEGUARD_PATH', plugin_dir_path( __FILE__ ) );
38
  define( 'SITEGUARD_URL_PATH', plugin_dir_url( __FILE__ ) );
39
 
40
+ define( 'SITEGUARD_LOGIN_NOSELECT', 4 );
41
+ define( 'SITEGUARD_LOGIN_SUCCESS', 0 );
42
+ define( 'SITEGUARD_LOGIN_FAILED', 1 );
43
  define( 'SITEGUARD_LOGIN_FAIL_ONCE', 2 );
44
+ define( 'SITEGUARD_LOGIN_LOCKED', 3 );
45
 
46
  define( 'SITEGUARD_LOGIN_TYPE_NOSELECT', 2 );
47
+ define( 'SITEGUARD_LOGIN_TYPE_NORMAL', 0 );
48
+ define( 'SITEGUARD_LOGIN_TYPE_XMLRPC', 1 );
49
 
50
+ require_once 'classes/siteguard-base.php';
51
+ require_once 'classes/siteguard-config.php';
52
+ require_once 'classes/siteguard-htaccess.php';
53
+ require_once 'classes/siteguard-admin-filter.php';
54
+ require_once 'classes/siteguard-rename-login.php';
55
+ require_once 'classes/siteguard-login-history.php';
56
+ require_once 'classes/siteguard-login-lock.php';
57
+ require_once 'classes/siteguard-login-alert.php';
58
+ require_once 'classes/siteguard-captcha.php';
59
+ require_once 'classes/siteguard-disable-xmlrpc.php';
60
+ require_once 'classes/siteguard-disable-pingback.php';
61
+ require_once 'classes/siteguard-disable-author-query.php';
62
+ require_once 'classes/siteguard-waf-exclude-rule.php';
63
+ require_once 'classes/siteguard-updates-notify.php';
64
+ require_once 'admin/siteguard-menu-init.php';
65
 
66
  global $siteguard_htaccess;
67
  global $siteguard_config;
77
  global $siteguard_waf_exclude_rule;
78
  global $siteguard_updates_notify;
79
 
80
+ $siteguard_htaccess = new SiteGuard_Htaccess();
81
+ $siteguard_config = new SiteGuard_Config();
82
+ $siteguard_admin_filter = new SiteGuard_AdminFilter();
83
+ $siteguard_rename_login = new SiteGuard_RenameLogin();
84
+ $siteguard_loginlock = new SiteGuard_LoginLock();
85
+ $siteguard_loginalert = new SiteGuard_LoginAlert();
86
+ $siteguard_login_history = new SiteGuard_LoginHistory();
87
+ $siteguard_captcha = new SiteGuard_CAPTCHA();
88
+ $siteguard_xmlrpc = new SiteGuard_Disable_XMLRPC();
89
+ $siteguard_pingback = new SiteGuard_Disable_Pingback();
90
+ $siteguard_author_query = new SiteGuard_Disable_Author_Query();
91
+ $siteguard_waf_exclude_rule = new SiteGuard_WAF_Exclude_Rule();
92
+ $siteguard_updates_notify = new SiteGuard_UpdatesNotify();
93
 
94
+ function siteguard_activate() {
95
  global $siteguard_config, $siteguard_admin_filter, $siteguard_rename_login, $siteguard_login_history, $siteguard_captcha, $siteguard_loginlock, $siteguard_loginalert, $siteguard_xmlrpc, $siteguard_pingback, $siteguard_author_query, $siteguard_waf_exclude_rule, $siteguard_updates_notify;
96
 
97
  load_plugin_textdomain(
101
  );
102
 
103
  $siteguard_config->set( 'show_admin_notices', '0' );
104
+ $siteguard_config->update();
105
  $siteguard_admin_filter->init();
106
  $siteguard_rename_login->init();
107
  $siteguard_login_history->init();
116
  }
117
  register_activation_hook( __FILE__, 'siteguard_activate' );
118
 
119
+ function siteguard_deactivate() {
120
  global $siteguard_config;
121
  $siteguard_config->set( 'show_admin_notices', '0' );
122
+ $siteguard_config->update();
123
+ SiteGuard_RenameLogin::feature_off();
124
+ SiteGuard_AdminFilter::feature_off();
125
+ SiteGuard_Disable_XMLRPC::feature_off();
126
+ SiteGuard_WAF_Exclude_Rule::feature_off();
127
+ SiteGuard_UpdatesNotify::feature_off();
128
  }
129
  register_deactivation_hook( __FILE__, 'siteguard_deactivate' );
130
 
131
 
132
  class SiteGuard extends SiteGuard_Base {
133
  protected $menu_init;
134
+ function __construct() {
135
  global $siteguard_config;
136
  add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
137
+ $this->htaccess_check();
138
+ if ( is_admin() ) {
139
+ include 'admin/siteguard-menu-login-history.php';
140
+ $this->menu_init = new SiteGuard_Menu_Init();
141
  add_action( 'init', array( $this, 'set_cookie' ) );
142
  add_action( 'admin_init', array( $this, 'upgrade' ) );
143
  if ( '0' === $siteguard_config->get( 'show_admin_notices' ) && '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
144
  add_action( 'admin_notices', array( $this, 'admin_notices' ) );
145
  $siteguard_config->set( 'show_admin_notices', '1' );
146
+ $siteguard_config->update();
147
  }
148
  }
149
  }
150
+ function set_cookie() {
151
+ SiteGuard_Menu_Login_History::set_cookie();
152
  }
153
+ function plugins_loaded() {
154
  load_plugin_textdomain(
155
  'siteguard',
156
  false,
157
  dirname( plugin_basename( __FILE__ ) ) . '/languages'
158
  );
159
  }
160
+ function htaccess_check() {
161
  global $siteguard_config;
162
+
163
  $can_use_htaccess = true;
164
+ if ( false === SiteGuard_Htaccess::test_htaccess() ) {
165
  $can_use_htaccess = false;
166
  }
167
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
168
+ if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_AdminFilter::get_mark() ) ) {
169
  $siteguard_config->set( 'admin_filter_enable', '0' );
170
+ $siteguard_config->update();
171
  }
172
  }
173
  if ( '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
174
+ if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_RenameLogin::get_mark() ) ) {
175
  $siteguard_config->set( 'renamelogin_enable', '0' );
176
+ $siteguard_config->update();
177
  }
178
  }
179
  if ( '1' === $siteguard_config->get( 'disable_xmlrpc_enable' ) ) {
180
+ if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_Disable_XMLRPC::get_mark() ) ) {
181
  $siteguard_config->set( 'disable_xmlrpc_enable', '0' );
182
+ $siteguard_config->update();
183
  }
184
  }
185
  if ( '1' === $siteguard_config->get( 'waf_exclude_rule_enable' ) ) {
186
+ if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_WAF_Exclude_Rule::get_mark() ) ) {
187
  $siteguard_config->set( 'waf_exclude_rule_enable', '0' );
188
+ $siteguard_config->update();
189
  }
190
  }
191
  if ( '1' === $siteguard_config->get( 'captcha_enable' ) ) {
192
+ if ( false === $can_use_htaccess ) {
193
  $siteguard_config->set( 'captcha_enable', '0' );
194
+ $siteguard_config->update();
195
  }
196
  }
197
  }
198
+ function admin_notices() {
199
  global $siteguard_rename_login;
200
  echo '<div class="updated" style="background-color:#719f1d;"><p><span style="border: 4px solid #def1b8;padding: 4px 4px;color:#fff;font-weight:bold;background-color:#038bc3;">';
201
  echo esc_html__( 'Login page URL was changed.', 'siteguard' ) . '</span>';
202
  echo '<span style="color:#eee;">';
203
+ echo esc_html__( ' Please bookmark ', 'siteguard' ) . '<a style="color:#fff;text-decoration:underline;" href="' . esc_url( wp_login_url() ) . '">';
204
  echo esc_html__( 'new login URL', 'siteguard' ) . '</a>';
205
+ echo esc_html__( '. Setting change is ', 'siteguard' ) . '<a style="color:#fff;text-decoration:underline;" href="' . esc_url( menu_page_url( 'siteguard_rename_login', false ) ) . '">';
206
  echo esc_html__( 'here', 'siteguard' ) . '</a>';
207
  echo '.</span></p></div>';
208
+ $siteguard_rename_login->send_notify();
209
  }
210
+ function upgrade() {
211
  global $siteguard_config, $siteguard_rename_login, $siteguard_admin_filter, $siteguard_loginalert, $siteguard_updates_notify, $siteguard_login_history, $siteguard_xmlrpc, $siteguard_author_query;
212
  $upgrade_ok = true;
213
  $old_version = $siteguard_config->get( 'version' );
219
  }
220
  if ( version_compare( $old_version, '1.0.6' ) < 0 ) {
221
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
222
+ if ( true !== $siteguard_admin_filter->feature_on( $this->get_ip() ) ) {
223
  siteguard_error_log( 'Failed to update at admin_filter from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
224
  $upgrade_ok = false;
225
  }
233
  }
234
  if ( version_compare( $old_version, '1.2.5' ) < 0 ) {
235
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
236
+ $siteguard_admin_filter->cvt_status_for_1_2_5( $this->get_ip() );
237
  }
238
  if ( '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
239
+ if ( true !== $siteguard_rename_login->feature_on() ) {
240
  siteguard_error_log( 'Failed to update at rename_login from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
241
  $upgrade_ok = false;
242
  }
243
  }
244
  }
245
  if ( version_compare( $old_version, '1.3.0' ) < 0 ) {
246
+ $siteguard_login_history->init();
247
+ $siteguard_xmlrpc->init();
248
  }
249
  if ( version_compare( $old_version, '1.5.0' ) < 0 ) {
250
+ $admin_filter_exclude_path = $siteguard_config->get( 'admin_filter_exclude_path' );
251
+ if ( false === strpos( $admin_filter_exclude_path, 'site-health.php' ) ) {
252
+ $admin_filter_exclude_path .= ', site-health.php';
253
+ $siteguard_config->set( 'admin_filter_exclude_path', $admin_filter_exclude_path );
254
+ $siteguard_config->update();
255
+ }
256
  }
257
  if ( version_compare( $old_version, '1.5.1' ) < 0 ) {
258
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
259
+ if ( true !== $siteguard_admin_filter->feature_on( $this->get_ip() ) ) {
260
  siteguard_error_log( 'Failed to update at admin_filter from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
261
  $upgrade_ok = false;
262
  }
263
  }
264
  if ( '1' === $siteguard_config->get( 'disable_xmlrpc_enable' ) ) {
265
+ if ( true !== $siteguard_xmlrpc->feature_on() ) {
266
  siteguard_error_log( 'Failed to update at disable_xmlrpc from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
267
  $upgrade_ok = false;
268
  }
273
  }
274
  if ( version_compare( $old_version, '1.7.0' ) < 0 ) {
275
  if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
276
+ if ( true !== $siteguard_admin_filter->feature_on( $this->get_ip() ) ) {
277
  siteguard_error_log( 'Failed to update at admin_filter from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
278
  $upgrade_ok = false;
279
  }
281
  }
282
  if ( $upgrade_ok && SITEGUARD_VERSION !== $old_version ) {
283
  $siteguard_config->set( 'version', SITEGUARD_VERSION );
284
+ $siteguard_config->update();
285
  }
286
  }
287
  }
288
+ $siteguard = new SiteGuard();
test/siteguard-dummy.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  echo 'dummy page.';
3
- ?>
1
  <?php
2
  echo 'dummy page.';
3
+
uninstall.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
 
3
  if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
4
- exit ();
5
  }
6
 
7
- function delete_siteguard_plugin( ) {
8
  global $wpdb;
9
 
10
  delete_option( 'siteguard_config' );
11
 
12
- $table_name = $wpdb->prefix . 'siteguard_login';
13
  $wpdb->query( "DROP TABLE IF EXISTS $table_name;" );
14
 
15
- $table_name = $wpdb->prefix . 'siteguard_history';
16
  $wpdb->query( "DROP TABLE IF EXISTS $table_name;" );
17
  }
18
 
19
- delete_siteguard_plugin( );
1
  <?php
2
 
3
  if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
4
+ exit();
5
  }
6
 
7
+ function delete_siteguard_plugin() {
8
  global $wpdb;
9
 
10
  delete_option( 'siteguard_config' );
11
 
12
+ $table_name = $wpdb->prefix . 'siteguard_login';
13
  $wpdb->query( "DROP TABLE IF EXISTS $table_name;" );
14
 
15
+ $table_name = $wpdb->prefix . 'siteguard_history';
16
  $wpdb->query( "DROP TABLE IF EXISTS $table_name;" );
17
  }
18
 
19
+ delete_siteguard_plugin();