summaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
Diffstat (limited to 'www')
-rwxr-xr-xwww/js/DataModel.js29
-rwxr-xr-xwww/js/app.js283
2 files changed, 179 insertions, 133 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js
index 2e7279ad..ee0603e5 100755
--- a/www/js/DataModel.js
+++ b/www/js/DataModel.js
@@ -302,17 +302,19 @@ angular.module('zmApp.controllers')
var myurl = apiurl + '/configs/viewByName/ZM_MIN_STREAMING_PORT.json';
$http.get(myurl)
.success(function (data) {
- configParams.ZM_MIN_STREAMING_PORT = data.config.Value;
+ //console.log ("GOT " + JSON.stringify(data));
- if (!data.config.Value) {
+ if (data.config && data.config.Value) {
+ configParams.ZM_MIN_STREAMING_PORT = data.config.Value;
+ setCurrentServerMultiPortSupported(true);
+ log("Got min streaming port value of: " + configParams.ZM_MIN_STREAMING_PORT);
+ }
+ else {
setCurrentServerMultiPortSupported(false);
log("ZM_MIN_STREAMING_PORT not configure, disabling");
configParams.ZM_MIN_STREAMING_PORT = 0;
- } else {
- setCurrentServerMultiPortSupported(true);
- log("Got min streaming port value of: " + configParams.ZM_MIN_STREAMING_PORT);
}
-
+
d.resolve(configParams.ZM_MIN_STREAMING_PORT);
return (d.promise);
@@ -347,10 +349,10 @@ angular.module('zmApp.controllers')
return d.promise;
}
- if (versionCompare(currentServerVersion, zm.versionWithLoginAPI) != -1 || loginData.loginAPISupported) {
+ if (currentServerVersion && (versionCompare(currentServerVersion, zm.versionWithLoginAPI) != -1 || loginData.loginAPISupported)) {
myurl = loginData.apiurl + '/host/getCredentials.json';
- debug("Server version > 1.31.41, so using getCredentials API:" + myurl);
+ debug("Server version " + currentServerVersion+ " > 1.31.41, so using getCredentials API:" + myurl);
$http.get(myurl)
.then(function (s) {
@@ -1590,6 +1592,7 @@ angular.module('zmApp.controllers')
$http.get(apiurl)
.then(function (success) {
if (success.data.version) {
+ // console.log ("API VERSION RETURNED: " + JSON.stringify(success));
$rootScope.apiValid = true;
setCurrentServerVersion(success.data.version);
d.resolve(success.data.version);
@@ -1921,7 +1924,7 @@ angular.module('zmApp.controllers')
debug("Monitor URL to fetch is:" + myurl);
$http.get(myurl /*,{timeout:15000}*/ )
.success(function (data) {
- //console.log("HTTP success got " + JSON.stringify(data.monitors));
+ // console.log("HTTP success got " + JSON.stringify(data.monitors));
monitors = data.monitors;
@@ -2645,17 +2648,19 @@ angular.module('zmApp.controllers')
$rootScope.authSession = "undefined";
- if (versionCompare(currentServerVersion, zm.versionWithLoginAPI) != -1 || loginData.loginAPISupported) {
+// console.log ("CURRENT SERVER: "+currentServerVersion);
+
+ if (currentServerVersion && (versionCompare(currentServerVersion, zm.versionWithLoginAPI) != -1 || loginData.loginAPISupported)) {
debug ("Logging out using API method");
$http.get(loginData.apiurl+'/host/logout.json')
.then (function(s) {
- debug ("Logout returned "+JSON.stringify(s));
+ debug ("Logout returned... ");
d.resolve(true);
return d.promise;
},
function (e) {
- debug ("Logout errored "+JSON.stringify(e));
+ debug ("Logout errored but really don't worry, your ZM version may not support it");
d.resolve(true);
return d.promise;
}
diff --git a/www/js/app.js b/www/js/app.js
index c5c9c8ba..6be6d91a 100755
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -1060,7 +1060,26 @@ angular.module('zmApp', [
//$http.get(loginAPI)
.then(function (succ) {
- NVRDataModel.debug ("API based login returned: "+JSON.stringify(succ));
+
+ if (!succ.data.version) {
+
+ NVRDataModel.debug ("API login returned fake success, going back to webscrape");
+ var ld = NVRDataModel.getLogin();
+ ld.loginAPISupported = false;
+ NVRDataModel.setLogin(ld);
+
+ loginWebScrape()
+ .then ( function (succ) {
+ d.resolve("Login Success");
+ return d.promise;
+ },
+ function (err) {
+ d.reject("Login Error");
+ return (d.promise);
+ });
+ return d.promise;
+ }
+ NVRDataModel.debug ("API based login returned... ");
NVRDataModel.setCurrentServerVersion(succ.data.version);
$ionicLoading.hide();
$rootScope.loggedIntoZm = 1;
@@ -1074,9 +1093,9 @@ angular.module('zmApp', [
}
}
- var ld = NVRDataModel.getLogin();
- ld.loginAPISupported = true;
- NVRDataModel.setLogin(ld);
+ var ldg = NVRDataModel.getLogin();
+ ldg.loginAPISupported = true;
+ NVRDataModel.setLogin(ldg);
NVRDataModel.log("Stream authentication construction: " +
$rootScope.authSession);
@@ -1098,156 +1117,178 @@ angular.module('zmApp', [
if ('success' in err.data) {
console.log("API based login not supported, need to use web scraping...");
// login using old web scraping
+ var ld = NVRDataModel.getLogin();
+ ld.loginAPISupported = false;
+ NVRDataModel.setLogin(ld);
+ loginWebScrape()
+ .then ( function (succ) {
+ d.resolve("Login Success");
+ return d.promise;
+ },
+ function (err) {
+ d.reject("Login Error");
+ return (d.promise);
+ });
- NVRDataModel.debug("Logging in using old web-scrape method");
- NVRDataModel.isReCaptcha()
- .then(function (result) {
- if (result == true) {
- $ionicLoading.hide();
- NVRDataModel.displayBanner('error', ['reCaptcha must be disabled', ], "", 8000);
- var alertPopup = $ionicPopup.alert({
- title: 'reCaptcha enabled',
- template: $translate.instant('kRecaptcha'),
- okText: $translate.instant('kButtonOk'),
- cancelText: $translate.instant('kButtonCancel'),
- });
-
- // close it after 5 seconds
- $timeout(function () {
- alertPopup.close();
- }, 5000);
+ }
+ else {
+ $rootScope.loggedIntoZm = -1;
+ //console.log("**** ZM Login FAILED");
+ NVRDataModel.log("zmAutologin Error via API: some meta foo", "error");
+ $rootScope.$broadcast('auth-error', "I'm confused why");
- d.reject("Error-disable recaptcha");
- return (d.promise);
- }
+ d.reject("Login Error");
+ return (d.promise);
- });
+ }
- var hDelay = loginData.enableSlowLoading ? zm.largeHttpTimeout : zm.httpTimeout;
- //NVRDataModel.debug ("*** AUTH LOGIN URL IS " + loginData.url);
- $http({
-
- method: 'POST',
- timeout: hDelay,
- //withCredentials: true,
- url: loginData.url + '/index.php',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Accept': 'application/json',
- },
- transformRequest: function (obj) {
- var str = [];
- for (var p in obj)
- str.push(encodeURIComponent(p) + "=" +
- encodeURIComponent(obj[p]));
- var params = str.join("&");
- return params;
- },
-
- data: {
- username: loginData.username,
- password: loginData.password,
- action: "login",
- view: "console"
- }
- })
- .success(function (data, status, headers) {
- // console.log(">>>>>>>>>>>>>> PARALLEL POST SUCCESS");
- $ionicLoading.hide();
+
+ }
+ );
- // Coming here does not mean success
- // it could also be a bad login, but
- // ZM returns you to login.php and returns 200 OK
- // so we will check if the data has
- // <title>ZM - Login</title> -- it it does then its the login page
- if (data.indexOf(zm.loginScreenString) == -1) {
- //eventServer.start();
- $rootScope.loggedIntoZm = 1;
- NVRDataModel.log("zmAutologin successfully logged into Zoneminder");
+ return d.promise;
+ }
- d.resolve("Login Success");
+ return d.promise;
- $rootScope.$broadcast('auth-success', data);
+ }
- } else // this means login error
- {
- $rootScope.loggedIntoZm = -1;
- //console.log("**** ZM Login FAILED");
- NVRDataModel.log("zmAutologin Error: Bad Credentials ", "error");
- $rootScope.$broadcast('auth-error', "incorrect credentials");
+ function loginWebScrape() {
+ var loginData = NVRDataModel.getLogin();
+ var d = $q.defer();
+ NVRDataModel.debug("Logging in using old web-scrape method");
+ NVRDataModel.isReCaptcha()
+ .then(function (result) {
+ if (result == true) {
+ $ionicLoading.hide();
+ NVRDataModel.displayBanner('error', ['reCaptcha must be disabled', ], "", 8000);
+ var alertPopup = $ionicPopup.alert({
+ title: 'reCaptcha enabled',
+ template: $translate.instant('kRecaptcha'),
+ okText: $translate.instant('kButtonOk'),
+ cancelText: $translate.instant('kButtonCancel'),
+ });
- d.reject("Login Error");
- return (d.promise);
- }
+ // close it after 5 seconds
+ $timeout(function () {
- // Now go ahead and re-get auth key
- // if login was a success
- $rootScope.authSession = "undefined";
- var ld = NVRDataModel.getLogin();
- NVRDataModel.getAuthKey($rootScope.validMonitorId)
- .then(function (success) {
+ alertPopup.close();
+ }, 5000);
- //console.log(success);
- $rootScope.authSession = success;
- NVRDataModel.log("Stream authentication construction: " +
- $rootScope.authSession);
+ d.reject("Error-disable recaptcha");
+ return (d.promise);
+ }
- },
- function (error) {
- //console.log(error);
+ });
- NVRDataModel.log("Modal: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession);
- NVRDataModel.debug("Error was: " + JSON.stringify(error));
- });
+ var hDelay = loginData.enableSlowLoading ? zm.largeHttpTimeout : zm.httpTimeout;
+ //NVRDataModel.debug ("*** AUTH LOGIN URL IS " + loginData.url);
+ $http({
+
+ method: 'POST',
+ timeout: hDelay,
+ //withCredentials: true,
+ url: loginData.url + '/index.php',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ 'Accept': 'application/json',
+ },
+ transformRequest: function (obj) {
+ var str = [];
+ for (var p in obj)
+ str.push(encodeURIComponent(p) + "=" +
+ encodeURIComponent(obj[p]));
+ var params = str.join("&");
+ return params;
+ },
- return (d.promise);
+ data: {
+ username: loginData.username,
+ password: loginData.password,
+ action: "login",
+ view: "console"
+ }
+ })
+ .success(function (data, status, headers) {
+ // console.log(">>>>>>>>>>>>>> PARALLEL POST SUCCESS");
+ $ionicLoading.hide();
- })
- .error(function (error, status) {
+ // Coming here does not mean success
+ // it could also be a bad login, but
+ // ZM returns you to login.php and returns 200 OK
+ // so we will check if the data has
+ // <title>ZM - Login</title> -- it it does then its the login page
- // console.log(">>>>>>>>>>>>>> PARALLEL POST ERROR");
- $ionicLoading.hide();
+ if (data.indexOf(zm.loginScreenString) == -1) {
+ //eventServer.start();
+ $rootScope.loggedIntoZm = 1;
- //console.log("**** ZM Login FAILED");
+ NVRDataModel.log("zmAutologin successfully logged into Zoneminder");
+ $rootScope.apiValid = true;
- // FIXME: Is this sometimes results in null
+ // now go to authKey part, so don't return yet...
- NVRDataModel.log("zmAutologin Error " + JSON.stringify(error) + " and status " + status);
- // bad urls etc come here
- $rootScope.loggedIntoZm = -1;
- $rootScope.$broadcast('auth-error', error);
+ } else // this means login error
+ {
+ $rootScope.loggedIntoZm = -1;
+ //console.log("**** ZM Login FAILED");
+ NVRDataModel.log("zmAutologin Error: Bad Credentials ", "error");
+ $rootScope.$broadcast('auth-error', "incorrect credentials");
+
+ d.reject("Login Error");
+ return (d.promise);
+ // no need to go to next code, so return above
+ }
- d.reject("Login Error");
- return d.promise;
- });
+ // Now go ahead and re-get auth key
+ // if login was a success
+ $rootScope.authSession = "undefined";
+ var ld = NVRDataModel.getLogin();
+ NVRDataModel.getAuthKey($rootScope.validMonitorId)
+ .then(function (success) {
+ //console.log(success);
+ $rootScope.authSession = success;
+ NVRDataModel.log("Stream authentication construction: " +
+ $rootScope.authSession);
+ d.resolve("Login Success");
+ $rootScope.$broadcast('auth-success', data);
+ return d.promise;
- }
- else {
- $rootScope.loggedIntoZm = -1;
- //console.log("**** ZM Login FAILED");
- NVRDataModel.log("zmAutologin Error via API: some meta foo", "error");
- $rootScope.$broadcast('auth-error', "I'm confused why");
+ },
+ function (error) {
+ //console.log(error);
- d.reject("Login Error");
- return (d.promise);
+ NVRDataModel.log("Modal: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession);
+ NVRDataModel.debug("Error was: " + JSON.stringify(error));
+ d.resolve("Login Success");
+ $rootScope.$broadcast('auth-success', data);
+ });
- }
+ return (d.promise);
-
- }
- );
+ })
+ .error(function (error, status) {
+ // console.log(">>>>>>>>>>>>>> PARALLEL POST ERROR");
+ $ionicLoading.hide();
+ //console.log("**** ZM Login FAILED");
- return d.promise;
- }
+ // FIXME: Is this sometimes results in null
- return d.promise;
+ NVRDataModel.log("zmAutologin Error " + JSON.stringify(error) + " and status " + status);
+ // bad urls etc come here
+ $rootScope.loggedIntoZm = -1;
+ $rootScope.$broadcast('auth-error', error);
+ d.reject("Login Error");
+ return d.promise;
+ });
+ return d.promise;
}
function start() {