Revision b4ff3ccd
Added by Scott Ullrich over 20 years ago
- Added progress bar. Needs to be converted from green -> pfSense red
usr/local/www/pkg_mgr_install.php | ||
---|---|---|
30 | 30 |
require("guiconfig.inc"); |
31 | 31 |
require("xmlparse_pkg.inc"); |
32 | 32 |
|
33 |
$pb_percent = 1; |
|
34 |
|
|
33 | 35 |
/* |
34 | 36 |
* open logging facility |
35 | 37 |
*/ |
... | ... | |
96 | 98 |
* exec_command_and_return_text: execute command and update output window dynamically |
97 | 99 |
*/ |
98 | 100 |
function execute_command_return_output($command) { |
99 |
global $fd_log; |
|
101 |
global $fd_log, $pb_percent; |
|
102 |
if($pb_percent > 100) $pb_percent = 1; |
|
103 |
update_progress_bar($pb_percent); |
|
100 | 104 |
$fd = popen($command . " 2>&1 ", "r"); |
101 | 105 |
echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = \"\";</script>"; |
102 | 106 |
$counter = 0; |
... | ... | |
127 | 131 |
$counter2++; |
128 | 132 |
echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = this.document.forms[0].output.value + \"" . $text . $extrabreak . "\"; f('output'); </script>"; |
129 | 133 |
} |
134 |
$pb_percent++; |
|
130 | 135 |
fclose($fd); |
131 | 136 |
} |
132 | 137 |
|
138 |
function update_progress_bar($percent) { |
|
139 |
if($percent > 100) $percent = 1; |
|
140 |
echo "\n<script type=\"text/javascript\" language=\"javascript\">"; |
|
141 |
echo "\ndocument.progressbar.style.width='" . $percent . "%';"; |
|
142 |
echo "\n</script>"; |
|
143 |
} |
|
144 |
|
|
133 | 145 |
$a_out = &$pkg_config['packages']; |
134 | 146 |
|
135 | 147 |
?> |
... | ... | |
183 | 195 |
<table width="100%" border="0" cellpadding="6" cellspacing="0"> |
184 | 196 |
<tr> |
185 | 197 |
<td> |
186 |
<textarea cols="100%" rows="1" name="status" id="status" wrap="hard">One moment please... This will take a while!</textarea> |
|
187 |
<textarea cols="100%" rows="25" name="output" id="output" wrap="hard"></textarea> |
|
198 |
<!-- progress bar --> |
|
199 |
<center> |
|
200 |
<table id="progholder" name="progholder" height='20' border='1' bordercolor='black' width='420' bordercolordark='#000000' bordercolorlight='#000000' style='border-collapse: collapse' colspacing='2' cellpadding='2' cellspacing='2'><tr><td><img border='0' src='progress_bar.gif' width='280' height='23' name='progressbar' id='progressbar'></td></tr></table> |
|
201 |
<br> |
|
202 |
<!-- status box --> |
|
203 |
<textarea cols="60" rows="1" name="status" id="status" wrap="hard">One moment please... This will take a while!</textarea> |
|
204 |
<!-- command output box --> |
|
205 |
<textarea cols="60" rows="25" name="output" id="output" wrap="hard"></textarea> |
|
206 |
</center> |
|
188 | 207 |
</td> |
189 | 208 |
</tr> |
190 | 209 |
</table> |
... | ... | |
196 | 215 |
</body> |
197 | 216 |
</html> |
198 | 217 |
|
199 |
<? |
|
218 |
<?php |
|
219 |
|
|
220 |
update_progress_bar($pb_percent); |
|
221 |
$pb_percent += 10; |
|
200 | 222 |
|
201 | 223 |
/* install the package */ |
202 | 224 |
|
... | ... | |
208 | 230 |
mwexec("mkdir /usr/local/www/ext/VPN >/dev/null 2>&1"); |
209 | 231 |
mwexec("mkdir /usr/local/www/ext/Status >/dev/null 2>&1"); |
210 | 232 |
|
233 |
update_progress_bar($pb_percent); |
|
234 |
$pb_percent += 10; |
|
235 |
|
|
211 | 236 |
$a_out = &$pkg_config['packages']['package']; |
212 | 237 |
$pkgent = array(); |
213 | 238 |
$pkgent['name'] = $pkg_config['packages']['package'][$id]['name']; |
... | ... | |
220 | 245 |
$pkgent['configurationfile'] = $a_out[$id]['configurationfile']; |
221 | 246 |
$a_out = &$config['packages']['package']; |
222 | 247 |
|
248 |
update_progress_bar($pb_percent); |
|
249 |
$pb_percent += 10; |
|
250 |
|
|
223 | 251 |
fwrite($fd_log, "ls /var/db/pkg | grep " . $pkgent['name'] . "\n" . $status); |
224 | 252 |
if($status <> "") { |
225 | 253 |
// package is already installed!? |
... | ... | |
229 | 257 |
update_status("Downloading and installing " . $pkgent['name'] . " - " . $pkgent['pfsense_package'] . " and its dependencies ... This could take a moment ..."); |
230 | 258 |
fwrite($fd_log, "Downloading and installing " . $pkgent['name'] . " ... \n"); |
231 | 259 |
|
260 |
update_progress_bar($pb_percent); |
|
261 |
$pb_percent += 10; |
|
262 |
|
|
232 | 263 |
$text = exec_command_and_return_text("cd /tmp/ && /usr/sbin/pkg_add -r " . $pkgent['pfsense_package_base'] . "/" . $pkgent['pfsense_package']); |
233 | 264 |
update_output_window($text); |
234 | 265 |
fwrite($fd_log, "Executing: cd /tmp/ && /usr/sbin/pkg_add -r " . $pkgent['pfsense_package_base'] . "/" . $pkgent['pfsense_package'] . "\n" . $text); |
235 | 266 |
|
267 |
update_progress_bar($pb_percent); |
|
268 |
$pb_percent += 10; |
|
269 |
|
|
236 | 270 |
if ($pkgent['pfsense_package_base']) { |
237 | 271 |
update_status("Downloading and installing " . $pkgent['name'] . " - " . $pkgent['depends_on_package_base'] . " and its dependencies ... This could take a moment ..."); |
238 | 272 |
$text = exec_command_and_return_text("cd /tmp/ && /usr/sbin/pkg_add -r " . $pkgent['depends_on_package_base'] . "/" . $pkgent['depends_on_package']); |
... | ... | |
240 | 274 |
fwrite($fd_log, "cd /tmp/ && /usr/sbin/pkg_add -r " . $pkgent['depends_on_package_base'] . "/" . $pkgent['depends_on_package'] . "\n" . $text);; |
241 | 275 |
} |
242 | 276 |
|
277 |
update_progress_bar($pb_percent); |
|
278 |
$pb_percent += 10; |
|
279 |
|
|
243 | 280 |
$config = parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']); |
244 | 281 |
|
282 |
update_progress_bar($pb_percent); |
|
283 |
$pb_percent += 10; |
|
284 |
|
|
245 | 285 |
$config['installedpackages']['package'][] = $pkgent; |
246 | 286 |
|
247 | 287 |
if (isset($id) && $a_out[$id]) |
... | ... | |
249 | 289 |
else |
250 | 290 |
$a_out[] = $pkgent; |
251 | 291 |
|
292 |
update_progress_bar($pb_percent); |
|
293 |
$pb_percent += 10; |
|
294 |
|
|
252 | 295 |
write_config(); |
253 | 296 |
|
297 |
update_progress_bar($pb_percent); |
|
298 |
$pb_percent += 10; |
|
299 |
|
|
254 | 300 |
$name = $pkgent['name']; |
255 | 301 |
|
302 |
update_progress_bar($pb_percent); |
|
303 |
$pb_percent++; |
|
304 |
|
|
256 | 305 |
// parse the config file for this package and install neededtext items. |
257 | 306 |
if(file_exists("/usr/local/pkg/" . $pkgent['name'] . ".xml")) { |
258 | 307 |
$config = parse_xml_config("/usr/local/pkg/" . $pkgent['name'] . ".xml", "packagegui"); |
259 | 308 |
foreach ($config['modify_system']['item'] as $ms) { |
309 |
update_progress_bar($pb_percent); |
|
310 |
$pb_percent += 10; |
|
260 | 311 |
if($ms['textneeded']) { |
261 | 312 |
fwrite($fd_log, "Adding needed text items:\n"); |
262 | 313 |
$filecontents = exec_command_and_return_text("cat " . $ms['modifyfilename']); |
... | ... | |
279 | 330 |
} |
280 | 331 |
fwrite($fd_log, "End of Package Manager installation session.\n"); |
281 | 332 |
|
333 |
update_progress_bar($pb_percent); |
|
334 |
$pb_percent += 10; |
|
335 |
|
|
282 | 336 |
// return dependency list to output later. |
283 | 337 |
$command = "TODELETE=`ls /var/db/pkg | grep " . $name . "` && /usr/sbin/pkg_info -r \$TODELETE | grep Dependency: | cut -d\" \" -f2"; |
284 | 338 |
$dependencies = exec_command_and_return_text($command); |
285 | 339 |
fwrite($fd_log, "Installed " . $name . " and the following dependencies:\n" . $dependencies); |
286 | 340 |
|
341 |
update_progress_bar($pb_percent); |
|
342 |
$pb_percent += 10; |
|
343 |
|
|
287 | 344 |
$status = exec_command_and_return_text("ls /var/db/pkg | grep " . $pkgent['name']); |
288 | 345 |
fwrite($fd_log, "ls /var/db/pkg | grep " . $pkgent['name'] . "\n" . $status); |
289 | 346 |
if($status <> "") { |
... | ... | |
294 | 351 |
fwrite($fd_log, "Package WAS NOT installed properly.\n"); |
295 | 352 |
} |
296 | 353 |
|
354 |
update_progress_bar($pb_percent); |
|
355 |
$pb_percent += 10; |
|
356 |
|
|
297 | 357 |
// close log |
298 | 358 |
fclose($fd_log); |
299 | 359 |
|
... | ... | |
307 | 367 |
$log = ereg_replace("\n", "\\n", $tmp); |
308 | 368 |
echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = \"" . $log . "\";</script>"; |
309 | 369 |
|
370 |
update_progress_bar(100); |
|
371 |
|
|
372 |
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>"; |
|
373 |
echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>"; |
|
374 |
|
|
310 | 375 |
?> |
311 | 376 |
|
312 | 377 |
|
Also available in: Unified diff