Subversion Repositories oidplus

Rev

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

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2021 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('INSIDE_OIDPLUS')) die();
  21.  
  22. class OIDplusPagePublicWhois extends OIDplusPagePluginPublic {
  23.  
  24.         public function init($html=true) {
  25.                 OIDplus::config()->prepareConfigKey('whois_auth_token',                       'OID-over-WHOIS authentication token to display confidential data', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  26.                         $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value);
  27.                         if ($test_value != '') {
  28.                                 throw new OIDplusException(_L('Only characters and numbers are allowed as authentication token.'));
  29.                         }
  30.                 });
  31.                 OIDplus::config()->prepareConfigKey('webwhois_output_format_spacer',          'WebWHOIS: Spacer', '2', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  32.                         if (!is_numeric($value) || ($value < 0)) {
  33.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  34.                         }
  35.                 });
  36.                 OIDplus::config()->prepareConfigKey('webwhois_output_format_max_line_length', 'WebWHOIS: Max line length', '80', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  37.                         if (!is_numeric($value) || ($value < 0)) {
  38.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  39.                         }
  40.                 });
  41.         }
  42.  
  43.         private function getExampleId() {
  44.                 $firsts = array();
  45.                 $first_ns = null;
  46.                 foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  47.                         if (is_null($first_ns)) $first_ns = $ot::ns();
  48.                         $res = OIDplus::db()->query("SELECT id FROM ###objects WHERE parent = ? ORDER BY id", array($ot::ns().':'));
  49.                         if ($row = $res->fetch_array())
  50.                                 $firsts[$ot::ns()] = $row['id'];
  51.                 }
  52.                 if (count($firsts) == 0) {
  53.                         return 'oid:2.999';
  54.                 } elseif (isset($firsts['oid'])) {
  55.                         return  $firsts['oid'];
  56.                 } else {
  57.                         return  $firsts[$first_ns];
  58.                 }
  59.         }
  60.  
  61.         public function gui($id, &$out, &$handled) {
  62.                 if (explode('$',$id)[0] == 'oidplus:whois') {
  63.                         $handled = true;
  64.  
  65.                         $example = $this->getExampleId();
  66.  
  67.                         $out['title'] = _L('Web WHOIS');
  68.                         $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
  69.  
  70.                         $out['text']  = '';
  71.                         $out['text'] .= '<p>'._L('With the web based whois service, you can query object information in a machine-readable format.').'</p>';
  72.  
  73.                         $out['text'] .= '<form action="'.OIDplus::webpath(__DIR__).'whois/webwhois.php" method="GET" target="_blank">';
  74.                         $out['text'] .= '<br>'._L('Output format').':<br><fieldset id="whois_format">';
  75.                         $out['text'] .= '    <input type="radio" id="txt" name="format" value="txt" checked onclick="refresh_whois_url_bar()">';
  76.                         $out['text'] .= '    <label for="txt"> '._L('Text format').'</label> ('._L('RFC draft').': <a target="_blank" href="'.OIDplus::webpath(__DIR__).'whois/rfc/draft-viathinksoft-oidwhois-00.txt">'._L('TXT').'</a> | <a target="_blank" href="'.OIDplus::webpath(__DIR__).'whois/rfc/draft-viathinksoft-oidwhois-00.nroff">'._L('NROFF').'</a>)<br>';
  77.                         $out['text'] .= '    <input type="radio" id="json" name="format" value="json" onclick="refresh_whois_url_bar()">';
  78.                         $out['text'] .= '    <label for="json"> '._L('JSON').'</label> (<a target="_blank" href="'.OIDplus::webpath(__DIR__).'whois/json_schema.json">'._L('Schema').'</a>)<br>';
  79.                         $out['text'] .= '    <input type="radio" id="xml" name="format" value="xml" onclick="refresh_whois_url_bar()">';
  80.                         $out['text'] .= '    <label for="xml"> '._L('XML').'</label> (<a target="_blank" href="'.OIDplus::webpath(__DIR__).'whois/xml_schema.xsd">'._L('Schema').'</a>)<br>';
  81.                         $out['text'] .= '</fieldset><br>';
  82.                         $out['text'] .= '       <!--<label class="padding_label">-->'._L('Query').':<!--</label>--> <input type="text" id="whois_query" name="query" value="'.htmlentities($example).'" style="width:250px" onkeyup="refresh_whois_url_bar()">';
  83.                         $out['text'] .= '       <input type="submit" value="'._L('Query').'">';
  84.                         $out['text'] .= '</form>';
  85.                         $out['text'] .= '<div id="whois_url_bar_section" style="display:none">';
  86.                         $out['text'] .= '       <p><pre id="whois_url_bar"></pre></p>';
  87.                         $out['text'] .= '       <input type="button" value="'._L('Copy to clipboard').'" onClick="copyToClipboard(whois_url_bar)">';
  88.                         $out['text'] .= '</div>';
  89.                         $out['text'] .= '<script> refresh_whois_url_bar(); </script>'; // TODO: Copy to clipboard
  90.                 }
  91.         }
  92.  
  93.         public function publicSitemap(&$out) {
  94.                 $out[] = 'oidplus:whois';
  95.         }
  96.  
  97.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  98.                 if (file_exists(__DIR__.'/treeicon.png')) {
  99.                         $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
  100.                 } else {
  101.                         $tree_icon = null; // default icon (folder)
  102.                 }
  103.  
  104.                 $json[] = array(
  105.                         'id' => 'oidplus:whois',
  106.                         'icon' => $tree_icon,
  107.                         'text' => _L('Web WHOIS')
  108.                 );
  109.  
  110.                 return true;
  111.         }
  112.  
  113.         public function implementsFeature($id) {
  114.                 if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.2') return true; // modifyContent
  115.                 return false;
  116.         }
  117.  
  118.         public function modifyContent($id, &$title, &$icon, &$text) {
  119.                 // Interface 1.3.6.1.4.1.37476.2.5.2.3.2
  120.  
  121.                 $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">'._L('Whois').'</a>';
  122.  
  123.                 $obj = OIDplusObject::parse($id);
  124.                 if ($obj->userHasParentalWriteRights()) {
  125.                         $text .= '<br><span class="gray_footer_font">'._L('OID-WHOIS Auth Token for displaying full object information: %1 (only applies if the this or superior objects are marked confidential)','<b>'.self::genWhoisAuthToken($id).'</b>').'</span>';
  126.                         $text .= '<br><span class="gray_footer_font">'._L('OID-WHOIS Auth Token for displaying full RA information: %1 (only applies if the RA has set the privacy-flag)','<b>'.self::genWhoisAuthToken('ra:'.$obj->getRaMail()).'</b>').'</span>';
  127.                 }
  128.  
  129.         }
  130.  
  131.         public function tree_search($request) {
  132.                 return false;
  133.         }
  134.  
  135.         public static function genWhoisAuthToken($id) {
  136.                 return smallhash(OIDplus::baseConfig()->getValue('SERVER_SECRET').'/WHOIS/'.$id);
  137.         }
  138. }
  139.