Subversion Repositories oidplus

Rev

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