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