Subversion Repositories oidplus

Rev

Rev 753 | Rev 783 | 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];
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
 
772 daniel-mar 317
                        if (!$objParent->isRoot() && (OIDplus::db()->query("select id from ###objects where id = ?", array($objParent->nodeId()))->num_rows() == 0)) {
635 daniel-mar 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
 
772 daniel-mar 327
                        // For the root objects, let the user also enter a WEID
328
                        if ($objParent::ns() == 'oid') {
329
                                if (strtolower(substr(trim($params['id']),0,5)) === 'weid:') {
330
                                        if ($objParent->isRoot()) {
331
                                                $params['id'] = WeidOidConverter::weid2oid($params['id']);
332
                                                if ($params['id'] === false) {
333
                                                        throw new OIDplusException(_L('Invalid WEID'));
334
                                                }
335
                                        } else {
336
                                                throw new OIDplusException(_L('You can use the WEID syntax only at your object tree root.'));
337
                                        }
338
                                }
339
                        }
340
 
635 daniel-mar 341
                        // Determine absolute OID name
342
                        // Note: At addString() and parse(), the syntax of the ID will be checked
343
                        $id = $objParent->addString($params['id']);
344
 
345
                        // Check, if the OID exists
346
                        $test = OIDplus::db()->query("select id from ###objects where id = ?", array($id));
347
                        if ($test->num_rows() >= 1) {
348
                                throw new OIDplusException(_L('Object %1 already exists!',$id));
349
                        }
350
 
351
                        $obj = OIDplusObject::parse($id);
352
                                if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
353
 
354
                        foreach (OIDplus::getPagePlugins() as $plugin) {
355
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
356
                                        $plugin->beforeObjectInsert($id, $params);
357
                                }
358
                        }
359
 
360
                        // First simulate if there are any problems of ASN.1 IDs und IRIs
361
                        if ($obj::ns() == 'oid') {
362
                                if (!$obj->isWellKnown()) {
363
                                        if (isset($params['iris'])) {
364
                                                $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
365
                                                $ids = array_map('trim',$ids);
366
                                                $obj->replaceIris($ids, true);
367
                                        }
368
 
369
                                        if (isset($params['asn1ids'])) {
370
                                                $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
371
                                                $ids = array_map('trim',$ids);
372
                                                $obj->replaceAsn1Ids($ids, true);
373
                                        }
374
                                }
375
                        }
376
 
377
                        // Apply superior RA change
378
                        $parent = $params['parent'];
379
                        $ra_email = isset($params['ra_email']) ? $params['ra_email'] : '';
380
                        if ($obj::ns() == 'oid') {
381
                                if ($obj->isWellKnown()) {
382
                                        $ra_email = '';
383
                                }
384
                        }
385
                        if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) {
386
                                throw new OIDplusException(_L('Invalid RA email address'));
387
                        }
388
 
389
                        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'";
390
                        if (!empty($ra_email)) {
391
                                OIDplus::logger()->log("[INFO]RA($ra_email)!", "Gained ownership of newly created object '$id'");
392
                        }
393
 
394
                        $confidential = isset($params['confidential']) ? ($params['confidential'] == 'true') : false;
395
                        $comment = isset($params['comment']) ? $params['comment'] : '';
396
                        $title = '';
397
                        $description = '';
398
 
399
                        if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) {
400
                                $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH');
401
                                throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen));
402
                        }
403
 
404
                        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));
405
 
406
                        // Set ASN.1 IDs und IRIs
407
                        if ($obj::ns() == 'oid') {
408
                                if (!$obj->isWellKnown()) {
409
                                        if (isset($params['iris'])) {
410
                                                $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
411
                                                $ids = array_map('trim',$ids);
412
                                                $obj->replaceIris($ids, false);
413
                                        }
414
 
415
                                        if (isset($params['asn1ids'])) {
416
                                                $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
417
                                                $ids = array_map('trim',$ids);
418
                                                $obj->replaceAsn1Ids($ids, false);
419
                                        }
420
                                }
421
                        }
422
 
423
                        $status = 0;
424
 
425
                        if (!empty($ra_email)) {
426
                                // Do we need to notify that the RA does not exist?
427
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
428
                                $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
429
                                if ($res->num_rows() == 0) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
430
                        }
431
 
432
                        if ($obj::ns() == 'oid') {
433
                                if ($obj->isWellKnown()) {
434
                                        $status += 4;
435
                                }
436
                        }
