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