2016-09-20 23:33:32 +00:00
< ? php
/**
* Pterodactyl - Panel
2017-01-24 22:57:08 +00:00
* Copyright ( c ) 2015 - 2017 Dane Everitt < dane @ daneeveritt . com >.
2016-09-20 23:33:32 +00:00
*
* Permission is hereby granted , free of charge , to any person obtaining a copy
* of this software and associated documentation files ( the " Software " ), to deal
* in the Software without restriction , including without limitation the rights
* to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
* copies of the Software , and to permit persons to whom the Software is
* furnished to do so , subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE .
*/
2016-12-07 22:46:38 +00:00
2016-09-20 23:33:32 +00:00
namespace Pterodactyl\Console\Commands ;
use Illuminate\Console\Command ;
class UpdateEmailSettings extends Command
{
/**
* The name and signature of the console command .
*
* @ var string
*/
2016-10-12 23:02:15 +00:00
protected $signature = ' pterodactyl : mail
{ -- driver = }
{ -- email = }
2017-02-18 00:23:27 +00:00
{ -- from - name = }
2016-10-12 23:02:15 +00:00
{ -- host = }
{ -- port = }
{ -- username = }
{ -- password = } ' ;
2016-09-20 23:33:32 +00:00
/**
* The console command description .
*
* @ var string
*/
protected $description = 'Sets or updates email settings for the .env file.' ;
/**
* Create a new command instance .
*/
public function __construct ()
{
parent :: __construct ();
}
/**
* Execute the console command .
*
* @ return mixed
*/
public function handle ()
{
$variables = [];
$file = base_path () . '/.env' ;
2016-12-07 22:46:38 +00:00
if ( ! file_exists ( $file )) {
2016-09-20 23:33:32 +00:00
$this -> error ( 'Missing environment file! It appears that you have not installed this panel correctly.' );
exit ();
}
$envContents = file_get_contents ( $file );
$this -> table ([
'Option' ,
2016-12-07 22:46:38 +00:00
'Description' ,
2016-09-20 23:33:32 +00:00
], [
[
'smtp' ,
2016-12-07 22:46:38 +00:00
'SMTP Server Email' ,
2016-09-20 23:33:32 +00:00
],
[
'mail' ,
2016-12-07 22:46:38 +00:00
'PHP\'s Internal Mail Server' ,
2016-09-20 23:33:32 +00:00
],
[
'mailgun' ,
2016-12-07 22:46:38 +00:00
'Mailgun Email Service' ,
2016-09-20 23:33:32 +00:00
],
[
'mandrill' ,
2016-12-07 22:46:38 +00:00
'Mandrill Transactional Email Service' ,
2016-09-20 23:33:32 +00:00
],
[
'postmark' ,
2016-12-07 22:46:38 +00:00
'Postmark Transactional Email Service' ,
],
2016-09-20 23:33:32 +00:00
]);
2017-03-18 19:56:19 +00:00
2016-10-12 23:02:15 +00:00
$variables [ 'MAIL_DRIVER' ] = is_null ( $this -> option ( 'driver' )) ? $this -> choice ( 'Which email driver would you like to use?' , [
2016-09-20 23:33:32 +00:00
'smtp' ,
'mail' ,
'mailgun' ,
'mandrill' ,
2016-12-07 22:46:38 +00:00
'postmark' ,
2016-10-12 23:02:15 +00:00
]) : $this -> option ( 'driver' );
2016-09-20 23:33:32 +00:00
switch ( $variables [ 'MAIL_DRIVER' ]) {
case 'smtp' :
2017-03-18 19:56:19 +00:00
$variables [ 'MAIL_HOST' ] = is_null ( $this -> option ( 'host' )) ? $this -> ask ( 'SMTP Host (e.g smtp.google.com)' , config ( 'mail.host' )) : $this -> option ( 'host' );
$variables [ 'MAIL_PORT' ] = is_null ( $this -> option ( 'port' )) ? $this -> anticipate ( 'SMTP Host Port (e.g 587)' , [ '587' , config ( 'mail.port' )], config ( 'mail.port' )) : $this -> option ( 'port' );
$variables [ 'MAIL_USERNAME' ] = is_null ( $this -> option ( 'username' )) ? $this -> ask ( 'SMTP Username' , config ( 'mail.username' )) : $this -> option ( 'password' );
2016-10-12 23:02:15 +00:00
$variables [ 'MAIL_PASSWORD' ] = is_null ( $this -> option ( 'password' )) ? $this -> secret ( 'SMTP Password' ) : $this -> option ( 'password' );
2016-09-20 23:33:32 +00:00
break ;
case 'mail' :
break ;
case 'mailgun' :
2016-10-12 23:02:15 +00:00
$variables [ 'MAILGUN_DOMAIN' ] = is_null ( $this -> option ( 'host' )) ? $this -> ask ( 'Mailgun Domain' ) : $this -> option ( 'host' );
$variables [ 'MAILGUN_KEY' ] = is_null ( $this -> option ( 'username' )) ? $this -> ask ( 'Mailgun Key' ) : $this -> option ( 'username' );
2016-09-20 23:33:32 +00:00
break ;
case 'mandrill' :
2016-10-12 23:02:15 +00:00
$variables [ 'MANDRILL_SECRET' ] = is_null ( $this -> option ( 'username' )) ? $this -> ask ( 'Mandrill Secret' ) : $this -> option ( 'username' );
2016-09-20 23:33:32 +00:00
break ;
case 'postmark' :
2016-09-20 23:35:26 +00:00
$variables [ 'MAIL_DRIVER' ] = 'smtp' ;
2016-09-20 23:33:32 +00:00
$variables [ 'MAIL_HOST' ] = 'smtp.postmarkapp.com' ;
$variables [ 'MAIL_PORT' ] = 587 ;
2017-03-18 19:56:19 +00:00
$variables [ 'MAIL_USERNAME' ] = is_null ( $this -> option ( 'username' )) ? $this -> ask ( 'Postmark API Token' , config ( 'mail.username' )) : $this -> option ( 'username' );
2016-09-20 23:33:32 +00:00
$variables [ 'MAIL_PASSWORD' ] = $variables [ 'MAIL_USERNAME' ];
break ;
default :
$this -> error ( 'No email service was defined!' );
exit ();
break ;
}
2017-03-18 19:56:19 +00:00
$variables [ 'MAIL_FROM' ] = is_null ( $this -> option ( 'email' )) ? $this -> ask ( 'Email address emails should originate from' , config ( 'mail.from.address' )) : $this -> option ( 'email' );
$variables [ 'MAIL_FROM_NAME' ] = is_null ( $this -> option ( 'from-name' )) ? $this -> ask ( 'Name emails should appear to be from' , config ( 'mail.from.name' )) : $this -> option ( 'from-name' );
$variables [ 'MAIL_FROM_NAME' ] = '"' . $variables [ 'MAIL_FROM_NAME' ] . '"' ;
2016-09-20 23:33:32 +00:00
$variables [ 'MAIL_ENCRYPTION' ] = 'tls' ;
$bar = $this -> output -> createProgressBar ( count ( $variables ));
$this -> line ( 'Writing new email environment configuration to file.' );
foreach ( $variables as $key => $value ) {
2017-04-27 20:26:22 +00:00
if ( str_contains ( $value , ' ' ) && ! str_contains ( $value , '"' )) {
$value = '"' . $value . '"' ;
}
$newValue = $key . '=' . $value . ' # DO NOT EDIT! set using pterodactyl:mail' ;
2016-09-20 23:33:32 +00:00
if ( preg_match_all ( '/^' . $key . '=(.*)$/m' , $envContents ) < 1 ) {
$envContents = $envContents . " \n " . $newValue ;
} else {
$envContents = preg_replace ( '/^' . $key . '=(.*)$/m' , $newValue , $envContents );
}
$bar -> advance ();
}
file_put_contents ( $file , $envContents );
$bar -> finish ();
2017-02-02 20:06:35 +00:00
$this -> line ( 'Updating evironment configuration cache file.' );
$this -> call ( 'config:cache' );
2016-09-20 23:33:32 +00:00
echo " \n " ;
}
}