| @@ -2,17 +2,15 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace AcyMailing\Controllers\Configuration; |
| 4 | 4 | |
| 5 | 5 | use AcyMailing\Helpers\ExportHelper; |
| 6 | +use AcyMailing\Helpers\MailerHelper; | |
| 6 | 7 | |
| 7 | 8 | trait Mail |
| 8 | 9 | { |
| 9 | 10 | public function ports(): void |
| 10 | 11 | { |
| 11 | - if (!function_exists('fsockopen')) { | |
| 12 | - echo '<span style="color:red">'.acym_translation('ACYM_FSOCKOPEN').'</span>'; | |
| 13 | - exit; | |
| 14 | - } | |
| 12 | + $mailerHelper = new MailerHelper(); | |
| 15 | 13 | |
| 16 | 14 | $tests = [ |
| 17 | 15 | 25 => 'smtp.sendgrid.com', |
| 18 | 16 | 2525 => 'smtp.sendgrid.com', |
| @@ -19,19 +17,26 @@ | ||
| 19 | 17 | 587 => 'smtp.sendgrid.com', |
| 20 | 18 | 465 => 'ssl://smtp.gmail.com', |
| 21 | 19 | ]; |
| 22 | 20 | |
| 23 | - foreach ($tests as $port => $server) { | |
| 24 | - $fp = @fsockopen($server, $port, $errno, $errstr, 5); | |
| 25 | - if ($fp) { | |
| 26 | - echo '<span style="color:#3dea91">'.acym_translationSprintf('ACYM_SMTP_AVAILABLE_PORT', $port).'</span><br />'; | |
| 27 | - fclose($fp); | |
| 21 | + $response = []; | |
| 22 | + foreach ($tests as $port => $targetServer) { | |
| 23 | + if ($mailerHelper->isPortOpen($port, $targetServer)) { | |
| 24 | + $response[$port] = [ | |
| 25 | + 'open' => true, | |
| 26 | + 'port' => $port, | |
| 27 | + 'message' => acym_translationSprintf('ACYM_SMTP_AVAILABLE_PORT', $port), | |
| 28 | + ]; | |
| 28 | 29 | } else { |
| 29 | - echo '<span style="color:#ff5259">'.acym_translationSprintf('ACYM_SMTP_NOT_AVAILABLE_PORT', $port, $errno.' - '.acym_utf8Encode($errstr)).'</span><br />'; | |
| 30 | + $response[$port] = [ | |
| 31 | + 'open' => false, | |
| 32 | + 'port' => $port, | |
| 33 | + 'message' => acym_translationSprintf('ACYM_SMTP_NOT_AVAILABLE_PORT', $port, $mailerHelper->portError), | |
| 34 | + ]; | |
| 30 | 35 | } |
| 31 | 36 | } |
| 32 | 37 | |
| 33 | - exit; | |
| 38 | + acym_sendAjaxResponse('', $response); | |
| 34 | 39 | } |
| 35 | 40 | |
| 36 | 41 | public function testCredentialsSendingMethod(): void |
| 37 | 42 | { |
| @@ -75,8 +80,10 @@ | ||
| 75 | 80 | } |
| 76 | 81 | |
| 77 | 82 | public function synchronizeExistingUsers(): void |
| 78 | 83 | { |
| 84 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 85 | + | |
| 79 | 86 | $sendingMethod = acym_getVar('string', 'sendingMethod', ''); |
| 80 | 87 | |
| 81 | 88 | if (empty($sendingMethod)) { |
| 82 | 89 | acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_FIND_SENDING_METHOD'), [], false); |
| @@ -123,10 +130,13 @@ | ||
| 123 | 130 | } |
| 124 | 131 | |
| 125 | 132 | acym_createArchive($filename, $zipFiles); |
| 126 | 133 | |
| 127 | - if (ACYM_CMS === 'wordpress') @ob_get_clean(); | |
| 134 | + if (ob_get_level()) { | |
| 135 | + ob_end_clean(); | |
| 136 | + } | |
| 128 | 137 | $exportHelper->setDownloadHeaders($filenameToSearch, 'zip'); |
| 138 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Downloading a file, better than WP functions for memory handling. | |
| 129 | 139 | readfile($filename.'.zip'); |
| 130 | 140 | acym_deleteFile($filename.'.zip'); |
| 131 | 141 | |
| 132 | 142 | exit; |
| @@ -143,8 +153,10 @@ | ||
| 143 | 153 | } |
| 144 | 154 | |
| 145 | 155 | public function logoutForOAuth2Smtp(): void |
| 146 | 156 | { |
| 157 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 158 | + | |
| 147 | 159 | acym_trigger('onAcymOauthRevoke'); |
| 148 | 160 | |
| 149 | 161 | $this->listing(); |
| 150 | 162 | } |
| @@ -150,9 +162,11 @@ | ||
| 150 | 162 | } |
| 151 | 163 | |
| 152 | 164 | public function logoutForOAuth2Bounce(): void |
| 153 | 165 | { |
| 154 | - $this->config->save( | |
| 166 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 167 | + | |
| 168 | + $this->config->saveConfig( | |
| 155 | 169 | [ |
| 156 | 170 | 'bounce_refresh_token' => '', |
| 157 | 171 | 'bounce_refresh_token_expiration' => '', |
| 158 | 172 | ] |