From 0ccbacaeb1db89b75bf77f1fb968ba783574420a Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 20 May 2017 09:33:28 +1000 Subject: [PATCH 1/5] Use composer for Net_SMTP and Net_Socket and patch for TLS and CiviCRM Custom Error Roll back Net_Socket for php compatabilty --- composer.json | 10 +- composer.lock | 115 +++++++++++++++++- tools/scripts/composer/net-smtp-fix.sh | 20 +++ .../composer/patches/net-smtp-patch.txt | 15 +++ .../composer/patches/net-smtp-tls-patch.txt | 23 ++++ ...execption-fix.sh => pear-exception-fix.sh} | 0 6 files changed, 179 insertions(+), 4 deletions(-) create mode 100755 tools/scripts/composer/net-smtp-fix.sh create mode 100644 tools/scripts/composer/patches/net-smtp-patch.txt create mode 100644 tools/scripts/composer/patches/net-smtp-tls-patch.txt rename tools/scripts/composer/{pear-execption-fix.sh => pear-exception-fix.sh} (100%) diff --git a/composer.json b/composer.json index 62c55e5442a7..952a46695898 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,9 @@ "phpoffice/phpword": "^0.13.0", "pear/Validate_Finance_CreditCard": "dev-master", "civicrm/civicrm-cxn-rpc": "~0.16.12.05", - "pear/Auth_SASL": "1.1.0" + "pear/Auth_SASL": "1.1.0", + "pear/Net_SMTP": "1.6.*", + "pear/Net_socket": "1.0.*" }, "repositories": [ { @@ -35,12 +37,14 @@ "post-install-cmd": [ "bash tools/scripts/composer/dompdf-cleanup.sh", "bash tools/scripts/composer/tcpdf-cleanup.sh", - "bash tools/scripts/composer/pear-execption-fix.sh" + "bash tools/scripts/composer/pear-exception-fix.sh", + "bash tools/scripts/composer/net-smtp-fix.sh" ], "post-update-cmd": [ "bash tools/scripts/composer/dompdf-cleanup.sh", "bash tools/scripts/composer/tcpdf-cleanup.sh", - "bash tools/scripts/composer/pear-execption-fix.sh" + "bash tools/scripts/composer/pear-exception-fix.sh", + "bash tools/scripts/composer/net-smtp-fix.sh" ] } } diff --git a/composer.lock b/composer.lock index ad486f28a39b..ac754e81998b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "60d5a363eaca7fd7db0dbb3ba0599fa5", + "content-hash": "9717496290241ba85372c78b619e957b", "packages": [ { "name": "civicrm/civicrm-cxn-rpc", @@ -197,6 +197,119 @@ "description": "Abstraction of various SASL mechanism responses", "time": "2017-03-07T14:37:05+00:00" }, + { + "name": "pear/net_smtp", + "version": "1.6.3", + "source": { + "type": "git", + "url": "https://github.com/pear/Net_SMTP.git", + "reference": "7b6240761adf6ee245098e238a25d5c35650d82c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pear/Net_SMTP/zipball/7b6240761adf6ee245098e238a25d5c35650d82c", + "reference": "7b6240761adf6ee245098e238a25d5c35650d82c", + "shasum": "" + }, + "require": { + "pear/net_socket": "*", + "pear/pear_exception": "*", + "php": ">=4.0.5" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "suggest": { + "pear/auth_sasl": "Install optionally via your project's composer.json" + }, + "type": "library", + "autoload": { + "psr-0": { + "Net": "./" + } + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "./" + ], + "license": [ + "PHP License" + ], + "authors": [ + { + "name": "Jon Parise", + "email": "jon@php.net", + "homepage": "http://www.indelible.org", + "role": "Lead" + }, + { + "name": "Chuck Hagenbuch", + "email": "chuck@horde.org", + "role": "Lead" + } + ], + "description": "An implementation of the SMTP protocol", + "homepage": "http://pear.github.io/Net_SMTP/", + "keywords": [ + "email", + "mail", + "smtp" + ], + "time": "2015-08-02T17:20:17+00:00" + }, + { + "name": "pear/net_socket", + "version": "1.0.14", + "source": { + "type": "git", + "url": "https://github.com/pear/Net_Socket.git", + "reference": "fcd33efd77e4b35ce85489141ab9145343579fe8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pear/Net_Socket/zipball/fcd33efd77e4b35ce85489141ab9145343579fe8", + "reference": "fcd33efd77e4b35ce85489141ab9145343579fe8", + "shasum": "" + }, + "require": { + "pear/pear_exception": "*" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Net": "./" + } + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "./" + ], + "license": [ + "PHP License" + ], + "authors": [ + { + "name": "Chuck Hagenbuch", + "email": "chuck@horde.org", + "role": "Lead" + }, + { + "name": "Aleksander Machniak", + "email": "alec@php.net", + "role": "Lead" + }, + { + "name": "Stig Bakken", + "email": "stig@php.net", + "role": "Lead" + } + ], + "description": "More info available on: http://pear.php.net/package/Net_Socket", + "time": "2014-02-20T19:27:06+00:00" + }, { "name": "pear/pear_exception", "version": "v1.0.0", diff --git a/tools/scripts/composer/net-smtp-fix.sh b/tools/scripts/composer/net-smtp-fix.sh new file mode 100755 index 000000000000..fb573c15b64c --- /dev/null +++ b/tools/scripts/composer/net-smtp-fix.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +## Cleanup the vendor tree. The main issue here is that civi Civi is +## deployed as a module inside a CMS, so all its source-code gets published. +## Some libraries distribute admin tools and sample files which should not +## be published. +## +## This script should be idempotent -- if you rerun it several times, it +## should always produce the same post-condition. + +## Replace a line in a file +## This is a bit like 'sed -i', but dumber and more cross-platform. + +# Add in CiviCRM custom error message for CRM-8744. +if ! grep -q 'CRM-8744' vendor/pear/net_smtp/Net/SMTP.php; then +patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-patch.txt +fi +if ! grep -q '@STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT' vendor/pear/net_smtp/Net/SMTP.php; then +patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-tls-patch.txt +fi diff --git a/tools/scripts/composer/patches/net-smtp-patch.txt b/tools/scripts/composer/patches/net-smtp-patch.txt new file mode 100644 index 000000000000..6b12048ca5f8 --- /dev/null +++ b/tools/scripts/composer/patches/net-smtp-patch.txt @@ -0,0 +1,15 @@ +--- SMTP.php 2017-01-15 05:19:55.000000000 +1100 ++++ SMTP.php.new 2017-05-20 09:01:52.832373840 +1000 +@@ -368,8 +368,10 @@ + return true; + } + +- return PEAR::raiseError('Invalid response code received from server', +- $this->_code, PEAR_ERROR_RETURN); ++ // CRM-8744 ++ $errorMessage = 'Invalid response code received from SMTP server while sending email. This is often caused by a misconfiguration in Outbound Email settings. Please verify the settings at Administer CiviCRM >> Global Settings >> Outbound Email (SMTP).'; ++ return PEAR::raiseError($errorMessage, $this->_code, PEAR_ERROR_RETURN); ++ + } + + /** diff --git a/tools/scripts/composer/patches/net-smtp-tls-patch.txt b/tools/scripts/composer/patches/net-smtp-tls-patch.txt new file mode 100644 index 000000000000..94c549fd6001 --- /dev/null +++ b/tools/scripts/composer/patches/net-smtp-tls-patch.txt @@ -0,0 +1,23 @@ +diff --git a/Net/SMTP.php b/Net/SMTP.php +index 28eae8c..8f4e92b 100644 +--- a/Net/SMTP.php ++++ b/Net/SMTP.php +@@ -602,7 +602,17 @@ + if (PEAR::isError($result = $this->_parseResponse(220))) { + return $result; + } +- if (PEAR::isError($result = $this->_socket->enableCrypto(true, STREAM_CRYPTO_METHOD_TLS_CLIENT))) { ++ if (isset($this->socket_options['ssl']['crypto_method'])) { ++ $crypto_method = $this->socket_options['ssl']['crypto_method']; ++ } else { ++ /* STREAM_CRYPTO_METHOD_TLS_ANY_CLIENT constant does not exist ++ * and STREAM_CRYPTO_METHOD_SSLv23_CLIENT constant is ++ * inconsistent across PHP versions. */ ++ $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT ++ | @STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT ++ | @STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; ++ } ++ if (PEAR::isError($result = $this->socket->enableCrypto(true, $crypto_method))) { + return $result; + } elseif ($result !== true) { + return PEAR::raiseError('STARTTLS failed'); diff --git a/tools/scripts/composer/pear-execption-fix.sh b/tools/scripts/composer/pear-exception-fix.sh similarity index 100% rename from tools/scripts/composer/pear-execption-fix.sh rename to tools/scripts/composer/pear-exception-fix.sh From 5b0dd2c07b4b4e54a243e103472e7e3873842277 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 20 May 2017 12:42:47 +1000 Subject: [PATCH 2/5] Add patch to Net_SMTP for php7 compatability --- tools/scripts/composer/net-smtp-fix.sh | 3 +++ .../scripts/composer/patches/net-smtp-php7-patch.txt | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 tools/scripts/composer/patches/net-smtp-php7-patch.txt diff --git a/tools/scripts/composer/net-smtp-fix.sh b/tools/scripts/composer/net-smtp-fix.sh index fb573c15b64c..87721739d956 100755 --- a/tools/scripts/composer/net-smtp-fix.sh +++ b/tools/scripts/composer/net-smtp-fix.sh @@ -18,3 +18,6 @@ fi if ! grep -q '@STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT' vendor/pear/net_smtp/Net/SMTP.php; then patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-tls-patch.txt fi +if ! grep -q 'function __construct' vendor/pear/net_smtp/Net/SMTP.php; then +patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-php7-patch.txt +fi diff --git a/tools/scripts/composer/patches/net-smtp-php7-patch.txt b/tools/scripts/composer/patches/net-smtp-php7-patch.txt new file mode 100644 index 000000000000..6ed1605c041c --- /dev/null +++ b/tools/scripts/composer/patches/net-smtp-php7-patch.txt @@ -0,0 +1,11 @@ +--- SMTP.php 2017-05-20 11:50:53.716664059 +1000 ++++ SMTP.php.new 2017-05-20 12:38:36.271530119 +1000 +@@ -167,7 +167,7 @@ + * @access public + * @since 1.0 + */ +- function Net_SMTP($host = null, $port = null, $localhost = null, ++ function __construct($host = null, $port = null, $localhost = null, + $pipelining = false, $timeout = 0, $socket_options = null) + { + if (isset($host)) { From 764b4bffa3ee3d4c41523e81909ff7eb549156ff Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Jun 2017 20:13:22 -0700 Subject: [PATCH 3/5] CRM-8597, CRM-20561 - Restore fix for `&` --- tools/scripts/composer/net-smtp-fix.sh | 3 +++ .../composer/patches/net-smtp-ref-patch.txt | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tools/scripts/composer/patches/net-smtp-ref-patch.txt diff --git a/tools/scripts/composer/net-smtp-fix.sh b/tools/scripts/composer/net-smtp-fix.sh index 87721739d956..c01f908adec0 100755 --- a/tools/scripts/composer/net-smtp-fix.sh +++ b/tools/scripts/composer/net-smtp-fix.sh @@ -21,3 +21,6 @@ fi if ! grep -q 'function __construct' vendor/pear/net_smtp/Net/SMTP.php; then patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-php7-patch.txt fi +if grep -q '&Auth_SASL::factory' vendor/pear/net_smtp/Net/SMTP.php; then +patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-ref-patch.txt +fi \ No newline at end of file diff --git a/tools/scripts/composer/patches/net-smtp-ref-patch.txt b/tools/scripts/composer/patches/net-smtp-ref-patch.txt new file mode 100644 index 000000000000..84f080d19eea --- /dev/null +++ b/tools/scripts/composer/patches/net-smtp-ref-patch.txt @@ -0,0 +1,22 @@ +--- SMTP.php 2017-06-15 20:08:34.696988543 -0700 ++++ SMTP.php.new 2017-06-15 20:08:25.951703778 -0700 +@@ -732,7 +732,8 @@ + } + + $challenge = base64_decode($this->_arguments[0]); +- $digest = &Auth_SASL::factory('digest-md5'); ++ // CRM-8597 ++ $digest = Auth_SASL::factory('digest-md5'); + $auth_str = base64_encode($digest->getResponse($uid, $pwd, $challenge, + $this->host, "smtp", + $authz)); +@@ -784,7 +785,8 @@ + } + + $challenge = base64_decode($this->_arguments[0]); +- $cram = &Auth_SASL::factory('cram-md5'); ++ // CRM-8597 ++ $cram = Auth_SASL::factory('cram-md5'); + $auth_str = base64_encode($cram->getResponse($uid, $pwd, $challenge)); + + if (PEAR::isError($error = $this->_put($auth_str))) { From ced6fbcb37bc7a1880991d744dad4e8aac687765 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Jun 2017 21:03:18 -0700 Subject: [PATCH 4/5] CRM-20561 - Net_SMTP - Remove example files --- tools/scripts/composer/net-smtp-fix.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/scripts/composer/net-smtp-fix.sh b/tools/scripts/composer/net-smtp-fix.sh index c01f908adec0..71dd98b8ed58 100755 --- a/tools/scripts/composer/net-smtp-fix.sh +++ b/tools/scripts/composer/net-smtp-fix.sh @@ -11,6 +11,20 @@ ## Replace a line in a file ## This is a bit like 'sed -i', but dumber and more cross-platform. +############################################################################## +## usage: safe_delete +function safe_delete() { + for file in "$@" ; do + if [ -z "$file" ]; then + echo "Skip: empty file name" + elif [ -e "$file" ]; then + rm -rf "$file" + fi + done +} + + +############################################################################## # Add in CiviCRM custom error message for CRM-8744. if ! grep -q 'CRM-8744' vendor/pear/net_smtp/Net/SMTP.php; then patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-patch.txt @@ -23,4 +37,6 @@ patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smt fi if grep -q '&Auth_SASL::factory' vendor/pear/net_smtp/Net/SMTP.php; then patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-ref-patch.txt -fi \ No newline at end of file +fi + +safe_delete vendor/pear/net_smtp/{examples,phpdoc.sh,tests} From 23e72ac4d5f6b16e197922bc0662362e8845a31f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Jun 2017 21:03:44 -0700 Subject: [PATCH 5/5] CRM-20561 - net-smtp-fix.sh - Cleanup code style --- tools/scripts/composer/net-smtp-fix.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/scripts/composer/net-smtp-fix.sh b/tools/scripts/composer/net-smtp-fix.sh index 71dd98b8ed58..7e4b688315c2 100755 --- a/tools/scripts/composer/net-smtp-fix.sh +++ b/tools/scripts/composer/net-smtp-fix.sh @@ -27,16 +27,16 @@ function safe_delete() { ############################################################################## # Add in CiviCRM custom error message for CRM-8744. if ! grep -q 'CRM-8744' vendor/pear/net_smtp/Net/SMTP.php; then -patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-patch.txt + patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-patch.txt fi if ! grep -q '@STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT' vendor/pear/net_smtp/Net/SMTP.php; then -patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-tls-patch.txt + patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-tls-patch.txt fi if ! grep -q 'function __construct' vendor/pear/net_smtp/Net/SMTP.php; then -patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-php7-patch.txt + patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-php7-patch.txt fi if grep -q '&Auth_SASL::factory' vendor/pear/net_smtp/Net/SMTP.php; then -patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-ref-patch.txt + patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-ref-patch.txt fi safe_delete vendor/pear/net_smtp/{examples,phpdoc.sh,tests}