437
 
438
                        foreach (OIDplus::getPagePlugins() as $plugin) {
439
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
440
                                        $plugin->afterObjectInsert($id, $params);
441
                                }
442
                        }
443
 
444
                        return array(
445
                                "status" => $status,
446
                                "inserted_id" => $id
447
                        );
448
                } else {
449
                        throw new OIDplusException(_L('Unknown action ID'));
450
                }
451
        }
452
 
453
        public function init($html=true) {
454
                OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
693 daniel-mar 455
                OIDplus::config()->prepareConfigKey('oid_grid_show_weid', 'Show WEID/Base36 column in CRUD grid of OIDs?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
456
                        if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
457
                                throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
458
                        }
459
                });
635 daniel-mar 460
        }
461
 
462
        public function gui($id, &$out, &$handled) {
463
                if ($id === 'oidplus:system') {
464
                        $handled = true;
465
 
466
                        $out['title'] = OIDplus::config()->getValue('system_title');
467
                        $out['icon'] = OIDplus::webpath(__DIR__).'system_big.png';
468
 
469
                        if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) {
470
                                $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html');
471
                        } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) {
472
                                $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html');
473
                        } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) {
474
                                $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html');
475
                        } else if (file_exists(__DIR__ . '/welcome.html')) {
476
                                $cont = file_get_contents(__DIR__ . '/welcome.html');
477
                        } else {
478
                                $cont = '';
479
                        }
480
 
481
                        list($html, $js, $css) = extractHtmlContents($cont);
482
                        $cont = '';
483
                        if (!empty($js))  $cont .= "<script>\n$js\n</script>";
484
                        if (!empty($css)) $cont .= "<style>\n$css\n</style>";
485
                        $cont .= $html;
486
 
487
                        $out['text'] = $cont;
488
 
489
                        if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) {
490
                                $tmp = '<ul>';
491
                                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
492
                                        $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>';
493
                                }
494
                                $tmp .= '</ul>';
495
                                $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']);
496
                        }
497
 
498
                        return;
499
                }
500
 
501
                try {
502
                        $obj = OIDplusObject::parse($id);
503
                } catch (Exception $e) {
504
                        $obj = null;
505
                }
506
 
507
                if (!is_null($obj)) {
508
                        $handled = true;
509
 
510
                        if (!$obj->userHasReadRights()) {
511
                                $out['title'] = _L('Access denied');
512
                                $out['icon'] = 'img/error_big.png';
513
                                $out['text'] = '<p>'._L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')).'</p>';
514
                                return;
515
                        }
516
 
517
                        $parent = null;
518
                        $res = null;
519
                        $row = null;
520
                        $matches_any_registered_type = false;
521
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
522
                                if ($obj = $ot::parse($id)) {
523
                                        $matches_any_registered_type = true;
524
                                        if ($obj->isRoot()) {
525
                                                $obj->getContentPage($out['title'], $out['text'], $out['icon']);
526
                                                $parent = null; // $obj->getParent();
527
                                                break;
528
                                        } else {
529
                                                $res = OIDplus::db()->query("select * from ###objects where id = ?", array($obj->nodeId()));
530
                                                if ($res->num_rows() == 0) {
531
                                                        http_response_code(404);
532
                                                        $out['title'] = _L('Object not found');
533
                                                        $out['icon'] = 'img/error_big.png';
534
                                                        $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>');
535
                                                        return;
536
                                                } else {
537
                                                        $row = $res->fetch_array(); // will be used further down the code
538
                                                        $obj->getContentPage($out['title'], $out['text'], $out['icon']);
539
                                                        if (empty($out['title'])) $out['title'] = explode(':',$id,2)[1];
540
                                                        $parent = $obj->getParent();
541
                                                        break;
542
                                                }
543
                                        }
544
                                }
545
                        }
546
                        if (!$matches_any_registered_type) {
547
                                http_response_code(404);
548
                                $out['title'] = _L('Object not found');
549
                                $out['icon'] = 'img/error_big.png';
550
                                $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>');
551
                                return;
552
                        }
553
 
554
                        // ---
555
 
