postman_begin_test_button_id = 'input#begin-port-test'; jQuery(document).ready(function() { var elHostname = jQuery(postman_begin_test_button_id); jQuery(postman_hostname_element_name).focus(); elHostname.click(function() { valid = jQuery('#port_test_form_id').valid(); if (!valid) { return false; } // initialize the view for a new test elHostname.attr('disabled', 'disabled'); hide('#conclusion'); hide('#blocked-port-help'); jQuery('ol.conclusion').html(''); showLoaderIcon(); var $elTestingTable = jQuery('#connectivity_test_table'); $elTestingTable.show(); show('.portquiz'); var hostname = jQuery(postman_hostname_element_name).val(); var data = { 'action' : 'postman_get_hosts_to_test', 'hostname' : hostname }; totalPortsTested = 0; portsToBeTested = 0; jQuery.post(ajaxurl, data, function(response) { if (postmanValidateAjaxResponseWithPopup(response)) { handleHostsToCheckResponse(response.data); } }).fail(function(response) { ajaxFailed(response); }); // return false; }); }); /** * Handles the response from the server of the list of sockets to check. * * @param hostname * @param response */ function handleHostsToCheckResponse(response) { for ( var x in response.hosts) { var id = response.hosts[x].id; var transportSlug = response.hosts[x].transport_id; var hostname = response.hosts[x].host; var port = response.hosts[x].port var cell = 'tr#' + id + " td.socket"; var testEl = jQuery(cell); testEl.html('' + hostname + ':' + port + ''); portQuizTest(response.hosts[x], hostname, port); } } function portQuizTest(socket, hostname, port) { resetView(socket.id); portsToBeTested += 1; var cell = 'tr#' + socket.id + " td.firewall"; var testEl = jQuery(cell); testEl.html('' + postman_port_test.in_progress + ''); var data = { 'action' : 'postman_port_quiz_test', 'hostname' : hostname, 'port' : port }; jQuery.post( ajaxurl, data, function(response) { if (postmanValidateAjaxResponseWithPopup(response)) { if (response.success) { testEl.html('' + postman_port_test.open + ''); // start the next test } else { testEl.html('' + postman_port_test.closed + ''); } firstServiceTest(socket, hostname, port, response.success); } }).fail( function(response) { totalPortsTested += 1; testEl.html('' + postman_email_test.ajax_error + ""); enableButtonCheck(); }); } function firstServiceTest(socket, hostname, port, open) { var cell = 'tr#' + socket.id + " td.service"; var testEl = jQuery(cell); testEl.html('' + postman_port_test.in_progress + ''); var data = { 'action' : 'postman_test_port', 'hostname' : hostname, 'port' : port }; jQuery .post( ajaxurl, data, function(response) { if (postmanValidateAjaxResponseWithPopup(response)) { if (response.success) { totalPortsTested += 1; if (port == 443) { // API test testEl .html('🔒 ' + response.data.protocol + ''); var cell = 'tr#' + socket.id + " td.reported_id"; var p443El = jQuery(cell); if (response.data.reported_hostname_domain_only) { p443El .html('' + response.data.reported_hostname_domain_only + ''); } addConclusion(sprintf( postman_port_test.https_success, response.data.port, socket.transport_name), true, response.data.secure); } else { // SMTP test testEl.html('' + response.data.protocol + ''); inspectResponse(socket.id, response.data, port); var message = sprintf(postman_port_test.success, port, hostname); if (response.data.mitm) { message += ' ' + sprintf( postman_port_test.mitm, response.data.reported_hostname_domain_only, response.data.hostname_domain_only) + ''; } addConclusion(message, true, response.data.secure); } } else { if (port == 443) { // API test testEl.html('' + postman_port_test.no + ''); totalPortsTested += 1; var p443El = jQuery(cell); addConclusion(sprintf(postman_port_test.try_dif_smtp, port, hostname), false, response.data.secure); } else { if (response.data.try_smtps) { // start the SMTPS test portTest3(socket, hostname, port, open); } else { testEl.html('' + postman_port_test.no + ''); totalPortsTested += 1; addConclusion(sprintf( postman_port_test.blocked, port), false, response.data.secure); show('#blocked-port-help'); } } } enableButtonCheck(); } }).fail( function(response) { totalPortsTested += 1; testEl.html('' + postman_email_test.ajax_error + ""); enableButtonCheck(); }); } function portTest3(socket, hostname, port, open) { var cell = 'tr#' + socket.id + " td.service"; var testEl = jQuery(cell); testEl.html('' + postman_port_test.in_progress + ''); var data = { 'action' : 'postman_test_smtps', 'hostname' : hostname, 'port' : port }; jQuery .post( ajaxurl, data, function(response) { if (postmanValidateAjaxResponseWithPopup(response)) { if (response.success) { if (response.data.protocol == 'SMTPS') { testEl .html('🔒 ' + response.data.protocol + ''); } else { testEl.html('' + response.data.protocol + ''); } inspectResponse(socket.id, response.data, port); var message = sprintf(postman_port_test.success, port, hostname); if (response.data.mitm) { message += ' ' + sprintf( postman_port_test.mitm, response.data.reported_hostname_domain_only, response.data.hostname_domain_only + ''); } addConclusion(message, true, response.data.secure); } else { testEl.html('' + postman_port_test.no + ''); show('#blocked-port-help'); if (open) { addConclusion(sprintf(postman_port_test.try_dif_smtp, port, hostname), false, response.data.secure); } else { addConclusion(sprintf(postman_port_test.blocked, port), false, response.data.secure); } } totalPortsTested += 1; enableButtonCheck(); } }).fail( function(response) { totalPortsTested += 1; testEl.html('' + postman_email_test.ajax_error + ""); enableButtonCheck(); }); } function enableButtonCheck() { if (totalPortsTested >= portsToBeTested) { enable(postman_begin_test_button_id); hideLoaderIcon(); jQuery(postman_hostname_element_name).focus(); } } function inspectResponse(id, response, port) { var cell = 'tr#' + id + " td.reported_id"; var testEl = jQuery(cell); if (response.reported_hostname_domain_only) { testEl.html('' + response.reported_hostname_domain_only + ''); } var cell = 'tr#' + id + " td.service"; var testEl = jQuery(cell); if (response.protocol == 'SMTPS') { testEl.html('🔒 SMTPS'); } else if (response.start_tls) { testEl.html('🔒 SMTP-STARTTLS'); } else { testEl.html('SMTP'); } var cell = 'tr#' + id + " td.auth_none"; var testEl = jQuery(cell); if (response.auth_none) { testEl.html('' + postman_port_test.yes + ''); } else { testEl.html('' + postman_port_test.no + ''); } var cell = 'tr#' + id + " td.auth_plain"; var testEl = jQuery(cell); if (response.auth_plain) { testEl.html('' + postman_port_test.yes + ''); } else { testEl.html('' + postman_port_test.no + ''); } var cell = 'tr#' + id + " td.auth_login"; var testEl = jQuery(cell); if (response.auth_login) { testEl.html('' + postman_port_test.yes + ''); } else { testEl.html('' + postman_port_test.no + ''); } var cell = 'tr#' + id + " td.auth_crammd5"; var testEl = jQuery(cell); if (response.auth_crammd5) { testEl.html('' + postman_port_test.yes + ''); } else { testEl.html('' + postman_port_test.no + ''); } var cell = 'tr#' + id + " td.auth_xoauth2"; var testEl = jQuery(cell); if (response.auth_xoauth) { testEl.html('' + postman_port_test.yes + ''); } else { testEl.html('' + postman_port_test.no + ''); } } function resetView(id) { var testEl = jQuery('tr#' + id + ' td.resettable'); testEl.html('-'); } function addConclusion(message, success, isSecure) { show('#conclusion'); var secureIcon = ''; if (isSecure) { secureIcon = '🔒 '; } if (success) { message = '✅ ' + secureIcon + message; } else { message = '❌ ' + secureIcon + message; } jQuery('ol.conclusion').append('