otsdaq_utilities  v2_05_02_indev
SecuritySettings.js
1 var selectedSecurityChoice_ = "";
2 var IDs_ = ['NoSecurity', 'DigestAccessAuthentication'];//, 'ResetSecurityUserData'];//'Kerberos','ResetSecurityUserData'];
3 var selection_ = [];
4 INTERVAL_ = 1;
5 state_ = document.getElementById("state");
7 nonSelectedRed = 2;
8 nonSelectedGreen = 2;
9 nonSelectedBlue = 2;
11 var nonSelectedTargetRed;
12 var nonSelectedTargetGreen;
13 var nonSelectedtargetBlue;
15 selectedRed = 2;
16 selectedGreen = 2;
17 selectedBlue = 2;
19 var selectedTargetRed;
20 var selectedTargetGreen;
21 var selectedtargetBlue;
23 
24 
25 
26 //=====================================================================================
27 function init()
28 {
29  var windowTooltip = "This is an introduction into the Wiz-Mode Security!" +
30  "\n\n" +
31  "There are currently two options for otsdaq Security:" +
32  "\n\t- <b>No Security:</b>\n<INDENT>" +
33  "Just as it sounds, there will be no login required, and all requests " +
34  "will be treated as though they come from fully priveleged administrators. " +
35  "The only security is afforded by keeping your URL unknown (like on a private network)." +
36  "\n\n" +
37  "This mode is usually convenient during development when no hardware is at stake." +
38  "</INDENT>" +
39  "\n\t- <b>Digest Access Authentication:</b>\n<INDENT>" +
40  "This is a straightforward username and password approach to security. " +
41  "Included in this selection, when using a HTTPS gateway, is CILOGON certificate access if users associate and email " +
42  "address with their accounts." +
43  "Users can be assigned different levels of access individually." +
44  "\n\n" +
45  "This mode, behind the ots HTTPS nodejs gateway, is the recommended <i>otsdaq</i> security approach." +
46  "</INDENT>";
47  console.log("init()");
48  DesktopContent.tooltip("Security in the Wiz-Mode",
49  windowTooltip
50  );
51  DesktopContent.setWindowTooltip(windowTooltip);
52 
53  for(var index = 0; index < IDs_.length; index++)
54  selection_[index] = IDs_[index];
55  //Added all of the IDs into the selection_ array and position the selection at the end
56 
57  colorFade('orange', "all");
58  state_= document.getElementById("state");
59  state_.innerHTML = "Loading...";
60 
61  var setSelection=setTimeout(makeServerRequest, 1000);
62 } //end init()
63 
64 
65 //=====================================================================================
66 function colorFade(secondColor, which)
67 {
68 
69 
70  //Added all of the IDs into the selection_ array and position the selection at the end
71 
72  if(which == "selected" || which == "all")
73  {
74 
75  if(secondColor == 'orange')
76  {
77  selectedTargetRed = 255;
78  selectedTargetGreen = 188;
79  selectedTargetBlue = 18;
80  }
81  else if(secondColor == 'red')
82  {
83  selectedTargetRed = 242;
84  selectedTargetGreen = 5;
85  selectedTargetBlue = 5;
86  }
87  else if(secondColor == 'green')
88  {
89  selectedTargetRed = 56;
90  selectedTargetGreen = 224;
91  selectedTargetBlue = 56;
92  }
93  else if(secondColor == 'current')
94  {
95 
96  }
97 
98  }
99 
100 
101  if(which == "notSelected" || which == "all")
102  {
103 
104  if(secondColor == 'orange')
105  {
106  nonSelectedTargetRed = 255;
107  nonSelectedTargetGreen = 188;
108  nonSelectedTargetBlue = 18;
109  }
110  else if(secondColor == 'red')
111  {
112  nonSelectedTargetRed = 242;
113  nonSelectedTargetGreen = 5;
114  nonSelectedTargetBlue = 5;
115  }
116  else if(secondColor == 'green')
117  {
118  nonSelectedTargetRed = 56;
119  nonSelectedTargetGreen = 224;
120  nonSelectedTargetBlue = 56;
121  }
122  else if(secondColor == 'current')
123  {
124 
125  }
126  }
127 
128  //console.log(selectedRed, selectedGreen, selectedBlue, nonSelectedRed, nonSelectedGreen, nonSelectedBlue);
129 
130  var colorChanger=setTimeout(decreaseColor, INTERVAL_);
131 
132 
133 } //end colorFade()
134 
135 
136 //=====================================================================================
137 function decreaseColor()
138 {
139  if(selectedRed > 0)
140  --selectedRed;
141  if(selectedGreen > 0)
142  --selectedGreen;
143  if(selectedBlue > 0)
144  --selectedBlue;
145  if(nonSelectedRed > 0)
146  --nonSelectedRed;
147  if(nonSelectedGreen > 0)
148  --nonSelectedGreen;
149  if(nonSelectedBlue > 0)
150  --nonSelectedBlue;
151  //console.log("Called");
152  setDivGlow();
153 
154  if((selectedRed + selectedGreen + selectedBlue +
155  nonSelectedRed + nonSelectedGreen + nonSelectedBlue) > 0)
156  colorChanger = setTimeout(decreaseColor, INTERVAL_);
157  else
158  {
159  restructure();
160  colorChanger = setTimeout(increaseColor, INTERVAL_);
161 
162  }
163 } //end decreaseColor()
164 
165 
166 //=====================================================================================
167 function increaseColor()
168 {
169  if(selectedRed < selectedTargetRed)
170  ++selectedRed;
171  if(selectedGreen < selectedTargetGreen)
172  ++selectedGreen;
173  if(selectedBlue < selectedTargetBlue)
174  ++selectedBlue;
175  if(nonSelectedRed < nonSelectedTargetRed)
176  ++nonSelectedRed;
177  if(nonSelectedGreen < nonSelectedTargetGreen)
178  ++nonSelectedGreen;
179  if(nonSelectedBlue < nonSelectedTargetBlue)
180  ++nonSelectedBlue;
181  setDivGlow();
182 
183  if((selectedRed + selectedGreen + selectedBlue +
184  nonSelectedRed + nonSelectedGreen + nonSelectedBlue) <
185  (selectedTargetRed + selectedTargetGreen + selectedTargetBlue +
186  nonSelectedTargetRed + nonSelectedTargetGreen + nonSelectedTargetBlue))
187  colorChanger = setTimeout(increaseColor, INTERVAL_);
188 
189 } //end increaseColor()
190 
191 
192 //=====================================================================================
193 function setDivGlow()
194 {
195  for(var index = 0; index < (selection_.length); index++)
196  {
197  var div = document.getElementById(selection_[index]);
198  if(index < (selection_.length-1))
199  {
200  div.style.boxShadow = "0px 0px 64px 20px rgba(" + nonSelectedRed +
201  "," + nonSelectedGreen + "," + nonSelectedBlue + ",1)";
202  div.style.webkitBoxShadow = "0px 0px 64px 20px rgba(" + nonSelectedRed +
203  "," + nonSelectedGreen + "," + nonSelectedBlue + ",1)";
204  div.style.mozBoxShadow = "0px 0px 64px 20px rgba(" + nonSelectedRed +
205  "," + nonSelectedGreen + "," + nonSelectedBlue + ",1)";
206  }
207  else
208  {
209  div.style.boxShadow = "0px 0px 64px 20px rgba(" + selectedRed +
210  "," + selectedGreen + "," + selectedBlue + ",1)";
211  div.style.webkitBoxShadow = "0px 0px 64px 20px rgba(" + selectedRed +
212  "," + selectedGreen + "," + selectedBlue + ",1)";
213  div.style.mozBoxShadow = "0px 0px 64px 20px rgba(" + selectedRed +
214  "," + selectedGreen + "," + selectedBlue + ",1)";
215  }
216  }
217 
218 } //end setDivGlow()
219 
220 
221 //=====================================================================================
222 function showVisualSelection()
223 {
224 
225 
226  state_.innerHTML = "&nbsp";
227 
228  //set selected to green
229  colorFade('green', 'selected');
230  //set selected to green
231  colorFade('red', 'notSelected');
232 
233 } //end showVisualSelection()
234 
235 
236 //=====================================================================================
237 function confirm(description)
238 {
239  var randomNumber = Math.floor(Math.random() * 99999999);
240  if(prompt("Are you sure? "+ description + " Type " +
241  randomNumber + " to continue:") == randomNumber)
242  {
243  if(prompt("I know exactly what I'm doing. Type 'I Do':") == "I Do")
244  {
245  setSecurity('ResetSecurityUserData');
246  }
247  else
248  alert("You did not type 'I Do.' Mission aborted!");
249  }
250  else
251  alert("You did not type the correct number. Mission aborted!");
252 } //end confirm()
253 
254 //=====================================================================================
255 function setSecurity(id)
256 {
257 
258  if(id == 'NoSecurity')
259  {
260  console.log("No Security selected.")
261  selectedSecurityChoice_ = 'NoSecurity';
262  }
263  else if(id == 'DigestAccessAuthentication')
264  {
265  console.log("Digest Access Authentication selcted.")
266  selectedSecurityChoice_= 'DigestAccessAuthentication';
267  }
268  else if(id == 'Kerberos')
269  {
270  console.log("Kerberos selected.")
271  selectedSecurityChoice_= 'Kerberos';
272  }
273  else if(id == 'ResetSecurityUserData')
274  {
275  console.log("Reset Data selected.")
276  selectedSecurityChoice_= 'ResetSecurityUserData';
277  }
278  else{
279  console.log("Selection not recognized!");
280  return;
281  }
282 
283 
284  var serverRequest = "selection=" + selectedSecurityChoice_;
285  console.log(serverRequest);
286  makeServerRequest(serverRequest);
287 } //end setSecurity()
288 
289 
290 //=====================================================================================
291 function makeServerRequest(data)
292 {
293  DesktopContent.XMLHttpRequest("editSecurity", data, editSecurityHandler,
294  undefined /*reqParam*/,
295  undefined /*progressHandler*/,
296  true /*callHandlerOnErr*/);
297 
298 } //end makeServerRequest()
299 
300 
301 //=====================================================================================
302 function restructure()
303 {
304 
305  for(var index = 0; index < IDs_.length; index++)
306  {
307  if(selectedSecurityChoice_ != "")
308  {
309  if(selectedSecurityChoice_ != IDs_[index])
310  selection_[index] = IDs_[index];
311  }
312  }
313  if(selectedSecurityChoice_ != "")
314  selection_[selection_.length] = selectedSecurityChoice_;
315 
316 } //end restructure()
317 
318 
319 //=====================================================================================
320 //Note: not an xml response, just text
321 function editSecurityHandler(req)
322 {
323 
324  if(!req || !req.responseText.length ||
325  req.responseText.indexOf("Error") >= 0)
326  {
327  Debug.log("Action Failed. Invalid Verify Code!", Debug.HIGH_PRIORITY);
328  selectedSecurityChoice_ = "NoSecurity"; //default to NoSecurity
329  showVisualSelection();
330  return;
331  }
332 
333  console.log("req.responseText",req.responseText);
334 
335  if(selectedSecurityChoice_ == "DigestAccessAuthentication")
336  Debug.log("Digest Access Authentication was enabled successfully!" +
337  "\n\n NOTE: If this is the first time you are enabling users and passwords, " +
338  "then you must get the New Account Code for the admin account from " +
339  "the printouts in normal mode. In verbose mode ('ots -v'), the admin New Account Code will be in the linux console; " +
340  "otherwise ('ots'), the admin New Account Code can be retrieved in the Gateway log file. " +
341  "\n\nAfter the admin account has been setup, new accounts can be made and " +
342  "the admin account will have access to the New Account Codes in the settings " +
343  "web GUI.",
344  Debug.INFO_PRIORITY);
345  else if(selectedSecurityChoice_ == "NoSecurity")
346  Debug.log("Security was disabled successfully! " +
347  "\n\nNow anyone with the ots normal mode URL will have admin privileges.",
348  Debug.INFO_PRIORITY);
349 
350  selectedSecurityChoice_ = req.responseText;
351  console.log(selectedSecurityChoice_);
352  showVisualSelection();
353 
354 } //end editSecurityHandler()
355 
356 
357