$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);
}
?>