|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Pterodactyl - Panel |
| 4 | + * Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +namespace Pterodactyl\Console\Commands\Environment; |
| 26 | + |
| 27 | +use Illuminate\Console\Command; |
| 28 | +use Pterodactyl\Traits\Commands\EnvironmentWriterTrait; |
| 29 | +use Illuminate\Contracts\Config\Repository as ConfigRepository; |
| 30 | + |
| 31 | +class EmailSettingsCommand extends Command |
| 32 | +{ |
| 33 | + use EnvironmentWriterTrait; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var \Illuminate\Contracts\Config\Repository |
| 37 | + */ |
| 38 | + protected $config; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var string |
| 42 | + */ |
| 43 | + protected $description = 'Set or update the email sending configuration for the Panel.'; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var string |
| 47 | + */ |
| 48 | + protected $signature = 'p:environment:mail |
| 49 | + {--driver= : The mail driver to use.} |
| 50 | + {--email= : Email address that messages from the Panel will originate from.} |
| 51 | + {--from= : The name emails from the Panel will appear to be from.} |
| 52 | + {--encryption=} |
| 53 | + {--host=} |
| 54 | + {--port=} |
| 55 | + {--username=} |
| 56 | + {--password=}'; |
| 57 | + |
| 58 | + /** |
| 59 | + * @var array |
| 60 | + */ |
| 61 | + protected $variables = []; |
| 62 | + |
| 63 | + /** |
| 64 | + * EmailSettingsCommand constructor. |
| 65 | + * |
| 66 | + * @param \Illuminate\Contracts\Config\Repository $config |
| 67 | + */ |
| 68 | + public function __construct(ConfigRepository $config) |
| 69 | + { |
| 70 | + parent::__construct(); |
| 71 | + |
| 72 | + $this->config = $config; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Handle command execution. |
| 77 | + */ |
| 78 | + public function handle() |
| 79 | + { |
| 80 | + $this->variables['MAIL_DRIVER'] = $this->option('driver') ?? $this->choice( |
| 81 | + trans('command/messages.environment.mail.ask_driver'), [ |
| 82 | + 'smtp' => 'SMTP Server', |
| 83 | + 'mail' => 'PHP\'s Internal Mail Function', |
| 84 | + 'mailgun' => 'Mailgun Transactional Email', |
| 85 | + 'mandrill' => 'Mandrill Transactional Email', |
| 86 | + 'postmark' => 'Postmarkapp Transactional Email', |
| 87 | + ], $this->config->get('mail.driver', 'smtp') |
| 88 | + ); |
| 89 | + |
| 90 | + $method = 'setup' . studly_case($this->variables['MAIL_DRIVER']) . 'DriverVariables'; |
| 91 | + if (method_exists($this, $method)) { |
| 92 | + $this->{$method}(); |
| 93 | + } |
| 94 | + |
| 95 | + $this->variables['MAIL_FROM'] = $this->option('email') ?? $this->ask( |
| 96 | + trans('command/messages.environment.mail.ask_mail_from'), $this->config->get('mail.from.address') |
| 97 | + ); |
| 98 | + |
| 99 | + $this->variables['MAIL_FROM_NAME'] = $this->option('from') ?? $this->ask( |
| 100 | + trans('command/messages.environment.mail.ask_mail_name'), $this->config->get('mail.from.name') |
| 101 | + ); |
| 102 | + |
| 103 | + $this->variables['MAIL_ENCRYPTION'] = $this->option('encryption') ?? $this->choice( |
| 104 | + trans('command/messages.environment.mail.ask_encryption'), ['tls' => 'TLS', 'ssl' => 'SSL', '' => 'None'], $this->config->get('mail.encryption', 'tls') |
| 105 | + ); |
| 106 | + |
| 107 | + $this->writeToEnvironment($this->variables); |
| 108 | + |
| 109 | + $this->line('Updating stored environment configuration file.'); |
| 110 | + $this->call('config:cache'); |
| 111 | + $this->line(''); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Handle variables for SMTP driver. |
| 116 | + */ |
| 117 | + private function setupSmtpDriverVariables() |
| 118 | + { |
| 119 | + $this->variables['MAIL_HOST'] = $this->option('host') ?? $this->ask( |
| 120 | + trans('command/messages.environment.mail.ask_smtp_host'), $this->config->get('mail.host') |
| 121 | + ); |
| 122 | + |
| 123 | + $this->variables['MAIL_PORT'] = $this->option('port') ?? $this->ask( |
| 124 | + trans('command/messages.environment.mail.ask_smtp_port'), $this->config->get('mail.port') |
| 125 | + ); |
| 126 | + |
| 127 | + $this->variables['MAIL_USERNAME'] = $this->option('username') ?? $this->ask( |
| 128 | + trans('command/messages.environment.mail.ask_smtp_username'), $this->config->get('mail.username') |
| 129 | + ); |
| 130 | + |
| 131 | + $this->variables['MAIL_PASSWORD'] = $this->option('password') ?? $this->secret( |
| 132 | + trans('command/messages.environment.mail.ask_smtp_password') |
| 133 | + ); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Handle variables for mailgun driver. |
| 138 | + */ |
| 139 | + private function setupMailgunDriverVariables() |
| 140 | + { |
| 141 | + $this->variables['MAILGUN_DOMAIN'] = $this->option('host') ?? $this->ask( |
| 142 | + trans('command/messages.environment.mail.ask_mailgun_domain'), $this->config->get('services.mailgun.domain') |
| 143 | + ); |
| 144 | + |
| 145 | + $this->variables['MAILGUN_KEY'] = $this->option('password') ?? $this->ask( |
| 146 | + trans('command/messages.environment.mail.ask_mailgun_secret'), $this->config->get('services.mailgun.secret') |
| 147 | + ); |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Handle variables for mandrill driver. |
| 152 | + */ |
| 153 | + private function setupMandrillDriverVariables() |
| 154 | + { |
| 155 | + $this->variables['MANDRILL_SECRET'] = $this->option('password') ?? $this->ask( |
| 156 | + trans('command/messages.environment.mail.ask_mandrill_secret'), $this->config->get('services.mandrill.secret') |
| 157 | + ); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Handle variables for postmark driver. |
| 162 | + */ |
| 163 | + private function setupPostmarkDriverVariables() |
| 164 | + { |
| 165 | + $this->variables['MAIL_DRIVER'] = 'smtp'; |
| 166 | + $this->variables['MAIL_HOST'] = 'smtp.postmarkapp.com'; |
| 167 | + $this->variables['MAIL_PORT'] = 587; |
| 168 | + $this->variables['MAIL_USERNAME'] = $this->variables['MAIL_PASSWORD'] = $this->option('username') ?? $this->ask( |
| 169 | + trans('command/messages.environment.mail.ask_postmark_username'), $this->config->get('mail.username') |
| 170 | + ); |
| 171 | + } |
| 172 | +} |
0 commit comments