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