Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
61 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
 
139 daniel-mar 22
require_once __DIR__ . '/oidinfo_api.inc.php';
23
 
61 daniel-mar 24
class OIDplusPageAdminOIDInfoExport extends OIDplusPagePlugin {
25
        public function type() {
26
                return 'admin';
27
        }
28
 
29
        public function priority() {
30
                return 400;
31
        }
32
 
33
        public function action(&$handled) {
34
                // Nothing
35
        }
36
 
75 daniel-mar 37
        public function init($html=true) {
139 daniel-mar 38
                // Nothing
61 daniel-mar 39
        }
40
 
41
        public function cfgSetValue($name, $value) {
139 daniel-mar 42
                // Nothing
61 daniel-mar 43
        }
44
 
45
        public function gui($id, &$out, &$handled) {
46
                if ($id === 'oidplus:export') {
47
                        $handled = true;
48
                        $out['title'] = 'Data export';
148 daniel-mar 49
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : '';
61 daniel-mar 50
 
51
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
52
                                $out['icon'] = 'img/error_big.png';
153 daniel-mar 53
                                $out['text'] = '<p>You need to <a '.oidplus_link('oidplus:login').'>log in</a> as administrator.</p>';
61 daniel-mar 54
                        } else {
55
                                $out['text'] = '<p>Here you can prepare the data export to <b>oid-info.com</b>.</p>'.
148 daniel-mar 56
                                               '<p><a href="plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/oidinfo_export.php">Generate XML (all)</a></p>'.
57
                                               '<p><a href="plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/oidinfo_export.php?online=1">Generate XML (only non-existing)</a></p>'.
61 daniel-mar 58
                                               '<p><a href="http://www.oid-info.com/submit.htm">Upload to oid-info.com</a></p>';
59
                        }
60
                }
61
        }
62
 
106 daniel-mar 63
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
61 daniel-mar 64
                if (file_exists(__DIR__.'/treeicon.png')) {
148 daniel-mar 65
                        $tree_icon = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/treeicon.png';
61 daniel-mar 66
                } else {
67
                        $tree_icon = null; // default icon (folder)
68
                }
69
 
70
                $json[] = array(
71
                        'id' => 'oidplus:export',
72
                        'icon' => $tree_icon,
73
                        'text' => 'Data export'
74
                );
104 daniel-mar 75
 
76
                return true;
61 daniel-mar 77
        }
108 daniel-mar 78
 
79
        public function tree_search($request) {
80
                return false;
81
        }
139 daniel-mar 82
 
