Subversion Repositories oidplus

Rev

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