From 0e5055bf5b513df03b0f9ac8bd2810ffe72ed744 Mon Sep 17 00:00:00 2001 From: yehudah Date: Tue, 17 Oct 2017 19:09:18 +0000 Subject: = 1.7.6 - 2017-10-17 * Missing sendgrid files * Fixed: Localization slug * Fixed: Error sending files with sendgrid --- .../PostmanConnectivityTestController.php | 296 ++++++++++----------- 1 file changed, 146 insertions(+), 150 deletions(-) (limited to 'Postman/Postman-Connectivity-Test/PostmanConnectivityTestController.php') diff --git a/Postman/Postman-Connectivity-Test/PostmanConnectivityTestController.php b/Postman/Postman-Connectivity-Test/PostmanConnectivityTestController.php index 3c1a23f..069c414 100644 --- a/Postman/Postman-Connectivity-Test/PostmanConnectivityTestController.php +++ b/Postman/Postman-Connectivity-Test/PostmanConnectivityTestController.php @@ -1,45 +1,43 @@ logger = new PostmanLogger ( get_class ( $this ) ); + public function __construct( $rootPluginFilenameAndPath ) { + assert( ! empty( $rootPluginFilenameAndPath ) ); + assert( PostmanUtils::isAdmin() ); + assert( is_admin() ); + + $this->logger = new PostmanLogger( get_class( $this ) ); $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath; - - PostmanUtils::registerAdminMenu ( $this, 'addPortTestSubmenu' ); - + + PostmanUtils::registerAdminMenu( $this, 'addPortTestSubmenu' ); + // hook on the init event - add_action ( 'init', array ( + add_action( 'init', array( $this, - 'on_init' + 'on_init', ) ); - + // initialize the scripts, stylesheets and form fields - add_action ( 'admin_init', array ( + add_action( 'admin_init', array( $this, - 'on_admin_init' + 'on_admin_init', ) ); } - + /** * Functions to execute on the init event * @@ -48,133 +46,132 @@ class PostmanConnectivityTestController { */ public function on_init() { // register Ajax handlers - new PostmanPortTestAjaxController (); + new PostmanPortTestAjaxController(); } - + /** * Fires on the admin_init method */ public function on_admin_init() { - // - $this->registerStylesAndScripts (); + $this->registerStylesAndScripts(); } - + /** * Register and add settings */ private function registerStylesAndScripts() { - if ($this->logger->isTrace ()) { - $this->logger->trace ( 'registerStylesAndScripts()' ); + if ( $this->logger->isTrace() ) { + $this->logger->trace( 'registerStylesAndScripts()' ); } // register the stylesheet and javascript external resources - $pluginData = apply_filters ( 'postman_get_plugin_metadata', null ); - wp_register_script ( 'postman_port_test_script', plugins_url ( 'Postman/Postman-Connectivity-Test/postman_port_test.js', $this->rootPluginFilenameAndPath ), array ( + $pluginData = apply_filters( 'postman_get_plugin_metadata', null ); + wp_register_script( 'postman_port_test_script', plugins_url( 'Postman/Postman-Connectivity-Test/postman_port_test.js', $this->rootPluginFilenameAndPath ), array( PostmanViewController::JQUERY_SCRIPT, 'jquery_validation', PostmanViewController::POSTMAN_SCRIPT, - 'sprintf' + 'sprintf', ), $pluginData ['version'] ); } - + /** * Register the Email Test screen */ public function addPortTestSubmenu() { - $page = add_submenu_page ( null, sprintf ( __ ( '%s Setup', Postman::TEXT_DOMAIN ), __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ) ), __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ), Postman::MANAGE_POSTMAN_CAPABILITY_NAME, PostmanConnectivityTestController::PORT_TEST_SLUG, array ( + $page = add_submenu_page( null, sprintf( __( '%s Setup', Postman::TEXT_DOMAIN ), __( 'Postman SMTP', Postman::TEXT_DOMAIN ) ), __( 'Postman SMTP', Postman::TEXT_DOMAIN ), Postman::MANAGE_POSTMAN_CAPABILITY_NAME, PostmanConnectivityTestController::PORT_TEST_SLUG, array( $this, - 'outputPortTestContent' + 'outputPortTestContent', ) ); // When the plugin options page is loaded, also load the stylesheet - add_action ( 'admin_print_styles-' . $page, array ( + add_action( 'admin_print_styles-' . $page, array( $this, - 'enqueuePortTestResources' + 'enqueuePortTestResources', ) ); } - + /** */ function enqueuePortTestResources() { - wp_enqueue_style ( PostmanViewController::POSTMAN_STYLE ); - wp_enqueue_script ( 'postman_port_test_script' ); - $warning = __ ( 'Warning', Postman::TEXT_DOMAIN ); - wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_hostname_element_name', '#input_' . PostmanOptions::HOSTNAME ); - PostmanConnectivityTestController::addLocalizeScriptForPortTest (); + wp_enqueue_style( PostmanViewController::POSTMAN_STYLE ); + wp_enqueue_script( 'postman_port_test_script' ); + $warning = __( 'Warning', Postman::TEXT_DOMAIN ); + wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_hostname_element_name', '#input_' . PostmanOptions::HOSTNAME ); + PostmanConnectivityTestController::addLocalizeScriptForPortTest(); } static function addLocalizeScriptForPortTest() { - wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_port_test', array ( - 'in_progress' => _x ( 'Checking..', 'The "please wait" message', Postman::TEXT_DOMAIN ), - 'open' => _x ( 'Open', 'The port is open', Postman::TEXT_DOMAIN ), - 'closed' => _x ( 'Closed', 'The port is closed', Postman::TEXT_DOMAIN ), - 'yes' => __ ( 'Yes', Postman::TEXT_DOMAIN ), - 'no' => __ ( 'No', Postman::TEXT_DOMAIN ), - /* translators: where %d is a port number */ - 'blocked' => __ ( 'No outbound route between this site and the Internet on Port %d.', Postman::TEXT_DOMAIN ), - /* translators: where %d is a port number and %s is a hostname */ - 'try_dif_smtp' => __ ( 'Port %d is open, but not to %s.', Postman::TEXT_DOMAIN ), - /* translators: where %d is the port number and %s is the hostname */ - 'success' => __ ( 'Port %d can be used for SMTP to %s.', Postman::TEXT_DOMAIN ), - 'mitm' => sprintf ( '%s: %s', __ ( 'Warning', Postman::TEXT_DOMAIN ), __ ( 'connected to %1$s instead of %2$s.', Postman::TEXT_DOMAIN ) ), - /* translators: where %d is a port number and %s is the URL for the Postman Gmail Extension */ - 'https_success' => __ ( 'Port %d can be used with the %s.', Postman::TEXT_DOMAIN ) + wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_port_test', array( + 'in_progress' => _x( 'Checking..', 'The "please wait" message', Postman::TEXT_DOMAIN ), + 'open' => _x( 'Open', 'The port is open', Postman::TEXT_DOMAIN ), + 'closed' => _x( 'Closed', 'The port is closed', Postman::TEXT_DOMAIN ), + 'yes' => __( 'Yes', Postman::TEXT_DOMAIN ), + 'no' => __( 'No', Postman::TEXT_DOMAIN ), + /* translators: where %d is a port number */ + 'blocked' => __( 'No outbound route between this site and the Internet on Port %d.', Postman::TEXT_DOMAIN ), + /* translators: where %d is a port number and %s is a hostname */ + 'try_dif_smtp' => __( 'Port %d is open, but not to %s.', Postman::TEXT_DOMAIN ), + /* translators: where %d is the port number and %s is the hostname */ + 'success' => __( 'Port %d can be used for SMTP to %s.', Postman::TEXT_DOMAIN ), + 'mitm' => sprintf( '%s: %s', __( 'Warning', Postman::TEXT_DOMAIN ), __( 'connected to %1$s instead of %2$s.', Postman::TEXT_DOMAIN ) ), + /* translators: where %d is a port number and %s is the URL for the Postman Gmail Extension */ + 'https_success' => __( 'Port %d can be used with the %s.', Postman::TEXT_DOMAIN ), ) ); } - + /** * Get the settings option array and print one of its values */ public function port_test_hostname_callback() { - $hostname = PostmanTransportRegistry::getInstance ()->getSelectedTransport ()->getHostname (); - if (empty ( $hostname )) { - $hostname = PostmanTransportRegistry::getInstance ()->getActiveTransport ()->getHostname (); + $hostname = PostmanTransportRegistry::getInstance()->getSelectedTransport()->getHostname(); + if ( empty( $hostname ) ) { + $hostname = PostmanTransportRegistry::getInstance()->getActiveTransport()->getHostname(); } - printf ( '', $hostname ); + printf( '', $hostname ); } - + /** */ public function outputPortTestContent() { print '
'; - - PostmanViewController::outputChildPageHeader ( __ ( 'Connectivity Test', Postman::TEXT_DOMAIN ) ); - + + PostmanViewController::outputChildPageHeader( __( 'Connectivity Test', Postman::TEXT_DOMAIN ) ); + print '

'; - print __ ( 'This test determines which well-known ports are available for Postman to use.', Postman::TEXT_DOMAIN ); + print __( 'This test determines which well-known ports are available for Postman to use.', Postman::TEXT_DOMAIN ); print '

'; - printf ( '', __ ( 'Outgoing Mail Server Hostname', Postman::TEXT_DOMAIN ) ); - $this->port_test_hostname_callback (); - submit_button ( _x ( 'Begin Test', 'Button Label', Postman::TEXT_DOMAIN ), 'primary', 'begin-port-test', true ); + printf( '', __( 'Outgoing Mail Server Hostname', Postman::TEXT_DOMAIN ) ); + $this->port_test_hostname_callback(); + submit_button( _x( 'Begin Test', 'Button Label', Postman::TEXT_DOMAIN ), 'primary', 'begin-port-test', true ); print '
'; print ''; - print sprintf ( '', __ ( 'Transport', Postman::TEXT_DOMAIN ), _x ( 'Socket', 'A socket is the network term for host and port together', Postman::TEXT_DOMAIN ), __ ( 'Status', Postman::TEXT_DOMAIN ) . '*', __ ( 'Service Available', Postman::TEXT_DOMAIN ), __ ( 'Server ID', Postman::TEXT_DOMAIN ), __ ( 'Authentication', Postman::TEXT_DOMAIN ) ); - print sprintf ( '', 'None', 'Login', 'Plain', 'CRAM-MD5', 'OAuth 2.0' ); - $sockets = PostmanTransportRegistry::getInstance ()->getSocketsForSetupWizardToProbe (); + print sprintf( '', __( 'Transport', Postman::TEXT_DOMAIN ), _x( 'Socket', 'A socket is the network term for host and port together', Postman::TEXT_DOMAIN ), __( 'Status', Postman::TEXT_DOMAIN ) . '*', __( 'Service Available', Postman::TEXT_DOMAIN ), __( 'Server ID', Postman::TEXT_DOMAIN ), __( 'Authentication', Postman::TEXT_DOMAIN ) ); + print sprintf( '', 'None', 'Login', 'Plain', 'CRAM-MD5', 'OAuth 2.0' ); + $sockets = PostmanTransportRegistry::getInstance()->getSocketsForSetupWizardToProbe(); foreach ( $sockets as $socket ) { - if ($socket ['smtp']) { - print sprintf ( '', $socket ['id'], $socket ['transport_name'], $socket ['host'], $socket ['port'] ); + if ( $socket ['smtp'] ) { + print sprintf( '', $socket ['id'], $socket ['transport_name'], $socket ['host'], $socket ['port'] ); } else { - print sprintf ( '', $socket ['id'], $socket ['transport_name'], $socket ['host'], $socket ['port'], __ ( 'n/a', Postman::TEXT_DOMAIN ) ); + print sprintf( '', $socket ['id'], $socket ['transport_name'], $socket ['host'], $socket ['port'], __( 'n/a', Postman::TEXT_DOMAIN ) ); } } print '
%s%s%s%s%s%s
%s%s%s%s%s
%s%s%s%s%s%s
%s%s%s%s%s
%s%s:%s-------
%s%s:%s-------
%s%s:%s---%s
%s%s:%s---%s
'; /* Translators: Where %s is the name of the service providing Internet connectivity test */ - printf ( '', sprintf ( __ ( 'According to %s', Postman::TEXT_DOMAIN ), 'portquiz.net' ) ); - printf ( '', plugins_url ( 'postman-smtp/style/ajax-loader.gif' ) ); + printf( '', sprintf( __( 'According to %s', Postman::TEXT_DOMAIN ), 'portquiz.net' ) ); + printf( '', plugins_url( 'post-smtp/style/ajax-loader.gif' ) ); print ''; print ''; print '
'; } @@ -183,25 +180,24 @@ class PostmanConnectivityTestController { /** * * @author jasonhendriks - * */ class PostmanPortTestAjaxController { private $logger; /** * Constructor * - * @param PostmanOptions $options + * @param PostmanOptions $options */ function __construct() { - $this->logger = new PostmanLogger ( get_class ( $this ) ); - PostmanUtils::registerAjaxHandler ( 'postman_get_hosts_to_test', $this, 'getPortsToTestViaAjax' ); - PostmanUtils::registerAjaxHandler ( 'postman_wizard_port_test', $this, 'runSmtpTest' ); - PostmanUtils::registerAjaxHandler ( 'postman_wizard_port_test_smtps', $this, 'runSmtpsTest' ); - PostmanUtils::registerAjaxHandler ( 'postman_port_quiz_test', $this, 'runPortQuizTest' ); - PostmanUtils::registerAjaxHandler ( 'postman_test_port', $this, 'runSmtpTest' ); - PostmanUtils::registerAjaxHandler ( 'postman_test_smtps', $this, 'runSmtpsTest' ); + $this->logger = new PostmanLogger( get_class( $this ) ); + PostmanUtils::registerAjaxHandler( 'postman_get_hosts_to_test', $this, 'getPortsToTestViaAjax' ); + PostmanUtils::registerAjaxHandler( 'postman_wizard_port_test', $this, 'runSmtpTest' ); + PostmanUtils::registerAjaxHandler( 'postman_wizard_port_test_smtps', $this, 'runSmtpsTest' ); + PostmanUtils::registerAjaxHandler( 'postman_port_quiz_test', $this, 'runPortQuizTest' ); + PostmanUtils::registerAjaxHandler( 'postman_test_port', $this, 'runSmtpTest' ); + PostmanUtils::registerAjaxHandler( 'postman_test_smtps', $this, 'runSmtpsTest' ); } - + /** * This Ajax function determines which hosts/ports to test in both the Wizard Connectivity Test and direct Connectivity Test * @@ -209,79 +205,79 @@ class PostmanPortTestAjaxController { * combinations to run the connectivity test on */ function getPortsToTestViaAjax() { - $queryHostname = PostmanUtils::getRequestParameter ( 'hostname' ); + $queryHostname = PostmanUtils::getRequestParameter( 'hostname' ); // originalSmtpServer is what SmtpDiscovery thinks the SMTP server should be, given an email address - $originalSmtpServer = PostmanUtils::getRequestParameter ( 'original_smtp_server' ); - if ($this->logger->isDebug ()) { - $this->logger->debug ( 'Probing available transports for sockets against hostname ' . $queryHostname ); + $originalSmtpServer = PostmanUtils::getRequestParameter( 'original_smtp_server' ); + if ( $this->logger->isDebug() ) { + $this->logger->debug( 'Probing available transports for sockets against hostname ' . $queryHostname ); } - $sockets = PostmanTransportRegistry::getInstance ()->getSocketsForSetupWizardToProbe ( $queryHostname, $originalSmtpServer ); - $response = array ( - 'hosts' => $sockets + $sockets = PostmanTransportRegistry::getInstance()->getSocketsForSetupWizardToProbe( $queryHostname, $originalSmtpServer ); + $response = array( + 'hosts' => $sockets, ); - wp_send_json_success ( $response ); + wp_send_json_success( $response ); } - + /** * This Ajax function retrieves whether a TCP port is open or not */ function runPortQuizTest() { $hostname = 'portquiz.net'; - $port = intval ( PostmanUtils::getRequestParameter ( 'port' ) ); - $this->logger->debug ( 'testing TCP port: hostname ' . $hostname . ' port ' . $port ); - $portTest = new PostmanPortTest ( $hostname, $port ); - $success = $portTest->genericConnectionTest (); - $this->buildResponse ( $hostname, $port, $portTest, $success ); + $port = intval( PostmanUtils::getRequestParameter( 'port' ) ); + $this->logger->debug( 'testing TCP port: hostname ' . $hostname . ' port ' . $port ); + $portTest = new PostmanPortTest( $hostname, $port ); + $success = $portTest->genericConnectionTest(); + $this->buildResponse( $hostname, $port, $portTest, $success ); } - + /** * This Ajax function retrieves whether a TCP port is open or not. * This is called by both the Wizard and Port Test */ function runSmtpTest() { - $hostname = trim ( PostmanUtils::getRequestParameter ( 'hostname' ) ); - $port = intval ( PostmanUtils::getRequestParameter ( 'port' ) ); - $transport = trim ( PostmanUtils::getRequestParameter ( 'transport' ) ); - $timeout = PostmanUtils::getRequestParameter ( 'timeout' ); - $this->logger->trace ( $timeout ); - $portTest = new PostmanPortTest ( $hostname, $port ); - if (isset ( $timeout )) { - $portTest->setConnectionTimeout ( intval ( $timeout ) ); - $portTest->setReadTimeout ( intval ( $timeout ) ); + $hostname = trim( PostmanUtils::getRequestParameter( 'hostname' ) ); + $port = intval( PostmanUtils::getRequestParameter( 'port' ) ); + $transport = trim( PostmanUtils::getRequestParameter( 'transport' ) ); + $timeout = PostmanUtils::getRequestParameter( 'timeout' ); + $this->logger->trace( $timeout ); + $portTest = new PostmanPortTest( $hostname, $port ); + if ( isset( $timeout ) ) { + $portTest->setConnectionTimeout( intval( $timeout ) ); + $portTest->setReadTimeout( intval( $timeout ) ); } - if ($port != 443) { - $this->logger->debug ( sprintf ( 'testing SMTP socket %s:%s (%s)', $hostname, $port, $transport ) ); - $success = $portTest->testSmtpPorts (); + if ( $port != 443 ) { + $this->logger->debug( sprintf( 'testing SMTP socket %s:%s (%s)', $hostname, $port, $transport ) ); + $success = $portTest->testSmtpPorts(); } else { - $this->logger->debug ( sprintf ( 'testing HTTPS socket %s:%s (%s)', $hostname, $port, $transport ) ); - $success = $portTest->testHttpPorts (); + $this->logger->debug( sprintf( 'testing HTTPS socket %s:%s (%s)', $hostname, $port, $transport ) ); + $success = $portTest->testHttpPorts(); } - $this->buildResponse ( $hostname, $port, $portTest, $success, $transport ); + $this->buildResponse( $hostname, $port, $portTest, $success, $transport ); } /** * This Ajax function retrieves whether a TCP port is open or not */ function runSmtpsTest() { - $hostname = trim ( PostmanUtils::getRequestParameter ( 'hostname' ) ); - $port = intval ( PostmanUtils::getRequestParameter ( 'port' ) ); - $transport = trim ( PostmanUtils::getRequestParameter ( 'transport' ) ); - $transportName = trim ( PostmanUtils::getRequestParameter ( 'transport_name' ) ); - $this->logger->debug ( sprintf ( 'testing SMTPS socket %s:%s (%s)', $hostname, $port, $transport ) ); - $portTest = new PostmanPortTest ( $hostname, $port ); + $hostname = trim( PostmanUtils::getRequestParameter( 'hostname' ) ); + $port = intval( PostmanUtils::getRequestParameter( 'port' ) ); + $transport = trim( PostmanUtils::getRequestParameter( 'transport' ) ); + $transportName = trim( PostmanUtils::getRequestParameter( 'transport_name' ) ); + $this->logger->debug( sprintf( 'testing SMTPS socket %s:%s (%s)', $hostname, $port, $transport ) ); + $portTest = new PostmanPortTest( $hostname, $port ); $portTest->transportName = $transportName; - $success = $portTest->testSmtpsPorts (); - $this->buildResponse ( $hostname, $port, $portTest, $success, $transport ); + $success = $portTest->testSmtpsPorts(); + $this->buildResponse( $hostname, $port, $portTest, $success, $transport ); } - + /** * - * @param unknown $hostname - * @param unknown $port - * @param unknown $success + * @param unknown $hostname + * @param unknown $port + * @param unknown $success */ - private function buildResponse($hostname, $port, PostmanPortTest $portTest, $success, $transport = '') { - $this->logger->debug ( sprintf ( 'testing port result for %s:%s success=%s', $hostname, $port, $success ) ); - $response = array ( + private function buildResponse( $hostname, $port, PostmanPortTest $portTest, $success, $transport = '' ) { + $this->logger->debug( sprintf( 'testing port result for %s:%s success=%s', $hostname, $port, $success ) ); + $response = array( 'hostname' => $hostname, 'hostname_domain_only' => $portTest->hostnameDomainOnly, 'port' => $port, @@ -290,7 +286,7 @@ class PostmanPortTestAjaxController { 'mitm' => ($portTest->mitm), 'reported_hostname' => $portTest->reportedHostname, 'reported_hostname_domain_only' => $portTest->reportedHostnameDomainOnly, - 'message' => $portTest->getErrorMessage (), + 'message' => $portTest->getErrorMessage(), 'start_tls' => $portTest->startTls, 'auth_plain' => $portTest->authPlain, 'auth_login' => $portTest->authLogin, @@ -299,14 +295,14 @@ class PostmanPortTestAjaxController { 'auth_none' => $portTest->authNone, 'try_smtps' => $portTest->trySmtps, 'success' => $success, - 'transport' => $transport + 'transport' => $transport, ); - $this->logger->trace ( 'Ajax response:' ); - $this->logger->trace ( $response ); - if ($success) { - wp_send_json_success ( $response ); + $this->logger->trace( 'Ajax response:' ); + $this->logger->trace( $response ); + if ( $success ) { + wp_send_json_success( $response ); } else { - wp_send_json_error ( $response ); + wp_send_json_error( $response ); } } } -- cgit v1.2.3