Subversion Repositories oidplus

Rev

Rev 279 | 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. class OIDplusPagePublicWhois extends OIDplusPagePluginPublic {
  21.  
  22.         public function action(&$handled) {
  23.                 // Nothing
  24.         }
  25.  
  26.         public function init($html=true) {
  27.                 OIDplus::config()->prepareConfigKey('whois_auth_token',                       'OID-over-WHOIS authentication token to display confidential data', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  28.                         $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value);
  29.                         if ($test_value != '') {
  30.                                 throw new OIDplusException("Only characters and numbers are allowed as authentication token.");
  31.                         }
  32.                 });
  33.                 OIDplus::config()->prepareConfigKey('webwhois_output_format_spacer',          'WebWHOIS: Spacer', 2, OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  34.                         if (!is_numeric($value) || ($value < 0)) {
  35.                                 throw new OIDplusException("Please enter a valid value.");
  36.                         }
  37.                 });
  38.                 OIDplus::config()->prepareConfigKey('webwhois_output_format_max_line_length', 'WebWHOIS: Max line length', 80, OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  39.                         if (!is_numeric($value) || ($value < 0)) {
  40.                                 throw new OIDplusException("Please enter a valid value.");
  41.                         }
  42.                 });
  43.         }
  44.  
  45.         private function getExampleId() {
  46.                 $firsts = array();
  47.                 $first_ns = null;
  48.                 foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  49.                         if (is_null($first_ns)) $first_ns = $ot::ns();
  50.                         $res = OIDplus::db()->query("SELECT id FROM ###objects WHERE parent = ? ORDER BY id", array($ot::ns().':'));
  51.                         if ($row = $res->fetch_array())
  52.                                 $firsts[$ot::ns()] = $row['id'];
  53.                 }
  54.                 if (count($firsts) == 0) {
  55.                         return 'oid:2.999';
  56.                 } elseif (isset($firsts['oid'])) {
  57.                         return  $firsts['oid'];
  58.                 } else {
  59.                         return  $firsts[$first_ns];
  60.                 }
  61.         }
  62.  
  63.         public function gui($id, &$out, &$handled) {
  64.                 if (explode('$',$id)[0] == 'oidplus:whois') {
  65.                         $handled = true;
  66.  
  67.                         $example = $this->getExampleId();
  68.  
  69.                         $out['title'] = 'Web WHOIS';
  70.                         $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
  71.  
  72.                         $out['text']  = '';
  73.                         $out['text'] .= '<p>With the web based whois service, you can query object information in a machine readable format.</p>';
  74.                         $out['text'] .= '<p>RFC draft (for Text format): <a href="'.OIDplus::webpath(__DIR__).'whois/rfc/draft-viathinksoft-oidwhois-00.txt">TXT</a> | <a href="'.OIDplus::webpath(__DIR__).'whois/rfc/draft-viathinksoft-oidwhois-00.nroff">NROFF</a></p>';
  75.                         $out['text'] .= '<form action="'.OIDplus::webpath(__DIR__).'whois/webwhois.php" method="GET">';
  76.                         $out['text'] .= '       <label class="padding_label">Format:</label><select name="format">';
  77.                         $out['text'] .= '               <option value="txt">Text (RFC pending)</option>';
  78.                         $out['text'] .= '               <option value="json">JSON</option>';
  79.                         $out['text'] .= '               <option value="xml">XML</option>';
  80.                         $out['text'] .= '       </select><br>';
  81.                         $out['text'] .= '       <label class="padding_label">Query:</label><input type="text" name="query" value="'.htmlentities($example).'" style="width:250px">';
  82.                         $out['text'] .= '       <input type="submit" value="Query">';
  83.                         $out['text'] .= '</form>';
  84.                 }
  85.         }
  86.  
  87.         public function publicSitemap(&$out) {
  88.                 $out[] = OIDplus::getSystemUrl().'?goto=oidplus:whois';
  89.         }
  90.  
  91.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  92.                 if (file_exists(__DIR__.'/treeicon.png')) {
  93.                         $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
  94.                 } else {
  95.                         $tree_icon = null; // default icon (folder)
  96.                 }
  97.  
  98.                 $json[] = array(
  99.                         'id' => 'oidplus:whois',
  100.                         'icon' => $tree_icon,
  101.                         'text' => 'Web WHOIS'
  102.                 );
  103.  
  104.                 return true;
  105.         }
  106.  
  107.         public function modifyContent($id, &$title, &$icon, &$text) {
  108.                 $text .= '<br><img src="'.OIDplus::webpath(__DIR__).'page_pictogram.png" height="15" alt=""> <a href="'.OIDplus::webpath(__DIR__).'whois/webwhois.php?query='.urlencode($id).'" class="gray_footer_font">Whois</a>';
  109.         }
  110.  
  111.         public function tree_search($request) {
  112.                 return false;
  113.         }
  114. }
  115.