From 4e2e09ea24568488201aec52ed3ebac57250935c Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 25 May 2017 15:55:33 -0400 Subject: [PATCH 1/2] Adds server OS, web server information and cron ping response to HS beacon --- lib/Helpscout/Beacon.php | 4 ++++ tests/unit/Helpscout/BeaconTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/Helpscout/Beacon.php b/lib/Helpscout/Beacon.php index 36da0e5162..4e76409d80 100644 --- a/lib/Helpscout/Beacon.php +++ b/lib/Helpscout/Beacon.php @@ -1,5 +1,6 @@ MAILPOET_VERSION, 'WordPress version' => get_bloginfo('version'), 'Database version' => $db_version, + 'Web server' => $_SERVER["SERVER_SOFTWARE"], + 'Server OS' => (function_exists('php_uname')) ? php_uname() : 'N/A', 'WP_MEMORY_LIMIT' => WP_MEMORY_LIMIT, 'WP_MAX_MEMORY_LIMIT' => WP_MAX_MEMORY_LIMIT, 'WP_DEBUG' => WP_DEBUG, @@ -38,6 +41,7 @@ class Beacon { $mta['frequency']['interval'] ), 'Task Scheduler method' => Setting::getValue('cron_trigger.method'), + 'Cron ping response' => CronHelper::pingDaemon(), 'Default FROM address' => Setting::getValue('sender.address'), 'Default Reply-To address' => Setting::getValue('reply_to.address'), 'Bounce Email Address' => Setting::getValue('bounce.address'), diff --git a/tests/unit/Helpscout/BeaconTest.php b/tests/unit/Helpscout/BeaconTest.php index 7e24fceb39..9ce0d082f4 100644 --- a/tests/unit/Helpscout/BeaconTest.php +++ b/tests/unit/Helpscout/BeaconTest.php @@ -108,4 +108,16 @@ class BeaconTest extends MailPoetTest { // unsubscribed users are not taken into account expect($this->beacon_data['Total number of subscribers'])->equals(2); } + + function testItReturnsWebserverInformation() { + expect($this->beacon_data['Web server'])->equals($_SERVER["SERVER_SOFTWARE"]); + } + + function testItReturnsServerOSInformation() { + expect($this->beacon_data['Server OS'])->equals(php_uname()); + } + + function testItReturnsCronPingResponse() { + expect($this->beacon_data['Cron ping response'])->true(); + } } \ No newline at end of file From 7f0396747db26b55be0b292f23fbf68e06492e2b Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 29 May 2017 19:29:56 -0400 Subject: [PATCH 2/2] Adds cron ping URL instead of ping response Checks for existence of SERVER_SOFTWARE variable --- lib/Helpscout/Beacon.php | 11 +++++++++-- tests/unit/Helpscout/BeaconTest.php | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Helpscout/Beacon.php b/lib/Helpscout/Beacon.php index 4e76409d80..be304ea15f 100644 --- a/lib/Helpscout/Beacon.php +++ b/lib/Helpscout/Beacon.php @@ -3,6 +3,8 @@ namespace MailPoet\Helpscout; use MailPoet\Cron\CronHelper; use MailPoet\Models\Subscriber; use MailPoet\Models\Setting; +use MailPoet\Router\Endpoints\CronDaemon; +use MailPoet\Router\Router; if(!defined('ABSPATH')) exit; @@ -13,6 +15,11 @@ class Beacon { $mta = Setting::getValue('mta'); $current_theme = wp_get_theme(); $current_user = wp_get_current_user(); + $cron_ping_url = Router::buildRequest( + CronDaemon::ENDPOINT, + CronDaemon::ACTION_PING + ); + $cron_ping_url = str_replace(home_url(), CronHelper::getSiteUrl(), $cron_ping_url); return array( 'name' => $current_user->display_name, @@ -21,7 +28,7 @@ class Beacon { 'MailPoet version' => MAILPOET_VERSION, 'WordPress version' => get_bloginfo('version'), 'Database version' => $db_version, - 'Web server' => $_SERVER["SERVER_SOFTWARE"], + 'Web server' => (!empty($_SERVER["SERVER_SOFTWARE"])) ? $_SERVER["SERVER_SOFTWARE"] : 'N/A', 'Server OS' => (function_exists('php_uname')) ? php_uname() : 'N/A', 'WP_MEMORY_LIMIT' => WP_MEMORY_LIMIT, 'WP_MAX_MEMORY_LIMIT' => WP_MAX_MEMORY_LIMIT, @@ -41,7 +48,7 @@ class Beacon { $mta['frequency']['interval'] ), 'Task Scheduler method' => Setting::getValue('cron_trigger.method'), - 'Cron ping response' => CronHelper::pingDaemon(), + 'Cron ping URL' => $cron_ping_url, 'Default FROM address' => Setting::getValue('sender.address'), 'Default Reply-To address' => Setting::getValue('reply_to.address'), 'Bounce Email Address' => Setting::getValue('bounce.address'), diff --git a/tests/unit/Helpscout/BeaconTest.php b/tests/unit/Helpscout/BeaconTest.php index 9ce0d082f4..509d2ed072 100644 --- a/tests/unit/Helpscout/BeaconTest.php +++ b/tests/unit/Helpscout/BeaconTest.php @@ -110,7 +110,9 @@ class BeaconTest extends MailPoetTest { } function testItReturnsWebserverInformation() { - expect($this->beacon_data['Web server'])->equals($_SERVER["SERVER_SOFTWARE"]); + expect($this->beacon_data['Web server'])->equals( + (!empty($_SERVER["SERVER_SOFTWARE"])) ? $_SERVER["SERVER_SOFTWARE"] : 'N/A' + ); } function testItReturnsServerOSInformation() { @@ -118,6 +120,6 @@ class BeaconTest extends MailPoetTest { } function testItReturnsCronPingResponse() { - expect($this->beacon_data['Cron ping response'])->true(); + expect($this->beacon_data['Cron ping URL'])->contains('&action=ping'); } } \ No newline at end of file