Subversion Repositories oidplus

Rev

Rev 636 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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