summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/NVR.js737
-rwxr-xr-xwww/js/app.js95
2 files changed, 481 insertions, 351 deletions
diff --git a/www/js/NVR.js b/www/js/NVR.js
index d22cf294..4f888c21 100644
--- a/www/js/NVR.js
+++ b/www/js/NVR.js
@@ -192,7 +192,7 @@ angular.module('zmApp.controllers')
'montageReviewCollapse': true,
'objectDetectionFilter': false,
'enableEventRefresh': true,
- 'lastEventCheckTimes':{},
+ 'lastEventCheckTimes': {},
'enableMontageOverlays': true,
'showMontageSidebars': false,
'isTokenSupported': false,
@@ -335,7 +335,7 @@ angular.module('zmApp.controllers')
if (configParams.ZM_MIN_STREAMING_PORT == -1 || forceReload) {
log("Checking value of ZM_MIN_STREAMING_PORT for the first time");
var apiurl = loginData.apiurl;
- var myurl = apiurl + '/configs/viewByName/ZM_MIN_STREAMING_PORT.json?'+$rootScope.authSession;
+ var myurl = apiurl + '/configs/viewByName/ZM_MIN_STREAMING_PORT.json?' + $rootScope.authSession;
$http.get(myurl)
.then(function (data) {
data = data.data;
@@ -386,7 +386,7 @@ angular.module('zmApp.controllers')
}
if ($rootScope.authSession != '' && $rootScope.authSession != 'undefined') {
- log ("We already have an auth key of:"+$rootScope.authSession);
+ log("We already have an auth key of:" + $rootScope.authSession);
d.resolve($rootScope.authSession);
return d.promise;
}
@@ -519,11 +519,10 @@ angular.module('zmApp.controllers')
try {
positions = JSON.parse(positionsStr);
+ } catch (e) {
+ debug("error parsing positions");
}
- catch (e) {
- debug ("error parsing positions");
- }
-
+
for (var m = 0; m < monitors.length; m++) {
var positionFound = false;
for (var p = 0; p < positions.length; p++) {
@@ -616,490 +615,490 @@ angular.module('zmApp.controllers')
}
function _checkInitSanity(loginData) {
- // old version hacks for new variables
-
- // always true Oct 27 2016
- loginData.persistMontageOrder = true;
- loginData.enableh264 = true;
-
- if (typeof loginData.isUseBasicAuth === 'undefined') {
- loginData.isUseBasicAuth = false;
- loginData.basicAuthUser = '';
- loginData.basicAuthPassword = '';
- $rootScope.basicAuthHeader = '';
- $rootScope.basicAuthToken = '';
- }
+ // old version hacks for new variables
+
+ // always true Oct 27 2016
+ loginData.persistMontageOrder = true;
+ loginData.enableh264 = true;
+
+ if (typeof loginData.isUseBasicAuth === 'undefined') {
+ loginData.isUseBasicAuth = false;
+ loginData.basicAuthUser = '';
+ loginData.basicAuthPassword = '';
+ $rootScope.basicAuthHeader = '';
+ $rootScope.basicAuthToken = '';
+ }
- if (loginData.url.indexOf('@') != -1) {
- log(">> " + loginData.url);
- log(">>User/Password detected in URL, changing to new auth handling...");
- loginData.isUseBasicAuth = true;
+ if (loginData.url.indexOf('@') != -1) {
+ log(">> " + loginData.url);
+ log(">>User/Password detected in URL, changing to new auth handling...");
+ loginData.isUseBasicAuth = true;
- var components = URI.parse(loginData.url);
- loginData.url = components.scheme + "://" + components.host;
- if (components.port) loginData.url = loginData.url + ":" + components.port;
- if (components.path) loginData.url = loginData.url + components.path;
+ var components = URI.parse(loginData.url);
+ loginData.url = components.scheme + "://" + components.host;
+ if (components.port) loginData.url = loginData.url + ":" + components.port;
+ if (components.path) loginData.url = loginData.url + components.path;
- components = URI.parse(loginData.streamingurl);
- loginData.streamingurl = components.scheme + "://" + components.host;
- if (components.port) loginData.streamingurl = loginData.streamingurl + ":" + components.port;
- if (components.path) loginData.streamingurl = loginData.streamingurl + components.path;
+ components = URI.parse(loginData.streamingurl);
+ loginData.streamingurl = components.scheme + "://" + components.host;
+ if (components.port) loginData.streamingurl = loginData.streamingurl + ":" + components.port;
+ if (components.path) loginData.streamingurl = loginData.streamingurl + components.path;
- components = URI.parse(loginData.apiurl);
- loginData.apiurl = components.scheme + "://" + components.host;
- if (components.port) loginData.apiurl = loginData.apiurl + ":" + components.port;
- if (components.path) loginData.apiurl = loginData.apiurl + components.path;
+ components = URI.parse(loginData.apiurl);
+ loginData.apiurl = components.scheme + "://" + components.host;
+ if (components.port) loginData.apiurl = loginData.apiurl + ":" + components.port;
+ if (components.path) loginData.apiurl = loginData.apiurl + components.path;
- $rootScope.basicAuthToken = btoa(components.userinfo);
- $rootScope.basicAuthHeader = 'Basic ' + $rootScope.basicAuthToken;
- //console.log (">>>> SET BASIC AUTH TO " + $rootScope.basicAuthHeader);
+ $rootScope.basicAuthToken = btoa(components.userinfo);
+ $rootScope.basicAuthHeader = 'Basic ' + $rootScope.basicAuthToken;
+ //console.log (">>>> SET BASIC AUTH TO " + $rootScope.basicAuthHeader);
- var up = components.userinfo.split(':');
- loginData.basicAuthPassword = up[1];
- loginData.basicAuthUser = up[0];
- //console.log ("SETTING "+loginData.basicAuthUser+" "+loginData.basicAuthPassword);
+ var up = components.userinfo.split(':');
+ loginData.basicAuthPassword = up[1];
+ loginData.basicAuthUser = up[0];
+ //console.log ("SETTING "+loginData.basicAuthUser+" "+loginData.basicAuthPassword);
- }
+ }
- if (loginData.isUseBasicAuth) {
- $rootScope.basicAuthToken = btoa(loginData.basicAuthUser + ':' + loginData.basicAuthPassword);
- $rootScope.basicAuthHeader = 'Basic ' + $rootScope.basicAuthToken;
- debug("Basic authentication detected, constructing Authorization Header");
+ if (loginData.isUseBasicAuth) {
+ $rootScope.basicAuthToken = btoa(loginData.basicAuthUser + ':' + loginData.basicAuthPassword);
+ $rootScope.basicAuthHeader = 'Basic ' + $rootScope.basicAuthToken;
+ debug("Basic authentication detected, constructing Authorization Header");
- // console.log ("BASIC AUTH SET TO:"+$rootScope.basicAuthHeader);
+ // console.log ("BASIC AUTH SET TO:"+$rootScope.basicAuthHeader);
- }
+ }
- if (typeof loginData.enableAlarmCount === 'undefined') {
- debug("enableAlarmCount does not exist, setting to true");
- loginData.enableAlarmCount = true;
- }
+ if (typeof loginData.enableAlarmCount === 'undefined') {
+ debug("enableAlarmCount does not exist, setting to true");
+ loginData.enableAlarmCount = true;
+ }
- if (typeof loginData.onTapScreen == 'undefined') {
- loginData.onTapScreen = $translate.instant('kTapMontage');
- }
+ if (typeof loginData.onTapScreen == 'undefined') {
+ loginData.onTapScreen = $translate.instant('kTapMontage');
+ }
- if (loginData.onTapScreen != $translate.instant('kTapMontage') &&
- loginData.onTapScreen != $translate.instant('kTapEvents') &&
- loginData.onTapScreen != $translate.instant('kTapLiveMonitor')) {
- log("Invalid onTap setting found, resetting. I got " + loginData.onTapScreen);
- loginData.onTapScreen = $translate.instant('kMontage');
- }
+ if (loginData.onTapScreen != $translate.instant('kTapMontage') &&
+ loginData.onTapScreen != $translate.instant('kTapEvents') &&
+ loginData.onTapScreen != $translate.instant('kTapLiveMonitor')) {
+ log("Invalid onTap setting found, resetting. I got " + loginData.onTapScreen);
+ loginData.onTapScreen = $translate.instant('kMontage');
+ }
- if (typeof loginData.minAlarmCount === 'undefined') {
- debug("minAlarmCount does not exist, setting to true");
- loginData.minAlarmCount = 1;
- }
+ if (typeof loginData.minAlarmCount === 'undefined') {
+ debug("minAlarmCount does not exist, setting to true");
+ loginData.minAlarmCount = 1;
+ }
- if (typeof loginData.montageSize == 'undefined') {
- debug("montageSize does not exist, setting to 2 (2 per col)");
- loginData.montageSize = 2;
- }
+ if (typeof loginData.montageSize == 'undefined') {
+ debug("montageSize does not exist, setting to 2 (2 per col)");
+ loginData.montageSize = 2;
+ }
- if (typeof loginData.useNphZms == 'undefined') {
- debug("useNphZms does not exist. Setting to true");
- loginData.useNphZms = true;
- }
+ if (typeof loginData.useNphZms == 'undefined') {
+ debug("useNphZms does not exist. Setting to true");
+ loginData.useNphZms = true;
+ }
- if (typeof loginData.useNphZmsForEvents == 'undefined') {
- debug("useNphZmsForEvents does not exist. Setting to true");
- loginData.useNphZmsForEvents = true;
- }
+ if (typeof loginData.useNphZmsForEvents == 'undefined') {
+ debug("useNphZmsForEvents does not exist. Setting to true");
+ loginData.useNphZmsForEvents = true;
+ }
- if (typeof loginData.forceImageModePath == 'undefined') {
- debug("forceImageModePath does not exist. Setting to false");
- loginData.forceImageModePath = false;
- }
+ if (typeof loginData.forceImageModePath == 'undefined') {
+ debug("forceImageModePath does not exist. Setting to false");
+ loginData.forceImageModePath = false;
+ }
- if (typeof loginData.reachability == 'undefined') {
- debug("reachability does not exist. Setting to true");
- loginData.reachability = true;
- }
+ if (typeof loginData.reachability == 'undefined') {
+ debug("reachability does not exist. Setting to true");
+ loginData.reachability = true;
+ }
- // force it - this may not be the problem
- loginData.reachability = true;
+ // force it - this may not be the problem
+ loginData.reachability = true;
- // and now, force enable it
- loginData.useNphZms = true;
- loginData.useNphZmsForEvents = true;
+ // and now, force enable it
+ loginData.useNphZms = true;
+ loginData.useNphZmsForEvents = true;
- if (typeof loginData.packMontage == 'undefined') {
- debug("packMontage does not exist. Setting to false");
- loginData.packMontage = false;
- }
+ if (typeof loginData.packMontage == 'undefined') {
+ debug("packMontage does not exist. Setting to false");
+ loginData.packMontage = false;
+ }
- if (typeof loginData.forceNetworkStop == 'undefined') {
- debug("forceNetwork does not exist. Setting to false");
- loginData.forceNetworkStop = false;
- }
+ if (typeof loginData.forceNetworkStop == 'undefined') {
+ debug("forceNetwork does not exist. Setting to false");
+ loginData.forceNetworkStop = false;
+ }
- if (typeof loginData.enableLogs == 'undefined') {
- debug("enableLogs does not exist. Setting to true");
- loginData.enableLogs = true;
- }
+ if (typeof loginData.enableLogs == 'undefined') {
+ debug("enableLogs does not exist. Setting to true");
+ loginData.enableLogs = true;
+ }
- if (typeof loginData.defaultPushSound == 'undefined') {
- debug("defaultPushSound does not exist. Setting to false");
- loginData.defaultPushSound = false;
- }
+ if (typeof loginData.defaultPushSound == 'undefined') {
+ debug("defaultPushSound does not exist. Setting to false");
+ loginData.defaultPushSound = false;
+ }
- //console.log("INIT SIMUL=" + loginData.disableSimulStreaming);
- //console.log("INIT PLATFORM IS=" + $rootScope.platformOS);
- if (typeof loginData.disableSimulStreaming == 'undefined') {
+ //console.log("INIT SIMUL=" + loginData.disableSimulStreaming);
+ //console.log("INIT PLATFORM IS=" + $rootScope.platformOS);
+ if (typeof loginData.disableSimulStreaming == 'undefined') {
- loginData.disableSimulStreaming = false;
- //console.log("INIT DISABLING SIMUL:" + loginData.disableSimulStreaming);
- }
+ loginData.disableSimulStreaming = false;
+ //console.log("INIT DISABLING SIMUL:" + loginData.disableSimulStreaming);
+ }
- if (typeof loginData.exitOnSleep == 'undefined') {
- debug("exitOnSleep does not exist. Setting to false");
- loginData.exitOnSleep = false;
- }
+ if (typeof loginData.exitOnSleep == 'undefined') {
+ debug("exitOnSleep does not exist. Setting to false");
+ loginData.exitOnSleep = false;
+ }
- if (typeof loginData.enableBlog == 'undefined') {
- debug("enableBlog does not exist. Setting to true");
- loginData.enableBlog = true;
+ if (typeof loginData.enableBlog == 'undefined') {
+ debug("enableBlog does not exist. Setting to true");
+ loginData.enableBlog = true;
- }
+ }
- if (typeof loginData.packeryPositionsArray == 'undefined') {
- debug("packeryPositionsArray does not exist. Setting to empty");
- loginData.packeryPositionsArray = {};
+ if (typeof loginData.packeryPositionsArray == 'undefined') {
+ debug("packeryPositionsArray does not exist. Setting to empty");
+ loginData.packeryPositionsArray = {};
- }
+ }
- if (typeof loginData.packeryPositions == 'undefined') {
- debug("packeryPositions does not exist. Setting to empty");
- loginData.packeryPositions = "";
+ if (typeof loginData.packeryPositions == 'undefined') {
+ debug("packeryPositions does not exist. Setting to empty");
+ loginData.packeryPositions = "";
- }
+ }
- if (typeof loginData.EHpackeryPositions == 'undefined') {
- debug("EHpackeryPositions does not exist. Setting to empty");
- loginData.EHpackeryPositions = "";
+ if (typeof loginData.EHpackeryPositions == 'undefined') {
+ debug("EHpackeryPositions does not exist. Setting to empty");
+ loginData.EHpackeryPositions = "";
- }
+ }
- if (typeof loginData.packerySizes == 'undefined') {
- debug("packerySizes does not exist. Setting to empty");
- loginData.packerySizes = "";
+ if (typeof loginData.packerySizes == 'undefined') {
+ debug("packerySizes does not exist. Setting to empty");
+ loginData.packerySizes = "";
- }
+ }
- if (typeof loginData.use24hr == 'undefined') {
- debug("use24hr does not exist. Setting to false");
- loginData.use24hr = false;
+ if (typeof loginData.use24hr == 'undefined') {
+ debug("use24hr does not exist. Setting to false");
+ loginData.use24hr = false;
- }
+ }
- if (typeof timelineModalGraphType == 'undefined') {
- debug("timeline graph type not set. Setting to all");
- loginData.timelineModalGraphType = $translate.instant('kGraphAll');
- //console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + loginData.timelineModalGraphType);
- }
+ if (typeof timelineModalGraphType == 'undefined') {
+ debug("timeline graph type not set. Setting to all");
+ loginData.timelineModalGraphType = $translate.instant('kGraphAll');
+ //console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + loginData.timelineModalGraphType);
+ }
- if (typeof loginData.resumeDelay == 'undefined') {
- debug("resumeDelay does not exist. Setting to 0");
- loginData.resumeDelay = 0;
+ if (typeof loginData.resumeDelay == 'undefined') {
+ debug("resumeDelay does not exist. Setting to 0");
+ loginData.resumeDelay = 0;
- }
- // override resumeDelay - it was developed on a wrong assumption
- loginData.resumeDelay = 0;
+ }
+ // override resumeDelay - it was developed on a wrong assumption
+ loginData.resumeDelay = 0;
- if (typeof loginData.montageHistoryQuality == 'undefined') {
- debug("montageHistoryQuality does not exist. Setting to 50");
- loginData.montageHistoryQuality = "50";
+ if (typeof loginData.montageHistoryQuality == 'undefined') {
+ debug("montageHistoryQuality does not exist. Setting to 50");
+ loginData.montageHistoryQuality = "50";
- }
+ }
- if (typeof loginData.vibrateOnPush == 'undefined') {
- debug("vibrate on push not found, setting to true");
- loginData.vibrateOnPush = true;
+ if (typeof loginData.vibrateOnPush == 'undefined') {
+ debug("vibrate on push not found, setting to true");
+ loginData.vibrateOnPush = true;
- }
+ }
- if (typeof loginData.isFullScreen == 'undefined') {
+ if (typeof loginData.isFullScreen == 'undefined') {
- loginData.isFullScreen = false;
+ loginData.isFullScreen = false;
- }
+ }
- if (typeof loginData.reloadInMontage == 'undefined') {
+ if (typeof loginData.reloadInMontage == 'undefined') {
- loginData.reloadInMontage = false;
+ loginData.reloadInMontage = false;
- }
+ }
- if (typeof loginData.soundOnPush == 'undefined') {
- debug("sound on push not found, setting to true");
- loginData.soundOnPush = true;
+ if (typeof loginData.soundOnPush == 'undefined') {
+ debug("sound on push not found, setting to true");
+ loginData.soundOnPush = true;
- }
+ }
- if (typeof loginData.cycleMonitors == 'undefined') {
+ if (typeof loginData.cycleMonitors == 'undefined') {
- loginData.cycleMonitors = false;
+ loginData.cycleMonitors = false;
- }
+ }
- if (typeof loginData.cycleMonitorsInterval == 'undefined') {
+ if (typeof loginData.cycleMonitorsInterval == 'undefined') {
- loginData.cycleMonitorsInterval = 10;
+ loginData.cycleMonitorsInterval = 10;
- }
+ }
- if (typeof loginData.cycleMontage == 'undefined') {
+ if (typeof loginData.cycleMontage == 'undefined') {
- loginData.cycleMontage = false;
+ loginData.cycleMontage = false;
- }
+ }
- if (typeof loginData.cycleMontageInterval == 'undefined') {
+ if (typeof loginData.cycleMontageInterval == 'undefined') {
- loginData.cycleMontageInterval = 10;
+ loginData.cycleMontageInterval = 10;
- }
+ }
- if (typeof loginData.enableLowBandwidth == 'undefined') {
+ if (typeof loginData.enableLowBandwidth == 'undefined') {
- loginData.enableLowBandwidth = false;
+ loginData.enableLowBandwidth = false;
- }
- // wtf is wrong with this ternary?
- //$rootScope.runMode = (loginData.enableLowBandwith==true)? "low": "normal";
+ }
+ // wtf is wrong with this ternary?
+ //$rootScope.runMode = (loginData.enableLowBandwith==true)? "low": "normal";
- if (typeof loginData.autoSwitchBandwidth == 'undefined') {
+ if (typeof loginData.autoSwitchBandwidth == 'undefined') {
- loginData.autoSwitchBandwidth = false;
+ loginData.autoSwitchBandwidth = false;
- }
+ }
- $rootScope.runMode = getBandwidth();
- log("Setting NVR init bandwidth to: " + $rootScope.runMode);
+ $rootScope.runMode = getBandwidth();
+ log("Setting NVR init bandwidth to: " + $rootScope.runMode);
- if (typeof loginData.refreshSecLowBW == 'undefined') {
+ if (typeof loginData.refreshSecLowBW == 'undefined') {
- loginData.refreshSecLowBW = 8;
+ loginData.refreshSecLowBW = 8;
- }
+ }
- if (typeof loginData.disableAlarmCheckMontage == 'undefined') {
+ if (typeof loginData.disableAlarmCheckMontage == 'undefined') {
- loginData.disableAlarmCheckMontage = false;
+ loginData.disableAlarmCheckMontage = false;
- }
+ }
- if (typeof loginData.useLocalTimeZone == 'undefined') {
+ if (typeof loginData.useLocalTimeZone == 'undefined') {
- loginData.useLocalTimeZone = true;
+ loginData.useLocalTimeZone = true;
- }
+ }
- if (typeof loginData.fastLogin == 'undefined') {
+ if (typeof loginData.fastLogin == 'undefined') {
- loginData.fastLogin = true;
+ loginData.fastLogin = true;
- }
+ }
- if (typeof loginData.currentMontageProfile == 'undefined') {
+ if (typeof loginData.currentMontageProfile == 'undefined') {
- loginData.currentMontageProfile = '';
+ loginData.currentMontageProfile = '';
- }
+ }
- if (typeof loginData.followTimeLine == 'undefined') {
+ if (typeof loginData.followTimeLine == 'undefined') {
- loginData.followTimeLine = false;
+ loginData.followTimeLine = false;
- }
+ }
- if (typeof loginData.timelineScale == 'undefined') {
+ if (typeof loginData.timelineScale == 'undefined') {
- loginData.timelineScale = -1;
+ loginData.timelineScale = -1;
- }
+ }
- if (typeof loginData.showMontageSubMenu == 'undefined') {
+ if (typeof loginData.showMontageSubMenu == 'undefined') {
- loginData.showMontageSubMenu = false;
+ loginData.showMontageSubMenu = false;
- }
+ }
- if (typeof loginData.monSingleImageQuality == 'undefined') {
+ if (typeof loginData.monSingleImageQuality == 'undefined') {
- loginData.monSingleImageQuality = 100;
+ loginData.monSingleImageQuality = 100;
- }
+ }
- if (typeof loginData.hideArchived == 'undefined') {
+ if (typeof loginData.hideArchived == 'undefined') {
- loginData.hideArchived = false;
+ loginData.hideArchived = false;
- }
+ }
- if (typeof loginData.videoPlaybackSpeed == 'undefined') {
+ if (typeof loginData.videoPlaybackSpeed == 'undefined') {
- loginData.videoPlaybackSpeed = 1;
+ loginData.videoPlaybackSpeed = 1;
- }
+ }
- if (typeof loginData.enableThumbs == 'undefined') {
+ if (typeof loginData.enableThumbs == 'undefined') {
- loginData.enableThumbs = true;
+ loginData.enableThumbs = true;
- }
+ }
- if (typeof loginData.enableSlowLoading == 'undefined') {
+ if (typeof loginData.enableSlowLoading == 'undefined') {
- loginData.enableSlowLoading = false;
+ loginData.enableSlowLoading = false;
- }
+ }
- if (typeof loginData.enableStrictSSL == 'undefined') {
+ if (typeof loginData.enableStrictSSL == 'undefined') {
- loginData.enableStrictSSL = false;
+ loginData.enableStrictSSL = false;
- }
+ }
- if (typeof loginData.momentGridSize == 'undefined') {
+ if (typeof loginData.momentGridSize == 'undefined') {
- loginData.momentGridSize = 40;
+ loginData.momentGridSize = 40;
- }
+ }
- if (typeof loginData.enableMomentSubMenu == 'undefined') {
+ if (typeof loginData.enableMomentSubMenu == 'undefined') {
- loginData.enableMomentSubMenu = true;
+ loginData.enableMomentSubMenu = true;
- }
+ }
- if (typeof loginData.momentMonitorFilter == 'undefined') {
+ if (typeof loginData.momentMonitorFilter == 'undefined') {
- loginData.momentMonitorFilter = JSON.stringify([]);
+ loginData.momentMonitorFilter = JSON.stringify([]);
- }
+ }
- if (typeof loginData.momentArrangeBy == 'undefined') {
+ if (typeof loginData.momentArrangeBy == 'undefined') {
- loginData.momentArrangeBy = "StartTime";
+ loginData.momentArrangeBy = "StartTime";
- }
+ }
- if (typeof loginData.insertBasicAuthToken == 'undefined') {
+ if (typeof loginData.insertBasicAuthToken == 'undefined') {
- loginData.insertBasicAuthToken = false;
+ loginData.insertBasicAuthToken = false;
- }
+ }
- if (typeof loginData.showLiveForInProgressEvents == 'undefined') {
+ if (typeof loginData.showLiveForInProgressEvents == 'undefined') {
- loginData.showLiveForInProgressEvents = true;
+ loginData.showLiveForInProgressEvents = true;
- }
+ }
- if (typeof loginData.loginAPISupported == 'undefined') {
+ if (typeof loginData.loginAPISupported == 'undefined') {
- loginData.loginAPISupported = false;
+ loginData.loginAPISupported = false;
- }
+ }
- if (typeof loginData.montageResizeSteps == 'undefined') {
+ if (typeof loginData.montageResizeSteps == 'undefined') {
- loginData.montageResizeSteps = 5;
+ loginData.montageResizeSteps = 5;
- }
+ }
- if (typeof loginData.saveToCloud == 'undefined') {
+ if (typeof loginData.saveToCloud == 'undefined') {
- loginData.saveToCloud = true;
+ loginData.saveToCloud = true;
- }
+ }
- if (typeof loginData.montageReviewCollapse == 'undefined') {
+ if (typeof loginData.montageReviewCollapse == 'undefined') {
- loginData.montageReviewCollapse = true;
+ loginData.montageReviewCollapse = true;
- }
+ }
- if (typeof loginData.objectDetectionFilter == 'undefined') {
+ if (typeof loginData.objectDetectionFilter == 'undefined') {
- loginData.objectDetectionFilter = false;
+ loginData.objectDetectionFilter = false;
- }
+ }
- if (typeof loginData.enableEventRefresh == 'undefined') {
+ if (typeof loginData.enableEventRefresh == 'undefined') {
- loginData.enableEventRefresh = true;
+ loginData.enableEventRefresh = true;
- }
+ }
-
-
- if (typeof loginData.lastEventCheckTimes == 'undefined') {
- loginData.lastEventCheckTimes = {};
- }
+ if (typeof loginData.lastEventCheckTimes == 'undefined') {
+ loginData.lastEventCheckTimes = {};
- if (typeof loginData.enableMontageOverlays == 'undefined') {
- loginData.enableMontageOverlays = true;
+ }
- }
- if (typeof loginData.showMontageSidebars == 'undefined') {
- loginData.showMontageSidebars = false;
+ if (typeof loginData.enableMontageOverlays == 'undefined') {
+ loginData.enableMontageOverlays = true;
- }
+ }
- if (typeof loginData.isTokenSupported == 'undefined') {
- loginData.isTokenSupported = false;
+ if (typeof loginData.showMontageSidebars == 'undefined') {
+ loginData.showMontageSidebars = false;
- }
+ }
- if (typeof loginData.accessTokenExpires == 'undefined') {
- loginData.accessTokenExpires = '';
+ if (typeof loginData.isTokenSupported == 'undefined') {
+ loginData.isTokenSupported = false;
- }
+ }
- if (typeof loginData.refreshTokenExpires == 'undefined') {
- loginData.refreshTokenExpires = '';
+ if (typeof loginData.accessTokenExpires == 'undefined') {
+ loginData.accessTokenExpires = '';
- }
+ }
- if (typeof loginData.refreshToken == 'undefined') {
- loginData.refreshToken = '';
+ if (typeof loginData.refreshTokenExpires == 'undefined') {
+ loginData.refreshTokenExpires = '';
- }
+ }
- if (typeof loginData.accessToken == 'undefined') {
- loginData.accessToken = '';
+ if (typeof loginData.refreshToken == 'undefined') {
+ loginData.refreshToken = '';
- }
+ }
+
+ if (typeof loginData.accessToken == 'undefined') {
+ loginData.accessToken = '';
+
+ }
- loginData.canSwipeMonitors = true;
- loginData.forceImageModePath = false;
- loginData.enableBlog = true;
+ loginData.canSwipeMonitors = true;
+ loginData.forceImageModePath = false;
+ loginData.enableBlog = true;
}
@@ -1531,7 +1530,7 @@ angular.module('zmApp.controllers')
},
checkInitSanity: function (l) {
- _checkInitSanity(l);
+ _checkInitSanity(l);
},
init: function () {
@@ -1865,7 +1864,7 @@ angular.module('zmApp.controllers')
getAPIversion: function () {
var d = $q.defer();
- var apiurl = loginData.apiurl + '/host/getVersion.json?'+$rootScope.authSession;
+ var apiurl = loginData.apiurl + '/host/getVersion.json?' + $rootScope.authSession;
debug("getAPIversion called with " + apiurl);
$http.get(apiurl)
.then(function (success) {
@@ -1977,7 +1976,7 @@ angular.module('zmApp.controllers')
getAuthHashLogin: function () {
- return $http.get(loginData.apiurl + '/configs/viewByName/ZM_AUTH_HASH_LOGINS.json?'+$rootScope.authSession);
+ return $http.get(loginData.apiurl + '/configs/viewByName/ZM_AUTH_HASH_LOGINS.json?' + $rootScope.authSession);
},
@@ -1987,7 +1986,7 @@ angular.module('zmApp.controllers')
if (forceReload == 1 || configParams.ZM_EVENT_IMAGE_DIGITS == '-1') {
var apiurl = loginData.apiurl;
- var myurl = apiurl + '/configs/viewByName/ZM_EVENT_IMAGE_DIGITS.json?'+$rootScope.authSession;
+ var myurl = apiurl + '/configs/viewByName/ZM_EVENT_IMAGE_DIGITS.json?' + $rootScope.authSession;
//debug("Config URL for digits is:" + myurl);
$http.get(myurl)
.then(function (data) {
@@ -2024,7 +2023,7 @@ angular.module('zmApp.controllers')
var apiurl = loginData.apiurl;
- var myurl = apiurl + '/configs/viewByName/ZM_PATH_ZMS.json?'+$rootScope.authSession;
+ var myurl = apiurl + '/configs/viewByName/ZM_PATH_ZMS.json?' + $rootScope.authSession;
debug("Config URL for ZMS PATH is:" + myurl);
$http.get(myurl)
.then(function (data) {
@@ -2194,7 +2193,7 @@ angular.module('zmApp.controllers')
// use non cached for daemon status
getMultiServers: function () {
- return $http.get(loginData.apiurl + '/servers.json?'+$rootScope.authSession);
+ return $http.get(loginData.apiurl + '/servers.json?' + $rootScope.authSession);
},
@@ -2239,7 +2238,7 @@ angular.module('zmApp.controllers')
log((forceReload == 1) ? "getMonitors:Force reloading all monitors" : "getMonitors:Loading all monitors");
var apiurl = loginData.apiurl;
var myurl = apiurl + "/monitors";
- myurl += "/index/Type !=:WebSite.json?"+$rootScope.authSession;
+ myurl += "/index/Type !=:WebSite.json?" + $rootScope.authSession;
getZmsMultiPortSupport()
.then(function (zmsPort) {
@@ -2269,7 +2268,7 @@ angular.module('zmApp.controllers')
debug("Inside getMonitors, will also regen connkeys");
debug("Now trying to get multi-server data, if present");
- $http.get(apiurl + "/servers.json?"+$rootScope.authSession)
+ $http.get(apiurl + "/servers.json?" + $rootScope.authSession)
.then(function (data) {
data = data.data;
// We found a server list API, so lets make sure
@@ -2385,7 +2384,7 @@ angular.module('zmApp.controllers')
var sport = parseInt(zmsPort) + parseInt(monitors[i].Monitor.Id);
st = st + ':' + sport;
}
-
+
}
baseurl = st;
@@ -2535,9 +2534,117 @@ angular.module('zmApp.controllers')
},
+ recreateTokens: function () {
+
+ var d = $q.defer();
+
+ log("Doing fresh login to ZM");
+ var httpDelay = loginData.enableSlowLoading ? zm.largeHttpTimeout : zm.httpTimeout;
+
+ //first login using new API
+ $rootScope.authSession = '';
+ var loginAPI = loginData.apiurl + '/host/login.json';
+
+
+ $http({
+ method: 'post',
+ url: loginAPI,
+ timeout: httpDelay,
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded'
+ },
+ responseType: 'text',
+ transformResponse: undefined,
+ transformRequest: function (obj) {
+ var str = [];
+ for (var p in obj)
+ str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
+ return str.join("&");
+ },
+ data: {
+ user: loginData.username,
+ pass: loginData.password
+ }
+ })
+ //$http.get(loginAPI)
+ .then(function (textsucc) {
+ var succ;
+ //log (JSON.stringify(textsucc));
+ try {
+
+ succ = JSON.parse(textsucc.data);
+
+ if (!succ.version) {
+ d.reject("No version retrieved in API");
+ return d.promise;
+
+ }
+ debug("API based login returned... ");
+
+ $rootScope.authSession = '';
+ if (succ.refresh_token) {
+ $rootScope.authSession = '&token=' + succ.access_token;
+ log("New refresh token retrieved:" + succ.refresh_token);
+ loginData.isTokenSupported = true;
+
+ loginData.accessToken = succ.access_token;
+ loginData.accessTokenExpires = moment.utc().add(succ.access_token_expires, 'seconds');
+ loginData.refreshToken = succ.refresh_token;
+
+ loginData.refreshTokenExpires = moment.utc().add(succ.refresh_token_expires, 'seconds');
+
+ log("Current time is: UTC " + moment.utc().format("YYYY-MM-DD hh:mm:ss"));
+ log("New refresh token expires on: UTC " + loginData.refreshTokenExpires.format("YYYY-MM-DD hh:mm:ss"));
+ log("New access token expires on: UTC " + loginData.accessTokenExpires.format("YYYY-MM-DD hh:mm:ss"));
+ setLogin(loginData);
+
+ } else {
+ if (succ.credentials) {
+ log("Could not recover token details, trying old auth credentials");
+ loginData.isTokenSupported = false;
+ setLogin(loginData);
+ $rootScope.authSession = "&" + succ.credentials;
+ if (succ.append_password == '1') {
+ $rootScope.authSession = $rootScope.authSession +
+ loginData.password;
+ }
+ } else {
+ log("Neither token nor old cred worked. Seems like an error");
+ }
+ }
+
+ loginData.loginAPISupported = true;
+ setLogin(loginData);
+
+ log("Stream authentication construction: " +
+ $rootScope.authSession);
+
+ log("zmAutologin successfully logged into Zoneminder via API");
+ d.resolve("Login Success");
+ return d.promise;
+
+ } catch (e) {
+ debug("Login API approach did not work...");
+
+ d.reject("API based login failed")
+ return d.promise;
+
+ }
+ },
+ function (err) {
+ log("Error using login.json:" + JSON.stringify(err));
+ d.reject("Error in HTTP call to login.json");
+ return d.promise;
+ }
+ ); // post .then
+
+ return d.promise;
+
+ },
+
zmPrivacyProcessed: function () {
var apiurl = loginData.apiurl;
- var myurl = apiurl + '/configs/viewByName/ZM_SHOW_PRIVACY.json?'+$rootScope.authSession;
+ var myurl = apiurl + '/configs/viewByName/ZM_SHOW_PRIVACY.json?' + $rootScope.authSession;
var d = $q.defer();
$http({
@@ -2676,7 +2783,7 @@ angular.module('zmApp.controllers')
if (!tz || isForce) {
log("First invocation of TimeZone, asking server");
- var apiurl = loginData.apiurl + '/host/getTimeZone.json?'+$rootScope.authSession;
+ var apiurl = loginData.apiurl + '/host/getTimeZone.json?' + $rootScope.authSession;
$http.get(apiurl)
.then(function (success) {
tz = success.data.tz;
@@ -2739,7 +2846,7 @@ angular.module('zmApp.controllers')
}
- myurl = myurl + ".json?"+$rootScope.authSession;
+ myurl = myurl + ".json?" + $rootScope.authSession;
//console.log (">>>>>Constructed URL " + myurl);
$ionicLoading.show({
@@ -2827,7 +2934,7 @@ angular.module('zmApp.controllers')
myurl = myurl + '/Notes REGEXP:detected:';
}
- myurl = myurl + ".json?&sort=StartTime&direction=desc&page=" + pageId+$rootScope.authSession;
+ myurl = myurl + ".json?&sort=StartTime&direction=desc&page=" + pageId + $rootScope.authSession;
debug("getEvents:" + myurl);
@@ -3095,7 +3202,7 @@ angular.module('zmApp.controllers')
// always resolves
if (!loginData.isUseAuth || (loginData.loginAPISupported && loginData.isTokenSupported)) {
- log ("No need for logout!");
+ log("No need for logout!");
d.resolve(true);
return d.promise;
}
@@ -3106,7 +3213,7 @@ angular.module('zmApp.controllers')
});
-
+
log(loginData.url + "=>Logging out of any existing ZM sessions...");
$rootScope.authSession = "undefined";
diff --git a/www/js/app.js b/www/js/app.js
index f64ea1da..3cdf49da 100755
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -648,7 +648,7 @@ angular.module('zmApp', [
//console.log ("HERE TIMEOUT");
return {
- 'request': function (config) {
+ request: function (config) {
if (!config) return config;
if (!config.url) return config;
@@ -682,7 +682,25 @@ angular.module('zmApp', [
return config;
},
- 'response': function (response) {
+ responseError: function (rejection) {
+ if (rejection.status == 401) {
+ nvr = $injector.get('NVR');
+ nvr.log ("******** INTERCEPTOR CAUGHT ERROR, RE-LOGIN NEEDED");
+
+ return nvr.recreateTokens()
+ .then (function() {
+ return $injector.get('$http')(rejection.config);
+ })
+ }
+ else {
+ nvr.log ("NOT 401");
+ return response;
+ }
+
+ },
+
+ response: function (response) {
+
var cookies = response.headers("Set-Cookie");
if (cookies != null) {
@@ -699,6 +717,7 @@ angular.module('zmApp', [
//console.log ("HTTP response");
+
if (response.data && typeof(response.data) == 'string' && (response.data.indexOf("<pre class=\"cake-error\">")==0)) {
console.log ("cake error detected, attempting fix...");
@@ -1037,7 +1056,7 @@ angular.module('zmApp', [
return d.promise;
-
+
function proceedWithLogin() {
@@ -1065,7 +1084,7 @@ angular.module('zmApp', [
var diff_refresh = moment.utc(ld.refreshTokenExpires).diff(now, 'minutes');
// first see if we can work with access token
- if (moment.utc(ld.accessTokenExpires).isAfter(now) && diff_access >=30) {
+ if (moment.utc(ld.accessTokenExpires).isAfter(now) && diff_access >=5) {
NVR.log ("Access token still has "+diff_access+" minutes left, using it");
$rootScope.authSession = '&token='+ld.accessToken;
d.resolve("Login success via access token");
@@ -1075,8 +1094,8 @@ angular.module('zmApp', [
// then see if we have at least 30 mins left for refresh token
else if (moment.utc(ld.refreshTokenExpires).isAfter(now) && diff_refresh >=30) {
NVR.log ("Refresh token still has "+diff_refresh+" minutes left, using it");
- var loginAPI = loginData.apiurl + '/host/login.json?token='+ld.refreshToken;
- $http.get($loginAPI)
+ var loginAPI = ld.apiurl + '/host/login.json?token='+ld.refreshToken;
+ $http.get(loginAPI)
.then (function (succ) {
succ = succ.data;
if (succ.access_token) {
@@ -1116,17 +1135,17 @@ angular.module('zmApp', [
// your stream should not get frozen
$rootScope.rand = Math.floor((Math.random() * 100000) + 1);
$rootScope.modalRand = Math.floor((Math.random() * 100000) + 1);
-
+
// console.log ("***** STATENAME IS " + statename);
-
+
var d = $q.defer();
var ld = NVR.getLogin();
NVR.log("Doing fresh login to ZM");
var httpDelay = NVR.getLogin().enableSlowLoading ? zm.largeHttpTimeout : zm.httpTimeout;
-
+
if (!str) str = $translate.instant('kAuthenticating');
-
+
if (str) {
$ionicLoading.show({
template: str,
@@ -1134,19 +1153,19 @@ angular.module('zmApp', [
duration: httpDelay
});
}
-
+
//console.log(">>>>>>>>>>>>>> ISRECAPTCHA");
-
+
var loginData = NVR.getLogin();
var currentServerVersion = NVR.getCurrentServerVersion();
-
-
+
+
//first login using new API
$rootScope.authSession = '';
var loginAPI = loginData.apiurl + '/host/login.json';
-
-
-
+
+
+
$http({
method: 'post',
url: loginAPI,
@@ -1169,19 +1188,19 @@ angular.module('zmApp', [
})
//$http.get(loginAPI)
.then(function (textsucc) {
-
+
$ionicLoading.hide();
var succ;
try {
-
+
succ = JSON.parse(textsucc.data);
-
+
if (!succ.version) {
NVR.debug("API login returned fake success, going back to webscrape");
ld = NVR.getLogin();
ld.loginAPISupported = false;
NVR.setLogin(ld);
-
+
loginWebScrape()
.then(function (succ) {
d.resolve("Login Success");
@@ -1200,7 +1219,7 @@ angular.module('zmApp', [
$ionicLoading.hide();
//$rootScope.loggedIntoZm = 1;
$rootScope.authSession = '';
-
+
if (succ.refresh_token) {
$rootScope.authSession = '&token='+succ.access_token;
NVR.log ("New refresh token retrieved:"+succ.refresh_token);
@@ -1216,7 +1235,7 @@ angular.module('zmApp', [
NVR.log ("New refresh token expires on: UTC "+ld.refreshTokenExpires.format("YYYY-MM-DD hh:mm:ss"));
NVR.log ("New access token expires on: UTC "+ld.accessTokenExpires.format("YYYY-MM-DD hh:mm:ss"));
NVR.setLogin(ld);
-
+
}
else {
if (succ.credentials) {
@@ -1234,22 +1253,22 @@ angular.module('zmApp', [
}
}
-
+
var ldg = NVR.getLogin();
ldg.loginAPISupported = true;
NVR.setLogin(ldg);
-
+
NVR.log("Stream authentication construction: " +
$rootScope.authSession);
-
+
NVR.log("zmAutologin successfully logged into Zoneminder via API");
-
-
-
+
+
+
d.resolve("Login Success");
$rootScope.$broadcast('auth-success', succ);
return d.promise;
-
+
} catch (e) {
NVR.debug("Login API approach did not work...");
@@ -1268,11 +1287,11 @@ angular.module('zmApp', [
return (d.promise);
});
return d.promise;
-
+
}
-
-
-
+
+
+
},
function (err) {
console.log("******************* API login error " + JSON.stringify(err));
@@ -1292,17 +1311,21 @@ angular.module('zmApp', [
d.reject("Login Error");
return (d.promise);
});
-
+
}
); // post .then
-
+
return d.promise;
}
+
return d.promise;
}
+
+
+
function loginWebScrape() {
var loginData = NVR.getLogin();
var d = $q.defer();