556
                        if ($parent) {
557
                                if ($parent->isRoot()) {
558
 
559
                                        $parent_link_text = $parent->objectTypeTitle();
560
                                        $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'];
561
 
562
                                } else {
563
                                        $res_ = OIDplus::db()->query("select * from ###objects where id = ?", array($parent->nodeId()));
564
                                        if ($res_->num_rows() > 0) {
565
                                                $row_ = $res_->fetch_array();
566
 
567
                                                $parent_title = $row_['title'];
568
                                                if (empty($parent_title) && ($parent->ns() == 'oid')) {
569
                                                        // If not title is available, then use an ASN.1 identifier
570
                                                        $res_ = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($parent->nodeId()));
571
                                                        if ($res_->num_rows() > 0) {
572
                                                                $row_ = $res_->fetch_array();
573
                                                                $parent_title = $row_['name']; // TODO: multiple ASN1 ids?
574
                                                        }
575
                                                }
576
 
577
                                                $parent_link_text = empty($parent_title) ? explode(':',$parent->nodeId())[1] : $parent_title.' ('.explode(':',$parent->nodeId())[1].')';
578
 
579
                                                $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'];
580
                                        } else {
581
                                                $out['text'] = '';
582
                                        }
583
                                }
584
                        } else {
585
                                $parent_link_text = _L('Go back to front page');
586
                                $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'];
587
                        }
588
 
589
                        // ---
590
 
591
                        if (!is_null($row) && isset($row['description'])) {
592
                                if (empty($row['description'])) {
593
                                        if (empty($row['title'])) {
594
                                                $desc = '<p><i>'._L('No description for this object available').'</i></p>';
595
                                        } else {
596
                                                $desc = $row['title'];
597
                                        }
598
                                } else {
599
                                        $desc = self::objDescription($row['description']);
600
                                }
601
 
602
                                if ($obj->userHasWriteRights()) {
603
                                        $rand = ++self::$crudCounter;
604
                                        $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>';
605
                                        $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
606
                                        $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($row['title']).'"><br><br>'._L('Description').':<br>';
607
                                        $desc .= self::showMCE('description', $row['description']);
608
                                        $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>';
609
                                        $desc .= '</div>';
610
                                        $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>';
611
                                }
612
                        } else {
613
                                $desc = '';
614
                        }
615
 
616
                        // ---
617
 
618
                        if (strpos($out['text'], '%%DESC%%') !== false)
619
                                $out['text'] = str_replace('%%DESC%%',    $desc,                              $out['text']);
620
                        if (strpos($out['text'], '%%CRUD%%') !== false)
621
                                $out['text'] = str_replace('%%CRUD%%',    self::showCrud($id),                $out['text']);
622
                        if (strpos($out['text'], '%%RA_INFO%%') !== false)
623
                                $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($row['ra_email']), $out['text']);
624
 
625
                        $alt_ids = $obj->getAltIds();
626
                        if (count($alt_ids) > 0) {
627
                                $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>';
628
                                foreach ($alt_ids as $alt_id) {
629
                                        $ns = $alt_id->getNamespace();
630
                                        $aid = $alt_id->getId();
631
                                        $aiddesc = $alt_id->getDescription();
632
                                        $out['text'] .= "$aiddesc <code>$ns:$aid</code><br>";
633
                                }
634
                        }
635
 
636
                        foreach (OIDplus::getPagePlugins() as $plugin) {
637
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.2')) {
638
                                        $plugin->modifyContent($id, $out['title'], $out['icon'], $out['text']);
639
                                }
640
                        }
641
                }
642
        }
643
 
644
        private function publicSitemap_rec($json, &$out) {
645
                foreach ($json as $x) {
646
                        if (isset($x['id']) && $x['id']) {
647
                                $out[] = $x['id'];
648
                        }
649
                        if (isset($x['children'])) {
650
                                $this->publicSitemap_rec($x['children'], $out);
651
                        }
652
                }
653
        }
654
 
655
        public function publicSitemap(&$out) {
656
                $json = array();
657
                $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, true/*display all*/);
658
                $this->publicSitemap_rec($json, $out);
659
        }
660
 
661
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
662
                if ($nonjs) {
663
                        $json[] = array(
664
                                'id' => 'oidplus:system',
665
                                'icon' => OIDplus::webpath(__DIR__).'system.png',
666
                                'text' => _L('System')
667
                        );
668
 
669
                        $parent = '';
670
                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($req_goto));
671
                        while ($row = $res->fetch_object()) {
672
                                $parent = $row->parent;
673
                        }
674
 
675
                        $objTypesChildren = array();
676
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
677
                                $icon = $this->get_treeicon_root($ot);
