$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); } $headline = "
"; if ($_POST) { if (empty($_POST['id']) && $_POST['mode'] != 'reinstallall') { header("Location: pkg_mgr_installed.php"); return; } if (isset($_POST['pkgcancel']) || (empty($_POST['id']) && $_POST['mode'] != 'reinstallall')) { header("Location: pkg_mgr_installed.php"); return; } } else if ($_GET && !$_GET['id']) { if (empty($_GET['pkg']) && ($_GET['mode'] != 'reinstallall')) { header("Location: pkg_mgr_installed.php"); return; } switch ($_GET['mode']) { case 'reinstallall': $headline = gettext("Reinstall all packages"); case 'reinstallpkg': if ($_GET['from'] && $_GET['to']) { $headline = gettext("Upgrade package"); } else { $headline = gettext("Reinstall package"); } break; case 'delete': $headline = gettext("Remove package"); break; default: $headline = gettext("Install package"); break; } } if ($_GET && $_GET['id'] == "firmware") { $firmwareupdate = true; $firmwareversion = get_system_pkg_version(); $headline = gettext("System Update") ; } $tab_array = array(); if ($firmwareupdate || ($_POST['id'] == "firmware")) { $pgtitle = array(gettext("System"), gettext("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"), $headline); $tab_array[] = array(gettext("Available Packages"), false, "pkg_mgr.php"); $tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php"); $tab_array[] = array(gettext("Package Installer"), true, ""); } include("head.inc"); display_top_tabs($tab_array); if ($input_errors) { print_input_errors($input_errors); } ?>
", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401)); $pkgmode = 'installed'; } else if (!empty($_GET['mode']) && !empty($_GET['pkg'])) { $pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401)); $pkgmode = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['mode'], ENT_QUOTES | ENT_HTML401)); } else if ($_GET['mode'] == 'reinstallall') { $pkgmode = 'reinstallall'; } switch ($pkgmode) { case 'reinstallpkg': $pkgtxt = 'reinstalled'; break; case 'delete': $pkgtxt = 'removed'; break; default: $pkgtxt = $pkgmode; break; } ?>

Package: will be upgraded from to . Package: will be .



", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401)); } if ($_POST && ($_POST['completed'] != "true")) { /* Write out configuration to create a backup prior to pkg install. */ write_config(gettext("Creating restore point before package installation.")); $progbar = true; $upgrade_script = "/usr/local/sbin/{$g['product_name']}-upgrade -y -l {$g['tmp_path']}/webgui-log.txt -p {$g['tmp_path']}/webgui-log.sock"; switch ($_POST['mode']) { case 'delete': mwexec_bg("{$upgrade_script} -r {$pkgid}"); $start_polling = true; break; case 'reinstallall': if (is_array($config['installedpackages']) && is_array($config['installedpackages']['package'])) { $progbar = false; // We don't show the progress bar for reinstallall. It would be far too confusing mwexec_bg("{$upgrade_script} -i ALL_PACKAGES -f"); $start_polling = true; } break; case 'reinstallpkg': mwexec_bg("{$upgrade_script} -i {$pkgid} -f"); $start_polling = true; break; case 'installed': default: if ($pkgid == 'firmware') { mwexec_bg("{$upgrade_script}"); } else { mwexec_bg("{$upgrade_script} -i {$pkgid}"); } $start_polling = true; break; } } // $_POST['completed'] just means that we are refreshing the page to update any new menu items // that were installed if ($_POST && $_POST['completed'] == "true"): if (($pkgid == 'firmware') && ($_POST['reboot_needed'] == "yes")): ?>