Subversion Repositories oidplus

Rev

Rev 148 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 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('IN_OIDPLUS')) die();
  21.  
  22. class OIDplusPageAdminWellKnownOIDs extends OIDplusPagePlugin {
  23.         public function type() {
  24.                 return 'admin';
  25.         }
  26.  
  27.         public function priority() {
  28.                 return 100;
  29.         }
  30.  
  31.         public function action(&$handled) {
  32.                 // Nothing
  33.         }
  34.  
  35.         public function init($html=true) {
  36.                 // Nothing
  37.         }
  38.  
  39.         public function cfgSetValue($name, $value) {
  40.                 // Nothing
  41.         }
  42.  
  43.         public function gui($id, &$out, &$handled) {
  44.                 if ($id === 'oidplus:well_known_oids') {
  45.                         $handled = true;
  46.                         $out['title'] = 'Well known OIDs';
  47.                         $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : '';
  48.  
  49.                         if (!OIDplus::authUtils()::isAdminLoggedIn()) {
  50.                                 $out['icon'] = 'img/error_big.png';
  51.                                 $out['text'] .= '<p>You need to <a '.oidplus_link('oidplus:login').'>log in</a> as administrator.</p>';
  52.                         } else {
  53.                                 $out['text'] = '<p><abbr title="These ID names can only be edited in the database directly (Tables '.OIDPLUS_TABLENAME_PREFIX.'asn1id and '.OIDPLUS_TABLENAME_PREFIX.'iri). Usually, there is no need to do this, though.">How to edit these IDs?</abbr></p>';
  54.  
  55.                                 $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  56.                                 $out['text'] .= '<table class="table table-bordered table-striped">';
  57.                                 $out['text'] .= '       <tr>';
  58.                                 $out['text'] .= '            <th>OID</th>';
  59.                                 $out['text'] .= '            <th>ASN.1 identifiers (comma sep.)</th>';
  60.                                 $out['text'] .= '            <th>IRI identifiers (comma sep.)</th>';
  61.                                 $out['text'] .= '       </tr>';
  62.  
  63.                                 $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."asn1id where well_known = 1 union select oid from ".OIDPLUS_TABLENAME_PREFIX."iri where well_known = 1 order by ".OIDplus::db()->natOrder('oid'));
  64.                                 while ($row = OIDplus::db()->fetch_array($res)) {
  65.                                         $asn1ids = array();
  66.                                         $res2 = OIDplus::db()->query("select name, standardized from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = ?", array($row['oid']));
  67.                                         while ($row2 = OIDplus::db()->fetch_array($res2)) {
  68.                                                 $asn1ids[] = $row2['name'].($row2['standardized'] ? ' (standardized)' : '');
  69.                                         }
  70.  
  71.                                         $iris = array();
  72.                                         $res2 = OIDplus::db()->query("select name, longarc from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = ?", array($row['oid']));
  73.                                         while ($row2 = OIDplus::db()->fetch_array($res2)) {
  74.                                                 $iris[] = $row2['name'].($row2['longarc'] ? ' (long arc)' : '');
  75.                                         }
  76.  
  77.                                         $out['text'] .= '<tr>';
  78.                                         $out['text'] .= '     <td>'.htmlentities(explode(':',$row['oid'])[1]).'</td>';
  79.                                         $out['text'] .= '     <td>'.htmlentities(implode(', ', $asn1ids)).'</td>';
  80.                                         $out['text'] .= '     <td>'.htmlentities(implode(', ', $iris)).'</td>';
  81.                                         $out['text'] .= '</tr>';
  82.                                 }
  83.  
  84.                                 $out['text'] .= '</table>';
  85.                                 $out['text'] .= '</div></div>';
  86.                         }
  87.                 }
  88.         }
  89.  
  90.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  91.                 if (file_exists(__DIR__.'/treeicon.png')) {
  92.                         $tree_icon = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/treeicon.png';
  93.                 } else {
  94.                         $tree_icon = null; // default icon (folder)
  95.                 }
  96.  
  97.                 $json[] = array(
  98.                         'id' => 'oidplus:well_known_oids',
  99.                         'icon' => $tree_icon,
  100.                         'text' => 'Well known OIDs'
  101.                 );
  102.  
  103.                 return true;
  104.         }
  105.  
  106.         public function tree_search($request) {
  107.                 return false;
  108.         }
  109. }
  110.  
  111. OIDplus::registerPagePlugin(new OIDplusPageAdminWellKnownOIDs());
  112.