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