diff options
Diffstat (limited to 'www/js')
| -rw-r--r-- | www/js/DataModel.js | 73 | ||||
| -rw-r--r-- | www/js/LogCtrl.js | 8 | ||||
| -rw-r--r-- | www/js/app.js | 16 |
3 files changed, 72 insertions, 25 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js index 8a5c5921..5ee4c18c 100644 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -2,7 +2,7 @@ /* jslint browser: true*/ -/* global cordova,StatusBar,angular,console, URI, moment, localforage*/ +/* global cordova,StatusBar,angular,console, URI, moment, localforage, CryptoJS */ // This is my central data respository and common functions // that many other controllers use @@ -141,7 +141,20 @@ angular.module('zmApp.controllers') //-------------------------------------------------------------------------- function zmLog(val, logtype) { if (loginData.enableLogs) + { + if (val!== undefined) + { + var regex = /"password":".*?"/; + + //console.log ("VAL IS " + val); + val = val.replace(regex, "<password removed>"); + + } + // make sure password is removed + //"username":"zmninja","password":"xyz", + //val = val.replace(/\"password:\", $fileLogger.log(logtype, val); + } } @@ -150,8 +163,12 @@ angular.module('zmApp.controllers') function setLogin(newLogin) { loginData = angular.copy(newLogin); serverGroupList[loginData.serverName] = angular.copy(loginData); + + var ct = CryptoJS.AES.encrypt(JSON.stringify(serverGroupList), zm.cipherKey).toString(); + + console.log ("****serverLogin was encrypted to " + ct); //$localstorage.setObject("serverGroupList", serverGroupList); - localforage.setItem("serverGroupList", serverGroupList, function (err) { + localforage.setItem("serverGroupList", ct, function (err) { if (err) zmLog("localforage store error " + JSON.stringify(err)); }); //$localstorage.set("defaultServerName", loginData.serverName); @@ -161,22 +178,22 @@ angular.module('zmApp.controllers') - //setDB("serverGroupList", serverGroupList); - //setDB ("defaultServerName", loginData.serverName); - - - - - - // console.log ("SAVING " + loginData.serverName); - // console.log ("DATA IS " + JSON.stringify(loginData)); } // separate out a debug so we don't do this if comparison for normal logs function zmDebug(val) { if (loginData.enableDebug && loginData.enableLogs) + { + if (val!== undefined) + { + var regex = /"password":".*?"/; + + //console.log ("VAL IS " + val); + val = val.replace(regex, "<password removed>"); + } $fileLogger.debug(val); + } } //credit: https://gist.github.com/alexey-bass/1115557 @@ -248,6 +265,7 @@ angular.module('zmApp.controllers') zmDebug: function (val) { + zmDebug(val); }, @@ -432,12 +450,33 @@ angular.module('zmApp.controllers') localforage.getItem("serverGroupList").then(function (val) { + // decrypt it now + + var decodedVal; + + if (typeof val == 'string') + { + zmLog ("user profile encrypted, decoding..."); + var bytes = CryptoJS.AES.decrypt(val.toString(), zm.cipherKey); + decodedVal = JSON.parse(bytes.toString(CryptoJS.enc.Utf8)); + + } + else + { + zmLog ("user profile not encrypted"); + decodedVal = val; + } + + zmDebug ("user profile retrieved:"+JSON.stringify(decodedVal)); + $ionicLoading.hide(); - serverGroupList = val; - console.log(">>>> serverGroupList " + JSON.stringify(serverGroupList)); + serverGroupList = decodedVal; + + + // console.log(">>>> DECRYPTED serverGroupList " + JSON.stringify(serverGroupList)); var demoServer = "{\"serverName\":\"zmNinjaDemo\",\"username\":\"zmninja\",\"password\":\"zmNinja$xc129\",\"url\":\"https://demo.zoneminder.com/zm\",\"apiurl\":\"https://demo.zoneminder.com/zm/api\",\"eventServer\":\"\",\"maxMontage\":\"40\",\"streamingurl\":\"https://demo.zoneminder.com/cgi-bin-zm\",\"maxFPS\":\"3\",\"montageQuality\":\"50\",\"singleImageQuality\":\"100\",\"montageHistoryQuality\":\"50\",\"useSSL\":true,\"keepAwake\":true,\"isUseAuth\":\"1\",\"isUseEventServer\":false,\"disablePush\":false,\"eventServerMonitors\":\"\",\"eventServerInterval\":\"\",\"refreshSec\":\"2\",\"enableDebug\":false,\"usePin\":false,\"pinCode\":\"\",\"canSwipeMonitors\":true,\"persistMontageOrder\":false,\"onTapScreen\":\"Events\",\"enableh264\":true,\"gapless\":false,\"montageOrder\":\"\",\"montageHiddenOrder\":\"\",\"montageArraySize\":\"0\",\"graphSize\":2000,\"enableAlarmCount\":true,\"montageSize\":\"3\",\"useNphZms\":true,\"useNphZmsForEvents\":true,\"packMontage\":false,\"exitOnSleep\":false,\"forceNetworkStop\":false,\"defaultPushSound\":false,\"enableBlog\":true,\"use24hr\":false, \"packeryPositions\":\"\"}"; var demoS = JSON.parse(demoServer); - console.log("JSON parsed demo" + JSON.stringify(demoS)); + //console.log("JSON parsed demo" + JSON.stringify(demoS)); var isFoundDemo = false; var as = Object.keys(serverGroupList); @@ -466,9 +505,9 @@ angular.module('zmApp.controllers') $ionicLoading.hide(); //console.log ("!!!!!!!!!!!!!!!!!!default server name is " + sname); sname = val; - console.log("!!!!!!!!!!!!!!!!!!!Got VAL " + sname); + // console.log("!!!!!!!!!!!!!!!!!!!Got VAL " + sname); var loadedData = serverGroupList[sname]; - console.log(">>>>>>>>>>> loadedData is: " + JSON.stringify(loadedData)); + // console.log(">>>>>>>>>>> loadedData is: " + JSON.stringify(loadedData)); if (!isEmpty(loadedData)) { loginData = loadedData; @@ -588,7 +627,7 @@ angular.module('zmApp.controllers') if (typeof timelineModalGraphType == 'undefined') { zmDebug("timeline graph type not set. Setting to all"); loginData.timelineModalGraphType = $translate.instant('kGraphAll'); - console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + loginData.timelineModalGraphType); + //console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + loginData.timelineModalGraphType); } if (typeof loginData.resumeDelay == 'undefined') { diff --git a/www/js/LogCtrl.js b/www/js/LogCtrl.js index f7c2f66a..31e580e3 100644 --- a/www/js/LogCtrl.js +++ b/www/js/LogCtrl.js @@ -96,12 +96,14 @@ angular.module('zmApp.controllers').controller('zmApp.LogCtrl', ['$scope', '$roo // do my best to replace sensitive information var loginData = ZMDataModel.getLogin(); - // if its null you will see deleted everywhere - if (loginData.password !="") + + + // We don't need this anymore as zmLog and zmDebug now strip passwords + /*if (loginData.password !="") { var re1 = new RegExp(loginData.password, "g"); logstring = logstring.replace(re1, "<deleted>"); - } + }*/ // keep the protocol, helps to debug var urlNoProtocol = loginData.url.replace(/.*?:\/\//, ""); if (urlNoProtocol != "") diff --git a/www/js/app.js b/www/js/app.js index 2cd9422c..e776d18c 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1,6 +1,6 @@ /* jshint -W041 */ /* jslint browser: true*/ -/* global cordova,StatusBar,angular,console,alert,PushNotification, moment ,ionic, URI,Packery, ConnectSDK, localforage,$*/ +/* global cordova,StatusBar,angular,console,alert,PushNotification, moment ,ionic, URI,Packery, ConnectSDK, CryptoJS, localforage,$*/ var appVersion = "0.0.0"; @@ -78,11 +78,10 @@ angular.module('zmApp', [ eventHistoryTimer: 10000, eventPlaybackQuery: 3000, packeryTimer: 500, - dbName: 'zmninja' + dbName: 'zmninja', + cipherKey: 'sdf#@#%FSXSA_AR' - - }) @@ -1085,6 +1084,11 @@ angular.module('zmApp', [ //--------------------------------------------------------------------- $ionicPlatform.ready(function () { + + + + + $rootScope.db = null; @@ -1176,7 +1180,9 @@ angular.module('zmApp', [ }) .then (function() { ZMDataModel.zmLog (">>>>migrated latestBlogPostChecked..."); - return localforage.setItem('serverGroupList', sgl); + // lets encrypt serverGroupList + var ct = CryptoJS.AES.encrypt(JSON.stringify(sgl), zm.cipherKey); + return localforage.setItem('serverGroupList', ct); }) .then (function() { ZMDataModel.zmLog (">>>>migrated serverGroupList..."); |
