1*b4144a6dSGreg Roach<?php 2*b4144a6dSGreg Roach 3*b4144a6dSGreg Roach/** 4*b4144a6dSGreg Roach * webtrees: online genealogy 5*b4144a6dSGreg Roach * Copyright (C) 2019 webtrees development team 6*b4144a6dSGreg Roach * This program is free software: you can redistribute it and/or modify 7*b4144a6dSGreg Roach * it under the terms of the GNU General Public License as published by 8*b4144a6dSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*b4144a6dSGreg Roach * (at your option) any later version. 10*b4144a6dSGreg Roach * This program is distributed in the hope that it will be useful, 11*b4144a6dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*b4144a6dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*b4144a6dSGreg Roach * GNU General Public License for more details. 14*b4144a6dSGreg Roach * You should have received a copy of the GNU General Public License 15*b4144a6dSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*b4144a6dSGreg Roach */ 17*b4144a6dSGreg Roach 18*b4144a6dSGreg Roachdeclare(strict_types=1); 19*b4144a6dSGreg Roach 20*b4144a6dSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*b4144a6dSGreg Roach 22*b4144a6dSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 23*b4144a6dSGreg Roachuse Fisharebest\Webtrees\I18N; 24*b4144a6dSGreg Roachuse Fisharebest\Webtrees\Services\EmailService; 25*b4144a6dSGreg Roachuse Fisharebest\Webtrees\Site; 26*b4144a6dSGreg Roachuse Psr\Http\Message\ResponseInterface; 27*b4144a6dSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 28*b4144a6dSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 29*b4144a6dSGreg Roach 30*b4144a6dSGreg Roachuse function filter_var; 31*b4144a6dSGreg Roach 32*b4144a6dSGreg Roachuse const FILTER_VALIDATE_DOMAIN; 33*b4144a6dSGreg Roach 34*b4144a6dSGreg Roach/** 35*b4144a6dSGreg Roach * Edit the email preferences. 36*b4144a6dSGreg Roach */ 37*b4144a6dSGreg Roachclass EmailPreferencesPage implements RequestHandlerInterface 38*b4144a6dSGreg Roach{ 39*b4144a6dSGreg Roach use ViewResponseTrait; 40*b4144a6dSGreg Roach 41*b4144a6dSGreg Roach /** @var EmailService */ 42*b4144a6dSGreg Roach private $email_service; 43*b4144a6dSGreg Roach 44*b4144a6dSGreg Roach /** 45*b4144a6dSGreg Roach * AdminSiteController constructor. 46*b4144a6dSGreg Roach * 47*b4144a6dSGreg Roach * @param EmailService $email_service 48*b4144a6dSGreg Roach */ 49*b4144a6dSGreg Roach public function __construct(EmailService $email_service) 50*b4144a6dSGreg Roach { 51*b4144a6dSGreg Roach $this->email_service = $email_service; 52*b4144a6dSGreg Roach } 53*b4144a6dSGreg Roach 54*b4144a6dSGreg Roach /** 55*b4144a6dSGreg Roach * @param ServerRequestInterface $request 56*b4144a6dSGreg Roach * 57*b4144a6dSGreg Roach * @return ResponseInterface 58*b4144a6dSGreg Roach */ 59*b4144a6dSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 60*b4144a6dSGreg Roach { 61*b4144a6dSGreg Roach $mail_ssl_options = $this->email_service->mailSslOptions(); 62*b4144a6dSGreg Roach $mail_transport_options = $this->email_service->mailTransportOptions(); 63*b4144a6dSGreg Roach 64*b4144a6dSGreg Roach $title = I18N::translate('Sending email'); 65*b4144a6dSGreg Roach 66*b4144a6dSGreg Roach $SMTP_ACTIVE = Site::getPreference('SMTP_ACTIVE'); 67*b4144a6dSGreg Roach $SMTP_AUTH = Site::getPreference('SMTP_AUTH'); 68*b4144a6dSGreg Roach $SMTP_AUTH_USER = Site::getPreference('SMTP_AUTH_USER'); 69*b4144a6dSGreg Roach $SMTP_FROM_NAME = $this->email_service->senderEmail(); 70*b4144a6dSGreg Roach $SMTP_HELO = $this->email_service->localDomain(); 71*b4144a6dSGreg Roach $SMTP_HOST = Site::getPreference('SMTP_HOST'); 72*b4144a6dSGreg Roach $SMTP_PORT = Site::getPreference('SMTP_PORT'); 73*b4144a6dSGreg Roach $SMTP_SSL = Site::getPreference('SMTP_SSL'); 74*b4144a6dSGreg Roach $DKIM_DOMAIN = Site::getPreference('DKIM_DOMAIN'); 75*b4144a6dSGreg Roach $DKIM_SELECTOR = Site::getPreference('DKIM_SELECTOR'); 76*b4144a6dSGreg Roach $DKIM_KEY = Site::getPreference('DKIM_KEY'); 77*b4144a6dSGreg Roach 78*b4144a6dSGreg Roach $smtp_from_name_valid = $this->email_service->isValidEmail($SMTP_FROM_NAME); 79*b4144a6dSGreg Roach $smtp_helo_valid = filter_var($SMTP_HELO, FILTER_VALIDATE_DOMAIN); 80*b4144a6dSGreg Roach 81*b4144a6dSGreg Roach $this->layout = 'layouts/administration'; 82*b4144a6dSGreg Roach 83*b4144a6dSGreg Roach return $this->viewResponse('admin/site-mail', [ 84*b4144a6dSGreg Roach 'mail_ssl_options' => $mail_ssl_options, 85*b4144a6dSGreg Roach 'mail_transport_options' => $mail_transport_options, 86*b4144a6dSGreg Roach 'title' => $title, 87*b4144a6dSGreg Roach 'smtp_helo_valid' => $smtp_helo_valid, 88*b4144a6dSGreg Roach 'smtp_from_name_valid' => $smtp_from_name_valid, 89*b4144a6dSGreg Roach 'SMTP_ACTIVE' => $SMTP_ACTIVE, 90*b4144a6dSGreg Roach 'SMTP_AUTH' => $SMTP_AUTH, 91*b4144a6dSGreg Roach 'SMTP_AUTH_USER' => $SMTP_AUTH_USER, 92*b4144a6dSGreg Roach 'SMTP_FROM_NAME' => $SMTP_FROM_NAME, 93*b4144a6dSGreg Roach 'SMTP_HELO' => $SMTP_HELO, 94*b4144a6dSGreg Roach 'SMTP_HOST' => $SMTP_HOST, 95*b4144a6dSGreg Roach 'SMTP_PORT' => $SMTP_PORT, 96*b4144a6dSGreg Roach 'SMTP_SSL' => $SMTP_SSL, 97*b4144a6dSGreg Roach 'DKIM_DOMAIN' => $DKIM_DOMAIN, 98*b4144a6dSGreg Roach 'DKIM_SELECTOR' => $DKIM_SELECTOR, 99*b4144a6dSGreg Roach 'DKIM_KEY' => $DKIM_KEY, 100*b4144a6dSGreg Roach ]); 101*b4144a6dSGreg Roach } 102*b4144a6dSGreg Roach} 103