From b8aa426abd13cc349472755263fe0c0e9e35b96f Mon Sep 17 00:00:00 2001 From: Tom Mortensen Date: Fri, 13 Dec 2024 15:39:22 -0800 Subject: [PATCH] Put file in correct place, oops --- emhttp/plugins/InstallKey.php | 84 ------------------- emhttp/plugins/dynamix/include/InstallKey.php | 9 +- 2 files changed, 5 insertions(+), 88 deletions(-) delete mode 100644 emhttp/plugins/InstallKey.php diff --git a/emhttp/plugins/InstallKey.php b/emhttp/plugins/InstallKey.php deleted file mode 100644 index 62b80a912..000000000 --- a/emhttp/plugins/InstallKey.php +++ /dev/null @@ -1,84 +0,0 @@ -isGetRequest = !empty($_SERVER) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET'; - $this->getHasUrlParam = $_GET !== null && !empty($_GET) && isset($_GET['url']); - - if ($this->isGetRequest && $this->getHasUrlParam) { - $this->installKey(); - } - } - - /** - * @param int $httpcode https://developer.mozilla.org/en-US/docs/Web/HTTP/Status - * @param string|array $result - strings are assumed to be encoded JSON. Arrays will be encoded to JSON. - */ - private function responseComplete($httpcode, $result) - { - $mutatedResult = is_array($result) ? json_encode($result) : $result; - - if ($this->isGetRequest && $this->getHasUrlParam) { // return JSON to the caller - header('Content-Type: application/json'); - http_response_code($httpcode); - exit((string)$mutatedResult); - } else { // return the result to the caller - return $mutatedResult; - } - } - - public function installKey($keyUrl = null) - { - $url = unscript($keyUrl ?? _var($_GET, 'url')); - $host = parse_url($url)['host'] ?? ''; - - if (!function_exists('_')) { - function _($text) {return $text;} - } - - if ($host && in_array($host, ['keys.lime-technology.com', 'lime-technology.com'])) { - $keyFile = basename($url); - exec("/usr/bin/wget -q -O " . escapeshellarg("/boot/config/$keyFile") . " " . escapeshellarg($url), $output, $returnVar); - - if ($returnVar === 0) { - $var = (array)@parse_ini_file('/var/local/emhttp/var.ini'); - if (_var($var, 'mdState') == "STARTED") { - return $this->responseComplete(200, ['status' => _('Please Stop array to complete key installation')], _('success') . ', ' . _('Please Stop array to complete key installation')); - } else { - return $this->responseComplete(200, ['status' => ''], _('success')); - } - } else { - @unlink(escapeshellarg("/boot/config/$keyFile")); - return $this->responseComplete(406, ['error' => _('download error') . " $returnVar"]); - } - } else { - return $this->responseComplete(406, ['error' => _('bad or missing key file') . ": $url"]); - } - } -} - -$isGetRequest = !empty($_SERVER) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET'; -$getHasUrlParam = $_GET !== null && !empty($_GET) && isset($_GET['url']); - -if ($isGetRequest && $getHasUrlParam) { - $keyInstaller = new KeyInstaller(); - $keyInstaller->installKey(); -} diff --git a/emhttp/plugins/dynamix/include/InstallKey.php b/emhttp/plugins/dynamix/include/InstallKey.php index 3f19f9e42..62b80a912 100644 --- a/emhttp/plugins/dynamix/include/InstallKey.php +++ b/emhttp/plugins/dynamix/include/InstallKey.php @@ -61,15 +61,16 @@ class KeyInstaller if ($returnVar === 0) { $var = (array)@parse_ini_file('/var/local/emhttp/var.ini'); if (_var($var, 'mdState') == "STARTED") { - return $this->responseComplete(200, ['status' => _('Please Stop array to complete key installation')], _('success') . ', ' . _('Please Stop array to complete key installation'));; + return $this->responseComplete(200, ['status' => _('Please Stop array to complete key installation')], _('success') . ', ' . _('Please Stop array to complete key installation')); } else { - return $this->responseComplete(200, ['status' => ''], _('success'));; + return $this->responseComplete(200, ['status' => ''], _('success')); } } else { - return $this->responseComplete(406, ['error' => _('download error') . " $returnVar"]);; + @unlink(escapeshellarg("/boot/config/$keyFile")); + return $this->responseComplete(406, ['error' => _('download error') . " $returnVar"]); } } else { - return $this->responseComplete(406, ['error' => _('bad or missing key file') . ": $url"]);; + return $this->responseComplete(406, ['error' => _('bad or missing key file') . ": $url"]); } } }