237 |
237 |
$pkgmode = $_REQUEST['mode'];
|
238 |
238 |
}
|
239 |
239 |
|
240 |
|
if ($_POST) {
|
241 |
|
if (empty($_POST['id']) && $pkgmode != 'reinstallall') {
|
|
240 |
$confirmed = isset($_POST['confirmed']) && $_POST['confirmed'] == 'true';
|
|
241 |
$completed = isset($_POST['completed']) && $_POST['completed'] == 'true';
|
|
242 |
|
|
243 |
if (!empty($_REQUEST['id'])) {
|
|
244 |
if ($_REQUEST['id'] != "firmware") {
|
242 |
245 |
header("Location: pkg_mgr_installed.php");
|
243 |
246 |
return;
|
244 |
247 |
}
|
245 |
|
} else if ($_GET && !$_GET['id']) {
|
246 |
|
if (empty($_GET['pkg']) && ($pkgmode != 'reinstallall')) {
|
|
248 |
$firmwareupdate = true;
|
|
249 |
} elseif (!$completed && empty($_REQUEST['pkg']) && $pkgmode != 'reinstallall') {
|
|
250 |
header("Location: pkg_mgr_installed.php");
|
|
251 |
return;
|
|
252 |
}
|
|
253 |
|
|
254 |
$pkgname = '';
|
|
255 |
if (!empty($_REQUEST['pkg'])) {
|
|
256 |
$pkgname = $_REQUEST['pkg'];
|
|
257 |
|
|
258 |
if (!pkg_valid_name($pkgname)) {
|
247 |
259 |
header("Location: pkg_mgr_installed.php");
|
248 |
260 |
return;
|
249 |
261 |
}
|
250 |
262 |
}
|
251 |
263 |
|
252 |
|
if ($_GET && $_GET['id'] == "firmware") {
|
253 |
|
$firmwareupdate = true;
|
254 |
|
}
|
255 |
|
|
256 |
264 |
$tab_array = array();
|
257 |
265 |
|
258 |
|
if ($firmwareupdate || ($_POST['id'] == "firmware")) {
|
|
266 |
if ($firmwareupdate) {
|
259 |
267 |
$pgtitle = array(gettext("System"), gettext("Update"), gettext("System Update"));
|
260 |
268 |
$tab_array[] = array(gettext("System Update"), true, "");
|
261 |
269 |
$tab_array[] = array(gettext("Update Settings"), false, "system_update_settings.php");
|
... | ... | |
267 |
275 |
}
|
268 |
276 |
|
269 |
277 |
include("head.inc");
|
270 |
|
|
271 |
|
if (!empty($_POST['id']) || $pkgmode == "reinstallall"):
|
272 |
278 |
?>
|
273 |
|
<div id="final" class="alert" role="alert" style="display: none;"></div>
|
274 |
|
<?php
|
275 |
|
endif;
|
276 |
279 |
|
|
280 |
<div id="final" class="alert" role="alert" style="display: none;"></div>
|
|
281 |
|
|
282 |
<?php
|
277 |
283 |
display_top_tabs($tab_array);
|
278 |
284 |
|
279 |
285 |
if ($input_errors) {
|
... | ... | |
284 |
290 |
<form action="pkg_mgr_install.php" method="post" class="form-horizontal">
|
285 |
291 |
<?php
|
286 |
292 |
|
287 |
|
if (($_POST['completed'] != "true") && (empty($pkgmode) && $_GET['id']) || (!empty($pkgmode) && (!empty($_GET['pkg']) || $pkgmode == 'reinstallall'))):
|
288 |
|
if (empty($pkgmode) && $_GET['id']) {
|
289 |
|
$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401));
|
290 |
|
} else if (!empty($pkgmode) && !empty($_GET['pkg'])) {
|
291 |
|
$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
|
292 |
|
}
|
293 |
|
|
|
293 |
if (!$confirmed && !$completed &&
|
|
294 |
($firmwareupdate || $pkgmode == 'reinstallall' || !empty($pkgname))):
|
294 |
295 |
switch ($pkgmode) {
|
295 |
296 |
case 'reinstallpkg':
|
296 |
297 |
$pkgtxt = sprintf(gettext('Confirmation Required to reinstall package %s.'), $pkgname);
|
... | ... | |
356 |
357 |
</label>
|
357 |
358 |
<div class="col-sm-10">
|
358 |
359 |
<input type="hidden" name="id" value="firmware" />
|
|
360 |
<input type="hidden" name="confirmed" value="true" />
|
359 |
361 |
<button type="submit" class="btn btn-success" name="pkgconfirm" id="pkgconfirm" value="<?=gettext("Confirm")?>" style="display: none">
|
360 |
362 |
<i class="fa fa-check icon-embed-btn"></i>
|
361 |
363 |
<?=gettext("Confirm")?>
|
... | ... | |
366 |
368 |
<?php
|
367 |
369 |
else:
|
368 |
370 |
?>
|
369 |
|
<input type="hidden" name="id" value="<?=$pkgname;?>" />
|
|
371 |
<input type="hidden" name="pkg" value="<?=$pkgname;?>" />
|
|
372 |
<input type="hidden" name="confirmed" value="true" />
|
370 |
373 |
<button type="submit" class="btn btn-success" name="pkgconfirm" id="pkgconfirm" value="<?=gettext("Confirm")?>">
|
371 |
374 |
<i class="fa fa-check icon-embed-btn"></i>
|
372 |
375 |
<?=gettext("Confirm")?>
|
... | ... | |
377 |
380 |
</div>
|
378 |
381 |
</div>
|
379 |
382 |
</div>
|
380 |
|
<?php endif;
|
381 |
|
|
|
383 |
<?php
|
|
384 |
endif;
|
382 |
385 |
?>
|
383 |
386 |
<div id="unable" style="display: none">
|
384 |
387 |
<?=print_info_box(gettext("Unable to retrieve system versions."), 'danger')?>
|
... | ... | |
386 |
389 |
<?php
|
387 |
390 |
|
388 |
391 |
if ($_POST) {
|
389 |
|
$pkgid = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401));
|
390 |
|
if ($pkgid == "firmware") {
|
|
392 |
if ($firmwareupdate) {
|
391 |
393 |
$logfilename = $g['cf_conf_path'] . '/upgrade_log';
|
392 |
394 |
} else {
|
393 |
|
$logfilename = $g['cf_conf_path'] . '/pkg_log_' . $pkgid;
|
|
395 |
$logfilename = $g['cf_conf_path'] . '/pkg_log_' . $pkgname;
|
394 |
396 |
}
|
395 |
397 |
}
|
396 |
398 |
|
397 |
399 |
if ($pkgmode == 'delete') {
|
398 |
400 |
$panel_heading_txt = gettext("Package Removal");
|
399 |
|
$pkg_success_txt = sprintf(gettext('<b>%1$s</b> removal successfully completed.'), $pkgid);
|
400 |
|
$pkg_fail_txt = sprintf(gettext('<b>%1$s</b> removal failed!'), $pkgid);
|
401 |
|
$pkg_wait_txt = sprintf(gettext('Please wait while the removal of <b>%1$s</b> completes.'), $pkgid);
|
402 |
|
} else if (($pkgmode == 'reinstallpkg') || ($pkgmode == 'reinstallall')) {
|
|
401 |
$pkg_success_txt = sprintf(gettext('<b>%1$s</b> removal successfully completed.'), $pkgname);
|
|
402 |
$pkg_fail_txt = sprintf(gettext('<b>%1$s</b> removal failed!'), $pkgname);
|
|
403 |
$pkg_wait_txt = sprintf(gettext('Please wait while the removal of <b>%1$s</b> completes.'), $pkgname);
|
|
404 |
} else if ($pkgmode == 'reinstallall') {
|
|
405 |
$panel_heading_txt = gettext("Packages Reinstallation");
|
|
406 |
$pkg_success_txt = gettext('All packages reinstallation successfully completed.');
|
|
407 |
$pkg_fail_txt = gettext('All packages reinstallation failed!');
|
|
408 |
$pkg_wait_txt = gettext('Please wait while the reinstallation of all packages completes.');
|
|
409 |
} else if ($pkgmode == 'reinstallpkg') {
|
403 |
410 |
$panel_heading_txt = gettext("Package Reinstallation");
|
404 |
|
$pkg_success_txt = sprintf(gettext('<b>%1$s</b> reinstallation successfully completed.'), $pkgid);
|
405 |
|
$pkg_fail_txt = sprintf(gettext('<b>%1$s</b> reinstallation failed!'), $pkgid);
|
406 |
|
$pkg_wait_txt = sprintf(gettext('Please wait while the reinstallation of <b>%1$s</b> completes.'), $pkgid);
|
|
411 |
$pkg_success_txt = sprintf(gettext('<b>%1$s</b> reinstallation successfully completed.'), $pkgname);
|
|
412 |
$pkg_fail_txt = sprintf(gettext('<b>%1$s</b> reinstallation failed!'), $pkgname);
|
|
413 |
$pkg_wait_txt = sprintf(gettext('Please wait while the reinstallation of <b>%1$s</b> completes.'), $pkgname);
|
407 |
414 |
} else {
|
408 |
415 |
$panel_heading_txt = gettext("Package Installation");
|
409 |
|
$pkg_success_txt = sprintf(gettext('<b>%1$s</b> installation successfully completed.'), $pkgid);
|
410 |
|
$pkg_fail_txt = sprintf(gettext('<b>%1$s</b> installation failed!'), $pkgid);
|
411 |
|
$pkg_wait_txt = sprintf(gettext('Please wait while the installation of <b>%1$s</b> completes.'), $pkgid);
|
|
416 |
$pkg_success_txt = sprintf(gettext('<b>%1$s</b> installation successfully completed.'), $pkgname);
|
|
417 |
$pkg_fail_txt = sprintf(gettext('<b>%1$s</b> installation failed!'), $pkgname);
|
|
418 |
$pkg_wait_txt = sprintf(gettext('Please wait while the installation of <b>%1$s</b> completes.'), $pkgname);
|
412 |
419 |
}
|
413 |
420 |
|
414 |
|
if (!empty($_POST['id']) || $pkgmode == "reinstallall"):
|
415 |
|
// What if the user navigates away from this page and then comes back via his/her "Back" button?
|
|
421 |
if ($confirmed):
|
|
422 |
// XXX: What if the user navigates away from this page and then comes back via his/her "Back" button?
|
416 |
423 |
$pidfile = $g['varrun_path'] . '/' . $g['product_name'] . '-upgrade.pid';
|
417 |
424 |
|
418 |
425 |
if (isvalidpid($pidfile)) {
|
419 |
426 |
$start_polling = true;
|
420 |
427 |
}
|
421 |
428 |
?>
|
422 |
|
<input type="hidden" name="id" value="<?=htmlspecialchars($_POST['id'])?>" />
|
|
429 |
<input type="hidden" name="id" value="<?=$_REQUEST['id']?>" />
|
423 |
430 |
<input type="hidden" name="mode" value="<?=$pkgmode?>" />
|
424 |
431 |
<input type="hidden" name="completed" value="true" />
|
|
432 |
<input type="hidden" name="confirmed" value="true" />
|
425 |
433 |
<input type="hidden" id="reboot_needed" name="reboot_needed" value="no" />
|
426 |
434 |
|
427 |
435 |
<div id="countdown" class="text-center"></div>
|
... | ... | |
458 |
466 |
|
459 |
467 |
ob_flush();
|
460 |
468 |
|
461 |
|
if ($_POST && ($_POST['completed'] != "true")) {
|
|
469 |
if ($confirmed && !$completed) {
|
462 |
470 |
/* Write out configuration to create a backup prior to pkg install. */
|
463 |
471 |
write_config(gettext("Creating restore point before package installation."));
|
464 |
472 |
|
... | ... | |
467 |
475 |
|
468 |
476 |
switch ($pkgmode) {
|
469 |
477 |
case 'delete':
|
470 |
|
mwexec_bg("{$upgrade_script} -r {$pkgid}");
|
|
478 |
mwexec_bg("{$upgrade_script} -r {$pkgname}");
|
471 |
479 |
$start_polling = true;
|
472 |
480 |
break;
|
473 |
481 |
|
... | ... | |
480 |
488 |
|
481 |
489 |
break;
|
482 |
490 |
case 'reinstallpkg':
|
483 |
|
mwexec_bg("{$upgrade_script} -i {$pkgid} -f");
|
|
491 |
mwexec_bg("{$upgrade_script} -i {$pkgname} -f");
|
484 |
492 |
$start_polling = true;
|
485 |
493 |
break;
|
486 |
494 |
|
487 |
495 |
case 'installed':
|
488 |
496 |
default:
|
489 |
|
if ($pkgid == 'firmware') {
|
|
497 |
if ($firmwareupdate) {
|
490 |
498 |
mwexec_bg("{$upgrade_script}");
|
491 |
499 |
} else {
|
492 |
|
mwexec_bg("{$upgrade_script} -i {$pkgid}");
|
|
500 |
mwexec_bg("{$upgrade_script} -i {$pkgname}");
|
493 |
501 |
}
|
494 |
502 |
$start_polling = true;
|
495 |
503 |
break;
|
... | ... | |
500 |
508 |
$confirmlabel = gettext("Confirm Update");
|
501 |
509 |
$sysmessage = gettext("Status");
|
502 |
510 |
|
503 |
|
// $_POST['completed'] just means that we are refreshing the page to update any new menu items
|
|
511 |
// $completed just means that we are refreshing the page to update any new menu items
|
504 |
512 |
// that were installed
|
505 |
|
if ($_POST && $_POST['completed'] == "true"):
|
|
513 |
if ($completed):
|
506 |
514 |
unlink_if_exists($logfilename . ".json");
|
507 |
|
if (($pkgid == 'firmware') && ($_POST['reboot_needed'] == "yes")):
|
|
515 |
if (($firmwareupdate) && ($_POST['reboot_needed'] == "yes")):
|
508 |
516 |
|
509 |
517 |
?>
|
510 |
518 |
<script>
|
... | ... | |
538 |
546 |
function show_success() {
|
539 |
547 |
$('#final').removeClass("alert-info").addClass("alert-success");
|
540 |
548 |
if ("<?=$pkgmode?>" != "reinstallall") {
|
541 |
|
if ("<?=$pkgid?>" == "firmware") {
|
|
549 |
if ("<?=$firmwareupdate?>") {
|
542 |
550 |
$('#final').html("<?=gettext('System update successfully completed.')?>");
|
543 |
551 |
} else {
|
544 |
552 |
$('#final').html("<?=$pkg_success_txt?>");
|
... | ... | |
672 |
680 |
$('#reboot_needed').val("yes");
|
673 |
681 |
}
|
674 |
682 |
|
675 |
|
$('form').submit();
|
|
683 |
setProgress('progressbar', 100, false);
|
|
684 |
$('#progressbar').addClass("progress-bar-success");
|
|
685 |
show_success();
|
|
686 |
setTimeout(scrollToBottom, 200);
|
676 |
687 |
}
|
677 |
688 |
|
678 |
689 |
if ((json.pid == "stopped") && ((progress != 0) || (json.exitstatus != 0))) {
|
... | ... | |
729 |
740 |
show_info();
|
730 |
741 |
}
|
731 |
742 |
|
732 |
|
// If we are just re-drawing the page after a successful install/remove/reinstall,
|
733 |
|
// we only need to re-populate the progress indicator and the status banner
|
734 |
|
if ("<?=$_POST['completed']?>" == "true") {
|
735 |
|
setProgress('progressbar', 100, false);
|
736 |
|
$('#progressbar').addClass("progress-bar-success");
|
737 |
|
show_success();
|
738 |
|
setTimeout(scrollToBottom, 200);
|
739 |
|
}
|
740 |
|
|
741 |
743 |
if ("<?=$firmwareupdate?>") {
|
742 |
744 |
get_firmware_versions();
|
743 |
745 |
}
|
Rework pkg_mgr_install.php:
- Stop using id parameter for additional packages, keep using it only
for firmware upgrades
- Created to control variables $completed and $confirmed to check all
the stages and make it easy to understand what is happening
- Stop using $pkgid and use $pkgname instead
- Set $pkgname early and validate the port name
- Use $firmwareupdate everywhere to check if it's a firmware upgrade
- Add hidden input called confirmed to control when user has confirmed
installation / upgrade / removal
- Add specific messages for reinstall all
- Remove an extra form submit and just changes progress bar and
informative panel when json process finished successfully