PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/dogtag-pki-theme-9.0.11/dogtag/tps-ui/shared/docroot/esc/GenericAuth.html

#
HTML | 536 lines | 364 code | 155 blank | 17 comment | 0 complexity | 53c718b952aa9cb7c3f4e6b6a1c59dac MD5 | raw file
Possible License(s): GPL-2.0
  1. <!-- --- BEGIN COPYRIGHT BLOCK ---
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  12. Copyright (C) 2009 Red Hat, Inc.
  13. All rights reserved.
  14. --- END COPYRIGHT BLOCK --- -->
  15. <html>
  16. <head>
  17. <style>
  18. body {
  19. background: #ffffff url(../images/bg.jpg) repeat-x;
  20. font-family: arial;
  21. font-size: 7pt;
  22. }
  23. h1
  24. {
  25. text-align: left;
  26. font-weight: bold;
  27. font-size: 13pt;
  28. }
  29. h2 {
  30. text-align: left;
  31. font-size: 10pt;
  32. font-weight: lighter;
  33. }
  34. </style>
  35. <script language = "Javascript">
  36. var test_ui = "id=USER_ID&name=User ID&desc=User ID&type=string&option=option1,option2,option3&&id=USER_PWD&name=User Password&desc=User Password&type=password&option=&&id=USER_PIN&name=PIN&desc=One time PIN received via mail&type=password&option=";
  37. var theForm = null;
  38. var curKeyID = null;
  39. var curKeyType = 0;
  40. var gTitle = null;
  41. var gDescription = null;
  42. function ConfirmPassword(password_element)
  43. {
  44. if(!password_element)
  45. return 0;
  46. password_id = password_element.id;
  47. if(!password_id)
  48. return 0;
  49. confirm_id = "RE_" + password_element.id;
  50. var size = theForm.length;
  51. if(theForm)
  52. {
  53. for(i = 0; i < size ; i++)
  54. {
  55. var cur_element = theForm.elements[i];
  56. if(cur_element.id == confirm_id)
  57. {
  58. if(cur_element.value != password_element.value)
  59. {
  60. alert("Value " + password_element.name + " must match " + cur_element.name);
  61. return 0;
  62. }
  63. else
  64. {
  65. return 1;
  66. }
  67. }
  68. }
  69. }
  70. return 1;
  71. }
  72. function Validate()
  73. {
  74. if(theForm)
  75. {
  76. var size = theForm.length;
  77. for( i = 0; i < size ; i++)
  78. {
  79. var element = theForm.elements[i];
  80. if(element.type == "text" )
  81. {
  82. if(element.value == "")
  83. {
  84. alert("Please enter value for " + element.name);
  85. return 0;
  86. }
  87. }
  88. if(element.type == "password")
  89. {
  90. if(element.value == "")
  91. {
  92. alert("Please enter value for " + element.name);
  93. return 0;
  94. }
  95. if(!ConfirmPassword(element))
  96. {
  97. return 0;
  98. }
  99. }
  100. }
  101. }
  102. return 1;
  103. }
  104. function FormSubmit()
  105. {
  106. var result = Validate();
  107. var thisParent = window.opener;
  108. if(!parent)
  109. {
  110. alert("No parent window.");
  111. window.close();
  112. return;
  113. }
  114. if(!result)
  115. {
  116. return;
  117. }
  118. if(theForm)
  119. {
  120. var size = theForm.length;
  121. for( i = 0; i < size ; i++)
  122. {
  123. var element = theForm.elements[i];
  124. var value = element.value;
  125. if(element.type == "text" )
  126. {
  127. var id = element.id;
  128. value = element.value;
  129. if(thisParent)
  130. {
  131. //alert("about to set data value key " + curKeyID + " id " + id + " value " + value);
  132. thisParent.COOLKeySetDataValue(curKeyType,curKeyID,id,value);
  133. }
  134. }
  135. if(element.type == "password")
  136. {
  137. var p_id = new String(element.id);
  138. if(p_id.indexOf("RE_") == -1)
  139. {
  140. if(thisParent)
  141. {
  142. thisParent.COOLKeySetDataValue(curKeyType,curKeyID,p_id,value);
  143. }
  144. }
  145. }
  146. }
  147. }
  148. window.close();
  149. }
  150. function GetUIObjectList(uiData)
  151. {
  152. var str = new String(uiData);
  153. var splits = str.split("&&");
  154. // alert("Get " + splits + " len " + splits.length);
  155. var params = new Array();
  156. var size = splits.length;
  157. for(i = 0 ; i < size ; i++)
  158. {
  159. params[i] = splits[i].split("&");
  160. }
  161. size = params.length;
  162. var name_value_objects = new Array();
  163. for(i = 0 ; i < size; i++)
  164. {
  165. var name_values = new Array();
  166. pISize = params[i].length;
  167. for(j = 0 ; j < pISize ; j ++)
  168. {
  169. var pair = params[i][j].split("=");
  170. //alert(" pair " + pair[0] + " pair1 " + pair[1]);
  171. if(pair[0] == "option")
  172. {
  173. var options = pair[1].split(",");
  174. }
  175. name_values[pair[0]] = pair[1];
  176. }
  177. name_value_objects[i] = name_values;
  178. }
  179. return name_value_objects;
  180. }
  181. function AddBRToNode(theNode)
  182. {
  183. if(!theNode)
  184. return;
  185. var br = document.createElement("br");
  186. theNode.appendChild(br);
  187. }
  188. function AddTextToNode(theNode,theText)
  189. {
  190. if(!theNode || !theText)
  191. return;
  192. var text = document.createTextNode(theText);
  193. theNode.appendChild(text);
  194. }
  195. function AddTextToDocument(theText)
  196. {
  197. if(!theText)
  198. return;
  199. var p = document.createElement("p");
  200. if(p)
  201. {
  202. p.appendChild(document.createTextNode(theText));
  203. }
  204. document.body.appendChild(p);
  205. }
  206. function CreateForm()
  207. {
  208. var form = document.createElement("form");
  209. document.body.appendChild(form);
  210. return form;
  211. }
  212. function CreateTable()
  213. {
  214. var table = document.createElement("table");
  215. document.body.appendChild(table);
  216. tbody = document.createElement("tbody");
  217. table.appendChild(tbody);
  218. return table;
  219. }
  220. function AddRowToTable(table)
  221. {
  222. if(!table)
  223. return null;
  224. var tr = document.createElement("tr");
  225. (table.tBodies[0]).appendChild(tr);
  226. return tr;
  227. }
  228. function AddColumnToRow(row)
  229. {
  230. if(!row)
  231. return null;
  232. var td = document.createElement("td");
  233. row.appendChild(td);
  234. return td;
  235. }
  236. function AddTextToColumn(column,text)
  237. {
  238. if(!column || !text)
  239. return;
  240. var text_node = document.createTextNode(text);
  241. column.appendChild(text_node);
  242. return text_node;
  243. }
  244. function AddInputField(type,id, name,value)
  245. {
  246. var field = document.createElement("input");
  247. if(!field)
  248. return null;
  249. field.type = type;
  250. field.id =id;
  251. field.name =name;
  252. field.value =value;
  253. return field;
  254. }
  255. function ConstructUI(aKeyType,aKeyID,uiData)
  256. {
  257. //alert("Construct UI data " + uiData);
  258. var name_value_objects = GetUIObjectList(uiData);
  259. var len = name_value_objects.length;
  260. gTitle = document.createElement("h1");
  261. gDescription = document.createElement("h2");
  262. document.body.appendChild(gTitle);
  263. document.body.appendChild(gDescription);
  264. form = CreateForm();
  265. theForm = form;
  266. curKeyID = aKeyID;
  267. curKeyType = aKeyType;
  268. table = CreateTable();
  269. form.appendChild(table);
  270. for(i = 0 ; i < len ; i ++)
  271. {
  272. curParameter = name_value_objects[i];
  273. if(curParameter)
  274. {
  275. title = curParameter["title"];
  276. if(title)
  277. {
  278. //alert("title " + title);
  279. AddTextToNode(gTitle,title);
  280. }
  281. description = curParameter["description"];
  282. if(description)
  283. {
  284. AddBRToNode(document.body);
  285. AddBRToNode(document.body);
  286. AddTextToNode(gDescription,description);
  287. AddBRToNode(document.body);
  288. }
  289. id = curParameter["id"];
  290. name = curParameter["name"];
  291. type = curParameter["type"];
  292. desc = curParameter["desc"];
  293. //alert(" id " + id + " name " + name + " type " + type + " desc " + desc);
  294. if(id)
  295. {
  296. if(table)
  297. {
  298. row = AddRowToTable(table);
  299. }
  300. if(row)
  301. {
  302. column = AddColumnToRow(row);
  303. }
  304. if(column)
  305. {
  306. AddTextToColumn(column,name);
  307. }
  308. if(type == "string" || type == "integer")
  309. {
  310. field = AddInputField("text",id,name,"");
  311. }
  312. re_field = null;
  313. if(type == "password")
  314. {
  315. field = AddInputField("password",id,name,"");
  316. }
  317. if(type == "hidden")
  318. {
  319. field = AddInputField("hidden",id,name,"");
  320. }
  321. if(field)
  322. {
  323. field_col = AddColumnToRow(row);
  324. if(field_col)
  325. {
  326. field_col.appendChild(field);
  327. }
  328. }
  329. if(re_field)
  330. {
  331. re_text = AddColumnToRow(row);
  332. if(re_text)
  333. {
  334. AddTextToColumn(re_text,"Confirm " + name);
  335. re_field_col = AddColumnToRow(row);
  336. if(re_field_col)
  337. {
  338. re_field_col.appendChild(re_field);
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. var last_row = AddRowToTable(table);
  346. if(last_row)
  347. {
  348. var button_field = AddColumnToRow(last_row);
  349. if(button_field)
  350. {
  351. var button = AddInputField("button","Submit","Submit","Submit");
  352. button.onclick = FormSubmit;
  353. button_field.appendChild(button);
  354. }
  355. }
  356. }
  357. function UiLoad()
  358. {
  359. var thisParent = window.opener;
  360. if(!thisParent)
  361. {
  362. alert("Auth dialog has no parent!");
  363. return;
  364. }
  365. var keyID = this.name;
  366. var ui = thisParent.getUIForKey(keyID);
  367. var type = thisParent.getTypeForKey(keyID);
  368. //alert("UiLoad " + ui);
  369. if(ui)
  370. {
  371. ConstructUI(type,keyID,ui);
  372. }
  373. }
  374. </script>
  375. </head>
  376. <body onload = "UiLoad()">
  377. </body>
  378. </html>