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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
/* jshint -W041 */
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console, Masonry, URI */
angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel','$ionicSideMenuDelegate', '$ionicHistory', '$state', '$ionicPopup', 'SecuredPopups', '$http','$q','zm',function ($scope, $rootScope, $ionicModal, ZMDataModel,$ionicSideMenuDelegate, $ionicHistory, $state, $ionicPopup, SecuredPopups, $http, $q,zm) {
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
function login (u,zmu,zmp)
{
var d = $q.defer();
$http({
method: 'POST',
//withCredentials: true,
url: u,
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: zmu,
password: zmp,
action: "login",
view: "console"
}
})
.success (function (data, status,headers){
console.log ("LOOKING FOR " + zm.loginScreenString);
//console.log ("DATA RECEIVED " + JSON.stringify(data));
if (data.indexOf(zm.loginScreenString) == -1)
{
d.resolve(true);
return d.promise;
}
else
{
console.log ("************ERROR");
d.reject(false);
return d.promise;
}
});
return d.promise;
}
function logout(u)
{
var d = $q.defer();
$http({
method: 'POST',
url: u,
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: {
action: "logout",
view: "login"
}
})
.finally (function (ans) {
return d.resolve(true);
});
return d.promise;
}
$scope.exitValidate = function()
{
$rootScope.authSession = 'undefined';
$rootScope.zmCookie = '';
$scope.portalValidText = "";
$scope.apiValidateText = "";
$scope.streamingValidateText = "";
$scope.wizard.fqportal = "";
var d = $q.defer();
var c = URI.parse ($scope.wizard.portalurl);
var b ="";
if ($scope.wizard.useauth && $scope.wizard.usebasicauth)
{
b = $scope.wizard.basicuser+":"+$scope.wizard.basicpassword+"@";
console.log ("B="+b);
}
var u = c.scheme+"://"+b+c.host;
if (c.port) u+= ":"+c.port;
if (c.path) u+= c.path;
if (u.slice(-1) == '/') {
u = u.slice(0, -1);
}
$scope.fqportal = u;
u = u+'/index.php';
ZMDataModel.zmLog ("Wizard: login url is " + u);
// now lets login
var zmu = "x";
var zmp = "x";
if ($scope.wizard.usezmauth)
{
zmu = $scope.wizard.zmuser;
zmp = $scope.wizard.zmpassword;
}
// logout first for the adventurers amongst us who must
// use it even after logging in
ZMDataModel.zmLog ("zmWizard: logging out");
logout(u)
.then ( function (ans)
{
// login now
ZMDataModel.zmLog ("zmWizard: logging in with "+u+" "+zmu+":"+zmp);
login(u,zmu,zmp)
.then ( function (success){
ZMDataModel.zmLog ("zmWizard: login succeeded");
$scope.wizard.portalValidText = "Portal login was successful";
$scope.wizard.portalColor = "#16a085";
return d.resolve(true);
},
function (error) {
ZMDataModel.zmLog ("zmWizard: login failed");
$scope.wizard.portalValidText = "Portal login was unsuccessful";
$scope.wizard.portalColor = "#e74c3c";
return d.resolve(false);
});
});//finally
return d.promise;
};
//--------------------------------------------------------------------------
// tags a protocol
//--------------------------------------------------------------------------
function checkscheme(url) {
if ((!/^(f|ht)tps?:\/\//i.test(url)) && (url != "")) {
return false;
}
else
return true;
}
//--------------------------------------------------------------------------
// exit validator for auth wizard
//--------------------------------------------------------------------------
$scope.exitAuth = function()
{
ZMDataModel.zmLog ("Wizard: validating auth syntax");
if ($scope.wizard.useauth)
{
if (!$scope.wizard.usezmauth && !$scope.wizard.usebasicauth)
{
$rootScope.zmPopup = SecuredPopups.show('show',{
title: 'Whoops!',
template: 'You need to enable at least one authentication mechanism',
buttons: [{text: 'Ok'}]
});
return false;
}
if ($scope.wizard.usezmauth)
{
if ((!$scope.wizard.zmuser) || (!$scope.wizard.zmpassword))
{
$rootScope.zmPopup = SecuredPopups.show('show',{
title: 'Whoops!',
template: 'Please enter a valid username and password for ZM auth',
buttons: [{text: 'Ok'}]
});
return false;
}
}
if ($scope.wizard.usebasicauth)
{
if ((!$scope.wizard.basicuser) || (!$scope.wizard.basicpassword))
{
$rootScope.zmPopup = SecuredPopups.show('show',{
title: 'Whoops!',
template: 'Please enter a valid username and password for basic auth',
buttons: [{text: 'Ok'}]
});
return false;
}
}
}
return true;
};
//--------------------------------------------------------------------------
// validator for portal url wizard
//--------------------------------------------------------------------------
$scope.exitPortal = function()
{
ZMDataModel.zmLog ("Wizard: validating portal url syntax");
if (!$scope.wizard.portalurl)
{
$rootScope.zmPopup = SecuredPopups.show('show',{
title: 'Whoops!',
template: 'Portal url cannot be empty',
buttons: [{text: 'Ok'}]
});
return false;
}
if ( !checkscheme($scope.wizard.portalurl))
{
$rootScope.zmPopup = SecuredPopups.show('show',{
title: 'Whoops!',
template: 'Please specify http:// or https:// in the url',
buttons: [{text: 'Ok'}]
});
return false;
}
$scope.wizard.portalurl = $scope.wizard.portalurl.toLowerCase().trim();
ZMDataModel.zmLog ("Wizard: stripped url:"+$scope.wizard.portalurl);
var c = URI.parse ($scope.wizard.portalurl);
if (!c.scheme)
{
$rootScope.zmPopup = SecuredPopups.show('show',{
title: 'Whoops!',
template: 'URL seems invalid (no protocol detected)',
buttons: [{text: 'Ok'}]
});
return false;
}
if (c.userinfo) // basic auth stuff in here, take it out and put it into the next screen
{
$scope.wizard.useauth = true;
$scope.wizard.usebasicauth = true;
var barray = c.userinfo.split(":",2);
$scope.wizard.basicuser = barray[0];
$scope.wizard.basicpassword = barray[1];
}
$scope.wizard.portalurl = c.scheme+"://";
if (c.host) $scope.wizard.portalurl += c.host;
if (c.port) $scope.wizard.portalurl += ":"+c.port;
if (c.path) $scope.wizard.portalurl += c.path;
ZMDataModel.zmLog ("Wizard: normalized url:"+$scope.wizard.portalurl);
return true;
};
//--------------------------------------------------------------------------
// part of auth wizard - toggles display of auth components
//--------------------------------------------------------------------------
$scope.toggleAuth = function()
{
$scope.wizard.useauth = !$scope.wizard.useauth;
if (!$scope.wizard.useauth)
{
$scope.wizard.usebasicauth = false;
$scope.wizard.usezmauth = false;
}
};
//--------------------------------------------------------------------------
// global tip toggler for all wizard steps
//--------------------------------------------------------------------------
$scope.toggleTip = function()
{
$scope.wizard.tipshow = !$scope.wizard.tipshow;
if ($scope.wizard.tipshow)
$scope.wizard.tiptext = "hide tip";
else
$scope.wizard.tiptext = "show tip";
};
//--------------------------------------------------------------------------
// initial
//--------------------------------------------------------------------------
$scope.$on('$ionicView.beforeEnter', function () {
//console.log("**VIEW ** Help Ctrl Entered");
$scope.wizard = {
tipshow:false,
tiptext:"show tip",
useauth:false,
usebasicauth:false,
usezmauth:false,
portalurl: "",
basicuser : "",
basicpassword : "",
zmuser : "",
zmpassword : "",
///////////////////////
loginURL: "",
apiURL: "",
streamingURL: "",
fqportal:"",
portalValidText:"",
portalColor:"",
apiValidText:"",
apiColor:"",
streamingValidText:"",
streamingColor:"",
};
});
}]);
|