From daf368d176e3c1e3c65b6a21563acdf677d67915 Mon Sep 17 00:00:00 2001
From: magepeopleteam
Date: Thu, 15 Dec 2022 10:51:49 +0000
Subject: [PATCH] appserro lib update
---
lib/appsero/src/Insights.php | 108 ++++++++++++++++++++++++-------
lib/appsero/src/License.php | 121 +++++++++++++++++++++++++++--------
2 files changed, 177 insertions(+), 52 deletions(-)
diff --git a/lib/appsero/src/Insights.php b/lib/appsero/src/Insights.php
index ac52cb3..ef42db5 100755
--- a/lib/appsero/src/Insights.php
+++ b/lib/appsero/src/Insights.php
@@ -38,10 +38,18 @@ class Insights {
*/
protected $client;
+ /**
+ * @var boolean
+ */
+ private $plugin_data = false;
+
+
/**
* Initialize the class
*
- * @param AppSero\Client
+ * @param $client
+ * @param null $name
+ * @param null $file
*/
public function __construct( $client, $name = null, $file = null ) {
@@ -65,6 +73,17 @@ class Insights {
return $this;
}
+ /**
+ * Add plugin data if needed
+ *
+ * @return \self
+ */
+ public function add_plugin_data() {
+ $this->plugin_data = true;
+
+ return $this;
+ }
+
/**
* Add extra data if needed
*
@@ -85,7 +104,7 @@ class Insights {
*
* @return \self
*/
- public function notice( $text ) {
+ public function notice($text='' ) {
$this->notice = $text;
return $this;
@@ -165,11 +184,6 @@ class Insights {
* @return void
*/
public function send_tracking_data( $override = false ) {
- // skip on AJAX Requests
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
- return;
- }
-
if ( ! $this->tracking_allowed() && ! $override ) {
return;
}
@@ -227,8 +241,33 @@ class Insights {
'ip_address' => $this->get_user_ip_address(),
'project_version' => $this->client->project_version,
'tracking_skipped' => false,
+ 'is_local' => $this->is_local_server(),
);
+ // Add Plugins
+ if ($this->plugin_data) {
+
+ $plugins_data = array();
+
+ foreach ($all_plugins['active_plugins'] as $slug => $plugin) {
+ $slug = strstr($slug, '/', true);
+ if (! $slug) {
+ continue;
+ }
+
+ $plugins_data[ $slug ] = array(
+ 'name' => isset($plugin['name']) ? $plugin['name'] : '',
+ 'version' => isset($plugin['version']) ? $plugin['version'] : '',
+ );
+ }
+
+ if (array_key_exists($this->client->slug, $plugins_data)) {
+ unset($plugins_data[$this->client->slug]);
+ }
+
+ $data['plugins'] = $plugins_data;
+ }
+
// Add metadata
if ( $extra = $this->get_extra_data() ) {
$data['extra'] = $extra;
@@ -274,10 +313,14 @@ class Insights {
'Number of users in your site',
'Site language',
'Number of active and inactive plugins',
- 'Site name and url',
+ 'Site name and URL',
'Your name and email address',
);
+ if ($this->plugin_data) {
+ array_splice($data, 4, 0, ["active plugins' name"]);
+ }
+
return $data;
}
@@ -322,9 +365,17 @@ class Insights {
* @return boolean
*/
private function is_local_server() {
- return false;
- $is_local = in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ) );
+ $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'localhost';
+ $ip = isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
+ $is_local = false;
+
+ if( in_array( $ip,array( '127.0.0.1', '::1' ) )
+ || ! strpos( $host, '.' )
+ || in_array( strrchr( $host, '.' ), array( '.test', '.testing', '.local', '.localhost', '.localdomain' ) )
+ ) {
+ $is_local = true;
+ }
return apply_filters( 'appsero_is_local', $is_local );
}
@@ -388,10 +439,10 @@ class Insights {
$notice .= ' (' . $this->client->__trans( 'what we collect' ) . ')';
$notice .= '' . implode( ', ', $this->data_we_collect() ) . '. No sensitive data is tracked. ';
- $notice .= 'We are using Appsero to collect your data. Learn more about how Appsero collects and handle your data.
';
+ $notice .= 'We are using Appsero to collect your data. Learn more about how Appsero collects and handle your data.
';
echo '';
- echo mep_esc_html($notice);
+ echo $notice;
echo '
';
echo ' ' . $this->client->__trans( 'Allow' ) . '';
echo ' ' . $this->client->__trans( 'No thanks' ) . '';
@@ -412,14 +463,14 @@ class Insights {
*/
public function handle_optin_optout() {
- if ( isset( $_GET[ $this->client->slug . '_tracker_optin' ] ) && mage_array_strip($_GET[ $this->client->slug . '_tracker_optin' ]) == 'true' ) {
+ if ( isset( $_GET[ $this->client->slug . '_tracker_optin' ] ) && $_GET[ $this->client->slug . '_tracker_optin' ] == 'true' ) {
$this->optin();
wp_redirect( remove_query_arg( $this->client->slug . '_tracker_optin' ) );
exit;
}
- if ( isset( $_GET[ $this->client->slug . '_tracker_optout' ] ) && mage_array_strip($_GET[ $this->client->slug . '_tracker_optout' ]) == 'true' ) {
+ if ( isset( $_GET[ $this->client->slug . '_tracker_optout' ] ) && $_GET[ $this->client->slug . '_tracker_optout' ] == 'true' ) {
$this->optout();
wp_redirect( remove_query_arg( $this->client->slug . '_tracker_optout' ) );
@@ -730,6 +781,14 @@ class Insights {
wp_send_json_error();
}
+ if ( ! wp_verify_nonce( $_POST['nonce'], 'appsero-security-nonce' ) ) {
+ wp_send_json_error( 'Nonce verification failed' );
+ }
+
+ if ( ! current_user_can( 'manage_options' ) ) {
+ wp_send_json_error( 'You are not allowed for this task' );
+ }
+
$data = $this->get_tracking_data();
$data['reason_id'] = sanitize_text_field( $_POST['reason_id'] );
$data['reason_info'] = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '';
@@ -756,7 +815,7 @@ class Insights {
$custom_reasons = apply_filters( 'appsero_custom_deactivation_reasons', array() );
?>
-