Subversion Repositories oidplus

Rev

Rev 1206 | 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 - 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.                         $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>';
  56.                         // $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>';
  57.                         $out['text'] .= '</ol></p>';
  58.  
  59.                         $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>';
  60.                         $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  61.                         $out['text'] .= '<table class="table table-bordered table-striped">';
  62.                         $out['text'] .= '<thead>';
  63.                         $out['text'] .= '       <tr>';
  64.                         $out['text'] .= '            <th>'._L('OID').'</th>';
  65.                         $out['text'] .= '            <th>'._L('ASN.1 identifiers (comma sep.)').'</th>';
  66.                         $out['text'] .= '            <th>'._L('IRI identifiers (comma sep.)').'</th>';
  67.                         $out['text'] .= '       </tr>';
  68.                         $out['text'] .= '</thead>';
  69.                         $out['text'] .= '<tbody>';
  70.  
  71.                         $asn1ids = array();
  72.                         $res = OIDplus::db()->query("select oid, name, standardized from ###asn1id where well_known = ?", array(true));
  73.                         while ($row = $res->fetch_array()) {
  74.                                 $oid = $row['oid'];
  75.                                 if (!isset($asn1ids[$oid])) $asn1ids[$oid] = array();
  76.                                 $asn1ids[$oid][] = $row['name'].($row['standardized'] ? ' ('._L('standardized').')' : '');
  77.                         }
  78.  
  79.                         $iris = array();
  80.                         $res = OIDplus::db()->query("select oid, name, longarc from ###iri where well_known = ?", array(true));
  81.                         while ($row = $res->fetch_array()) {
  82.                                 $oid = $row['oid'];
  83.                                 if (!isset($iris[$oid])) $iris[$oid] = array();
  84.                                 $iris[$oid][] = $row['name'].($row['longarc'] ? ' ('._L('long arc').')' : '');
  85.                         }
  86.  
  87.                         $oids = array_merge(array_keys($asn1ids), array_keys($iris));
  88.                         $oids = array_unique($oids);
  89.                         natsort($oids);
  90.  
  91.                         foreach ($oids as $oid) {
  92.                                 $local_asn1ids = $asn1ids[$oid] ?? array();
  93.                                 $local_iris = $iris[$oid] ?? array();
  94.                                 $out['text'] .= '<tr>';
  95.                                 $out['text'] .= '     <td>'.htmlentities(explode(':', $oid)[1]).'</td>';
  96.                                 $out['text'] .= '     <td>'.htmlentities(implode(', ', $local_asn1ids)).'</td>';
  97.                                 $out['text'] .= '     <td>'.htmlentities(implode(', ', $local_iris)).'</td>';
  98.                                 $out['text'] .= '</tr>';
  99.                         }
  100.  
  101.                         $out['text'] .= '</tbody>';
  102.                         $out['text'] .= '</table>';
  103.                         $out['text'] .= '</div></div>';
  104.                 }
  105.         }
  106.  
  107.         /**
  108.          * @param array $json
  109.          * @param string|null $ra_email
  110.          * @param bool $nonjs
  111.          * @param string $req_goto
  112.          * @return bool
  113.          * @throws OIDplusException
  114.          */
  115.         public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
  116.                 if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
  117.  
  118.                 if (file_exists(__DIR__.'/img/main_icon16.png')) {
  119.                         $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
  120.                 } else {
  121.                         $tree_icon = null; // default icon (folder)
  122.                 }
  123.  
  124.                 $json[] = array(
  125.                         'id' => 'oidplus:well_known_oids',
  126.                         'icon' => $tree_icon,
  127.                         'text' => _L('Well known OIDs')
  128.                 );
  129.  
  130.                 return true;
  131.         }
  132.  
  133.         /**
  134.          * @param string $request
  135.          * @return array|false
  136.          */
  137.         public function tree_search(string $request) {
  138.                 return false;
  139.         }
  140. }
  141.