diff options
author | Stephen Beaver <sbeaver@netgate.com> | 2016-04-28 13:36:59 -0400 |
---|---|---|
committer | Stephen Beaver <sbeaver@netgate.com> | 2016-04-28 13:36:59 -0400 |
commit | cb6f87f3bf3b616133414ac2863d24892544b828 (patch) | |
tree | 1ef7e097d44b5be0ea942a323c33df4b3952561c /src/usr/local/www/pkg_mgr_install.php | |
parent | cac808f0433eed64d9c970fc49ab39d52b1acb40 (diff) | |
download | pfsense-cb6f87f3bf3b616133414ac2863d24892544b828.zip pfsense-cb6f87f3bf3b616133414ac2863d24892544b828.tar.gz |
Retrieve firmware versions via Ajax so we don't hang the GUI if unable to reach the server
Diffstat (limited to 'src/usr/local/www/pkg_mgr_install.php')
-rw-r--r-- | src/usr/local/www/pkg_mgr_install.php | 93 |
1 files changed, 67 insertions, 26 deletions
diff --git a/src/usr/local/www/pkg_mgr_install.php b/src/usr/local/www/pkg_mgr_install.php index 10d58f3..838db7a 100644 --- a/src/usr/local/www/pkg_mgr_install.php +++ b/src/usr/local/www/pkg_mgr_install.php @@ -97,6 +97,14 @@ if ($_REQUEST['ajax']) { $response = ""; $code = 0; + // If this is an ajax call to get the installed and newst versions, call that function, + // JSON encode thre result, print it and exit + if ($_REQUEST['getversion']) { + $firmwareversions = get_system_pkg_version(); + print(json_encode($firmwareversions)); + exit; + } + // Check to see if our process is still running $pidfile = $g['varrun_path'] . '/' . $g['product_name'] . '-upgrade.pid'; $running = "running"; @@ -231,7 +239,6 @@ if ($_POST) { if ($_GET && $_GET['id'] == "firmware") { $firmwareupdate = true; - $firmwareversion = get_system_pkg_version(); } $tab_array = array(); @@ -320,8 +327,7 @@ if ($input_errors) { <label class="col-sm-2 control-label"> <?=gettext("Current Base System")?> </label> - <div class="col-sm-10"> - <?=$firmwareversion['installed_version']?> + <div class="col-sm-10" id="installed_version"> </div> </div> @@ -329,37 +335,24 @@ if ($input_errors) { <label class="col-sm-2 control-label"> <?=gettext("Latest Base System")?> </label> - <div class="col-sm-10"> - <?=$firmwareversion['version']?> + <div class="col-sm-10" id="version"> </div> </div> -<?php - if ($firmwareversion['version'] != $firmwareversion['installed_version']) { -?> - <div class="form-group"> - <label class="col-sm-2 control-label"> - <?=gettext("Confirm Update")?> + + <div class="form-group" id="confirm"> + <label class="col-sm-2 control-label" id="confirmlabel"> + <?=gettext("Retrieving")?> </label> <div class="col-sm-10"> <input type="hidden" name="id" value="firmware" /> - <button type="submit" class="btn btn-success" name="pkgconfirm" id="pkgconfirm" value="<?=gettext("Confirm")?>"> + <button type="submit" class="btn btn-success" name="pkgconfirm" id="pkgconfirm" value="<?=gettext("Confirm")?>" style="display: none"> <i class="fa fa-check icon-embed-btn"></i> <?=gettext("Confirm")?> </button> + <span id="uptodate"><i class="fa fa-cog fa-spin fa-lg text-warning"></i></span> </div> </div> <?php - } else { -?> - <div class="form-group"> - <label class="col-sm-2 control-label"> - </label> - <div class="col-sm-10"> - <?=($firmwareversion) ? gettext("System is up to date") : ""?> - </div> - </div> -<?php - } } else { ?> <input type="hidden" name="id" value="<?=$pkgname;?>" /> @@ -375,9 +368,11 @@ if ($input_errors) { </div> <?php endif; -if ($firmwareupdate && !$firmwareversion) { - print_info_box(gettext("Unable to retrieve system versions."), 'danger'); -} +?> + <div id="unable" style="display: none"> + <?=print_info_box(gettext("Unable to retrieve system versions."), 'danger')?> + </div> +<?php if ($_POST) { $pkgid = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401)); @@ -484,11 +479,16 @@ if ($_POST && ($_POST['completed'] != "true")) { } } +$uptodatemsg = gettext("Up to date."); +$confirmlabel = gettext("Confirm Update"); +$sysmessage = gettext("Status"); + // $_POST['completed'] just means that we are refreshing the page to update any new menu items // that were installed if ($_POST && $_POST['completed'] == "true"): unlink_if_exists($logfilename . ".json"); if (($pkgid == 'firmware') && ($_POST['reboot_needed'] == "yes")): + ?> <script> //<![CDATA[ @@ -558,6 +558,43 @@ function show_info() { $('#final').show(); } +function get_firmware_versions() +{ + var ajaxVersionRequest; + + // Retrieve the version information + ajaxVersionRequest = $.ajax({ + url: "pkg_mgr_install.php", + type: "post", + data: { + ajax: "ajax", + getversion: "yes" + } + }); + + // Deal with the results of the above ajax call + ajaxVersionRequest.done(function (response, textStatus, jqXHR) { + var json = new Object; + + json = jQuery.parseJSON(response); + + if(json) { + $('#installed_version').text(json.installed_version); + $('#version').text(json.version); + + // If the installed and latest versions are the same, print an "Up to date" message + if (json.installed_version == json.version) { + $('#confirmlabel').text("<?=$sysmessage?>"); + $('#uptodate').html('<span class="text-success">' + '<?=$uptodatemsg?>' + "</span>"); + } else { // If htey differ display the "Confirm" button + $('#uptodate').hide(); + $('#confirmlabel').text( "<?=$confirmlabel?>"); + $('#pkgconfirm').show(); + } + } + }); +} + function getLogsStatus() { var ajaxRequest; var repeat; @@ -684,6 +721,10 @@ events.push(function() { setTimeout(scrollToBottom, 200); } + if ("<?=$firmwareupdate?>") { + get_firmware_versions(); + } + }); //]]> </script> |