Skip to content

Commit

Permalink
Update terminal.php
Browse files Browse the repository at this point in the history
  • Loading branch information
skerbis authored Sep 2, 2024
1 parent bed3f5d commit 98f56ba
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ public function __call(string $cmd, array $arg): string
return $this->runCommand($cmd . (isset($arg[0]) ? ' ' . $arg[0] : ''));
}


public function runCommand(string $command): string
{
$parts = explode(' ', $command, 2);
$cmd = $parts[0];
$arg = $parts[1] ?? '';

// Handle environment variable expansion
$arg = preg_replace_callback('/\$(\w+)/', function($matches) {
return $this->environment_variables[$matches[1]] ?? '';
}, $arg);

if (method_exists($this, '_' . $cmd)) {
$method = '_' . $cmd;
return $this->$method($arg);
}

if (in_array($cmd, $this->allowed_commands)) {
return trim(shell_exec($command) ?? '');
} else {
return "terminal.php: Permission denied for command: $cmd";
}
}

public function runCommand(string $command): string
{
$parts = explode(' ', $command, 2);
Expand Down

0 comments on commit 98f56ba

Please sign in to comment.