2017-09-22 05:30:09 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-22 05:30:09 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-09-22 05:30:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Console\Commands\Environment;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
|
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
|
|
|
|
|
|
class EmailSettingsCommand extends Command
|
|
|
|
{
|
|
|
|
use EnvironmentWriterTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Config\Repository
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Set or update the email sending configuration for the Panel.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'p:environment:mail
|
|
|
|
{--driver= : The mail driver to use.}
|
|
|
|
{--email= : Email address that messages from the Panel will originate from.}
|
|
|
|
{--from= : The name emails from the Panel will appear to be from.}
|
|
|
|
{--encryption=}
|
|
|
|
{--host=}
|
|
|
|
{--port=}
|
2021-06-05 15:38:47 +00:00
|
|
|
{--endpoint=}
|
2017-09-22 05:30:09 +00:00
|
|
|
{--username=}
|
|
|
|
{--password=}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $variables = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EmailSettingsCommand constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(ConfigRepository $config)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle command execution.
|
2019-09-06 04:32:57 +00:00
|
|
|
*
|
2018-05-13 16:30:53 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\PterodactylException
|
2017-09-22 05:30:09 +00:00
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$this->variables['MAIL_DRIVER'] = $this->option('driver') ?? $this->choice(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_driver'),
|
|
|
|
[
|
2017-09-22 05:30:09 +00:00
|
|
|
'smtp' => 'SMTP Server',
|
|
|
|
'mail' => 'PHP\'s Internal Mail Function',
|
|
|
|
'mailgun' => 'Mailgun Transactional Email',
|
|
|
|
'mandrill' => 'Mandrill Transactional Email',
|
|
|
|
'postmark' => 'Postmarkapp Transactional Email',
|
2021-01-23 20:33:34 +00:00
|
|
|
],
|
|
|
|
$this->config->get('mail.driver', 'smtp')
|
2020-04-11 20:07:40 +00:00
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
|
|
|
$method = 'setup' . studly_case($this->variables['MAIL_DRIVER']) . 'DriverVariables';
|
|
|
|
if (method_exists($this, $method)) {
|
|
|
|
$this->{$method}();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->variables['MAIL_FROM'] = $this->option('email') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_mail_from'),
|
|
|
|
$this->config->get('mail.from.address')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
|
|
|
$this->variables['MAIL_FROM_NAME'] = $this->option('from') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_mail_name'),
|
|
|
|
$this->config->get('mail.from.name')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
|
|
|
$this->variables['MAIL_ENCRYPTION'] = $this->option('encryption') ?? $this->choice(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_encryption'),
|
|
|
|
['tls' => 'TLS', 'ssl' => 'SSL', '' => 'None'],
|
|
|
|
$this->config->get('mail.encryption', 'tls')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
|
|
|
$this->writeToEnvironment($this->variables);
|
|
|
|
|
|
|
|
$this->line('Updating stored environment configuration file.');
|
|
|
|
$this->line('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle variables for SMTP driver.
|
|
|
|
*/
|
|
|
|
private function setupSmtpDriverVariables()
|
|
|
|
{
|
|
|
|
$this->variables['MAIL_HOST'] = $this->option('host') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_smtp_host'),
|
|
|
|
$this->config->get('mail.host')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
|
|
|
$this->variables['MAIL_PORT'] = $this->option('port') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_smtp_port'),
|
|
|
|
$this->config->get('mail.port')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
|
|
|
$this->variables['MAIL_USERNAME'] = $this->option('username') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_smtp_username'),
|
|
|
|
$this->config->get('mail.username')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
|
|
|
$this->variables['MAIL_PASSWORD'] = $this->option('password') ?? $this->secret(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_smtp_password')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle variables for mailgun driver.
|
|
|
|
*/
|
|
|
|
private function setupMailgunDriverVariables()
|
|
|
|
{
|
|
|
|
$this->variables['MAILGUN_DOMAIN'] = $this->option('host') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_mailgun_domain'),
|
|
|
|
$this->config->get('services.mailgun.domain')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
2018-02-17 19:00:11 +00:00
|
|
|
$this->variables['MAILGUN_SECRET'] = $this->option('password') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_mailgun_secret'),
|
|
|
|
$this->config->get('services.mailgun.secret')
|
|
|
|
);
|
2021-06-05 15:38:47 +00:00
|
|
|
|
|
|
|
$this->variables['MAILGUN_ENDPOINT'] = $this->option('endpoint') ?? $this->ask(
|
|
|
|
trans('command/messages.environment.mail.ask_mailgun_endpoint'),
|
|
|
|
$this->config->get('services.mailgun.endpoint')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle variables for mandrill driver.
|
|
|
|
*/
|
|
|
|
private function setupMandrillDriverVariables()
|
|
|
|
{
|
|
|
|
$this->variables['MANDRILL_SECRET'] = $this->option('password') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_mandrill_secret'),
|
|
|
|
$this->config->get('services.mandrill.secret')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle variables for postmark driver.
|
|
|
|
*/
|
|
|
|
private function setupPostmarkDriverVariables()
|
|
|
|
{
|
|
|
|
$this->variables['MAIL_DRIVER'] = 'smtp';
|
|
|
|
$this->variables['MAIL_HOST'] = 'smtp.postmarkapp.com';
|
|
|
|
$this->variables['MAIL_PORT'] = 587;
|
|
|
|
$this->variables['MAIL_USERNAME'] = $this->variables['MAIL_PASSWORD'] = $this->option('username') ?? $this->ask(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.environment.mail.ask_postmark_username'),
|
|
|
|
$this->config->get('mail.username')
|
|
|
|
);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
}
|