Subversion Repositories oidplus

Rev

Rev 783 | Rev 800 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2022 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))->any()) {
  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->any()) 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))->any()) {
  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->any()) $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))->any()) {
  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->isRoot() && (!OIDplus::db()->query("select id from ###objects where id = ?", array($objParent->nodeId()))->any())) {
  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.                         // 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.  
  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->any()) {
  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->any()) $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) {});
  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.                 });
  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->any()) {
  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_->any()) {
  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_->any()) {
  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.                         // DM 16.03.2022 commented out isset() because Oracle does not set 'description' if it is NULL?!
  592.                         if (!is_null($row)/* && isset($row['description'])*/) {
  593.                                 if (empty($row['description'])) {
  594.                                         if (empty($row['title'])) {
  595.                                                 $desc = '<p><i>'._L('No description for this object available').'</i></p>';
  596.                                         } else {
  597.                                                 $desc = $row['title'];
  598.                                         }
  599.                                 } else {
  600.                                         $desc = self::objDescription($row['description']);
  601.                                 }
  602.  
  603.                                 if ($obj->userHasWriteRights()) {
  604.                                         $rand = ++self::$crudCounter;
  605.                                         $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>';
  606.                                         $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
  607.                                         $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($row['title']).'"><br><br>'._L('Description').':<br>';
  608.                                         $desc .= self::showMCE('description', $row['description']);
  609.                                         $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>';
  610.                                         $desc .= '</div>';
  611.                                         $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>';
  612.                                 }
  613.                         } else {
  614.                                 $desc = '';
  615.                         }
  616.  
  617.                         // ---
  618.  
  619.                         if (strpos($out['text'], '%%DESC%%') !== false)
  620.                                 $out['text'] = str_replace('%%DESC%%',    $desc,                              $out['text']);
  621.                         if (strpos($out['text'], '%%CRUD%%') !== false)
  622.                                 $out['text'] = str_replace('%%CRUD%%',    self::showCrud($id),                $out['text']);
  623.                         if (strpos($out['text'], '%%RA_INFO%%') !== false)
  624.                                 $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($row['ra_email']), $out['text']);
  625.  
  626.                         $alt_ids = $obj->getAltIds();
  627.                         if (count($alt_ids) > 0) {
  628.                                 $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>';
  629.                                 foreach ($alt_ids as $alt_id) {
  630.                                         $ns = $alt_id->getNamespace();
  631.                                         $aid = $alt_id->getId();
  632.                                         $aiddesc = $alt_id->getDescription();
  633.                                         $out['text'] .= "$aiddesc <code>$ns:$aid</code><br>";
  634.                                 }
  635.                         }
  636.  
  637.                         foreach (OIDplus::getPagePlugins() as $plugin) {
  638.                                 if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.2')) {
  639.                                         $plugin->modifyContent($id, $out['title'], $out['icon'], $out['text']);
  640.                                 }
  641.                         }
  642.                 }
  643.         }
  644.  
  645.         private function publicSitemap_rec($json, &$out) {
  646.                 foreach ($json as $x) {
  647.                         if (isset($x['id']) && $x['id']) {
  648.                                 $out[] = $x['id'];
  649.                         }
  650.                         if (isset($x['children'])) {
  651.                                 $this->publicSitemap_rec($x['children'], $out);
  652.                         }
  653.                 }
  654.         }
  655.  
  656.         public function publicSitemap(&$out) {
  657.                 $json = array();
  658.                 $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, true/*display all*/);
  659.                 $this->publicSitemap_rec($json, $out);
  660.         }
  661.  
  662.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  663.                 if ($nonjs) {
  664.                         $json[] = array(
  665.                                 'id' => 'oidplus:system',
  666.                                 'icon' => OIDplus::webpath(__DIR__).'system.png',
  667.                                 'text' => _L('System')
  668.                         );
  669.  
  670.                         $parent = '';
  671.                         $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($req_goto));
  672.                         while ($row = $res->fetch_object()) {
  673.                                 $parent = $row->parent;
  674.                         }
  675.  
  676.                         $objTypesChildren = array();
  677.                         foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  678.                                 $icon = $this->get_treeicon_root($ot);
  679.  
  680.                                 $json[] = array(
  681.                                         'id' => $ot::root(),
  682.                                         'icon' => $icon,
  683.                                         'text' => $ot::objectTypeTitle()
  684.                                 );
  685.  
  686.                                 try {
  687.                                         $tmp = OIDplusObject::parse($req_goto);
  688.                                 } catch (Exception $e) {
  689.                                         $tmp = null;
  690.                                 }
  691.                                 if (!is_null($tmp) && ($ot == get_class($tmp))) {
  692.                                         // 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
  693.                                         //       on the other hand, for giving search engines content, this is good enough
  694.                                         if (empty($parent)) {
  695.                                                 $res = OIDplus::db()->query("select * from ###objects where " .
  696.                                                                             "parent = ? or " .
  697.                                                                             "id = ? " .
  698.                                                                             "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto));
  699.                                         } else {
  700.                                                 $res = OIDplus::db()->query("select * from ###objects where " .
  701.                                                                             "parent = ? or " .
  702.                                                                             "id = ? or " .
  703.                                                                             "id = ? ".
  704.                                                                             "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto, $parent));
  705.                                         }
  706.  
  707.                                         $z_used = 0;
  708.                                         $y_used = 0;
  709.                                         $x_used = 0;
  710.                                         $stufe = 0;
  711.                                         $menu_entries = array();
  712.                                         $stufen = array();
  713.                                         while ($row = $res->fetch_object()) {
  714.                                                 $obj = OIDplusObject::parse($row->id);
  715.                                                 if (is_null($obj)) continue; // might happen if the objectType is not available/loaded
  716.                                                 if (!$obj->userHasReadRights()) continue;
  717.                                                 $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title);
  718.  
  719.                                                 if ($row->id == $parent) { $stufe=0; $z_used++; }
  720.                                                 if ($row->id == $req_goto) { $stufe=1; $y_used++; }
  721.                                                 if ($row->parent == $req_goto) { $stufe=2; $x_used++; }
  722.  
  723.                                                 $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0);
  724.                                                 $menu_entries[] = $menu_entry;
  725.                                                 $stufen[] = $stufe;
  726.                                         }
  727.                                         if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1;
  728.                                         if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1;
  729.                                         if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1;
  730.                                         $json = array_merge($json, $menu_entries);
  731.                                 }
  732.                         }
  733.  
  734.                         return true;
  735.                 } else {
  736.                         if ($req_goto === true) {
  737.                                 $goto_path = true; // display everything recursively
  738.                         } else if (isset($req_goto)) {
  739.                                 $goto = $req_goto;
  740.                                 $path = array();
  741.                                 while (true) {
  742.                                         $path[] = $goto;
  743.                                         $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($goto));
  744.                                         if (!$res->any()) break;
  745.                                         $row = $res->fetch_array();
  746.                                         $goto = $row['parent'];
  747.                                         if ($goto == '') continue;
  748.                                 }
  749.  
  750.                                 $goto_path = array_reverse($path);
  751.                         } else {
  752.                                 $goto_path = null;
  753.                         }
  754.  
  755.                         $objTypesChildren = array();
  756.                         foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  757.                                 $icon = $this->get_treeicon_root($ot);
  758.  
  759.                                 $child = array('id' => $ot::root(),
  760.                                                'text' => $ot::objectTypeTitle(),
  761.                                                'state' => array("opened" => true),
  762.                                                'icon' => $icon,
  763.                                                'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path)
  764.                                                );
  765.                                 if (!file_exists($child['icon'])) $child['icon'] = null; // default icon (folder)
  766.                                 $objTypesChildren[] = $child;
  767.                         }
  768.  
  769.                         $json[] = array(
  770.                                 'id' => "oidplus:system",
  771.                                 'text' => _L('Objects'),
  772.                                 'state' => array(
  773.                                         "opened" => true,
  774.                                         // "selected" => true)  // "selected" is buggy:
  775.                                         // 1) The select-event will not be triggered upon loading
  776.                                         // 2) The nodes directly blow cannot be opened (loading infinite time)
  777.                                 ),
  778.                                 'icon' => OIDplus::webpath(__DIR__).'system.png',
  779.                                 'children' => $objTypesChildren
  780.                         );
  781.  
  782.                         return true;
  783.                 }
  784.         }
  785.  
  786.         public function tree_search($request) {
  787.                 $ary = array();
  788.                 if ($obj = OIDplusObject::parse($request)) {
  789.                         if ($obj->userHasReadRights()) {
  790.                                 do {
  791.                                         $ary[] = $obj->nodeId();
  792.                                 } while ($obj = $obj->getParent());
  793.                                 $ary = array_reverse($ary);
  794.                         }
  795.                 }
  796.                 return $ary;
  797.         }
  798.  
  799.         private static $crudCounter = 0;
  800.  
  801.         protected static function showCrud($parent='oid:') {
  802.                 $items_total = 0;
  803.                 $items_hidden = 0;
  804.  
  805.                 $objParent = OIDplusObject::parse($parent);
  806.                 $parentNS = $objParent::ns();
  807.  
  808.                 // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers
  809.                 $no_asn1 = array(
  810.                         'oid:1.3.6.1.4.1',
  811.                         'oid:1.3.6.1.4.1.37476.9000',
  812.                         'oid:1.3.6.1.4.1.37553.8.8',
  813.                         'oid:2.16.276.1',
  814.                         //'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
  815.                         //'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.
  816.                 );
  817.  
  818.                 // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels
  819.                 $no_iri = array(
  820.                         'oid:1.2.250.1',
  821.                         'oid:1.3.6.1.4.1',
  822.                         'oid:1.3.6.1.4.1.37476.9000',
  823.                         'oid:1.3.6.1.4.1.37553.8.8',
  824.                         'oid:2.16.276.1',
  825.                         'oid:2.25'
  826.                 );
  827.  
  828.                 $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true));
  829.                 $accepts_iri  = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true));
  830.  
  831.                 $result = OIDplus::db()->query("select o.*, r.ra_name " .
  832.                                                "from ###objects o " .
  833.                                                "left join ###ra r on r.email = o.ra_email " .
  834.                                                "where parent = ? " .
  835.                                                "order by ".OIDplus::db()->natOrder('id'), array($parent));
  836.  
  837.                 $rows = array();
  838.                 while ($row = $result->fetch_object()) {
  839.                         $obj = OIDplusObject::parse($row->id);
  840.                         $rows[] = array($obj,$row);
  841.                 }
  842.  
  843.                 $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid');
  844.  
  845.                 $output = '';
  846.                 $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  847.                 $output .= '<table class="table table-bordered table-striped">';
  848.                 $output .= '    <tr>';
  849.                 $output .= '         <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>';
  850.                 if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
  851.                         $output .= '         <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>';
  852.                 }
  853.                 if ($parentNS == 'oid') {
  854.                         if ($accepts_asn1) $output .= '      <th>'._L('ASN.1 IDs (comma sep.)').'</th>';
  855.                         if ($accepts_iri)  $output .= '      <th>'._L('IRI IDs (comma sep.)').'</th>';
  856.                 }
  857.                 $output .= '         <th>'._L('RA').'</th>';
  858.                 $output .= '         <th>'._L('Comment').'</th>';
  859.                 if ($objParent->userHasWriteRights()) {
  860.                         $output .= '         <th>'._L('Hide').'</th>';
  861.                         $output .= '         <th>'._L('Update').'</th>';
  862.                         $output .= '         <th>'._L('Delete').'</th>';
  863.                 }
  864.                 $output .= '         <th>'._L('Created').'</th>';
  865.                 $output .= '         <th>'._L('Updated').'</th>';
  866.                 $output .= '    </tr>';
  867.  
  868.                 foreach ($rows as list($obj,$row)) {
  869.                         $items_total++;
  870.                         if (!$obj->userHasReadRights()) {
  871.                                 $items_hidden++;
  872.                                 continue;
  873.                         }
  874.  
  875.                         $show_id = $obj->crudShowId($objParent);
  876.  
  877.                         $asn1ids = array();
  878.                         $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id));
  879.                         while ($row2 = $res2->fetch_array()) {
  880.                                 $asn1ids[] = $row2['name'];
  881.                         }
  882.  
  883.                         $iris = array();
  884.                         $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id));
  885.                         while ($row2 = $res2->fetch_array()) {
  886.                                 $iris[] = $row2['name'];
  887.                         }
  888.  
  889.                         $date_created = explode(' ', $row->created)[0] == '0000-00-00' ? '' : explode(' ', $row->created)[0];
  890.                         $date_updated = explode(' ', $row->updated)[0] == '0000-00-00' ? '' : explode(' ', $row->updated)[0];
  891.  
  892.                         $output .= '<tr>';
  893.                         $output .= '     <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>';
  894.                         if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) {
  895.                                 // To save space horizontal space, the WEIDs were written below the OIDs
  896.                                 $output .= '<br>'.$obj->getWeidNotation(true);
  897.                         }
  898.                         $output .= '</td>';
  899.                         if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
  900.                                 $output .= '    <td>'.htmlentities($obj->weidArc()).'</td>';
  901.                         }
  902.                         if ($objParent->userHasWriteRights()) {
  903.                                 if ($parentNS == 'oid') {
  904.                                         if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>';
  905.                                         if ($accepts_iri)  $output .= '     <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>';
  906.                                 }
  907.                                 $output .= '     <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email).'"></td>';
  908.                                 $output .= '     <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment).'"></td>';
  909.                                 $output .= '     <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>';
  910.                                 $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>';
  911.                                 $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>';
  912.                                 $output .= '     <td>'.$date_created.'</td>';
  913.                                 $output .= '     <td>'.$date_updated.'</td>';
  914.                         } else {
  915.                                 if ($parentNS == 'oid') {
  916.                                         if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>';
  917.                                         if ($iris == '') $iris = '<i>'._L('(none)').'</i>';
  918.                                         $asn1ids_ext = array();
  919.                                         foreach ($asn1ids as $asn1id) {
  920.                                                 $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>';
  921.                                         }
  922.                                         if ($accepts_asn1) $output .= '     <td>'.implode(', ', $asn1ids_ext).'</td>';
  923.                                         if ($accepts_iri)  $output .= '     <td>'.implode(', ', $iris).'</td>';
  924.                                 }
  925.                                 $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>';
  926.                                 $output .= '     <td>'.htmlentities($row->comment).'</td>';
  927.                                 $output .= '     <td>'.$date_created.'</td>';
  928.                                 $output .= '     <td>'.$date_updated.'</td>';
  929.                         }
  930.                         $output .= '</tr>';
  931.                 }
  932.  
  933.                 $result = OIDplus::db()->query("select * from ###objects where id = ?", array($parent));
  934.                 $parent_ra_email = $result->any() ? $result->fetch_object()->ra_email : '';
  935.  
  936.                 // "Create OID" row
  937.                 if ($objParent->userHasWriteRights()) {
  938.                         $output .= '<tr>';
  939.                         $prefix = is_null($objParent) ? '' : $objParent->crudInsertPrefix();
  940.  
  941.                         $suffix = is_null($objParent) ? '' : $objParent->crudInsertSuffix();
  942.                         foreach (OIDplus::getObjectTypePlugins() as $plugin) {
  943.                                 if (($plugin::getObjectTypeClassName()::ns() == $parentNS) && $plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.6')) {
  944.                                         $suffix .= $plugin->gridGeneratorLinks($objParent);
  945.                                 }
  946.                         }
  947.  
  948.                         if ($parentNS == 'guid') {
  949.                                 $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>';
  950.                         } else if ($parentNS == 'oid') {
  951.                                 // 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
  952.                                 if ($objParent->nodeId() === 'oid:2.25') {
  953.                                         $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
  954.                                         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!
  955.                                 } else if ($objParent->isRoot()) {
  956.                                         $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
  957.                                         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)
  958.                                 } else {
  959.                                         if ($enable_weid_presentation) {
  960.                                                 $output .= '     <td>'.$prefix.' <input oninput="OIDplusPagePublicObjects.frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
  961.                                                 $output .= '     <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>';
  962.                                         } else {
  963.                                                 $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
  964.                                         }
  965.                                 }
  966.                         } else {
  967.                                 $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
  968.                         }
  969.                         if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids" value=""></td>';
  970.                         if ($accepts_iri)  $output .= '     <td><input type="text" id="iris" value=""></td>';
  971.                         $output .= '     <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email).'"></td>';
  972.                         $output .= '     <td><input type="text" id="comment" value=""></td>';
  973.                         $output .= '     <td><input type="checkbox" id="hide"></td>';
  974.                         $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>';
  975.                         $output .= '     <td></td>';
  976.                         $output .= '     <td></td>';
  977.                         $output .= '     <td></td>';
  978.                         $output .= '</tr>';
  979.                 } else {
  980.                         if ($items_total-$items_hidden == 0) {
  981.                                 $cols = ($parentNS == 'oid') ? 7 : 5;
  982.                                 if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
  983.                                         $cols++;
  984.                                 }
  985.                                 $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>';
  986.                         }
  987.                 }
  988.  
  989.                 $output .= '</table>';
  990.                 $output .= '</div></div>';
  991.  
  992.                 if ($items_hidden == 1) {
  993.                         $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
  994.                 } else if ($items_hidden > 1) {
  995.                         $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
  996.                 }
  997.  
  998.                 return $output;
  999.         }
  1000.  
  1001.         protected static function objDescription($html) {
  1002.                 // We allow HTML, but no hacking
  1003.                 $html = anti_xss($html);
  1004.  
  1005.                 return trim_br($html);
  1006.         }
  1007.  
  1008.         // 'quickbars' added 11 July 2019: Disabled because of two problems:
  1009.         //                                 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus
  1010.         //                                 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit
  1011.         // 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core.
  1012.         // 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar)
  1013.         // 'legacyoutput' added 24 September 2021, because it is declared as deprecated
  1014.         // 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0
  1015.         // 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium")
  1016.         public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc');
  1017.  
  1018.         protected static function showMCE($name, $content) {
  1019.                 $mce_plugins = array();
  1020.                 foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */
  1021.                         $mce_plugins[] = basename($m);
  1022.                 }
  1023.  
  1024.                 foreach (self::$exclude_tinymce_plugins as $exclude) {
  1025.                         $index = array_search($exclude, $mce_plugins);
  1026.                         if ($index !== false) unset($mce_plugins[$index]);
  1027.                 }
  1028.  
  1029.                 $oidplusLang = OIDplus::getCurrentLang();
  1030.  
  1031.                 $langCandidates = array(
  1032.                         strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE
  1033.                         strtolower(substr($oidplusLang,0,2)) // de
  1034.                 );
  1035.                 $tinyMCELang = '';
  1036.                 foreach ($langCandidates as $candidate) {
  1037.                         if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) {
  1038.                                 $tinyMCELang = $candidate;
  1039.                                 break;
  1040.                         }
  1041.                 }
  1042.  
  1043.                 $out = '<script>
  1044.                                 tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce";
  1045.                                 tinymce.init({
  1046.                                         document_base_url: "'.OIDplus::webpath().'",
  1047.                                         selector: "#'.$name.'",
  1048.                                         height: 200,
  1049.                                         statusbar: false,
  1050. //                                      menubar:false,
  1051. //                                      toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect",
  1052.                                         toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
  1053.                                         plugins: "'.implode(' ', $mce_plugins).'",
  1054.                                         mobile: {
  1055.                                                 theme: "mobile",
  1056.                                                 toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
  1057.                                                 plugins: "'.implode(' ', $mce_plugins).'"
  1058.                                         }
  1059.                                         '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').'
  1060.                                         '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath().'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').'
  1061.                                 });
  1062.  
  1063.                                 pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]);
  1064.                                 pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]);
  1065.                         </script>';
  1066.  
  1067.                 $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?
  1068.  
  1069.                 $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>';
  1070.  
  1071.                 return $out;
  1072.         }
  1073.  
  1074.         public function implementsFeature($id) {
  1075.                 if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested()
  1076.                 return false;
  1077.         }
  1078.  
  1079.         public function oobeRequested(): bool {
  1080.                 // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
  1081.  
  1082.                 return OIDplus::config()->getValue('oobe_objects_done') == '0';
  1083.         }
  1084.  
  1085.         public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ {
  1086.                 // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
  1087.  
  1088.                 echo '<p><u>'._L('Step %1: Enable/Disable object type plugins',$step).'</u></p>';
  1089.                 echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>';
  1090.  
  1091.                 $enabled_ary = array();
  1092.  
  1093.                 foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  1094.                         echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
  1095.                         if (isset($_REQUEST['sent'])) {
  1096.                                 if (isset($_REQUEST['enable_ot_'.$ot::ns()])) {
  1097.                                         echo ' checked';
  1098.                                         $enabled_ary[] = $ot::ns();
  1099.                                 }
  1100.                         } else {
  1101.                                 echo ' checked';
  1102.                         }
  1103.                         echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
  1104.                 }
  1105.  
  1106.                 foreach (OIDplus::getDisabledObjectTypes() as $ot) {
  1107.                         echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
  1108.                         if (isset($_REQUEST['sent'])) {
  1109.                                 if (isset($_REQUEST['enable_ot_'.$ot::ns()])) {
  1110.                                         echo ' checked';
  1111.                                         $enabled_ary[] = $ot::ns();
  1112.                                 }
  1113.                         } else {
  1114.                                 echo ''; // <-- difference
  1115.                         }
  1116.                         echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
  1117.                 }
  1118.  
  1119.                 $msg = '';
  1120.                 if ($do_edits) {
  1121.                         try {
  1122.                                 OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary));
  1123.                                 OIDplus::config()->setValue('oobe_objects_done', '1');
  1124.                         } catch (Exception $e) {
  1125.                                 $msg = $e->getMessage();
  1126.                                 $errors_happened = true;
  1127.                         }
  1128.                 }
  1129.  
  1130.                 echo ' <font color="red"><b>'.$msg.'</b></font>';
  1131.         }
  1132.  
  1133. }
  1134.