Rescue upload progress bar from the dead!!! OMG, Zombies!

This commit is contained in:
Scott Ullrich 2008-11-24 01:06:44 +00:00
parent 5a54464bbe
commit 0045dfd17a
2 changed files with 154 additions and 7 deletions

View File

@ -38,19 +38,20 @@
##|*MATCH=system_firmware.php*
##|-PRIV
$d_isfwfile = 1;
require_once("guiconfig.inc");
$curcfg = $config['system']['firmware'];
require_once("xmlrpc_client.inc");
/* Allow additional execution time 0 = no limit. */
ini_set('max_execution_time', '3600');
ini_set('max_input_time', '3600');
/* Construct an upload_id for this session */
$upload_id = $_SERVER['REQUEST_TIME'] . $_SESSION['Username'];
/* if upgrade in progress, alert user */
if(file_exists($d_firmwarelock_path)) {
$pgtitle = array("System","Firmware","Manual Update");
@ -155,13 +156,14 @@ $pgtitle = array("Diagnostics","Firmware");
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
<?php if ($sig_warning && !$input_errors): ?>
<form action="system_firmware.php" method="post">
<form id="formitem" action="system_firmware.php" method="post">
<?php
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
"is not an official/supported image and may lead to unexpected behavior or security " .
@ -201,12 +203,14 @@ print_info_box($sig_warning);
upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
to be uploaded.<br>Click &quot;Upgrade firmware&quot;
to start the upgrade process.</p>
<div id="firmwarearea">
<?php if (!file_exists($d_sysrebootreqd_path)): ?>
<?php if (!file_exists($d_fwupenabled_path)): ?>
<input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
<?php else: ?>
<input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
<br><br>
<input type="hidden" name="APC_UPLOAD_PROGRESS" value="<?=$upload_id?>" />
<strong>Firmware image file: </strong>&nbsp;
<input name="ulfile" type="file" class="formfld">
<br><br>
@ -224,12 +228,13 @@ print_info_box($sig_warning);
}
}
?>
<input name="Submit" type="submit" class="formbtn" value="Upgrade firmware">
<input name="Submit" type="submit" class="formbtn" value="Upgrade firmware" onClick="window.open('progress.php?uploadid=<?=$upload_id?>','UploadMeter','width=370,height=115', true); return true;">
<?php endif; else: ?>
<strong>You must reboot the system before you can upgrade the firmware.</strong>
<?php endif; ?>
</div>
</td>
</td>
</td>
</tr>
<tr>
<td width="22%" valign="top">&nbsp;</td>
@ -242,7 +247,6 @@ print_info_box($sig_warning);
</tr>
</td>
</table>
</form>
<?php endif; endif; ?>
<?php include("fend.inc"); ?>

View File

@ -0,0 +1,143 @@
<?php
/* $Id$ */
/*
upload_progress.php
Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* DISABLE_PHP_LINT_CHECKING */
##|+PRIV
##|*IDENT=page-upload_progress
##|*NAME=System: Firmware: Manual Update page (progress bar)
##|*DESCR=Allow access to the 'System: Firmware: Manual Update: Progress bar' page.
##|*MATCH=upload_progress*
##|-PRIV
include("guiconfig.inc");
// sanitize the ID value
$id = $_REQUEST['uploadid'];
if (strlen($id) == 0) {
echo "Invalid uploadid#.";
exit;
}
// ensure the uploaded status data exists in the session
if (!array_key_exists($id, $_SESSION[self::SESSION_KEY])) {
$_SESSION[self::SESSION_KEY][$id] = array(
'id' => $id,
'finished' => false,
'percent' => 0,
'total' => 0,
'complete' => 0
);
}
// retrieve the data from the session so it can be updated and returned
$ret = $_SESSION[self::SESSION_KEY][$id];
// retrieve the upload data from APC
$status = apc_fetch('upload_' . $id);
// false is returned if the data isn't found
if ($status) {
$ret['finished'] = (bool) $status['done'];
$ret['total'] = $status['total'];
$ret['complete'] = $status['current'];
// calculate the completed percentage
if ($ret['total'] > 0)
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
// write the changed data back to the session
$_SESSION[self::SESSION_KEY][$id] = $ret;
}
if (!$ret) {
if ( array_key_exists( "e", $_GET ) ) {
echo "<html><body onLoad='window.close();'>Invalid Meter ID! {$_REQUEST['uploadid]}";
echo ('</body></html>');
exit;
} else {
echo ('<html><meta http-equiv="Refresh" CONTENT="1; url=progress.php?uploadid={$id}"><body></body></html>');
exit;
}
} else {
if ($ret['percent'] > "99") {
echo ('<html><body onLoad="window.close()"> UPLOAD completed!</body></html>');
} else {
?>
<html>
<head>
<meta http-equiv="Refresh" content="1; url=<?=$url?>">
<title>Uploading Files... Please wait ...</title>
<style type='text/css'>
td {font-size: 10pt }
</style>
</head>
<body bgcolor="#FFFFFF">
<table height="100%" width="100%" cellPadding="4" cellSpacing="4" style="border:1px solid #990000;">
<tr>
<td>
<font face="arial"><b><center>Uploading files...</b></center>
<br>
<table width="100%" height="15" colspacing="0" cellpadding="0" cellspacing="0" border="0" align="top" nowrap>
<tr>
<td width="5" height="15" background="./themes/<?= $g['theme']; ?>/images/misc/bar_left.gif" align="top"></td>
<td>
<table WIDTH="100%" height="15" colspacing="0" cellpadding="0" cellspacing="0" border="0" align="top" nowrap>
<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_gray.gif">
<?echo("<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' WIDTH='$meter%'>");?>
</td>
</table>
</td>
<td width="5" height="15" background="./themes/<?= $g['theme']; ?>/images/misc/bar_right.gif" align="top"></td>
</table>
<br>
<table width="100%">
<tr>
<td align="right"><font face="arial"><b>Uploaded:</td>
<td><font face="arial"><?=$ret['finished']?></td>
<td align="right"><font face="arial"><b>File Size:</td>
<td><font face="arial"><?=$ret['total']?></td>
</tr>
<tr>
<td align="right"><font face="arial"><b>Completed:</td>
<td><font face="arial"><?=$ret['complete']?>%</td>
<td align="right"><font face="arial"><b></td>
<td><font face="arial"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>