678
 
679
                                $json[] = array(
680
                                        'id' => $ot::root(),
681
                                        'icon' => $icon,
682
                                        'text' => $ot::objectTypeTitle()
683
                                );
684
 
685
                                try {
686
                                        $tmp = OIDplusObject::parse($req_goto);
687
                                } catch (Exception $e) {
688
                                        $tmp = null;
689
                                }
690
                                if (!is_null($tmp) && ($ot == get_class($tmp))) {
691
                                        // 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
692
                                        //       on the other hand, for giving search engines content, this is good enough
693
                                        if (empty($parent)) {
694
                                                $res = OIDplus::db()->query("select * from ###objects where " .
695
                                                                            "parent = ? or " .
696
                                                                            "id = ? " .
697
                                                                            "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto));
698
                                        } else {
699
                                                $res = OIDplus::db()->query("select * from ###objects where " .
700
                                                                            "parent = ? or " .
701
                                                                            "id = ? or " .
702
                                                                            "id = ? ".
703
                                                                            "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto, $parent));
704
                                        }
705
 
706
                                        $z_used = 0;
707
                                        $y_used = 0;
708
                                        $x_used = 0;
709
                                        $stufe = 0;
710
                                        $menu_entries = array();
711
                                        $stufen = array();
712
                                        while ($row = $res->fetch_object()) {
713
                                                $obj = OIDplusObject::parse($row->id);
714
                                                if (is_null($obj)) continue; // might happen if the objectType is not available/loaded
715
                                                if (!$obj->userHasReadRights()) continue;
716
                                                $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title);
717
 
718
                                                if ($row->id == $parent) { $stufe=0; $z_used++; }
719
                                                if ($row->id == $req_goto) { $stufe=1; $y_used++; }
720
                                                if ($row->parent == $req_goto) { $stufe=2; $x_used++; }
721
 
722
                                                $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0);
723
                                                $menu_entries[] = $menu_entry;
724
                                                $stufen[] = $stufe;
725
                                        }
726
                                        if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1;
727
                                        if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1;
728
                                        if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1;
729
                                        $json = array_merge($json, $menu_entries);
730
                                }
731
                        }
732
 
733
                        return true;
734
                } else {
735
                        if ($req_goto === true) {
736
                                $goto_path = true; // display everything recursively
737
                        } else if (isset($req_goto)) {
738
                                $goto = $req_goto;
739
                                $path = array();
740
                                while (true) {
741
                                        $path[] = $goto;
742
                                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($goto));
743
                                        if ($res->num_rows() == 0) break;
744
                                        $row = $res->fetch_array();
745
                                        $goto = $row['parent'];
746
                                        if ($goto == '') continue;
747
                                }
748
 
749
                                $goto_path = array_reverse($path);
750
                        } else {
751
                                $goto_path = null;
752
                        }
753
 
754
                        $objTypesChildren = array();
755
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
756
                                $icon = $this->get_treeicon_root($ot);
757
 
758
                                $child = array('id' => $ot::root(),
759
                                               'text' => $ot::objectTypeTitle(),
760
                                               'state' => array("opened" => true),
761
                                               'icon' => $icon,
762
                                               'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path)
763
                                               );
764
                                if (!file_exists($child['icon'])) $child['icon'] = null; // default icon (folder)
765
                                $objTypesChildren[] = $child;
766
                        }
767
 
768
                        $json[] = array(
769
                                'id' => "oidplus:system",
770
                                'text' => _L('Objects'),
771
                                'state' => array(
772
                                        "opened" => true,
773
                                        // "selected" => true)  // "selected" is buggy:
774
                                        // 1) The select-event will not be triggered upon loading
775
                                        // 2) The nodes directly blow cannot be opened (loading infinite time)
776
                                ),
777
                                'icon' => OIDplus::webpath(__DIR__).'system.png',
778
                                'children' => $objTypesChildren
779
                        );
780
 
781
                        return true;
782
                }
783
        }
784
 
785
        public function tree_search($request) {
786
                $ary = array();
787
                if ($obj = OIDplusObject::parse($request)) {
788
                        if ($obj->userHasReadRights()) {
789
                                do {
790
                                        $ary[] = $obj->nodeId();
791
                                } while ($obj = $obj->getParent());
792
                                $ary = array_reverse($ary);
793
                        }
794
                }
795
                return $ary;
796
        }
797
 
798
        private static $crudCounter = 0;
