1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/* jshint -W041 */
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console */
angular.module('zmApp.controllers').controller('zmApp.LogCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$fileLogger', '$cordovaEmailComposer', '$ionicPopup', function ($scope, $rootScope, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $fileLogger, $cordovaEmailComposer, $ionicPopup) {
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
//--------------------------------------------------------------------------
// Make sure user knows information masking is best effort
//--------------------------------------------------------------------------
$scope.sendEmail = function (logstring) {
$ionicPopup.confirm({
title: 'Sensitive Information',
template: 'zmNinja will modify the logs when creating the email to remove sensitive data like urls and passwords. However it is eventually <b>your responsibility</b> to make sure there is no sensitive data in the logs. Please make sure you review and edit the logs in the next screen before you send.'
})
.then(function (res) {
if (res) sendEmailReally(logstring);
});
};
//--------------------------------------------------------------------------
// Convenience function to send logs via email
//--------------------------------------------------------------------------
function sendEmailReally(logstring) {
if (window.cordova) {
$cordovaEmailComposer.isAvailable().then(function () {
// do my best to replace sensitive information
var loginData = ZMDataModel.getLogin();
var re1 = new RegExp(loginData.password, "g");
logstring = logstring.replace(re1, "<deleted>");
// keep the protocol, helps to debug
var urlNoProtocol = loginData.url.replace(/.*?:\/\//, "");
var re2 = new RegExp(urlNoProtocol, "g");
// just replacing baseurl - that will take care of
// masking api but may not be cgi
logstring = logstring.replace(re2, "<server>");
urlNoProtocol = loginData.streamingurl.replace(/.*?:\/\//, "");
var re3 = new RegExp(urlNoProtocol, "g");
logstring = logstring.replace(re3, "<server>");
var email = {
to: 'pliablepixels+zmNinja@gmail.com',
subject: 'zmNinja Logs',
body: logstring,
isHtml: false
};
$cordovaEmailComposer.open(email)
.then(null, function () {
// user cancelled email
});
}, function () {
ZMDataModel.zmLog("Email plugin not found", "error");
});
} else {
console.log("Skipping email module as cordova does not exist");
}
}
//-------------------------------------------------------------------------
// Lets make sure we set screen dim properly as we enter
// The problem is we enter other states before we leave previous states
// from a callback perspective in ionic, so we really can't predictably
// reset power state on exit as if it is called after we enter another
// state, that effectively overwrites current view power management needs
//------------------------------------------------------------------------
$scope.$on('$ionicView.enter', function () {
console.log("**VIEW ** Log Ctrl Entered");
ZMDataModel.setAwake(false);
$scope.zmLog = {
logString: ""
};
$fileLogger.getLogfile().then(function (l) {
$scope.zmLog.logString = l;
//console.log ("LOGS" + logstring);
},
function (error) {
$scope.zmLog.logString = "Error getting log: " + JSON.stringify(error);
});
});
}]);
|