Hide startup line from API response if user doesn't have startup permissions
This commit is contained in:
parent
9ae3c17913
commit
813a671571
2 changed files with 4 additions and 3 deletions
|
@ -10,16 +10,17 @@ class StartupCommandService
|
|||
* Generates a startup command for a given server instance.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param bool $hideAllValues
|
||||
* @return string
|
||||
*/
|
||||
public function handle(Server $server): string
|
||||
public function handle(Server $server, bool $hideAllValues = false): string
|
||||
{
|
||||
$find = ['{{SERVER_MEMORY}}', '{{SERVER_IP}}', '{{SERVER_PORT}}'];
|
||||
$replace = [$server->memory, $server->allocation->ip, $server->allocation->port];
|
||||
|
||||
foreach ($server->variables as $variable) {
|
||||
$find[] = '{{' . $variable->env_variable . '}}';
|
||||
$replace[] = $variable->user_viewable ? ($variable->server_value ?? $variable->default_value) : '[hidden]';
|
||||
$replace[] = ($variable->user_viewable && !$hideAllValues) ? ($variable->server_value ?? $variable->default_value) : '[hidden]';
|
||||
}
|
||||
|
||||
return str_replace($find, $replace, $server->startup);
|
||||
|
|
Reference in a new issue