2017-12-15 03:05:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Settings;
|
|
|
|
|
2018-09-15 23:43:22 +00:00
|
|
|
use Exception;
|
2017-12-15 03:05:26 +00:00
|
|
|
use Illuminate\View\View;
|
2018-09-15 23:59:07 +00:00
|
|
|
use Illuminate\Http\Request;
|
2018-09-16 02:49:16 +00:00
|
|
|
use Illuminate\Http\Response;
|
2017-12-15 03:05:26 +00:00
|
|
|
use Illuminate\Contracts\Console\Kernel;
|
2018-09-15 23:59:07 +00:00
|
|
|
use Pterodactyl\Notifications\MailTested;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\View\Factory as ViewFactory;
|
2018-09-15 23:59:07 +00:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
2017-12-15 03:05:26 +00:00
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Contracts\Encryption\Encrypter;
|
|
|
|
use Pterodactyl\Providers\SettingsServiceProvider;
|
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
|
|
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Settings\MailSettingsFormRequest;
|
|
|
|
|
|
|
|
class MailController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* MailController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
private ConfigRepository $config,
|
|
|
|
private Encrypter $encrypter,
|
|
|
|
private Kernel $kernel,
|
|
|
|
private SettingsRepositoryInterface $settings,
|
|
|
|
private ViewFactory $view
|
2017-12-15 03:05:26 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render UI for editing mail settings. This UI should only display if
|
|
|
|
* the server is configured to send mail using SMTP.
|
|
|
|
*/
|
|
|
|
public function index(): View
|
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
return $this->view->make('admin.settings.mail', [
|
2017-12-15 03:05:26 +00:00
|
|
|
'disabled' => $this->config->get('mail.driver') !== 'smtp',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to update SMTP mail settings.
|
|
|
|
*
|
2018-05-13 16:19:35 +00:00
|
|
|
* @throws DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-12-15 03:05:26 +00:00
|
|
|
*/
|
2018-09-16 02:49:16 +00:00
|
|
|
public function update(MailSettingsFormRequest $request): Response
|
2017-12-15 03:05:26 +00:00
|
|
|
{
|
|
|
|
if ($this->config->get('mail.driver') !== 'smtp') {
|
2018-09-15 23:53:59 +00:00
|
|
|
throw new DisplayException('This feature is only available if SMTP is the selected email driver for the Panel.');
|
2017-12-15 03:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$values = $request->normalize();
|
|
|
|
if (array_get($values, 'mail:password') === '!e') {
|
|
|
|
$values['mail:password'] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
2021-01-23 20:33:34 +00:00
|
|
|
if (in_array($key, SettingsServiceProvider::getEncryptedKeys()) && !empty($value)) {
|
2017-12-15 03:05:26 +00:00
|
|
|
$value = $this->encrypter->encrypt($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->settings->set('settings::' . $key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->kernel->call('queue:restart');
|
|
|
|
|
2018-09-16 02:49:16 +00:00
|
|
|
return response('', 204);
|
2017-12-15 03:05:26 +00:00
|
|
|
}
|
2018-09-15 23:43:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit a request to send a test mail message.
|
|
|
|
*/
|
2018-09-16 02:49:16 +00:00
|
|
|
public function test(Request $request): Response
|
2018-09-15 23:43:22 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
Notification::route('mail', $request->user()->email)
|
|
|
|
->notify(new MailTested($request->user()));
|
|
|
|
} catch (Exception $exception) {
|
2018-09-16 02:49:16 +00:00
|
|
|
return response($exception->getMessage(), 500);
|
2018-09-15 23:43:22 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 02:49:16 +00:00
|
|
|
return response('', 204);
|
2018-09-15 23:43:22 +00:00
|
|
|
}
|
2017-12-15 03:05:26 +00:00
|
|
|
}
|