Version Description
- 2017-10-17
- Fixed: Error sending files with sendgrid
- Fixed: Wrong attachments format in Mandrill
- Fixed: Wrong Sender Header in Mandrill
Download this release
Release Info
Developer | yehudah |
Plugin | ![]() |
Version | 1.7.7 |
Comparing to | |
See all releases |
Code changes from version 1.7.6 to 1.7.7
- Postman/Postman-Configuration/PostmanConfigurationController.php +345 -349
- Postman/Postman-Connectivity-Test/PostmanConnectivityTestController.php +146 -150
- Postman/Postman-Diagnostic-Test/PostmanDiagnosticTestController.php +133 -135
- Postman/Postman-Mail/PostmanMandrillMailEngine.php +134 -135
- Postman/Postman-Mail/PostmanMessage.php +216 -219
- Postman/Postman-Mail/PostmanSendGridMailEngine.php +110 -112
- Postman/Postman-Mail/PostmanSmtpModuleTransport.php +232 -233
- Postman/Postman-Mail/PostmanZendMailEngine.php +120 -122
- Postman/Postman-Mail/sendgrid-php-3.2.0/lib/SendGrid/Email.php +617 -672
- Postman/Postman-Send-Test-Email/PostmanSendTestEmailController.php +144 -148
- Postman/Postman.php +1 -1
- Postman/PostmanConfigTextHelper.php +62 -62
- Postman/PostmanOptions.php +144 -157
- Postman/PostmanViewController.php +146 -148
- Postman/PostmanWpMail.php +175 -176
- postman-smtp.php +2 -2
- readme.txt +15 -1
Postman/Postman-Configuration/PostmanConfigurationController.php
CHANGED
@@ -1,48 +1,48 @@
|
|
1 |
<?php
|
2 |
-
require_once
|
3 |
class PostmanConfigurationController {
|
4 |
const CONFIGURATION_SLUG = 'postman/configuration';
|
5 |
const CONFIGURATION_WIZARD_SLUG = 'postman/configuration_wizard';
|
6 |
-
|
7 |
// logging
|
8 |
private $logger;
|
9 |
private $options;
|
10 |
private $settingsRegistry;
|
11 |
-
|
12 |
// Holds the values to be used in the fields callbacks
|
13 |
private $rootPluginFilenameAndPath;
|
14 |
-
|
15 |
/**
|
16 |
* Constructor
|
17 |
*
|
18 |
-
* @param unknown $rootPluginFilenameAndPath
|
19 |
*/
|
20 |
-
public function __construct($rootPluginFilenameAndPath) {
|
21 |
-
assert
|
22 |
-
assert
|
23 |
-
assert
|
24 |
-
|
25 |
-
$this->logger = new PostmanLogger
|
26 |
$this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
|
27 |
-
$this->options = PostmanOptions::getInstance
|
28 |
-
$this->settingsRegistry = new PostmanSettingsRegistry
|
29 |
-
|
30 |
-
PostmanUtils::registerAdminMenu
|
31 |
-
PostmanUtils::registerAdminMenu
|
32 |
-
|
33 |
// hook on the init event
|
34 |
-
add_action
|
35 |
$this,
|
36 |
-
'on_init'
|
37 |
) );
|
38 |
-
|
39 |
// initialize the scripts, stylesheets and form fields
|
40 |
-
add_action
|
41 |
$this,
|
42 |
-
'on_admin_init'
|
43 |
) );
|
44 |
}
|
45 |
-
|
46 |
/**
|
47 |
* Functions to execute on the init event
|
48 |
*
|
@@ -51,189 +51,187 @@ class PostmanConfigurationController {
|
|
51 |
*/
|
52 |
public function on_init() {
|
53 |
// register Ajax handlers
|
54 |
-
new PostmanGetHostnameByEmailAjaxController
|
55 |
-
new PostmanManageConfigurationAjaxHandler
|
56 |
-
new PostmanImportConfigurationAjaxController
|
57 |
}
|
58 |
-
|
59 |
/**
|
60 |
* Fires on the admin_init method
|
61 |
*/
|
62 |
public function on_admin_init() {
|
63 |
-
|
64 |
-
$this->
|
65 |
-
$this->settingsRegistry->on_admin_init ();
|
66 |
}
|
67 |
-
|
68 |
/**
|
69 |
* Register and add settings
|
70 |
*/
|
71 |
private function registerStylesAndScripts() {
|
72 |
-
if ($this->logger->isTrace
|
73 |
-
$this->logger->trace
|
74 |
}
|
75 |
// register the stylesheet and javascript external resources
|
76 |
-
$pluginData = apply_filters
|
77 |
-
wp_register_script
|
78 |
PostmanViewController::JQUERY_SCRIPT,
|
79 |
'jquery_validation',
|
80 |
-
PostmanViewController::POSTMAN_SCRIPT
|
81 |
), $pluginData ['version'] );
|
82 |
-
wp_register_script
|
83 |
PostmanViewController::JQUERY_SCRIPT,
|
84 |
'jquery_validation',
|
85 |
'jquery_steps_script',
|
86 |
PostmanViewController::POSTMAN_SCRIPT,
|
87 |
-
'sprintf'
|
88 |
), $pluginData ['version'] );
|
89 |
}
|
90 |
-
|
91 |
/**
|
92 |
*/
|
93 |
private function addLocalizeScriptsToPage() {
|
94 |
-
$warning = __
|
95 |
/* translators: where %s is the name of the SMTP server */
|
96 |
-
wp_localize_script
|
97 |
/* translators: where %d is a port number */
|
98 |
-
wp_localize_script
|
99 |
-
|
100 |
// user input
|
101 |
-
wp_localize_script
|
102 |
-
wp_localize_script
|
103 |
-
wp_localize_script
|
104 |
-
wp_localize_script
|
105 |
-
|
106 |
// the enc input
|
107 |
-
wp_localize_script
|
108 |
// these are the ids for the <option>s in the encryption <select>
|
109 |
-
|
110 |
// the password inputs
|
111 |
-
wp_localize_script
|
112 |
-
wp_localize_script
|
113 |
-
|
114 |
// the auth input
|
115 |
-
wp_localize_script
|
116 |
-
wp_localize_script
|
117 |
-
|
118 |
// the transport modules scripts
|
119 |
-
foreach ( PostmanTransportRegistry::getInstance
|
120 |
-
$transport->enqueueScript
|
121 |
}
|
122 |
|
123 |
// we need data from port test
|
124 |
-
PostmanConnectivityTestController::addLocalizeScriptForPortTest
|
125 |
-
|
126 |
}
|
127 |
-
|
128 |
/**
|
129 |
* Register the Configuration screen
|
130 |
*/
|
131 |
public function addConfigurationSubmenu() {
|
132 |
-
$page = add_submenu_page
|
133 |
$this,
|
134 |
-
'outputManualConfigurationContent'
|
135 |
) );
|
136 |
// When the plugin options page is loaded, also load the stylesheet
|
137 |
-
add_action
|
138 |
$this,
|
139 |
-
'enqueueConfigurationResources'
|
140 |
) );
|
141 |
}
|
142 |
-
|
143 |
/**
|
144 |
*/
|
145 |
function enqueueConfigurationResources() {
|
146 |
-
$this->addLocalizeScriptsToPage
|
147 |
-
wp_enqueue_style
|
148 |
-
wp_enqueue_style
|
149 |
-
wp_enqueue_script
|
150 |
-
wp_enqueue_script
|
151 |
}
|
152 |
-
|
153 |
/**
|
154 |
* Register the Setup Wizard screen
|
155 |
*/
|
156 |
public function addSetupWizardSubmenu() {
|
157 |
-
$page = add_submenu_page
|
158 |
$this,
|
159 |
-
'outputWizardContent'
|
160 |
) );
|
161 |
// When the plugin options page is loaded, also load the stylesheet
|
162 |
-
add_action
|
163 |
$this,
|
164 |
-
'enqueueWizardResources'
|
165 |
) );
|
166 |
}
|
167 |
-
|
168 |
/**
|
169 |
*/
|
170 |
function enqueueWizardResources() {
|
171 |
-
$this->addLocalizeScriptsToPage
|
172 |
-
$this->importableConfiguration = new PostmanImportableConfiguration
|
173 |
$startPage = 1;
|
174 |
-
if ($this->importableConfiguration->isImportAvailable
|
175 |
$startPage = 0;
|
176 |
}
|
177 |
-
wp_localize_script
|
178 |
-
'start_page' => $startPage
|
179 |
) );
|
180 |
-
wp_enqueue_style
|
181 |
-
wp_enqueue_style
|
182 |
-
wp_enqueue_script
|
183 |
-
wp_localize_script
|
184 |
-
$shortLocale = substr
|
185 |
-
if ($shortLocale != 'en') {
|
186 |
-
$url = plugins_url
|
187 |
-
wp_enqueue_script
|
188 |
}
|
189 |
}
|
190 |
-
|
191 |
/**
|
192 |
*/
|
193 |
public function outputManualConfigurationContent() {
|
194 |
print '<div class="wrap">';
|
195 |
-
|
196 |
-
PostmanViewController::outputChildPageHeader
|
197 |
print '<div id="config_tabs"><ul>';
|
198 |
-
print sprintf
|
199 |
-
print sprintf
|
200 |
-
print sprintf
|
201 |
-
print sprintf
|
202 |
print '</ul>';
|
203 |
print '<form method="post" action="options.php">';
|
204 |
// This prints out all hidden setting fields
|
205 |
-
settings_fields
|
206 |
print '<section id="account_config">';
|
207 |
-
if (sizeof
|
208 |
-
do_settings_sections
|
209 |
} else {
|
210 |
-
printf
|
211 |
}
|
212 |
print '<div id="smtp_config" class="transport_setting">';
|
213 |
-
do_settings_sections
|
214 |
print '</div>';
|
215 |
print '<div id="password_settings" class="authentication_setting non-oauth2">';
|
216 |
-
do_settings_sections
|
217 |
print '</div>';
|
218 |
print '<div id="oauth_settings" class="authentication_setting non-basic">';
|
219 |
-
do_settings_sections
|
220 |
print '</div>';
|
221 |
print '<div id="mandrill_settings" class="authentication_setting non-basic non-oauth2">';
|
222 |
-
do_settings_sections
|
223 |
print '</div>';
|
224 |
print '<div id="sendgrid_settings" class="authentication_setting non-basic non-oauth2">';
|
225 |
-
do_settings_sections
|
226 |
print '</div>';
|
227 |
print '</section>';
|
228 |
print '<section id="message_config">';
|
229 |
-
do_settings_sections
|
230 |
-
do_settings_sections
|
231 |
-
do_settings_sections
|
232 |
-
do_settings_sections
|
233 |
-
do_settings_sections
|
234 |
print '</section>';
|
235 |
print '<section id="logging_config">';
|
236 |
-
do_settings_sections
|
237 |
print '</section>';
|
238 |
/*
|
239 |
* print '<section id="logging_config">';
|
@@ -241,133 +239,132 @@ class PostmanConfigurationController {
|
|
241 |
* print '</section>';
|
242 |
*/
|
243 |
print '<section id="advanced_options_config">';
|
244 |
-
do_settings_sections
|
245 |
-
do_settings_sections
|
246 |
print '</section>';
|
247 |
-
submit_button
|
248 |
print '</form>';
|
249 |
print '</div>';
|
250 |
print '</div>';
|
251 |
}
|
252 |
-
|
253 |
/**
|
254 |
*/
|
255 |
public function outputWizardContent() {
|
256 |
// Set default values for input fields
|
257 |
-
$this->options->setMessageSenderEmailIfEmpty
|
258 |
-
$this->options->setMessageSenderNameIfEmpty
|
259 |
-
|
260 |
// construct Wizard
|
261 |
print '<div class="wrap">';
|
262 |
-
|
263 |
-
PostmanViewController::outputChildPageHeader
|
264 |
-
|
265 |
print '<form id="postman_wizard" method="post" action="options.php">';
|
266 |
-
|
267 |
// account tab
|
268 |
-
|
269 |
// message tab
|
270 |
-
printf
|
271 |
-
printf
|
272 |
-
printf
|
273 |
-
printf
|
274 |
-
printf
|
275 |
-
printf
|
276 |
-
printf
|
277 |
-
printf
|
278 |
-
|
279 |
// logging tab
|
280 |
-
printf
|
281 |
-
printf
|
282 |
-
printf
|
283 |
-
|
284 |
// advanced tab
|
285 |
-
printf
|
286 |
-
printf
|
287 |
-
printf
|
288 |
-
printf
|
289 |
-
printf
|
290 |
-
printf
|
291 |
-
|
292 |
// display the setting text
|
293 |
-
settings_fields
|
294 |
-
|
295 |
// Wizard Step 0
|
296 |
-
printf
|
297 |
print '<fieldset>';
|
298 |
-
printf
|
299 |
-
printf
|
300 |
print '<table class="input_auth_type">';
|
301 |
-
printf
|
302 |
-
|
303 |
-
if ($this->importableConfiguration->isImportAvailable
|
304 |
-
foreach ( $this->importableConfiguration->getAvailableOptions
|
305 |
-
printf
|
306 |
}
|
307 |
}
|
308 |
print '</table>';
|
309 |
print '</fieldset>';
|
310 |
-
|
311 |
// Wizard Step 1
|
312 |
-
printf
|
313 |
print '<fieldset>';
|
314 |
-
printf
|
315 |
-
printf
|
316 |
-
printf
|
317 |
-
printf
|
318 |
-
print $this->settingsRegistry->from_email_callback
|
319 |
print '<br/>';
|
320 |
-
printf
|
321 |
-
print $this->settingsRegistry->sender_name_callback
|
322 |
print '</fieldset>';
|
323 |
-
|
324 |
// Wizard Step 2
|
325 |
-
printf
|
326 |
print '<fieldset>';
|
327 |
-
foreach ( PostmanTransportRegistry::getInstance
|
328 |
-
$transport->printWizardMailServerHostnameStep
|
329 |
}
|
330 |
print '</fieldset>';
|
331 |
-
|
332 |
// Wizard Step 3
|
333 |
-
printf
|
334 |
print '<fieldset>';
|
335 |
-
printf
|
336 |
-
printf
|
337 |
-
printf
|
338 |
-
printf
|
339 |
-
printf
|
340 |
-
printf
|
341 |
-
printf
|
342 |
-
printf
|
343 |
print '<p id="wizard_recommendation"></p>';
|
344 |
/* Translators: Where %1$s is the socket identifier and %2$s is the authentication type */
|
345 |
-
printf
|
346 |
-
printf
|
347 |
print ('<p><span id="smtp_mitm" style="display:none; background-color:yellow"></span></p>') ;
|
348 |
-
$warning = __
|
349 |
-
$clearCredentialsWarning = __
|
350 |
-
printf
|
351 |
print '</fieldset>';
|
352 |
-
|
353 |
// Wizard Step 4
|
354 |
-
printf
|
355 |
print '<fieldset>';
|
356 |
-
printf
|
357 |
-
foreach ( PostmanTransportRegistry::getInstance
|
358 |
-
$transport->printWizardAuthenticationStep
|
359 |
}
|
360 |
print '</fieldset>';
|
361 |
-
|
362 |
// Wizard Step 5
|
363 |
-
printf
|
364 |
print '<fieldset>';
|
365 |
-
printf
|
366 |
print '<section>';
|
367 |
-
printf
|
368 |
print '<ul style="margin-left: 20px">';
|
369 |
-
printf
|
370 |
-
printf
|
371 |
print '</ul>';
|
372 |
print '</section>';
|
373 |
print '</fieldset>';
|
@@ -379,188 +376,187 @@ class PostmanConfigurationController {
|
|
379 |
/**
|
380 |
*
|
381 |
* @author jasonhendriks
|
382 |
-
*
|
383 |
*/
|
384 |
class PostmanGetHostnameByEmailAjaxController extends PostmanAbstractAjaxHandler {
|
385 |
const IS_GOOGLE_PARAMETER = 'is_google';
|
386 |
function __construct() {
|
387 |
-
parent::__construct
|
388 |
-
PostmanUtils::registerAjaxHandler
|
389 |
}
|
390 |
/**
|
391 |
* This Ajax function retrieves the smtp hostname for a give e-mail address
|
392 |
*/
|
393 |
function getAjaxHostnameByEmail() {
|
394 |
-
$goDaddyHostDetected = $this->getBooleanRequestParameter
|
395 |
-
$email = $this->getRequestParameter
|
396 |
-
$d = new PostmanSmtpDiscovery
|
397 |
-
$smtp = $d->getSmtpServer
|
398 |
-
$this->logger->debug
|
399 |
-
$this->logger->trace
|
400 |
-
if ($goDaddyHostDetected && ! $d->isGoogle) {
|
401 |
// override with the GoDaddy SMTP server
|
402 |
$smtp = 'relay-hosting.secureserver.net';
|
403 |
-
$this->logger->debug
|
404 |
}
|
405 |
-
$response = array
|
406 |
'hostname' => $smtp,
|
407 |
self::IS_GOOGLE_PARAMETER => $d->isGoogle,
|
408 |
'is_go_daddy' => $d->isGoDaddy,
|
409 |
-
'is_well_known' => $d->isWellKnownDomain
|
410 |
);
|
411 |
-
$this->logger->trace
|
412 |
-
wp_send_json_success
|
413 |
}
|
414 |
}
|
415 |
class PostmanManageConfigurationAjaxHandler extends PostmanAbstractAjaxHandler {
|
416 |
function __construct() {
|
417 |
-
parent::__construct
|
418 |
-
PostmanUtils::registerAjaxHandler
|
419 |
-
PostmanUtils::registerAjaxHandler
|
420 |
}
|
421 |
-
|
422 |
/**
|
423 |
* Handle a Advanced Configuration request with Ajax
|
424 |
*
|
425 |
* @throws Exception
|
426 |
*/
|
427 |
function getManualConfigurationViaAjax() {
|
428 |
-
$queryTransportType = $this->getTransportTypeFromRequest
|
429 |
-
$queryAuthType = $this->getAuthenticationTypeFromRequest
|
430 |
-
$queryHostname = $this->getHostnameFromRequest
|
431 |
-
|
432 |
// the outgoing server hostname is only required for the SMTP Transport
|
433 |
// the Gmail API transport doesn't use an SMTP server
|
434 |
-
$transport = PostmanTransportRegistry::getInstance
|
435 |
-
if (! $transport) {
|
436 |
-
throw new Exception
|
437 |
}
|
438 |
-
|
439 |
// create the response
|
440 |
-
$response = $transport->populateConfiguration
|
441 |
$response ['referer'] = 'manual_config';
|
442 |
-
|
443 |
// set the display_auth to oauth2 if the transport needs it
|
444 |
-
if ($transport->isOAuthUsed
|
445 |
$response ['display_auth'] = 'oauth2';
|
446 |
-
$this->logger->debug
|
447 |
}
|
448 |
-
$this->logger->trace
|
449 |
-
wp_send_json_success
|
450 |
}
|
451 |
-
|
452 |
/**
|
453 |
* Once the Port Tests have run, the results are analyzed.
|
454 |
* The Transport place bids on the sockets and highest bid becomes the recommended
|
455 |
* The UI response is built so the user may choose a different socket with different options.
|
456 |
*/
|
457 |
function getWizardConfigurationViaAjax() {
|
458 |
-
$this->logger->debug
|
459 |
-
$originalSmtpServer = $this->getRequestParameter
|
460 |
-
$queryHostData = $this->getHostDataFromRequest
|
461 |
-
$sockets = array
|
462 |
foreach ( $queryHostData as $id => $datum ) {
|
463 |
-
array_push
|
464 |
}
|
465 |
-
$this->logger->error
|
466 |
-
$userPortOverride = $this->getUserPortOverride
|
467 |
-
$userAuthOverride = $this->getUserAuthOverride
|
468 |
-
|
469 |
// determine a configuration recommendation
|
470 |
-
$winningRecommendation = $this->getWinningRecommendation
|
471 |
-
if ($this->logger->isTrace
|
472 |
-
$this->logger->trace
|
473 |
-
$this->logger->trace
|
474 |
}
|
475 |
-
|
476 |
// create the reponse
|
477 |
-
$response = array
|
478 |
-
$configuration = array
|
479 |
$response ['referer'] = 'wizard';
|
480 |
-
if (isset
|
481 |
$configuration ['user_override'] = true;
|
482 |
}
|
483 |
-
|
484 |
-
if (isset
|
485 |
-
|
486 |
// create an appropriate (theoretical) transport
|
487 |
-
$transport = PostmanTransportRegistry::getInstance
|
488 |
-
|
489 |
// create user override menu
|
490 |
-
$overrideMenu = $this->createOverrideMenus
|
491 |
-
if ($this->logger->isTrace
|
492 |
-
$this->logger->trace
|
493 |
-
$this->logger->trace
|
494 |
}
|
495 |
-
|
496 |
$queryHostName = $winningRecommendation ['hostname'];
|
497 |
-
if ($this->logger->isDebug
|
498 |
-
$this->logger->debug
|
499 |
}
|
500 |
-
$generalConfig1 = $transport->populateConfiguration
|
501 |
-
$generalConfig2 = $transport->populateConfigurationFromRecommendation
|
502 |
-
$configuration = array_merge
|
503 |
$response ['override_menu'] = $overrideMenu;
|
504 |
$response ['configuration'] = $configuration;
|
505 |
-
if ($this->logger->isTrace
|
506 |
-
$this->logger->trace
|
507 |
-
$this->logger->trace
|
508 |
-
$this->logger->trace
|
509 |
-
$this->logger->trace
|
510 |
}
|
511 |
-
wp_send_json_success
|
512 |
} else {
|
513 |
/* translators: where %s is the URL to the Connectivity Test page */
|
514 |
-
$configuration ['message'] = sprintf
|
515 |
$response ['configuration'] = $configuration;
|
516 |
-
if ($this->logger->isTrace
|
517 |
-
$this->logger->trace
|
518 |
-
$this->logger->trace
|
519 |
}
|
520 |
-
wp_send_json_error
|
521 |
}
|
522 |
}
|
523 |
-
|
524 |
/**
|
525 |
* // for each successful host/port combination
|
526 |
* // ask a transport if they support it, and if they do at what priority is it
|
527 |
* // configure for the highest priority you find
|
528 |
*
|
529 |
-
* @param unknown $queryHostData
|
530 |
* @return unknown
|
531 |
*/
|
532 |
-
private function getWinningRecommendation($sockets, $userSocketOverride, $userAuthOverride, $originalSmtpServer) {
|
533 |
foreach ( $sockets as $socket ) {
|
534 |
-
$winningRecommendation = $this->getWin
|
535 |
-
$this->logger->error
|
536 |
}
|
537 |
return $winningRecommendation;
|
538 |
}
|
539 |
-
|
540 |
/**
|
541 |
*
|
542 |
-
* @param PostmanSocket $socket
|
543 |
-
* @param unknown
|
544 |
-
* @param unknown
|
545 |
-
* @param unknown
|
546 |
* @return Ambigous <NULL, unknown, string>
|
547 |
*/
|
548 |
-
private function getWin(PostmanWizardSocket $socket, $userSocketOverride, $userAuthOverride, $originalSmtpServer) {
|
549 |
static $recommendationPriority = - 1;
|
550 |
static $winningRecommendation = null;
|
551 |
$available = $socket->success;
|
552 |
-
if ($available) {
|
553 |
-
$this->logger->debug
|
554 |
-
$recommendation = PostmanTransportRegistry::getInstance
|
555 |
-
$recommendationId = sprintf
|
556 |
$recommendation ['id'] = $recommendationId;
|
557 |
-
$this->logger->debug
|
558 |
-
if (isset
|
559 |
-
if ($recommendationId == $userSocketOverride) {
|
560 |
$winningRecommendation = $recommendation;
|
561 |
-
$this->logger->debug
|
562 |
}
|
563 |
-
} elseif ($recommendation && $recommendation ['priority'] > $recommendationPriority) {
|
564 |
$recommendationPriority = $recommendation ['priority'];
|
565 |
$winningRecommendation = $recommendation;
|
566 |
}
|
@@ -568,82 +564,82 @@ class PostmanManageConfigurationAjaxHandler extends PostmanAbstractAjaxHandler {
|
|
568 |
}
|
569 |
return $winningRecommendation;
|
570 |
}
|
571 |
-
|
572 |
/**
|
573 |
*
|
574 |
-
* @param unknown $queryHostData
|
575 |
* @return multitype:
|
576 |
*/
|
577 |
-
private function createOverrideMenus($sockets, $winningRecommendation, $userSocketOverride, $userAuthOverride) {
|
578 |
-
$overrideMenu = array
|
579 |
foreach ( $sockets as $socket ) {
|
580 |
-
$overrideItem = $this->createOverrideMenu
|
581 |
-
if ($overrideItem != null) {
|
582 |
-
$overrideMenu [$socket->id] = $overrideItem;
|
583 |
}
|
584 |
}
|
585 |
-
|
586 |
// sort
|
587 |
-
krsort
|
588 |
-
$sortedMenu = array
|
589 |
foreach ( $overrideMenu as $menu ) {
|
590 |
-
array_push
|
591 |
}
|
592 |
-
|
593 |
return $sortedMenu;
|
594 |
}
|
595 |
-
|
596 |
/**
|
597 |
*
|
598 |
-
* @param PostmanWizardSocket $socket
|
599 |
-
* @param unknown
|
600 |
-
* @param unknown
|
601 |
-
* @param unknown
|
602 |
*/
|
603 |
-
private function createOverrideMenu(PostmanWizardSocket $socket, $winningRecommendation, $userSocketOverride, $userAuthOverride) {
|
604 |
-
if ($socket->success) {
|
605 |
-
$transport = PostmanTransportRegistry::getInstance
|
606 |
-
$this->logger->debug
|
607 |
-
$overrideItem = $transport->createOverrideMenu
|
608 |
return $overrideItem;
|
609 |
}
|
610 |
return null;
|
611 |
}
|
612 |
-
|
613 |
/**
|
614 |
*/
|
615 |
private function getTransportTypeFromRequest() {
|
616 |
-
return $this->getRequestParameter
|
617 |
}
|
618 |
-
|
619 |
/**
|
620 |
*/
|
621 |
private function getHostnameFromRequest() {
|
622 |
-
return $this->getRequestParameter
|
623 |
}
|
624 |
-
|
625 |
/**
|
626 |
*/
|
627 |
private function getAuthenticationTypeFromRequest() {
|
628 |
-
return $this->getRequestParameter
|
629 |
}
|
630 |
-
|
631 |
/**
|
632 |
*/
|
633 |
private function getHostDataFromRequest() {
|
634 |
-
return $this->getRequestParameter
|
635 |
}
|
636 |
-
|
637 |
/**
|
638 |
*/
|
639 |
private function getUserPortOverride() {
|
640 |
-
return $this->getRequestParameter
|
641 |
}
|
642 |
-
|
643 |
/**
|
644 |
*/
|
645 |
private function getUserAuthOverride() {
|
646 |
-
return $this->getRequestParameter
|
647 |
}
|
648 |
}
|
649 |
class PostmanImportConfigurationAjaxController extends PostmanAbstractAjaxHandler {
|
@@ -651,44 +647,44 @@ class PostmanImportConfigurationAjaxController extends PostmanAbstractAjaxHandle
|
|
651 |
/**
|
652 |
* Constructor
|
653 |
*
|
654 |
-
* @param PostmanOptions $options
|
655 |
*/
|
656 |
-
function __construct(PostmanOptions $options) {
|
657 |
-
parent::__construct
|
658 |
$this->options = $options;
|
659 |
-
PostmanUtils::registerAjaxHandler
|
660 |
}
|
661 |
-
|
662 |
/**
|
663 |
* This function extracts configuration details form a competing SMTP plugin
|
664 |
* and pushes them into the Postman configuration screen.
|
665 |
*/
|
666 |
function getConfigurationFromExternalPluginViaAjax() {
|
667 |
-
$importableConfiguration = new PostmanImportableConfiguration
|
668 |
-
$plugin = $this->getRequestParameter
|
669 |
-
$this->logger->debug
|
670 |
-
foreach ( $importableConfiguration->getAvailableOptions
|
671 |
-
if ($this->options->getPluginSlug
|
672 |
-
$this->logger->debug
|
673 |
-
$response = array
|
674 |
-
PostmanOptions::MESSAGE_SENDER_EMAIL => $this->options->getMessageSenderEmail
|
675 |
-
PostmanOptions::MESSAGE_SENDER_NAME => $this->options->getMessageSenderName
|
676 |
-
PostmanOptions::HOSTNAME => $this->options->getHostname
|
677 |
-
PostmanOptions::PORT => $this->options->getPort
|
678 |
-
PostmanOptions::AUTHENTICATION_TYPE => $this->options->getAuthenticationType
|
679 |
-
PostmanOptions::SECURITY_TYPE => $this->options->getEncryptionType
|
680 |
-
PostmanOptions::BASIC_AUTH_USERNAME => $this->options->getUsername
|
681 |
-
PostmanOptions::BASIC_AUTH_PASSWORD => $this->options->getPassword
|
682 |
-
'success' => true
|
683 |
);
|
684 |
break;
|
685 |
}
|
686 |
}
|
687 |
-
if (! isset
|
688 |
-
$response = array
|
689 |
-
'success' => false
|
690 |
);
|
691 |
}
|
692 |
-
wp_send_json
|
693 |
}
|
694 |
}
|
1 |
<?php
|
2 |
+
require_once( 'PostmanRegisterConfigurationSettings.php' );
|
3 |
class PostmanConfigurationController {
|
4 |
const CONFIGURATION_SLUG = 'postman/configuration';
|
5 |
const CONFIGURATION_WIZARD_SLUG = 'postman/configuration_wizard';
|
6 |
+
|
7 |
// logging
|
8 |
private $logger;
|
9 |
private $options;
|
10 |
private $settingsRegistry;
|
11 |
+
|
12 |
// Holds the values to be used in the fields callbacks
|
13 |
private $rootPluginFilenameAndPath;
|
14 |
+
|
15 |
/**
|
16 |
* Constructor
|
17 |
*
|
18 |
+
* @param unknown $rootPluginFilenameAndPath
|
19 |
*/
|
20 |
+
public function __construct( $rootPluginFilenameAndPath ) {
|
21 |
+
assert( ! empty( $rootPluginFilenameAndPath ) );
|
22 |
+
assert( PostmanUtils::isAdmin() );
|
23 |
+
assert( is_admin() );
|
24 |
+
|
25 |
+
$this->logger = new PostmanLogger( get_class( $this ) );
|
26 |
$this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
|
27 |
+
$this->options = PostmanOptions::getInstance();
|
28 |
+
$this->settingsRegistry = new PostmanSettingsRegistry();
|
29 |
+
|
30 |
+
PostmanUtils::registerAdminMenu( $this, 'addConfigurationSubmenu' );
|
31 |
+
PostmanUtils::registerAdminMenu( $this, 'addSetupWizardSubmenu' );
|
32 |
+
|
33 |
// hook on the init event
|
34 |
+
add_action( 'init', array(
|
35 |
$this,
|
36 |
+
'on_init',
|
37 |
) );
|
38 |
+
|
39 |
// initialize the scripts, stylesheets and form fields
|
40 |
+
add_action( 'admin_init', array(
|
41 |
$this,
|
42 |
+
'on_admin_init',
|
43 |
) );
|
44 |
}
|
45 |
+
|
46 |
/**
|
47 |
* Functions to execute on the init event
|
48 |
*
|
51 |
*/
|
52 |
public function on_init() {
|
53 |
// register Ajax handlers
|
54 |
+
new PostmanGetHostnameByEmailAjaxController();
|
55 |
+
new PostmanManageConfigurationAjaxHandler();
|
56 |
+
new PostmanImportConfigurationAjaxController( $this->options );
|
57 |
}
|
58 |
+
|
59 |
/**
|
60 |
* Fires on the admin_init method
|
61 |
*/
|
62 |
public function on_admin_init() {
|
63 |
+
$this->registerStylesAndScripts();
|
64 |
+
$this->settingsRegistry->on_admin_init();
|
|
|
65 |
}
|
66 |
+
|
67 |
/**
|
68 |
* Register and add settings
|
69 |
*/
|
70 |
private function registerStylesAndScripts() {
|
71 |
+
if ( $this->logger->isTrace() ) {
|
72 |
+
$this->logger->trace( 'registerStylesAndScripts()' );
|
73 |
}
|
74 |
// register the stylesheet and javascript external resources
|
75 |
+
$pluginData = apply_filters( 'postman_get_plugin_metadata', null );
|
76 |
+
wp_register_script( 'postman_manual_config_script', plugins_url( 'Postman/Postman-Configuration/postman_manual_config.js', $this->rootPluginFilenameAndPath ), array(
|
77 |
PostmanViewController::JQUERY_SCRIPT,
|
78 |
'jquery_validation',
|
79 |
+
PostmanViewController::POSTMAN_SCRIPT,
|
80 |
), $pluginData ['version'] );
|
81 |
+
wp_register_script( 'postman_wizard_script', plugins_url( 'Postman/Postman-Configuration/postman_wizard.js', $this->rootPluginFilenameAndPath ), array(
|
82 |
PostmanViewController::JQUERY_SCRIPT,
|
83 |
'jquery_validation',
|
84 |
'jquery_steps_script',
|
85 |
PostmanViewController::POSTMAN_SCRIPT,
|
86 |
+
'sprintf',
|
87 |
), $pluginData ['version'] );
|
88 |
}
|
89 |
+
|
90 |
/**
|
91 |
*/
|
92 |
private function addLocalizeScriptsToPage() {
|
93 |
+
$warning = __( 'Warning', Postman::TEXT_DOMAIN );
|
94 |
/* translators: where %s is the name of the SMTP server */
|
95 |
+
wp_localize_script( 'postman_wizard_script', 'postman_smtp_mitm', sprintf( '%s: %s', $warning, __( 'connected to %1$s instead of %2$s.', Postman::TEXT_DOMAIN ) ) );
|
96 |
/* translators: where %d is a port number */
|
97 |
+
wp_localize_script( 'postman_wizard_script', 'postman_wizard_bad_redirect_url', __( 'You are about to configure OAuth 2.0 with an IP address instead of a domain name. This is not permitted. Either assign a real domain name to your site or add a fake one in your local host file.', Postman::TEXT_DOMAIN ) );
|
98 |
+
|
99 |
// user input
|
100 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_sender_email', '#input_' . PostmanOptions::MESSAGE_SENDER_EMAIL );
|
101 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_sender_name', '#input_' . PostmanOptions::MESSAGE_SENDER_NAME );
|
102 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_port_element_name', '#input_' . PostmanOptions::PORT );
|
103 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_hostname_element_name', '#input_' . PostmanOptions::HOSTNAME );
|
104 |
+
|
105 |
// the enc input
|
106 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_enc_for_password_el', '#input_enc_type_password' );
|
107 |
// these are the ids for the <option>s in the encryption <select>
|
|
|
108 |
// the password inputs
|
109 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_basic_username', '#input_' . PostmanOptions::BASIC_AUTH_USERNAME );
|
110 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_basic_password', '#input_' . PostmanOptions::BASIC_AUTH_PASSWORD );
|
111 |
+
|
112 |
// the auth input
|
113 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_redirect_url_el', '#input_oauth_redirect_url' );
|
114 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_auth_type', '#input_' . PostmanOptions::AUTHENTICATION_TYPE );
|
115 |
+
|
116 |
// the transport modules scripts
|
117 |
+
foreach ( PostmanTransportRegistry::getInstance()->getTransports() as $transport ) {
|
118 |
+
$transport->enqueueScript();
|
119 |
}
|
120 |
|
121 |
// we need data from port test
|
122 |
+
PostmanConnectivityTestController::addLocalizeScriptForPortTest();
|
123 |
+
|
124 |
}
|
125 |
+
|
126 |
/**
|
127 |
* Register the Configuration screen
|
128 |
*/
|
129 |
public function addConfigurationSubmenu() {
|
130 |
+
$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, PostmanConfigurationController::CONFIGURATION_SLUG, array(
|
131 |
$this,
|
132 |
+
'outputManualConfigurationContent',
|
133 |
) );
|
134 |
// When the plugin options page is loaded, also load the stylesheet
|
135 |
+
add_action( 'admin_print_styles-' . $page, array(
|
136 |
$this,
|
137 |
+
'enqueueConfigurationResources',
|
138 |
) );
|
139 |
}
|
140 |
+
|
141 |
/**
|
142 |
*/
|
143 |
function enqueueConfigurationResources() {
|
144 |
+
$this->addLocalizeScriptsToPage();
|
145 |
+
wp_enqueue_style( PostmanViewController::POSTMAN_STYLE );
|
146 |
+
wp_enqueue_style( 'jquery_ui_style' );
|
147 |
+
wp_enqueue_script( 'postman_manual_config_script' );
|
148 |
+
wp_enqueue_script( 'jquery-ui-tabs' );
|
149 |
}
|
150 |
+
|
151 |
/**
|
152 |
* Register the Setup Wizard screen
|
153 |
*/
|
154 |
public function addSetupWizardSubmenu() {
|
155 |
+
$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, PostmanConfigurationController::CONFIGURATION_WIZARD_SLUG, array(
|
156 |
$this,
|
157 |
+
'outputWizardContent',
|
158 |
) );
|
159 |
// When the plugin options page is loaded, also load the stylesheet
|
160 |
+
add_action( 'admin_print_styles-' . $page, array(
|
161 |
$this,
|
162 |
+
'enqueueWizardResources',
|
163 |
) );
|
164 |
}
|
165 |
+
|
166 |
/**
|
167 |
*/
|
168 |
function enqueueWizardResources() {
|
169 |
+
$this->addLocalizeScriptsToPage();
|
170 |
+
$this->importableConfiguration = new PostmanImportableConfiguration();
|
171 |
$startPage = 1;
|
172 |
+
if ( $this->importableConfiguration->isImportAvailable() ) {
|
173 |
$startPage = 0;
|
174 |
}
|
175 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_setup_wizard', array(
|
176 |
+
'start_page' => $startPage,
|
177 |
) );
|
178 |
+
wp_enqueue_style( 'jquery_steps_style' );
|
179 |
+
wp_enqueue_style( PostmanViewController::POSTMAN_STYLE );
|
180 |
+
wp_enqueue_script( 'postman_wizard_script' );
|
181 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, '$jq', 'jQuery.noConflict(true)' );
|
182 |
+
$shortLocale = substr( get_locale(), 0, 2 );
|
183 |
+
if ( $shortLocale != 'en' ) {
|
184 |
+
$url = plugins_url( sprintf( 'script/jquery-validate/localization/messages_%s.js', $shortLocale ), $this->rootPluginFilenameAndPath );
|
185 |
+
wp_enqueue_script( sprintf( 'jquery-validation-locale-%s', $shortLocale ), $url );
|
186 |
}
|
187 |
}
|
188 |
+
|
189 |
/**
|
190 |
*/
|
191 |
public function outputManualConfigurationContent() {
|
192 |
print '<div class="wrap">';
|
193 |
+
|
194 |
+
PostmanViewController::outputChildPageHeader( __( 'Settings', Postman::TEXT_DOMAIN ), 'advanced_config' );
|
195 |
print '<div id="config_tabs"><ul>';
|
196 |
+
print sprintf( '<li><a href="#account_config">%s</a></li>', __( 'Account', Postman::TEXT_DOMAIN ) );
|
197 |
+
print sprintf( '<li><a href="#message_config">%s</a></li>', __( 'Message', Postman::TEXT_DOMAIN ) );
|
198 |
+
print sprintf( '<li><a href="#logging_config">%s</a></li>', __( 'Logging', Postman::TEXT_DOMAIN ) );
|
199 |
+
print sprintf( '<li><a href="#advanced_options_config">%s</a></li>', __( 'Advanced', Postman::TEXT_DOMAIN ) );
|
200 |
print '</ul>';
|
201 |
print '<form method="post" action="options.php">';
|
202 |
// This prints out all hidden setting fields
|
203 |
+
settings_fields( PostmanAdminController::SETTINGS_GROUP_NAME );
|
204 |
print '<section id="account_config">';
|
205 |
+
if ( sizeof( PostmanTransportRegistry::getInstance()->getTransports() ) > 1 ) {
|
206 |
+
do_settings_sections( 'transport_options' );
|
207 |
} else {
|
208 |
+
printf( '<input id="input_%2$s" type="hidden" name="%1$s[%2$s]" value="%3$s"/>', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TRANSPORT_TYPE, PostmanSmtpModuleTransport::SLUG );
|
209 |
}
|
210 |
print '<div id="smtp_config" class="transport_setting">';
|
211 |
+
do_settings_sections( PostmanAdminController::SMTP_OPTIONS );
|
212 |
print '</div>';
|
213 |
print '<div id="password_settings" class="authentication_setting non-oauth2">';
|
214 |
+
do_settings_sections( PostmanAdminController::BASIC_AUTH_OPTIONS );
|
215 |
print '</div>';
|
216 |
print '<div id="oauth_settings" class="authentication_setting non-basic">';
|
217 |
+
do_settings_sections( PostmanAdminController::OAUTH_AUTH_OPTIONS );
|
218 |
print '</div>';
|
219 |
print '<div id="mandrill_settings" class="authentication_setting non-basic non-oauth2">';
|
220 |
+
do_settings_sections( PostmanMandrillTransport::MANDRILL_AUTH_OPTIONS );
|
221 |
print '</div>';
|
222 |
print '<div id="sendgrid_settings" class="authentication_setting non-basic non-oauth2">';
|
223 |
+
do_settings_sections( PostmanSendGridTransport::SENDGRID_AUTH_OPTIONS );
|
224 |
print '</div>';
|
225 |
print '</section>';
|
226 |
print '<section id="message_config">';
|
227 |
+
do_settings_sections( PostmanAdminController::MESSAGE_SENDER_OPTIONS );
|
228 |
+
do_settings_sections( PostmanAdminController::MESSAGE_FROM_OPTIONS );
|
229 |
+
do_settings_sections( PostmanAdminController::EMAIL_VALIDATION_OPTIONS );
|
230 |
+
do_settings_sections( PostmanAdminController::MESSAGE_OPTIONS );
|
231 |
+
do_settings_sections( PostmanAdminController::MESSAGE_HEADERS_OPTIONS );
|
232 |
print '</section>';
|
233 |
print '<section id="logging_config">';
|
234 |
+
do_settings_sections( PostmanAdminController::LOGGING_OPTIONS );
|
235 |
print '</section>';
|
236 |
/*
|
237 |
* print '<section id="logging_config">';
|
239 |
* print '</section>';
|
240 |
*/
|
241 |
print '<section id="advanced_options_config">';
|
242 |
+
do_settings_sections( PostmanAdminController::NETWORK_OPTIONS );
|
243 |
+
do_settings_sections( PostmanAdminController::ADVANCED_OPTIONS );
|
244 |
print '</section>';
|
245 |
+
submit_button();
|
246 |
print '</form>';
|
247 |
print '</div>';
|
248 |
print '</div>';
|
249 |
}
|
250 |
+
|
251 |
/**
|
252 |
*/
|
253 |
public function outputWizardContent() {
|
254 |
// Set default values for input fields
|
255 |
+
$this->options->setMessageSenderEmailIfEmpty( wp_get_current_user()->user_email );
|
256 |
+
$this->options->setMessageSenderNameIfEmpty( wp_get_current_user()->display_name );
|
257 |
+
|
258 |
// construct Wizard
|
259 |
print '<div class="wrap">';
|
260 |
+
|
261 |
+
PostmanViewController::outputChildPageHeader( __( 'Setup Wizard', Postman::TEXT_DOMAIN ) );
|
262 |
+
|
263 |
print '<form id="postman_wizard" method="post" action="options.php">';
|
264 |
+
|
265 |
// account tab
|
|
|
266 |
// message tab
|
267 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE, $this->options->isPluginSenderEmailEnforced() );
|
268 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE, $this->options->isPluginSenderNameEnforced() );
|
269 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::REPLY_TO, $this->options->getReplyTo() );
|
270 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_TO_RECIPIENTS, $this->options->getForcedToRecipients() );
|
271 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_CC_RECIPIENTS, $this->options->getForcedCcRecipients() );
|
272 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_BCC_RECIPIENTS, $this->options->getForcedBccRecipients() );
|
273 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::ADDITIONAL_HEADERS, $this->options->getAdditionalHeaders() );
|
274 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::DISABLE_EMAIL_VALIDAITON, $this->options->isEmailValidationDisabled() );
|
275 |
+
|
276 |
// logging tab
|
277 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::MAIL_LOG_ENABLED_OPTION, $this->options->getMailLoggingEnabled() );
|
278 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::MAIL_LOG_MAX_ENTRIES, $this->options->getMailLoggingMaxEntries() );
|
279 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TRANSCRIPT_SIZE, $this->options->getTranscriptSize() );
|
280 |
+
|
281 |
// advanced tab
|
282 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::CONNECTION_TIMEOUT, $this->options->getConnectionTimeout() );
|
283 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::READ_TIMEOUT, $this->options->getReadTimeout() );
|
284 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::LOG_LEVEL, $this->options->getLogLevel() );
|
285 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::RUN_MODE, $this->options->getRunMode() );
|
286 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::STEALTH_MODE, $this->options->isStealthModeEnabled() );
|
287 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TEMPORARY_DIRECTORY, $this->options->getTempDirectory() );
|
288 |
+
|
289 |
// display the setting text
|
290 |
+
settings_fields( PostmanAdminController::SETTINGS_GROUP_NAME );
|
291 |
+
|
292 |
// Wizard Step 0
|
293 |
+
printf( '<h5>%s</h5>', _x( 'Import Configuration', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
|
294 |
print '<fieldset>';
|
295 |
+
printf( '<legend>%s</legend>', _x( 'Import configuration from another plugin?', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
|
296 |
+
printf( '<p>%s</p>', __( 'If you had a working configuration with another Plugin, the Setup Wizard can begin with those settings.', Postman::TEXT_DOMAIN ) );
|
297 |
print '<table class="input_auth_type">';
|
298 |
+
printf( '<tr><td><input type="radio" id="import_none" name="input_plugin" value="%s" checked="checked"></input></td><td><label> %s</label></td></tr>', 'none', __( 'None', Postman::TEXT_DOMAIN ) );
|
299 |
+
|
300 |
+
if ( $this->importableConfiguration->isImportAvailable() ) {
|
301 |
+
foreach ( $this->importableConfiguration->getAvailableOptions() as $options ) {
|
302 |
+
printf( '<tr><td><input type="radio" name="input_plugin" value="%s"/></td><td><label> %s</label></td></tr>', $options->getPluginSlug(), $options->getPluginName() );
|
303 |
}
|
304 |
}
|
305 |
print '</table>';
|
306 |
print '</fieldset>';
|
307 |
+
|
308 |
// Wizard Step 1
|
309 |
+
printf( '<h5>%s</h5>', _x( 'Sender Details', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
|
310 |
print '<fieldset>';
|
311 |
+
printf( '<legend>%s</legend>', _x( 'Who is the mail coming from?', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
|
312 |
+
printf( '<p>%s</p>', __( 'Enter the email address and name you\'d like to send mail as.', Postman::TEXT_DOMAIN ) );
|
313 |
+
printf( '<p>%s</p>', __( 'Please note that to prevent abuse, many email services will <em>not</em> let you send from an email address other than the one you authenticate with.', Postman::TEXT_DOMAIN ) );
|
314 |
+
printf( '<label for="postman_options[sender_email]">%s</label>', __( 'Email Address', Postman::TEXT_DOMAIN ) );
|
315 |
+
print $this->settingsRegistry->from_email_callback();
|
316 |
print '<br/>';
|
317 |
+
printf( '<label for="postman_options[sender_name]">%s</label>', __( 'Name', Postman::TEXT_DOMAIN ) );
|
318 |
+
print $this->settingsRegistry->sender_name_callback();
|
319 |
print '</fieldset>';
|
320 |
+
|
321 |
// Wizard Step 2
|
322 |
+
printf( '<h5>%s</h5>', __( 'Outgoing Mail Server Hostname', Postman::TEXT_DOMAIN ) );
|
323 |
print '<fieldset>';
|
324 |
+
foreach ( PostmanTransportRegistry::getInstance()->getTransports() as $transport ) {
|
325 |
+
$transport->printWizardMailServerHostnameStep();
|
326 |
}
|
327 |
print '</fieldset>';
|
328 |
+
|
329 |
// Wizard Step 3
|
330 |
+
printf( '<h5>%s</h5>', __( 'Connectivity Test', Postman::TEXT_DOMAIN ) );
|
331 |
print '<fieldset>';
|
332 |
+
printf( '<legend>%s</legend>', __( 'How will the connection to the mail server be established?', Postman::TEXT_DOMAIN ) );
|
333 |
+
printf( '<p>%s</p>', __( 'Your connection settings depend on what your email service provider offers, and what your WordPress host allows.', Postman::TEXT_DOMAIN ) );
|
334 |
+
printf( '<p id="connectivity_test_status">%s: <span id="port_test_status">%s</span></p>', __( 'Connectivity Test', Postman::TEXT_DOMAIN ), _x( 'Ready', 'TCP Port Test Status', Postman::TEXT_DOMAIN ) );
|
335 |
+
printf( '<p class="ajax-loader" style="display:none"><img src="%s"/></p>', plugins_url( 'post-smtp/style/ajax-loader.gif' ) );
|
336 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TRANSPORT_TYPE );
|
337 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PORT );
|
338 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::SECURITY_TYPE );
|
339 |
+
printf( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::AUTHENTICATION_TYPE );
|
340 |
print '<p id="wizard_recommendation"></p>';
|
341 |
/* Translators: Where %1$s is the socket identifier and %2$s is the authentication type */
|
342 |
+
printf( '<p class="user_override" style="display:none"><label><span>%s:</span></label> <table id="user_socket_override" class="user_override"></table></p>', _x( 'Socket', 'A socket is the network term for host and port together', Postman::TEXT_DOMAIN ) );
|
343 |
+
printf( '<p class="user_override" style="display:none"><label><span>%s:</span></label> <table id="user_auth_override" class="user_override"></table></p>', __( 'Authentication', Postman::TEXT_DOMAIN ) );
|
344 |
print ('<p><span id="smtp_mitm" style="display:none; background-color:yellow"></span></p>') ;
|
345 |
+
$warning = __( 'Warning', Postman::TEXT_DOMAIN );
|
346 |
+
$clearCredentialsWarning = __( 'This configuration option will send your authorization credentials in the clear.', Postman::TEXT_DOMAIN );
|
347 |
+
printf( '<p id="smtp_not_secure" style="display:none"><span style="background-color:yellow">%s: %s</span></p>', $warning, $clearCredentialsWarning );
|
348 |
print '</fieldset>';
|
349 |
+
|
350 |
// Wizard Step 4
|
351 |
+
printf( '<h5>%s</h5>', __( 'Authentication', Postman::TEXT_DOMAIN ) );
|
352 |
print '<fieldset>';
|
353 |
+
printf( '<legend>%s</legend>', __( 'How will you prove your identity to the mail server?', Postman::TEXT_DOMAIN ) );
|
354 |
+
foreach ( PostmanTransportRegistry::getInstance()->getTransports() as $transport ) {
|
355 |
+
$transport->printWizardAuthenticationStep();
|
356 |
}
|
357 |
print '</fieldset>';
|
358 |
+
|
359 |
// Wizard Step 5
|
360 |
+
printf( '<h5>%s</h5>', _x( 'Finish', 'The final step of the Wizard', Postman::TEXT_DOMAIN ) );
|
361 |
print '<fieldset>';
|
362 |
+
printf( '<legend>%s</legend>', _x( 'You\'re Done!', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
|
363 |
print '<section>';
|
364 |
+
printf( '<p>%s</p>', __( 'Click Finish to save these settings, then:', Postman::TEXT_DOMAIN ) );
|
365 |
print '<ul style="margin-left: 20px">';
|
366 |
+
printf( '<li class="wizard-auth-oauth2">%s</li>', __( 'Grant permission with the Email Provider for Postman to send email and', Postman::TEXT_DOMAIN ) );
|
367 |
+
printf( '<li>%s</li>', __( 'Send yourself a Test Email to make sure everything is working!', Postman::TEXT_DOMAIN ) );
|
368 |
print '</ul>';
|
369 |
print '</section>';
|
370 |
print '</fieldset>';
|
376 |
/**
|
377 |
*
|
378 |
* @author jasonhendriks
|
|
|
379 |
*/
|
380 |
class PostmanGetHostnameByEmailAjaxController extends PostmanAbstractAjaxHandler {
|
381 |
const IS_GOOGLE_PARAMETER = 'is_google';
|
382 |
function __construct() {
|
383 |
+
parent::__construct();
|
384 |
+
PostmanUtils::registerAjaxHandler( 'postman_check_email', $this, 'getAjaxHostnameByEmail' );
|
385 |
}
|
386 |
/**
|
387 |
* This Ajax function retrieves the smtp hostname for a give e-mail address
|
388 |
*/
|
389 |
function getAjaxHostnameByEmail() {
|
390 |
+
$goDaddyHostDetected = $this->getBooleanRequestParameter( 'go_daddy' );
|
391 |
+
$email = $this->getRequestParameter( 'email' );
|
392 |
+
$d = new PostmanSmtpDiscovery( $email );
|
393 |
+
$smtp = $d->getSmtpServer();
|
394 |
+
$this->logger->debug( 'given email ' . $email . ', smtp server is ' . $smtp );
|
395 |
+
$this->logger->trace( $d );
|
396 |
+
if ( $goDaddyHostDetected && ! $d->isGoogle ) {
|
397 |
// override with the GoDaddy SMTP server
|
398 |
$smtp = 'relay-hosting.secureserver.net';
|
399 |
+
$this->logger->debug( 'detected GoDaddy SMTP server, smtp server is ' . $smtp );
|
400 |
}
|
401 |
+
$response = array(
|
402 |
'hostname' => $smtp,
|
403 |
self::IS_GOOGLE_PARAMETER => $d->isGoogle,
|
404 |
'is_go_daddy' => $d->isGoDaddy,
|
405 |
+
'is_well_known' => $d->isWellKnownDomain,
|
406 |
);
|
407 |
+
$this->logger->trace( $response );
|
408 |
+
wp_send_json_success( $response );
|
409 |
}
|
410 |
}
|
411 |
class PostmanManageConfigurationAjaxHandler extends PostmanAbstractAjaxHandler {
|
412 |
function __construct() {
|
413 |
+
parent::__construct();
|
414 |
+
PostmanUtils::registerAjaxHandler( 'manual_config', $this, 'getManualConfigurationViaAjax' );
|
415 |
+
PostmanUtils::registerAjaxHandler( 'get_wizard_configuration_options', $this, 'getWizardConfigurationViaAjax' );
|
416 |
}
|
417 |
+
|
418 |
/**
|
419 |
* Handle a Advanced Configuration request with Ajax
|
420 |
*
|
421 |
* @throws Exception
|
422 |
*/
|
423 |
function getManualConfigurationViaAjax() {
|
424 |
+
$queryTransportType = $this->getTransportTypeFromRequest();
|
425 |
+
$queryAuthType = $this->getAuthenticationTypeFromRequest();
|
426 |
+
$queryHostname = $this->getHostnameFromRequest();
|
427 |
+
|
428 |
// the outgoing server hostname is only required for the SMTP Transport
|
429 |
// the Gmail API transport doesn't use an SMTP server
|
430 |
+
$transport = PostmanTransportRegistry::getInstance()->getTransport( $queryTransportType );
|
431 |
+
if ( ! $transport ) {
|
432 |
+
throw new Exception( 'Unable to find transport ' . $queryTransportType );
|
433 |
}
|
434 |
+
|
435 |
// create the response
|
436 |
+
$response = $transport->populateConfiguration( $queryHostname );
|
437 |
$response ['referer'] = 'manual_config';
|
438 |
+
|
439 |
// set the display_auth to oauth2 if the transport needs it
|
440 |
+
if ( $transport->isOAuthUsed( $queryAuthType ) ) {
|
441 |
$response ['display_auth'] = 'oauth2';
|
442 |
+
$this->logger->debug( 'ajaxRedirectUrl answer display_auth:' . $response ['display_auth'] );
|
443 |
}
|
444 |
+
$this->logger->trace( $response );
|
445 |
+
wp_send_json_success( $response );
|
446 |
}
|
447 |
+
|
448 |
/**
|
449 |
* Once the Port Tests have run, the results are analyzed.
|
450 |
* The Transport place bids on the sockets and highest bid becomes the recommended
|
451 |
* The UI response is built so the user may choose a different socket with different options.
|
452 |
*/
|
453 |
function getWizardConfigurationViaAjax() {
|
454 |
+
$this->logger->debug( 'in getWizardConfiguration' );
|
455 |
+
$originalSmtpServer = $this->getRequestParameter( 'original_smtp_server' );
|
456 |
+
$queryHostData = $this->getHostDataFromRequest();
|
457 |
+
$sockets = array();
|
458 |
foreach ( $queryHostData as $id => $datum ) {
|
459 |
+
array_push( $sockets, new PostmanWizardSocket( $datum ) );
|
460 |
}
|
461 |
+
$this->logger->error( $sockets );
|
462 |
+
$userPortOverride = $this->getUserPortOverride();
|
463 |
+
$userAuthOverride = $this->getUserAuthOverride();
|
464 |
+
|
465 |
// determine a configuration recommendation
|
466 |
+
$winningRecommendation = $this->getWinningRecommendation( $sockets, $userPortOverride, $userAuthOverride, $originalSmtpServer );
|
467 |
+
if ( $this->logger->isTrace() ) {
|
468 |
+
$this->logger->trace( 'winning recommendation:' );
|
469 |
+
$this->logger->trace( $winningRecommendation );
|
470 |
}
|
471 |
+
|
472 |
// create the reponse
|
473 |
+
$response = array();
|
474 |
+
$configuration = array();
|
475 |
$response ['referer'] = 'wizard';
|
476 |
+
if ( isset( $userPortOverride ) || isset( $userAuthOverride ) ) {
|
477 |
$configuration ['user_override'] = true;
|
478 |
}
|
479 |
+
|
480 |
+
if ( isset( $winningRecommendation ) ) {
|
481 |
+
|
482 |
// create an appropriate (theoretical) transport
|
483 |
+
$transport = PostmanTransportRegistry::getInstance()->getTransport( $winningRecommendation ['transport'] );
|
484 |
+
|
485 |
// create user override menu
|
486 |
+
$overrideMenu = $this->createOverrideMenus( $sockets, $winningRecommendation, $userPortOverride, $userAuthOverride );
|
487 |
+
if ( $this->logger->isTrace() ) {
|
488 |
+
$this->logger->trace( 'override menu:' );
|
489 |
+
$this->logger->trace( $overrideMenu );
|
490 |
}
|
491 |
+
|
492 |
$queryHostName = $winningRecommendation ['hostname'];
|
493 |
+
if ( $this->logger->isDebug() ) {
|
494 |
+
$this->logger->debug( 'Getting scribe for ' . $queryHostName );
|
495 |
}
|
496 |
+
$generalConfig1 = $transport->populateConfiguration( $queryHostName );
|
497 |
+
$generalConfig2 = $transport->populateConfigurationFromRecommendation( $winningRecommendation );
|
498 |
+
$configuration = array_merge( $configuration, $generalConfig1, $generalConfig2 );
|
499 |
$response ['override_menu'] = $overrideMenu;
|
500 |
$response ['configuration'] = $configuration;
|
501 |
+
if ( $this->logger->isTrace() ) {
|
502 |
+
$this->logger->trace( 'configuration:' );
|
503 |
+
$this->logger->trace( $configuration );
|
504 |
+
$this->logger->trace( 'response:' );
|
505 |
+
$this->logger->trace( $response );
|
506 |
}
|
507 |
+
wp_send_json_success( $response );
|
508 |
} else {
|
509 |
/* translators: where %s is the URL to the Connectivity Test page */
|
510 |
+
$configuration ['message'] = sprintf( __( 'Postman can\'t find any way to send mail on your system. Run a <a href="%s">connectivity test</a>.', Postman::TEXT_DOMAIN ), PostmanViewController::getPageUrl( PostmanViewController::PORT_TEST_SLUG ) );
|
511 |
$response ['configuration'] = $configuration;
|
512 |
+
if ( $this->logger->isTrace() ) {
|
513 |
+
$this->logger->trace( 'configuration:' );
|
514 |
+
$this->logger->trace( $configuration );
|
515 |
}
|
516 |
+
wp_send_json_error( $response );
|
517 |
}
|
518 |
}
|
519 |
+
|
520 |
/**
|
521 |
* // for each successful host/port combination
|
522 |
* // ask a transport if they support it, and if they do at what priority is it
|
523 |
* // configure for the highest priority you find
|
524 |
*
|
525 |
+
* @param unknown $queryHostData
|
526 |
* @return unknown
|
527 |
*/
|
528 |
+
private function getWinningRecommendation( $sockets, $userSocketOverride, $userAuthOverride, $originalSmtpServer ) {
|
529 |
foreach ( $sockets as $socket ) {
|
530 |
+
$winningRecommendation = $this->getWin( $socket, $userSocketOverride, $userAuthOverride, $originalSmtpServer );
|
531 |
+
$this->logger->error( $socket->label );
|
532 |
}
|
533 |
return $winningRecommendation;
|
534 |
}
|
535 |
+
|
536 |
/**
|
537 |
*
|
538 |
+
* @param PostmanSocket $socket
|
539 |
+
* @param unknown $userSocketOverride
|
540 |
+
* @param unknown $userAuthOverride
|
541 |
+
* @param unknown $originalSmtpServer
|
542 |
* @return Ambigous <NULL, unknown, string>
|
543 |
*/
|
544 |
+
private function getWin( PostmanWizardSocket $socket, $userSocketOverride, $userAuthOverride, $originalSmtpServer ) {
|
545 |
static $recommendationPriority = - 1;
|
546 |
static $winningRecommendation = null;
|
547 |
$available = $socket->success;
|
548 |
+
if ( $available ) {
|
549 |
+
$this->logger->debug( sprintf( 'Asking for judgement on %s:%s', $socket->hostname, $socket->port ) );
|
550 |
+
$recommendation = PostmanTransportRegistry::getInstance()->getRecommendation( $socket, $userAuthOverride, $originalSmtpServer );
|
551 |
+
$recommendationId = sprintf( '%s_%s', $socket->hostname, $socket->port );
|
552 |
$recommendation ['id'] = $recommendationId;
|
553 |
+
$this->logger->debug( sprintf( 'Got a recommendation: [%d] %s', $recommendation ['priority'], $recommendationId ) );
|
554 |
+
if ( isset( $userSocketOverride ) ) {
|
555 |
+
if ( $recommendationId == $userSocketOverride ) {
|
556 |
$winningRecommendation = $recommendation;
|
557 |
+
$this->logger->debug( sprintf( 'User chosen socket %s is the winner', $recommendationId ) );
|
558 |
}
|
559 |
+
} elseif ( $recommendation && $recommendation ['priority'] > $recommendationPriority ) {
|
560 |
$recommendationPriority = $recommendation ['priority'];
|
561 |
$winningRecommendation = $recommendation;
|
562 |
}
|
564 |
}
|
565 |
return $winningRecommendation;
|
566 |
}
|
567 |
+
|
568 |
/**
|
569 |
*
|
570 |
+
* @param unknown $queryHostData
|
571 |
* @return multitype:
|
572 |
*/
|
573 |
+
private function createOverrideMenus( $sockets, $winningRecommendation, $userSocketOverride, $userAuthOverride ) {
|
574 |
+
$overrideMenu = array();
|
575 |
foreach ( $sockets as $socket ) {
|
576 |
+
$overrideItem = $this->createOverrideMenu( $socket, $winningRecommendation, $userSocketOverride, $userAuthOverride );
|
577 |
+
if ( $overrideItem != null ) {
|
578 |
+
$overrideMenu [ $socket->id ] = $overrideItem;
|
579 |
}
|
580 |
}
|
581 |
+
|
582 |
// sort
|
583 |
+
krsort( $overrideMenu );
|
584 |
+
$sortedMenu = array();
|
585 |
foreach ( $overrideMenu as $menu ) {
|
586 |
+
array_push( $sortedMenu, $menu );
|
587 |
}
|
588 |
+
|
589 |
return $sortedMenu;
|
590 |
}
|
591 |
+
|
592 |
/**
|
593 |
*
|
594 |
+
* @param PostmanWizardSocket $socket
|
595 |
+
* @param unknown $winningRecommendation
|
596 |
+
* @param unknown $userSocketOverride
|
597 |
+
* @param unknown $userAuthOverride
|
598 |
*/
|
599 |
+
private function createOverrideMenu( PostmanWizardSocket $socket, $winningRecommendation, $userSocketOverride, $userAuthOverride ) {
|
600 |
+
if ( $socket->success ) {
|
601 |
+
$transport = PostmanTransportRegistry::getInstance()->getTransport( $socket->transport );
|
602 |
+
$this->logger->debug( sprintf( 'Transport %s is building the override menu for socket', $transport->getSlug() ) );
|
603 |
+
$overrideItem = $transport->createOverrideMenu( $socket, $winningRecommendation, $userSocketOverride, $userAuthOverride );
|
604 |
return $overrideItem;
|
605 |
}
|
606 |
return null;
|
607 |
}
|
608 |
+
|
609 |
/**
|
610 |
*/
|
611 |
private function getTransportTypeFromRequest() {
|
612 |
+
return $this->getRequestParameter( 'transport' );
|
613 |
}
|
614 |
+
|
615 |
/**
|
616 |
*/
|
617 |
private function getHostnameFromRequest() {
|
618 |
+
return $this->getRequestParameter( 'hostname' );
|
619 |
}
|
620 |
+
|
621 |
/**
|
622 |
*/
|
623 |
private function getAuthenticationTypeFromRequest() {
|
624 |
+
return $this->getRequestParameter( 'auth_type' );
|
625 |
}
|
626 |
+
|
627 |
/**
|
628 |
*/
|
629 |
private function getHostDataFromRequest() {
|
630 |
+
return $this->getRequestParameter( 'host_data' );
|
631 |
}
|
632 |
+
|
633 |
/**
|
634 |
*/
|
635 |
private function getUserPortOverride() {
|
636 |
+
return $this->getRequestParameter( 'user_port_override' );
|
637 |
}
|
638 |
+
|
639 |
/**
|
640 |
*/
|
641 |
private function getUserAuthOverride() {
|
642 |
+
return $this->getRequestParameter( 'user_auth_override' );
|
643 |
}
|
644 |
}
|
645 |
class PostmanImportConfigurationAjaxController extends PostmanAbstractAjaxHandler {
|
647 |
/**
|
648 |
* Constructor
|
649 |
*
|
650 |
+
* @param PostmanOptions $options
|
651 |
*/
|
652 |
+
function __construct( PostmanOptions $options ) {
|
653 |
+
parent::__construct();
|
654 |
$this->options = $options;
|
655 |
+
PostmanUtils::registerAjaxHandler( 'import_configuration', $this, 'getConfigurationFromExternalPluginViaAjax' );
|
656 |
}
|
657 |
+
|
658 |
/**
|
659 |
* This function extracts configuration details form a competing SMTP plugin
|
660 |
* and pushes them into the Postman configuration screen.
|
661 |
*/
|
662 |
function getConfigurationFromExternalPluginViaAjax() {
|
663 |
+
$importableConfiguration = new PostmanImportableConfiguration();
|
664 |
+
$plugin = $this->getRequestParameter( 'plugin' );
|
665 |
+
$this->logger->debug( 'Looking for config=' . $plugin );
|
666 |
+
foreach ( $importableConfiguration->getAvailableOptions() as $this->options ) {
|
667 |
+
if ( $this->options->getPluginSlug() == $plugin ) {
|
668 |
+
$this->logger->debug( 'Sending configuration response' );
|
669 |
+
$response = array(
|
670 |
+
PostmanOptions::MESSAGE_SENDER_EMAIL => $this->options->getMessageSenderEmail(),
|
671 |
+
PostmanOptions::MESSAGE_SENDER_NAME => $this->options->getMessageSenderName(),
|
672 |
+
PostmanOptions::HOSTNAME => $this->options->getHostname(),
|
673 |
+
PostmanOptions::PORT => $this->options->getPort(),
|
674 |
+
PostmanOptions::AUTHENTICATION_TYPE => $this->options->getAuthenticationType(),
|
675 |
+
PostmanOptions::SECURITY_TYPE => $this->options->getEncryptionType(),
|
676 |
+
PostmanOptions::BASIC_AUTH_USERNAME => $this->options->getUsername(),
|
677 |
+
PostmanOptions::BASIC_AUTH_PASSWORD => $this->options->getPassword(),
|
678 |
+
'success' => true,
|
679 |
);
|
680 |
break;
|
681 |
}
|
682 |
}
|
683 |
+
if ( ! isset( $response ) ) {
|
684 |
+
$response = array(
|
685 |
+
'success' => false,
|
686 |
);
|
687 |
}
|
688 |
+
wp_send_json( $response );
|
689 |
}
|
690 |
}
|
Postman/Postman-Connectivity-Test/PostmanConnectivityTestController.php
CHANGED
@@ -1,45 +1,43 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
//
|
4 |
class PostmanConnectivityTestController {
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
// logging
|
10 |
private $logger;
|
11 |
-
|
12 |
// Holds the values to be used in the fields callbacks
|
13 |
private $rootPluginFilenameAndPath;
|
14 |
-
|
15 |
/**
|
16 |
* Constructor
|
17 |
*
|
18 |
-
* @param unknown $rootPluginFilenameAndPath
|
19 |
*/
|
20 |
-
public function __construct($rootPluginFilenameAndPath) {
|
21 |
-
assert
|
22 |
-
assert
|
23 |
-
assert
|
24 |
-
|
25 |
-
$this->logger = new PostmanLogger
|
26 |
$this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
|
27 |
-
|
28 |
-
PostmanUtils::registerAdminMenu
|
29 |
-
|
30 |
// hook on the init event
|
31 |
-
add_action
|
32 |
$this,
|
33 |
-
'on_init'
|
34 |
) );
|
35 |
-
|
36 |
// initialize the scripts, stylesheets and form fields
|
37 |
-
add_action
|
38 |
$this,
|
39 |
-
'on_admin_init'
|
40 |
) );
|
41 |
}
|
42 |
-
|
43 |
/**
|
44 |
* Functions to execute on the init event
|
45 |
*
|
@@ -48,133 +46,132 @@ class PostmanConnectivityTestController {
|
|
48 |
*/
|
49 |
public function on_init() {
|
50 |
// register Ajax handlers
|
51 |
-
new PostmanPortTestAjaxController
|
52 |
}
|
53 |
-
|
54 |
/**
|
55 |
* Fires on the admin_init method
|
56 |
*/
|
57 |
public function on_admin_init() {
|
58 |
-
|
59 |
-
$this->registerStylesAndScripts ();
|
60 |
}
|
61 |
-
|
62 |
/**
|
63 |
* Register and add settings
|
64 |
*/
|
65 |
private function registerStylesAndScripts() {
|
66 |
-
if ($this->logger->isTrace
|
67 |
-
$this->logger->trace
|
68 |
}
|
69 |
// register the stylesheet and javascript external resources
|
70 |
-
$pluginData = apply_filters
|
71 |
-
wp_register_script
|
72 |
PostmanViewController::JQUERY_SCRIPT,
|
73 |
'jquery_validation',
|
74 |
PostmanViewController::POSTMAN_SCRIPT,
|
75 |
-
'sprintf'
|
76 |
), $pluginData ['version'] );
|
77 |
}
|
78 |
-
|
79 |
/**
|
80 |
* Register the Email Test screen
|
81 |
*/
|
82 |
public function addPortTestSubmenu() {
|
83 |
-
$page = add_submenu_page
|
84 |
$this,
|
85 |
-
'outputPortTestContent'
|
86 |
) );
|
87 |
// When the plugin options page is loaded, also load the stylesheet
|
88 |
-
add_action
|
89 |
$this,
|
90 |
-
'enqueuePortTestResources'
|
91 |
) );
|
92 |
}
|
93 |
-
|
94 |
/**
|
95 |
*/
|
96 |
function enqueuePortTestResources() {
|
97 |
-
wp_enqueue_style
|
98 |
-
wp_enqueue_script
|
99 |
-
$warning = __
|
100 |
-
wp_localize_script
|
101 |
-
PostmanConnectivityTestController::addLocalizeScriptForPortTest
|
102 |
}
|
103 |
static function addLocalizeScriptForPortTest() {
|
104 |
-
wp_localize_script
|
105 |
-
'in_progress' => _x
|
106 |
-
'open' => _x
|
107 |
-
'closed' => _x
|
108 |
-
'yes' => __
|
109 |
-
'no' => __
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
'mitm' => sprintf
|
117 |
-
|
118 |
-
|
119 |
) );
|
120 |
}
|
121 |
-
|
122 |
/**
|
123 |
* Get the settings option array and print one of its values
|
124 |
*/
|
125 |
public function port_test_hostname_callback() {
|
126 |
-
$hostname = PostmanTransportRegistry::getInstance
|
127 |
-
if (empty
|
128 |
-
$hostname = PostmanTransportRegistry::getInstance
|
129 |
}
|
130 |
-
printf
|
131 |
}
|
132 |
-
|
133 |
/**
|
134 |
*/
|
135 |
public function outputPortTestContent() {
|
136 |
print '<div class="wrap">';
|
137 |
-
|
138 |
-
PostmanViewController::outputChildPageHeader
|
139 |
-
|
140 |
print '<p>';
|
141 |
-
print __
|
142 |
print '<form id="port_test_form_id" method="post">';
|
143 |
-
printf
|
144 |
-
$this->port_test_hostname_callback
|
145 |
-
submit_button
|
146 |
print '</form>';
|
147 |
print '<table id="connectivity_test_table">';
|
148 |
-
print sprintf
|
149 |
-
print sprintf
|
150 |
-
$sockets = PostmanTransportRegistry::getInstance
|
151 |
foreach ( $sockets as $socket ) {
|
152 |
-
if ($socket ['smtp']) {
|
153 |
-
print sprintf
|
154 |
} else {
|
155 |
-
print sprintf
|
156 |
}
|
157 |
}
|
158 |
print '</table>';
|
159 |
/* Translators: Where %s is the name of the service providing Internet connectivity test */
|
160 |
-
printf
|
161 |
-
printf
|
162 |
print '<section id="conclusion" style="display:none">';
|
163 |
-
print sprintf
|
164 |
print '<ol class="conclusion">';
|
165 |
print '</ol>';
|
166 |
print '</section>';
|
167 |
print '<section id="blocked-port-help" style="display:none">';
|
168 |
-
print sprintf
|
169 |
print '<ol>';
|
170 |
-
printf
|
171 |
-
printf
|
172 |
/* translators: where (1) is the URL and (2) is the system */
|
173 |
-
$systemBlockMessage = __
|
174 |
-
printf
|
175 |
-
printf
|
176 |
print '</ol></p>';
|
177 |
-
print sprintf
|
178 |
print '</section>';
|
179 |
print '</div>';
|
180 |
}
|
@@ -183,25 +180,24 @@ class PostmanConnectivityTestController {
|
|
183 |
/**
|
184 |
*
|
185 |
* @author jasonhendriks
|
186 |
-
*
|
187 |
*/
|
188 |
class PostmanPortTestAjaxController {
|
189 |
private $logger;
|
190 |
/**
|
191 |
* Constructor
|
192 |
*
|
193 |
-
* @param PostmanOptions $options
|
194 |
*/
|
195 |
function __construct() {
|
196 |
-
$this->logger = new PostmanLogger
|
197 |
-
PostmanUtils::registerAjaxHandler
|
198 |
-
PostmanUtils::registerAjaxHandler
|
199 |
-
PostmanUtils::registerAjaxHandler
|
200 |
-
PostmanUtils::registerAjaxHandler
|
201 |
-
PostmanUtils::registerAjaxHandler
|
202 |
-
PostmanUtils::registerAjaxHandler
|
203 |
}
|
204 |
-
|
205 |
/**
|
206 |
* This Ajax function determines which hosts/ports to test in both the Wizard Connectivity Test and direct Connectivity Test
|
207 |
*
|
@@ -209,79 +205,79 @@ class PostmanPortTestAjaxController {
|
|
209 |
* combinations to run the connectivity test on
|
210 |
*/
|
211 |
function getPortsToTestViaAjax() {
|
212 |
-
$queryHostname = PostmanUtils::getRequestParameter
|
213 |
// originalSmtpServer is what SmtpDiscovery thinks the SMTP server should be, given an email address
|
214 |
-
$originalSmtpServer = PostmanUtils::getRequestParameter
|
215 |
-
if ($this->logger->isDebug
|
216 |
-
$this->logger->debug
|
217 |
}
|
218 |
-
$sockets = PostmanTransportRegistry::getInstance
|
219 |
-
$response = array
|
220 |
-
'hosts' => $sockets
|
221 |
);
|
222 |
-
wp_send_json_success
|
223 |
}
|
224 |
-
|
225 |
/**
|
226 |
* This Ajax function retrieves whether a TCP port is open or not
|
227 |
*/
|
228 |
function runPortQuizTest() {
|
229 |
$hostname = 'portquiz.net';
|
230 |
-
$port = intval
|
231 |
-
$this->logger->debug
|
232 |
-
$portTest = new PostmanPortTest
|
233 |
-
$success = $portTest->genericConnectionTest
|
234 |
-
$this->buildResponse
|
235 |
}
|
236 |
-
|
237 |
/**
|
238 |
* This Ajax function retrieves whether a TCP port is open or not.
|
239 |
* This is called by both the Wizard and Port Test
|
240 |
*/
|
241 |
function runSmtpTest() {
|
242 |
-
$hostname = trim
|
243 |
-
$port = intval
|
244 |
-
$transport = trim
|
245 |
-
$timeout = PostmanUtils::getRequestParameter
|
246 |
-
$this->logger->trace
|
247 |
-
$portTest = new PostmanPortTest
|
248 |
-
if (isset
|
249 |
-
$portTest->setConnectionTimeout
|
250 |
-
$portTest->setReadTimeout
|
251 |
}
|
252 |
-
if ($port != 443) {
|
253 |
-
$this->logger->debug
|
254 |
-
$success = $portTest->testSmtpPorts
|
255 |
} else {
|
256 |
-
$this->logger->debug
|
257 |
-
$success = $portTest->testHttpPorts
|
258 |
}
|
259 |
-
$this->buildResponse
|
260 |
}
|
261 |
/**
|
262 |
* This Ajax function retrieves whether a TCP port is open or not
|
263 |
*/
|
264 |
function runSmtpsTest() {
|
265 |
-
$hostname = trim
|
266 |
-
$port = intval
|
267 |
-
$transport = trim
|
268 |
-
$transportName = trim
|
269 |
-
$this->logger->debug
|
270 |
-
$portTest = new PostmanPortTest
|
271 |
$portTest->transportName = $transportName;
|
272 |
-
$success = $portTest->testSmtpsPorts
|
273 |
-
$this->buildResponse
|
274 |
}
|
275 |
-
|
276 |
/**
|
277 |
*
|
278 |
-
* @param unknown $hostname
|
279 |
-
* @param unknown $port
|
280 |
-
* @param unknown $success
|
281 |
*/
|
282 |
-
private function buildResponse($hostname, $port, PostmanPortTest $portTest, $success, $transport = '') {
|
283 |
-
$this->logger->debug
|
284 |
-
$response = array
|
285 |
'hostname' => $hostname,
|
286 |
'hostname_domain_only' => $portTest->hostnameDomainOnly,
|
287 |
'port' => $port,
|
@@ -290,7 +286,7 @@ class PostmanPortTestAjaxController {
|
|
290 |
'mitm' => ($portTest->mitm),
|
291 |
'reported_hostname' => $portTest->reportedHostname,
|
292 |
'reported_hostname_domain_only' => $portTest->reportedHostnameDomainOnly,
|
293 |
-
'message' => $portTest->getErrorMessage
|
294 |
'start_tls' => $portTest->startTls,
|
295 |
'auth_plain' => $portTest->authPlain,
|
296 |
'auth_login' => $portTest->authLogin,
|
@@ -299,14 +295,14 @@ class PostmanPortTestAjaxController {
|
|
299 |
'auth_none' => $portTest->authNone,
|
300 |
'try_smtps' => $portTest->trySmtps,
|
301 |
'success' => $success,
|
302 |
-
'transport' => $transport
|
303 |
);
|
304 |
-
$this->logger->trace
|
305 |
-
$this->logger->trace
|
306 |
-
if ($success) {
|
307 |
-
wp_send_json_success
|
308 |
} else {
|
309 |
-
wp_send_json_error
|
310 |
}
|
311 |
}
|
312 |
}
|
1 |
<?php
|
2 |
|
|
|
3 |
class PostmanConnectivityTestController {
|
4 |
+
|
5 |
+
const PORT_TEST_SLUG = 'postman/port_test';
|
6 |
+
|
|
|
7 |
// logging
|
8 |
private $logger;
|
9 |
+
|
10 |
// Holds the values to be used in the fields callbacks
|
11 |
private $rootPluginFilenameAndPath;
|
12 |
+
|
13 |
/**
|
14 |
* Constructor
|
15 |
*
|
16 |
+
* @param unknown $rootPluginFilenameAndPath
|
17 |
*/
|
18 |
+
public function __construct( $rootPluginFilenameAndPath ) {
|
19 |
+
assert( ! empty( $rootPluginFilenameAndPath ) );
|
20 |
+
assert( PostmanUtils::isAdmin() );
|
21 |
+
assert( is_admin() );
|
22 |
+
|
23 |
+
$this->logger = new PostmanLogger( get_class( $this ) );
|
24 |
$this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
|
25 |
+
|
26 |
+
PostmanUtils::registerAdminMenu( $this, 'addPortTestSubmenu' );
|
27 |
+
|
28 |
// hook on the init event
|
29 |
+
add_action( 'init', array(
|
30 |
$this,
|
31 |
+
'on_init',
|
32 |
) );
|
33 |
+
|
34 |
// initialize the scripts, stylesheets and form fields
|
35 |
+
add_action( 'admin_init', array(
|
36 |
$this,
|
37 |
+
'on_admin_init',
|
38 |
) );
|
39 |
}
|
40 |
+
|
41 |
/**
|
42 |
* Functions to execute on the init event
|
43 |
*
|
46 |
*/
|
47 |
public function on_init() {
|
48 |
// register Ajax handlers
|
49 |
+
new PostmanPortTestAjaxController();
|
50 |
}
|
51 |
+
|
52 |
/**
|
53 |
* Fires on the admin_init method
|
54 |
*/
|
55 |
public function on_admin_init() {
|
56 |
+
$this->registerStylesAndScripts();
|
|
|
57 |
}
|
58 |
+
|
59 |
/**
|
60 |
* Register and add settings
|
61 |
*/
|
62 |
private function registerStylesAndScripts() {
|
63 |
+
if ( $this->logger->isTrace() ) {
|
64 |
+
$this->logger->trace( 'registerStylesAndScripts()' );
|
65 |
}
|
66 |
// register the stylesheet and javascript external resources
|
67 |
+
$pluginData = apply_filters( 'postman_get_plugin_metadata', null );
|
68 |
+
wp_register_script( 'postman_port_test_script', plugins_url( 'Postman/Postman-Connectivity-Test/postman_port_test.js', $this->rootPluginFilenameAndPath ), array(
|
69 |
PostmanViewController::JQUERY_SCRIPT,
|
70 |
'jquery_validation',
|
71 |
PostmanViewController::POSTMAN_SCRIPT,
|
72 |
+
'sprintf',
|
73 |
), $pluginData ['version'] );
|
74 |
}
|
75 |
+
|
76 |
/**
|
77 |
* Register the Email Test screen
|
78 |
*/
|
79 |
public function addPortTestSubmenu() {
|
80 |
+
$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(
|
81 |
$this,
|
82 |
+
'outputPortTestContent',
|
83 |
) );
|
84 |
// When the plugin options page is loaded, also load the stylesheet
|
85 |
+
add_action( 'admin_print_styles-' . $page, array(
|
86 |
$this,
|
87 |
+
'enqueuePortTestResources',
|
88 |
) );
|
89 |
}
|
90 |
+
|
91 |
/**
|
92 |
*/
|
93 |
function enqueuePortTestResources() {
|
94 |
+
wp_enqueue_style( PostmanViewController::POSTMAN_STYLE );
|
95 |
+
wp_enqueue_script( 'postman_port_test_script' );
|
96 |
+
$warning = __( 'Warning', Postman::TEXT_DOMAIN );
|
97 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_hostname_element_name', '#input_' . PostmanOptions::HOSTNAME );
|
98 |
+
PostmanConnectivityTestController::addLocalizeScriptForPortTest();
|
99 |
}
|
100 |
static function addLocalizeScriptForPortTest() {
|
101 |
+
wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_port_test', array(
|
102 |
+
'in_progress' => _x( 'Checking..', 'The "please wait" message', Postman::TEXT_DOMAIN ),
|
103 |
+
'open' => _x( 'Open', 'The port is open', Postman::TEXT_DOMAIN ),
|
104 |
+
'closed' => _x( 'Closed', 'The port is closed', Postman::TEXT_DOMAIN ),
|
105 |
+
'yes' => __( 'Yes', Postman::TEXT_DOMAIN ),
|
106 |
+
'no' => __( 'No', Postman::TEXT_DOMAIN ),
|
107 |
+
/* translators: where %d is a port number */
|
108 |
+
'blocked' => __( 'No outbound route between this site and the Internet on Port %d.', Postman::TEXT_DOMAIN ),
|
109 |
+
/* translators: where %d is a port number and %s is a hostname */
|
110 |
+
'try_dif_smtp' => __( 'Port %d is open, but not to %s.', Postman::TEXT_DOMAIN ),
|
111 |
+
/* translators: where %d is the port number and %s is the hostname */
|
112 |
+
'success' => __( 'Port %d can be used for SMTP to %s.', Postman::TEXT_DOMAIN ),
|
113 |
+
'mitm' => sprintf( '%s: %s', __( 'Warning', Postman::TEXT_DOMAIN ), __( 'connected to %1$s instead of %2$s.', Postman::TEXT_DOMAIN ) ),
|
114 |
+
/* translators: where %d is a port number and %s is the URL for the Postman Gmail Extension */
|
115 |
+
'https_success' => __( 'Port %d can be used with the %s.', Postman::TEXT_DOMAIN ),
|
116 |
) );
|
117 |
}
|
118 |
+
|
119 |
/**
|
120 |
* Get the settings option array and print one of its values
|
121 |
*/
|
122 |
public function port_test_hostname_callback() {
|
123 |
+
$hostname = PostmanTransportRegistry::getInstance()->getSelectedTransport()->getHostname();
|
124 |
+
if ( empty( $hostname ) ) {
|
125 |
+
$hostname = PostmanTransportRegistry::getInstance()->getActiveTransport()->getHostname();
|
126 |
}
|
127 |
+
printf( '<input type="text" id="input_hostname" name="postman_options[hostname]" value="%s" size="40" class="required"/>', $hostname );
|
128 |
}
|
129 |
+
|
130 |
/**
|
131 |
*/
|
132 |
public function outputPortTestContent() {
|
133 |
print '<div class="wrap">';
|
134 |
+
|
135 |
+
PostmanViewController::outputChildPageHeader( __( 'Connectivity Test', Postman::TEXT_DOMAIN ) );
|
136 |
+
|
137 |
print '<p>';
|
138 |
+
print __( 'This test determines which well-known ports are available for Postman to use.', Postman::TEXT_DOMAIN );
|
139 |
print '<form id="port_test_form_id" method="post">';
|
140 |
+
printf( '<label for="hostname">%s</label>', __( 'Outgoing Mail Server Hostname', Postman::TEXT_DOMAIN ) );
|
141 |
+
$this->port_test_hostname_callback();
|
142 |
+
submit_button( _x( 'Begin Test', 'Button Label', Postman::TEXT_DOMAIN ), 'primary', 'begin-port-test', true );
|
143 |
print '</form>';
|
144 |
print '<table id="connectivity_test_table">';
|
145 |
+
print sprintf( '<tr><th rowspan="2">%s</th><th rowspan="2">%s</th><th rowspan="2">%s</th><th rowspan="2">%s</th><th rowspan="2">%s</th><th colspan="5">%s</th></tr>', __( 'Transport', Postman::TEXT_DOMAIN ), _x( 'Socket', 'A socket is the network term for host and port together', Postman::TEXT_DOMAIN ), __( 'Status', Postman::TEXT_DOMAIN ) . '<sup>*</sup>', __( 'Service Available', Postman::TEXT_DOMAIN ), __( 'Server ID', Postman::TEXT_DOMAIN ), __( 'Authentication', Postman::TEXT_DOMAIN ) );
|
146 |
+
print sprintf( '<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>', 'None', 'Login', 'Plain', 'CRAM-MD5', 'OAuth 2.0' );
|
147 |
+
$sockets = PostmanTransportRegistry::getInstance()->getSocketsForSetupWizardToProbe();
|
148 |
foreach ( $sockets as $socket ) {
|
149 |
+
if ( $socket ['smtp'] ) {
|
150 |
+
print sprintf( '<tr id="%s"><th class="name">%s</th><td class="socket">%s:%s</td><td class="firewall resettable">-</td><td class="service resettable">-</td><td class="reported_id resettable">-</td><td class="auth_none resettable">-</td><td class="auth_login resettable">-</td><td class="auth_plain resettable">-</td><td class="auth_crammd5 resettable">-</td><td class="auth_xoauth2 resettable">-</td></tr>', $socket ['id'], $socket ['transport_name'], $socket ['host'], $socket ['port'] );
|
151 |
} else {
|
152 |
+
print sprintf( '<tr id="%s"><th class="name">%s</th><td class="socket">%s:%s</td><td class="firewall resettable">-</td><td class="service resettable">-</td><td class="reported_id resettable">-</td><td colspan="5">%s</td></tr>', $socket ['id'], $socket ['transport_name'], $socket ['host'], $socket ['port'], __( 'n/a', Postman::TEXT_DOMAIN ) );
|
153 |
}
|
154 |
}
|
155 |
print '</table>';
|
156 |
/* Translators: Where %s is the name of the service providing Internet connectivity test */
|
157 |
+
printf( '<p class="portquiz" style="display:none; font-size:0.8em">* %s</p>', sprintf( __( 'According to %s', Postman::TEXT_DOMAIN ), '<a target="_new" href="http://ww.downor.me/portquiz.net">portquiz.net</a>' ) );
|
158 |
+
printf( '<p class="ajax-loader" style="display:none"><img src="%s"/></p>', plugins_url( 'post-smtp/style/ajax-loader.gif' ) );
|
159 |
print '<section id="conclusion" style="display:none">';
|
160 |
+
print sprintf( '<h3>%s:</h3>', __( 'Summary', Postman::TEXT_DOMAIN ) );
|
161 |
print '<ol class="conclusion">';
|
162 |
print '</ol>';
|
163 |
print '</section>';
|
164 |
print '<section id="blocked-port-help" style="display:none">';
|
165 |
+
print sprintf( '<p><b>%s</b></p>', __( 'A test with <span style="color:red">"No"</span> Service Available indicates one or more of these issues:', Postman::TEXT_DOMAIN ) );
|
166 |
print '<ol>';
|
167 |
+
printf( '<li>%s</li>', __( 'Your web host has placed a firewall between this site and the Internet', Postman::TEXT_DOMAIN ) );
|
168 |
+
printf( '<li>%s</li>', __( 'The SMTP hostname is wrong or the mail server does not provide service on this port', Postman::TEXT_DOMAIN ) );
|
169 |
/* translators: where (1) is the URL and (2) is the system */
|
170 |
+
$systemBlockMessage = __( 'Your <a href="%1$s">%2$s configuration</a> is preventing outbound connections', Postman::TEXT_DOMAIN );
|
171 |
+
printf( '<li>%s</li>', sprintf( $systemBlockMessage, 'http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen', 'PHP' ) );
|
172 |
+
printf( '<li>%s</li>', sprintf( $systemBlockMessage, 'http://wp-mix.com/disable-external-url-requests/', 'WordPress' ) );
|
173 |
print '</ol></p>';
|
174 |
+
print sprintf( '<p><b>%s</b></p>', __( 'If the issues above can not be resolved, your last option is to configure Postman to use an email account managed by your web host with an SMTP server managed by your web host.', Postman::TEXT_DOMAIN ) );
|
175 |
print '</section>';
|
176 |
print '</div>';
|
177 |
}
|
180 |
/**
|
181 |
*
|
182 |
* @author jasonhendriks
|
|
|
183 |
*/
|
184 |
class PostmanPortTestAjaxController {
|
185 |
private $logger;
|
186 |
/**
|
187 |
* Constructor
|
188 |
*
|
189 |
+
* @param PostmanOptions $options
|
190 |
*/
|
191 |
function __construct() {
|
192 |
+
$this->logger = new PostmanLogger( get_class( $this ) );
|
193 |
+
PostmanUtils::registerAjaxHandler( 'postman_get_hosts_to_test', $this, 'getPortsToTestViaAjax' );
|
194 |
+
PostmanUtils::registerAjaxHandler( 'postman_wizard_port_test', $this, 'runSmtpTest' );
|
195 |
+
PostmanUtils::registerAjaxHandler( 'postman_wizard_port_test_smtps', $this, 'runSmtpsTest' );
|
196 |
+
PostmanUtils::registerAjaxHandler( 'postman_port_quiz_test', $this, 'runPortQuizTest' );
|
197 |
+
PostmanUtils::registerAjaxHandler( 'postman_test_port', $this, 'runSmtpTest' );
|
198 |
+
PostmanUtils::registerAjaxHandler( 'postman_test_smtps', $this, 'runSmtpsTest' );
|
199 |
}
|
200 |
+
|
201 |
/**
|
202 |
* This Ajax function determines which hosts/ports to test in both the Wizard Connectivity Test and direct Connectivity Test
|
203 |
*
|
205 |
* combinations to run the connectivity test on
|
206 |
*/
|
207 |
function getPortsToTestViaAjax() {
|
208 |
+
$queryHostname = PostmanUtils::getRequestParameter( 'hostname' );
|
209 |
// originalSmtpServer is what SmtpDiscovery thinks the SMTP server should be, given an email address
|
210 |
+
$originalSmtpServer = PostmanUtils::getRequestParameter( 'original_smtp_server' );
|
211 |
+
if ( $this->logger->isDebug() ) {
|
212 |
+
$this->logger->debug( 'Probing available transports for sockets against hostname ' . $queryHostname );
|
213 |
}
|
214 |
+
$sockets = PostmanTransportRegistry::getInstance()->getSocketsForSetupWizardToProbe( $queryHostname, $originalSmtpServer );
|
215 |
+
$response = array(
|
216 |
+
'hosts' => $sockets,
|
217 |
);
|
218 |
+
wp_send_json_success( $response );
|
219 |
}
|
220 |
+
|
221 |
/**
|
222 |
* This Ajax function retrieves whether a TCP port is open or not
|
223 |
*/
|
224 |
function runPortQuizTest() {
|
225 |
$hostname = 'portquiz.net';
|
226 |
+
$port = intval( PostmanUtils::getRequestParameter( 'port' ) );
|
227 |
+
$this->logger->debug( 'testing TCP port: hostname ' . $hostname . ' port ' . $port );
|
228 |
+
$portTest = new PostmanPortTest( $hostname, $port );
|
229 |
+
$success = $portTest->genericConnectionTest();
|
230 |
+
$this->buildResponse( $hostname, $port, $portTest, $success );
|
231 |
}
|
232 |
+
|
233 |
/**
|
234 |
* This Ajax function retrieves whether a TCP port is open or not.
|
235 |
* This is called by both the Wizard and Port Test
|
236 |
*/
|
237 |
function runSmtpTest() {
|
238 |
+
$hostname = trim( PostmanUtils::getRequestParameter( 'hostname' ) );
|
239 |
+
$port = intval( PostmanUtils::getRequestParameter( 'port' ) );
|
240 |
+
$transport = trim( PostmanUtils::getRequestParameter( 'transport' ) );
|
241 |
+
$timeout = PostmanUtils::getRequestParameter( 'timeout' );
|
242 |
+
$this->logger->trace( $timeout );
|
243 |
+
$portTest = new PostmanPortTest( $hostname, $port );
|
244 |
+
if ( isset( $timeout ) ) {
|
245 |
+
$portTest->setConnectionTimeout( intval( $timeout ) );
|
246 |
+
$portTest->setReadTimeout( intval( $timeout ) );
|
247 |
}
|
248 |
+
if ( $port != 443 ) {
|
249 |
+
$this->logger->debug( sprintf( 'testing SMTP socket %s:%s (%s)', $hostname, $port, $transport ) );
|
250 |
+
$success = $portTest->testSmtpPorts();
|
251 |
} else {
|
252 |
+
$this->logger->debug( sprintf( 'testing HTTPS socket %s:%s (%s)', $hostname, $port, $transport ) );
|
253 |
+
$success = $portTest->testHttpPorts();
|
254 |
}
|
255 |
+
$this->buildResponse( $hostname, $port, $portTest, $success, $transport );
|
256 |
}
|
257 |
/**
|
258 |
* This Ajax function retrieves whether a TCP port is open or not
|
259 |
*/
|
260 |
function runSmtpsTest() {
|
261 |
+
$hostname = trim( PostmanUtils::getRequestParameter( 'hostname' ) );
|
262 |
+
$port = intval( PostmanUtils::getRequestParameter( 'port' ) );
|
263 |
+
$transport = trim( PostmanUtils::getRequestParameter( 'transport' ) );
|
264 |
+
$transportName = trim( PostmanUtils::getRequestParameter( 'transport_name' ) );
|
265 |
+
$this->logger->debug( sprintf( 'testing SMTPS socket %s:%s (%s)', $hostname, $port, $transport ) );
|
266 |
+
$portTest = new PostmanPortTest( $hostname, $port );
|
267 |
$portTest->transportName = $transportName;
|
268 |
+
$success = $portTest->testSmtpsPorts();
|
269 |
+
$this->buildResponse( $hostname, $port, $portTest, $success, $transport );
|
270 |
}
|
271 |
+
|
272 |
/**
|
273 |
*
|
274 |
+
* @param unknown $hostname
|
275 |
+
* @param unknown $port
|
276 |
+
* @param unknown $success
|
277 |
*/
|
278 |
+
private function buildResponse( $hostname, $port, PostmanPortTest $portTest, $success, $transport = '' ) {
|
279 |
+
$this->logger->debug( sprintf( 'testing port result for %s:%s success=%s', $hostname, $port, $success ) );
|
280 |
+
$response = array(
|
281 |
'hostname' => $hostname,
|
282 |
'hostname_domain_only' => $portTest->hostnameDomainOnly,
|
283 |
'port' => $port,
|
286 |
'mitm' => ($portTest->mitm),
|
287 |
'reported_hostname' => $portTest->reportedHostname,
|
288 |
'reported_hostname_domain_only' => $portTest->reportedHostnameDomainOnly,
|
289 |
+
'message' => $portTest->getErrorMessage(),
|
290 |
'start_tls' => $portTest->startTls,
|
291 |
'auth_plain' => $portTest->authPlain,
|
292 |
'auth_login' => $portTest->authLogin,
|
295 |
'auth_none' => $portTest->authNone,
|
296 |
'try_smtps' => $portTest->trySmtps,
|
297 |
'success' => $success,
|
298 |
+
'transport' => $transport,
|
299 |
);
|
300 |
+
$this->logger->trace( 'Ajax response:' );
|
301 |
+
$this->logger->trace( $response );
|
302 |
+
if ( $success ) {
|
303 |
+
wp_send_json_success( $response );
|
304 |
} else {
|
305 |
+
wp_send_json_error( $response );
|
306 |
}
|
307 |
}
|
308 |
}
|
Postman/Postman-Diagnostic-Test/PostmanDiagnosticTestController.php
CHANGED
@@ -1,44 +1,44 @@
|
|
1 |
<?php
|
2 |
class PostmanDiagnosticTestController {
|
3 |
const DIAGNOSTICS_SLUG = 'postman/diagnostics';
|
4 |
-
|
5 |
// logging
|
6 |
private $logger;
|
7 |
private $options;
|
8 |
-
|
9 |
// Holds the values to be used in the fields callbacks
|
10 |
private $rootPluginFilenameAndPath;
|
11 |
-
|
12 |
/**
|
13 |
* Constructor
|
14 |
*
|
15 |
-
* @param unknown $rootPluginFilenameAndPath
|
16 |
*/
|
17 |
-
public function __construct($rootPluginFilenameAndPath) {
|
18 |
-
assert
|
19 |
-
assert
|
20 |
-
assert
|
21 |
-
|
22 |
-
$this->logger = new PostmanLogger
|
23 |
$this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
|
24 |
-
$this->options = PostmanOptions::getInstance
|
25 |
-
|
26 |
// register the admin menu
|
27 |
-
PostmanUtils::registerAdminMenu
|
28 |
-
|
29 |
// hook on the init event
|
30 |
-
add_action
|
31 |
$this,
|
32 |
-
'on_init'
|
33 |
) );
|
34 |
-
|
35 |
// initialize the scripts, stylesheets and form fields
|
36 |
-
add_action
|
37 |
$this,
|
38 |
-
'on_admin_init'
|
39 |
) );
|
40 |
}
|
41 |
-
|
42 |
/**
|
43 |
* Functions to execute on the init event
|
44 |
*
|
@@ -47,66 +47,65 @@ class PostmanDiagnosticTestController {
|
|
47 |
*/
|
48 |
public function on_init() {
|
49 |
// register Ajax handlers
|
50 |
-
new PostmanGetDiagnosticsViaAjax
|
51 |
}
|
52 |
-
|
53 |
/**
|
54 |
* Fires on the admin_init method
|
55 |
*/
|
56 |
public function on_admin_init() {
|
57 |
-
|
58 |
-
$this->registerStylesAndScripts ();
|
59 |
}
|
60 |
-
|
61 |
/**
|
62 |
* Register and add settings
|
63 |
*/
|
64 |
private function registerStylesAndScripts() {
|
65 |
-
if ($this->logger->isTrace
|
66 |
-
$this->logger->trace
|
67 |
}
|
68 |
-
|
69 |
// register the javascript resource
|
70 |
-
$pluginData = apply_filters
|
71 |
-
wp_register_script
|
72 |
PostmanViewController::JQUERY_SCRIPT,
|
73 |
-
PostmanViewController::POSTMAN_SCRIPT
|
74 |
), $pluginData ['version'] );
|
75 |
}
|
76 |
-
|
77 |
/**
|
78 |
* Register the Diagnostics screen
|
79 |
*/
|
80 |
public function addDiagnosticsSubmenu() {
|
81 |
-
$page = add_submenu_page
|
82 |
$this,
|
83 |
-
'outputDiagnosticsContent'
|
84 |
) );
|
85 |
// When the plugin options page is loaded, also load the stylesheet
|
86 |
-
add_action
|
87 |
$this,
|
88 |
-
'enqueueDiagnosticsScreenStylesheet'
|
89 |
) );
|
90 |
}
|
91 |
function enqueueDiagnosticsScreenStylesheet() {
|
92 |
-
wp_enqueue_style
|
93 |
-
wp_enqueue_script
|
94 |
}
|
95 |
-
|
96 |
/**
|
97 |
*/
|
98 |
public function outputDiagnosticsContent() {
|
99 |
// test features
|
100 |
print '<div class="wrap">';
|
101 |
-
|
102 |
-
PostmanViewController::outputChildPageHeader
|
103 |
-
|
104 |
-
printf
|
105 |
/* translators: where %1$s and %2$s are the URLs to the Troubleshooting and Support Forums on WordPress.org */
|
106 |
-
printf
|
107 |
-
printf
|
108 |
-
printf
|
109 |
-
printf
|
110 |
print '</div>';
|
111 |
}
|
112 |
}
|
@@ -114,7 +113,6 @@ class PostmanDiagnosticTestController {
|
|
114 |
/**
|
115 |
*
|
116 |
* @author jasonhendriks
|
117 |
-
*
|
118 |
*/
|
119 |
class PostmanGetDiagnosticsViaAjax {
|
120 |
private $diagnostics;
|
@@ -123,59 +121,59 @@ class PostmanGetDiagnosticsViaAjax {
|
|
123 |
/**
|
124 |
* Constructor
|
125 |
*
|
126 |
-
* @param PostmanOptions $options
|
127 |
*/
|
128 |
function __construct() {
|
129 |
-
$this->options = PostmanOptions::getInstance
|
130 |
-
$this->authorizationToken = PostmanOAuthToken::getInstance
|
131 |
$this->diagnostics = '';
|
132 |
-
PostmanUtils::registerAjaxHandler
|
133 |
}
|
134 |
-
private function addToDiagnostics($header, $data) {
|
135 |
-
if (isset
|
136 |
-
$this->diagnostics .= sprintf
|
137 |
}
|
138 |
}
|
139 |
private function getActivePlugins() {
|
140 |
// from http://stackoverflow.com/questions/20488264/how-do-i-get-activated-plugin-list-in-wordpress-plugin-development
|
141 |
-
$apl = get_option
|
142 |
-
$plugins = get_plugins
|
143 |
-
$pluginText = array
|
144 |
foreach ( $apl as $p ) {
|
145 |
-
if (isset
|
146 |
-
array_push
|
147 |
}
|
148 |
}
|
149 |
-
return implode
|
150 |
}
|
151 |
private function getPhpDependencies() {
|
152 |
-
$apl = PostmanPreRequisitesCheck::getState
|
153 |
-
$pluginText = array
|
154 |
foreach ( $apl as $p ) {
|
155 |
-
array_push
|
156 |
}
|
157 |
-
return implode
|
158 |
}
|
159 |
private function getTransports() {
|
160 |
$transports = '';
|
161 |
-
foreach ( PostmanTransportRegistry::getInstance
|
162 |
-
$transports .= ' : ' . $transport->getName
|
163 |
}
|
164 |
return $transports;
|
165 |
}
|
166 |
-
|
167 |
/**
|
168 |
* Diagnostic Data test to current SMTP server
|
169 |
*
|
170 |
* @return string
|
171 |
*/
|
172 |
-
private function testConnectivity(PostmanModuleTransport $transport) {
|
173 |
-
$hostname = $transport->getHostname
|
174 |
-
$port = $transport->getPort
|
175 |
-
if (! empty
|
176 |
-
$portTest = new PostmanPortTest
|
177 |
-
$result = $portTest->genericConnectionTest
|
178 |
-
if ($result) {
|
179 |
return 'Yes';
|
180 |
} else {
|
181 |
return 'No';
|
@@ -183,93 +181,93 @@ class PostmanGetDiagnosticsViaAjax {
|
|
183 |
}
|
184 |
return 'n/a';
|
185 |
}
|
186 |
-
|
187 |
/**
|
188 |
* Inspects the $wp_filter variable and returns the plugins attached to it
|
189 |
* From: http://stackoverflow.com/questions/5224209/wordpress-how-do-i-get-all-the-registered-functions-for-the-content-filter
|
190 |
*/
|
191 |
-
private function getFilters($hook = '') {
|
192 |
global $wp_filter;
|
193 |
-
if (empty
|
194 |
-
return null;
|
195 |
-
$functionArray = array
|
196 |
-
foreach ( $wp_filter [$hook] as $functions ) {
|
197 |
foreach ( $functions as $function ) {
|
198 |
$thing = $function ['function'];
|
199 |
-
if (is_array
|
200 |
-
$name = get_class
|
201 |
-
array_push
|
202 |
} else {
|
203 |
-
array_push
|
204 |
}
|
205 |
}
|
206 |
}
|
207 |
-
return implode
|
208 |
}
|
209 |
-
|
210 |
/**
|
211 |
*/
|
212 |
public function getDiagnostics() {
|
213 |
-
$transportRegistry = PostmanTransportRegistry::getInstance
|
214 |
-
$this->addToDiagnostics
|
215 |
-
$this->addToDiagnostics
|
216 |
-
$this->addToDiagnostics
|
217 |
-
$this->addToDiagnostics
|
218 |
-
$this->addToDiagnostics
|
219 |
-
$this->addToDiagnostics
|
220 |
{
|
221 |
-
$bindResult = apply_filters
|
222 |
$wp_mail_file_name = 'n/a';
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
}
|
230 |
}
|
231 |
-
|
232 |
-
$this->addToDiagnostics
|
233 |
-
$this->addToDiagnostics
|
234 |
-
$this->addToDiagnostics
|
235 |
-
$this->addToDiagnostics
|
236 |
-
$this->addToDiagnostics
|
237 |
-
$
|
238 |
-
$
|
|
|
239 |
{
|
240 |
-
$s1 = $this->options->getEnvelopeSender
|
241 |
-
$s2 = $this->options->getMessageSenderEmail
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
}
|
246 |
-
$this->addToDiagnostics
|
247 |
{
|
248 |
// status of the active transport
|
249 |
-
$transport = $transportRegistry->getActiveTransport
|
250 |
-
$this->addToDiagnostics
|
251 |
-
$this->addToDiagnostics
|
252 |
}
|
253 |
-
if ($transportRegistry->getActiveTransport
|
254 |
// status of the selected transport
|
255 |
-
$transport = $transportRegistry->getSelectedTransport
|
256 |
-
$this->addToDiagnostics
|
257 |
-
$this->addToDiagnostics
|
258 |
}
|
259 |
-
$this->addToDiagnostics
|
260 |
-
if ($this->options->getConnectionTimeout
|
261 |
-
$this->addToDiagnostics
|
262 |
}
|
263 |
-
if ($this->options->isMailLoggingEnabled
|
264 |
-
$this->addToDiagnostics
|
265 |
}
|
266 |
-
$this->addToDiagnostics
|
267 |
-
$this->addToDiagnostics
|
268 |
-
$this->addToDiagnostics
|
269 |
-
$this->addToDiagnostics
|
270 |
-
$response = array
|
271 |
-
'message' => $this->diagnostics
|
272 |
);
|
273 |
-
wp_send_json_success
|
274 |
}
|
275 |
}
|
1 |
<?php
|
2 |
class PostmanDiagnosticTestController {
|
3 |
const DIAGNOSTICS_SLUG = 'postman/diagnostics';
|
4 |
+
|
5 |
// logging
|
6 |
private $logger;
|
7 |
private $options;
|
8 |
+
|
9 |
// Holds the values to be used in the fields callbacks
|
10 |
private $rootPluginFilenameAndPath;
|
11 |
+
|
12 |
/**
|
13 |
* Constructor
|
14 |
*
|
15 |
+
* @param unknown $rootPluginFilenameAndPath
|
16 |
*/
|
17 |
+
public function __construct( $rootPluginFilenameAndPath ) {
|
18 |
+
assert( ! empty( $rootPluginFilenameAndPath ) );
|
19 |
+
assert( PostmanUtils::isAdmin() );
|
20 |
+
assert( is_admin() );
|
21 |
+
|
22 |
+
$this->logger = new PostmanLogger( get_class( $this ) );
|
23 |
$this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
|
24 |
+
$this->options = PostmanOptions::getInstance();
|
25 |
+
|
26 |
// register the admin menu
|
27 |
+
PostmanUtils::registerAdminMenu( $this, 'addDiagnosticsSubmenu' );
|
28 |
+
|
29 |
// hook on the init event
|
30 |
+
add_action( 'init', array(
|
31 |
$this,
|
32 |
+
'on_init',
|
33 |
) );
|
34 |
+
|
35 |
// initialize the scripts, stylesheets and form fields
|
36 |
+
add_action( 'admin_init', array(
|
37 |
$this,
|
38 |
+
'on_admin_init',
|
39 |
) );
|
40 |
}
|
41 |
+
|
42 |
/**
|
43 |
* Functions to execute on the init event
|
44 |
*
|
47 |
*/
|
48 |
public function on_init() {
|
49 |
// register Ajax handlers
|
50 |
+
new PostmanGetDiagnosticsViaAjax();
|
51 |
}
|
52 |
+
|
53 |
/**
|
54 |
* Fires on the admin_init method
|
55 |
*/
|
56 |
public function on_admin_init() {
|
57 |
+
$this->registerStylesAndScripts();
|
|
|
58 |
}
|
59 |
+
|
60 |
/**
|
61 |
* Register and add settings
|
62 |
*/
|
63 |
private function registerStylesAndScripts() {
|
64 |
+
if ( $this->logger->isTrace() ) {
|
65 |
+
$this->logger->trace( 'registerStylesAndScripts()' );
|
66 |
}
|
67 |
+
|
68 |
// register the javascript resource
|
69 |
+
$pluginData = apply_filters( 'postman_get_plugin_metadata', null );
|
70 |
+
wp_register_script( 'postman_diagnostics_script', plugins_url( 'Postman/Postman-Diagnostic-Test/postman_diagnostics.js', $this->rootPluginFilenameAndPath ), array(
|
71 |
PostmanViewController::JQUERY_SCRIPT,
|
72 |
+
PostmanViewController::POSTMAN_SCRIPT,
|
73 |
), $pluginData ['version'] );
|
74 |
}
|
75 |
+
|
76 |
/**
|
77 |
* Register the Diagnostics screen
|
78 |
*/
|
79 |
public function addDiagnosticsSubmenu() {
|
80 |
+
$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, PostmanDiagnosticTestController::DIAGNOSTICS_SLUG, array(
|
81 |
$this,
|
82 |
+
'outputDiagnosticsContent',
|
83 |
) );
|
84 |
// When the plugin options page is loaded, also load the stylesheet
|
85 |
+
add_action( 'admin_print_styles-' . $page, array(
|
86 |
$this,
|
87 |
+
'enqueueDiagnosticsScreenStylesheet',
|
88 |
) );
|
89 |
}
|
90 |
function enqueueDiagnosticsScreenStylesheet() {
|
91 |
+
wp_enqueue_style( PostmanViewController::POSTMAN_STYLE );
|
92 |
+
wp_enqueue_script( 'postman_diagnostics_script' );
|
93 |
}
|
94 |
+
|
95 |
/**
|
96 |
*/
|
97 |
public function outputDiagnosticsContent() {
|
98 |
// test features
|
99 |
print '<div class="wrap">';
|
100 |
+
|
101 |
+
PostmanViewController::outputChildPageHeader( __( 'Diagnostic Test', Postman::TEXT_DOMAIN ) );
|
102 |
+
|
103 |
+
printf( '<h4>%s</h4>', __( 'Are you having issues with Postman?', Postman::TEXT_DOMAIN ) );
|
104 |
/* translators: where %1$s and %2$s are the URLs to the Troubleshooting and Support Forums on WordPress.org */
|
105 |
+
printf( '<p style="margin:0 10px">%s</p>', sprintf( __( 'Please check the <a href="%1$s">troubleshooting and error messages</a> page and the <a href="%2$s">support forum</a>.', Postman::TEXT_DOMAIN ), 'https://wordpress.org/plugins/post-smtp/other_notes/', 'https://wordpress.org/support/plugin/postman-smtp' ) );
|
106 |
+
printf( '<h4>%s</h4>', __( 'Diagnostic Test', Postman::TEXT_DOMAIN ) );
|
107 |
+
printf( '<p style="margin:0 10px">%s</p><br/>', sprintf( __( 'If you write for help, please include the following:', Postman::TEXT_DOMAIN ), 'https://wordpress.org/plugins/post-smtp/other_notes/', 'https://wordpress.org/support/plugin/postman-smtp' ) );
|
108 |
+
printf( '<textarea readonly="readonly" id="diagnostic-text" cols="80" rows="15">%s</textarea>', _x( 'Checking..', 'The "please wait" message', Postman::TEXT_DOMAIN ) );
|
109 |
print '</div>';
|
110 |
}
|
111 |
}
|
113 |
/**
|
114 |
*
|
115 |
* @author jasonhendriks
|
|
|
116 |
*/
|
117 |
class PostmanGetDiagnosticsViaAjax {
|
118 |
private $diagnostics;
|
121 |
/**
|
122 |
* Constructor
|
123 |
*
|
124 |
+
* @param PostmanOptions $options
|
125 |
*/
|
126 |
function __construct() {
|
127 |
+
$this->options = PostmanOptions::getInstance();
|
128 |
+
$this->authorizationToken = PostmanOAuthToken::getInstance();
|
129 |
$this->diagnostics = '';
|
130 |
+
PostmanUtils::registerAjaxHandler( 'postman_diagnostics', $this, 'getDiagnostics' );
|
131 |
}
|
132 |
+
private function addToDiagnostics( $header, $data ) {
|
133 |
+
if ( isset( $data ) ) {
|
134 |
+
$this->diagnostics .= sprintf( '%s: %s%s', $header, $data, PHP_EOL );
|
135 |
}
|
136 |
}
|
137 |
private function getActivePlugins() {
|
138 |
// from http://stackoverflow.com/questions/20488264/how-do-i-get-activated-plugin-list-in-wordpress-plugin-development
|
139 |
+
$apl = get_option( 'active_plugins' );
|
140 |
+
$plugins = get_plugins();
|
141 |
+
$pluginText = array();
|
142 |
foreach ( $apl as $p ) {
|
143 |
+
if ( isset( $plugins [ $p ] ) ) {
|
144 |
+
array_push( $pluginText, $plugins [ $p ] ['Name'] );
|
145 |
}
|
146 |
}
|
147 |
+
return implode( ', ', $pluginText );
|
148 |
}
|
149 |
private function getPhpDependencies() {
|
150 |
+
$apl = PostmanPreRequisitesCheck::getState();
|
151 |
+
$pluginText = array();
|
152 |
foreach ( $apl as $p ) {
|
153 |
+
array_push( $pluginText, $p ['name'] . '=' . ($p ['ready'] ? 'Yes' : 'No') );
|
154 |
}
|
155 |
+
return implode( ', ', $pluginText );
|
156 |
}
|
157 |
private function getTransports() {
|
158 |
$transports = '';
|
159 |
+
foreach ( PostmanTransportRegistry::getInstance()->getTransports() as $transport ) {
|
160 |
+
$transports .= ' : ' . $transport->getName();
|
161 |
}
|
162 |
return $transports;
|
163 |
}
|
164 |
+
|
165 |
/**
|
166 |
* Diagnostic Data test to current SMTP server
|
167 |
*
|
168 |
* @return string
|
169 |
*/
|
170 |
+
private function testConnectivity( PostmanModuleTransport $transport ) {
|
171 |
+
$hostname = $transport->getHostname( $this->options );
|
172 |
+
$port = $transport->getPort( $this->options );
|
173 |
+
if ( ! empty( $hostname ) && ! empty( $port ) ) {
|
174 |
+
$portTest = new PostmanPortTest( $transport->getHostname( $this->options ), $transport->getPort( $this->options ) );
|
175 |
+
$result = $portTest->genericConnectionTest( $this->options->getConnectionTimeout() );
|
176 |
+
if ( $result ) {
|
177 |
return 'Yes';
|
178 |
} else {
|
179 |
return 'No';
|
181 |
}
|
182 |
return 'n/a';
|
183 |
}
|
184 |
+
|
185 |
/**
|
186 |
* Inspects the $wp_filter variable and returns the plugins attached to it
|
187 |
* From: http://stackoverflow.com/questions/5224209/wordpress-how-do-i-get-all-the-registered-functions-for-the-content-filter
|
188 |
*/
|
189 |
+
private function getFilters( $hook = '' ) {
|
190 |
global $wp_filter;
|
191 |
+
if ( empty( $hook ) || ! isset( $wp_filter [ $hook ] ) ) {
|
192 |
+
return null; }
|
193 |
+
$functionArray = array();
|
194 |
+
foreach ( $wp_filter [ $hook ] as $functions ) {
|
195 |
foreach ( $functions as $function ) {
|
196 |
$thing = $function ['function'];
|
197 |
+
if ( is_array( $thing ) ) {
|
198 |
+
$name = get_class( $thing [0] ) . '->' . $thing [1];
|
199 |
+
array_push( $functionArray, $name );
|
200 |
} else {
|
201 |
+
array_push( $functionArray, $thing );
|
202 |
}
|
203 |
}
|
204 |
}
|
205 |
+
return implode( ', ', $functionArray );
|
206 |
}
|
207 |
+
|
208 |
/**
|
209 |
*/
|
210 |
public function getDiagnostics() {
|
211 |
+
$transportRegistry = PostmanTransportRegistry::getInstance();
|
212 |
+
$this->addToDiagnostics( 'OS', php_uname() );
|
213 |
+
$this->addToDiagnostics( 'PHP', PHP_OS . ' ' . PHP_VERSION . ' ' . setlocale( LC_CTYPE, 0 ) );
|
214 |
+
$this->addToDiagnostics( 'PHP Dependencies', $this->getPhpDependencies() );
|
215 |
+
$this->addToDiagnostics( 'WordPress', (is_multisite() ? 'Multisite ' : '') . get_bloginfo( 'version' ) . ' ' . get_locale() . ' ' . get_bloginfo( 'charset', 'display' ) );
|
216 |
+
$this->addToDiagnostics( 'WordPress Theme', wp_get_theme() );
|
217 |
+
$this->addToDiagnostics( 'WordPress Plugins', $this->getActivePlugins() );
|
218 |
{
|
219 |
+
$bindResult = apply_filters( 'postman_wp_mail_bind_status', null );
|
220 |
$wp_mail_file_name = 'n/a';
|
221 |
+
if ( class_exists( 'ReflectionFunction' ) ) {
|
222 |
+
$wp_mail = new ReflectionFunction( 'wp_mail' );
|
223 |
+
$wp_mail_file_name = realpath( $wp_mail->getFileName() );
|
224 |
+
}
|
225 |
+
if ( ! $bindResult ['bound'] ) {
|
226 |
+
$this->addToDiagnostics( 'WordPress wp_mail Owner', $wp_mail_file_name );
|
|
|
227 |
}
|
228 |
+
}
|
229 |
+
$this->addToDiagnostics( 'WordPress wp_mail Filter(s)', $this->getFilters( 'wp_mail' ) );
|
230 |
+
$this->addToDiagnostics( 'WordPress wp_mail_from Filter(s)', $this->getFilters( 'wp_mail_from' ) );
|
231 |
+
$this->addToDiagnostics( 'WordPress wp_mail_from_name Filter(s)', $this->getFilters( 'wp_mail_from_name' ) );
|
232 |
+
$this->addToDiagnostics( 'WordPress wp_mail_content_type Filter(s)', $this->getFilters( 'wp_mail_content_type' ) );
|
233 |
+
$this->addToDiagnostics( 'WordPress wp_mail_charset Filter(s)', $this->getFilters( 'wp_mail_charset' ) );
|
234 |
+
$this->addToDiagnostics( 'WordPress phpmailer_init Action(s)', $this->getFilters( 'phpmailer_init' ) );
|
235 |
+
$pluginData = apply_filters( 'postman_get_plugin_metadata', null );
|
236 |
+
$this->addToDiagnostics( 'Postman', $pluginData ['version'] );
|
237 |
{
|
238 |
+
$s1 = $this->options->getEnvelopeSender();
|
239 |
+
$s2 = $this->options->getMessageSenderEmail();
|
240 |
+
if ( ! empty( $s1 ) || ! empty( $s2 ) ) {
|
241 |
+
$this->addToDiagnostics( 'Postman Sender Domain (Envelope|Message)', ($hostname = substr( strrchr( $this->options->getEnvelopeSender(), '@' ), 1 )) . ' | ' . ($hostname = substr( strrchr( $this->options->getMessageSenderEmail(), '@' ), 1 )) );
|
242 |
+
}
|
243 |
}
|
244 |
+
$this->addToDiagnostics( 'Postman Prevent Message Sender Override (Email|Name)', ($this->options->isSenderEmailOverridePrevented() ? 'Yes' : 'No') . ' | ' . ($this->options->isSenderNameOverridePrevented() ? 'Yes' : 'No') );
|
245 |
{
|
246 |
// status of the active transport
|
247 |
+
$transport = $transportRegistry->getActiveTransport();
|
248 |
+
$this->addToDiagnostics( 'Postman Active Transport', sprintf( '%s (%s)', $transport->getName(), $transportRegistry->getPublicTransportUri( $transport ) ) );
|
249 |
+
$this->addToDiagnostics( 'Postman Active Transport Status (Ready|Connected)', ($transport->isConfiguredAndReady() ? 'Yes' : 'No') . ' | ' . ($this->testConnectivity( $transport )) );
|
250 |
}
|
251 |
+
if ( $transportRegistry->getActiveTransport() != $transportRegistry->getSelectedTransport() && $transportRegistry->getSelectedTransport() != null ) {
|
252 |
// status of the selected transport
|
253 |
+
$transport = $transportRegistry->getSelectedTransport();
|
254 |
+
$this->addToDiagnostics( 'Postman Selected Transport', sprintf( '%s (%s)', $transport->getName(), $transportRegistry->getPublicTransportUri( $transport ) ) );
|
255 |
+
$this->addToDiagnostics( 'Postman Selected Transport Status (Ready|Connected)', ($transport->isConfiguredAndReady() ? 'Yes' : 'No') . ' | ' . ($this->testConnectivity( $transport )) );
|
256 |
}
|
257 |
+
$this->addToDiagnostics( 'Postman Deliveries (Success|Fail)', (PostmanState::getInstance()->getSuccessfulDeliveries()) . ' | ' . (PostmanState::getInstance()->getFailedDeliveries()) );
|
258 |
+
if ( $this->options->getConnectionTimeout() != PostmanOptions::DEFAULT_TCP_CONNECTION_TIMEOUT || $this->options->getReadTimeout() != PostmanOptions::DEFAULT_TCP_READ_TIMEOUT ) {
|
259 |
+
$this->addToDiagnostics( 'Postman TCP Timeout (Connection|Read)', $this->options->getConnectionTimeout() . ' | ' . $this->options->getReadTimeout() );
|
260 |
}
|
261 |
+
if ( $this->options->isMailLoggingEnabled() != PostmanOptions::DEFAULT_MAIL_LOG_ENABLED || $this->options->getMailLoggingMaxEntries() != PostmanOptions::DEFAULT_MAIL_LOG_ENTRIES || $this->options->getTranscriptSize() != PostmanOptions::DEFAULT_TRANSCRIPT_SIZE ) {
|
262 |
+
$this->addToDiagnostics( 'Postman Email Log (Enabled|Limit|Transcript Size)', ($this->options->isMailLoggingEnabled() ? 'Yes' : 'No') . ' | ' . $this->options->getMailLoggingMaxEntries() . ' | ' . $this->options->getTranscriptSize() );
|
263 |
}
|
264 |
+
$this->addToDiagnostics( 'Postman Run Mode', $this->options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION ? null : $this->options->getRunMode() );
|
265 |
+
$this->addToDiagnostics( 'Postman PHP LogLevel', $this->options->getLogLevel() == PostmanLogger::ERROR_INT ? null : $this->options->getLogLevel() );
|
266 |
+
$this->addToDiagnostics( 'Postman Stealth Mode', $this->options->isStealthModeEnabled() ? 'Yes' : null );
|
267 |
+
$this->addToDiagnostics( 'Postman File Locking (Enabled|Temp Dir)', PostmanState::getInstance()->isFileLockingEnabled() ? null : 'No' . ' | ' . $this->options->getTempDirectory() );
|
268 |
+
$response = array(
|
269 |
+
'message' => $this->diagnostics,
|
270 |
);
|
271 |
+
wp_send_json_success( $response );
|
272 |
}
|
273 |
}
|
Postman/Postman-Mail/PostmanMandrillMailEngine.php
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
<?php
|
2 |
-
if (! class_exists
|
3 |
-
|
4 |
require_once 'mailchimp-mandrill-api-php-da3adc10042e/src/Mandrill.php';
|
5 |
-
|
6 |
/**
|
7 |
* Sends mail with Mandrill API
|
8 |
* https://mandrillapp.com/api/docs/messages.php.html
|
@@ -10,222 +10,221 @@ if (! class_exists ( "PostmanMandrillMailEngine" )) {
|
|
10 |
* @author jasonhendriks
|
11 |
*/
|
12 |
class PostmanMandrillMailEngine implements PostmanMailEngine {
|
13 |
-
|
14 |
// logger for all concrete classes - populate with setLogger($logger)
|
15 |
protected $logger;
|
16 |
-
|
17 |
// the result
|
18 |
private $transcript;
|
19 |
-
|
20 |
-
//
|
21 |
private $apiKey;
|
22 |
private $mandrillMessage;
|
23 |
-
|
24 |
/**
|
25 |
*
|
26 |
-
* @param unknown $senderEmail
|
27 |
-
* @param unknown $accessToken
|
28 |
*/
|
29 |
-
function __construct($apiKey) {
|
30 |
-
assert
|
31 |
$this->apiKey = $apiKey;
|
32 |
-
|
33 |
// create the logger
|
34 |
-
$this->logger = new PostmanLogger
|
35 |
-
|
36 |
// create the Message
|
37 |
-
$this->mandrillMessage = array
|
38 |
-
'to' => array
|
39 |
-
'headers' => array
|
40 |
);
|
41 |
}
|
42 |
-
|
43 |
/**
|
44 |
* (non-PHPdoc)
|
45 |
*
|
46 |
* @see PostmanSmtpEngine::send()
|
47 |
*/
|
48 |
-
public function send(PostmanMessage $message) {
|
49 |
-
$options = PostmanOptions::getInstance
|
50 |
-
|
51 |
// add the Postman signature - append it to whatever the user may have set
|
52 |
-
if (! $options->isStealthModeEnabled
|
53 |
-
$pluginData = apply_filters
|
54 |
-
$this->addHeader
|
55 |
}
|
56 |
-
|
57 |
// add the headers - see http://framework.zend.com/manual/1.12/en/zend.mail.additional-headers.html
|
58 |
-
foreach ( ( array ) $message->getHeaders
|
59 |
-
$this->logger->debug
|
60 |
-
$this->addHeader
|
61 |
}
|
62 |
-
|
63 |
// if the caller set a Content-Type header, use it
|
64 |
-
$contentType = $message->getContentType
|
65 |
-
if (! empty
|
66 |
-
$this->logger->debug
|
67 |
-
$this->addHeader
|
68 |
}
|
69 |
-
|
70 |
// add the From Header
|
71 |
-
$sender = $message->getFromAddress
|
72 |
{
|
73 |
-
$senderEmail =
|
74 |
-
$senderName = $sender->getName
|
75 |
-
assert
|
76 |
$this->mandrillMessage ['from_email'] = $senderEmail;
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
// now log it
|
81 |
-
$sender->log
|
82 |
}
|
83 |
-
|
84 |
// add the Sender Header, overriding what the user may have set
|
85 |
-
$this->addHeader
|
86 |
-
|
87 |
// add the to recipients
|
88 |
-
foreach ( ( array ) $message->getToRecipients
|
89 |
-
$recipient->log
|
90 |
-
$recipient = array
|
91 |
-
'email' => $recipient->getEmail
|
92 |
-
'name' => $recipient->getName
|
93 |
-
'type' => 'to'
|
94 |
);
|
95 |
-
array_push
|
96 |
}
|
97 |
-
|
98 |
// add the cc recipients
|
99 |
-
foreach ( ( array ) $message->getCcRecipients
|
100 |
-
$recipient->log
|
101 |
-
$recipient = array
|
102 |
-
'email' => $recipient->getEmail
|
103 |
-
'name' => $recipient->getName
|
104 |
-
'type' => 'cc'
|
105 |
);
|
106 |
-
array_push
|
107 |
}
|
108 |
-
|
109 |
// add the bcc recipients
|
110 |
-
foreach ( ( array ) $message->getBccRecipients
|
111 |
-
$recipient->log
|
112 |
-
$recipient = array
|
113 |
-
'email' => $recipient->getEmail
|
114 |
-
'name' => $recipient->getName
|
115 |
-
'type' => 'bcc'
|
116 |
);
|
117 |
-
array_push
|
118 |
}
|
119 |
-
|
120 |
// add the reply-to
|
121 |
-
$replyTo = $message->getReplyTo
|
122 |
// $replyTo is null or a PostmanEmailAddress object
|
123 |
-
if (isset
|
124 |
-
$this->addHeader
|
125 |
}
|
126 |
-
|
127 |
// add the date
|
128 |
-
$date = $message->getDate
|
129 |
-
if (! empty
|
130 |
-
$this->addHeader
|
131 |
}
|
132 |
-
|
133 |
// add the messageId
|
134 |
-
$messageId = $message->getMessageId
|
135 |
-
if (! empty
|
136 |
-
$this->addHeader
|
137 |
}
|
138 |
-
|
139 |
// add the subject
|
140 |
-
if (null !== $message->getSubject
|
141 |
-
$this->mandrillMessage ['subject'] = $message->getSubject
|
142 |
}
|
143 |
-
|
144 |
// add the message content
|
145 |
{
|
146 |
-
$textPart = $message->getBodyTextPart
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
$htmlPart = $message->getBodyHtmlPart
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
}
|
156 |
}
|
157 |
-
|
|
|
158 |
// add attachments
|
159 |
-
$this->logger->debug
|
160 |
-
$this->addAttachmentsToMail
|
161 |
-
|
162 |
-
$result = array
|
163 |
try {
|
164 |
-
if ($this->logger->isDebug
|
165 |
-
$this->logger->debug
|
166 |
}
|
167 |
-
$mandrill = new Postman_Mandrill
|
168 |
-
|
169 |
// send the message
|
170 |
-
if ($this->logger->isDebug
|
171 |
-
$this->logger->debug
|
172 |
}
|
173 |
-
|
174 |
-
$result = $mandrill->messages->send
|
175 |
-
if ($this->logger->isInfo
|
176 |
-
$this->logger->info
|
177 |
}
|
178 |
-
|
179 |
-
$this->transcript = print_r
|
180 |
$this->transcript .= PostmanModuleTransport::RAW_MESSAGE_FOLLOWS;
|
181 |
-
$this->transcript .= print_r
|
182 |
} catch ( Exception $e ) {
|
183 |
-
$this->transcript = $e->getMessage
|
184 |
$this->transcript .= PostmanModuleTransport::RAW_MESSAGE_FOLLOWS;
|
185 |
-
$this->transcript .= print_r
|
186 |
throw $e;
|
187 |
}
|
188 |
}
|
189 |
-
private function addHeader($key, $value, $append = false) {
|
190 |
-
$this->logger->debug
|
191 |
$header = &$this->mandrillMessage ['headers'];
|
192 |
-
if ($append && ! empty
|
193 |
-
$header [$key] = $header [$key] . ', ' . $value;
|
194 |
} else {
|
195 |
-
$header [$key] = $value;
|
196 |
}
|
197 |
}
|
198 |
-
|
199 |
/**
|
200 |
* Add attachments to the message
|
201 |
*
|
202 |
-
* @param Postman_Zend_Mail $mail
|
203 |
*/
|
204 |
-
private function addAttachmentsToMail(PostmanMessage $message) {
|
205 |
-
$attachments = $message->getAttachments
|
206 |
-
if (isset
|
207 |
-
$this->mandrillMessage ['attachments'] = array
|
208 |
-
if (! is_array
|
209 |
// WordPress may a single filename or a newline-delimited string list of multiple filenames
|
210 |
-
$attArray = explode
|
211 |
} else {
|
212 |
$attArray = $attachments;
|
213 |
}
|
214 |
// otherwise WordPress sends an array
|
215 |
foreach ( $attArray as $file ) {
|
216 |
-
if (! empty
|
217 |
-
$this->logger->debug
|
218 |
-
$attachment = array
|
219 |
'type' => 'attachment',
|
220 |
-
'name' => basename
|
221 |
-
'content' => file_get_contents
|
222 |
);
|
223 |
-
array_push
|
224 |
}
|
225 |
}
|
226 |
}
|
227 |
}
|
228 |
-
|
229 |
// return the SMTP session transcript
|
230 |
public function getTranscript() {
|
231 |
return $this->transcript;
|
1 |
<?php
|
2 |
+
if ( ! class_exists( 'PostmanMandrillMailEngine' ) ) {
|
3 |
+
|
4 |
require_once 'mailchimp-mandrill-api-php-da3adc10042e/src/Mandrill.php';
|
5 |
+
|
6 |
/**
|
7 |
* Sends mail with Mandrill API
|
8 |
* https://mandrillapp.com/api/docs/messages.php.html
|
10 |
* @author jasonhendriks
|
11 |
*/
|
12 |
class PostmanMandrillMailEngine implements PostmanMailEngine {
|
13 |
+
|
14 |
// logger for all concrete classes - populate with setLogger($logger)
|
15 |
protected $logger;
|
16 |
+
|
17 |
// the result
|
18 |
private $transcript;
|
19 |
+
|
|
|
20 |
private $apiKey;
|
21 |
private $mandrillMessage;
|
22 |
+
|
23 |
/**
|
24 |
*
|
25 |
+
* @param unknown $senderEmail
|
26 |
+
* @param unknown $accessToken
|
27 |
*/
|
28 |
+
function __construct( $apiKey ) {
|
29 |
+
assert( ! empty( $apiKey ) );
|
30 |
$this->apiKey = $apiKey;
|
31 |
+
|
32 |
// create the logger
|
33 |
+
$this->logger = new PostmanLogger( get_class( $this ) );
|
34 |
+
|
35 |
// create the Message
|
36 |
+
$this->mandrillMessage = array(
|
37 |
+
'to' => array(),
|
38 |
+
'headers' => array(),
|
39 |
);
|
40 |
}
|
41 |
+
|
42 |
/**
|
43 |
* (non-PHPdoc)
|
44 |
*
|
45 |
* @see PostmanSmtpEngine::send()
|
46 |
*/
|
47 |
+
public function send( PostmanMessage $message ) {
|
48 |
+
$options = PostmanOptions::getInstance();
|
49 |
+
|
50 |
// add the Postman signature - append it to whatever the user may have set
|
51 |
+
if ( ! $options->isStealthModeEnabled() |