1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
upload_progress.php
|
5
|
Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
|
6
|
All rights reserved.
|
7
|
|
8
|
Redistribution and use in source and binary forms, with or without
|
9
|
modification, are permitted provided that the following conditions are met:
|
10
|
|
11
|
1. Redistributions of source code must retain the above copyright notice,
|
12
|
this list of conditions and the following disclaimer.
|
13
|
|
14
|
2. Redistributions in binary form must reproduce the above copyright
|
15
|
notice, this list of conditions and the following disclaimer in the
|
16
|
documentation and/or other materials provided with the distribution.
|
17
|
|
18
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
19
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
21
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
22
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27
|
POSSIBILITY OF SUCH DAMAGE.
|
28
|
*/
|
29
|
|
30
|
/* DISABLE_PHP_LINT_CHECKING */
|
31
|
|
32
|
##|+PRIV
|
33
|
##|*IDENT=page-upload_progress
|
34
|
##|*NAME=System: Firmware: Manual Update page (progress bar)
|
35
|
##|*DESCR=Allow access to the 'System: Firmware: Manual Update: Progress bar' page.
|
36
|
##|*MATCH=upload_progress*
|
37
|
##|-PRIV
|
38
|
|
39
|
include("guiconfig.inc");
|
40
|
|
41
|
// sanitize the ID value
|
42
|
$id = $_REQUEST['uploadid'];
|
43
|
if (strlen($id) == 0) {
|
44
|
echo "Invalid uploadid#.";
|
45
|
exit;
|
46
|
}
|
47
|
|
48
|
// ensure the uploaded status data exists in the session
|
49
|
if (!array_key_exists($id, $_SESSION[self::SESSION_KEY])) {
|
50
|
$_SESSION[self::SESSION_KEY][$id] = array(
|
51
|
'id' => $id,
|
52
|
'finished' => false,
|
53
|
'percent' => 0,
|
54
|
'total' => 0,
|
55
|
'complete' => 0
|
56
|
);
|
57
|
}
|
58
|
|
59
|
// retrieve the data from the session so it can be updated and returned
|
60
|
$ret = $_SESSION[self::SESSION_KEY][$id];
|
61
|
|
62
|
// retrieve the upload data from APC
|
63
|
$status = apc_fetch('upload_' . $id);
|
64
|
|
65
|
// false is returned if the data isn't found
|
66
|
if ($status) {
|
67
|
$ret['finished'] = (bool) $status['done'];
|
68
|
$ret['total'] = $status['total'];
|
69
|
$ret['complete'] = $status['current'];
|
70
|
// calculate the completed percentage
|
71
|
if ($ret['total'] > 0)
|
72
|
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
73
|
// write the changed data back to the session
|
74
|
$_SESSION[self::SESSION_KEY][$id] = $ret;
|
75
|
}
|
76
|
|
77
|
if (!$ret) {
|
78
|
|
79
|
if ( array_key_exists( "e", $_GET ) ) {
|
80
|
echo "<html><body onLoad='window.close();'>Invalid Meter ID! {$_REQUEST['uploadid]}";
|
81
|
echo ('</body></html>');
|
82
|
exit;
|
83
|
} else {
|
84
|
echo ('<html><meta http-equiv="Refresh" CONTENT="1; url=progress.php?uploadid={$id}"><body></body></html>');
|
85
|
exit;
|
86
|
}
|
87
|
|
88
|
} else {
|
89
|
|
90
|
if ($ret['percent'] > "99") {
|
91
|
|
92
|
echo ('<html><body onLoad="window.close()"> UPLOAD completed!</body></html>');
|
93
|
|
94
|
} else {
|
95
|
|
96
|
?>
|
97
|
|
98
|
<html>
|
99
|
<head>
|
100
|
<meta http-equiv="Refresh" content="1; url=<?=$url?>">
|
101
|
<title>Uploading Files... Please wait ...</title>
|
102
|
<style type='text/css'>
|
103
|
td {font-size: 10pt }
|
104
|
</style>
|
105
|
</head>
|
106
|
<body bgcolor="#FFFFFF">
|
107
|
<table height="100%" width="100%" cellPadding="4" cellSpacing="4" style="border:1px solid #990000;">
|
108
|
<tr>
|
109
|
<td>
|
110
|
<font face="arial"><b><center>Uploading files...</b></center>
|
111
|
<br>
|
112
|
<table width="100%" height="15" colspacing="0" cellpadding="0" cellspacing="0" border="0" align="top" nowrap>
|
113
|
<tr>
|
114
|
<td width="5" height="15" background="./themes/<?= $g['theme']; ?>/images/misc/bar_left.gif" align="top"></td>
|
115
|
<td>
|
116
|
<table WIDTH="100%" height="15" colspacing="0" cellpadding="0" cellspacing="0" border="0" align="top" nowrap>
|
117
|
<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_gray.gif">
|
118
|
<?echo("<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' WIDTH='$meter%'>");?>
|
119
|
</td>
|
120
|
</table>
|
121
|
</td>
|
122
|
<td width="5" height="15" background="./themes/<?= $g['theme']; ?>/images/misc/bar_right.gif" align="top"></td>
|
123
|
</table>
|
124
|
<br>
|
125
|
<table width="100%">
|
126
|
<tr>
|
127
|
<td align="right"><font face="arial"><b>Uploaded:</td>
|
128
|
<td><font face="arial"><?=$ret['finished']?></td>
|
129
|
<td align="right"><font face="arial"><b>File Size:</td>
|
130
|
<td><font face="arial"><?=$ret['total']?></td>
|
131
|
</tr>
|
132
|
<tr>
|
133
|
<td align="right"><font face="arial"><b>Completed:</td>
|
134
|
<td><font face="arial"><?=$ret['complete']?>%</td>
|
135
|
<td align="right"><font face="arial"><b></td>
|
136
|
<td><font face="arial"></td>
|
137
|
</tr>
|
138
|
</table>
|
139
|
</td>
|
140
|
</tr>
|
141
|
</table>
|
142
|
</body>
|
143
|
</html>
|