PhyrePanel/web/app/ShellApi.php

42 lines
1 KiB
PHP
Raw Normal View History

2023-11-27 20:32:39 +00:00
<?php
namespace App;
class ShellApi
{
public static function exec($command, $argsArray = [])
{
$args = '';
if (!empty($argsArray)) {
foreach ($argsArray as $arg) {
$args .= escapeshellarg($arg) . ' ';
}
}
2024-04-01 15:00:03 +00:00
$fullCommand = $command . ' ' . $args;
// Run the command as sudo "/usr/bin/sudo "
2024-04-01 14:33:57 +00:00
$execOutput = shell_exec("/usr/bin/sudo " . $fullCommand);
2023-11-27 20:57:30 +00:00
$execOutput = str_replace(PHP_EOL, '', $execOutput);
return $execOutput;
}
public static function callBin($command, $argsArray = [])
{
$args = '';
if (!empty($argsArray)) {
foreach ($argsArray as $arg) {
$args .= escapeshellarg($arg) . ' ';
}
}
2023-11-27 20:32:39 +00:00
$fullCommand = escapeshellarg('/usr/local/phyre/bin/' . $command . '.sh') . ' ' . $args;
$commandAsSudo = '/usr/bin/sudo ' . $fullCommand;
$execOutput = shell_exec($commandAsSudo);
return $execOutput;
}
}