thephpleague / climate

PHP's best friend for the terminal.
http://climate.thephpleague.com
MIT License
1.87k stars 126 forks source link

Exception: 2: exec() has been disabled for security reasons #182

Closed mariuszkrzaczkowski closed 3 years ago

mariuszkrzaczkowski commented 3 years ago

Is the exec function mandatory ??? my security policy does not allow it?

Exception: 2: exec() has been disabled for security reasons in /home/yfprod/html/vendor/league/climate/src/Util/System/System.php, line 66 in /home/yfprod/html/cli.php:18
Stack trace:
#0 [internal function]: {closure}()
#1 /home/yfprod/html/vendor/league/climate/src/Util/System/System.php(66): exec()
#2 /home/yfprod/html/vendor/league/climate/src/Util/System/Linux.php(38): League\CLImate\Util\System\System->exec()
#3 /home/yfprod/html/vendor/league/climate/src/Util/System/Linux.php(16): League\CLImate\Util\System\Linux->tput()
#4 /home/yfprod/html/vendor/league/climate/src/Util/UtilFactory.php(39): League\CLImate\Util\System\Linux->width()
#5 /home/yfprod/html/vendor/league/climate/src/TerminalObject/Dynamic/Checkbox/Checkbox.php(176): League\CLImate\Util\UtilFactory->width()
#6 /home/yfprod/html/vendor/league/climate/src/TerminalObject/Dynamic/Checkbox/Checkbox.php(164): League\CLImate\TerminalObject\Dynamic\Checkbox\Checkbox->getPaddingString()
#7 /home/yfprod/html/vendor/league/climate/src/TerminalObject/Dynamic/Checkbox/Checkbox.php(213): League\CLImate\TerminalObject\Dynamic\Checkbox\Checkbox->buildCheckboxString()
#8 /home/yfprod/html/vendor/league/climate/src/TerminalObject/Dynamic/Checkbox/CheckboxGroup.php(182): League\CLImate\TerminalObject\Dynamic\Checkbox\Checkbox->__toString()
#9 [internal function]: League\CLImate\TerminalObject\Dynamic\Checkbox\CheckboxGroup->writeCheckbox()
#10 /home/yfprod/html/vendor/league/climate/src/TerminalObject/Dynamic/Checkbox/CheckboxGroup.php(31): array_map()
#11 /home/yfprod/html/vendor/league/climate/src/TerminalObject/Dynamic/Checkboxes.php(157): League\CLImate\TerminalObject\Dynamic\Checkbox\CheckboxGroup->write()
#12 /home/yfprod/html/vendor/league/climate/src/TerminalObject/Dynamic/Checkboxes.php(68): League\CLImate\TerminalObject\Dynamic\Checkboxes->updateCheckboxView()
#13 /home/yfprod/html/vendor/league/climate/src/TerminalObject/Dynamic/Checkboxes.php(34): League\CLImate\TerminalObject\Dynamic\Checkboxes->writeCheckboxes()
#14 /home/yfprod/html/app/Cli.php(90): League\CLImate\TerminalObject\Dynamic\Checkboxes->prompt()
#15 /home/yfprod/html/app/Cli.php(76): App\Cli->modulesList()
#16 /home/yfprod/html/cli.php(23): App\Cli->__construct()
duncan3dc commented 3 years ago

We use exec() to figure out certain aspects of the terminal window based on the current operating system.

You can avoid the use of it by providing a custom System implementation yourself that provides the details of the environment, something like this:

$system = new class extends \League\CLImate\Util\System\System {
    public function width() {
        return 120;
    }
    public function height() {
        return 40;
    }
    protected function systemHasAnsiSupport() {
        return true;
    }
    public function exec($command, $full = false) {
        return '';
    }
};
$factory = new UtilFactory($system);
$climate->setUtil($factory);

Although I can see you're using checkboxes and we also depend on stty there, so I don't think the above will work correctly for your particular use case

mariuszkrzaczkowski commented 3 years ago

did not work :/ is there any other workaround for this? exec blocking multiple servers