799
 
800
        protected static function showCrud($parent='oid:') {
801
                $items_total = 0;
802
                $items_hidden = 0;
803
 
804
                $objParent = OIDplusObject::parse($parent);
805
                $parentNS = $objParent::ns();
806
 
807
                // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers
808
                $no_asn1 = array(
809
                        'oid:1.3.6.1.4.1',
810
                        'oid:1.3.6.1.4.1.37476.9000',
811
                        'oid:1.3.6.1.4.1.37553.8.8',
812
                        'oid:2.16.276.1',
719 daniel-mar 813
                        //'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
814
                        //'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 815
                );
816
 
817
                // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels
818
                $no_iri = array(
819
                        'oid:1.2.250.1',
820
                        'oid:1.3.6.1.4.1',
821
                        'oid:1.3.6.1.4.1.37476.9000',
822
                        'oid:1.3.6.1.4.1.37553.8.8',
823
                        'oid:2.16.276.1',
824
                        'oid:2.25'
825
                );
826
 
827
                $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true));
828
                $accepts_iri  = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true));
829
 
830
                $result = OIDplus::db()->query("select o.*, r.ra_name " .
831
                                               "from ###objects o " .
832
                                               "left join ###ra r on r.email = o.ra_email " .
833
                                               "where parent = ? " .
834
                                               "order by ".OIDplus::db()->natOrder('id'), array($parent));
835
 
693 daniel-mar 836
                $rows = array();
837
                while ($row = $result->fetch_object()) {
838
                        $obj = OIDplusObject::parse($row->id);
839
                        $rows[] = array($obj,$row);
840
                }
841
 
842
                $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid');
843
 
635 daniel-mar 844
                $output = '';
845
                $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
846
                $output .= '<table class="table table-bordered table-striped">';
847
                $output .= '    <tr>';
848
                $output .= '         <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>';
692 daniel-mar 849
                if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
693 daniel-mar 850
                        $output .= '         <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>';
851
                }
635 daniel-mar 852
                if ($parentNS == 'oid') {
853
                        if ($accepts_asn1) $output .= '      <th>'._L('ASN.1 IDs (comma sep.)').'</th>';
854
                        if ($accepts_iri)  $output .= '      <th>'._L('IRI IDs (comma sep.)').'</th>';
855
                }
856
                $output .= '         <th>'._L('RA').'</th>';
857
                $output .= '         <th>'._L('Comment').'</th>';
858
                if ($objParent->userHasWriteRights()) {
859
                        $output .= '         <th>'._L('Hide').'</th>';
860
                        $output .= '         <th>'._L('Update').'</th>';
861
                        $output .= '         <th>'._L('Delete').'</th>';
862
                }
863
                $output .= '         <th>'._L('Created').'</th>';
864
                $output .= '         <th>'._L('Updated').'</th>';
865
                $output .= '    </tr>';
866
 
867
                foreach ($rows as list($obj,$row)) {
868
                        $items_total++;
869
                        if (!$obj->userHasReadRights()) {
870
                                $items_hidden++;
871
                                continue;
872
                        }
873
 
874
                        $show_id = $obj->crudShowId($objParent);
875
 
876
                        $asn1ids = array();
877
                        $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id));
878
                        while ($row2 = $res2->fetch_array()) {
879
                                $asn1ids[] = $row2['name'];
880
                        }
881
 
882
                        $iris = array();
883
                        $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id));
884
                        while ($row2 = $res2->fetch_array()) {
885
                                $iris[] = $row2['name'];
886
                        }
887
 
888
                        $date_created = explode(' ', $row->created)[0] == '0000-00-00' ? '' : explode(' ', $row->created)[0];
889
                        $date_updated = explode(' ', $row->updated)[0] == '0000-00-00' ? '' : explode(' ', $row->updated)[0];
890
 
891
                        $output .= '<tr>';
693 daniel-mar 892
                        $output .= '     <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>';
893
                        if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) {
894
                                // To save space horizontal space, the WEIDs were written below the OIDs
895
                                $output .= '<br>'.$obj->getWeidNotation(true);
896
                        }
897
                        $output .= '</td>';
898
                        if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
899
                                $output .= '    <td>'.htmlentities($obj->weidArc()).'</td>';
900
                        }
