Subversion Repositories oidplus

Rev

Rev 224 | 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
 
101 daniel-mar 22
class OIDplusPagePublicWhois extends OIDplusPagePlugin {
23
        public function type() {
24
                return 'public';
25
        }
26
 
222 daniel-mar 27
        public static function getPluginInformation() {
28
                $out = array();
29
                $out['name'] = 'WhoIs';
30
                $out['author'] = 'ViaThinkSoft';
31
                $out['version'] = null;
32
                $out['descriptionHTML'] = null;
33
                return $out;
34
        }
35
 
101 daniel-mar 36
        public function priority() {
37
                return 100;
38
        }
39
 
40
        public function action(&$handled) {
41
                // Nothing
42
        }
43
 
44
        public function init($html=true) {
104 daniel-mar 45
                OIDplus::config()->prepareConfigKey('whois_auth_token', 'OID-over-WHOIS authentication token to display confidential data', '', 0, 1);
101 daniel-mar 46
        }
47
 
48
        public function cfgSetValue($name, $value) {
104 daniel-mar 49
                if ($name == 'whois_auth_token') {
50
                        $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value);
51
                        if ($test_value != '') {
52
                                throw new Exception("Only characters and numbers are allowed as authentication token.");
53
                        }
54
                }
101 daniel-mar 55
        }
56
 
202 daniel-mar 57
        private function getExampleId() {
58
                $firsts = array();
59
                $first_ns = null;
227 daniel-mar 60
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
202 daniel-mar 61
                        if (is_null($first_ns)) $first_ns = $ot::ns();
203 daniel-mar 62
                        $res = OIDplus::db()->query("SELECT id FROM ".OIDPLUS_TABLENAME_PREFIX."objects WHERE parent = ? ORDER BY id", array($ot::ns().':'));
202 daniel-mar 63
                        if ($row = OIDplus::db()->fetch_array($res))
64
                                $firsts[$ot::ns()] = $row['id'];
65
                }
66
                if (count($firsts) == 0) {
67
                        return 'oid:2.999';
68
                } elseif (isset($firsts['oid'])) {
69
                        return  $firsts['oid'];
70
                } else {
71
                        return  $firsts[$first_ns];
72
                }
73
        }
74
 
101 daniel-mar 75
        public function gui($id, &$out, &$handled) {
76
                if (explode('$',$id)[0] == 'oidplus:whois') {
77
                        $handled = true;
78
 
202 daniel-mar 79
                        $example = $this->getExampleId();
80
 
101 daniel-mar 81
                        $out['title'] = 'Web WHOIS';
148 daniel-mar 82
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : '';
101 daniel-mar 83
 
104 daniel-mar 84
                        $out['text']  = '';
101 daniel-mar 85
                        $out['text'] .= '<p>With the web based whois service, you can query object information in a machine readable format.</p>';
201 daniel-mar 86
                        $out['text'] .= '<p>RFC draft (for Text format): <a href="plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/whois/rfc/draft-viathinksoft-oidwhois-00.txt">TXT</a> | <a href="plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/whois/rfc/draft-viathinksoft-oidwhois-00.nroff">NROFF</a></p>';
148 daniel-mar 87
                        $out['text'] .= '<form action="plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/whois/webwhois.php" method="GET">';
201 daniel-mar 88
                        $out['text'] .= '       <label class="padding_label">Format:</label><select name="format">';
89
                        $out['text'] .= '               <option value="txt">Text (RFC pending)</option>';
90
                        $out['text'] .= '               <option value="json">JSON</option>';
91
                        $out['text'] .= '               <option value="xml">XML</option>';
92
                        $out['text'] .= '       </select><br>';
202 daniel-mar 93
                        $out['text'] .= '       <label class="padding_label">Query:</label><input type="text" name="query" value="'.htmlentities($example).'" style="width:250px">';
104 daniel-mar 94
                        $out['text'] .= '       <input type="submit" value="Query">';
101 daniel-mar 95
                        $out['text'] .= '</form>';
96
                }
97
        }
98
 
106 daniel-mar 99
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
101 daniel-mar 100
                if (file_exists(__DIR__.'/treeicon.png')) {
148 daniel-mar 101
                        $tree_icon = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/treeicon.png';
101 daniel-mar 102
                } else {
103
                        $tree_icon = null; // default icon (folder)
104
                }
105
 
106
                $json[] = array(
107
                        'id' => 'oidplus:whois',
108
                        'icon' => $tree_icon,
109
                        'text' => 'Web WHOIS'
110
                );
104 daniel-mar 111
 
112
                return true;
101 daniel-mar 113
        }
114
 
115
        public function modifyContent($id, &$title, &$icon, &$text) {
148 daniel-mar 116
                $text .= '<br><img src="plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/page_pictogram.png" height="15" alt=""> <a href="plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/whois/webwhois.php?query='.urlencode($id).'" class="gray_footer_font">Whois</a>';
101 daniel-mar 117
        }
108 daniel-mar 118
 
119
        public function tree_search($request) {
120
                return false;
121
        }
101 daniel-mar 122
}