Rev 1137 | Rev 1141 | 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 |
||
1086 | daniel-mar | 5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
635 | daniel-mar | 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 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
635 | daniel-mar | 21 | |
1086 | daniel-mar | 22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
||
24 | // phpcs:enable PSR1.Files.SideEffects |
||
25 | |||
1131 | daniel-mar | 26 | class OIDplusPagePublicObjects extends OIDplusPagePluginPublic |
27 | implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1, /* oobeEntry, oobeRequested */ |
||
28 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 /* getNotifications */ |
||
29 | // Important: Do NOT implement INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7, because our getAlternativesForQuery() is the one that calls others! |
||
30 | { |
||
635 | daniel-mar | 31 | |
1116 | daniel-mar | 32 | /** |
1130 | daniel-mar | 33 | * @param string|OIDplusObject $ot |
1116 | daniel-mar | 34 | * @return string|null |
35 | */ |
||
36 | private function get_treeicon_root($ot)/*: ?string*/ { |
||
1127 | daniel-mar | 37 | $root = $ot::parse($ot::root()); |
38 | if (!$root) return null; |
||
39 | return $root->getIcon(); |
||
635 | daniel-mar | 40 | } |
41 | |||
1116 | daniel-mar | 42 | /** |
1130 | daniel-mar | 43 | * @param string $id |
44 | * @param string $old_ra |
||
45 | * @param string $new_ra |
||
1116 | daniel-mar | 46 | * @return void |
47 | * @throws OIDplusConfigInitializationException |
||
48 | * @throws OIDplusException |
||
49 | */ |
||
1130 | daniel-mar | 50 | private function ra_change_rec(string $id, string $old_ra, string $new_ra) { |
635 | daniel-mar | 51 | 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)); |
978 | daniel-mar | 52 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 53 | |
54 | $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra)); |
||
55 | while ($row = $res->fetch_array()) { |
||
56 | $this->ra_change_rec($row['id'], $old_ra, $new_ra); |
||
57 | } |
||
58 | } |
||
59 | |||
1116 | daniel-mar | 60 | /** |
61 | * @param string $actionID |
||
62 | * @param array $params |
||
63 | * @return array|int[] |
||
64 | * @throws OIDplusConfigInitializationException |
||
65 | * @throws OIDplusException |
||
66 | */ |
||
67 | public function action(string $actionID, array $params): array { |
||
635 | daniel-mar | 68 | |
69 | // Action: Delete |
||
70 | // Method: POST |
||
71 | // Parameters: id |
||
72 | // Outputs: <0 Error, =0 Success |
||
73 | if ($actionID == 'Delete') { |
||
74 | _CheckParamExists($params, 'id'); |
||
75 | $id = $params['id']; |
||
76 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 77 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id)); |
635 | daniel-mar | 78 | |
977 | daniel-mar | 79 | if (!OIDplusObject::exists($id)) { |
635 | daniel-mar | 80 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
81 | } |
||
82 | |||
83 | // Check if permitted |
||
84 | if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.')); |
||
85 | |||
1005 | daniel-mar | 86 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 87 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
88 | $plugin->beforeObjectDelete($id); |
||
635 | daniel-mar | 89 | } |
90 | } |
||
91 | |||
92 | OIDplus::logger()->log("[WARN]OID($id)+[?WARN/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "Object '$id' (recursively) deleted"); |
||
93 | OIDplus::logger()->log("[CRIT]OIDRA($id)!", "Lost ownership of object '$id' because it was deleted"); |
||
94 | |||
95 | if ($parentObj = $obj->getParent()) { |
||
96 | $parent_oid = $parentObj->nodeId(); |
||
97 | OIDplus::logger()->log("[WARN]OID($parent_oid)", "Object '$id' (recursively) deleted"); |
||
98 | } |
||
99 | |||
100 | // Delete object |
||
101 | OIDplus::db()->query("delete from ###objects where id = ?", array($id)); |
||
978 | daniel-mar | 102 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 103 | |
104 | // Delete orphan stuff |
||
105 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
106 | do { |
||
107 | $res = OIDplus::db()->query("select tchild.id from ###objects tchild " . |
||
108 | "left join ###objects tparent on tparent.id = tchild.parent " . |
||
109 | "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%')); |
||
790 | daniel-mar | 110 | if (!$res->any()) break; |
635 | daniel-mar | 111 | |
112 | while ($row = $res->fetch_array()) { |
||
113 | $id_to_delete = $row['id']; |
||
114 | 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"); |
||
115 | OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete)); |
||
978 | daniel-mar | 116 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 117 | } |
118 | } while (true); |
||
119 | } |
||
120 | OIDplus::db()->query("delete from ###asn1id where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false)); |
||
121 | OIDplus::db()->query("delete from ###iri where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false)); |
||
122 | |||
1005 | daniel-mar | 123 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 124 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
125 | $plugin->afterObjectDelete($id); |
||
635 | daniel-mar | 126 | } |
127 | } |
||
128 | |||
129 | return array("status" => 0); |
||
130 | } |
||
131 | |||
132 | // Action: Update |
||
133 | // Method: POST |
||
134 | // Parameters: id, ra_email, comment, iris, asn1ids, confidential |
||
135 | // Outputs: <0 Error, =0 Success, with following bitfields for further information: |
||
136 | // 1 = RA is not registered |
||
137 | // 2 = RA is not registered, but it cannot be invited |
||
138 | // 4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset |
||
139 | else if ($actionID == 'Update') { |
||
140 | _CheckParamExists($params, 'id'); |
||
141 | $id = $params['id']; |
||
142 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 143 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id)); |
635 | daniel-mar | 144 | |
977 | daniel-mar | 145 | if (!OIDplusObject::exists($id)) { |
635 | daniel-mar | 146 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
147 | } |
||
148 | |||
149 | // Check if permitted |
||
150 | if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.')); |
||
151 | |||
1005 | daniel-mar | 152 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 153 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
154 | $plugin->beforeObjectUpdateSuperior($id, $params); |
||
635 | daniel-mar | 155 | } |
156 | } |
||
157 | |||
158 | // First, do a simulation for ASN.1 IDs and IRIs to check if there are any problems (then an Exception will be thrown) |
||
159 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 160 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 161 | if (!$obj->isWellKnown()) { |
162 | if (isset($params['iris'])) { |
||
163 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
164 | $ids = array_map('trim',$ids); |
||
165 | $obj->replaceIris($ids, true); |
||
166 | } |
||
167 | |||
168 | if (isset($params['asn1ids'])) { |
||
169 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
170 | $ids = array_map('trim',$ids); |
||
171 | $obj->replaceAsn1Ids($ids, true); |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | |||
176 | // RA E-Mail change |
||
177 | if (isset($params['ra_email'])) { |
||
178 | // Validate RA email address |
||
1137 | daniel-mar | 179 | $new_ra = $params['ra_email'] ?? ''; |
635 | daniel-mar | 180 | if ($obj::ns() == 'oid') { |
1116 | daniel-mar | 181 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 182 | if ($obj->isWellKnown()) { |
183 | $new_ra = ''; |
||
184 | } |
||
185 | } |
||
186 | if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) { |
||
187 | throw new OIDplusException(_L('Invalid RA email address')); |
||
188 | } |
||
189 | |||
190 | // Change RA recursively |
||
1130 | daniel-mar | 191 | $current_ra = $obj->getRaMail() ?? ''; |
977 | daniel-mar | 192 | if ($new_ra != $current_ra) { |
193 | OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "RA of object '$id' changed from '$current_ra' to '$new_ra'"); |
||
194 | OIDplus::logger()->log("[WARN]RA($current_ra)!", "Lost ownership of object '$id' due to RA transfer of superior RA / admin."); |
||
195 | OIDplus::logger()->log("[INFO]RA($new_ra)!", "Gained ownership of object '$id' due to RA transfer of superior RA / admin."); |
||
196 | if ($parentObj = $obj->getParent()) { |
||
197 | $parent_oid = $parentObj->nodeId(); |
||
198 | OIDplus::logger()->log("[INFO]OID($parent_oid)", "RA of object '$id' changed from '$current_ra' to '$new_ra'"); |
||
635 | daniel-mar | 199 | } |
977 | daniel-mar | 200 | $this->ra_change_rec($id, $current_ra, $new_ra); // Recursively change inherited RAs |
635 | daniel-mar | 201 | } |
202 | } |
||
203 | |||
204 | // Log if confidentially flag was changed |
||
205 | 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! |
||
206 | if ($parentObj = $obj->getParent()) { |
||
207 | $parent_oid = $parentObj->nodeId(); |
||
208 | OIDplus::logger()->log("[INFO]OID($parent_oid)", "Identifiers/Confidential flag of object '$id' updated"); // TODO: Check if they were ACTUALLY updated! |
||
209 | } |
||
210 | |||
211 | // Replace ASN.1 IDs und IRIs |
||
212 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 213 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 214 | if (!$obj->isWellKnown()) { |
215 | if (isset($params['iris'])) { |
||
216 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
217 | $ids = array_map('trim',$ids); |
||
218 | $obj->replaceIris($ids, false); |
||
219 | } |
||
220 | |||
221 | if (isset($params['asn1ids'])) { |
||
222 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
223 | $ids = array_map('trim',$ids); |
||
224 | $obj->replaceAsn1Ids($ids, false); |
||
225 | } |
||
226 | } |
||
227 | |||
228 | // TODO: Check if any identifiers have been actually changed, |
||
229 | // and log it to OID($id), OID($parent), ... (see above) |
||
230 | } |
||
231 | |||
232 | if (isset($params['confidential'])) { |
||
233 | $confidential = $params['confidential'] == 'true'; |
||
234 | OIDplus::db()->query("UPDATE ###objects SET confidential = ? WHERE id = ?", array($confidential, $id)); |
||
978 | daniel-mar | 235 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 236 | } |
237 | |||
238 | if (isset($params['comment'])) { |
||
239 | $comment = $params['comment']; |
||
240 | OIDplus::db()->query("UPDATE ###objects SET comment = ? WHERE id = ?", array($comment, $id)); |
||
978 | daniel-mar | 241 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 242 | } |
243 | |||
244 | OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id)); |
||
978 | daniel-mar | 245 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 246 | |
247 | $status = 0; |
||
248 | |||
249 | if (!empty($new_ra)) { |
||
250 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra)); |
||
251 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
||
790 | daniel-mar | 252 | if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2; |
635 | daniel-mar | 253 | } |
254 | |||
255 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 256 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 257 | if ($obj->isWellKnown()) { |
258 | $status += 4; |
||
259 | } |
||
260 | } |
||
261 | |||
1005 | daniel-mar | 262 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 263 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
264 | $plugin->afterObjectUpdateSuperior($id, $params); |
||
635 | daniel-mar | 265 | } |
266 | } |
||
267 | |||
268 | return array("status" => $status); |
||
269 | } |
||
270 | |||
271 | // Action: Update2 |
||
272 | // Method: POST |
||
273 | // Parameters: id, title, description |
||
274 | // Outputs: <0 Error, =0 Success |
||
275 | else if ($actionID == 'Update2') { |
||
276 | _CheckParamExists($params, 'id'); |
||
277 | $id = $params['id']; |
||
278 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 279 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE2',$id)); |
635 | daniel-mar | 280 | |
977 | daniel-mar | 281 | if (!OIDplusObject::exists($id)) { |
635 | daniel-mar | 282 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
283 | } |
||
284 | |||
285 | // Check if allowed |
||
286 | if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.')); |
||
287 | |||
1005 | daniel-mar | 288 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 289 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
290 | $plugin->beforeObjectUpdateSelf($id, $params); |
||
635 | daniel-mar | 291 | } |
292 | } |
||
293 | |||
294 | OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]OIDRA($id)?/[?INFO/!OK]A?", "Title/Description of object '$id' updated"); |
||
295 | |||
296 | if (isset($params['title'])) { |
||
297 | $title = $params['title']; |
||
298 | OIDplus::db()->query("UPDATE ###objects SET title = ? WHERE id = ?", array($title, $id)); |
||
978 | daniel-mar | 299 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 300 | } |
301 | |||
302 | if (isset($params['description'])) { |
||
303 | $description = $params['description']; |
||
304 | OIDplus::db()->query("UPDATE ###objects SET description = ? WHERE id = ?", array($description, $id)); |
||
978 | daniel-mar | 305 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 306 | } |
307 | |||
308 | OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id)); |
||
978 | daniel-mar | 309 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 310 | |
1005 | daniel-mar | 311 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 312 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
313 | $plugin->afterObjectUpdateSelf($id, $params); |
||
635 | daniel-mar | 314 | } |
315 | } |
||
316 | |||
317 | return array("status" => 0); |
||
318 | } |
||
319 | |||
320 | // Generate UUID |
||
321 | else if ($actionID == 'generate_uuid') { |
||
322 | $uuid = gen_uuid(); |
||
323 | if (!$uuid) return array("status" => 1); |
||
324 | return array( |
||
325 | "status" => 0, |
||
326 | "uuid" => $uuid, |
||
327 | "intval" => substr(uuid_to_oid($uuid),strlen('2.25.')) |
||
328 | ); |
||
329 | } |
||
330 | |||
331 | // Action: Insert |
||
332 | // Method: POST |
||
333 | // Parameters: parent, id, ra_email, confidential, iris, asn1ids |
||
334 | // Outputs: status=<0 Error, =0 Success, with following bitfields for further information: |
||
335 | // 1 = RA is not registered |
||
336 | // 2 = RA is not registered, but it cannot be invited |
||
337 | // 4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset |
||
338 | else if ($actionID == 'Insert') { |
||
339 | // Check if you have write rights on the parent (to create a new object) |
||
340 | _CheckParamExists($params, 'parent'); |
||
341 | $objParent = OIDplusObject::parse($params['parent']); |
||
1116 | daniel-mar | 342 | if (!$objParent) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent'])); |
635 | daniel-mar | 343 | |
977 | daniel-mar | 344 | if (!$objParent->isRoot()) { |
345 | $idParent = $objParent->nodeId(); |
||
346 | if (!OIDplusObject::exists($idParent)) { |
||
347 | throw new OIDplusException(_L('Parent object %1 does not exist',$idParent)); |
||
348 | } |
||
635 | daniel-mar | 349 | } |
350 | |||
351 | if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.')); |
||
352 | |||
353 | // Check if the ID is valid |
||
354 | _CheckParamExists($params, 'id'); |
||
355 | if ($params['id'] == '') throw new OIDplusException(_L('ID may not be empty')); |
||
356 | |||
772 | daniel-mar | 357 | // For the root objects, let the user also enter a WEID |
358 | if ($objParent::ns() == 'oid') { |
||
1116 | daniel-mar | 359 | assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
772 | daniel-mar | 360 | if (strtolower(substr(trim($params['id']),0,5)) === 'weid:') { |
361 | if ($objParent->isRoot()) { |
||
1050 | daniel-mar | 362 | $params['id'] = \Frdl\Weid\WeidOidConverter::weid2oid($params['id']); |
772 | daniel-mar | 363 | if ($params['id'] === false) { |
364 | throw new OIDplusException(_L('Invalid WEID')); |
||
365 | } |
||
366 | } else { |
||
367 | throw new OIDplusException(_L('You can use the WEID syntax only at your object tree root.')); |
||
368 | } |
||
369 | } |
||
370 | } |
||
371 | |||
635 | daniel-mar | 372 | // Determine absolute OID name |
373 | // Note: At addString() and parse(), the syntax of the ID will be checked |
||
374 | $id = $objParent->addString($params['id']); |
||
375 | |||
376 | // Check, if the OID exists |
||
977 | daniel-mar | 377 | if (OIDplusObject::exists($id)) { |
635 | daniel-mar | 378 | throw new OIDplusException(_L('Object %1 already exists!',$id)); |
379 | } |
||
380 | |||
381 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 382 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id)); |
635 | daniel-mar | 383 | |
1005 | daniel-mar | 384 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 385 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
386 | $plugin->beforeObjectInsert($id, $params); |
||
635 | daniel-mar | 387 | } |
388 | } |
||
389 | |||
390 | // First simulate if there are any problems of ASN.1 IDs und IRIs |
||
391 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 392 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 393 | if (!$obj->isWellKnown()) { |
394 | if (isset($params['iris'])) { |
||
395 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
396 | $ids = array_map('trim',$ids); |
||
397 | $obj->replaceIris($ids, true); |
||
398 | } |
||
399 | |||
400 | if (isset($params['asn1ids'])) { |
||
401 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
402 | $ids = array_map('trim',$ids); |
||
403 | $obj->replaceAsn1Ids($ids, true); |
||
404 | } |
||
405 | } |
||
406 | } |
||
407 | |||
408 | // Apply superior RA change |
||
409 | $parent = $params['parent']; |
||
1130 | daniel-mar | 410 | $ra_email = $params['ra_email'] ?? ''; |
635 | daniel-mar | 411 | if ($obj::ns() == 'oid') { |
1116 | daniel-mar | 412 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 413 | if ($obj->isWellKnown()) { |
414 | $ra_email = ''; |
||
415 | } |
||
416 | } |
||
417 | if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) { |
||
418 | throw new OIDplusException(_L('Invalid RA email address')); |
||
419 | } |
||
420 | |||
421 | 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'"; |
||
422 | if (!empty($ra_email)) { |
||
423 | OIDplus::logger()->log("[INFO]RA($ra_email)!", "Gained ownership of newly created object '$id'"); |
||
424 | } |
||
425 | |||
1130 | daniel-mar | 426 | $confidential = isset($params['confidential']) && $params['confidential'] == 'true'; |
427 | $comment = $params['comment'] ?? ''; |
||
635 | daniel-mar | 428 | $title = ''; |
429 | $description = ''; |
||
430 | |||
431 | if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) { |
||
432 | $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH'); |
||
433 | throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen)); |
||
434 | } |
||
435 | |||
436 | 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)); |
||
978 | daniel-mar | 437 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 438 | |
439 | // Set ASN.1 IDs und IRIs |
||
440 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 441 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 442 | if (!$obj->isWellKnown()) { |
443 | if (isset($params['iris'])) { |
||
444 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
445 | $ids = array_map('trim',$ids); |
||
446 | $obj->replaceIris($ids, false); |
||
447 | } |
||
448 | |||
449 | if (isset($params['asn1ids'])) { |
||
450 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
451 | $ids = array_map('trim',$ids); |
||
452 | $obj->replaceAsn1Ids($ids, false); |
||
453 | } |
||
454 | } |
||
455 | } |
||
456 | |||
457 | $status = 0; |
||
458 | |||
459 | if (!empty($ra_email)) { |
||
460 | // Do we need to notify that the RA does not exist? |
||
461 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email)); |
||
462 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
||
790 | daniel-mar | 463 | if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2; |
635 | daniel-mar | 464 | } |
465 | |||
466 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 467 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 468 | if ($obj->isWellKnown()) { |
469 | $status += 4; |
||
470 | } |
||
471 | } |
||
472 | |||
1005 | daniel-mar | 473 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 474 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
475 | $plugin->afterObjectInsert($id, $params); |
||
635 | daniel-mar | 476 | } |
477 | } |
||
478 | |||
479 | return array( |
||
480 | "status" => $status, |
||
481 | "inserted_id" => $id |
||
482 | ); |
||
483 | } else { |
||
1116 | daniel-mar | 484 | return parent::action($actionID, $params); |
635 | daniel-mar | 485 | } |
486 | } |
||
487 | |||
1116 | daniel-mar | 488 | /** |
489 | * @param bool $html |
||
490 | * @return void |
||
491 | * @throws OIDplusException |
||
492 | */ |
||
493 | public function init(bool $html=true) { |
||
635 | daniel-mar | 494 | OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {}); |
693 | daniel-mar | 495 | OIDplus::config()->prepareConfigKey('oid_grid_show_weid', 'Show WEID/Base36 column in CRUD grid of OIDs?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
496 | if (!is_numeric($value) || ($value < 0) || ($value > 1)) { |
||
497 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
||
498 | } |
||
499 | }); |
||
635 | daniel-mar | 500 | } |
501 | |||
1116 | daniel-mar | 502 | /** |
1130 | daniel-mar | 503 | * @param string $id |
504 | * @param array $out |
||
1116 | daniel-mar | 505 | * @return array|false |
506 | * @throws OIDplusException |
||
507 | */ |
||
1130 | daniel-mar | 508 | private function tryObject(string $id, array &$out) { |
951 | daniel-mar | 509 | $parent = null; |
510 | $res = null; |
||
511 | $row = null; |
||
954 | daniel-mar | 512 | $obj = OIDplusObject::parse($id); |
1116 | daniel-mar | 513 | if (!$obj) return false; |
954 | daniel-mar | 514 | if ($obj->isRoot()) { |
515 | $obj->getContentPage($out['title'], $out['text'], $out['icon']); |
||
977 | daniel-mar | 516 | $objParent = null; // $obj->getParent(); |
954 | daniel-mar | 517 | } else { |
977 | daniel-mar | 518 | $obj = OIDplusObject::findFitting($id); // this time, the object will be found, not just the object type |
519 | if (!$obj) { |
||
954 | daniel-mar | 520 | return false; |
521 | } else { |
||
522 | $obj->getContentPage($out['title'], $out['text'], $out['icon']); |
||
523 | if (empty($out['title'])) $out['title'] = explode(':',$obj->nodeId(),2)[1]; |
||
977 | daniel-mar | 524 | $objParent = $obj->getParent(); |
953 | daniel-mar | 525 | } |
951 | daniel-mar | 526 | } |
977 | daniel-mar | 527 | return array($id, $obj, $objParent); |
951 | daniel-mar | 528 | } |
529 | |||
1116 | daniel-mar | 530 | /** |
1130 | daniel-mar | 531 | * @param string $id |
1116 | daniel-mar | 532 | * @return array |
533 | */ |
||
1130 | daniel-mar | 534 | public static function getAlternativesForQuery(string $id): array { |
1131 | daniel-mar | 535 | // Attention: This is NOT an implementation of INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7! |
536 | // This is the function that calls getAlternativesForQuery() of every plugin that implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7 |
||
968 | daniel-mar | 537 | |
951 | daniel-mar | 538 | // e.g. used for "Reverse Alt Id" |
539 | $alternatives = array(); |
||
1005 | daniel-mar | 540 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 541 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7) { |
542 | $tmp = $plugin->getAlternativesForQuery($id); |
||
951 | daniel-mar | 543 | if (is_array($tmp)) { |
544 | $alternatives = array_merge($tmp, $alternatives); |
||
545 | } |
||
546 | } |
||
547 | } |
||
968 | daniel-mar | 548 | |
549 | // If something is more than one time, remove it |
||
951 | daniel-mar | 550 | $alternatives = array_unique($alternatives); |
968 | daniel-mar | 551 | |
552 | // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID |
||
553 | $alternatives_tmp = array(); |
||
554 | foreach ($alternatives as $alt) { |
||
555 | if ($alt !== $id) $alternatives_tmp[] = $alt; |
||
556 | } |
||
1130 | daniel-mar | 557 | return $alternatives_tmp; |
951 | daniel-mar | 558 | } |
559 | |||
1116 | daniel-mar | 560 | /** |
561 | * @param string $id |
||
562 | * @param array $out |
||
563 | * @param bool $handled |
||
564 | * @return void |
||
565 | * @throws OIDplusConfigInitializationException |
||
566 | * @throws OIDplusException |
||
567 | */ |
||
568 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 569 | if ($id === 'oidplus:system') { |
570 | $handled = true; |
||
571 | |||
572 | $out['title'] = OIDplus::config()->getValue('system_title'); |
||
801 | daniel-mar | 573 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png'; |
635 | daniel-mar | 574 | |
575 | if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) { |
||
576 | $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html'); |
||
577 | } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) { |
||
578 | $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html'); |
||
579 | } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) { |
||
580 | $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html'); |
||
581 | } else if (file_exists(__DIR__ . '/welcome.html')) { |
||
582 | $cont = file_get_contents(__DIR__ . '/welcome.html'); |
||
583 | } else { |
||
584 | $cont = ''; |
||
585 | } |
||
586 | |||
587 | list($html, $js, $css) = extractHtmlContents($cont); |
||
588 | $cont = ''; |
||
589 | if (!empty($js)) $cont .= "<script>\n$js\n</script>"; |
||
590 | if (!empty($css)) $cont .= "<style>\n$css\n</style>"; |
||
821 | daniel-mar | 591 | $cont .= stripHtmlComments($html); |
635 | daniel-mar | 592 | |
593 | $out['text'] = $cont; |
||
594 | |||
595 | if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) { |
||
596 | $tmp = '<ul>'; |
||
597 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
598 | $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>'; |
||
599 | } |
||
600 | $tmp .= '</ul>'; |
||
601 | $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']); |
||
602 | } |
||
603 | } |
||
604 | |||
957 | daniel-mar | 605 | // Never answer to an object type that is called 'oidplus:', |
606 | // otherwise, an object type plugin could break the whole system! |
||
607 | else if ((strpos($id,':') !== false) && (!str_starts_with($id,'oidplus:'))) { |
||
635 | daniel-mar | 608 | |
955 | daniel-mar | 609 | // --- Try to find the object or an alternative |
635 | daniel-mar | 610 | |
951 | daniel-mar | 611 | $test = $this->tryObject($id, $out); |
612 | if ($test === false) { |
||
955 | daniel-mar | 613 | // try to find an alternative |
952 | daniel-mar | 614 | $alternatives = $this->getAlternativesForQuery($id); |
951 | daniel-mar | 615 | foreach ($alternatives as $alternative) { |
616 | $test = $this->tryObject($alternative, $out); |
||
955 | daniel-mar | 617 | if ($test !== false) break; // found something |
635 | daniel-mar | 618 | } |
619 | } |
||
955 | daniel-mar | 620 | if ($test !== false) { |
977 | daniel-mar | 621 | list($id, $obj, $objParent) = $test; |
1132 | daniel-mar | 622 | } else { |
623 | $objParent = null; // to avoid warnings |
||
955 | daniel-mar | 624 | } |
625 | |||
626 | // --- If the object type is disabled or not an object at all (e.g. "oidplus:"), then $handled=false |
||
627 | // If the object type is enabled but object not found, $handled=true |
||
628 | |||
970 | daniel-mar | 629 | $obj = OIDplusObject::parse($id); |
955 | daniel-mar | 630 | |
951 | daniel-mar | 631 | if ($test === false) { |
1116 | daniel-mar | 632 | if (!$obj) { |
955 | daniel-mar | 633 | // Object type disabled or not known (e.g. ObjectType "oidplus:"). |
634 | $handled = false; |
||
635 | return; |
||
636 | } else { |
||
637 | // Object type enabled but identifier not in database |
||
638 | $handled = true; |
||
639 | if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box |
||
640 | http_response_code(404); |
||
641 | } |
||
642 | $out['title'] = _L('Object not found'); |
||
643 | $out['icon'] = 'img/error.png'; |
||
644 | $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>'); |
||
645 | return; |
||
646 | } |
||
647 | } else { |
||
648 | $handled = true; |
||
649 | } |
||
650 | |||
651 | unset($test); |
||
652 | |||
653 | // --- If found, do we have read rights? |
||
654 | |||
655 | if (!$obj->userHasReadRights()) { |
||
843 | daniel-mar | 656 | if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box |
955 | daniel-mar | 657 | http_response_code(403); |
843 | daniel-mar | 658 | } |
955 | daniel-mar | 659 | $out['title'] = _L('Access denied'); |
800 | daniel-mar | 660 | $out['icon'] = 'img/error.png'; |
955 | daniel-mar | 661 | $out['text'] = '<p>'._L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')).'</p>'; |
635 | daniel-mar | 662 | return; |
663 | } |
||
664 | |||
665 | // --- |
||
666 | |||
977 | daniel-mar | 667 | if ($objParent) { |
668 | if ($objParent->isRoot()) { |
||
669 | $parent_link_text = $objParent->objectTypeTitle(); |
||
670 | $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->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']; |
||
635 | daniel-mar | 671 | } else { |
977 | daniel-mar | 672 | $parent_title = $objParent->getTitle(); |
673 | if (empty($parent_title) && ($objParent->ns() == 'oid')) { |
||
1116 | daniel-mar | 674 | assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
977 | daniel-mar | 675 | // If not title is available, then use an ASN.1 identifier |
676 | $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($objParent->nodeId())); |
||
677 | if ($res_asn->any()) { |
||
678 | $row_asn = $res_asn->fetch_array(); |
||
679 | $parent_title = $row_asn['name']; // TODO: multiple ASN1 ids? |
||
635 | daniel-mar | 680 | } |
977 | daniel-mar | 681 | } |
635 | daniel-mar | 682 | |
977 | daniel-mar | 683 | $parent_link_text = empty($parent_title) ? explode(':',$objParent->nodeId())[1] : $parent_title.' ('.explode(':',$objParent->nodeId())[1].')'; |
635 | daniel-mar | 684 | |
977 | daniel-mar | 685 | $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->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']; |
635 | daniel-mar | 686 | } |
687 | } else { |
||
688 | $parent_link_text = _L('Go back to front page'); |
||
689 | $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']; |
||
690 | } |
||
691 | |||
692 | // --- |
||
693 | |||
977 | daniel-mar | 694 | if ($obj) { |
695 | $title = $obj->getTitle(); |
||
696 | $description = $obj->getDescription(); |
||
999 | daniel-mar | 697 | if (empty(strip_tags($description)) && (stripos($description,'<img') === false)) { |
977 | daniel-mar | 698 | if (empty($title)) { |
635 | daniel-mar | 699 | $desc = '<p><i>'._L('No description for this object available').'</i></p>'; |
700 | } else { |
||
977 | daniel-mar | 701 | $desc = $title; |
635 | daniel-mar | 702 | } |
703 | } else { |
||
977 | daniel-mar | 704 | $desc = self::objDescription($description); |
635 | daniel-mar | 705 | } |
706 | |||
707 | if ($obj->userHasWriteRights()) { |
||
708 | $rand = ++self::$crudCounter; |
||
709 | $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>'; |
||
710 | $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">'; |
||
977 | daniel-mar | 711 | $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($title).'"><br><br>'._L('Description').':<br>'; |
712 | $desc .= self::showMCE('description', $description); |
||
635 | daniel-mar | 713 | $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>'; |
714 | $desc .= '</div>'; |
||
715 | $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>'; |
||
716 | } |
||
717 | } else { |
||
718 | $desc = ''; |
||
719 | } |
||
720 | |||
721 | // --- |
||
722 | |||
723 | if (strpos($out['text'], '%%DESC%%') !== false) |
||
724 | $out['text'] = str_replace('%%DESC%%', $desc, $out['text']); |
||
725 | if (strpos($out['text'], '%%CRUD%%') !== false) |
||
856 | daniel-mar | 726 | $out['text'] = str_replace('%%CRUD%%', self::showCrud($obj->nodeId()), $out['text']); |
635 | daniel-mar | 727 | if (strpos($out['text'], '%%RA_INFO%%') !== false) |
977 | daniel-mar | 728 | $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($obj->getRaMail()), $out['text']); |
635 | daniel-mar | 729 | |
730 | $alt_ids = $obj->getAltIds(); |
||
731 | if (count($alt_ids) > 0) { |
||
732 | $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>'; |
||
1138 | daniel-mar | 733 | |
734 | // Sorty by namespace |
||
735 | usort($alt_ids, function(OIDplusAltId $a, OIDplusAltId $b) { |
||
736 | if($a->getNamespace() > $b->getNamespace()) { |
||
737 | return 1; |
||
738 | } |
||
739 | elseif($a->getNamespace() < $b->getNamespace()) { |
||
740 | return -1; |
||
741 | } |
||
742 | else { |
||
743 | return 0; |
||
744 | } |
||
745 | }); |
||
746 | |||
747 | $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
748 | $out['text'] .= '<table class="table table-bordered table-striped">'; |
||
749 | $out['text'] .= '<thead>'; |
||
750 | $out['text'] .= '<tr><th>'._L('Identifier').'</th><th>'._L('Description').'</th></tr>'; |
||
751 | $out['text'] .= '</thead>'; |
||
752 | $out['text'] .= '<tbody>'; |
||
635 | daniel-mar | 753 | foreach ($alt_ids as $alt_id) { |
754 | $ns = $alt_id->getNamespace(); |
||
755 | $aid = $alt_id->getId(); |
||
756 | $aiddesc = $alt_id->getDescription(); |
||
945 | daniel-mar | 757 | $suffix = $alt_id->getSuffix(); |
1138 | daniel-mar | 758 | $out['text'] .= '<tr><td>'.htmlentities($ns.':'.$aid).($suffix ? '<br/><font size="-1">'.htmlentities($suffix).'</font>' : '').'</td><td>'.htmlentities($aiddesc).'</td></tr>'; |
635 | daniel-mar | 759 | } |
1138 | daniel-mar | 760 | $out['text'] .= '</tbody>'; |
761 | $out['text'] .= '</table>'; |
||
762 | $out['text'] .= '</div></div>'; |
||
635 | daniel-mar | 763 | } |
764 | |||
1005 | daniel-mar | 765 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 766 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2) { |
767 | $plugin->modifyContent($obj->nodeId(), $out['title'], $out['icon'], $out['text']); |
||
635 | daniel-mar | 768 | } |
769 | } |
||
770 | } |
||
771 | } |
||
772 | |||
1116 | daniel-mar | 773 | /** |
1130 | daniel-mar | 774 | * @param array $json |
775 | * @param array $out |
||
1116 | daniel-mar | 776 | * @return void |
777 | */ |
||
1130 | daniel-mar | 778 | private function publicSitemap_rec(array $json, array &$out) { |
635 | daniel-mar | 779 | foreach ($json as $x) { |
780 | if (isset($x['id']) && $x['id']) { |
||
781 | $out[] = $x['id']; |
||
782 | } |
||
783 | if (isset($x['children'])) { |
||
784 | $this->publicSitemap_rec($x['children'], $out); |
||
785 | } |
||
786 | } |
||
787 | } |
||
788 | |||
1116 | daniel-mar | 789 | /** |
790 | * @param array $out |
||
791 | * @return void |
||
792 | */ |
||
793 | public function publicSitemap(array &$out) { |
||
635 | daniel-mar | 794 | $json = array(); |
1116 | daniel-mar | 795 | $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, "*"/*display all*/); |
635 | daniel-mar | 796 | $this->publicSitemap_rec($json, $out); |
797 | } |
||
798 | |||
1116 | daniel-mar | 799 | /** |
800 | * @param array $json |
||
801 | * @param string|null $ra_email |
||
802 | * @param bool $nonjs |
||
803 | * @param string $req_goto |
||
804 | * @return bool |
||
805 | * @throws OIDplusConfigInitializationException |
||
806 | * @throws OIDplusException |
||
807 | */ |
||
808 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 809 | if ($nonjs) { |
810 | $json[] = array( |
||
811 | 'id' => 'oidplus:system', |
||
801 | daniel-mar | 812 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png', |
635 | daniel-mar | 813 | 'text' => _L('System') |
814 | ); |
||
815 | |||
977 | daniel-mar | 816 | $objGoto = OIDplusObject::findFitting($req_goto); |
998 | daniel-mar | 817 | $objGotoParent = $objGoto ? $objGoto->getParent() : null; |
977 | daniel-mar | 818 | $parent = $objGotoParent ? $objGotoParent->nodeId() : ''; |
635 | daniel-mar | 819 | |
820 | $objTypesChildren = array(); |
||
821 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
822 | $icon = $this->get_treeicon_root($ot); |
||
823 | |||
824 | $json[] = array( |
||
825 | 'id' => $ot::root(), |
||
826 | 'icon' => $icon, |
||
827 | 'text' => $ot::objectTypeTitle() |
||
828 | ); |
||
829 | |||
954 | daniel-mar | 830 | $tmp = OIDplusObject::parse($req_goto); |
1116 | daniel-mar | 831 | if ($tmp && ($ot == get_class($tmp))) { |
635 | daniel-mar | 832 | // 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 |
833 | // on the other hand, for giving search engines content, this is good enough |
||
834 | if (empty($parent)) { |
||
835 | $res = OIDplus::db()->query("select * from ###objects where " . |
||
836 | "parent = ? or " . |
||
837 | "id = ? " . |
||
838 | "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto)); |
||
839 | } else { |
||
840 | $res = OIDplus::db()->query("select * from ###objects where " . |
||
841 | "parent = ? or " . |
||
842 | "id = ? or " . |
||
843 | "id = ? ". |
||
844 | "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto, $parent)); |
||
845 | } |
||
846 | |||
847 | $z_used = 0; |
||
848 | $y_used = 0; |
||
849 | $x_used = 0; |
||
850 | $stufe = 0; |
||
851 | $menu_entries = array(); |
||
852 | $stufen = array(); |
||
853 | while ($row = $res->fetch_object()) { |
||
854 | $obj = OIDplusObject::parse($row->id); |
||
1116 | daniel-mar | 855 | if (!$obj) continue; // might happen if the objectType is not available/loaded |
635 | daniel-mar | 856 | if (!$obj->userHasReadRights()) continue; |
857 | $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title); |
||
858 | |||
859 | if ($row->id == $parent) { $stufe=0; $z_used++; } |
||
860 | if ($row->id == $req_goto) { $stufe=1; $y_used++; } |
||
861 | if ($row->parent == $req_goto) { $stufe=2; $x_used++; } |
||
862 | |||
863 | $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0); |
||
864 | $menu_entries[] = $menu_entry; |
||
865 | $stufen[] = $stufe; |
||
866 | } |
||
867 | if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1; |
||
868 | if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1; |
||
869 | if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1; |
||
870 | $json = array_merge($json, $menu_entries); |
||
871 | } |
||
872 | } |
||
873 | |||
874 | return true; |
||
875 | } else { |
||
1116 | daniel-mar | 876 | if ($req_goto === "*") { |
635 | daniel-mar | 877 | $goto_path = true; // display everything recursively |
1116 | daniel-mar | 878 | } else if ($req_goto !== "") { |
635 | daniel-mar | 879 | $goto = $req_goto; |
880 | $path = array(); |
||
881 | while (true) { |
||
882 | $path[] = $goto; |
||
977 | daniel-mar | 883 | $objGoto = OIDplusObject::findFitting($goto); |
884 | if (!$objGoto) break; |
||
885 | $objGotoParent = $objGoto->getParent(); |
||
886 | $goto = $objGotoParent ? $objGotoParent->nodeId() : ''; |
||
635 | daniel-mar | 887 | if ($goto == '') continue; |
888 | } |
||
889 | |||
890 | $goto_path = array_reverse($path); |
||
891 | } else { |
||
892 | $goto_path = null; |
||
893 | } |
||
894 | |||
895 | $objTypesChildren = array(); |
||
896 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
897 | $icon = $this->get_treeicon_root($ot); |
||
898 | |||
899 | $child = array('id' => $ot::root(), |
||
900 | 'text' => $ot::objectTypeTitle(), |
||
901 | 'state' => array("opened" => true), |
||
902 | 'icon' => $icon, |
||
903 | 'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path) |
||
904 | ); |
||
1122 | daniel-mar | 905 | if ($child['icon'] && !file_exists($child['icon'])) $child['icon'] = null; // default icon (folder) |
635 | daniel-mar | 906 | $objTypesChildren[] = $child; |
907 | } |
||
908 | |||
909 | $json[] = array( |
||
910 | 'id' => "oidplus:system", |
||
911 | 'text' => _L('Objects'), |
||
912 | 'state' => array( |
||
913 | "opened" => true, |
||
914 | // "selected" => true) // "selected" is buggy: |
||
915 | // 1) The select-event will not be triggered upon loading |
||
916 | // 2) The nodes directly blow cannot be opened (loading infinite time) |
||
917 | ), |
||
801 | daniel-mar | 918 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png', |
635 | daniel-mar | 919 | 'children' => $objTypesChildren |
920 | ); |
||
921 | |||
922 | return true; |
||
923 | } |
||
924 | } |
||
925 | |||
1116 | daniel-mar | 926 | /** |
927 | * @param string $request |
||
928 | * @return array|false |
||
929 | */ |
||
930 | public function tree_search(string $request) { |
||
635 | daniel-mar | 931 | $ary = array(); |
951 | daniel-mar | 932 | $found_leaf = false; |
635 | daniel-mar | 933 | if ($obj = OIDplusObject::parse($request)) { |
951 | daniel-mar | 934 | $found_leaf = OIDplusObject::exists($request); |
935 | do { |
||
936 | if ($obj->userHasReadRights()) { |
||
635 | daniel-mar | 937 | $ary[] = $obj->nodeId(); |
951 | daniel-mar | 938 | } |
939 | } while ($obj = $obj->getParent()); |
||
940 | $ary = array_reverse($ary); |
||
941 | } |
||
942 | if (!$found_leaf) { |
||
952 | daniel-mar | 943 | $alternatives = $this->getAlternativesForQuery($request); |
951 | daniel-mar | 944 | foreach ($alternatives as $alternative) { |
945 | $ary_ = array(); |
||
946 | if ($obj = OIDplusObject::parse($alternative)) { |
||
947 | if ($obj->userHasReadRights() && OIDplusObject::exists($alternative)) { |
||
948 | do { |
||
949 | $ary_[] = $obj->nodeId(); |
||
950 | } while ($obj = $obj->getParent()); |
||
951 | $ary_ = array_reverse($ary_); |
||
952 | } |
||
953 | } |
||
954 | if (!empty($ary_)) { |
||
955 | $ary = $ary_; |
||
956 | break; |
||
957 | } |
||
635 | daniel-mar | 958 | } |
959 | } |
||
960 | return $ary; |
||
961 | } |
||
962 | |||
1116 | daniel-mar | 963 | /** |
964 | * @var int |
||
965 | */ |
||
635 | daniel-mar | 966 | private static $crudCounter = 0; |
967 | |||
1116 | daniel-mar | 968 | /** |
1121 | daniel-mar | 969 | * @param string $parent |
970 | * @return string |
||
1116 | daniel-mar | 971 | * @throws OIDplusConfigInitializationException |
972 | * @throws OIDplusException |
||
973 | */ |
||
1121 | daniel-mar | 974 | protected static function showCrud(string $parent='oid:'): string { |
635 | daniel-mar | 975 | $items_total = 0; |
976 | $items_hidden = 0; |
||
977 | |||
978 | $objParent = OIDplusObject::parse($parent); |
||
1121 | daniel-mar | 979 | if (!$objParent) return ''; |
635 | daniel-mar | 980 | $parentNS = $objParent::ns(); |
981 | |||
982 | // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers |
||
983 | $no_asn1 = array( |
||
984 | 'oid:1.3.6.1.4.1', |
||
985 | 'oid:1.3.6.1.4.1.37476.9000', |
||
986 | 'oid:1.3.6.1.4.1.37553.8.8', |
||
987 | 'oid:2.16.276.1', |
||
719 | daniel-mar | 988 | //'oid:2.25', // according to Olivier, it is OK that UUID owners define their own ASN.1 ID, since the ASN.1 ID is not required to be unique |
989 | //'oid:1.2.840.113556.1.8000.2554' // Adhoc (GUID/UUID-based) customer use. It is probably the same case as the UUID OIDs, after all, these are UUIDs, too. |
||
635 | daniel-mar | 990 | ); |
991 | |||
992 | // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels |
||
993 | $no_iri = array( |
||
994 | 'oid:1.2.250.1', |
||
995 | 'oid:1.3.6.1.4.1', |
||
996 | 'oid:1.3.6.1.4.1.37476.9000', |
||
997 | 'oid:1.3.6.1.4.1.37553.8.8', |
||
998 | 'oid:2.16.276.1', |
||
999 | 'oid:2.25' |
||
1000 | ); |
||
1001 | |||
1002 | $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true)); |
||
1003 | $accepts_iri = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true)); |
||
1004 | |||
1005 | $result = OIDplus::db()->query("select o.*, r.ra_name " . |
||
1006 | "from ###objects o " . |
||
1007 | "left join ###ra r on r.email = o.ra_email " . |
||
1008 | "where parent = ? " . |
||
1009 | "order by ".OIDplus::db()->natOrder('id'), array($parent)); |
||
1010 | |||
693 | daniel-mar | 1011 | $rows = array(); |
1012 | while ($row = $result->fetch_object()) { |
||
1013 | $obj = OIDplusObject::parse($row->id); |
||
1121 | daniel-mar | 1014 | if ($obj) $rows[] = array($obj,$row); |
693 | daniel-mar | 1015 | } |
1016 | |||
1017 | $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid'); |
||
1018 | |||
1116 | daniel-mar | 1019 | $output = '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
635 | daniel-mar | 1020 | $output .= '<table class="table table-bordered table-striped">'; |
1138 | daniel-mar | 1021 | $output .= '<thead>'; |
635 | daniel-mar | 1022 | $output .= ' <tr>'; |
1023 | $output .= ' <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>'; |
||
692 | daniel-mar | 1024 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
693 | daniel-mar | 1025 | $output .= ' <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>'; |
1026 | } |
||
635 | daniel-mar | 1027 | if ($parentNS == 'oid') { |
1028 | if ($accepts_asn1) $output .= ' <th>'._L('ASN.1 IDs (comma sep.)').'</th>'; |
||
1029 | if ($accepts_iri) $output .= ' <th>'._L('IRI IDs (comma sep.)').'</th>'; |
||
1030 | } |
||
1031 | $output .= ' <th>'._L('RA').'</th>'; |
||
1032 | $output .= ' <th>'._L('Comment').'</th>'; |
||
1033 | if ($objParent->userHasWriteRights()) { |
||
1034 | $output .= ' <th>'._L('Hide').'</th>'; |
||
1035 | $output .= ' <th>'._L('Update').'</th>'; |
||
1036 | $output .= ' <th>'._L('Delete').'</th>'; |
||
1037 | } |
||
1038 | $output .= ' <th>'._L('Created').'</th>'; |
||
1039 | $output .= ' <th>'._L('Updated').'</th>'; |
||
1040 | $output .= ' </tr>'; |
||
1138 | daniel-mar | 1041 | $output .= '</thead>'; |
1042 | $output .= '<tbody>'; |
||
635 | daniel-mar | 1043 | |
1044 | foreach ($rows as list($obj,$row)) { |
||
1045 | $items_total++; |
||
1046 | if (!$obj->userHasReadRights()) { |
||
1047 | $items_hidden++; |
||
1048 | continue; |
||
1049 | } |
||
1050 | |||
1051 | $show_id = $obj->crudShowId($objParent); |
||
1052 | |||
1053 | $asn1ids = array(); |
||
1054 | $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id)); |
||
1055 | while ($row2 = $res2->fetch_array()) { |
||
1056 | $asn1ids[] = $row2['name']; |
||
1057 | } |
||
1058 | |||
1059 | $iris = array(); |
||
1060 | $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id)); |
||
1061 | while ($row2 = $res2->fetch_array()) { |
||
1062 | $iris[] = $row2['name']; |
||
1063 | } |
||
1064 | |||
1058 | daniel-mar | 1065 | $date_created = is_null($row->created) || (explode(' ', $row->created)[0] == '0000-00-00') ? '' : explode(' ', $row->created)[0]; |
1066 | $date_updated = is_null($row->updated) || (explode(' ', $row->updated)[0] == '0000-00-00') ? '' : explode(' ', $row->updated)[0]; |
||
635 | daniel-mar | 1067 | |
1068 | $output .= '<tr>'; |
||
693 | daniel-mar | 1069 | $output .= ' <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>'; |
1070 | if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) { |
||
1071 | // To save space horizontal space, the WEIDs were written below the OIDs |
||
1116 | daniel-mar | 1072 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
693 | daniel-mar | 1073 | $output .= '<br>'.$obj->getWeidNotation(true); |
1074 | } |
||
1075 | $output .= '</td>'; |
||
1076 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
||
1116 | daniel-mar | 1077 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
693 | daniel-mar | 1078 | $output .= ' <td>'.htmlentities($obj->weidArc()).'</td>'; |
1079 | } |
||
635 | daniel-mar | 1080 | if ($objParent->userHasWriteRights()) { |
1081 | if ($parentNS == 'oid') { |
||
1082 | if ($accepts_asn1) $output .= ' <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>'; |
||
1083 | if ($accepts_iri) $output .= ' <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>'; |
||
1084 | } |
||
1085 | $output .= ' <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email).'"></td>'; |
||
1086 | $output .= ' <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment).'"></td>'; |
||
1087 | $output .= ' <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>'; |
||
1088 | $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>'; |
||
1089 | $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>'; |
||
1090 | $output .= ' <td>'.$date_created.'</td>'; |
||
1091 | $output .= ' <td>'.$date_updated.'</td>'; |
||
1092 | } else { |
||
1093 | if ($parentNS == 'oid') { |
||
693 | daniel-mar | 1094 | if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>'; |
1095 | if ($iris == '') $iris = '<i>'._L('(none)').'</i>'; |
||
635 | daniel-mar | 1096 | $asn1ids_ext = array(); |
1097 | foreach ($asn1ids as $asn1id) { |
||
1098 | $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>'; |
||
1099 | } |
||
1100 | if ($accepts_asn1) $output .= ' <td>'.implode(', ', $asn1ids_ext).'</td>'; |
||
1101 | if ($accepts_iri) $output .= ' <td>'.implode(', ', $iris).'</td>'; |
||
1102 | } |
||
1103 | $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>'; |
||
1104 | $output .= ' <td>'.htmlentities($row->comment).'</td>'; |
||
1105 | $output .= ' <td>'.$date_created.'</td>'; |
||
1106 | $output .= ' <td>'.$date_updated.'</td>'; |
||
1107 | } |
||
1108 | $output .= '</tr>'; |
||
1109 | } |
||
1110 | |||
1121 | daniel-mar | 1111 | $parent_ra_email = $objParent->getRaMail() ; |
693 | daniel-mar | 1112 | |
692 | daniel-mar | 1113 | // "Create OID" row |
635 | daniel-mar | 1114 | if ($objParent->userHasWriteRights()) { |
1115 | $output .= '<tr>'; |
||
1121 | daniel-mar | 1116 | $prefix = $objParent->crudInsertPrefix(); |
693 | daniel-mar | 1117 | |
1121 | daniel-mar | 1118 | $suffix = $objParent->crudInsertSuffix(); |
693 | daniel-mar | 1119 | foreach (OIDplus::getObjectTypePlugins() as $plugin) { |
1137 | daniel-mar | 1120 | if (($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6) && ($plugin::getObjectTypeClassName()::ns() == $parentNS)) { |
1131 | daniel-mar | 1121 | $suffix .= $plugin->gridGeneratorLinks($objParent); |
693 | daniel-mar | 1122 | } |
1123 | } |
||
1124 | |||
1125 | if ($parentNS == 'guid') { |
||
695 | daniel-mar | 1126 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>'; |
693 | daniel-mar | 1127 | } else if ($parentNS == 'oid') { |
635 | daniel-mar | 1128 | // 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 |
693 | daniel-mar | 1129 | if ($objParent->nodeId() === 'oid:2.25') { |
695 | daniel-mar | 1130 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>'; |
693 | daniel-mar | 1131 | 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! |
1132 | } else if ($objParent->isRoot()) { |
||
695 | daniel-mar | 1133 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>'; |
693 | daniel-mar | 1134 | 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 | 1135 | } else { |
693 | daniel-mar | 1136 | if ($enable_weid_presentation) { |
695 | daniel-mar | 1137 | $output .= ' <td>'.$prefix.' <input oninput="OIDplusPagePublicObjects.frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
693 | daniel-mar | 1138 | $output .= ' <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>'; |
1139 | } else { |
||
695 | daniel-mar | 1140 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
693 | daniel-mar | 1141 | } |
635 | daniel-mar | 1142 | } |
1143 | } else { |
||
695 | daniel-mar | 1144 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
635 | daniel-mar | 1145 | } |
1146 | if ($accepts_asn1) $output .= ' <td><input type="text" id="asn1ids" value=""></td>'; |
||
1147 | if ($accepts_iri) $output .= ' <td><input type="text" id="iris" value=""></td>'; |
||
1137 | daniel-mar | 1148 | $output .= ' <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email ?? '').'"></td>'; |
635 | daniel-mar | 1149 | $output .= ' <td><input type="text" id="comment" value=""></td>'; |
1150 | $output .= ' <td><input type="checkbox" id="hide"></td>'; |
||
1151 | $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>'; |
||
1152 | $output .= ' <td></td>'; |
||
1153 | $output .= ' <td></td>'; |
||
1154 | $output .= ' <td></td>'; |
||
1155 | $output .= '</tr>'; |
||
1138 | daniel-mar | 1156 | $output .= '</tbody>'; |
635 | daniel-mar | 1157 | } else { |
1138 | daniel-mar | 1158 | $output .= '</tbody>'; |
635 | daniel-mar | 1159 | if ($items_total-$items_hidden == 0) { |
1160 | $cols = ($parentNS == 'oid') ? 7 : 5; |
||
692 | daniel-mar | 1161 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
1162 | $cols++; |
||
693 | daniel-mar | 1163 | } |
1138 | daniel-mar | 1164 | $output .= '<tfoot>'; |
635 | daniel-mar | 1165 | $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>'; |
1138 | daniel-mar | 1166 | $output .= '</tfoot>'; |
635 | daniel-mar | 1167 | } |
1168 | } |
||
1169 | |||
1170 | $output .= '</table>'; |
||
1171 | $output .= '</div></div>'; |
||
1172 | |||
1173 | if ($items_hidden == 1) { |
||
1174 | $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
1175 | } else if ($items_hidden > 1) { |
||
1176 | $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
1177 | } |
||
1178 | |||
1179 | return $output; |
||
1180 | } |
||
1181 | |||
1116 | daniel-mar | 1182 | /** |
1130 | daniel-mar | 1183 | * @param string $html |
1184 | * @return string |
||
1116 | daniel-mar | 1185 | */ |
1130 | daniel-mar | 1186 | protected static function objDescription(string $html): string { |
635 | daniel-mar | 1187 | // We allow HTML, but no hacking |
1188 | $html = anti_xss($html); |
||
1189 | |||
1190 | return trim_br($html); |
||
1191 | } |
||
1192 | |||
1116 | daniel-mar | 1193 | /** |
1194 | * 'quickbars' added 11 July 2019: Disabled because of two problems: |
||
1195 | * 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus |
||
1196 | * 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit |
||
1197 | * 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core. |
||
1198 | * 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar) |
||
1199 | * 'legacyoutput' added 24 September 2021, because it is declared as deprecated |
||
1200 | * 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0 |
||
1201 | * 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium") |
||
1202 | * @var string[] |
||
1203 | */ |
||
753 | daniel-mar | 1204 | public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc'); |
635 | daniel-mar | 1205 | |
1116 | daniel-mar | 1206 | /** |
1130 | daniel-mar | 1207 | * @param string $name |
1208 | * @param string $content |
||
1116 | daniel-mar | 1209 | * @return string |
1210 | * @throws OIDplusConfigInitializationException |
||
1211 | * @throws OIDplusException |
||
1212 | */ |
||
1130 | daniel-mar | 1213 | protected static function showMCE(string $name, string $content): string { |
635 | daniel-mar | 1214 | $mce_plugins = array(); |
1215 | foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */ |
||
1216 | $mce_plugins[] = basename($m); |
||
1217 | } |
||
1218 | |||
1219 | foreach (self::$exclude_tinymce_plugins as $exclude) { |
||
1220 | $index = array_search($exclude, $mce_plugins); |
||
1221 | if ($index !== false) unset($mce_plugins[$index]); |
||
1222 | } |
||
1223 | |||
1224 | $oidplusLang = OIDplus::getCurrentLang(); |
||
1225 | |||
1226 | $langCandidates = array( |
||
1227 | strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE |
||
1228 | strtolower(substr($oidplusLang,0,2)) // de |
||
1229 | ); |
||
1230 | $tinyMCELang = ''; |
||
1231 | foreach ($langCandidates as $candidate) { |
||
1232 | if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) { |
||
1233 | $tinyMCELang = $candidate; |
||
1234 | break; |
||
1235 | } |
||
1236 | } |
||
1237 | |||
1238 | $out = '<script> |
||
1239 | tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce"; |
||
1240 | tinymce.init({ |
||
801 | daniel-mar | 1241 | document_base_url: "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'", |
635 | daniel-mar | 1242 | selector: "#'.$name.'", |
1243 | height: 200, |
||
1244 | statusbar: false, |
||
1245 | // menubar:false, |
||
1246 | // toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect", |
||
1247 | toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect", |
||
1248 | plugins: "'.implode(' ', $mce_plugins).'", |
||
1249 | mobile: { |
||
1250 | theme: "mobile", |
||
1251 | toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect", |
||
1252 | plugins: "'.implode(' ', $mce_plugins).'" |
||
1253 | } |
||
1254 | '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').' |
||
801 | daniel-mar | 1255 | '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').' |
635 | daniel-mar | 1256 | }); |
1257 | |||
1258 | pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]); |
||
1259 | pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]); |
||
1260 | </script>'; |
||
1261 | |||
1262 | $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? |
||
1263 | |||
1264 | $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>'; |
||
1265 | |||
1266 | return $out; |
||
1267 | } |
||
1268 | |||
1116 | daniel-mar | 1269 | /** |
1131 | daniel-mar | 1270 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1 |
1116 | daniel-mar | 1271 | * @return bool |
1272 | * @throws OIDplusException |
||
1273 | */ |
||
635 | daniel-mar | 1274 | public function oobeRequested(): bool { |
1275 | return OIDplus::config()->getValue('oobe_objects_done') == '0'; |
||
1276 | } |
||
1277 | |||
1116 | daniel-mar | 1278 | /** |
1131 | daniel-mar | 1279 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1 |
1125 | daniel-mar | 1280 | * @param int $step |
1281 | * @param bool $do_edits |
||
1282 | * @param bool $errors_happened |
||
1116 | daniel-mar | 1283 | * @return void |
1284 | */ |
||
1125 | daniel-mar | 1285 | public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ { |
1055 | daniel-mar | 1286 | echo '<h2>'._L('Step %1: Enable/Disable object type plugins',$step).'</h2>'; |
635 | daniel-mar | 1287 | echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>'; |
1288 | |||
1289 | $enabled_ary = array(); |
||
1290 | |||
1291 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
1292 | echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"'; |
||
1033 | daniel-mar | 1293 | if (isset($_POST['sent'])) { |
1294 | if (isset($_POST['enable_ot_'.$ot::ns()])) { |
||
635 | daniel-mar | 1295 | echo ' checked'; |
1296 | $enabled_ary[] = $ot::ns(); |
||
1297 | } |
||
1298 | } else { |
||
1299 | echo ' checked'; |
||
1300 | } |
||
1301 | echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>'; |
||
1302 | } |
||
1303 | |||
1304 | foreach (OIDplus::getDisabledObjectTypes() as $ot) { |
||
1305 | echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"'; |
||
1033 | daniel-mar | 1306 | if (isset($_POST['sent'])) { |
1307 | if (isset($_POST['enable_ot_'.$ot::ns()])) { |
||
635 | daniel-mar | 1308 | echo ' checked'; |
1309 | $enabled_ary[] = $ot::ns(); |
||
1310 | } |
||
1311 | } else { |
||
1312 | echo ''; // <-- difference |
||
1313 | } |
||
1314 | echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>'; |
||
1315 | } |
||
1316 | |||
1317 | $msg = ''; |
||
1318 | if ($do_edits) { |
||
1319 | try { |
||
1320 | OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary)); |
||
1321 | OIDplus::config()->setValue('oobe_objects_done', '1'); |
||
1050 | daniel-mar | 1322 | } catch (\Exception $e) { |
635 | daniel-mar | 1323 | $msg = $e->getMessage(); |
1324 | $errors_happened = true; |
||
1325 | } |
||
1326 | } |
||
1327 | |||
1328 | echo ' <font color="red"><b>'.$msg.'</b></font>'; |
||
1329 | } |
||
1330 | |||
1116 | daniel-mar | 1331 | /** |
1131 | daniel-mar | 1332 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 |
1130 | daniel-mar | 1333 | * @param string|null $user |
1116 | daniel-mar | 1334 | * @return array |
1335 | * @throws OIDplusException |
||
1336 | */ |
||
1130 | daniel-mar | 1337 | public function getNotifications(string $user=null): array { |
1000 | daniel-mar | 1338 | $notifications = array(); |
1012 | daniel-mar | 1339 | $res = OIDplus::db()->query("select id, title from ###objects order by ".OIDplus::db()->natOrder('id')); |
1000 | daniel-mar | 1340 | if ($res->any()) { |
1341 | $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance |
||
1342 | while ($row = $res->fetch_array()) { |
||
1343 | if (empty($row['title'])) { |
||
1344 | if ($user === 'admin') { |
||
1345 | $accept = $is_admin_logged_in; |
||
1346 | } else { |
||
1347 | $accept = false; |
||
1348 | if ($obj = OIDplusObject::parse($row['id'])) { |
||
1349 | if ($obj->userHasWriteRights($user)) { |
||
1350 | $accept = true; |
||
1351 | } |
||
1352 | } |
||
1353 | } |
||
1354 | |||
1355 | if ($accept) { |
||
1356 | $notifications[] = array('WARN', _L('Object %1 has no title.', '<a '.OIDplus::gui()->link($row['id']).'>'.$row['id'].'</a>')); |
||
1357 | } |
||
1358 | } |
||
1359 | } |
||
1360 | } |
||
1361 | return $notifications; |
||
1362 | } |
||
1363 | |||
693 | daniel-mar | 1364 | } |