Subversion Repositories oidplus

Rev

Rev 1130 | 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 Frdlweb\OIDplus;
  21.  
  22. use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2;
  23. use ViaThinkSoft\OIDplus\OIDplus;
  24. use ViaThinkSoft\OIDplus\OIDplusException;
  25. use ViaThinkSoft\OIDplus\OIDplusPagePluginPublic;
  26.  
  27. // phpcs:disable PSR1.Files.SideEffects
  28. \defined('INSIDE_OIDPLUS') or die;
  29. // phpcs:enable PSR1.Files.SideEffects
  30.  
  31. class OIDplusPagePublicRdap extends OIDplusPagePluginPublic
  32.         implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2 /* modifyContent */
  33. {
  34.  
  35.         /**
  36.          * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2
  37.          * @param string $id
  38.          * @param string $title
  39.          * @param string $icon
  40.          * @param string $text
  41.          * @return void
  42.          * @throws \ViaThinkSoft\OIDplus\OIDplusException
  43.          */
  44.         public function modifyContent(string $id, string &$title, string &$icon, string &$text) {
  45.             $text .= '<br /> <a href="'.OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE)
  46.                         .'rdap/rdap.php?query='.urlencode($id).'" class="gray_footer_font" target="_blank">'._L('RDAP').'</a>';
  47.         }
  48.  
  49.         /**
  50.          * @param string $request
  51.          * @return bool
  52.          * @throws OIDplusException
  53.          */
  54.         public function handle404(string $request): bool {
  55.                 $namespaces = array();
  56.                 foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  57.                         $namespaces[] = $ot::ns();
  58.                 }
  59.                 foreach ($namespaces as $ns) {
  60.                         // Note: This only works if OIDplus is located at the domain root (because $request is relative to the domain)
  61.                         if (!preg_match('@^/'.preg_quote($ns,'@').'/(.+)$@', $request, $m)) return false;
  62.                         $oid = $m[1];
  63.                         $query = "$ns:$oid";
  64.                         $x = new OIDplusRDAP();
  65.                         list($out_content, $out_type) = $x->rdapQuery($query);
  66.                         if ($out_type) header('Content-Type:'.$out_type);
  67.                         echo $out_content;
  68.                         die();
  69.                         // return true;
  70.                 }
  71.                 return false;
  72.         }
  73.  
  74. }
  75.