Rev 148 | 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'; |
||
107 | 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(); |
||
106 | |||
107 | foreach ($nonConfidential as $id) { |
||
150 | daniel-mar | 108 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($id)); |
139 | daniel-mar | 109 | if ($row = OIDplus::db()->fetch_object($res)) { |
110 | $elements['identifier'] = array(); |
||
150 | daniel-mar | 111 | $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = ?", array($row->id)); |
139 | daniel-mar | 112 | while ($row2 = OIDplus::db()->fetch_object($res2)) { |
113 | $elements['identifier'][] = $row2->name; // 'unicode-label' is currently not in the standard format (oid.xsd) |
||
114 | } |
||
115 | |||
116 | $elements['unicode-label'] = array(); |
||
150 | daniel-mar | 117 | $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = ?", array($row->id)); |
139 | daniel-mar | 118 | while ($row2 = OIDplus::db()->fetch_object($res2)) { |
119 | $elements['unicode-label'][] = $row2->name; |
||
120 | } |
||
121 | |||
150 | daniel-mar | 122 | $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($row->ra_email)); |
139 | daniel-mar | 123 | $row2 = OIDplus::db()->fetch_object($res2); |
124 | |||
125 | if (!empty($row->title)) { |
||
126 | $elements['description'] = $row->title; |
||
127 | $elements['information'] = $row->description; |
||
128 | if (trim($row->title) == trim(strip_tags($row->description))) { |
||
129 | $elements['information'] = ''; |
||
130 | } |
||
131 | } else if (isset($elements['identifier'][0])) { |
||
132 | $elements['description'] = '"'.$elements['identifier'][0].'"'; |
||
133 | $elements['information'] = $row->description; |
||
134 | } else if (isset($elements['unicode-label'][0])) { |
||
135 | $elements['description'] = '"'.$elements['unicode-label'][0].'"'; |
||
136 | $elements['information'] = $row->description; |
||
137 | } else if (!empty($row->description)) { |
||
138 | $elements['description'] = $row->description; |
||
139 | $elements['information'] = ''; |
||
140 | } else { |
||
141 | $elements['description'] = '<i>No description available</i>'; |
||
142 | $elements['information'] = ''; |
||
143 | } |
||
144 | |||
145 | if ($elements['information'] != '') { |
||
146 | $elements['information'] .= '<br/><br/>'; |
||
147 | } |
||
148 | |||
149 | $elements['information'] .= 'See <a href="'.OIDplus::system_url(false).'?goto='.urlencode($id).'">more information</a>.'; // TODO: system_url() geht nicht bei CLI |
||
150 | |||
151 | if (explode(':',$id,2)[0] != 'oid') { |
||
152 | $elements['information'] = "Object: $id\n\n" . $elements['information']; |
||
153 | } |
||
154 | |||
155 | $elements['description'] = self::repair_relative_links($elements['description']); |
||
156 | $elements['information'] = self::repair_relative_links($elements['information']); |
||
157 | |||
158 | $elements['first-registrant']['first-name'] = ''; |
||
159 | $elements['first-registrant']['last-name'] = ''; |
||
160 | $elements['first-registrant']['address'] = ''; |
||
161 | $elements['first-registrant']['email'] = ''; |
||
162 | $elements['first-registrant']['phone'] = ''; |
||
163 | $elements['first-registrant']['fax'] = ''; |
||
164 | $elements['first-registrant']['creation-date'] = self::_formatdate($row->created); |
||
165 | |||
166 | $elements['current-registrant']['first-name'] = $row2 ? $row2->ra_name : ''; |
||
167 | $elements['current-registrant']['last-name'] = ''; |
||
168 | $elements['current-registrant']['email'] = $row->ra_email; |
||
169 | |||
170 | $elements['current-registrant']['phone'] = ''; |
||
171 | $elements['current-registrant']['fax'] = ''; |
||
172 | $elements['current-registrant']['address'] = ''; |
||
173 | if ($row2) { |
||
174 | $tmp = array(); |
||
175 | if (!empty($row2->organization) && ($row2->organization != $row2->ra_name)) $tmp[] = $row2->organization; |
||
176 | if (!empty($row2->office) && ($row2->office != $row2->ra_name)) $tmp[] = $row2->office; |
||
177 | if (!empty($row2->personal_name) && ($row2->personal_name != $row2->ra_name)) $tmp[] = (!empty($row2->organization) ? 'c/o ' : '') . $row2->personal_name; |
||
178 | if (!$row2->privacy) { |
||
179 | if (!empty($row2->street)) $tmp[] = $row2->street; |
||
180 | if (!empty($row2->zip_town)) $tmp[] = $row2->zip_town; |
||
181 | if (!empty($row2->country)) $tmp[] = $row2->country; |
||
182 | $elements['current-registrant']['phone'] = !empty($row2->phone) ? $row2->phone : $row2->mobile; |
||
183 | $elements['current-registrant']['fax'] = $row2->fax; |
||
184 | } |
||
185 | $elements['current-registrant']['address'] = implode("<br/>", $tmp); |
||
186 | } |
||
187 | $elements['current-registrant']['modification-date'] = self::_formatdate($row->updated); |
||
188 | |||
189 | // Request from O.D. 20 May 2019: First registrant should not be empty (especially for cases where Creation and Modify Dates are the same) |
||
190 | // Actually, this is a problem because we don't know the first registrant. |
||
191 | // However, since oidinfo gets their XML very fast (if using registration), it is likely that the reported RA is still the same... |
||
192 | // ... and changes at the RA are not reported to oid-info.com anyways - the XML is only for creation |
||
193 | |||
194 | $elements['first-registrant']['first-name'] = $elements['current-registrant']['first-name']; |
||
195 | $elements['first-registrant']['last-name'] = $elements['current-registrant']['last-name']; |
||
196 | $elements['first-registrant']['address'] = $elements['current-registrant']['address']; |
||
197 | $elements['first-registrant']['email'] = $elements['current-registrant']['email']; |
||
198 | $elements['first-registrant']['phone'] = $elements['current-registrant']['phone']; |
||
199 | $elements['first-registrant']['fax'] = $elements['current-registrant']['fax']; |
||
200 | |||
201 | $elements['current-registrant']['first-name'] = ''; |
||
202 | $elements['current-registrant']['last-name'] = ''; |
||
203 | $elements['current-registrant']['address'] = ''; |
||
204 | $elements['current-registrant']['email'] = ''; |
||
205 | $elements['current-registrant']['phone'] = ''; |
||
206 | $elements['current-registrant']['fax'] = ''; |
||
207 | $elements['current-registrant']['modification-date'] = ''; |
||
208 | |||
209 | // End request O.D. 20 May 2019 |
||
210 | |||
211 | $obj = OIDplusObject::parse($row->id); |
||
212 | $oid = $obj->getOid(); // TODO: slow! |
||
213 | if (empty($oid)) continue; // e.g. if no system ID is available, then we cannot submit non-OID objects |
||
214 | echo $oa->createXMLEntry($oid, $elements, $params, $comment=$obj->nodeId()); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | echo $oa->xmlAddFooter(); |
||
219 | } |
||
220 | |||
221 | private static function _formatdate($str) { |
||
222 | $str = explode(' ',$str)[0]; |
||
223 | if ($str == '0000-00-00') $str = ''; |
||
224 | return $str; |
||
225 | } |
||
226 | |||
227 | private static function repair_relative_links($str) { |
||
228 | $str = preg_replace_callback('@(href\s*=\s*([\'"]))(.+)(\\2)@ismU', function($treffer) { |
||
229 | $url = $treffer[3]; |
||
230 | if ((stripos($url,'http') === false) && (stripos($url,'ftp') === false)) { |
||
231 | if (stripos($url,'www') === 0) { |
||
232 | $url .= 'http://' . $url; |
||
233 | } else { |
||
234 | $url = OIDplus::system_url() . $url; |
||
235 | } |
||
236 | } |
||
237 | return $treffer[1].$url.$treffer[4]; |
||
238 | }, $str); |
||
239 | return $str; |
||
240 | } |
||
61 | daniel-mar | 241 | } |
242 | |||
243 | OIDplus::registerPagePlugin(new OIDplusPageAdminOIDInfoExport()); |