nickola / web-console

:desktop_computer: Simple web-based shell in your browser (outdated)
https://nickola.ru/projects/web-console
1.55k stars 347 forks source link

Alias not working #36

Open celorodovalho opened 6 years ago

celorodovalho commented 6 years ago

I have a hostgator shared account. In my .bashrc i have:

alias php='/opt/php71/bin/php'
alias composer='/home/XXX/bin/composer.phar'

In webconsole, when I try to run:

php -v

I got:

Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: x-requested-with, content-type

{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error","data":null}}

or when I try to run:

composer -v

I got:

sh: composer: command not found
celorodovalho commented 6 years ago

I must to do that in function "execute_command":

// Command execution
function execute_command($command) {
    $descriptors = array(
        0 => array('pipe', 'r'), // STDIN
        1 => array('pipe', 'w'), // STDOUT
        2 => array('pipe', 'w')  // STDERR
    );
    $preCommand = [
        'export HOME=/home/XXX'
    ];
    $commands = [
        'php' => '/opt/php71/bin/php',
        'composer.phar' => '/opt/php71/bin/php /home/XXX/bin/composer.phar',
        'composer' => '/opt/php71/bin/php /home/XXX/bin/composer.phar',
    ];
    foreach ($commands as $key => $cmd) {
        $command = preg_replace('/(^|\s)('.$key.')($|\s)/i', '$1'.$cmd.'$3', $command);
    }
    $preCommand = implode(' && ', $preCommand).' && ';

    $process = proc_open($preCommand.$command . ' 2>&1', $descriptors, $pipes);
    if (!is_resource($process)) die("Can't execute command.");

    // Nothing to push to STDIN
    fclose($pipes[0]);

    $output = stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    $error = stream_get_contents($pipes[2]);
    fclose($pipes[2]);

    // All pipes must be closed before "proc_close"
    $code = proc_close($process);

    return $output;
}