635 daniel-mar 901
                        if ($objParent->userHasWriteRights()) {
902
                                if ($parentNS == 'oid') {
903
                                        if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>';
904
                                        if ($accepts_iri)  $output .= '     <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>';
905
                                }
906
                                $output .= '     <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email).'"></td>';
907
                                $output .= '     <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment).'"></td>';
908
                                $output .= '     <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>';
909
                                $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>';
910
                                $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>';
911
                                $output .= '     <td>'.$date_created.'</td>';
912
                                $output .= '     <td>'.$date_updated.'</td>';
913
                        } else {
914
                                if ($parentNS == 'oid') {
693 daniel-mar 915
                                        if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>';
916
                                        if ($iris == '') $iris = '<i>'._L('(none)').'</i>';
635 daniel-mar 917
                                        $asn1ids_ext = array();
918
                                        foreach ($asn1ids as $asn1id) {
919
                                                $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>';
920
                                        }
921
                                        if ($accepts_asn1) $output .= '     <td>'.implode(', ', $asn1ids_ext).'</td>';
922
                                        if ($accepts_iri)  $output .= '     <td>'.implode(', ', $iris).'</td>';
923
                                }
924
                                $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>';
925
                                $output .= '     <td>'.htmlentities($row->comment).'</td>';
926
                                $output .= '     <td>'.$date_created.'</td>';
927
                                $output .= '     <td>'.$date_updated.'</td>';
928
                        }
929
                        $output .= '</tr>';
930
                }
931
 
932
                $result = OIDplus::db()->query("select * from ###objects where id = ?", array($parent));
933
                $parent_ra_email = $result->num_rows() > 0 ? $result->fetch_object()->ra_email : '';
693 daniel-mar 934
 
692 daniel-mar 935
                // "Create OID" row
635 daniel-mar 936
                if ($objParent->userHasWriteRights()) {
937
                        $output .= '<tr>';
938
                        $prefix = is_null($objParent) ? '' : $objParent->crudInsertPrefix();
693 daniel-mar 939
 
707 daniel-mar 940
                        $suffix = is_null($objParent) ? '' : $objParent->crudInsertSuffix();
693 daniel-mar 941
                        foreach (OIDplus::getObjectTypePlugins() as $plugin) {
942
                                if (($plugin::getObjectTypeClassName()::ns() == $parentNS) && $plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.6')) {
695 daniel-mar 943
                                        $suffix .= $plugin->gridGeneratorLinks($objParent);
693 daniel-mar 944
                                }
945
                        }
946
 
947
                        if ($parentNS == 'guid') {
695 daniel-mar 948
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>';
693 daniel-mar 949
                        } else if ($parentNS == 'oid') {
635 daniel-mar 950
                                // 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 951
                                if ($objParent->nodeId() === 'oid:2.25') {
695 daniel-mar 952
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
693 daniel-mar 953
                                        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!
954
                                } else if ($objParent->isRoot()) {
695 daniel-mar 955
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
693 daniel-mar 956
                                        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 957
                                } else {
693 daniel-mar 958
                                        if ($enable_weid_presentation) {
695 daniel-mar 959
                                                $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 960
                                                $output .= '     <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>';
961
                                        } else {
695 daniel-mar 962
                                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
693 daniel-mar 963
                                        }
635 daniel-mar 964
                                }
965
                        } else {
695 daniel-mar 966
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
635 daniel-mar 967
                        }
968
                        if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids" value=""></td>';
969
                        if ($accepts_iri)  $output .= '     <td><input type="text" id="iris" value=""></td>';
970
                        $output .= '     <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email).'"></td>';
971
                        $output .= '     <td><input type="text" id="comment" value=""></td>';
972
                        $output .= '     <td><input type="checkbox" id="hide"></td>';
973
                        $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>';
974
                        $output .= '     <td></td>';
975
                        $output .= '     <td></td>';
976
                        $output .= '     <td></td>';
977
                        $output .= '</tr>';
978
                } else {
979
                        if ($items_total-$items_hidden == 0) {
980
                                $cols = ($parentNS == 'oid') ? 7 : 5;
692 daniel-mar 981
                                if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
982
                                        $cols++;
693 daniel-mar 983
                                }
635 daniel-mar 984
                                $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>';
985
                        }
986
                }
987
 
988
                $output .= '</table>';
989
                $output .= '</div></div>';
990
 
991
                if ($items_hidden == 1) {
992
                        $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
993
                } else if ($items_hidden > 1) {
994
                        $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
995
                }
996
 
