From 85dd7bd905ff5c9b8d87742f91bd3ff0f578fe13 Mon Sep 17 00:00:00 2001 From: darylc Date: Sat, 4 Jan 2025 19:13:44 +1030 Subject: [PATCH] refine User installed OS packages part 1 --- www/api/controllers/system.php | 7 +- www/packages.php | 198 ++++++++++++++++----------------- www/packagesHelper.php | 71 ++++++++++++ 3 files changed, 172 insertions(+), 104 deletions(-) create mode 100644 www/packagesHelper.php diff --git a/www/api/controllers/system.php b/www/api/controllers/system.php index 11b788a5f..231bd974d 100644 --- a/www/api/controllers/system.php +++ b/www/api/controllers/system.php @@ -438,9 +438,10 @@ function GetOSPackageInfo() { // Fetch package information using apt-cache show $output = shell_exec("apt-cache show " . escapeshellarg($packageName) . " 2>&1"); - - if (!$output) { - return ['error' => "Package '$packageName' not found or no information available."]; + if (!$output || strpos($output, 'E:') === 0) { + // Return error if apt-cache output is empty or contains an error + error_log("Package '$packageName' not found or invalid: $output"); + return json_encode(['error' => "Package '$packageName' not found or no information available."]); } // Check installation status using dpkg-query diff --git a/www/packages.php b/www/packages.php index 809e229ce..c09cb3cee 100644 --- a/www/packages.php +++ b/www/packages.php @@ -1,10 +1,11 @@ + + + + &1", 'r'); - if (is_resource($process)) { - while (!feof($process)) { - echo fread($process, 1024); - flush(); - } - pclose($process); - } - - // Add package to user-installed packages if not already added - if (!in_array(trim($packageName, "'"), $userPackages)) { - $userPackages[] = trim($packageName, "'"); - file_put_contents($userPackagesFile, json_encode($userPackages, JSON_PRETTY_PRINT)); - } - - exit; - } - - if ($action === 'uninstall' && !empty($packageName)) { - $packageName = escapeshellarg($packageName); - header('Content-Type: text/plain'); - - $process = popen("sudo apt-get remove -y $packageName 2>&1", 'r'); - if (is_resource($process)) { - while (!feof($process)) { - echo fread($process, 1024); - flush(); - } - pclose($process); - } - - // Remove package from user-installed packages - $userPackages = array_filter($userPackages, function($pkg) use ($packageName) { - return $pkg !== trim($packageName, "'"); - }); - file_put_contents($userPackagesFile, json_encode($userPackages, JSON_PRETTY_PRINT)); - - exit; - } - } - include 'common/menuHead.inc'; writeFPPVersionJavascriptFunctions(); ?>