This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Pterodactyl - Panel |
||
4 | * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. |
||
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; |
||
26 | |||
27 | use Illuminate\Console\Command; |
||
28 | |||
29 | class UpdateEmailSettings extends Command |
||
30 | { |
||
31 | /** |
||
32 | * The name and signature of the console command. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $signature = 'pterodactyl:mail |
||
37 | {--driver=} |
||
38 | {--email=} |
||
39 | {--from-name=} |
||
40 | {--host=} |
||
41 | {--port=} |
||
42 | {--username=} |
||
43 | {--password=}'; |
||
44 | |||
45 | /** |
||
46 | * The console command description. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $description = 'Sets or updates email settings for the .env file.'; |
||
51 | |||
52 | /** |
||
53 | * Create a new command instance. |
||
54 | * |
||
55 | * @return void |
||
0 ignored issues
–
show
|
|||
56 | */ |
||
57 | public function __construct() |
||
58 | { |
||
59 | parent::__construct(); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Execute the console command. |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | public function handle() |
||
68 | { |
||
69 | $variables = []; |
||
70 | $file = base_path() . '/.env'; |
||
71 | if (! file_exists($file)) { |
||
72 | $this->error('Missing environment file! It appears that you have not installed this panel correctly.'); |
||
73 | exit(); |
||
0 ignored issues
–
show
The method
handle() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
74 | } |
||
75 | |||
76 | $envContents = file_get_contents($file); |
||
77 | |||
78 | $this->table([ |
||
79 | 'Option', |
||
80 | 'Description', |
||
81 | ], [ |
||
82 | [ |
||
83 | 'smtp', |
||
84 | 'SMTP Server Email', |
||
85 | ], |
||
86 | [ |
||
87 | 'mail', |
||
88 | 'PHP\'s Internal Mail Server', |
||
89 | ], |
||
90 | [ |
||
91 | 'mailgun', |
||
92 | 'Mailgun Email Service', |
||
93 | ], |
||
94 | [ |
||
95 | 'mandrill', |
||
96 | 'Mandrill Transactional Email Service', |
||
97 | ], |
||
98 | [ |
||
99 | 'postmark', |
||
100 | 'Postmark Transactional Email Service', |
||
101 | ], |
||
102 | ]); |
||
103 | |||
104 | $variables['MAIL_DRIVER'] = is_null($this->option('driver')) ? $this->choice('Which email driver would you like to use?', [ |
||
105 | 'smtp', |
||
106 | 'mail', |
||
107 | 'mailgun', |
||
108 | 'mandrill', |
||
109 | 'postmark', |
||
110 | ]) : $this->option('driver'); |
||
111 | |||
112 | switch ($variables['MAIL_DRIVER']) { |
||
113 | case 'smtp': |
||
114 | $variables['MAIL_HOST'] = is_null($this->option('host')) ? $this->ask('SMTP Host (e.g smtp.google.com)', config('mail.host')) : $this->option('host'); |
||
115 | $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'); |
||
116 | $variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('SMTP Username', config('mail.username')) : $this->option('password'); |
||
117 | $variables['MAIL_PASSWORD'] = is_null($this->option('password')) ? $this->secret('SMTP Password') : $this->option('password'); |
||
118 | break; |
||
119 | case 'mail': |
||
120 | break; |
||
121 | case 'mailgun': |
||
122 | $variables['MAILGUN_DOMAIN'] = is_null($this->option('host')) ? $this->ask('Mailgun Domain') : $this->option('host'); |
||
123 | $variables['MAILGUN_KEY'] = is_null($this->option('username')) ? $this->ask('Mailgun Key') : $this->option('username'); |
||
124 | break; |
||
125 | case 'mandrill': |
||
126 | $variables['MANDRILL_SECRET'] = is_null($this->option('username')) ? $this->ask('Mandrill Secret') : $this->option('username'); |
||
127 | break; |
||
128 | case 'postmark': |
||
129 | $variables['MAIL_DRIVER'] = 'smtp'; |
||
130 | $variables['MAIL_HOST'] = 'smtp.postmarkapp.com'; |
||
131 | $variables['MAIL_PORT'] = 587; |
||
132 | $variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('Postmark API Token', config('mail.username')) : $this->option('username'); |
||
133 | $variables['MAIL_PASSWORD'] = $variables['MAIL_USERNAME']; |
||
134 | break; |
||
135 | default: |
||
136 | $this->error('No email service was defined!'); |
||
137 | exit(); |
||
0 ignored issues
–
show
The method
handle() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
138 | break; |
||
0 ignored issues
–
show
break; does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
139 | } |
||
140 | |||
141 | $variables['MAIL_FROM'] = is_null($this->option('email')) ? $this->ask('Email address emails should originate from', config('mail.from.address')) : $this->option('email'); |
||
142 | $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'); |
||
143 | $variables['MAIL_FROM_NAME'] = '"' . $variables['MAIL_FROM_NAME'] . '"'; |
||
144 | $variables['MAIL_ENCRYPTION'] = 'tls'; |
||
145 | |||
146 | $bar = $this->output->createProgressBar(count($variables)); |
||
147 | |||
148 | $this->line('Writing new email environment configuration to file.'); |
||
149 | View Code Duplication | foreach ($variables as $key => $value) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
150 | if (str_contains($value, ' ') && ! str_contains($value, '"')) { |
||
0 ignored issues
–
show
It seems like
$value defined by $value on line 149 can also be of type array ; however, str_contains() does only seem to accept string , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
151 | $value = '"' . $value . '"'; |
||
152 | } |
||
153 | $newValue = $key . '=' . $value . ' # DO NOT EDIT! set using pterodactyl:mail'; |
||
154 | |||
155 | if (preg_match_all('/^' . $key . '=(.*)$/m', $envContents) < 1) { |
||
156 | $envContents = $envContents . "\n" . $newValue; |
||
157 | } else { |
||
158 | $envContents = preg_replace('/^' . $key . '=(.*)$/m', $newValue, $envContents); |
||
159 | } |
||
160 | $bar->advance(); |
||
161 | } |
||
162 | |||
163 | file_put_contents($file, $envContents); |
||
164 | $bar->finish(); |
||
165 | |||
166 | $this->line('Updating evironment configuration cache file.'); |
||
167 | $this->call('config:cache'); |
||
168 | echo "\n"; |
||
169 | } |
||
170 | } |
||
171 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.