997
                return $output;
998
        }
999
 
1000
        protected static function objDescription($html) {
1001
                // We allow HTML, but no hacking
1002
                $html = anti_xss($html);
1003
 
1004
                return trim_br($html);
1005
        }
1006
 
1007
        // 'quickbars' added 11 July 2019: Disabled because of two problems:
1008
        //                                 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus
1009
        //                                 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit
1010
        // 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core.
1011
        // 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar)
753 daniel-mar 1012
        // 'legacyoutput' added 24 September 2021, because it is declared as deprecated
1013
        // 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0
1014
        // 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium")
1015
        public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc');
635 daniel-mar 1016
 
1017
        protected static function showMCE($name, $content) {
1018
                $mce_plugins = array();
1019
                foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */
1020
                        $mce_plugins[] = basename($m);
1021
                }
1022
 
1023
                foreach (self::$exclude_tinymce_plugins as $exclude) {
1024
                        $index = array_search($exclude, $mce_plugins);
1025
                        if ($index !== false) unset($mce_plugins[$index]);
1026
                }
1027
 
1028
                $oidplusLang = OIDplus::getCurrentLang();
1029
 
1030
                $langCandidates = array(
1031
                        strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE
1032
                        strtolower(substr($oidplusLang,0,2)) // de
1033
                );
1034
                $tinyMCELang = '';
1035
                foreach ($langCandidates as $candidate) {
1036
                        if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) {
1037
                                $tinyMCELang = $candidate;
1038
                                break;
1039
                        }
1040
                }
1041
 
1042
                $out = '<script>
1043
                                tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce";
1044
                                tinymce.init({
1045
                                        document_base_url: "'.OIDplus::webpath().'",
1046
                                        selector: "#'.$name.'",
1047
                                        height: 200,
1048
                                        statusbar: false,
1049
//                                      menubar:false,
1050
//                                      toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect",
1051
                                        toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
1052
                                        plugins: "'.implode(' ', $mce_plugins).'",
1053
                                        mobile: {
1054
                                                theme: "mobile",
1055
                                                toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
1056
                                                plugins: "'.implode(' ', $mce_plugins).'"
1057
                                        }
1058
                                        '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').'
1059
                                        '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath().'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').'
1060
                                });
1061
 
1062
                                pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]);
1063
                                pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]);
1064
                        </script>';
1065
 
1066
                $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?
1067
 
1068
                $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>';
1069
 
1070
                return $out;
1071
        }
1072
 
1073
        public function implementsFeature($id) {
1074
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested()
1075
                return false;
1076
        }
1077
 
1078
        public function oobeRequested(): bool {
1079
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
1080
 
1081
                return OIDplus::config()->getValue('oobe_objects_done') == '0';
1082
        }
1083
 
1084
        public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ {
1085
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
1086
 
1087
                echo '<p><u>'._L('Step %1: Enable/Disable object type plugins',$step).'</u></p>';
1088
                echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>';
1089
 
1090
                $enabled_ary = array();
1091
 
1092
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1093
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
1094
                        if (isset($_REQUEST['sent'])) {
1095
                                if (isset($_REQUEST['enable_ot_'.$ot::ns()])) {
1096
                                        echo ' checked';
1097
                                        $enabled_ary[] = $ot::ns();
1098
                                }
1099
                        } else {
1100
                                echo ' checked';
1101
                        }
1102
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
1103
                }
1104
 
1105
                foreach (OIDplus::getDisabledObjectTypes() as $ot) {
1106
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
1107
                        if (isset($_REQUEST['sent'])) {
1108
                                if (isset($_REQUEST['enable_ot_'.$ot::ns()])) {
1109
                                        echo ' checked';
1110
                                        $enabled_ary[] = $ot::ns();
1111
                                }
1112
                        } else {
1113
                                echo ''; // <-- difference
1114
                        }
1115
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
1116
                }
1117
 
1118
                $msg = '';
1119
                if ($do_edits) {
1120
                        try {
1121
                                OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary));
1122
                                OIDplus::config()->setValue('oobe_objects_done', '1');
1123
                        } catch (Exception $e) {
1124
                                $msg = $e->getMessage();
1125
                                $errors_happened = true;
1126
                        }
1127
                }
1128
 
1129
                echo ' <font color="red"><b>'.$msg.'</b></font>';
1130
        }
1131
 
693 daniel-mar 1132
}