$running);
// Process log file -----------------------------------------------------------------------------------------------
$logfile = @fopen($_REQUEST['logfilename'] . '.txt', "r");
if ($logfile != FALSE) {
$resparray = array();
$statusarray = 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 = str_replace("__RC=", "", $logline);
if ($code == 0) {
$logline = gettext("Success") . "\n";
} else {
$logline = gettext("Failed") . "\n";
}
$response .= $logline;
$statusarray = array('exitstatus' => $code);
} 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['from']) {
$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();
}
$pgtitle = array(gettext("System"),gettext("Package Manager"), $headline);
include("head.inc");
$tab_array = array();
$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
if($firmwareupdate) {
$tab_array[] = array(gettext("System update"), true, "");
} else {
$tab_array[] = array(gettext("Package Installer"), true, "");
}
if($firmwareupdate) {
$tab_array[] = array(gettext("Update Settings"), false, "system_update_settings.php");
}
display_top_tabs($tab_array);
if ($input_errors)
print_input_errors($input_errors);
?>