Subversion Repositories oidplus

Rev

Rev 1266 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusPageAdminWellKnownOIDs extends OIDplusPagePluginAdmin {
  27.  
  28.         /**
  29.          * @param bool $html
  30.          * @return void
  31.          */
  32.         public function init(bool $html=true) {
  33.                 // Nothing
  34.         }
  35.  
  36.         /**
  37.          * @param string $id
  38.          * @param array $out
  39.          * @param bool $handled
  40.          * @return void
  41.          * @throws OIDplusException
  42.          */
  43.         public function gui(string $id, array &$out, bool &$handled) {
  44.                 if ($id === 'oidplus:well_known_oids') {
  45.                         $handled = true;
  46.                         $out['title'] = _L('Well known OIDs');
  47.                         $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
  48.  
  49.                         if (!OIDplus::authUtils()->isAdminLoggedIn()) {
  50.                                 throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
  51.                         }
  52.  
  53.                         $out['text']  = '<p>'._L('Well-known OIDs are OIDs of Registration Authorities which are assigning OIDs to customers, i.e. they are most likely to be used by OIDplus users as their root OID. Well-known OIDs have the following purposes:').'<ol>';
  54.                         $out['text'] .= '<li>'._L('When a new OIDplus user creates his root OID into OIDplus, then the ASN.1 identifiers and Unicode labels of the superior OIDs are automatically added.').'</li>';
  55.                         if (OIDplus::getEditionInfo()['vendor'] == 'ViaThinkSoft') {
  56.                                 $out['text'] .= '<li>'._L('In the automatic oid-info.com publishing, well-known OIDs will not be transmitted (because it is unlikely that RAs of well-known OIDs will be using OIDplus in combination with automatic publishing to oid-info.com). Instead, all children inside these well-known OIDs are most likely to be yours, so these will be reported to oid-info.com instead.').'</li>';
  57.                         }
  58.                         // $out['text'] .= '<li>'._L('In OID-WHOIS, if a user requests information about an unknown OID which is inside a well-known OID, then OID-WHOIS will output information at which place more information can be retrieved from.').'</li>';
  59.                         $out['text'] .= '</ol></p>';
  60.  
  61.                         $out['text'] .= '<p><b>'._L('How to edit these IDs?').'</b> '._L('These ID names can only be edited in the database directly (Tables ###asn1id and ###iri). Usually, there is no need to do this, though.').'</p>';
  62.                         $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  63.                         $out['text'] .= '<table class="table table-bordered table-striped">';
  64.                         $out['text'] .= '<thead>';
  65.                         $out['text'] .= '       <tr>';
  66.                         $out['text'] .= '            <th>'._L('OID').'</th>';
  67.                         $out['text'] .= '            <th>'._L('ASN.1 identifiers (comma sep.)').'</th>';
  68.                         $out['text'] .= '            <th>'._L('IRI identifiers (comma sep.)').'</th>';
  69.                         $out['text'] .= '       </tr>';
  70.                         $out['text'] .= '</thead>';
  71.                         $out['text'] .= '<tbody>';
  72.  
  73.                         $asn1ids = array();
  74.                         $res = OIDplus::db()->query("select oid, name, standardized from ###asn1id where well_known = ?", array(true));
  75.                         while ($row = $res->fetch_array()) {
  76.                                 $oid = $row['oid'];
  77.                                 if (!isset($asn1ids[$oid])) $asn1ids[$oid] = array();
  78.                                 $asn1ids[$oid][] = $row['name'].($row['standardized'] ? ' ('._L('standardized').')' : '');
  79.                         }
  80.  
  81.                         $iris = array();
  82.                         $res = OIDplus::db()->query("select oid, name, longarc from ###iri where well_known = ?", array(true));
  83.                         while ($row = $res->fetch_array()) {
  84.                                 $oid = $row['oid'];
  85.                                 if (!isset($iris[$oid])) $iris[$oid] = array();
  86.                                 $iris[$oid][] = $row['name'].($row['longarc'] ? ' ('._L('long arc').')' : '');
  87.                         }
  88.  
  89.                         $oids = array_merge(array_keys($asn1ids), array_keys($iris));
  90.                         $oids = array_unique($oids);
  91.                         natsort($oids);
  92.  
  93.                         foreach ($oids as $oid) {
  94.                                 $local_asn1ids = $asn1ids[$oid] ?? array();
  95.                                 $local_iris = $iris[$oid] ?? array();
  96.                                 $out['text'] .= '<tr>';
  97.                                 $out['text'] .= '     <td>'.htmlentities(explode(':', $oid)[1]).'</td>';
  98.                                 $out['text'] .= '     <td>'.htmlentities(implode(', ', $local_asn1ids)).'</td>';
  99.                                 $out['text'] .= '     <td>'.htmlentities(implode(', ', $local_iris)).'</td>';
  100.                                 $out['text'] .= '</tr>';
  101.                         }
  102.  
  103.                         $out['text'] .= '</tbody>';
  104.                         $out['text'] .= '</table>';
  105.                         $out['text'] .= '</div></div>';
  106.                 }
  107.         }
  108.  
  109.         /**
  110.          * @param array $json
  111.          * @param string|null $ra_email
  112.          * @param bool $nonjs
  113.          * @param string $req_goto
  114.          * @return bool
  115.          * @throws OIDplusException
  116.          */
  117.         public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
  118.                 if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
  119.  
  120.                 if (file_exists(__DIR__.'/img/main_icon16.png')) {
  121.                         $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
  122.                 } else {
  123.                         $tree_icon = null; // default icon (folder)
  124.                 }
  125.  
  126.                 $json[] = array(
  127.                         'id' => 'oidplus:well_known_oids',
  128.                         'icon' => $tree_icon,
  129.                         'text' => _L('Well known OIDs')
  130.                 );
  131.  
  132.                 return true;
  133.         }
  134.  
  135.         /**
  136.          * @param string $request
  137.          * @return array|false
  138.          */
  139.         public function tree_search(string $request) {
  140.                 return false;
  141.         }
  142. }
  143.