Subversion Repositories oidplus

Rev

Rev 1081 | Rev 1116 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
635 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
1081 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
635 daniel-mar 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
 
1050 daniel-mar 20
namespace ViaThinkSoft\OIDplus;
635 daniel-mar 21
 
1086 daniel-mar 22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
25
 
635 daniel-mar 26
class OIDplusPagePublicWhois extends OIDplusPagePluginPublic {
27
 
28
        public function init($html=true) {
29
                OIDplus::config()->prepareConfigKey('whois_auth_token',                       'OID-over-WHOIS authentication token to display confidential data', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
30
                        $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value);
31
                        if ($test_value != '') {
32
                                throw new OIDplusException(_L('Only characters and numbers are allowed as authentication token.'));
33
                        }
34
                });
35
                OIDplus::config()->prepareConfigKey('webwhois_output_format_spacer',          'WebWHOIS: Spacer', '2', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
36
                        if (!is_numeric($value) || ($value < 0)) {
37
                                throw new OIDplusException(_L('Please enter a valid value.'));
38
                        }
39
                });
40
                OIDplus::config()->prepareConfigKey('webwhois_output_format_max_line_length', 'WebWHOIS: Max line length', '80', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
41
                        if (!is_numeric($value) || ($value < 0)) {
42
                                throw new OIDplusException(_L('Please enter a valid value.'));
43
                        }
44
                });
776 daniel-mar 45
                OIDplus::config()->prepareConfigKey('individual_whois_server', 'A WHOIS/OID-IP "hostname:port" that will be presented', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
46
                        if ($value == '') return;
47
                        $ary = explode(':', $value);
48
                        if (count($ary) !== 2) {
49
                                throw new OIDplusException(_L('Please enter either an empty string or an input in the format "hostname:port".'));
50
                        }
51
                        // TODO: verify hostname $ary[0]
52
                        // TODO: verify port $ary[1]
53
                });
635 daniel-mar 54
        }
55
 
56
        private function getExampleId() {
57
                $firsts = array();
58
                $first_ns = null;
59
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1012 daniel-mar 60
                        $res = OIDplus::db()->query("SELECT id FROM ###objects WHERE parent = ? ORDER BY ".OIDplus::db()->natOrder('id'), array($ot::ns().':'));
729 daniel-mar 61
                        if ($row = $res->fetch_array()) {
62
                                if (is_null($first_ns)) $first_ns = $ot::ns();
635 daniel-mar 63
                                $firsts[$ot::ns()] = $row['id'];
729 daniel-mar 64
                        }
635 daniel-mar 65
                }
729 daniel-mar 66
                if ((count($firsts) == 0) || is_null($first_ns)) {
635 daniel-mar 67
                        return 'oid:2.999';
68
                } elseif (isset($firsts['oid'])) {
69
                        return  $firsts['oid'];
70
                } else {
71
                        return  $firsts[$first_ns];
72
                }
73
        }
74
 
