| @@ -1,0 +1,143 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace AcyMailing\Controllers; | |
| 4 | + | |
| 5 | +use AcyMailing\Controllers\Configuration\Language; | |
| 6 | +use AcyMailing\Core\AcymController; | |
| 7 | +use AcyMailing\Controllers\Configuration\Listing; | |
| 8 | +use AcyMailing\Controllers\Configuration\Security; | |
| 9 | +use AcyMailing\Controllers\Configuration\Mail; | |
| 10 | +use AcyMailing\Controllers\Configuration\Queue; | |
| 11 | +use AcyMailing\Controllers\Configuration\Subscription; | |
| 12 | +use AcyMailing\Controllers\Configuration\License; | |
| 13 | + | |
| 14 | +class ConfigurationController extends AcymController | |
| 15 | +{ | |
| 16 | + use Listing; | |
| 17 | + use Security; | |
| 18 | + use Mail; | |
| 19 | + use Queue; | |
| 20 | + use Subscription; | |
| 21 | + use License; | |
| 22 | + use Language; | |
| 23 | + | |
| 24 | + const CRON_TASK_NAME = 'acymailing_automated_tasks_cron_task'; | |
| 25 | + | |
| 26 | + public function __construct() | |
| 27 | + { | |
| 28 | + parent::__construct(); | |
| 29 | + $this->breadcrumb[acym_translation('ACYM_CONFIGURATION')] = acym_completeLink('configuration'); | |
| 30 | + | |
| 31 | + $this->loadScripts = [ | |
| 32 | + 'listing' => [ | |
| 33 | + 'colorpicker', | |
| 34 | + ], | |
| 35 | + ]; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public function displayMessage(string $message, bool $ajax = false): array | |
| 39 | + { | |
| 40 | + $correspondences = [ | |
| 41 | + 'WEBSITE_NOT_FOUND' => ['message' => 'ACYM_WEBSITE_NOT_FOUND', 'type' => 'error'], | |
| 42 | + 'LICENSE_NOT_FOUND' => ['message' => 'ACYM_LICENSE_NOT_FOUND', 'type' => 'error'], | |
| 43 | + 'WELL_ATTACH' => ['message' => 'ACYM_LICENSE_WELL_ATTACH', 'type' => 'info'], | |
| 44 | + 'ISSUE_WHILE_ATTACH' => ['message' => 'ACYM_ISSUE_WHILE_ATTACHING_LICENSE', 'type' => 'error'], | |
| 45 | + 'ALREADY_ATTACH' => ['message' => 'ACYM_WEBSITE_ALREADY_ATTACHED', 'type' => 'info'], | |
| 46 | + 'LICENSES_DONT_MATCH' => ['message' => 'ACYM_CANT_UNLINK_WEBSITE_LICENSE_DONT_MATCH', 'type' => 'error'], | |
| 47 | + 'MAX_SITES_ATTACH' => ['message' => 'ACYM_REACHED_MAX_SITES_ATTACHED', 'type' => 'error'], | |
| 48 | + 'SITE_NOT_FOUND' => ['message' => 'ACYM_ISSUE_WHILE_ATTACHING_LICENSE', 'type' => 'error'], | |
| 49 | + 'UNLINK_SUCCESSFUL' => ['message' => 'ACYM_LICENSE_UNLINK_SUCCESSFUL', 'type' => 'info'], | |
| 50 | + 'UNLINK_FAILED' => ['message' => 'ACYM_ERROR_WHILE_UNLINK_LICENSE', 'type' => 'error'], | |
| 51 | + 'CRON_WELL_ACTIVATED' => ['message' => 'ACYM_AUTOMATIC_SEND_PROCESS_WELL_ACTIVATED', 'type' => 'info'], | |
| 52 | + 'CRON_WELL_DEACTIVATED' => ['message' => 'ACYM_AUTOMATIC_SEND_PROCESS_WELL_DEACTIVATED', 'type' => 'info'], | |
| 53 | + 'CRON_NOT_SAVED' => ['message' => 'ACYM_AUTOMATIC_SEND_PROCESS_NOT_ENABLED', 'type' => 'error'], | |
| 54 | + ]; | |
| 55 | + | |
| 56 | + if (!$ajax) { | |
| 57 | + if (empty($message) || empty($correspondences[$message])) { | |
| 58 | + acym_enqueueMessage(acym_translation('ACYM_ERROR_ON_CALL_ACYBA_WEBSITE'), 'error'); | |
| 59 | + | |
| 60 | + if (!empty($message)) { | |
| 61 | + $notification = [ | |
| 62 | + 'name' => 'curl_error', | |
| 63 | + 'removable' => 1, | |
| 64 | + ]; | |
| 65 | + acym_enqueueMessage(acym_translationSprintf('ACYM_CURL_ERROR_MESSAGE', $message), 'error', true, [$notification]); | |
| 66 | + } | |
| 67 | + | |
| 68 | + return []; | |
| 69 | + } | |
| 70 | + | |
| 71 | + acym_enqueueMessage(acym_translation($correspondences[$message]['message']), $correspondences[$message]['type']); | |
| 72 | + | |
| 73 | + return $correspondences[$message]['type'] === 'info' ? $correspondences[$message] : []; | |
| 74 | + } else { | |
| 75 | + if (empty($message) || empty($correspondences[$message])) { | |
| 76 | + $response = ['message' => acym_translation('ACYM_ERROR_ON_CALL_ACYBA_WEBSITE'), 'type' => 'error']; | |
| 77 | + | |
| 78 | + if (!empty($message)) $response['message'] = acym_translationSprintf('ACYM_CURL_ERROR_MESSAGE', $message); | |
| 79 | + | |
| 80 | + return $response; | |
| 81 | + } | |
| 82 | + | |
| 83 | + $response = $correspondences[$message]; | |
| 84 | + $response['message'] = acym_translation($response['message']); | |
| 85 | + | |
| 86 | + return $response; | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + public function seeLogs(): void | |
| 91 | + { | |
| 92 | + $filename = acym_getVar('string', 'filename', ''); | |
| 93 | + | |
| 94 | + if (empty($filename) || !acym_fileNameValid($filename)) { | |
| 95 | + echo esc_html(acym_translation('ACYM_FILENAME_EMPTY_OR_NOT_VALID')); | |
| 96 | + exit; | |
| 97 | + } | |
| 98 | + | |
| 99 | + $reportPath = acym_getLogPath($filename); | |
| 100 | + | |
| 101 | + if (!file_exists($reportPath)) { | |
| 102 | + echo esc_html(acym_translation('ACYM_EXIST_LOG')); | |
| 103 | + exit; | |
| 104 | + } | |
| 105 | + | |
| 106 | + if (ACYM_CMS === 'wordpress') @ob_get_clean(); | |
| 107 | + | |
| 108 | + $final = acym_fileGetContent($reportPath); | |
| 109 | + echo nl2br(esc_html($final)); | |
| 110 | + | |
| 111 | + exit; | |
| 112 | + } | |
| 113 | + | |
| 114 | + private function loginForOAuth2(bool $isSmtp = true): void | |
| 115 | + { | |
| 116 | + // Step 1: prompt consent window to the user | |
| 117 | + $this->store(); | |
| 118 | + | |
| 119 | + $redirectUrl = ''; | |
| 120 | + acym_trigger('onAcymOauthAuthenticate', [&$redirectUrl, $isSmtp]); | |
| 121 | + | |
| 122 | + if (empty($redirectUrl)) { | |
| 123 | + $this->listing(); | |
| 124 | + | |
| 125 | + return; | |
| 126 | + } | |
| 127 | + | |
| 128 | + acym_redirect($redirectUrl, '', 'message', false); | |
| 129 | + } | |
| 130 | + | |
| 131 | + public function handleOauthAuthentication(): void | |
| 132 | + { | |
| 133 | + // Step 2: get the access and refresh tokens after the user is redirected to the config with a code in the URL | |
| 134 | + $code = acym_getVar('string', 'code'); | |
| 135 | + | |
| 136 | + if (empty($code)) { | |
| 137 | + return; | |
| 138 | + } | |
| 139 | + | |
| 140 | + $isSmtp = acym_getVar('string', 'auth_type', 'smtp') === 'smtp'; | |
| 141 | + acym_trigger('onAcymOauthCredentialsCreation', [$isSmtp, $code]); | |
| 142 | + } | |
| 143 | +} | |