Skip to content

Commit

Permalink
Version 8:
Browse files Browse the repository at this point in the history
* Local storage is no longer a strict requirement to run UI3, but cookies are.
Login version 17:
* Local storage feature detection improved to not throw an exception when the feature is unavailable.
  • Loading branch information
bp2008 committed Apr 20, 2018
1 parent 6469319 commit 10e88ee
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
2 changes: 2 additions & 0 deletions applet/loginScripts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions login.htm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Blue Iris Login</title>
<script type="text/javascript">
var login_version = "16";
var login_version = "17";
var bi_version = "%%VERSION%%";
var combined_version = login_version + "-" + bi_version;
</script>
Expand Down Expand Up @@ -104,9 +104,13 @@ <h1>%%SYSNAME%%</h1>
var existingSession = "";
var isStoredDataLoaded = false;
var windowUnloading = false;
var cookiesEnabled;
var localStorageEnabled;
$(function ()
{
if (UrlParameters.Get("autologin") == "0")
cookiesEnabled = areCookiesEnabled();
localStorageEnabled = isLocalStorageEnabled();
if (UrlParameters.Get("autologin") === "0")
{
SetPersistedValue("bi_override_disable_auto_login_once", "1");
location.href = location.href.replace(/autologin=0&?/gi, '');
Expand All @@ -115,12 +119,14 @@ <h1>%%SYSNAME%%</h1>
clearTimeout(showLoadingMessageTimeout);
$("#loginLoading").hide();
$("#login").show();
if (typeof window.JSON == 'undefined')
if (typeof window.JSON === 'undefined')
{
$("#login").text("Your web browser is too old to use the Blue Iris web interface properly.\n\nTo proceed with this browser, disable the \"Secure only\" requirement within Blue Iris's web server settings.");
$("#login").html("<div>Your web browser is too old to use the Blue Iris web interface properly.<br><br>To proceed with this browser, disable the \"Secure only\" requirement within Blue Iris's web server settings.</div>");
$("#login").css("color", "#EEEEEE").css("margin", "8px");
return;
}
if (!cookiesEnabled && !localStorageEnabled)
$("#cbLoginAutomatically").parent().text("Note: Cookies and Local Storage are disabled in your browser.").css("color", "#EEEEEE");
SetupLoginContextMenu();
SetStatus();
$(window).resize(resized);
Expand Down Expand Up @@ -258,10 +264,13 @@ <h1>%%SYSNAME%%</h1>
}
function LeaveLoginPage()
{
$.cookie("session", existingSession, { path: "/" });
var page = UrlParameters.Get("page");
if (page == "")
page = "/";
if (cookiesEnabled)
$.cookie("session", existingSession, { path: "/" });
else
page += (page.indexOf("?") < 0 ? "?" : "&") + "session=" + existingSession;
location.href = page + location.hash;
}
function cancelAutoLogin()
Expand Down Expand Up @@ -291,19 +300,19 @@ <h1>%%SYSNAME%%</h1>
function GetPersistedValue(key)
{
var value;
if (typeof Storage !== "undefined" && localStorage)
if (localStorageEnabled)
value = localStorage.getItem(key);
else
else if (cookiesEnabled)
value = $.cookie(key);
if (!value)
value = "";
return value;
}
function SetPersistedValue(key, value)
{
if (typeof Storage !== "undefined" && localStorage)
if (localStorageEnabled)
return localStorage.setItem(key, value);
else
else if (cookiesEnabled)
return $.cookie(key, value, { expires: 365 });
}
function pwKeypress(ele, e)
Expand Down
42 changes: 28 additions & 14 deletions ui3/ui3.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function DoUIFeatureDetection()
requestAnimationFramePolyFill();
if (!isCanvasSupported())
MissingRequiredFeature("HTML5 Canvas"); // Excludes IE 8
else if (!isLocalStorageEnabled())
MissingRequiredFeature("Local Storage");
else if (!areCookiesEnabled())
MissingRequiredFeature("Cookies", "Cookies are required for UI3's session management.");
else
{
// All critical tests pass
Expand Down Expand Up @@ -121,18 +121,32 @@ function DoUIFeatureDetection()
}
}
}
function MissingRequiredFeature(featureName)
function MissingRequiredFeature(featureName, description)
{
alert("This web interface requires a feature that is unavailable or disabled in your web browser.\n\nMissing feature: " + featureName + "\n\nYou will be redirected to a simpler web interface.");
alert("This web interface requires a feature that is unavailable or disabled in your web browser.\n\nMissing feature: " + featureName + (description ? ". " + description : "") + "\n\nYou will be redirected to a simpler web interface.");
}
function isCanvasSupported()
{
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
}
function isLocalStorageEnabled()
function areCookiesEnabled()
{
try
{
var session = $.cookie("session");
if (session)
return true;
$.cookie("session", "test", { path: "/" });
session = $.cookie("session")
$.cookie("session", "", { path: "/" });
return session === "test";
} catch (e) { }
return false;
}
function isLocalStorageEnabled()
{
try // May throw exception if local storage is disabled by browser settings!
{
var key = "local_storage_test_item";
localStorage.setItem(key, key);
Expand Down Expand Up @@ -1179,14 +1193,8 @@ function GetLocalStorage()
/// Returns the localStorage object, or a dummy localStorage object if the localStorage object is not available.
/// This method should be used only when the wrapped localStorage object is not desired (e.g. when using settings that are persisted globally, not specific to a Blue Iris server).
/// </summary>
try
{
if (typeof (Storage) !== "undefined" && localStorage)
return localStorage; // May throw exception if local storage is disabled by browser settings!
}
catch (ex)
{
}
if (isLocalStorageEnabled())
return localStorage;
return GetDummyLocalStorage();
}
function IsNewGeneration(key, gen)
Expand All @@ -1209,7 +1217,7 @@ function IsNewGeneration(key, gen)
function GetLocalStorageWrapper()
{
/// <summary>Returns the local storage object or a wrapper suitable for the current Blue Iris server. The result of this should be stored in the settings variable.</summary>
if (typeof (Storage) !== "undefined" && localStorage)
if (isLocalStorageEnabled())
{
if (currentServer.isUsingRemoteServer)
{
Expand Down Expand Up @@ -1309,6 +1317,12 @@ $(function ()
var fileSystemErrorMessage = "This interface must be loaded through the Blue Iris web server, and cannot function when loaded directly from your filesystem.";
alert(fileSystemErrorMessage);
toaster.Error(fileSystemErrorMessage, 60000);
return;
}

if (!isLocalStorageEnabled())
{
toaster.Warning("Local Storage is disabled or unavailable in your browser. Settings will not be saved between sessions.", 10000);
}

$("#ui_version_label").text(ui_version);
Expand Down

0 comments on commit 10e88ee

Please sign in to comment.