Subversion Repositories oidplus

Rev

Rev 729 | Rev 765 | 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
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
                        $res = OIDplus::db()->query("SELECT id FROM ###objects WHERE parent = ? ORDER BY id", array($ot::ns().':'));
729 daniel-mar 48
                        if ($row = $res->fetch_array()) {
49
                                if (is_null($first_ns)) $first_ns = $ot::ns();
635 daniel-mar 50
                                $firsts[$ot::ns()] = $row['id'];
729 daniel-mar 51
                        }
635 daniel-mar 52
                }
729 daniel-mar 53
                if ((count($firsts) == 0) || is_null($first_ns)) {
635 daniel-mar 54
                        return 'oid:2.999';
55
                } elseif (isset($firsts['oid'])) {
56
                        return  $firsts['oid'];
57
                } else {
58
                        return  $firsts[$first_ns];
59
                }
60
        }
61
 
62
        public function gui($id, &$out, &$handled) {
63
                if (explode('$',$id)[0] == 'oidplus:whois') {
64
                        $handled = true;
65
 
66
                        $example = $this->getExampleId();
67
 
68
                        $out['title'] = _L('Web WHOIS');
69
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
70
 
71
                        $out['text']  = '';
72
                        $out['text'] .= '<p>'._L('With the web based whois service, you can query object information in a machine-readable format.').'</p>';
73
 
74
                        $out['text'] .= '<form action="'.OIDplus::webpath(__DIR__).'whois/webwhois.php" method="GET" target="_blank">';
75
                        $out['text'] .= '<br>'._L('Output format').':<br><fieldset id="whois_format">';
76
                        $out['text'] .= '    <input type="radio" id="txt" name="format" value="txt" checked onclick="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
758 daniel-mar 77
                        $out['text'] .= '    <label for="txt"> '._L('Text format').'</label> ('._L('RFC Internet Draft').': <a target="_blank" href="https://datatracker.ietf.org/doc/draft-viathinksoft-oidip/">draft-viathinksoft-oidip-02</a>)<br>';
635 daniel-mar 78
                        $out['text'] .= '    <input type="radio" id="json" name="format" value="json" onclick="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
79
                        $out['text'] .= '    <label for="json"> '._L('JSON').'</label> (<a target="_blank" href="'.OIDplus::webpath(__DIR__).'whois/json_schema.json">'._L('Schema').'</a>)<br>';
80
                        $out['text'] .= '    <input type="radio" id="xml" name="format" value="xml" onclick="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
81
                        $out['text'] .= '    <label for="xml"> '._L('XML').'</label> (<a target="_blank" href="'.OIDplus::webpath(__DIR__).'whois/xml_schema.xsd">'._L('Schema').'</a>)<br>';
758 daniel-mar 82
                        //$out['text'] .= '    <input type="radio" id="html" name="format" value="html" onclick="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
83
                        //$out['text'] .= '    <label for="html"> '._L('HTML').'</label><br>';
635 daniel-mar 84
                        $out['text'] .= '</fieldset><br>';
85
                        $out['text'] .= '       <!--<label class="padding_label">-->'._L('Query').':<!--</label>--> <input type="text" id="whois_query" name="query" value="'.htmlentities($example).'" style="width:250px" onkeyup="OIDplusPagePublicWhois.refresh_whois_url_bar()">';
86
                        $out['text'] .= '       <input type="submit" value="'._L('Query').'">';
87
                        $out['text'] .= '</form>';
88
                        $out['text'] .= '<div id="whois_url_bar_section" style="display:none">';
89
                        $out['text'] .= '       <p><pre id="whois_url_bar"></pre></p>';
90
                        $out['text'] .= '       <input type="button" value="'._L('Copy to clipboard').'" onClick="OIDplusPagePublicWhois.copyToClipboard(whois_url_bar)">';
91
                        $out['text'] .= '</div>';
92
                        $out['text'] .= '<script> OIDplusPagePublicWhois.refresh_whois_url_bar(); </script>';
93
                }
94
        }
95
 
96
        public function publicSitemap(&$out) {
97
                $out[] = 'oidplus:whois';
98
        }
99
 
100
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
101
                if (file_exists(__DIR__.'/treeicon.png')) {
102
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
103
                } else {
104
                        $tree_icon = null; // default icon (folder)
105
                }
106
 
107
                $json[] = array(
108
                        'id' => 'oidplus:whois',
109
                        'icon' => $tree_icon,
110
                        'text' => _L('Web WHOIS')
111
                );
112
 
113
                return true;
114
        }
115
 
116
        public function implementsFeature($id) {
117
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.2') return true; // modifyContent
118
                return false;
119
        }
120
 
121
        public function modifyContent($id, &$title, &$icon, &$text) {
122
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.2
123
 
714 daniel-mar 124
                $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" target="_blank">'._L('Whois').'</a>';
635 daniel-mar 125
 
126
                $obj = OIDplusObject::parse($id);
127
                if ($obj->userHasParentalWriteRights()) {
128
                        $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>';
129
                        $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>';
130
                }
131
 
132
        }
133
 
134
        public function tree_search($request) {
135
                return false;
136
        }
137
 
138
        public static function genWhoisAuthToken($id) {
139
                return smallhash(OIDplus::baseConfig()->getValue('SERVER_SECRET').'/WHOIS/'.$id);
140
        }
141
}