|
64 | 64 | } |
65 | 65 | }); |
66 | 66 |
|
67 | | - $(function() { |
| 67 | + $(window).bind('cloudStack.pluginReady', function() { |
68 | 68 | // Get language |
69 | 69 | g_lang = $.cookie('lang') ? $.cookie('lang') : 'en'; |
70 | 70 |
|
71 | 71 | /** |
72 | 72 | * Generic error handling |
73 | 73 | */ |
74 | | - |
| 74 | + |
75 | 75 | $.ajaxSetup({ |
76 | | - url: clientApiUrl, |
| 76 | + url: clientApiUrl, |
77 | 77 | async: true, |
78 | 78 | dataType: 'json', |
79 | 79 | cache: false, |
80 | 80 | error: function(data) { |
81 | | - var clickAction = false; |
82 | | - if (isValidJsonString(data.responseText)) { |
83 | | - var json = JSON.parse(data.responseText); |
84 | | - if (json != null) { |
85 | | - var property; |
86 | | - for(property in json) {} |
87 | | - var errorObj = json[property]; |
88 | | - if(errorObj.errorcode == 401 && errorObj.errortext == "unable to verify user credentials and/or request signature") { |
89 | | - clickAction = function() { |
90 | | - $('#user-options a').eq(0).trigger('click'); |
91 | | - }; |
92 | | - } |
93 | | - } |
94 | | - } |
95 | | - cloudStack.dialog.notice({ message: parseXMLHttpResponse(data), clickAction: clickAction }); |
| 81 | + var clickAction = false; |
| 82 | + if (isValidJsonString(data.responseText)) { |
| 83 | + var json = JSON.parse(data.responseText); |
| 84 | + if (json != null) { |
| 85 | + var property; |
| 86 | + for(property in json) {} |
| 87 | + var errorObj = json[property]; |
| 88 | + if(errorObj.errorcode == 401 && errorObj.errortext == "unable to verify user credentials and/or request signature") { |
| 89 | + clickAction = function() { |
| 90 | + $('#user-options a').eq(0).trigger('click'); |
| 91 | + }; |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + cloudStack.dialog.notice({ message: parseXMLHttpResponse(data), clickAction: clickAction }); |
96 | 96 | }, |
97 | | - beforeSend: function(XMLHttpRequest) { |
98 | | - if (g_mySession == $.cookie("JSESSIONID")) { |
99 | | - return true; |
100 | | - } |
101 | | - else { |
102 | | - var clickAction = function() { |
103 | | - $('#user-options a').eq(0).trigger('click'); |
104 | | - }; |
105 | | - cloudStack.dialog.notice({ message: _l('label.session.expired'), clickAction: clickAction }); |
106 | | - return false; |
107 | | - } |
108 | | - } |
| 97 | + beforeSend: function(XMLHttpRequest) { |
| 98 | + if (g_mySession == $.cookie("JSESSIONID")) { |
| 99 | + return true; |
| 100 | + } |
| 101 | + else { |
| 102 | + var clickAction = function() { |
| 103 | + $('#user-options a').eq(0).trigger('click'); |
| 104 | + }; |
| 105 | + cloudStack.dialog.notice({ message: _l('label.session.expired'), clickAction: clickAction }); |
| 106 | + return false; |
| 107 | + } |
| 108 | + } |
109 | 109 | }); |
110 | 110 |
|
111 | 111 | var $container = $('#cloudStack3-container'); |
|
115 | 115 |
|
116 | 116 | // Use this for checking the session, to bypass login screen |
117 | 117 | bypassLoginCheck: function(args) { //determine to show or bypass login screen |
118 | | - if (g_loginResponse == null) { //show login screen |
119 | | - /* |
120 | | - but if this is a 2nd browser window (of the same domain), login screen still won't show because $.cookie('sessionKey') is valid for 2nd browser window (of the same domain) as well. |
121 | | - i.e. calling listCapabilities API with g_sessionKey from $.cookie('sessionKey') will succeed, |
122 | | - then userValid will be set to true, then an user object (instead of "false") will be returned, then login screen will be bypassed. |
123 | | - */ |
124 | | - g_mySession = $.cookie('JSESSIONID'); |
125 | | - g_sessionKey = $.cookie('sessionKey'); |
126 | | - g_role = $.cookie('role'); |
127 | | - g_username = $.cookie('username'); |
128 | | - g_userid = $.cookie('userid'); |
129 | | - g_account = $.cookie('account'); |
130 | | - g_domainid = $.cookie('domainid'); |
131 | | - g_userfullname = $.cookie('userfullname'); |
132 | | - g_timezone = $.cookie('timezone'); |
133 | | - if($.cookie('timezoneoffset') != null) |
134 | | - g_timezoneoffset = isNaN($.cookie('timezoneoffset'))? null: parseFloat($.cookie('timezoneoffset')); |
135 | | - else |
136 | | - g_timezoneoffset = null; |
| 118 | + if (g_loginResponse == null) { //show login screen |
| 119 | + /* |
| 120 | + but if this is a 2nd browser window (of the same domain), login screen still won't show because $.cookie('sessionKey') is valid for 2nd browser window (of the same domain) as well. |
| 121 | + i.e. calling listCapabilities API with g_sessionKey from $.cookie('sessionKey') will succeed, |
| 122 | + then userValid will be set to true, then an user object (instead of "false") will be returned, then login screen will be bypassed. |
| 123 | + */ |
| 124 | + g_mySession = $.cookie('JSESSIONID'); |
| 125 | + g_sessionKey = $.cookie('sessionKey'); |
| 126 | + g_role = $.cookie('role'); |
| 127 | + g_username = $.cookie('username'); |
| 128 | + g_userid = $.cookie('userid'); |
| 129 | + g_account = $.cookie('account'); |
| 130 | + g_domainid = $.cookie('domainid'); |
| 131 | + g_userfullname = $.cookie('userfullname'); |
| 132 | + g_timezone = $.cookie('timezone'); |
| 133 | + if($.cookie('timezoneoffset') != null) |
| 134 | + g_timezoneoffset = isNaN($.cookie('timezoneoffset'))? null: parseFloat($.cookie('timezoneoffset')); |
| 135 | + else |
| 136 | + g_timezoneoffset = null; |
137 | 137 | } |
138 | | - else { //single-sign-on (bypass login screen) |
139 | | - g_mySession = $.cookie('JSESSIONID'); |
140 | | - g_sessionKey = encodeURIComponent(g_loginResponse.sessionkey); |
141 | | - g_role = g_loginResponse.type; |
142 | | - g_username = g_loginResponse.username; |
143 | | - g_userid = g_loginResponse.userid; |
144 | | - g_account = g_loginResponse.account; |
145 | | - g_domainid = g_loginResponse.domainid; |
146 | | - g_userfullname = g_loginResponse.firstname + ' ' + g_loginResponse.lastname; |
147 | | - g_timezone = g_loginResponse.timezone; |
148 | | - if(g_loginResponse.timezoneoffset != null) |
149 | | - g_timezoneoffset = isNaN(g_loginResponse.timezoneoffset)? null: parseFloat(g_loginResponse.timezoneoffset); |
150 | | - else |
151 | | - g_timezoneoffset = null; |
152 | | - } |
153 | | - |
| 138 | + else { //single-sign-on (bypass login screen) |
| 139 | + g_mySession = $.cookie('JSESSIONID'); |
| 140 | + g_sessionKey = encodeURIComponent(g_loginResponse.sessionkey); |
| 141 | + g_role = g_loginResponse.type; |
| 142 | + g_username = g_loginResponse.username; |
| 143 | + g_userid = g_loginResponse.userid; |
| 144 | + g_account = g_loginResponse.account; |
| 145 | + g_domainid = g_loginResponse.domainid; |
| 146 | + g_userfullname = g_loginResponse.firstname + ' ' + g_loginResponse.lastname; |
| 147 | + g_timezone = g_loginResponse.timezone; |
| 148 | + if(g_loginResponse.timezoneoffset != null) |
| 149 | + g_timezoneoffset = isNaN(g_loginResponse.timezoneoffset)? null: parseFloat(g_loginResponse.timezoneoffset); |
| 150 | + else |
| 151 | + g_timezoneoffset = null; |
| 152 | + } |
| 153 | + |
154 | 154 | var userValid = false; |
155 | 155 | $.ajax({ |
156 | 156 | url: createURL("listCapabilities"), |
157 | 157 | dataType: "json", |
158 | 158 | async: false, |
159 | 159 | success: function(json) { |
160 | 160 | g_capabilities = json.listcapabilitiesresponse.capability; |
161 | | - $.cookie('capabilities', g_capabilities, { expires: 1}); |
162 | | - |
| 161 | + $.cookie('capabilities', g_capabilities, { expires: 1}); |
| 162 | + |
163 | 163 | g_supportELB = json.listcapabilitiesresponse.capability.supportELB.toString(); //convert boolean to string if it's boolean |
164 | 164 | $.cookie('supportELB', g_supportELB, { expires: 1}); |
165 | | - |
| 165 | + |
166 | 166 | if (json.listcapabilitiesresponse.capability.userpublictemplateenabled != null) { |
167 | 167 | g_userPublicTemplateEnabled = json.listcapabilitiesresponse.capability.userpublictemplateenabled.toString(); //convert boolean to string if it's boolean |
168 | 168 | $.cookie('userpublictemplateenabled', g_userPublicTemplateEnabled, { expires: 1}); |
169 | | - } |
170 | | - |
171 | | - g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects; |
| 169 | + } |
| 170 | + |
| 171 | + g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects; |
172 | 172 | $.cookie('userProjectsEnabled', g_userProjectsEnabled, { expires: 1 }); |
173 | | - |
| 173 | + |
174 | 174 | g_cloudstackversion = json.listcapabilitiesresponse.capability.cloudstackversion; |
175 | | - |
176 | | - if(json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) { |
177 | | - var intervalLimit = ((json.listcapabilitiesresponse.capability.apilimitinterval * 1000) / json.listcapabilitiesresponse.capability.apilimitmax ) * 3; //multiply 3 to be on safe side |
178 | | - //intervalLimit = 9999; //this line is for testing only, comment it before check in |
179 | | - if(intervalLimit > g_queryAsyncJobResultInterval) |
180 | | - g_queryAsyncJobResultInterval = intervalLimit; |
181 | | - } |
182 | | - |
| 175 | + |
| 176 | + if(json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) { |
| 177 | + var intervalLimit = ((json.listcapabilitiesresponse.capability.apilimitinterval * 1000) / json.listcapabilitiesresponse.capability.apilimitmax ) * 3; //multiply 3 to be on safe side |
| 178 | + //intervalLimit = 9999; //this line is for testing only, comment it before check in |
| 179 | + if(intervalLimit > g_queryAsyncJobResultInterval) |
| 180 | + g_queryAsyncJobResultInterval = intervalLimit; |
| 181 | + } |
| 182 | + |
183 | 183 | userValid = true; |
184 | 184 | }, |
185 | | - error: function(xmlHTTP) { //override default error handling, do nothing instead of showing error "unable to verify user credentials" on login screen |
| 185 | + error: function(xmlHTTP) { //override default error handling, do nothing instead of showing error "unable to verify user credentials" on login screen |
186 | 186 | }, |
187 | | - beforeSend : function(XMLHttpResponse) { |
188 | | - return true; |
189 | | - } |
| 187 | + beforeSend : function(XMLHttpResponse) { |
| 188 | + return true; |
| 189 | + } |
190 | 190 | }); |
191 | 191 |
|
192 | 192 | if (userValid && isAdmin()) { |
|
228 | 228 | username: g_username, |
229 | 229 | account: g_account, |
230 | 230 | name: g_userfullname, |
231 | | - role: g_role, |
| 231 | + role: g_role, |
232 | 232 | domainid: g_domainid |
233 | 233 | } |
234 | 234 | } : false; |
|
259 | 259 | else { |
260 | 260 | array1.push("&domain=" + encodeURIComponent("/")); |
261 | 261 | } |
262 | | - |
263 | | - var loginCmdText = array1.join(""); |
264 | | - |
| 262 | + |
| 263 | + var loginCmdText = array1.join(""); |
| 264 | + |
265 | 265 | $.ajax({ |
266 | 266 | type: "POST", |
267 | | - data: "command=login" + loginCmdText + "&response=json", |
| 267 | + data: "command=login" + loginCmdText + "&response=json", |
268 | 268 | dataType: "json", |
269 | 269 | async: false, |
270 | | - success: function(json) { |
| 270 | + success: function(json) { |
271 | 271 | var loginresponse = json.loginresponse; |
272 | 272 |
|
273 | 273 | g_mySession = $.cookie('JSESSIONID'); |
274 | 274 | g_sessionKey = encodeURIComponent(loginresponse.sessionkey); |
275 | | - g_role = loginresponse.type; |
| 275 | + g_role = loginresponse.type; |
276 | 276 | g_username = loginresponse.username; |
277 | 277 | g_userid = loginresponse.userid; |
278 | 278 | g_account = loginresponse.account; |
|
285 | 285 | $.cookie('username', g_username, { expires: 1}); |
286 | 286 | $.cookie('account', g_account, { expires: 1}); |
287 | 287 | $.cookie('domainid', g_domainid, { expires: 1}); |
288 | | - $.cookie('role', g_role, { expires: 1}); |
| 288 | + $.cookie('role', g_role, { expires: 1}); |
289 | 289 | $.cookie('timezoneoffset', g_timezoneoffset, { expires: 1}); |
290 | 290 | $.cookie('timezone', g_timezone, { expires: 1}); |
291 | 291 | $.cookie('userfullname', g_userfullname, { expires: 1 }); |
292 | 292 | $.cookie('userid', g_userid, { expires: 1 }); |
293 | 293 |
|
294 | 294 | $.ajax({ |
295 | | - url: createURL("listCapabilities"), |
| 295 | + url: createURL("listCapabilities"), |
296 | 296 | dataType: "json", |
297 | 297 | async: false, |
298 | 298 | success: function(json) { |
299 | 299 | g_capabilities = json.listcapabilitiesresponse.capability; |
300 | | - $.cookie('capabilities', g_capabilities, { expires: 1}); |
301 | | - |
| 300 | + $.cookie('capabilities', g_capabilities, { expires: 1}); |
| 301 | + |
302 | 302 | g_supportELB = json.listcapabilitiesresponse.capability.supportELB.toString(); //convert boolean to string if it's boolean |
303 | 303 | $.cookie('supportELB', g_supportELB, { expires: 1}); |
304 | 304 |
|
|
309 | 309 |
|
310 | 310 | g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects; |
311 | 311 | $.cookie('userProjectsEnabled', g_userProjectsEnabled, { expires: 1 }); |
312 | | - |
| 312 | + |
313 | 313 | g_cloudstackversion = json.listcapabilitiesresponse.capability.cloudstackversion; |
314 | | - |
315 | | - if(json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) { |
316 | | - var intervalLimit = ((json.listcapabilitiesresponse.capability.apilimitinterval * 1000) / json.listcapabilitiesresponse.capability.apilimitmax ) * 3; //multiply 3 to be on safe side |
317 | | - //intervalLimit = 8888; //this line is for testing only, comment it before check in |
318 | | - if(intervalLimit > g_queryAsyncJobResultInterval) |
319 | | - g_queryAsyncJobResultInterval = intervalLimit; |
320 | | - } |
321 | | - |
| 314 | + |
| 315 | + if(json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) { |
| 316 | + var intervalLimit = ((json.listcapabilitiesresponse.capability.apilimitinterval * 1000) / json.listcapabilitiesresponse.capability.apilimitmax ) * 3; //multiply 3 to be on safe side |
| 317 | + //intervalLimit = 8888; //this line is for testing only, comment it before check in |
| 318 | + if(intervalLimit > g_queryAsyncJobResultInterval) |
| 319 | + g_queryAsyncJobResultInterval = intervalLimit; |
| 320 | + } |
| 321 | + |
322 | 322 | args.response.success({ |
323 | 323 | data: { |
324 | 324 | user: $.extend(true, {}, loginresponse, { |
|
331 | 331 | }, |
332 | 332 | error: function(xmlHTTP) { |
333 | 333 | args.response.error(); |
334 | | - } |
| 334 | + } |
335 | 335 | }); |
336 | 336 |
|
337 | 337 | if (isAdmin()) { |
|
371 | 371 | // TEMPORARY -- replace w/ output of capability response, etc., once implemented |
372 | 372 | window.g_projectsInviteRequired = false; |
373 | 373 | }, |
374 | | - error: function(XMLHttpRequest) { |
375 | | - var errorMsg = parseXMLHttpResponse(XMLHttpRequest); |
376 | | - if(errorMsg.length == 0 && XMLHttpRequest.status == 0) |
377 | | - errorMsg = dictionary['error.unable.to.reach.management.server']; |
378 | | - else |
379 | | - errorMsg = _l('error.invalid.username.password'); //override error message |
380 | | - args.response.error(errorMsg); |
381 | | - }, |
382 | | - beforeSend : function(XMLHttpResponse) { |
383 | | - return true; |
384 | | - } |
| 374 | + error: function(XMLHttpRequest) { |
| 375 | + var errorMsg = parseXMLHttpResponse(XMLHttpRequest); |
| 376 | + if(errorMsg.length == 0 && XMLHttpRequest.status == 0) |
| 377 | + errorMsg = dictionary['error.unable.to.reach.management.server']; |
| 378 | + else |
| 379 | + errorMsg = _l('error.invalid.username.password'); //override error message |
| 380 | + args.response.error(errorMsg); |
| 381 | + }, |
| 382 | + beforeSend : function(XMLHttpResponse) { |
| 383 | + return true; |
| 384 | + } |
385 | 385 | }); |
386 | 386 | }, |
387 | 387 |
|
|
413 | 413 |
|
414 | 414 | if(onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen. |
415 | 415 | document.location.reload(); //when onLogoutCallback() returns true, reload the current document. |
416 | | - } |
| 416 | + } |
417 | 417 | }, |
418 | 418 | error: function() { |
419 | | - if(onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen. |
| 419 | + if(onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen. |
420 | 420 | document.location.reload(); //when onLogoutCallback() returns true, reload the current document. |
421 | | - } |
422 | | - }, |
423 | | - beforeSend : function(XMLHttpResponse) { |
424 | | - return true; |
425 | | - } |
| 421 | + } |
| 422 | + }, |
| 423 | + beforeSend : function(XMLHttpResponse) { |
| 424 | + return true; |
| 425 | + } |
426 | 426 | }); |
427 | 427 | }, |
428 | 428 |
|
|
479 | 479 | // SSO |
480 | 480 | loginArgs.hideLoginScreen = true; |
481 | 481 | } |
482 | | - |
| 482 | + |
483 | 483 | cloudStack.uiCustom.login(loginArgs); |
484 | 484 |
|
485 | 485 | // Localization |
|
0 commit comments