PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.7
Patchstack – WordPress & Plugins Security v2.2.7
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
← All changes | includes/admin/ajax.php +29 -22 2.1.212.2.7 View file →
@@ -19,16 +19,16 @@
19 19 public function __construct( $core ) {
20 20 parent::__construct( $core );
21 21 if ( isset( $_POST['PatchstackNonce'] ) && current_user_can( 'manage_options' ) && wp_verify_nonce( $_POST['PatchstackNonce'], 'patchstack-nonce' ) ) {
22 22 // Log tables actions.
23 - add_action( 'wp_ajax_patchstack_users_log_table', array( $this, 'users_log_table' ) );
24 - add_action( 'wp_ajax_patchstack_firewall_log_table', array( $this, 'firewall_log_table' ) );
23 + add_action( 'wp_ajax_patchstack_users_log_table', [ $this, 'users_log_table' ] );
24 + add_action( 'wp_ajax_patchstack_firewall_log_table', [ $this, 'firewall_log_table' ] );
25 25
26 26 // License related actions.
27 - add_action( 'wp_ajax_patchstack_activate_license', array( $this, 'activate_license' ) );
27 + add_action( 'wp_ajax_patchstack_activate_license', [ $this, 'activate_license' ] );
28 28
29 29 // Hide login related actions.
30 - add_action( 'wp_ajax_patchstack_send_new_url_email', array( $this, 'send_new_url_email' ) );
30 + add_action( 'wp_ajax_patchstack_send_new_url_email', [ $this, 'send_new_url_email' ] );
31 31 }
32 32 }
33 33
34 34 /**
@@ -44,15 +44,15 @@
44 44 // Pull all entries, given parameters.
45 45 global $wpdb;
46 46 $entries = $wpdb->get_results(
47 47 $wpdb->prepare(
48 - "SELECT a.id, a.ip, a.flag, a.method, a.log_date, case when a.referer IS NULL or a.referer = '' then a.request_uri else a.referer end as referer, a.fid, b.description
48 + "SELECT a.id, a.ip, a.flag, a.method, a.log_date, a.request_uri as referer, a.fid, b.description
49 49 FROM " . $wpdb->prefix . 'patchstack_firewall_log AS a
50 50 LEFT JOIN ' . $wpdb->prefix . 'patchstack_logic AS b ON b.id = a.fid
51 51 ORDER BY a.id DESC
52 52 LIMIT %d, %d
53 53 ',
54 - array( wp_filter_nohtml_kses( $_POST['start'] ), wp_filter_nohtml_kses( $_POST['length'] ) )
54 + [ wp_filter_nohtml_kses( $_POST['start'] ), wp_filter_nohtml_kses( $_POST['length'] ) ]
55 55 )
56 56 );
57 57
58 58 // Get total amount of rows.
@@ -57,20 +57,22 @@
57 57
58 58 // Get total amount of rows.
59 59 $count = $wpdb->get_var( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'patchstack_firewall_log' );
60 60 $firewall_rules = json_decode( get_option( 'patchstack_firewall_rules', '' ), true );
61 + $firewall_rules_v3 = json_decode( get_option( 'patchstack_firewall_rules_v3', [] ), true );
62 + $firewall_rules = array_merge($firewall_rules, $firewall_rules_v3);
61 63
62 64 // Modify data if necessary.
63 - $list = array();
65 + $list = [];
64 66 foreach ( $entries as $entry ) {
65 67 foreach ( $entry as $key => $value ) {
66 - if ( ! in_array( $key, array( 'referer' ) ) ) {
68 + if ( ! in_array( $key, [ 'referer' ] ) ) {
67 69 $entry->$key = sanitize_textarea_field( $value );
68 70 }
69 71 }
70 72
71 73 // Attempt to find the block reason.
72 - $reason = $wpdb->get_var( $wpdb->prepare( 'SELECT cname FROM ' . $wpdb->prefix . 'patchstack_logic WHERE id = %d LIMIT 1', array( $entry->fid ) ) );
74 + $reason = $wpdb->get_var( $wpdb->prepare( 'SELECT cname FROM ' . $wpdb->prefix . 'patchstack_logic WHERE id = %d LIMIT 1', [ $entry->fid ] ) );
73 75 if ( $reason ) {
74 76 $entry->fid = $reason;
75 77 } elseif ( $firewall_rules != '' ) {
76 78 foreach ( $firewall_rules as $rule ) {
@@ -87,13 +89,13 @@
87 89 }
88 90
89 91 // Return output.
90 92 wp_send_json(
91 - array(
93 + [
92 94 'data' => $list,
93 95 'recordsFiltered' => $count,
94 96 'recordsTotal' => $count
95 - )
97 + ]
96 98 );
97 99 }
98 100
99 101 /**
@@ -108,13 +110,13 @@
108 110
109 111 // Determine if searching?
110 112 global $wpdb;
111 113 $searching = false;
112 - $likes = array();
114 + $likes = [];
113 115 if ( isset( $_POST['search'], $_POST['search']['value'] ) && $_POST['search']['value'] != '' ) {
114 116 $val = wp_filter_nohtml_kses( $_POST['search']['value'] );
115 117 $searching = true;
116 - $columns = array( 'author', 'ip', 'object', 'object_name', 'action' );
118 + $columns = [ 'author', 'ip', 'object', 'object_name', 'action' ];
117 119 $search = 'WHERE 1=2 ';
118 120 foreach ( $columns as $column ) {
119 121 array_push( $likes, '%' . $wpdb->esc_like( $val ) . '%' );
120 122 $search .= 'OR ' . $column . ' LIKE %s';
@@ -127,9 +129,9 @@
127 129 FROM ' . $wpdb->prefix . 'patchstack_event_log ' . ( $searching ? $search : '' ) . '
128 130 ORDER BY id DESC
129 131 LIMIT %d, %d
130 132 ',
131 - array_merge( $likes, array( wp_filter_nohtml_kses( $_POST['start'] ), wp_filter_nohtml_kses( $_POST['length'] ) ) )
133 + array_merge( $likes, [ wp_filter_nohtml_kses( $_POST['start'] ), wp_filter_nohtml_kses( $_POST['length'] ) ] )
132 134 )
133 135 );
134 136
135 137 $count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'patchstack_event_log ' . ( $searching ? $search : '' ), $likes ) );
@@ -134,9 +136,9 @@
134 136
135 137 $count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'patchstack_event_log ' . ( $searching ? $search : '' ), $likes ) );
136 138
137 139 // Modify data if necessary.
138 - $list = array();
140 + $list = [];
139 141 foreach ( $logs as $log ) {
140 142 $list[] = $log;
141 143 }
142 144
@@ -141,13 +143,13 @@
141 143 }
142 144
143 145 // Return output.
144 146 wp_send_json(
145 - array(
147 + [
146 148 'data' => $list,
147 149 'recordsFiltered' => $count,
148 150 'recordsTotal' => $count
149 - )
151 + ]
150 152 );
151 153 }
152 154
153 155 /**
@@ -155,20 +157,25 @@
155 157 *
156 158 * @return void
157 159 */
158 160 public function activate_license() {
159 - if ( ! isset( $_POST['clientid'], $_POST['secretkey'] ) || !ctype_digit( $_POST['clientid'] ) ) {
161 + if ( ! isset( $_POST['key'] ) || strpos( $_POST['key'], '-' ) === false) {
160 162 wp_send_json(
161 - array(
163 + [
162 164 'result' => 'error',
163 - 'error_message' => 'Fill in all of the fields properly.'
164 - )
165 + 'error_message' => 'An invalid API key was provided.'
166 + ]
165 167 );
166 168 }
167 169
170 + // Since we have the keys combined into one now, split them up here.
171 + $split = explode('-', $_POST['key']);
172 + $secretkey = $split[0];
173 + $clientid = $split[1];
174 +
168 175 // Test the new keys.
169 176 update_option( 'patchstack_api_token', '' );
170 - $results = $this->plugin->activation->alter_license( wp_filter_nohtml_kses( $_POST['clientid'] ), wp_filter_nohtml_kses( $_POST['secretkey'] ), 'activate' );
177 + $results = $this->plugin->activation->alter_license( wp_filter_nohtml_kses( $clientid ), wp_filter_nohtml_kses( $secretkey ), 'activate' );
171 178 if ( $results ) {
172 179 $response = $this->plugin->api->update_license_status();
173 180 $results['response'] = $response;
174 181 wp_send_json( $results );