$running); // Process log file ----------------------------------------------------------------------------------------------- $logfile = @fopen($_REQUEST['logfilename'] . '.txt', "r"); if ($logfile != FALSE) { $resparray = array(); $statusarray = array(); $code = array(); // Log file is read a line at a time so that we can detect/modify certain entries while (($logline = fgets($logfile)) !== false) { // Check for return codes and replace with suitable strings if (strpos($logline, "__RC=") !== false) { $code = explode(" ", $logline); $rc = str_replace("__RC=", "", $code[0]); if (count($code) > 1 && strpos($code[1], "REBOOT_AFTER") !== false) { $statusarray['reboot_needed'] = "yes"; } else { $statusarray['reboot_needed'] = "no"; } if ($rc == 0) { $logline = gettext("Success") . "\n"; } else { $logline = gettext("Failed") . "\n"; } $response .= $logline; $statusarray['exitstatus'] = $rc; } else { $response .= htmlspecialchars($logline); } } fclose($logfile); $resparray['log'] = $response; } else { $resparray['log'] = "not_ready"; print(json_encode($resparray)); exit; } // Process progress file ------------------------------------------------------------------------------------------ $progress = ""; $progarray = array(); $JSONfile = @fopen($_REQUEST['logfilename'] . '.json', "r"); if ($JSONfile != FALSE) { while (($logline = fgets($JSONfile)) !== false) { if (!feof($JSONfile) && (strpos($logline, 'INFO_PROGRESS_TICK') !== false)) { if (strpos($logline, '}}') !== false) { $progress = $logline; } } } fclose($JSONfile); if (strlen($progress) > 0) { $progarray = json_decode($progress, true); } } // Glob all the arrays we have made together, and convert to JSON print(json_encode($resparray + $pidarray + $statusarray + $progarray)); exit; } function waitfor_string_in_file($filename, $string, $timeout) { $start = $now = time(); while (($now - $start) < $timeout) { $testfile = @fopen($filename, "r"); if ($testfile != FALSE) { while (($line = fgets($testfile)) !== false) { if (strpos($line, $string) !== false) { fclose($testfile); return(true); } } fclose($testfile); } usleep(100000); $now = time(); } return(false); } $pkgmode = ''; if (!empty($_REQUEST['mode'])) { $valid_modes = array( 'reinstallall', 'reinstallpkg', 'delete', 'installed' ); if (!in_array($_REQUEST['mode'], $valid_modes)) { header("Location: pkg_mgr_installed.php"); return; } $pkgmode = $_REQUEST['mode']; } // After a successful installation/removal/update the page is reloaded so that any menu changes show up // immediately. These values passed as POST arguments tell the page the state it was in before the reload. $confirmed = isset($_POST['confirmed']) && $_POST['confirmed'] == 'true'; $completed = isset($_POST['completed']) && $_POST['completed'] == 'true'; $reboot_needed = isset($_POST['reboot_needed']) && $_POST['reboot_needed'] == "yes"; if (!empty($_REQUEST['id'])) { if ($_REQUEST['id'] != "firmware") { header("Location: pkg_mgr_installed.php"); return; } $firmwareupdate = true; } elseif (!$completed && empty($_REQUEST['pkg']) && $pkgmode != 'reinstallall') { header("Location: pkg_mgr_installed.php"); return; } $pkgname = ''; if (!empty($_REQUEST['pkg'])) { $pkgname = $_REQUEST['pkg']; if (!pkg_valid_name($pkgname)) { header("Location: pkg_mgr_installed.php"); return; } } $tab_array = array(); if ($firmwareupdate) { $pgtitle = array(gettext("System"), gettext("Update"), gettext("System Update")); $tab_array[] = array(gettext("System Update"), true, ""); $tab_array[] = array(gettext("Update Settings"), false, "system_update_settings.php"); } else { $pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Package Installer")); $tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php"); $tab_array[] = array(gettext("Available Packages"), false, "pkg_mgr.php"); $tab_array[] = array(gettext("Package Installer"), true, ""); } include("head.inc"); ?>

%1$s removal successfully completed.'), $pkgname); $pkg_fail_txt = sprintf(gettext('%1$s removal failed!'), $pkgname); $pkg_wait_txt = sprintf(gettext('Please wait while the removal of %1$s completes.'), $pkgname); } else if ($pkgmode == 'reinstallall') { $panel_heading_txt = gettext("Packages Reinstallation"); $pkg_success_txt = gettext('All packages reinstallation successfully completed.'); $pkg_fail_txt = gettext('All packages reinstallation failed!'); $pkg_wait_txt = gettext('Please wait while the reinstallation of all packages completes.'); } else if ($pkgmode == 'reinstallpkg') { $panel_heading_txt = gettext("Package Reinstallation"); $pkg_success_txt = sprintf(gettext('%1$s reinstallation successfully completed.'), $pkgname); $pkg_fail_txt = sprintf(gettext('%1$s reinstallation failed!'), $pkgname); $pkg_wait_txt = sprintf(gettext('Please wait while the reinstallation of %1$s completes.'), $pkgname); } else { $panel_heading_txt = gettext("Package Installation"); $pkg_success_txt = sprintf(gettext('%1$s installation successfully completed.'), $pkgname); $pkg_fail_txt = sprintf(gettext('%1$s installation failed!'), $pkgname); $pkg_wait_txt = sprintf(gettext('Please wait while the installation of %1$s completes.'), $pkgname); } if ($confirmed): // XXX: What if the user navigates away from this page and then comes back via his/her "Back" button? $pidfile = $g['varrun_path'] . '/' . $g['product_name'] . '-upgrade.pid'; if (isvalidpid($pidfile)) { $start_polling = true; } ?>