Rev 684 | Rev 693 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
||
21 | |||
22 | class OIDplusPagePublicObjects extends OIDplusPagePluginPublic { |
||
23 | |||
24 | private function get_treeicon_root($ot) { |
||
25 | $dirs = glob(OIDplus::localpath().'plugins/'.'*'.'/objectTypes/'.$ot::ns()); |
||
26 | |||
27 | if (count($dirs) == 0) { |
||
28 | $icon = null; |
||
29 | } else { |
||
30 | $dir = $dirs[0]; |
||
31 | $icon = $dir.'/img/treeicon_root.png'; |
||
32 | if (!file_exists($icon)) $icon = null; |
||
33 | $icon = substr($icon, strlen(OIDplus::localpath())); |
||
34 | } |
||
35 | |||
36 | return $icon; |
||
37 | } |
||
38 | |||
39 | private function ra_change_rec($id, $old_ra, $new_ra) { |
||
40 | if (is_null($old_ra)) $old_ra = ''; |
||
41 | OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($new_ra, $id, $old_ra)); |
||
42 | |||
43 | $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra)); |
||
44 | while ($row = $res->fetch_array()) { |
||
45 | $this->ra_change_rec($row['id'], $old_ra, $new_ra); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | public function action($actionID, $params) { |
||
50 | |||
51 | // Action: Delete |
||
52 | // Method: POST |
||
53 | // Parameters: id |
||
54 | // Outputs: <0 Error, =0 Success |
||
55 | if ($actionID == 'Delete') { |
||
56 | _CheckParamExists($params, 'id'); |
||
57 | $id = $params['id']; |
||
58 | $obj = OIDplusObject::parse($id); |
||
59 | if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id)); |
||
60 | |||
61 | if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) { |
||
62 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
||
63 | } |
||
64 | |||
65 | // Check if permitted |
||
66 | if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.')); |
||
67 | |||
68 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
69 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) { |
||
70 | $plugin->beforeObjectDelete($id); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | OIDplus::logger()->log("[WARN]OID($id)+[?WARN/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "Object '$id' (recursively) deleted"); |
||
75 | OIDplus::logger()->log("[CRIT]OIDRA($id)!", "Lost ownership of object '$id' because it was deleted"); |
||
76 | |||
77 | if ($parentObj = $obj->getParent()) { |
||
78 | $parent_oid = $parentObj->nodeId(); |
||
79 | OIDplus::logger()->log("[WARN]OID($parent_oid)", "Object '$id' (recursively) deleted"); |
||
80 | } |
||
81 | |||
82 | // Delete object |
||
83 | OIDplus::db()->query("delete from ###objects where id = ?", array($id)); |
||
84 | |||
85 | // Delete orphan stuff |
||
86 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
87 | do { |
||
88 | $res = OIDplus::db()->query("select tchild.id from ###objects tchild " . |
||
89 | "left join ###objects tparent on tparent.id = tchild.parent " . |
||
90 | "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%')); |
||
91 | if ($res->num_rows() == 0) break; |
||
92 | |||
93 | while ($row = $res->fetch_array()) { |
||
94 | $id_to_delete = $row['id']; |
||
95 | OIDplus::logger()->log("[CRIT]OIDRA($id_to_delete)!", "Lost ownership of object '$id_to_delete' because one of the superior objects ('$id') was recursively deleted"); |
||
96 | OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete)); |
||
97 | } |
||
98 | } while (true); |
||
99 | } |
||
100 | OIDplus::db()->query("delete from ###asn1id where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false)); |
||
101 | OIDplus::db()->query("delete from ###iri where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false)); |
||
102 | |||
103 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
104 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) { |
||
105 | $plugin->afterObjectDelete($id); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | return array("status" => 0); |
||
110 | } |
||
111 | |||
112 | // Action: Update |
||
113 | // Method: POST |
||
114 | // Parameters: id, ra_email, comment, iris, asn1ids, confidential |
||
115 | // Outputs: <0 Error, =0 Success, with following bitfields for further information: |
||
116 | // 1 = RA is not registered |
||
117 | // 2 = RA is not registered, but it cannot be invited |
||
118 | // 4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset |
||
119 | else if ($actionID == 'Update') { |
||
120 | _CheckParamExists($params, 'id'); |
||
121 | $id = $params['id']; |
||
122 | $obj = OIDplusObject::parse($id); |
||
123 | if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id)); |
||
124 | |||
125 | if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) { |
||
126 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
||
127 | } |
||
128 | |||
129 | // Check if permitted |
||
130 | if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.')); |
||
131 | |||
132 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
133 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) { |
||
134 | $plugin->beforeObjectUpdateSuperior($id, $params); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | // First, do a simulation for ASN.1 IDs and IRIs to check if there are any problems (then an Exception will be thrown) |
||
139 | if ($obj::ns() == 'oid') { |
||
140 | if (!$obj->isWellKnown()) { |
||
141 | if (isset($params['iris'])) { |
||
142 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
143 | $ids = array_map('trim',$ids); |
||
144 | $obj->replaceIris($ids, true); |
||
145 | } |
||
146 | |||
147 | if (isset($params['asn1ids'])) { |
||
148 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
149 | $ids = array_map('trim',$ids); |
||
150 | $obj->replaceAsn1Ids($ids, true); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | |||
155 | // RA E-Mail change |
||
156 | if (isset($params['ra_email'])) { |
||
157 | // Validate RA email address |
||
158 | $new_ra = $params['ra_email']; |
||
159 | if ($obj::ns() == 'oid') { |
||
160 | if ($obj->isWellKnown()) { |
||
161 | $new_ra = ''; |
||
162 | } |
||
163 | } |
||
164 | if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) { |
||
165 | throw new OIDplusException(_L('Invalid RA email address')); |
||
166 | } |
||
167 | |||
168 | // Change RA recursively |
||
169 | $res = OIDplus::db()->query("select ra_email from ###objects where id = ?", array($id)); |
||
170 | if ($row = $res->fetch_array()) { |
||
171 | $current_ra = $row['ra_email']; |
||
172 | if ($new_ra != $current_ra) { |
||
173 | OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "RA of object '$id' changed from '$current_ra' to '$new_ra'"); |
||
174 | OIDplus::logger()->log("[WARN]RA($current_ra)!", "Lost ownership of object '$id' due to RA transfer of superior RA / admin."); |
||
175 | OIDplus::logger()->log("[INFO]RA($new_ra)!", "Gained ownership of object '$id' due to RA transfer of superior RA / admin."); |
||
176 | if ($parentObj = $obj->getParent()) { |
||
177 | $parent_oid = $parentObj->nodeId(); |
||
178 | OIDplus::logger()->log("[INFO]OID($parent_oid)", "RA of object '$id' changed from '$current_ra' to '$new_ra'"); |
||
179 | } |
||
180 | $this->ra_change_rec($id, $current_ra, $new_ra); // Recursively change inherited RAs |
||
181 | } |
||
182 | } |
||
183 | } |
||
184 | |||
185 | // Log if confidentially flag was changed |
||
186 | OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "Identifiers/Confidential flag of object '$id' updated"); // TODO: Check if they were ACTUALLY updated! |
||
187 | if ($parentObj = $obj->getParent()) { |
||
188 | $parent_oid = $parentObj->nodeId(); |
||
189 | OIDplus::logger()->log("[INFO]OID($parent_oid)", "Identifiers/Confidential flag of object '$id' updated"); // TODO: Check if they were ACTUALLY updated! |
||
190 | } |
||
191 | |||
192 | // Replace ASN.1 IDs und IRIs |
||
193 | if ($obj::ns() == 'oid') { |
||
194 | if (!$obj->isWellKnown()) { |
||
195 | if (isset($params['iris'])) { |
||
196 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
197 | $ids = array_map('trim',$ids); |
||
198 | $obj->replaceIris($ids, false); |
||
199 | } |
||
200 | |||
201 | if (isset($params['asn1ids'])) { |
||
202 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
203 | $ids = array_map('trim',$ids); |
||
204 | $obj->replaceAsn1Ids($ids, false); |
||
205 | } |
||
206 | } |
||
207 | |||
208 | // TODO: Check if any identifiers have been actually changed, |
||
209 | // and log it to OID($id), OID($parent), ... (see above) |
||
210 | } |
||
211 | |||
212 | if (isset($params['confidential'])) { |
||
213 | $confidential = $params['confidential'] == 'true'; |
||
214 | OIDplus::db()->query("UPDATE ###objects SET confidential = ? WHERE id = ?", array($confidential, $id)); |
||
215 | } |
||
216 | |||
217 | if (isset($params['comment'])) { |
||
218 | $comment = $params['comment']; |
||
219 | OIDplus::db()->query("UPDATE ###objects SET comment = ? WHERE id = ?", array($comment, $id)); |
||
220 | } |
||
221 | |||
222 | OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id)); |
||
223 | |||
224 | $status = 0; |
||
225 | |||
226 | if (!empty($new_ra)) { |
||
227 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra)); |
||
228 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
||
229 | if ($res->num_rows() == 0) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2; |
||
230 | } |
||
231 | |||
232 | if ($obj::ns() == 'oid') { |
||
233 | if ($obj->isWellKnown()) { |
||
234 | $status += 4; |
||
235 | } |
||
236 | } |
||
237 | |||
238 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
239 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) { |
||
240 | $plugin->afterObjectUpdateSuperior($id, $params); |
||
241 | } |
||
242 | } |
||
243 | |||
244 | return array("status" => $status); |
||
245 | } |
||
246 | |||
247 | // Action: Update2 |
||
248 | // Method: POST |
||
249 | // Parameters: id, title, description |
||
250 | // Outputs: <0 Error, =0 Success |
||
251 | else if ($actionID == 'Update2') { |
||
252 | _CheckParamExists($params, 'id'); |
||
253 | $id = $params['id']; |
||
254 | $obj = OIDplusObject::parse($id); |
||
255 | if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE2',$id)); |
||
256 | |||
257 | if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) { |
||
258 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
||
259 | } |
||
260 | |||
261 | // Check if allowed |
||
262 | if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.')); |
||
263 | |||
264 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
265 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) { |
||
266 | $plugin->beforeObjectUpdateSelf($id, $params); |
||
267 | } |
||
268 | } |
||
269 | |||
270 | OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]OIDRA($id)?/[?INFO/!OK]A?", "Title/Description of object '$id' updated"); |
||
271 | |||
272 | if (isset($params['title'])) { |
||
273 | $title = $params['title']; |
||
274 | OIDplus::db()->query("UPDATE ###objects SET title = ? WHERE id = ?", array($title, $id)); |
||
275 | } |
||
276 | |||
277 | if (isset($params['description'])) { |
||
278 | $description = $params['description']; |
||
279 | OIDplus::db()->query("UPDATE ###objects SET description = ? WHERE id = ?", array($description, $id)); |
||
280 | } |
||
281 | |||
282 | OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id)); |
||
283 | |||
284 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
285 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) { |
||
286 | $plugin->afterObjectUpdateSelf($id, $params); |
||
287 | } |
||
288 | } |
||
289 | |||
290 | return array("status" => 0); |
||
291 | } |
||
292 | |||
293 | // Generate UUID |
||
294 | else if ($actionID == 'generate_uuid') { |
||
295 | $uuid = gen_uuid(); |
||
296 | if (!$uuid) return array("status" => 1); |
||
297 | return array( |
||
298 | "status" => 0, |
||
299 | "uuid" => $uuid, |
||
300 | "intval" => substr(uuid_to_oid($uuid),strlen('2.25.')) |
||
301 | ); |
||
302 | } |
||
303 | |||
304 | // Action: Insert |
||
305 | // Method: POST |
||
306 | // Parameters: parent, id, ra_email, confidential, iris, asn1ids |
||
307 | // Outputs: status=<0 Error, =0 Success, with following bitfields for further information: |
||
308 | // 1 = RA is not registered |
||
309 | // 2 = RA is not registered, but it cannot be invited |
||
310 | // 4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset |
||
311 | else if ($actionID == 'Insert') { |
||
312 | // Check if you have write rights on the parent (to create a new object) |
||
313 | _CheckParamExists($params, 'parent'); |
||
314 | $objParent = OIDplusObject::parse($params['parent']); |
||
315 | if ($objParent === null) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent'])); |
||
316 | |||
317 | if (!$objParent::root() && (OIDplus::db()->query("select id from ###objects where id = ?", array($objParent->nodeId()))->num_rows() == 0)) { |
||
318 | throw new OIDplusException(_L('Parent object %1 does not exist','".($objParent->nodeId())."')); |
||
319 | } |
||
320 | |||
321 | if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.')); |
||
322 | |||
323 | // Check if the ID is valid |
||
324 | _CheckParamExists($params, 'id'); |
||
325 | if ($params['id'] == '') throw new OIDplusException(_L('ID may not be empty')); |
||
326 | |||
327 | // Determine absolute OID name |
||
328 | // Note: At addString() and parse(), the syntax of the ID will be checked |
||
329 | $id = $objParent->addString($params['id']); |
||
330 | |||
331 | // Check, if the OID exists |
||
332 | $test = OIDplus::db()->query("select id from ###objects where id = ?", array($id)); |
||
333 | if ($test->num_rows() >= 1) { |
||
334 | throw new OIDplusException(_L('Object %1 already exists!',$id)); |
||
335 | } |
||
336 | |||
337 | $obj = OIDplusObject::parse($id); |
||
338 | if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id)); |
||
339 | |||
340 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
341 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) { |
||
342 | $plugin->beforeObjectInsert($id, $params); |
||
343 | } |
||
344 | } |
||
345 | |||
346 | // First simulate if there are any problems of ASN.1 IDs und IRIs |
||
347 | if ($obj::ns() == 'oid') { |
||
348 | if (!$obj->isWellKnown()) { |
||
349 | if (isset($params['iris'])) { |
||
350 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
351 | $ids = array_map('trim',$ids); |
||
352 | $obj->replaceIris($ids, true); |
||
353 | } |
||
354 | |||
355 | if (isset($params['asn1ids'])) { |
||
356 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
357 | $ids = array_map('trim',$ids); |
||
358 | $obj->replaceAsn1Ids($ids, true); |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | |||
363 | // Apply superior RA change |
||
364 | $parent = $params['parent']; |
||
365 | $ra_email = isset($params['ra_email']) ? $params['ra_email'] : ''; |
||
366 | if ($obj::ns() == 'oid') { |
||
367 | if ($obj->isWellKnown()) { |
||
368 | $ra_email = ''; |
||
369 | } |
||
370 | } |
||
371 | if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) { |
||
372 | throw new OIDplusException(_L('Invalid RA email address')); |
||
373 | } |
||
374 | |||
375 | OIDplus::logger()->log("[INFO]OID($parent)+[INFO]OID($id)+[?INFO/!OK]OIDRA($parent)?/[?INFO/!OK]A?", "Object '$id' created, ".(empty($ra_email) ? "without defined RA" : "given to RA '$ra_email'")).", superior object is '$parent'"; |
||
376 | if (!empty($ra_email)) { |
||
377 | OIDplus::logger()->log("[INFO]RA($ra_email)!", "Gained ownership of newly created object '$id'"); |
||
378 | } |
||
379 | |||
380 | $confidential = isset($params['confidential']) ? ($params['confidential'] == 'true') : false; |
||
381 | $comment = isset($params['comment']) ? $params['comment'] : ''; |
||
382 | $title = ''; |
||
383 | $description = ''; |
||
384 | |||
385 | if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) { |
||
386 | $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH'); |
||
387 | throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen)); |
||
388 | } |
||
389 | |||
390 | OIDplus::db()->query("INSERT INTO ###objects (id, parent, ra_email, confidential, comment, created, title, description) VALUES (?, ?, ?, ?, ?, ".OIDplus::db()->sqlDate().", ?, ?)", array($id, $parent, $ra_email, $confidential, $comment, $title, $description)); |
||
391 | |||
392 | // Set ASN.1 IDs und IRIs |
||
393 | if ($obj::ns() == 'oid') { |
||
394 | if (!$obj->isWellKnown()) { |
||
395 | if (isset($params['iris'])) { |
||
396 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
397 | $ids = array_map('trim',$ids); |
||
398 | $obj->replaceIris($ids, false); |
||
399 | } |
||
400 | |||
401 | if (isset($params['asn1ids'])) { |
||
402 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
403 | $ids = array_map('trim',$ids); |
||
404 | $obj->replaceAsn1Ids($ids, false); |
||
405 | } |
||
406 | } |
||
407 | } |
||
408 | |||
409 | $status = 0; |
||
410 | |||
411 | if (!empty($ra_email)) { |
||
412 | // Do we need to notify that the RA does not exist? |
||
413 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email)); |
||
414 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
||
415 | if ($res->num_rows() == 0) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2; |
||
416 | } |
||
417 | |||
418 | if ($obj::ns() == 'oid') { |
||
419 | if ($obj->isWellKnown()) { |
||
420 | $status += 4; |
||
421 | } |
||
422 | } |
||
423 | |||
424 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
425 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) { |
||
426 | $plugin->afterObjectInsert($id, $params); |
||
427 | } |
||
428 | } |
||
429 | |||
430 | return array( |
||
431 | "status" => $status, |
||
432 | "inserted_id" => $id |
||
433 | ); |
||
434 | } else { |
||
435 | throw new OIDplusException(_L('Unknown action ID')); |
||
436 | } |
||
437 | } |
||
438 | |||
439 | public function init($html=true) { |
||
440 | OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {}); |
||
692 | daniel-mar | 441 | OIDplus::config()->prepareConfigKey('oid_grid_show_weid', 'Show WEID/Base36 column in CRUD grid of OIDs?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
442 | if (!is_numeric($value) || ($value < 0) || ($value > 1)) { |
||
443 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
||
444 | } |
||
445 | }); |
||
635 | daniel-mar | 446 | } |
447 | |||
448 | public function gui($id, &$out, &$handled) { |
||
449 | if ($id === 'oidplus:system') { |
||
450 | $handled = true; |
||
451 | |||
452 | $out['title'] = OIDplus::config()->getValue('system_title'); |
||
453 | $out['icon'] = OIDplus::webpath(__DIR__).'system_big.png'; |
||
454 | |||
455 | if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) { |
||
456 | $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html'); |
||
457 | } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) { |
||
458 | $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html'); |
||
459 | } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) { |
||
460 | $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html'); |
||
461 | } else if (file_exists(__DIR__ . '/welcome.html')) { |
||
462 | $cont = file_get_contents(__DIR__ . '/welcome.html'); |
||
463 | } else { |
||
464 | $cont = ''; |
||
465 | } |
||
466 | |||
467 | list($html, $js, $css) = extractHtmlContents($cont); |
||
468 | $cont = ''; |
||
469 | if (!empty($js)) $cont .= "<script>\n$js\n</script>"; |
||
470 | if (!empty($css)) $cont .= "<style>\n$css\n</style>"; |
||
471 | $cont .= $html; |
||
472 | |||
473 | $out['text'] = $cont; |
||
474 | |||
475 | if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) { |
||
476 | $tmp = '<ul>'; |
||
477 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
478 | $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>'; |
||
479 | } |
||
480 | $tmp .= '</ul>'; |
||
481 | $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']); |
||
482 | } |
||
483 | |||
484 | return; |
||
485 | } |
||
486 | |||
487 | try { |
||
488 | $obj = OIDplusObject::parse($id); |
||
489 | } catch (Exception $e) { |
||
490 | $obj = null; |
||
491 | } |
||
492 | |||
493 | if (!is_null($obj)) { |
||
494 | $handled = true; |
||
495 | |||
496 | if (!$obj->userHasReadRights()) { |
||
497 | $out['title'] = _L('Access denied'); |
||
498 | $out['icon'] = 'img/error_big.png'; |
||
499 | $out['text'] = '<p>'._L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
500 | return; |
||
501 | } |
||
502 | |||
503 | $parent = null; |
||
504 | $res = null; |
||
505 | $row = null; |
||
506 | $matches_any_registered_type = false; |
||
507 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
508 | if ($obj = $ot::parse($id)) { |
||
509 | $matches_any_registered_type = true; |
||
510 | if ($obj->isRoot()) { |
||
511 | $obj->getContentPage($out['title'], $out['text'], $out['icon']); |
||
512 | $parent = null; // $obj->getParent(); |
||
513 | break; |
||
514 | } else { |
||
515 | $res = OIDplus::db()->query("select * from ###objects where id = ?", array($obj->nodeId())); |
||
516 | if ($res->num_rows() == 0) { |
||
517 | http_response_code(404); |
||
518 | $out['title'] = _L('Object not found'); |
||
519 | $out['icon'] = 'img/error_big.png'; |
||
520 | $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>'); |
||
521 | return; |
||
522 | } else { |
||
523 | $row = $res->fetch_array(); // will be used further down the code |
||
524 | $obj->getContentPage($out['title'], $out['text'], $out['icon']); |
||
525 | if (empty($out['title'])) $out['title'] = explode(':',$id,2)[1]; |
||
526 | $parent = $obj->getParent(); |
||
527 | break; |
||
528 | } |
||
529 | } |
||
530 | } |
||
531 | } |
||
532 | if (!$matches_any_registered_type) { |
||
533 | http_response_code(404); |
||
534 | $out['title'] = _L('Object not found'); |
||
535 | $out['icon'] = 'img/error_big.png'; |
||
536 | $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>'); |
||
537 | return; |
||
538 | } |
||
539 | |||
540 | // --- |
||
541 | |||
542 | if ($parent) { |
||
543 | if ($parent->isRoot()) { |
||
544 | |||
545 | $parent_link_text = $parent->objectTypeTitle(); |
||
546 | $out['text'] = '<p><a '.OIDplus::gui()->link($parent->root()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text']; |
||
547 | |||
548 | } else { |
||
549 | $res_ = OIDplus::db()->query("select * from ###objects where id = ?", array($parent->nodeId())); |
||
550 | if ($res_->num_rows() > 0) { |
||
551 | $row_ = $res_->fetch_array(); |
||
552 | |||
553 | $parent_title = $row_['title']; |
||
554 | if (empty($parent_title) && ($parent->ns() == 'oid')) { |
||
555 | // If not title is available, then use an ASN.1 identifier |
||
556 | $res_ = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($parent->nodeId())); |
||
557 | if ($res_->num_rows() > 0) { |
||
558 | $row_ = $res_->fetch_array(); |
||
559 | $parent_title = $row_['name']; // TODO: multiple ASN1 ids? |
||
560 | } |
||
561 | } |
||
562 | |||
563 | $parent_link_text = empty($parent_title) ? explode(':',$parent->nodeId())[1] : $parent_title.' ('.explode(':',$parent->nodeId())[1].')'; |
||
564 | |||
565 | $out['text'] = '<p><a '.OIDplus::gui()->link($parent->nodeId()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text']; |
||
566 | } else { |
||
567 | $out['text'] = ''; |
||
568 | } |
||
569 | } |
||
570 | } else { |
||
571 | $parent_link_text = _L('Go back to front page'); |
||
572 | $out['text'] = '<p><a '.OIDplus::gui()->link('oidplus:system').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '.htmlentities($parent_link_text).'</a></p>' . $out['text']; |
||
573 | } |
||
574 | |||
575 | // --- |
||
576 | |||
577 | if (!is_null($row) && isset($row['description'])) { |
||
578 | if (empty($row['description'])) { |
||
579 | if (empty($row['title'])) { |
||
580 | $desc = '<p><i>'._L('No description for this object available').'</i></p>'; |
||
581 | } else { |
||
582 | $desc = $row['title']; |
||
583 | } |
||
584 | } else { |
||
585 | $desc = self::objDescription($row['description']); |
||
586 | } |
||
587 | |||
588 | if ($obj->userHasWriteRights()) { |
||
589 | $rand = ++self::$crudCounter; |
||
590 | $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>'; |
||
591 | $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">'; |
||
592 | $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($row['title']).'"><br><br>'._L('Description').':<br>'; |
||
593 | $desc .= self::showMCE('description', $row['description']); |
||
594 | $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>'; |
||
595 | $desc .= '</div>'; |
||
596 | $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>'; |
||
597 | } |
||
598 | } else { |
||
599 | $desc = ''; |
||
600 | } |
||
601 | |||
602 | // --- |
||
603 | |||
604 | if (strpos($out['text'], '%%DESC%%') !== false) |
||
605 | $out['text'] = str_replace('%%DESC%%', $desc, $out['text']); |
||
606 | if (strpos($out['text'], '%%CRUD%%') !== false) |
||
607 | $out['text'] = str_replace('%%CRUD%%', self::showCrud($id), $out['text']); |
||
608 | if (strpos($out['text'], '%%RA_INFO%%') !== false) |
||
609 | $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($row['ra_email']), $out['text']); |
||
610 | |||
611 | $alt_ids = $obj->getAltIds(); |
||
612 | if (count($alt_ids) > 0) { |
||
613 | $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>'; |
||
614 | foreach ($alt_ids as $alt_id) { |
||
615 | $ns = $alt_id->getNamespace(); |
||
616 | $aid = $alt_id->getId(); |
||
617 | $aiddesc = $alt_id->getDescription(); |
||
618 | $out['text'] .= "$aiddesc <code>$ns:$aid</code><br>"; |
||
619 | } |
||
620 | } |
||
621 | |||
622 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
623 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.2')) { |
||
624 | $plugin->modifyContent($id, $out['title'], $out['icon'], $out['text']); |
||
625 | } |
||
626 | } |
||
627 | } |
||
628 | } |
||
629 | |||
630 | private function publicSitemap_rec($json, &$out) { |
||
631 | foreach ($json as $x) { |
||
632 | if (isset($x['id']) && $x['id']) { |
||
633 | $out[] = $x['id']; |
||
634 | } |
||
635 | if (isset($x['children'])) { |
||
636 | $this->publicSitemap_rec($x['children'], $out); |
||
637 | } |
||
638 | } |
||
639 | } |
||
640 | |||
641 | public function publicSitemap(&$out) { |
||
642 | $json = array(); |
||
643 | $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, true/*display all*/); |
||
644 | $this->publicSitemap_rec($json, $out); |
||
645 | } |
||
646 | |||
647 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
648 | if ($nonjs) { |
||
649 | $json[] = array( |
||
650 | 'id' => 'oidplus:system', |
||
651 | 'icon' => OIDplus::webpath(__DIR__).'system.png', |
||
652 | 'text' => _L('System') |
||
653 | ); |
||
654 | |||
655 | $parent = ''; |
||
656 | $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($req_goto)); |
||
657 | while ($row = $res->fetch_object()) { |
||
658 | $parent = $row->parent; |
||
659 | } |
||
660 | |||
661 | $objTypesChildren = array(); |
||
662 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
663 | $icon = $this->get_treeicon_root($ot); |
||
664 | |||
665 | $json[] = array( |
||
666 | 'id' => $ot::root(), |
||
667 | 'icon' => $icon, |
||
668 | 'text' => $ot::objectTypeTitle() |
||
669 | ); |
||
670 | |||
671 | try { |
||
672 | $tmp = OIDplusObject::parse($req_goto); |
||
673 | } catch (Exception $e) { |
||
674 | $tmp = null; |
||
675 | } |
||
676 | if (!is_null($tmp) && ($ot == get_class($tmp))) { |
||
677 | // TODO: Instead of just having 3 levels (parent, this and children), it would be better if we'd had a full tree of all parents |
||
678 | // on the other hand, for giving search engines content, this is good enough |
||
679 | if (empty($parent)) { |
||
680 | $res = OIDplus::db()->query("select * from ###objects where " . |
||
681 | "parent = ? or " . |
||
682 | "id = ? " . |
||
683 | "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto)); |
||
684 | } else { |
||
685 | $res = OIDplus::db()->query("select * from ###objects where " . |
||
686 | "parent = ? or " . |
||
687 | "id = ? or " . |
||
688 | "id = ? ". |
||
689 | "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto, $parent)); |
||
690 | } |
||
691 | |||
692 | $z_used = 0; |
||
693 | $y_used = 0; |
||
694 | $x_used = 0; |
||
695 | $stufe = 0; |
||
696 | $menu_entries = array(); |
||
697 | $stufen = array(); |
||
698 | while ($row = $res->fetch_object()) { |
||
699 | $obj = OIDplusObject::parse($row->id); |
||
700 | if (is_null($obj)) continue; // might happen if the objectType is not available/loaded |
||
701 | if (!$obj->userHasReadRights()) continue; |
||
702 | $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title); |
||
703 | |||
704 | if ($row->id == $parent) { $stufe=0; $z_used++; } |
||
705 | if ($row->id == $req_goto) { $stufe=1; $y_used++; } |
||
706 | if ($row->parent == $req_goto) { $stufe=2; $x_used++; } |
||
707 | |||
708 | $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0); |
||
709 | $menu_entries[] = $menu_entry; |
||
710 | $stufen[] = $stufe; |
||
711 | } |
||
712 | if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1; |
||
713 | if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1; |
||
714 | if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1; |
||
715 | $json = array_merge($json, $menu_entries); |
||
716 | } |
||
717 | } |
||
718 | |||
719 | return true; |
||
720 | } else { |
||
721 | if ($req_goto === true) { |
||
722 | $goto_path = true; // display everything recursively |
||
723 | } else if (isset($req_goto)) { |
||
724 | $goto = $req_goto; |
||
725 | $path = array(); |
||
726 | while (true) { |
||
727 | $path[] = $goto; |
||
728 | $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($goto)); |
||
729 | if ($res->num_rows() == 0) break; |
||
730 | $row = $res->fetch_array(); |
||
731 | $goto = $row['parent']; |
||
732 | if ($goto == '') continue; |
||
733 | } |
||
734 | |||
735 | $goto_path = array_reverse($path); |
||
736 | } else { |
||
737 | $goto_path = null; |
||
738 | } |
||
739 | |||
740 | $objTypesChildren = array(); |
||
741 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
742 | $icon = $this->get_treeicon_root($ot); |
||
743 | |||
744 | $child = array('id' => $ot::root(), |
||
745 | 'text' => $ot::objectTypeTitle(), |
||
746 | 'state' => array("opened" => true), |
||
747 | 'icon' => $icon, |
||
748 | 'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path) |
||
749 | ); |
||
750 | if (!file_exists($child['icon'])) $child['icon'] = null; // default icon (folder) |
||
751 | $objTypesChildren[] = $child; |
||
752 | } |
||
753 | |||
754 | $json[] = array( |
||
755 | 'id' => "oidplus:system", |
||
756 | 'text' => _L('Objects'), |
||
757 | 'state' => array( |
||
758 | "opened" => true, |
||
759 | // "selected" => true) // "selected" is buggy: |
||
760 | // 1) The select-event will not be triggered upon loading |
||
761 | // 2) The nodes directly blow cannot be opened (loading infinite time) |
||
762 | ), |
||
763 | 'icon' => OIDplus::webpath(__DIR__).'system.png', |
||
764 | 'children' => $objTypesChildren |
||
765 | ); |
||
766 | |||
767 | return true; |
||
768 | } |
||
769 | } |
||
770 | |||
771 | public function tree_search($request) { |
||
772 | $ary = array(); |
||
773 | if ($obj = OIDplusObject::parse($request)) { |
||
774 | if ($obj->userHasReadRights()) { |
||
775 | do { |
||
776 | $ary[] = $obj->nodeId(); |
||
777 | } while ($obj = $obj->getParent()); |
||
778 | $ary = array_reverse($ary); |
||
779 | } |
||
780 | } |
||
781 | return $ary; |
||
782 | } |
||
783 | |||
784 | private static $crudCounter = 0; |
||
785 | |||
786 | protected static function showCrud($parent='oid:') { |
||
787 | $items_total = 0; |
||
788 | $items_hidden = 0; |
||
789 | |||
790 | $objParent = OIDplusObject::parse($parent); |
||
791 | $parentNS = $objParent::ns(); |
||
792 | |||
793 | // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers |
||
794 | $no_asn1 = array( |
||
795 | 'oid:1.3.6.1.4.1', |
||
796 | 'oid:1.3.6.1.4.1.37476.9000', |
||
797 | 'oid:1.3.6.1.4.1.37553.8.8', |
||
798 | 'oid:2.16.276.1', |
||
799 | //TODO?'oid:2.25' |
||
800 | ); |
||
801 | |||
802 | // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels |
||
803 | $no_iri = array( |
||
804 | 'oid:1.2.250.1', |
||
805 | 'oid:1.3.6.1.4.1', |
||
806 | 'oid:1.3.6.1.4.1.37476.9000', |
||
807 | 'oid:1.3.6.1.4.1.37553.8.8', |
||
808 | 'oid:2.16.276.1', |
||
809 | 'oid:2.25' |
||
810 | ); |
||
811 | |||
812 | $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true)); |
||
813 | $accepts_iri = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true)); |
||
814 | |||
815 | $result = OIDplus::db()->query("select o.*, r.ra_name " . |
||
816 | "from ###objects o " . |
||
817 | "left join ###ra r on r.email = o.ra_email " . |
||
818 | "where parent = ? " . |
||
819 | "order by ".OIDplus::db()->natOrder('id'), array($parent)); |
||
692 | daniel-mar | 820 | |
821 | $rows = array(); |
||
822 | while ($row = $result->fetch_object()) { |
||
823 | $obj = OIDplusObject::parse($row->id); |
||
824 | $rows[] = array($obj,$row); |
||
825 | } |
||
635 | daniel-mar | 826 | |
692 | daniel-mar | 827 | $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid'); |
828 | |||
635 | daniel-mar | 829 | $output = ''; |
830 | $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
831 | $output .= '<table class="table table-bordered table-striped">'; |
||
832 | $output .= ' <tr>'; |
||
833 | $output .= ' <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>'; |
||
692 | daniel-mar | 834 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
835 | $output .= ' <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>'; |
||
836 | } |
||
635 | daniel-mar | 837 | if ($parentNS == 'oid') { |
838 | if ($accepts_asn1) $output .= ' <th>'._L('ASN.1 IDs (comma sep.)').'</th>'; |
||
839 | if ($accepts_iri) $output .= ' <th>'._L('IRI IDs (comma sep.)').'</th>'; |
||
840 | } |
||
841 | $output .= ' <th>'._L('RA').'</th>'; |
||
842 | $output .= ' <th>'._L('Comment').'</th>'; |
||
843 | if ($objParent->userHasWriteRights()) { |
||
844 | $output .= ' <th>'._L('Hide').'</th>'; |
||
845 | $output .= ' <th>'._L('Update').'</th>'; |
||
846 | $output .= ' <th>'._L('Delete').'</th>'; |
||
847 | } |
||
848 | $output .= ' <th>'._L('Created').'</th>'; |
||
849 | $output .= ' <th>'._L('Updated').'</th>'; |
||
850 | $output .= ' </tr>'; |
||
851 | |||
852 | foreach ($rows as list($obj,$row)) { |
||
853 | $items_total++; |
||
854 | if (!$obj->userHasReadRights()) { |
||
855 | $items_hidden++; |
||
856 | continue; |
||
857 | } |
||
858 | |||
859 | $show_id = $obj->crudShowId($objParent); |
||
860 | |||
861 | $asn1ids = array(); |
||
862 | $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id)); |
||
863 | while ($row2 = $res2->fetch_array()) { |
||
864 | $asn1ids[] = $row2['name']; |
||
865 | } |
||
866 | |||
867 | $iris = array(); |
||
868 | $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id)); |
||
869 | while ($row2 = $res2->fetch_array()) { |
||
870 | $iris[] = $row2['name']; |
||
871 | } |
||
872 | |||
873 | $date_created = explode(' ', $row->created)[0] == '0000-00-00' ? '' : explode(' ', $row->created)[0]; |
||
874 | $date_updated = explode(' ', $row->updated)[0] == '0000-00-00' ? '' : explode(' ', $row->updated)[0]; |
||
875 | |||
876 | $output .= '<tr>'; |
||
692 | daniel-mar | 877 | $output .= ' <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>'; |
878 | if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) { |
||
879 | // To save space horizontal space, the WEIDs were written below the OIDs |
||
880 | $output .= '<br>'.$obj->getWeidNotation(true); |
||
881 | } |
||
882 | $output .= '</td>'; |
||
883 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
||
884 | $output .= ' <td>'.htmlentities($obj->weidArc()).'</td>'; |
||
885 | } |
||
635 | daniel-mar | 886 | if ($objParent->userHasWriteRights()) { |
887 | if ($parentNS == 'oid') { |
||
888 | if ($accepts_asn1) $output .= ' <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>'; |
||
889 | if ($accepts_iri) $output .= ' <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>'; |
||
890 | } |
||
891 | $output .= ' <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email).'"></td>'; |
||
892 | $output .= ' <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment).'"></td>'; |
||
893 | $output .= ' <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>'; |
||
894 | $output .= ' <td><button type="button" name="update_'.$row->id.'" id="update_'.$row->id.'" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionUpdate('.js_escape($row->id).', '.js_escape($parent).')">'._L('Update').'</button></td>'; |
||
895 | $output .= ' <td><button type="button" name="delete_'.$row->id.'" id="delete_'.$row->id.'" class="btn btn-danger btn-xs delete" onclick="OIDplusPagePublicObjects.crudActionDelete('.js_escape($row->id).', '.js_escape($parent).')">'._L('Delete').'</button></td>'; |
||
896 | $output .= ' <td>'.$date_created.'</td>'; |
||
897 | $output .= ' <td>'.$date_updated.'</td>'; |
||
898 | } else { |
||
899 | if ($parentNS == 'oid') { |
||
692 | daniel-mar | 900 | if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>'; |
901 | if ($iris == '') $iris = '<i>'._L('(none)').'</i>'; |
||
635 | daniel-mar | 902 | $asn1ids_ext = array(); |
903 | foreach ($asn1ids as $asn1id) { |
||
904 | $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>'; |
||
905 | } |
||
906 | if ($accepts_asn1) $output .= ' <td>'.implode(', ', $asn1ids_ext).'</td>'; |
||
907 | if ($accepts_iri) $output .= ' <td>'.implode(', ', $iris).'</td>'; |
||
908 | } |
||
909 | $output .= ' <td><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$row->ra_email)).'>'.htmlentities(empty($row->ra_name) ? str_replace('@','&',$row->ra_email) : $row->ra_name).'</a></td>'; |
||
910 | $output .= ' <td>'.htmlentities($row->comment).'</td>'; |
||
911 | $output .= ' <td>'.$date_created.'</td>'; |
||
912 | $output .= ' <td>'.$date_updated.'</td>'; |
||
913 | } |
||
914 | $output .= '</tr>'; |
||
915 | } |
||
916 | |||
917 | $result = OIDplus::db()->query("select * from ###objects where id = ?", array($parent)); |
||
918 | $parent_ra_email = $result->num_rows() > 0 ? $result->fetch_object()->ra_email : ''; |
||
692 | daniel-mar | 919 | |
920 | // "Create OID" row |
||
635 | daniel-mar | 921 | if ($objParent->userHasWriteRights()) { |
922 | $output .= '<tr>'; |
||
923 | $prefix = is_null($objParent) ? '' : $objParent->crudInsertPrefix(); |
||
692 | daniel-mar | 924 | if ($parentNS == 'guid') { |
925 | if ($objParent->isRoot()) { |
||
926 | // TODO: Should we give ObjectType plugins the ability to define such "Generate" links? (Via feature-interface?) |
||
927 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px"><br><a href="javascript:OIDplusPagePublicObjects.generateRandomGUID(false)">'._L('(Generate random GUID)').'</a></td>'; |
||
928 | } else { |
||
929 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px"></td>'; |
||
930 | } |
||
931 | } |
||
932 | if ($parentNS == 'oid') { |
||
635 | daniel-mar | 933 | // TODO: Idea: Give a class name, e.g. "OID" and then with a oid-specific CSS make the width individual. So, every plugin has more control over the appearance and widths of the input fields |
692 | daniel-mar | 934 | if ($objParent->nodeId() === 'oid:2.25') { |
935 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px"><br><a href="javascript:OIDplusPagePublicObjects.generateRandomUUID(false)">'._L('(Generate random UUID OID)').'</a></td>'; |
||
936 | if ($enable_weid_presentation) $output .= ' <td> </td>'; // For UUID-OIDs, you must generate a valid one. Don't be tempted to create one using the Base36 input! |
||
937 | } else if ($objParent->isRoot()) { |
||
938 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px"><br><a href="javascript:OIDplusPagePublicObjects.generateRandomUUID(true)">'._L('(Generate random UUID OID)').'</a></td>'; |
||
939 | if ($enable_weid_presentation) $output .= ''; // WEID-editor not available for root nodes at the moment. For the moment you need to enter the OID (TODO: Create JavaScript WEID encoder/decoder) |
||
635 | daniel-mar | 940 | } else { |
692 | daniel-mar | 941 | if ($enable_weid_presentation) { |
942 | $output .= ' <td>'.$prefix.' <input oninput="OIDplusPagePublicObjects.frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px"></td>'; |
||
943 | $output .= ' <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>'; |
||
944 | } else { |
||
945 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px"></td>'; |
||
946 | } |
||
635 | daniel-mar | 947 | } |
948 | } else { |
||
684 | daniel-mar | 949 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px"></td>'; |
635 | daniel-mar | 950 | } |
951 | if ($accepts_asn1) $output .= ' <td><input type="text" id="asn1ids" value=""></td>'; |
||
952 | if ($accepts_iri) $output .= ' <td><input type="text" id="iris" value=""></td>'; |
||
953 | $output .= ' <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email).'"></td>'; |
||
954 | $output .= ' <td><input type="text" id="comment" value=""></td>'; |
||
955 | $output .= ' <td><input type="checkbox" id="hide"></td>'; |
||
956 | $output .= ' <td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionInsert('.js_escape($parent).')">'._L('Insert').'</button></td>'; |
||
957 | $output .= ' <td></td>'; |
||
958 | $output .= ' <td></td>'; |
||
959 | $output .= ' <td></td>'; |
||
960 | $output .= '</tr>'; |
||
961 | } else { |
||
962 | if ($items_total-$items_hidden == 0) { |
||
963 | $cols = ($parentNS == 'oid') ? 7 : 5; |
||
692 | daniel-mar | 964 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
965 | $cols++; |
||
966 | } |
||
635 | daniel-mar | 967 | $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>'; |
968 | } |
||
969 | } |
||
970 | |||
971 | $output .= '</table>'; |
||
972 | $output .= '</div></div>'; |
||
973 | |||
974 | if ($items_hidden == 1) { |
||
975 | $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
976 | } else if ($items_hidden > 1) { |
||
977 | $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
978 | } |
||
979 | |||
980 | return $output; |
||
981 | } |
||
982 | |||
983 | protected static function objDescription($html) { |
||
984 | // We allow HTML, but no hacking |
||
985 | $html = anti_xss($html); |
||
986 | |||
987 | return trim_br($html); |
||
988 | } |
||
989 | |||
990 | // 'quickbars' added 11 July 2019: Disabled because of two problems: |
||
991 | // 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus |
||
992 | // 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit |
||
993 | // 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core. |
||
994 | // 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar) |
||
636 | daniel-mar | 995 | // 'legacyoutput' added 24 September 2021, because it is marked as deprecated |
671 | daniel-mar | 996 | // 'spellchecker' added 6 October 2021, because it is marked as deprecated and marked for removal in TinyMCE 6.0 |
997 | public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker'); |
||
635 | daniel-mar | 998 | |
999 | protected static function showMCE($name, $content) { |
||
1000 | $mce_plugins = array(); |
||
1001 | foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */ |
||
1002 | $mce_plugins[] = basename($m); |
||
1003 | } |
||
1004 | |||
1005 | foreach (self::$exclude_tinymce_plugins as $exclude) { |
||
1006 | $index = array_search($exclude, $mce_plugins); |
||
1007 | if ($index !== false) unset($mce_plugins[$index]); |
||
1008 | } |
||
1009 | |||
1010 | $oidplusLang = OIDplus::getCurrentLang(); |
||
1011 | |||
1012 | $langCandidates = array( |
||
1013 | strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE |
||
1014 | strtolower(substr($oidplusLang,0,2)) // de |
||
1015 | ); |
||
1016 | $tinyMCELang = ''; |
||
1017 | foreach ($langCandidates as $candidate) { |
||
1018 | if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) { |
||
1019 | $tinyMCELang = $candidate; |
||
1020 | break; |
||
1021 | } |
||
1022 | } |
||
1023 | |||
1024 | $out = '<script> |
||
1025 | tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce"; |
||
1026 | tinymce.init({ |
||
1027 | document_base_url: "'.OIDplus::webpath().'", |
||
1028 | selector: "#'.$name.'", |
||
1029 | height: 200, |
||
1030 | statusbar: false, |
||
1031 | // menubar:false, |
||
1032 | // toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect", |
||
1033 | toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect", |
||
1034 | plugins: "'.implode(' ', $mce_plugins).'", |
||
1035 | mobile: { |
||
1036 | theme: "mobile", |
||
1037 | toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect", |
||
1038 | plugins: "'.implode(' ', $mce_plugins).'" |
||
1039 | } |
||
1040 | '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').' |
||
1041 | '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath().'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').' |
||
1042 | }); |
||
1043 | |||
1044 | pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]); |
||
1045 | pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]); |
||
1046 | </script>'; |
||
1047 | |||
1048 | $content = htmlentities($content); // For some reason, if we want to display the text "<xyz>" in TinyMCE, we need to double-encode things! < will not be accepted, we need &lt; ... why? |
||
1049 | |||
1050 | $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>'; |
||
1051 | |||
1052 | return $out; |
||
1053 | } |
||
1054 | |||
1055 | public function implementsFeature($id) { |
||
1056 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested() |
||
1057 | return false; |
||
1058 | } |
||
1059 | |||
1060 | public function oobeRequested(): bool { |
||
1061 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.1 |
||
1062 | |||
1063 | return OIDplus::config()->getValue('oobe_objects_done') == '0'; |
||
1064 | } |
||
1065 | |||
1066 | public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ { |
||
1067 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.1 |
||
1068 | |||
1069 | echo '<p><u>'._L('Step %1: Enable/Disable object type plugins',$step).'</u></p>'; |
||
1070 | echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>'; |
||
1071 | |||
1072 | $enabled_ary = array(); |
||
1073 | |||
1074 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
1075 | echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"'; |
||
1076 | if (isset($_REQUEST['sent'])) { |
||
1077 | if (isset($_REQUEST['enable_ot_'.$ot::ns()])) { |
||
1078 | echo ' checked'; |
||
1079 | $enabled_ary[] = $ot::ns(); |
||
1080 | } |
||
1081 | } else { |
||
1082 | echo ' checked'; |
||
1083 | } |
||
1084 | echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>'; |
||
1085 | } |
||
1086 | |||
1087 | foreach (OIDplus::getDisabledObjectTypes() as $ot) { |
||
1088 | echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"'; |
||
1089 | if (isset($_REQUEST['sent'])) { |
||
1090 | if (isset($_REQUEST['enable_ot_'.$ot::ns()])) { |
||
1091 | echo ' checked'; |
||
1092 | $enabled_ary[] = $ot::ns(); |
||
1093 | } |
||
1094 | } else { |
||
1095 | echo ''; // <-- difference |
||
1096 | } |
||
1097 | echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>'; |
||
1098 | } |
||
1099 | |||
1100 | $msg = ''; |
||
1101 | if ($do_edits) { |
||
1102 | try { |
||
1103 | OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary)); |
||
1104 | OIDplus::config()->setValue('oobe_objects_done', '1'); |
||
1105 | } catch (Exception $e) { |
||
1106 | $msg = $e->getMessage(); |
||
1107 | $errors_happened = true; |
||
1108 | } |
||
1109 | } |
||
1110 | |||
1111 | echo ' <font color="red"><b>'.$msg.'</b></font>'; |
||
1112 | } |
||
1113 | |||
666 | daniel-mar | 1114 | } |