Rev 693 | Rev 833 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | /* |
2 | * OIDplus 2.0 |
||
3 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
||
4 | * |
||
5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
6 | * you may not use this file except in compliance with the License. |
||
7 | * You may obtain a copy of the License at |
||
8 | * |
||
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
10 | * |
||
11 | * Unless required by applicable law or agreed to in writing, software |
||
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
14 | * See the License for the specific language governing permissions and |
||
15 | * limitations under the License. |
||
16 | */ |
||
17 | |||
18 | var OIDplusPagePublicObjects = { |
||
19 | |||
20 | oid: "1.3.6.1.4.1.37476.2.5.2.4.1.0", |
||
21 | |||
22 | cbRemoveTinyMCE: function(selector) { |
||
23 | if ((typeof tinymce == "undefined") || (tinymce == null)) { |
||
24 | // This should not happen |
||
25 | console.error("OIDplusPagePublicObjects.cbRemoveTinyMCE(): TinyMCE is missing?!"); |
||
26 | return; |
||
27 | } |
||
28 | tinymce.remove(selector); // here, we need a "#" (selector contains "#") |
||
29 | }, |
||
30 | |||
31 | cbQueryTinyMCE: function(selector) { |
||
32 | // tinymce.get() does NOT allow a "#" prefix (but selector contains "#"). So we remove it |
||
33 | selector = selector.replace('#', ''); |
||
34 | |||
35 | if ((typeof tinymce == "undefined") || (tinymce == null) || (tinymce.get(selector) == null)) { |
||
36 | // This should not happen |
||
37 | console.error("OIDplusPagePublicObjects.cbQueryTinyMCE(): TinyMCE is missing?!"); |
||
38 | return true; |
||
39 | } |
||
40 | if (tinymce.get(selector).isDirty()) { |
||
41 | return confirm(_L("Attention: Do you want to continue without saving?")); |
||
42 | } else { |
||
43 | return true; |
||
44 | } |
||
45 | }, |
||
46 | |||
47 | checkMissingOrDoubleASN1: function(oid) { |
||
48 | var suffix = (oid == '') ? '' : '_'+oid; |
||
49 | |||
50 | //var curinput = $('#asn1ids'+suffix').value; |
||
51 | var curinput = $('input[id="asn1ids'+suffix+'"]')[0]; |
||
52 | |||
53 | if (typeof curinput == "undefined") return true; |
||
54 | |||
55 | if (curinput.value == '') { |
||
56 | // TODO: maybe we should only warn if ASN.1, IRI and Comment are all null, not just ASN.1? |
||
57 | if (!confirm(_L("Attention: You did not enter an ASN.1 identifier. Are you sure that you want to continue?"))) return false; |
||
58 | } |
||
59 | |||
60 | var ary = curinput.value.split(','); |
||
61 | |||
62 | for (var i=0; i<ary.length; i++) { |
||
63 | var toCheck = ary[i]; |
||
64 | var bry = $('input[id^="asn1ids_"]'); |
||
65 | for (var j=0; j<bry.length; j++) { |
||
66 | if (bry[j].id != 'asn1ids'+suffix) { |
||
67 | var cry = bry[j].value.split(','); |
||
68 | for (var k=0; k<cry.length; k++) { |
||
69 | var candidate = cry[k]; |
||
70 | if ((toCheck != "") && (candidate != "") && (toCheck == candidate)) { |
||
71 | if (!confirm(_L("Warning! ASN.1 ID %1 is already used in another OID. Continue?", candidate))) return false; |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | |||
78 | return true; |
||
79 | }, |
||
80 | |||
81 | crudActionInsert: function(parent) { |
||
82 | if (parent.startsWith('oid:') && !OIDplusPagePublicObjects.checkMissingOrDoubleASN1('')) return; |
||
83 | |||
84 | $.ajax({ |
||
85 | url:"ajax.php", |
||
86 | method:"POST", |
||
87 | beforeSend: function(jqXHR, settings) { |
||
88 | $.xhrPool.abortAll(); |
||
89 | $.xhrPool.add(jqXHR); |
||
90 | }, |
||
91 | complete: function(jqXHR, text) { |
||
92 | $.xhrPool.remove(jqXHR); |
||
93 | }, |
||
94 | data: { |
||
95 | csrf_token:csrf_token, |
||
96 | plugin:OIDplusPagePublicObjects.oid, |
||
97 | action:"Insert", |
||
98 | id:$("#id")[0].value, |
||
99 | ra_email:$("#ra_email")[0].value, |
||
100 | comment:$("#comment")[0].value, |
||
101 | asn1ids:($("#asn1ids")[0] ? $("#asn1ids")[0].value : null), |
||
102 | iris:($("#iris")[0] ? $("#iris")[0].value : null), |
||
103 | confidential:($("#hide")[0] ? $("#hide")[0].checked : null), |
||
104 | weid:($("#weid")[0] ? $("#weid")[0].checked : null), |
||
105 | parent:parent |
||
106 | }, |
||
107 | error:function(jqXHR, textStatus, errorThrown) { |
||
108 | if (errorThrown == "abort") return; |
||
109 | alert(_L("Error: %1",errorThrown)); |
||
110 | }, |
||
111 | success:function(data) { |
||
112 | if ("error" in data) { |
||
113 | alert(_L("Error: %1",data.error)); |
||
114 | } else if (data.status >= 0) { |
||
115 | if (data.status == 0/*OK*/) { |
||
116 | if (confirm(_L("Insert OK.")+"\n\n"+_L("Do you want to open the newly created object now?"))) { |
||
117 | openAndSelectNode(data.inserted_id, parent); |
||
118 | return; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | if ((data.status & 1) == 1/*RaNotExisting*/) { |
||
123 | if (confirm(_L("Insert OK. However, the email address you have entered (%1) is not in our system. Do you want to send an invitation, so that the RA can register an account to manage their OIDs?",$("#ra_email")[0].value))) { |
||
675 | daniel-mar | 124 | OIDplusPagePublicObjects.crudActionSendInvitation(parent, $("#ra_email_"+$.escapeSelector(id))[0].value); |
635 | daniel-mar | 125 | return; |
126 | } else { |
||
127 | if (confirm(_L("Do you want to open the newly created object now?"))) { |
||
128 | openAndSelectNode(data.inserted_id, parent); |
||
129 | return; |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | |||
134 | if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) { |
||
135 | if (confirm(_L("Insert OK.")+"\n\n"+_L("Do you want to open the newly created object now?"))) { |
||
136 | openAndSelectNode(data.inserted_id, parent); |
||
137 | return; |
||
138 | } |
||
139 | } |
||
140 | |||
141 | if ((data.status & 4) == 4/*IsWellKnownOID*/) { |
||
142 | if (confirm(_L("Insert OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.")+"\n\n"+_L("Do you want to open the newly created object now?"))) { |
||
143 | openAndSelectNode(data.inserted_id, parent); |
||
144 | return; |
||
145 | } |
||
146 | } |
||
147 | |||
148 | // TODO: Don't use reloadContent(); instead add a node at the tree at the left add at the right add a new row to the table |
||
149 | reloadContent(); |
||
150 | } else { |
||
151 | alert(_L("Error: %1",data)); |
||
152 | } |
||
153 | } |
||
154 | }); |
||
155 | }, |
||
156 | |||
157 | crudActionUpdate: function(id, parent) { |
||
158 | if (id.startsWith('oid:') && !OIDplusPagePublicObjects.checkMissingOrDoubleASN1(id)) return; |
||
159 | |||
160 | $.ajax({ |
||
161 | url:"ajax.php", |
||
162 | method:"POST", |
||
163 | beforeSend: function(jqXHR, settings) { |
||
164 | $.xhrPool.abortAll(); |
||
165 | $.xhrPool.add(jqXHR); |
||
166 | }, |
||
167 | complete: function(jqXHR, text) { |
||
168 | $.xhrPool.remove(jqXHR); |
||
169 | }, |
||
170 | data: { |
||
171 | csrf_token:csrf_token, |
||
172 | plugin:OIDplusPagePublicObjects.oid, |
||
173 | action:"Update", |
||
174 | id:id, |
||
675 | daniel-mar | 175 | ra_email:$("#ra_email_"+$.escapeSelector(id))[0].value, |
176 | comment:$("#comment_"+$.escapeSelector(id))[0].value, |
||
177 | asn1ids:($("#asn1ids_"+$.escapeSelector(id))[0] ? $("#asn1ids_"+$.escapeSelector(id))[0].value : null), |
||
178 | iris:($("#iris_"+$.escapeSelector(id))[0] ? $("#iris_"+$.escapeSelector(id))[0].value : null), |
||
179 | confidential:($("#hide_"+$.escapeSelector(id))[0] ? $("#hide_"+$.escapeSelector(id))[0].checked : null), |
||
635 | daniel-mar | 180 | parent:parent |
181 | }, |
||
182 | error:function(jqXHR, textStatus, errorThrown) { |
||
183 | if (errorThrown == "abort") return; |
||
184 | alert(_L("Error: %1",errorThrown)); |
||
185 | }, |
||
186 | success:function(data) { |
||
187 | if ("error" in data) { |
||
188 | alert(_L("Error: %1",data.error)); |
||
189 | } else if (data.status >= 0) { |
||
190 | if (data.status == 0/*OK*/) { |
||
191 | alert(_L("Update OK")); |
||
192 | } |
||
193 | |||
194 | if ((data.status & 1) == 1/*RaNotExisting*/) { |
||
675 | daniel-mar | 195 | if (confirm(_L("Update OK. However, the email address you have entered (%1) is not in our system. Do you want to send an invitation, so that the RA can register an account to manage their OIDs?",$("#ra_email_"+$.escapeSelector(id))[0].value))) { |
196 | OIDplusPagePublicObjects.crudActionSendInvitation(parent, $("#ra_email_"+$.escapeSelector(id))[0].value); |
||
635 | daniel-mar | 197 | return; |
198 | } |
||
199 | } |
||
200 | |||
201 | if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) { |
||
202 | alert(_L("Update OK")); |
||
203 | } |
||
204 | |||
205 | if ((data.status & 4) == 4/*IsWellKnownOID*/) { |
||
206 | alert(_L("Update OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.")); |
||
207 | } |
||
208 | |||
209 | // reloadContent(); |
||
210 | $('#oidtree').jstree("refresh"); |
||
211 | } else { |
||
212 | alert(_L("Error: %1",data)); |
||
213 | } |
||
214 | } |
||
215 | }); |
||
216 | }, |
||
217 | |||
218 | crudActionDelete: function(id, parent) { |
||
219 | if(!window.confirm(_L("Are you sure that you want to delete %1?",id))) return false; |
||
220 | |||
221 | $.ajax({ |
||
222 | url:"ajax.php", |
||
223 | method:"POST", |
||
224 | beforeSend: function(jqXHR, settings) { |
||
225 | $.xhrPool.abortAll(); |
||
226 | $.xhrPool.add(jqXHR); |
||
227 | }, |
||
228 | complete: function(jqXHR, text) { |
||
229 | $.xhrPool.remove(jqXHR); |
||
230 | }, |
||
231 | data: { |
||
232 | csrf_token:csrf_token, |
||
233 | plugin:OIDplusPagePublicObjects.oid, |
||
234 | action:"Delete", |
||
235 | id:id, |
||
236 | parent:parent |
||
237 | }, |
||
238 | error:function(jqXHR, textStatus, errorThrown) { |
||
239 | if (errorThrown == "abort") return; |
||
240 | alert(_L("Error: %1",errorThrown)); |
||
241 | }, |
||
242 | success:function(data) { |
||
243 | if ("error" in data) { |
||
244 | alert(_L("Error: %1",data.error)); |
||
245 | } else if (data.status >= 0) { |
||
246 | reloadContent(); |
||
247 | // TODO: Don't use reloadContent(); instead delete node at the left tree and remove the row at the right table |
||
248 | } else { |
||
249 | alert(_L("Error: %1",data.error)); |
||
250 | } |
||
251 | } |
||
252 | }); |
||
253 | }, |
||
254 | |||
255 | updateDesc: function() { |
||
256 | $.ajax({ |
||
257 | url:"ajax.php", |
||
258 | method:"POST", |
||
259 | beforeSend: function(jqXHR, settings) { |
||
260 | $.xhrPool.abortAll(); |
||
261 | $.xhrPool.add(jqXHR); |
||
262 | }, |
||
263 | complete: function(jqXHR, text) { |
||
264 | $.xhrPool.remove(jqXHR); |
||
265 | }, |
||
266 | data: { |
||
267 | csrf_token:csrf_token, |
||
268 | plugin:OIDplusPagePublicObjects.oid, |
||
269 | action:"Update2", |
||
270 | id:current_node, |
||
271 | title:($("#titleedit")[0] ? $("#titleedit")[0].value : null), |
||
272 | //description:($("#description")[0] ? $("#description")[0].value : null) |
||
273 | description:tinyMCE.get('description').getContent() |
||
274 | }, |
||
275 | error:function(jqXHR, textStatus, errorThrown) { |
||
276 | if (errorThrown == "abort") return; |
||
277 | alert(_L("Error: %1",errorThrown)); |
||
278 | }, |
||
279 | success:function(data) { |
||
280 | if ("error" in data) { |
||
281 | alert(_L("Error: %1",data.error)); |
||
282 | } else if (data.status >= 0) { |
||
283 | alert(_L("Update OK")); |
||
284 | //reloadContent(); |
||
285 | $('#oidtree').jstree("refresh"); |
||
286 | var h1s = $("h1"); |
||
287 | for (var i = 0; i < h1s.length; i++) { |
||
288 | var h1 = h1s[i]; |
||
289 | h1.innerHTML = $("#titleedit")[0].value.htmlentities(); |
||
290 | } |
||
291 | document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), $("#titleedit")[0].value); |
||
292 | |||
293 | var mce = tinymce.get('description'); |
||
294 | if (mce != null) mce.setDirty(false); |
||
295 | } else { |
||
296 | alert(_L("Error: %1",data.error)); |
||
297 | } |
||
298 | } |
||
299 | }); |
||
300 | }, |
||
301 | |||
302 | crudActionSendInvitation: function(origin, email) { |
||
303 | // window.location.href = "?goto=oidplus:invite_ra$"+encodeURIComponent(email)+"$"+encodeURIComponent(origin); |
||
304 | openOidInPanel('oidplus:invite_ra$'+email+'$'+origin, false); |
||
305 | }, |
||
306 | |||
307 | frdl_weid_change: function() { |
||
308 | var from_base = 36; |
||
309 | var from_control = "#weid"; |
||
310 | var to_base = 10; |
||
311 | var to_control = "#id"; |
||
312 | |||
672 | daniel-mar | 313 | var inp = $(from_control).val().toUpperCase().trim(); |
635 | daniel-mar | 314 | if (inp == "") { |
315 | $(to_control).val(""); |
||
316 | } else { |
||
752 | daniel-mar | 317 | var x = WeidOidConverter.base_convert_bigint(inp, from_base, to_base); |
318 | if (x == false) { |
||
635 | daniel-mar | 319 | $(to_control).val(""); |
320 | } else { |
||
752 | daniel-mar | 321 | $(to_control).val(x); |
635 | daniel-mar | 322 | } |
323 | } |
||
324 | }, |
||
325 | |||
326 | frdl_oidid_change: function() { |
||
327 | var from_base = 10; |
||
328 | var from_control = "#id"; |
||
329 | var to_base = 36; |
||
330 | var to_control = "#weid"; |
||
331 | |||
332 | var inp = $(from_control).val().trim(); |
||
333 | if (inp == "") { |
||
334 | $(to_control).val(""); |
||
335 | } else { |
||
752 | daniel-mar | 336 | var x = WeidOidConverter.base_convert_bigint(inp, from_base, to_base); |
337 | if (x == false) { |
||
635 | daniel-mar | 338 | $(to_control).val(""); |
339 | } else { |
||
752 | daniel-mar | 340 | $(to_control).val(x.toUpperCase()); |
635 | daniel-mar | 341 | } |
342 | } |
||
343 | } |
||
344 | |||
345 | }; |