Rev 256 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
101 | daniel-mar | 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 | |||
112 | daniel-mar | 20 | if (!defined('IN_OIDPLUS')) die(); |
21 | |||
256 | daniel-mar | 22 | class OIDplusPagePublicWhois extends OIDplusPagePluginPublic { |
101 | daniel-mar | 23 | |
222 | daniel-mar | 24 | public static function getPluginInformation() { |
25 | $out = array(); |
||
26 | $out['name'] = 'WhoIs'; |
||
27 | $out['author'] = 'ViaThinkSoft'; |
||
28 | $out['version'] = null; |
||
29 | $out['descriptionHTML'] = null; |
||
30 | return $out; |
||
31 | } |
||
32 | |||
101 | daniel-mar | 33 | public function priority() { |
34 | return 100; |
||
35 | } |
||
36 | |||
37 | public function action(&$handled) { |
||
38 | // Nothing |
||
39 | } |
||
40 | |||
41 | public function init($html=true) { |
||
261 | daniel-mar | 42 | OIDplus::config()->prepareConfigKey('whois_auth_token', 'OID-over-WHOIS authentication token to display confidential data', '', 0, 1); |
43 | OIDplus::config()->prepareConfigKey('webwhois_output_format_spacer', 'WebWHOIS: Spacer', 2, 0, 1); |
||
44 | OIDplus::config()->prepareConfigKey('webwhois_output_format_max_line_length', 'WebWHOIS: Max line length', 80, 0, 1); |
||
101 | daniel-mar | 45 | } |
46 | |||
47 | public function cfgSetValue($name, $value) { |
||
104 | daniel-mar | 48 | if ($name == 'whois_auth_token') { |
49 | $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value); |
||
50 | if ($test_value != '') { |
||
250 | daniel-mar | 51 | throw new OIDplusException("Only characters and numbers are allowed as authentication token."); |
104 | daniel-mar | 52 | } |
53 | } |
||
261 | daniel-mar | 54 | |
55 | if ($name == 'webwhois_output_format_spacer') { |
||
56 | if (!is_numeric($value) || ($value < 0)) { |
||
57 | throw new OIDplusException("Please enter a valid value."); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | if ($name == 'webwhois_output_format_max_line_length') { |
||
62 | if (!is_numeric($value) || ($value < 0)) { |
||
63 | throw new OIDplusException("Please enter a valid value."); |
||
64 | } |
||
65 | } |
||
101 | daniel-mar | 66 | } |
67 | |||
202 | daniel-mar | 68 | private function getExampleId() { |
69 | $firsts = array(); |
||
70 | $first_ns = null; |
||
227 | daniel-mar | 71 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
202 | daniel-mar | 72 | if (is_null($first_ns)) $first_ns = $ot::ns(); |
261 | daniel-mar | 73 | $res = OIDplus::db()->query("SELECT id FROM ###objects WHERE parent = ? ORDER BY id", array($ot::ns().':')); |
236 | daniel-mar | 74 | if ($row = $res->fetch_array()) |
202 | daniel-mar | 75 | $firsts[$ot::ns()] = $row['id']; |
76 | } |
||
77 | if (count($firsts) == 0) { |
||
78 | return 'oid:2.999'; |
||
79 | } elseif (isset($firsts['oid'])) { |
||
80 | return $firsts['oid']; |
||
81 | } else { |
||
82 | return $firsts[$first_ns]; |
||
83 | } |
||
84 | } |
||
85 | |||
101 | daniel-mar | 86 | public function gui($id, &$out, &$handled) { |
87 | if (explode('$',$id)[0] == 'oidplus:whois') { |
||
88 | $handled = true; |
||
89 | |||
202 | daniel-mar | 90 | $example = $this->getExampleId(); |
91 | |||
101 | daniel-mar | 92 | $out['title'] = 'Web WHOIS'; |
241 | daniel-mar | 93 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
101 | daniel-mar | 94 | |
104 | daniel-mar | 95 | $out['text'] = ''; |
101 | daniel-mar | 96 | $out['text'] .= '<p>With the web based whois service, you can query object information in a machine readable format.</p>'; |
241 | daniel-mar | 97 | $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>'; |
98 | $out['text'] .= '<form action="'.OIDplus::webpath(__DIR__).'whois/webwhois.php" method="GET">'; |
||
201 | daniel-mar | 99 | $out['text'] .= ' <label class="padding_label">Format:</label><select name="format">'; |
100 | $out['text'] .= ' <option value="txt">Text (RFC pending)</option>'; |
||
101 | $out['text'] .= ' <option value="json">JSON</option>'; |
||
102 | $out['text'] .= ' <option value="xml">XML</option>'; |
||
103 | $out['text'] .= ' </select><br>'; |
||
202 | daniel-mar | 104 | $out['text'] .= ' <label class="padding_label">Query:</label><input type="text" name="query" value="'.htmlentities($example).'" style="width:250px">'; |
104 | daniel-mar | 105 | $out['text'] .= ' <input type="submit" value="Query">'; |
101 | daniel-mar | 106 | $out['text'] .= '</form>'; |
107 | } |
||
108 | } |
||
109 | |||
106 | daniel-mar | 110 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
101 | daniel-mar | 111 | if (file_exists(__DIR__.'/treeicon.png')) { |
241 | daniel-mar | 112 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
101 | daniel-mar | 113 | } else { |
114 | $tree_icon = null; // default icon (folder) |
||
115 | } |
||
116 | |||
117 | $json[] = array( |
||
118 | 'id' => 'oidplus:whois', |
||
119 | 'icon' => $tree_icon, |
||
120 | 'text' => 'Web WHOIS' |
||
121 | ); |
||
104 | daniel-mar | 122 | |
123 | return true; |
||
101 | daniel-mar | 124 | } |
125 | |||
126 | public function modifyContent($id, &$title, &$icon, &$text) { |
||
241 | daniel-mar | 127 | $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>'; |
101 | daniel-mar | 128 | } |
108 | daniel-mar | 129 | |
130 | public function tree_search($request) { |
||
131 | return false; |
||
132 | } |
||
101 | daniel-mar | 133 | } |