Subversion Repositories oidplus

Rev

Rev 416 | 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
511 daniel-mar 5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
101 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
 
511 daniel-mar 20
if (!defined('INSIDE_OIDPLUS')) die();
21
 
256 daniel-mar 22
class OIDplusPagePublicWhois extends OIDplusPagePluginPublic {
101 daniel-mar 23
 
24
        public function init($html=true) {
263 daniel-mar 25
                OIDplus::config()->prepareConfigKey('whois_auth_token',                       'OID-over-WHOIS authentication token to display confidential data', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
104 daniel-mar 26
                        $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value);
27
                        if ($test_value != '') {
360 daniel-mar 28
                                throw new OIDplusException(_L('Only characters and numbers are allowed as authentication token.'));
104 daniel-mar 29
                        }
263 daniel-mar 30
                });
360 daniel-mar 31
                OIDplus::config()->prepareConfigKey('webwhois_output_format_spacer',          'WebWHOIS: Spacer', '2', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
261 daniel-mar 32
                        if (!is_numeric($value) || ($value < 0)) {
360 daniel-mar 33
                                throw new OIDplusException(_L('Please enter a valid value.'));
261 daniel-mar 34
                        }
263 daniel-mar 35
                });
360 daniel-mar 36
                OIDplus::config()->prepareConfigKey('webwhois_output_format_max_line_length', 'WebWHOIS: Max line length', '80', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
261 daniel-mar 37
                        if (!is_numeric($value) || ($value < 0)) {
360 daniel-mar 38
                                throw new OIDplusException(_L('Please enter a valid value.'));
261 daniel-mar 39
                        }
263 daniel-mar 40
                });
101 daniel-mar 41
        }
42
 
202 daniel-mar 43
        private function getExampleId() {
44
                $firsts = array();
45
                $first_ns = null;
227 daniel-mar 46
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
202 daniel-mar 47
                        if (is_null($first_ns)) $first_ns = $ot::ns();
261 daniel-mar 48
                        $res = OIDplus::db()->query("SELECT id FROM ###objects WHERE parent = ? ORDER BY id", array($ot::ns().':'));
236 daniel-mar 49
                        if ($row = $res->fetch_array())
202 daniel-mar 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
 
101 daniel-mar 61
        public function gui($id, &$out, &$handled) {
62
                if (explode('$',$id)[0] == 'oidplus:whois') {
63
                        $handled = true;
64
 
202 daniel-mar 65
                        $example = $this->getExampleId();
66
 
360 daniel-mar 67
                        $out['title'] = _L('Web WHOIS');
241 daniel-mar 68
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
101 daniel-mar 69
 
104 daniel-mar 70
                        $out['text']  = '';
360 daniel-mar 71
                        $out['text'] .= '<p>'._L('With the web based whois service, you can query object information in a machine-readable format.').'</p>';
330 daniel-mar 72
 
385 daniel-mar 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>';
330 daniel-mar 81
                        $out['text'] .= '</fieldset><br>';
385 daniel-mar 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()">';
360 daniel-mar 83
                        $out['text'] .= '       <input type="submit" value="'._L('Query').'">';
101 daniel-mar 84
                        $out['text'] .= '</form>';
385 daniel-mar 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
101 daniel-mar 90
                }
91
        }
92
 
282 daniel-mar 93
        public function publicSitemap(&$out) {
360 daniel-mar 94
                $out[] = 'oidplus:whois';
282 daniel-mar 95
        }
96
 
106 daniel-mar 97
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
101 daniel-mar 98
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 99
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
101 daniel-mar 100
                } else {
101
                        $tree_icon = null; // default icon (folder)
102
                }
103
 
104
                $json[] = array(
105
                        'id' => 'oidplus:whois',
106
                        'icon' => $tree_icon,
360 daniel-mar 107
                        'text' => _L('Web WHOIS')
101 daniel-mar 108
                );
104 daniel-mar 109
 
110
                return true;
101 daniel-mar 111
        }
112
 
304 daniel-mar 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
 
101 daniel-mar 118
        public function modifyContent($id, &$title, &$icon, &$text) {
304 daniel-mar 119
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.2
120
 
360 daniel-mar 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>';
416 daniel-mar 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
 
101 daniel-mar 129
        }
108 daniel-mar 130
 
131
        public function tree_search($request) {
132
                return false;
133
        }
416 daniel-mar 134
 
135
        public static function genWhoisAuthToken($id) {
136
                return smallhash(OIDplus::baseConfig()->getValue('SERVER_SECRET').'/WHOIS/'.$id);
137
        }
385 daniel-mar 138
}