75
        public function gui($id, &$out, &$handled) {
76
                if (explode('$',$id)[0] == 'oidplus:whois') {
77
                        $handled = true;
78
 
79
                        $example = $this->getExampleId();
80
 
894 daniel-mar 81
                        $whois_server = '';
82
                        if (OIDplus::config()->getValue('individual_whois_server', '') != '') {
83
                                $whois_server = OIDplus::config()->getValue('individual_whois_server', '');
84
                        }
85
                        else if (OIDplus::config()->getValue('vts_whois', '') != '') {
86
                                // This config setting is set by the "Registration" plugin
87
                                $whois_server = OIDplus::config()->getValue('vts_whois', '');
88
                        }
89
 
776 daniel-mar 90
                        $out['title'] = _L('OID Information Protocol (OID-IP) / WHOIS');
801 daniel-mar 91
                        $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
635 daniel-mar 92
 
93
                        $out['text']  = '';
890 daniel-mar 94
                        $out['text'] .= '<p>'._L('With the OID Information Protocol (OID-IP), you can query object information in a format that is human-readable and machine-readable.').'</p>';
896 daniel-mar 95
 
916 daniel-mar 96
                        // Use this if webwhois.php matches the currently uploaded Internet Draft:
1081 daniel-mar 97
                        $out['text'] .= '<p>'._L('RFC Internet Draft').': <a target="_blank" href="https://datatracker.ietf.org/doc/draft-viathinksoft-oidip/">draft-viathinksoft-oidip-05</a></p>';
916 daniel-mar 98
                        // Use this if webwhois.php implements something which is not yet uploaded to IETF:
1081 daniel-mar 99
                        //$out['text'] .= '<p>'._L('RFC Internet Draft').': <a href="'.OIDplus::webpath(__DIR__.'/whois/rfc/draft-viathinksoft-oidip-06.txt', true).'" target="_blank">draft-viathinksoft-oidip-06</a></p>';
894 daniel-mar 100
                        # ---
101
                        $out['text'] .= '<h2>'._L('Parameters for new request').'</h2>';
890 daniel-mar 102
                        $out['text'] .= '<noscript>';
103
                        $out['text'] .= '<p>'._L('You need to enable JavaScript to use the login area.').'</p>';
104
                        $out['text'] .= '</noscript>';
105
                        $out['text'] .= '<div id="oidipArea" style="display:none">';
894 daniel-mar 106
                        # ---
897 daniel-mar 107
                        $out['text'] .= _L('Requested object including namespace, e.g. %1','<code>oid:2.999</code>').'<br>';
891 daniel-mar 108
                        $out['text'] .= '<input type="text" id="whois_query" name="query" value="'.htmlentities($example).'" onkeyup="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
109
                        $out['text'] .= '&nbsp;<span id="whois_query_invalid" style="display:none"><font color="red"><b>('._L('Invalid').')</b></font></span>';
110
                        $out['text'] .= '<br><br>';
894 daniel-mar 111
                        # ---
890 daniel-mar 112
                        $out['text'] .= _L('Output format').':<br><fieldset id="whois_format">';
765 daniel-mar 113
                        $out['text'] .= '    <input type="radio" id="text" name="format" value="text" checked onclick="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
890 daniel-mar 114
                        $out['text'] .= '    <label for="text"><code>$format=text</code> '._L('Text format').'</label><br>';
635 daniel-mar 115
                        $out['text'] .= '    <input type="radio" id="json" name="format" value="json" onclick="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
1081 daniel-mar 116
                        $out['text'] .= '    <label for="json"><code>$format=json</code>  '._L('JSON format').'</label> (<a target="_blank" href="'.OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'whois/draft-viathinksoft-oidip-05.json">'._L('Schema').'</a>)<br>';
635 daniel-mar 117
                        $out['text'] .= '    <input type="radio" id="xml" name="format" value="xml" onclick="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
1081 daniel-mar 118
                        $out['text'] .= '    <label for="xml"><code>$format=xml</code>  '._L('XML format').'</label> (<a target="_blank" href="'.OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'whois/draft-viathinksoft-oidip-05.xsd">'._L('Schema').'</a>)<br>';
635 daniel-mar 119
                        $out['text'] .= '</fieldset><br>';
894 daniel-mar 120
                        # ---
890 daniel-mar 121
                        $out['text'] .= _L('Authentication token(s), comma separated (optional)').':<br>';
891 daniel-mar 122
                        $out['text'] .= '<code>$auth = </code><input type="text" id="whois_auth" name="auth" value="" onkeyup="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
123
                        $out['text'] .= '&nbsp;<span id="whois_auth_invalid" style="display:none"><font color="red"><b>('._L('Invalid').')</b></font></span>';
894 daniel-mar 124
                        $out['text'] .= '<br>';
125
                        # ---
126
                        $out['text'] .= '<h2>'._L('Access via OID Information Protocol').'</h2>';
127
                        $out['text'] .= '<p>'._L('The query according to OID Information Protocol is:').'</p>';
890 daniel-mar 128
                        $out['text'] .= '       <p><pre id="whois_query_bar"></pre></p>';
129
                        $out['text'] .= '       <p><input type="button" value="'._L('Copy to clipboard').'" onClick="copyToClipboard(whois_query_bar)"></p>';
894 daniel-mar 130
                        $out['text'] .= '<p>'._L('You can use any WHOIS compatible client to query the information from the WHOIS or OID-IP port.').'</p>';
131
                        if ($whois_server != '') {
132
                                $out['text'] .= '<p>'._L('The hostname and port number is:').'</p>';
133
                                $out['text'] .= '<p><pre>'.htmlentities($whois_server).'</pre></p>';
134
                        }
135
                        # ---
136
                        $out['text'] .= '<h2>'._L('Access via web-browser').'</h2>';
137
                        $out['text'] .= '<p>'._L('The URL for the Web Service is:').'</p>';
635 daniel-mar 138
                        $out['text'] .= '       <p><pre id="whois_url_bar"></pre></p>';
890 daniel-mar 139
                        $out['text'] .= '       <p>';
876 daniel-mar 140
                        $out['text'] .= '       <input type="button" value="'._L('Copy to clipboard').'" onClick="copyToClipboard(whois_url_bar)">';
890 daniel-mar 141
                        $out['text'] .= '       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
142
                        $out['text'] .= '       <input type="button" value="'._L('Open in web-browser').'" onClick="OIDplusPagePublicWhois.openInBrowser()">';
143
                        $out['text'] .= '       </p>';
635 daniel-mar 144
                        $out['text'] .= '</div>';
894 daniel-mar 145
                        # ---
890 daniel-mar 146
                        $out['text'] .= '<script>';
147
                        $out['text'] .= '   $("#oidipArea")[0].style.display = "Block";';  // because of NoScript
148
                        $out['text'] .= '   OIDplusPagePublicWhois.refresh_whois_url_bar();';
149
                        $out['text'] .= '</script>';
635 daniel-mar 150
                }
151
        }
152
 
153
        public function publicSitemap(&$out) {
154
                $out[] = 'oidplus:whois';
155
        }
156
 
157
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
800 daniel-mar 158
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 159
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 160
                } else {
161
                        $tree_icon = null; // default icon (folder)
162
                }
163
 
164
                $json[] = array(
165
                        'id' => 'oidplus:whois',
166
                        'icon' => $tree_icon,
779 daniel-mar 167
                        'text' => _L('OID-IP / WHOIS')
635 daniel-mar 168
                );
169
 
170
                return true;
171
        }
172
 
173
        public function implementsFeature($id) {
174
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.2') return true; // modifyContent
175
                return false;
176
        }
177
 
178
        public function modifyContent($id, &$title, &$icon, &$text) {
179
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.2
180
 
801 daniel-mar 181
                $text .= '<br><img src="'.OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/page_pictogram.png" height="15" alt=""> <a href="'.OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'whois/webwhois.php?query='.urlencode($id).'" class="gray_footer_font" target="_blank">'._L('Whois').'</a>';
635 daniel-mar 182
 
183
                $obj = OIDplusObject::parse($id);
184
                if ($obj->userHasParentalWriteRights()) {
185
                        $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>';
186
                        $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>';
187
                }
188
 
189
        }
190
 
191
        public function tree_search($request) {
192
                return false;
193
        }
194
 
195
        public static function genWhoisAuthToken($id) {
196
                return smallhash(OIDplus::baseConfig()->getValue('SERVER_SECRET').'/WHOIS/'.$id);
197
        }
198
}