PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.11
Patchstack – WordPress & Plugins Security v2.2.11
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 +42 -134 2.1.32.2.11 View file →
@@ -18,165 +18,73 @@
18 18 */
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 - // Log tables actions.
23 - add_action( 'wp_ajax_users_log_table', array( $this, 'users_log_table' ) );
24 - add_action( 'wp_ajax_firewall_log_table', array( $this, 'firewall_log_table' ) );
25 -
26 22 // License related actions.
27 - add_action( 'wp_ajax_activate_license', array( $this, 'activate_license' ) );
23 + add_action( 'wp_ajax_patchstack_activate_license', [ $this, 'activate_license' ] );
28 24
29 - // Hide login related actions.
30 - add_action( 'wp_ajax_send_new_url_email', array( $this, 'send_new_url_email' ) );
25 + // Auto license activator.
26 + add_action( 'wp_ajax_patchstack_activate_auto', [ $this, 'auto_activate' ] );
27 + add_action( 'wp_ajax_patchstack_activation_status', [ $this, 'activation_status' ] );
31 28 }
32 29 }
33 30
34 31 /**
35 - * Firewall logs pagination.
32 + * Test and activate a new license.
36 33 *
37 - * @return array
34 + * @return void
38 35 */
39 - public function firewall_log_table() {
40 - if ( ! isset( $_POST['start'], $_POST['length'] ) || !ctype_digit( $_POST['start'] ) || !ctype_digit( $_POST['length'] ) ) {
41 - exit;
36 + public function activate_license() {
37 + if ( ! isset( $_POST['key'] ) || strpos( $_POST['key'], '-' ) === false) {
38 + wp_send_json(
39 + [
40 + 'result' => 'error',
41 + 'error_message' => 'An invalid API key was provided.'
42 + ]
43 + );
42 44 }
43 45
44 - // Pull all entries, given parameters.
45 - global $wpdb;
46 - $entries = $wpdb->get_results(
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
49 - FROM " . $wpdb->prefix . 'patchstack_firewall_log AS a
50 - LEFT JOIN ' . $wpdb->prefix . 'patchstack_logic AS b ON b.id = a.fid
51 - ORDER BY a.id DESC
52 - LIMIT %d, %d
53 - ',
54 - array( wp_filter_nohtml_kses( $_POST['start'] ), wp_filter_nohtml_kses( $_POST['length'] ) )
55 - )
56 - );
46 + // Since we have the keys combined into one now, split them up here.
47 + $split = explode('-', $_POST['key']);
48 + $secretkey = $split[0];
49 + $clientid = $split[1];
57 50
58 - // Get total amount of rows.
59 - $count = $wpdb->get_var( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'patchstack_firewall_log' );
60 - $firewall_rules = json_decode( get_option( 'patchstack_firewall_rules', '' ), true );
61 -
62 - // Modify data if necessary.
63 - $list = array();
64 - foreach ( $entries as $entry ) {
65 - foreach ( $entry as $key => $value ) {
66 - if ( ! in_array( $key, array( 'referer' ) ) ) {
67 - $entry->$key = sanitize_textarea_field( $value );
68 - }
69 - }
70 -
71 - // 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 ) ) );
73 - if ( $reason ) {
74 - $entry->fid = $reason;
75 - } elseif ( $firewall_rules != '' ) {
76 - foreach ( $firewall_rules as $rule ) {
77 - if ( isset( $rule['title'], $rule['cat'] ) && '55' . $rule['id'] == $entry->fid ) {
78 - $entry->fid = $rule['cat'];
79 - $entry->description = $rule['title'];
80 - }
81 - }
82 - } else {
83 - $entry->fid = 'Unknown';
84 - }
85 -
86 - $list[] = $entry;
51 + // Test the new keys.
52 + update_option( 'patchstack_api_token', '' );
53 + $results = $this->plugin->activation->alter_license( wp_filter_nohtml_kses( $clientid ), wp_filter_nohtml_kses( $secretkey ), 'activate' );
54 + if ( $results ) {
55 + $response = $this->plugin->api->update_license_status();
56 + $results['response'] = $response;
57 + wp_send_json( $results );
87 58 }
88 -
89 - // Return output.
90 - wp_send_json(
91 - array(
92 - 'data' => $list,
93 - 'recordsFiltered' => $count,
94 - 'recordsTotal' => $count
95 - )
96 - );
97 59 }
98 60
99 61 /**
100 - * Activity logs pagination.
101 - *
62 + * Attempt to auto activate the license after a plugin activation, if no current license exists.
63 + *
102 64 * @return void
103 65 */
104 - public function users_log_table() {
105 - if ( ! isset( $_POST['start'], $_POST['length'] ) || !ctype_digit( $_POST['start'] ) || !ctype_digit( $_POST['length'] ) ) {
106 - exit;
107 - }
66 + public function auto_activate() {
67 + $secretToken = get_option( 'patchstack_activation_secret', '' );
108 68
109 - // Determine if searching?
110 - global $wpdb;
111 - $searching = false;
112 - $likes = array();
113 - if ( isset( $_POST['search'], $_POST['search']['value'] ) && $_POST['search']['value'] != '' ) {
114 - $val = wp_filter_nohtml_kses( $_POST['search']['value'] );
115 - $searching = true;
116 - $columns = array( 'author', 'ip', 'object', 'object_name', 'action' );
117 - $search = 'WHERE 1=2 ';
118 - foreach ( $columns as $column ) {
119 - array_push( $likes, '%' . $wpdb->esc_like( $val ) . '%' );
120 - $search .= 'OR ' . $column . ' LIKE %s';
121 - }
69 + // Only continue if we have a secret token.
70 + $autoActivated = false;
71 + if ( ! empty( $secretToken ) ) {
72 + $autoActivated = $this->plugin->api->send_secret_token( $secretToken );
122 73 }
123 74
124 - $logs = $wpdb->get_results(
125 - $wpdb->prepare(
126 - 'SELECT *
127 - FROM ' . $wpdb->prefix . 'patchstack_event_log ' . ( $searching ? $search : '' ) . '
128 - ORDER BY id DESC
129 - LIMIT %d, %d
130 - ',
131 - array_merge( $likes, array( wp_filter_nohtml_kses( $_POST['start'] ), wp_filter_nohtml_kses( $_POST['length'] ) ) )
132 - )
133 - );
134 -
135 - $count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'patchstack_event_log ' . ( $searching ? $search : '' ), $likes ) );
136 -
137 - // Modify data if necessary.
138 - $list = array();
139 - foreach ( $logs as $log ) {
140 - $list[] = $log;
141 - }
142 -
143 - // Return output.
144 - wp_send_json(
145 - array(
146 - 'data' => $list,
147 - 'recordsFiltered' => $count,
148 - 'recordsTotal' => $count
149 - )
150 - );
75 + wp_send_json( [
76 + 'result' => $autoActivated || get_option( 'patchstack_clientid', false ) != false ? 'success' : 'error'
77 + ] );
151 78 }
152 79
153 80 /**
154 - * Test and activate a new license.
155 - *
81 + * Get the current license activation status.
82 + *
156 83 * @return void
157 84 */
158 - public function activate_license() {
159 - if ( ! isset( $_POST['clientid'], $_POST['secretkey'] ) || !ctype_digit( $_POST['clientid'] ) ) {
160 - return;
161 - }
162 -
163 - // Test the new keys.
164 - update_option( 'patchstack_api_token', '' );
165 - $results = $this->plugin->activation->alter_license( wp_filter_nohtml_kses( $_POST['clientid'] ), wp_filter_nohtml_kses( $_POST['secretkey'] ), 'activate' );
166 - if ( $results ) {
167 - $response = $this->plugin->api->update_license_status();
168 - $results['response'] = $response;
169 - wp_send_json( $results );
170 - }
171 - }
172 -
173 - /**
174 - * Send an email to the current logged in user that contains the new admin page URL.
175 - *
176 - * @return void
177 - */
178 - public function send_new_url_email() {
179 - $success = $this->plugin->hide_login->send_email();
180 - die( $success ? 'success' : 'fail' );
85 + public function activation_status() {
86 + wp_send_json( [
87 + 'activated' => get_option( 'patchstack_clientid', false ) != false
88 + ] );
181 89 }
182 90 }