83
        public static function outputXML($only_non_existing) {
84
                $oa = new OIDInfoAPI();
85
                $oa->addSimplePingProvider('viathinksoft.de:49500');
86
 
87
                $email = OIDplus::config()->getValue('admin_email');
88
                if (empty($email)) $email = 'unknown@example.com';
89
 
90
                echo $oa->xmlAddHeader(OIDplus::config()->systemTitle(), isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'Export interface', $email);
91
 
92
                $params['allow_html'] = true;
93
                $params['allow_illegal_email'] = true; // It should be enabled, because the creator could have used some kind of human-readable anti-spam technique
94
                $params['soft_correct_behavior'] = OIDInfoAPI::SOFT_CORRECT_BEHAVIOR_NONE;
95
                $params['do_online_check'] = false; // Flag to disable this online check, because it generates a lot of traffic and runtime.
96
                $params['do_illegality_check'] = true;
97
                $params['do_simpleping_check'] = $only_non_existing;
98
                $params['auto_extract_name'] = '';
99
                $params['auto_extract_url'] = '';
100
                $params['always_output_comment'] = false;
101
                $params['creation_allowed_check'] = $only_non_existing;
102
                $params['tolerant_htmlentities'] = true;
103
                $params['ignore_xhtml_light'] = false;
104
 
105
                $nonConfidential = OIDplusObject::getAllNonConfidential();
181 daniel-mar 106
                natsort($nonConfidential);
139 daniel-mar 107
 
108
                foreach ($nonConfidential as $id) {
150 daniel-mar 109
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($id));
139 daniel-mar 110
                        if ($row = OIDplus::db()->fetch_object($res)) {
111
                                $elements['identifier'] = array();
150 daniel-mar 112
                                $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = ?", array($row->id));
139 daniel-mar 113
                                while ($row2 = OIDplus::db()->fetch_object($res2)) {
114
                                        $elements['identifier'][] = $row2->name; // 'unicode-label' is currently not in the standard format (oid.xsd)
115
                                }
116
 
117
                                $elements['unicode-label'] = array();
150 daniel-mar 118
                                $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = ?", array($row->id));
139 daniel-mar 119
                                while ($row2 = OIDplus::db()->fetch_object($res2)) {
120
                                        $elements['unicode-label'][] = $row2->name;
121
                                }
122
 
150 daniel-mar 123
                                $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($row->ra_email));
139 daniel-mar 124
                                $row2 = OIDplus::db()->fetch_object($res2);
125
 
126
                                if (!empty($row->title)) {
127
                                        $elements['description'] = $row->title;
128
                                        $elements['information'] = $row->description;
129
                                        if (trim($row->title) == trim(strip_tags($row->description))) {
130
                                                $elements['information'] = '';
131
                                        }
132
                                } else if (isset($elements['identifier'][0])) {
133
                                        $elements['description'] = '"'.$elements['identifier'][0].'"';
134
                                        $elements['information'] = $row->description;
135
                                } else if (isset($elements['unicode-label'][0])) {
136
                                        $elements['description'] = '"'.$elements['unicode-label'][0].'"';
137
                                        $elements['information'] = $row->description;
138
                                } else if (!empty($row->description)) {
139
                                        $elements['description'] = $row->description;
140
                                        $elements['information'] = '';
141
                                } else {
142
                                        $elements['description'] = '<i>No description available</i>';
143
                                        $elements['information'] = '';
144
                                }
145
 
146
                                if ($elements['information'] != '') {
147
                                        $elements['information'] .= '<br/><br/>';
148
                                }
149
 
150
                                $elements['information'] .= 'See <a href="'.OIDplus::system_url(false).'?goto='.urlencode($id).'">more information</a>.'; // TODO: system_url() geht nicht bei CLI
151
 
152
                                if (explode(':',$id,2)[0] != 'oid') {
153
                                        $elements['information'] = "Object: $id\n\n" . $elements['information'];
154
                                }
155
 
156
                                $elements['description'] = self::repair_relative_links($elements['description']);
157
                                $elements['information'] = self::repair_relative_links($elements['information']);
158
 
159
                                $elements['first-registrant']['first-name'] = '';
160
                                $elements['first-registrant']['last-name'] = '';
161
                                $elements['first-registrant']['address'] = '';
162
                                $elements['first-registrant']['email'] = '';
163
                                $elements['first-registrant']['phone'] = '';
164
                                $elements['first-registrant']['fax'] = '';
165
                                $elements['first-registrant']['creation-date'] = self::_formatdate($row->created);
166
 
182 daniel-mar 167
                                $elements['current-registrant']['first-name'] = '';
139 daniel-mar 168
                                $elements['current-registrant']['last-name'] = '';
169
                                $elements['current-registrant']['email'] = $row->ra_email;
170
                                $elements['current-registrant']['phone'] = '';
171
                                $elements['current-registrant']['fax'] = '';
172
                                $elements['current-registrant']['address'] = '';
173
                                if ($row2) {
174
                                        $tmp = array();
182 daniel-mar 175
                                        if (!empty($row2->personal_name)) {
176
                                                $name_ary = split_firstname_lastname($row2->personal_name);
177
                                                $elements['current-registrant']['first-name'] = $name_ary[0];
178
                                                $elements['current-registrant']['last-name']  = $name_ary[1];
179
                                                if (!empty($row2->ra_name)       ) $tmp[] = $row2->ra_name;
180
                                                if (!empty($row2->office)        ) $tmp[] = $row2->office;
181
                                                if (!empty($row2->organization)  ) $tmp[] = $row2->organization;
182
                                        } else {
183
                                                $elements['current-registrant']['first-name'] = $row2->ra_name;
184
                                                $elements['current-registrant']['last-name']  = '';
185
                                                if (!empty($row2->personal_name) ) $tmp[] = $row2->personal_name;
186
                                                if (!empty($row2->office)        ) $tmp[] = $row2->office;
187
                                                if (!empty($row2->organization)  ) $tmp[] = $row2->organization;
188
                                        }
189
 
190
                                        if ((count($tmp) > 0) && ($tmp[0] == $row2->ra_name)) array_shift($tmp);
191
                                        array_unique($tmp);
192
 
139 daniel-mar 193
                                        if (!$row2->privacy) {
194
                                                if (!empty($row2->street))   $tmp[] = $row2->street;
195
                                                if (!empty($row2->zip_town)) $tmp[] = $row2->zip_town;
196
                                                if (!empty($row2->country))  $tmp[] = $row2->country;
197
                                                $elements['current-registrant']['phone'] = !empty($row2->phone) ? $row2->phone : $row2->mobile;
198
                                                $elements['current-registrant']['fax'] = $row2->fax;
199
                                        }
200
                                        $elements['current-registrant']['address'] = implode("<br/>", $tmp);
201
                                }
202
                                $elements['current-registrant']['modification-date'] = self::_formatdate($row->updated);
203
 
204
                                // Request from O.D. 20 May 2019: First registrant should not be empty (especially for cases where Creation and Modify Dates are the same)
205
                                // Actually, this is a problem because we don't know the first registrant.
206
                                // However, since oidinfo gets their XML very fast (if using registration), it is likely that the reported RA is still the same...
207
                                // ... and changes at the RA are not reported to oid-info.com anyways - the XML is only for creation
208
 
209
                                $elements['first-registrant']['first-name'] = $elements['current-registrant']['first-name'];
210
                                $elements['first-registrant']['last-name']  = $elements['current-registrant']['last-name'];
211
                                $elements['first-registrant']['address']    = $elements['current-registrant']['address'];
212
                                $elements['first-registrant']['email']      = $elements['current-registrant']['email'];
213
                                $elements['first-registrant']['phone']      = $elements['current-registrant']['phone'];
214
                                $elements['first-registrant']['fax']        = $elements['current-registrant']['fax'];
215
 
216
                                $elements['current-registrant']['first-name'] = '';
217
                                $elements['current-registrant']['last-name'] = '';
218
                                $elements['current-registrant']['address'] = '';
219
                                $elements['current-registrant']['email'] = '';
220
                                $elements['current-registrant']['phone'] = '';
221
                                $elements['current-registrant']['fax'] = '';
222
                                $elements['current-registrant']['modification-date'] = '';
223
 
224
                                // End request O.D. 20 May 2019
225
 
226
                                $obj = OIDplusObject::parse($row->id);
193 daniel-mar 227
                                $alt_ids = $obj->getAltIds(); // TODO: slow!
228
                                foreach ($alt_ids as list($ns, $id, $desc)) {
229
                                        if ($ns == 'oid') {
230
                                                echo $oa->createXMLEntry($oid, $elements, $params, $comment=$obj->nodeId());
231
                                        }
232
                                }
139 daniel-mar 233
                        }
234
                }
235
 
236
                echo $oa->xmlAddFooter();
237
        }
238
 
239
        private static function _formatdate($str) {
240
                $str = explode(' ',$str)[0];
241
                if ($str == '0000-00-00') $str = '';
242
                return $str;
243
        }
244
 
245
        private static function repair_relative_links($str) {
246
                $str = preg_replace_callback('@(href\s*=\s*([\'"]))(.+)(\\2)@ismU', function($treffer) {
247
                        $url = $treffer[3];
182 daniel-mar 248
                        if ((stripos($url,'http:') !== 0) && (stripos($url,'https:') !== 0) && (stripos($url,'ftp:') !== 0)) {
249
                                if (stripos($url,'www.') === 0) {
139 daniel-mar 250
                                        $url .= 'http://' . $url;
251
                                } else {
252
                                        $url = OIDplus::system_url() . $url;
253
                                }
254
                        }
255
                        return $treffer[1].$url.$treffer[4];
256
                }, $str);
257
                return $str;
258
        }
61 daniel-mar 259
}
260
 
261
OIDplus::registerPagePlugin(new OIDplusPageAdminOIDInfoExport());