|
|
@@ -15,41 +15,6 @@ class HestiaApp {
|
|
|
@mkdir(self::TMPDIR_DOWNLOADS);
|
|
|
}
|
|
|
|
|
|
- public function run(string $cmd, $args, &$cmd_result = null): bool {
|
|
|
- $cli_script = realpath(HESTIA_DIR_BIN . $cmd);
|
|
|
- if (!str_starts_with((string) $cli_script, HESTIA_DIR_BIN)) {
|
|
|
- $errstr = "$cmd is trying to traverse outside of " . HESTIA_DIR_BIN;
|
|
|
- trigger_error($errstr);
|
|
|
- throw new \Exception($errstr);
|
|
|
- }
|
|
|
- $cli_script = "/usr/bin/sudo " . quoteshellarg($cli_script);
|
|
|
-
|
|
|
- $cli_arguments = "";
|
|
|
- if (!empty($args) && is_array($args)) {
|
|
|
- foreach ($args as $arg) {
|
|
|
- $cli_arguments .= quoteshellarg((string) $arg) . " ";
|
|
|
- }
|
|
|
- } else {
|
|
|
- $cli_arguments = quoteshellarg($args);
|
|
|
- }
|
|
|
-
|
|
|
- exec($cli_script . " " . $cli_arguments . " 2>&1", $output, $exit_code);
|
|
|
-
|
|
|
- $result["code"] = $exit_code;
|
|
|
- $result["args"] = $cli_arguments;
|
|
|
- $result["raw"] = $output;
|
|
|
- $result["text"] = implode(PHP_EOL, $output);
|
|
|
- $result["json"] = json_decode($result["text"], true);
|
|
|
- $cmd_result = (object) $result;
|
|
|
- if ($exit_code > 0) {
|
|
|
- //log error message in nginx-error.log
|
|
|
- trigger_error($result["text"]);
|
|
|
- //throw exception if command fails
|
|
|
- throw new \Exception($result["text"]);
|
|
|
- }
|
|
|
- return $exit_code === 0;
|
|
|
- }
|
|
|
-
|
|
|
public function runUser(string $cmd, $args, &$cmd_result = null): bool {
|
|
|
if (!empty($args) && is_array($args)) {
|
|
|
array_unshift($args, $this->user());
|
|
|
@@ -364,4 +329,39 @@ class HestiaApp {
|
|
|
public function __destruct() {
|
|
|
$this->cleanupTmpDir();
|
|
|
}
|
|
|
+
|
|
|
+ private function run(string $cmd, $args, &$cmd_result = null): bool {
|
|
|
+ $cli_script = realpath(HESTIA_DIR_BIN . $cmd);
|
|
|
+ if (!str_starts_with((string) $cli_script, HESTIA_DIR_BIN)) {
|
|
|
+ $errstr = "$cmd is trying to traverse outside of " . HESTIA_DIR_BIN;
|
|
|
+ trigger_error($errstr);
|
|
|
+ throw new \Exception($errstr);
|
|
|
+ }
|
|
|
+ $cli_script = "/usr/bin/sudo " . quoteshellarg($cli_script);
|
|
|
+
|
|
|
+ $cli_arguments = "";
|
|
|
+ if (!empty($args) && is_array($args)) {
|
|
|
+ foreach ($args as $arg) {
|
|
|
+ $cli_arguments .= quoteshellarg((string) $arg) . " ";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $cli_arguments = quoteshellarg($args);
|
|
|
+ }
|
|
|
+
|
|
|
+ exec($cli_script . " " . $cli_arguments . " 2>&1", $output, $exit_code);
|
|
|
+
|
|
|
+ $result["code"] = $exit_code;
|
|
|
+ $result["args"] = $cli_arguments;
|
|
|
+ $result["raw"] = $output;
|
|
|
+ $result["text"] = implode(PHP_EOL, $output);
|
|
|
+ $result["json"] = json_decode($result["text"], true);
|
|
|
+ $cmd_result = (object) $result;
|
|
|
+ if ($exit_code > 0) {
|
|
|
+ //log error message in nginx-error.log
|
|
|
+ trigger_error($cli_script . " " . $cli_arguments . " | " . $result["text"]);
|
|
|
+ //throw exception if command fails
|
|
|
+ throw new \Exception($result["text"]);
|
|
|
+ }
|
|
|
+ return $exit_code === 0;
|
|
|
+ }
|
|
|
}
|