Subversion Repositories oidplus

Rev

Rev 330 | 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
 
256 daniel-mar 20
class OIDplusPagePublicWhois extends OIDplusPagePluginPublic {
101 daniel-mar 21
 
22
        public function init($html=true) {
263 daniel-mar 23
                OIDplus::config()->prepareConfigKey('whois_auth_token',                       'OID-over-WHOIS authentication token to display confidential data', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
104 daniel-mar 24
                        $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value);
25
                        if ($test_value != '') {
360 daniel-mar 26
                                throw new OIDplusException(_L('Only characters and numbers are allowed as authentication token.'));
104 daniel-mar 27
                        }
263 daniel-mar 28
                });
360 daniel-mar 29
                OIDplus::config()->prepareConfigKey('webwhois_output_format_spacer',          'WebWHOIS: Spacer', '2', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
261 daniel-mar 30
                        if (!is_numeric($value) || ($value < 0)) {
360 daniel-mar 31
                                throw new OIDplusException(_L('Please enter a valid value.'));
261 daniel-mar 32
                        }
263 daniel-mar 33
                });
360 daniel-mar 34
                OIDplus::config()->prepareConfigKey('webwhois_output_format_max_line_length', 'WebWHOIS: Max line length', '80', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
261 daniel-mar 35
                        if (!is_numeric($value) || ($value < 0)) {
360 daniel-mar 36
                                throw new OIDplusException(_L('Please enter a valid value.'));
261 daniel-mar 37
                        }
263 daniel-mar 38
                });
101 daniel-mar 39
        }
40
 
202 daniel-mar 41
        private function getExampleId() {
42
                $firsts = array();
43
                $first_ns = null;
227 daniel-mar 44
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
202 daniel-mar 45
                        if (is_null($first_ns)) $first_ns = $ot::ns();
261 daniel-mar 46
                        $res = OIDplus::db()->query("SELECT id FROM ###objects WHERE parent = ? ORDER BY id", array($ot::ns().':'));
236 daniel-mar 47
                        if ($row = $res->fetch_array())
202 daniel-mar 48
                                $firsts[$ot::ns()] = $row['id'];
49
                }
50
                if (count($firsts) == 0) {
51
                        return 'oid:2.999';
52
                } elseif (isset($firsts['oid'])) {
53
                        return  $firsts['oid'];
54
                } else {
55
                        return  $firsts[$first_ns];
56
                }
57
        }
58
 
101 daniel-mar 59
        public function gui($id, &$out, &$handled) {
60
                if (explode('$',$id)[0] == 'oidplus:whois') {
61
                        $handled = true;
62
 
202 daniel-mar 63
                        $example = $this->getExampleId();
64
 
360 daniel-mar 65
                        $out['title'] = _L('Web WHOIS');
241 daniel-mar 66
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
101 daniel-mar 67
 
104 daniel-mar 68
                        $out['text']  = '';
360 daniel-mar 69
                        $out['text'] .= '<p>'._L('With the web based whois service, you can query object information in a machine-readable format.').'</p>';
330 daniel-mar 70
 
241 daniel-mar 71
                        $out['text'] .= '<form action="'.OIDplus::webpath(__DIR__).'whois/webwhois.php" method="GET">';
360 daniel-mar 72
                        $out['text'] .= '<br>'._L('Output format').':<br><fieldset>';
330 daniel-mar 73
                        $out['text'] .= '    <input type="radio" id="txt" name="format" value="txt" checked>';
360 daniel-mar 74
                        $out['text'] .= '    <label for="txt"> '._L('Text format (RFC draft: %1)','<a href="'.OIDplus::webpath(__DIR__).'whois/rfc/draft-viathinksoft-oidwhois-00.txt">'._L('TXT').'</a> | <a href="'.OIDplus::webpath(__DIR__).'whois/rfc/draft-viathinksoft-oidwhois-00.nroff">'._L('NROFF').'</a>').'</label><br>';
330 daniel-mar 75
                        $out['text'] .= '    <input type="radio" id="json" name="format" value="json">';
360 daniel-mar 76
                        $out['text'] .= '    <label for="json"> '._L('JSON').' (<a href="'.OIDplus::webpath(__DIR__).'whois/json_schema.json">'._L('Schema').'</a>)</label><br>';
330 daniel-mar 77
                        $out['text'] .= '    <input type="radio" id="xml" name="format" value="xml">';
360 daniel-mar 78
                        $out['text'] .= '    <label for="xml"> '._L('XML').' (<a href="'.OIDplus::webpath(__DIR__).'whois/xml_schema.xsd">'._L('Schema').'</a>)</label><br>';
330 daniel-mar 79
                        $out['text'] .= '</fieldset><br>';
360 daniel-mar 80
                        $out['text'] .= '       <!--<label class="padding_label">-->'._L('Query').':<!--</label>--> <input type="text" name="query" value="'.htmlentities($example).'" style="width:250px">';
81
                        $out['text'] .= '       <input type="submit" value="'._L('Query').'">';
101 daniel-mar 82
                        $out['text'] .= '</form>';
83
                }
84
        }
85
 
282 daniel-mar 86
        public function publicSitemap(&$out) {
360 daniel-mar 87
                $out[] = 'oidplus:whois';
282 daniel-mar 88
        }
89
 
106 daniel-mar 90
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
101 daniel-mar 91
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 92
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
101 daniel-mar 93
                } else {
94
                        $tree_icon = null; // default icon (folder)
95
                }
96
 
97
                $json[] = array(
98
                        'id' => 'oidplus:whois',
99
                        'icon' => $tree_icon,
360 daniel-mar 100
                        'text' => _L('Web WHOIS')
101 daniel-mar 101
                );
104 daniel-mar 102
 
103
                return true;
101 daniel-mar 104
        }
105
 
304 daniel-mar 106
        public function implementsFeature($id) {
107
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.2') return true; // modifyContent
108
                return false;
109
        }
110
 
101 daniel-mar 111
        public function modifyContent($id, &$title, &$icon, &$text) {
304 daniel-mar 112
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.2
113
 
360 daniel-mar 114
                $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>';
101 daniel-mar 115
        }
108 daniel-mar 116
 
117
        public function tree_search($request) {
118
                return false;
119
        }
360 daniel-mar 120
}