|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees: online genealogy |
|
5
|
|
|
* Copyright (C) 2019 webtrees development team |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* You should have received a copy of the GNU General Public License |
|
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
declare(strict_types=1); |
|
19
|
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees\Http\Controllers; |
|
21
|
|
|
|
|
22
|
|
|
use Fisharebest\Webtrees\FlashMessages; |
|
23
|
|
|
use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel; |
|
24
|
|
|
use Fisharebest\Webtrees\I18N; |
|
25
|
|
|
use Fisharebest\Webtrees\Module\ModuleThemeInterface; |
|
26
|
|
|
use Fisharebest\Webtrees\Services\MailService; |
|
27
|
|
|
use Fisharebest\Webtrees\Services\ModuleService; |
|
28
|
|
|
use Fisharebest\Webtrees\Site; |
|
29
|
|
|
use Illuminate\Support\Collection; |
|
30
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
31
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
32
|
|
|
|
|
33
|
|
|
use function filter_var; |
|
34
|
|
|
|
|
35
|
|
|
use const FILTER_VALIDATE_DOMAIN; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Controller for site administration. |
|
39
|
|
|
*/ |
|
40
|
|
|
class AdminSiteController extends AbstractBaseController |
|
41
|
|
|
{ |
|
42
|
|
|
/** @var string */ |
|
43
|
|
|
protected $layout = 'layouts/administration'; |
|
44
|
|
|
|
|
45
|
|
|
/** @var MailService */ |
|
46
|
|
|
private $mail_service; |
|
47
|
|
|
|
|
48
|
|
|
/** @var ModuleService */ |
|
49
|
|
|
private $module_service; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* AdminSiteController constructor. |
|
53
|
|
|
* |
|
54
|
|
|
* @param MailService $mail_service |
|
55
|
|
|
* @param ModuleService $module_service |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct(MailService $mail_service, ModuleService $module_service) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->mail_service = $mail_service; |
|
60
|
|
|
$this->module_service = $module_service; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param ServerRequestInterface $request |
|
65
|
|
|
* |
|
66
|
|
|
* @return ResponseInterface |
|
67
|
|
|
*/ |
|
68
|
|
|
public function mailForm(ServerRequestInterface $request): ResponseInterface |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
$mail_ssl_options = $this->mail_service->mailSslOptions(); |
|
71
|
|
|
$mail_transport_options = $this->mail_service->mailTransportOptions(); |
|
72
|
|
|
|
|
73
|
|
|
$title = I18N::translate('Sending email'); |
|
74
|
|
|
|
|
75
|
|
|
$SMTP_ACTIVE = Site::getPreference('SMTP_ACTIVE'); |
|
76
|
|
|
$SMTP_AUTH = Site::getPreference('SMTP_AUTH'); |
|
77
|
|
|
$SMTP_AUTH_USER = Site::getPreference('SMTP_AUTH_USER'); |
|
78
|
|
|
$SMTP_FROM_NAME = $this->mail_service->senderEmail(); |
|
79
|
|
|
$SMTP_HELO = $this->mail_service->localDomain(); |
|
80
|
|
|
$SMTP_HOST = Site::getPreference('SMTP_HOST'); |
|
81
|
|
|
$SMTP_PORT = Site::getPreference('SMTP_PORT'); |
|
82
|
|
|
$SMTP_SSL = Site::getPreference('SMTP_SSL'); |
|
83
|
|
|
$DKIM_DOMAIN = Site::getPreference('DKIM_DOMAIN'); |
|
84
|
|
|
$DKIM_SELECTOR = Site::getPreference('DKIM_SELECTOR'); |
|
85
|
|
|
$DKIM_KEY = Site::getPreference('DKIM_KEY'); |
|
86
|
|
|
|
|
87
|
|
|
$smtp_from_name_valid = $this->mail_service->isValidEmail($SMTP_FROM_NAME); |
|
88
|
|
|
$smtp_helo_valid = filter_var($SMTP_HELO, FILTER_VALIDATE_DOMAIN); |
|
89
|
|
|
|
|
90
|
|
|
return $this->viewResponse('admin/site-mail', [ |
|
91
|
|
|
'mail_ssl_options' => $mail_ssl_options, |
|
92
|
|
|
'mail_transport_options' => $mail_transport_options, |
|
93
|
|
|
'title' => $title, |
|
94
|
|
|
'smtp_helo_valid' => $smtp_helo_valid, |
|
95
|
|
|
'smtp_from_name_valid' => $smtp_from_name_valid, |
|
96
|
|
|
'SMTP_ACTIVE' => $SMTP_ACTIVE, |
|
97
|
|
|
'SMTP_AUTH' => $SMTP_AUTH, |
|
98
|
|
|
'SMTP_AUTH_USER' => $SMTP_AUTH_USER, |
|
99
|
|
|
'SMTP_FROM_NAME' => $SMTP_FROM_NAME, |
|
100
|
|
|
'SMTP_HELO' => $SMTP_HELO, |
|
101
|
|
|
'SMTP_HOST' => $SMTP_HOST, |
|
102
|
|
|
'SMTP_PORT' => $SMTP_PORT, |
|
103
|
|
|
'SMTP_SSL' => $SMTP_SSL, |
|
104
|
|
|
'DKIM_DOMAIN' => $DKIM_DOMAIN, |
|
105
|
|
|
'DKIM_SELECTOR' => $DKIM_SELECTOR, |
|
106
|
|
|
'DKIM_KEY' => $DKIM_KEY, |
|
107
|
|
|
]); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param ServerRequestInterface $request |
|
112
|
|
|
* |
|
113
|
|
|
* @return ResponseInterface |
|
114
|
|
|
*/ |
|
115
|
|
|
public function mailSave(ServerRequestInterface $request): ResponseInterface |
|
116
|
|
|
{ |
|
117
|
|
|
$params = $request->getParsedBody(); |
|
118
|
|
|
|
|
119
|
|
|
Site::setPreference('SMTP_ACTIVE', $params['SMTP_ACTIVE']); |
|
120
|
|
|
Site::setPreference('SMTP_FROM_NAME', $params['SMTP_FROM_NAME']); |
|
121
|
|
|
Site::setPreference('SMTP_HOST', $params['SMTP_HOST']); |
|
122
|
|
|
Site::setPreference('SMTP_PORT', $params['SMTP_PORT']); |
|
123
|
|
|
Site::setPreference('SMTP_AUTH', $params['SMTP_AUTH']); |
|
124
|
|
|
Site::setPreference('SMTP_AUTH_USER', $params['SMTP_AUTH_USER']); |
|
125
|
|
|
Site::setPreference('SMTP_SSL', $params['SMTP_SSL']); |
|
126
|
|
|
Site::setPreference('SMTP_HELO', $params['SMTP_HELO']); |
|
127
|
|
|
Site::setPreference('DKIM_DOMAIN', $params['DKIM_DOMAIN']); |
|
128
|
|
|
Site::setPreference('DKIM_SELECTOR', $params['DKIM_SELECTOR']); |
|
129
|
|
|
Site::setPreference('DKIM_KEY', $params['DKIM_KEY']); |
|
130
|
|
|
|
|
131
|
|
|
if ($params['SMTP_AUTH_PASS'] !== '') { |
|
132
|
|
|
Site::setPreference('SMTP_AUTH_PASS', $params['SMTP_AUTH_PASS']); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
FlashMessages::addMessage(I18N::translate('The website preferences have been updated.'), 'success'); |
|
136
|
|
|
$url = route(ControlPanel::class); |
|
137
|
|
|
|
|
138
|
|
|
return redirect($url); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @param ServerRequestInterface $request |
|
143
|
|
|
* |
|
144
|
|
|
* @return ResponseInterface |
|
145
|
|
|
*/ |
|
146
|
|
|
public function preferencesForm(ServerRequestInterface $request): ResponseInterface |
|
|
|
|
|
|
147
|
|
|
{ |
|
148
|
|
|
$all_themes = $this->themeOptions(); |
|
149
|
|
|
|
|
150
|
|
|
$title = I18N::translate('Website preferences'); |
|
151
|
|
|
|
|
152
|
|
|
return $this->viewResponse('admin/site-preferences', [ |
|
153
|
|
|
'all_themes' => $all_themes, |
|
154
|
|
|
'max_execution_time' => (int) get_cfg_var('max_execution_time'), |
|
155
|
|
|
'title' => $title, |
|
156
|
|
|
]); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @return Collection |
|
161
|
|
|
*/ |
|
162
|
|
|
private function themeOptions(): Collection |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->module_service |
|
165
|
|
|
->findByInterface(ModuleThemeInterface::class) |
|
166
|
|
|
->map($this->module_service->titleMapper()); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param ServerRequestInterface $request |
|
171
|
|
|
* |
|
172
|
|
|
* @return ResponseInterface |
|
173
|
|
|
*/ |
|
174
|
|
|
public function preferencesSave(ServerRequestInterface $request): ResponseInterface |
|
175
|
|
|
{ |
|
176
|
|
|
$params = $request->getParsedBody(); |
|
177
|
|
|
|
|
178
|
|
|
$INDEX_DIRECTORY = $params['INDEX_DIRECTORY']; |
|
179
|
|
|
if (substr($INDEX_DIRECTORY, -1) !== '/') { |
|
180
|
|
|
$INDEX_DIRECTORY .= '/'; |
|
181
|
|
|
} |
|
182
|
|
|
if (is_dir($INDEX_DIRECTORY)) { |
|
183
|
|
|
Site::setPreference('INDEX_DIRECTORY', $INDEX_DIRECTORY); |
|
184
|
|
|
} else { |
|
185
|
|
|
FlashMessages::addMessage(I18N::translate('The folder “%s” does not exist.', e($INDEX_DIRECTORY)), 'danger'); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
Site::setPreference('THEME_DIR', $params['THEME_DIR']); |
|
189
|
|
|
Site::setPreference('ALLOW_CHANGE_GEDCOM', $params['ALLOW_CHANGE_GEDCOM']); |
|
190
|
|
|
Site::setPreference('TIMEZONE', $params['TIMEZONE']); |
|
191
|
|
|
|
|
192
|
|
|
FlashMessages::addMessage(I18N::translate('The website preferences have been updated.'), 'success'); |
|
193
|
|
|
$url = route(ControlPanel::class); |
|
194
|
|
|
|
|
195
|
|
|
return redirect($url); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @param ServerRequestInterface $request |
|
200
|
|
|
* |
|
201
|
|
|
* @return ResponseInterface |
|
202
|
|
|
*/ |
|
203
|
|
|
public function registrationForm(ServerRequestInterface $request): ResponseInterface |
|
|
|
|
|
|
204
|
|
|
{ |
|
205
|
|
|
$title = I18N::translate('Sign-in and registration'); |
|
206
|
|
|
|
|
207
|
|
|
$registration_text_options = $this->registrationTextOptions(); |
|
208
|
|
|
|
|
209
|
|
|
return $this->viewResponse('admin/site-registration', [ |
|
210
|
|
|
'registration_text_options' => $registration_text_options, |
|
211
|
|
|
'title' => $title, |
|
212
|
|
|
]); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* A list of registration rules (e.g. for an edit control). |
|
217
|
|
|
* |
|
218
|
|
|
* @return string[] |
|
219
|
|
|
*/ |
|
220
|
|
|
private function registrationTextOptions(): array |
|
221
|
|
|
{ |
|
222
|
|
|
return [ |
|
223
|
|
|
0 => I18N::translate('No predefined text'), |
|
224
|
|
|
1 => I18N::translate('Predefined text that states all users can request a user account'), |
|
225
|
|
|
2 => I18N::translate('Predefined text that states admin will decide on each request for a user account'), |
|
226
|
|
|
3 => I18N::translate('Predefined text that states only family members can request a user account'), |
|
227
|
|
|
4 => I18N::translate('Choose user defined welcome text typed below'), |
|
228
|
|
|
]; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @param ServerRequestInterface $request |
|
233
|
|
|
* |
|
234
|
|
|
* @return ResponseInterface |
|
235
|
|
|
*/ |
|
236
|
|
|
public function registrationSave(ServerRequestInterface $request): ResponseInterface |
|
237
|
|
|
{ |
|
238
|
|
|
$params = $request->getParsedBody(); |
|
239
|
|
|
|
|
240
|
|
|
Site::setPreference('WELCOME_TEXT_AUTH_MODE', $params['WELCOME_TEXT_AUTH_MODE']); |
|
241
|
|
|
Site::setPreference('WELCOME_TEXT_AUTH_MODE_' . WT_LOCALE, $params['WELCOME_TEXT_AUTH_MODE_4']); |
|
242
|
|
|
Site::setPreference('USE_REGISTRATION_MODULE', $params['USE_REGISTRATION_MODULE']); |
|
243
|
|
|
Site::setPreference('SHOW_REGISTER_CAUTION', $params['SHOW_REGISTER_CAUTION']); |
|
244
|
|
|
|
|
245
|
|
|
FlashMessages::addMessage(I18N::translate('The website preferences have been updated.'), 'success'); |
|
246
|
|
|
$url = route(ControlPanel::class); |
|
247
|
|
|
|
|
248
|
|
|
return redirect($url); |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.