From e33f6bd6bce974ec0d9836e1589ea1facf159841 Mon Sep 17 00:00:00 2001 From: yehuda Date: Mon, 4 Mar 2019 16:40:35 +0200 Subject: * Added support for our new chrome notification extension. * few fixes --- .../PostmanConfigurationController.php | 23 ++++++++++++++ .../PostmanRegisterConfigurationSettings.php | 19 ++++++++++++ .../PostmanDiagnosticTestController.php | 3 ++ .../Postman-Email-Log/PostmanEmailLogService.php | 1 + Postman/Postman-Mail/PostmanMailgunMailEngine.php | 2 +- .../Zend-1.12.10/Mail/Protocol/Smtp.php | 14 ++++++++- Postman/PostmanInputSanitizer.php | 3 ++ Postman/PostmanOptions.php | 14 +++++++++ Postman/PostmanUtils.php | 36 ++++++---------------- Postman/PostmanViewController.php | 2 +- Postman/notifications/PostmanMailNotify.php | 2 +- Postman/notifications/PostmanNotify.php | 22 +++++++++++++ postman-smtp.php | 4 +-- readme.txt | 18 ++++++++--- 14 files changed, 126 insertions(+), 37 deletions(-) diff --git a/Postman/Postman-Configuration/PostmanConfigurationController.php b/Postman/Postman-Configuration/PostmanConfigurationController.php index 6abb5e2..208fa0b 100644 --- a/Postman/Postman-Configuration/PostmanConfigurationController.php +++ b/Postman/Postman-Configuration/PostmanConfigurationController.php @@ -428,6 +428,29 @@ class PostmanConfigurationController { +
+

+ + + + + + + + + + + +
+ + + + +
+ +
+
+ '; diff --git a/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php b/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php index ecd7ec3..6102d10 100644 --- a/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php +++ b/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php @@ -213,6 +213,16 @@ class PostmanSettingsRegistry { 'slack_token_callback', ), PostmanAdminController::NOTIFICATIONS_SLACK_CRED, 'slack_credentials' ); + add_settings_field( PostmanOptions::NOTIFICATION_USE_CHROME, _x( 'Push to chrome extension', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array( + $this, + 'notification_use_chrome_callback', + ), PostmanAdminController::NOTIFICATIONS_OPTIONS, PostmanAdminController::NOTIFICATIONS_SECTION ); + + add_settings_field( PostmanOptions::NOTIFICATION_CHROME_UID, _x( 'Chrome Extension UID', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array( + $this, + 'notification_chrome_uid_callback', + ), PostmanAdminController::NOTIFICATIONS_OPTIONS, PostmanAdminController::NOTIFICATIONS_SECTION ); + } } @@ -415,6 +425,15 @@ class PostmanSettingsRegistry { printf( '
%s', $inputDescription ); } + public function notification_use_chrome_callback() { + $value = $this->options->useChromeExtension(); + printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::NOTIFICATION_USE_CHROME, $value ? 'checked="checked"' : '' ); + } + + public function notification_chrome_uid_callback() { + printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::NOTIFICATION_CHROME_UID, $this->options->getNotificationChromeUid() ); + } + public function pushover_user_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PUSHOVER_USER, $this->options->getPushoverUser() ); } diff --git a/Postman/Postman-Diagnostic-Test/PostmanDiagnosticTestController.php b/Postman/Postman-Diagnostic-Test/PostmanDiagnosticTestController.php index 9f1c591..ad5fa84 100644 --- a/Postman/Postman-Diagnostic-Test/PostmanDiagnosticTestController.php +++ b/Postman/Postman-Diagnostic-Test/PostmanDiagnosticTestController.php @@ -208,8 +208,11 @@ class PostmanGetDiagnosticsViaAjax { /** */ public function getDiagnostics() { + $curl = curl_version(); $transportRegistry = PostmanTransportRegistry::getInstance(); $this->addToDiagnostics( 'HostName', PostmanUtils::getServerName() ); + $this->addToDiagnostics( 'cURL Version', $curl['version'] ); + $this->addToDiagnostics( 'OpenSSL Version', $curl['ssl_version'] ); $this->addToDiagnostics( 'OS', php_uname() ); $this->addToDiagnostics( 'PHP', PHP_OS . ' ' . PHP_VERSION . ' ' . setlocale( LC_CTYPE, 0 ) ); $this->addToDiagnostics( 'PHP Dependencies', $this->getPhpDependencies() ); diff --git a/Postman/Postman-Email-Log/PostmanEmailLogService.php b/Postman/Postman-Email-Log/PostmanEmailLogService.php index ebb2e54..103dcc1 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogService.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogService.php @@ -182,6 +182,7 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { $notify = new PostmanNotify( $notifyer, $message ); $notify->send($message, $log); + $notify->push_to_chrome($log->statusMessage); } /** diff --git a/Postman/Postman-Mail/PostmanMailgunMailEngine.php b/Postman/Postman-Mail/PostmanMailgunMailEngine.php index e874704..f098ec9 100644 --- a/Postman/Postman-Mail/PostmanMailgunMailEngine.php +++ b/Postman/Postman-Mail/PostmanMailgunMailEngine.php @@ -224,7 +224,7 @@ if ( ! class_exists( 'PostmanMailgunMailEngine' ) ) { private function addHeader( $name, $value, $deprecated = '' ) { if ( $value && ! empty( $value ) ) { - $this->mailgunMessage['h:' . $name] = $value; + $this->mailgunMessage['h:' . $name] = preg_replace('/.*:\s?/', '', $value); } } diff --git a/Postman/Postman-Mail/Zend-1.12.10/Mail/Protocol/Smtp.php b/Postman/Postman-Mail/Zend-1.12.10/Mail/Protocol/Smtp.php index be6d908..6f3c978 100644 --- a/Postman/Postman-Mail/Zend-1.12.10/Mail/Protocol/Smtp.php +++ b/Postman/Postman-Mail/Zend-1.12.10/Mail/Protocol/Smtp.php @@ -210,7 +210,19 @@ class Postman_Zend_Mail_Protocol_Smtp extends Postman_Zend_Mail_Protocol_Abstrac $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; - if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) { + $curl = curl_version(); + preg_match('/.*\/(\d*\.\d*\.\d*)[a-z]?/', $curl['ssl_version'], $ver_match ); + $tlsv1_2_installed = ! empty( $ver_match[1] ) ? $ver_match[1] >= '1.0.1' : true; + + if ( $this->_host == 'smtp.office365.com' && ! $tlsv1_2_installed ) { + + $error = sprintf( 'Office365 SMTP servie require TLS v1.2 and OpenSSL version 1.0.1 or greater, your current OpenSSL version is: %s. +You need to contact your web hosting support for help.', $ver_match[1] ); + + throw new Postman_Zend_Mail_Protocol_Exception( $error ); + } + + if ( defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT') ) { $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; } diff --git a/Postman/PostmanInputSanitizer.php b/Postman/PostmanInputSanitizer.php index b17df30..9e1fa52 100644 --- a/Postman/PostmanInputSanitizer.php +++ b/Postman/PostmanInputSanitizer.php @@ -74,6 +74,9 @@ if ( ! class_exists( 'PostmanInputSanitizer' ) ) { $this->sanitizePassword( 'Pushover Token', PostmanOptions::PUSHOVER_TOKEN, $input, $new_input, $this->options->getPushoverToken() ); $this->sanitizePassword( 'Slack Token', PostmanOptions::SLACK_TOKEN, $input, $new_input, $this->options->getSlackToken() ); + $this->sanitizeString( 'Push Chrome Extension', PostmanOptions::NOTIFICATION_USE_CHROME, $input, $new_input ); + $this->sanitizePassword( 'Push Chrome Extension UID', PostmanOptions::NOTIFICATION_CHROME_UID, $input, $new_input, $this->options->getNotificationChromeUid() ); + if ( $new_input [ PostmanOptions::CLIENT_ID ] != $this->options->getClientId() || $new_input [ PostmanOptions::CLIENT_SECRET ] != $this->options->getClientSecret() || $new_input [ PostmanOptions::HOSTNAME ] != $this->options->getHostname() ) { $this->logger->debug( 'Recognized new Client ID' ); // the user entered a new client id and we should destroy the stored auth token diff --git a/Postman/PostmanOptions.php b/Postman/PostmanOptions.php index 9c244bd..29ddbc6 100644 --- a/Postman/PostmanOptions.php +++ b/Postman/PostmanOptions.php @@ -106,6 +106,8 @@ if ( ! class_exists( 'PostmanOptions' ) ) { const TEMPORARY_DIRECTORY = 'tmp_dir'; const DISABLE_EMAIL_VALIDAITON = 'disable_email_validation'; const NOTIFICATION_SERVICE = 'notification_service'; + const NOTIFICATION_USE_CHROME = 'notification_use_chrome'; + const NOTIFICATION_CHROME_UID = 'notification_chrome_uid'; const PUSHOVER_USER = 'pushover_user'; const PUSHOVER_TOKEN = 'pushover_token'; const SLACK_TOKEN = 'slack_token'; @@ -341,6 +343,18 @@ if ( ! class_exists( 'PostmanOptions' ) ) { return base64_decode( $this->options [ PostmanOptions::SLACK_TOKEN ] ); } } + + public function useChromeExtension() { + if ( isset( $this->options [ PostmanOptions::NOTIFICATION_USE_CHROME ] ) ) { + return $this->options [ PostmanOptions::NOTIFICATION_USE_CHROME ]; + } + } + + public function getNotificationChromeUid() { + if ( isset( $this->options [ PostmanOptions::NOTIFICATION_CHROME_UID ] ) ) { + return base64_decode( $this->options [ PostmanOptions::NOTIFICATION_CHROME_UID ] ); + } + } public function getReplyTo() { if ( isset( $this->options [ PostmanOptions::REPLY_TO ] ) ) { diff --git a/Postman/PostmanUtils.php b/Postman/PostmanUtils.php index 8d5cd46..5405b79 100644 --- a/Postman/PostmanUtils.php +++ b/Postman/PostmanUtils.php @@ -445,37 +445,21 @@ class PostmanUtils { $result = 'localhost.localdomain'; if (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER)) { - $result = $_SERVER['SERVER_NAME']; + $host = $_SERVER['SERVER_NAME']; } elseif (function_exists('gethostname') and gethostname() !== false) { - $result = gethostname(); + $host = gethostname(); } elseif (php_uname('n') !== false) { - $result = php_uname('n'); + $host = php_uname('n'); } - if ( $result !== 'localhost.localdomain' ) { - // get the current result ip - $ip = gethostbyname($result); - - // dns query failed - if ( $ip == $result ) { - return $result; - } - - // get the current ip hostname - reverse dns - $host = gethostbyaddr($ip); - - // dns query failed - if ( $host == $ip ) { - return $result; - } - - // if hostname is not equal to the result set the ptr - if ( $result !== $host ) { - $result = $host; - } - } + // as final option - if ip returned or hostname without extension (not valid dns name) + $extension = pathinfo( $host, PATHINFO_EXTENSION ); + if ( filter_var( $result, FILTER_VALIDATE_IP ) || empty( $extension ) ) { + $siteurl = get_bloginfo('url'); + $host = parse_url($siteurl, PHP_URL_HOST); + } - return $result; + return str_replace('www.', '', $host ); } public static function getHost( $url ) { diff --git a/Postman/PostmanViewController.php b/Postman/PostmanViewController.php index 46aa39f..c0025a9 100644 --- a/Postman/PostmanViewController.php +++ b/Postman/PostmanViewController.php @@ -307,7 +307,7 @@ if ( ! class_exists( 'PostmanViewController' ) ) { echo '

- Version ' . $version . ' Mailgun Europe region support: Read Here + Version ' . $version . ' We have a new Chrome Extension: Read Here