Subversion Repositories oidplus

Rev

Rev 132 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 139
Line 16... Line 16...
16
 * See the License for the specific language governing permissions and
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
17
 * limitations under the License.
18
 */
18
 */
19
 
19
 
20
require_once __DIR__ . '/../../../includes/oidplus.inc.php';
20
require_once __DIR__ . '/../../../includes/oidplus.inc.php';
21
require_once __DIR__ . '/../../../includes/oidinfo_api.inc.php';
-
 
22
 
21
 
23
header('Content-Type:text/html; charset=UTF-8');
22
header('Content-Type:text/html; charset=UTF-8');
24
 
23
 
25
OIDplus::init(true);
24
OIDplus::init(true);
26
 
25
 
27
OIDplus::db()->set_charset("UTF8");
26
OIDplus::db()->set_charset("UTF8");
28
OIDplus::db()->query("SET NAMES 'utf8'");
27
OIDplus::db()->query("SET NAMES 'utf8'");
29
 
28
 
30
# ---
29
# ---
31
 
30
 
32
if (OIDplus::config()->getValue('oidinfo_export_protected') && !OIDplus::authUtils()::isAdminLoggedIn()) {
31
if (!OIDplus::authUtils()::isAdminLoggedIn()) {
33
        echo '<p>You need to <a href="'.OIDplus::system_url().'?goto=oidplus:login">log in</a> as administrator.</p>';
32
        echo '<p>You need to <a href="'.OIDplus::system_url().'?goto=oidplus:login">log in</a> as administrator.</p>';
34
        die();
33
        die();
35
}
34
}
36
 
35
 
37
header('Content-Type:text/xml');
36
header('Content-Type:text/xml');
38
 
37
 
39
$oa = new OIDInfoAPI();
-
 
40
$oa->addSimplePingProvider('viathinksoft.de:49500');
-
 
41
 
-
 
42
$email = OIDplus::config()->getValue('admin_email');
-
 
43
if (empty($email)) $email = 'unknown@example.com';
-
 
44
 
-
 
45
echo $oa->xmlAddHeader(OIDplus::config()->systemTitle(), isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'Export interface', $email);
-
 
46
 
-
 
47
$params['allow_html'] = true;
-
 
48
$params['allow_illegal_email'] = true; // It should be enabled, because the creator could have used some kind of human-readable anti-spam technique
-
 
49
$params['soft_correct_behavior'] = OIDInfoAPI::SOFT_CORRECT_BEHAVIOR_NONE;
-
 
50
$params['do_online_check'] = false; // Flag to disable this online check, because it generates a lot of traffic and runtime.
-
 
51
$params['do_illegality_check'] = true;
-
 
52
$params['do_simpleping_check'] = true;
-
 
53
$params['auto_extract_name'] = '';
-
 
54
$params['auto_extract_url'] = '';
-
 
55
$params['always_output_comment'] = false;
-
 
56
$params['creation_allowed_check'] = isset($_GET['online']) && $_GET['online'];
38
OIDplusPageAdminOIDInfoExport::outputXML(isset($_GET['online']) && $_GET['online']);
57
$params['tolerant_htmlentities'] = true;
-
 
58
$params['ignore_xhtml_light'] = false;
-
 
59
 
-
 
60
$nonConfidential = OIDplusObject::getAllNonConfidential();
-
 
61
 
-
 
62
foreach ($nonConfidential as $id) {
-
 
63
        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where id = '".OIDplus::db()->real_escape_string($id)."'");
-
 
64
        if ($row = OIDplus::db()->fetch_object($res)) {
-
 
65
                $elements['identifier'] = array();
-
 
66
                $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = '".OIDplus::db()->real_escape_string($row->id)."'");
-
 
67
                while ($row2 = OIDplus::db()->fetch_object($res2)) {
-
 
68
                        $elements['identifier'][] = $row2->name; // 'unicode-label' is currently not in the standard format (oid.xsd)
-
 
69
                }
-
 
70
 
-
 
71
                $elements['unicode-label'] = array();
-
 
72
                $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = '".OIDplus::db()->real_escape_string($row->id)."'");
-
 
73
                while ($row2 = OIDplus::db()->fetch_object($res2)) {
-
 
74
                        $elements['unicode-label'][] = $row2->name;
-
 
75
                }
-
 
76
 
-
 
77
                $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = '".OIDplus::db()->real_escape_string($row->ra_email)."'");
-
 
78
                $row2 = OIDplus::db()->fetch_object($res2);
-
 
79
 
-
 
80
                if (!empty($row->title)) {
-
 
81
                        $elements['description'] = $row->title;
-
 
82
                        $elements['information'] = $row->description;
-
 
83
                        if (trim($row->title) == trim(strip_tags($row->description))) {
-
 
84
                                $elements['information'] = '';
-
 
85
                        }
-
 
86
                } else if (isset($elements['identifier'][0])) {
-
 
87
                        $elements['description'] = '"'.$elements['identifier'][0].'"';
-
 
88
                        $elements['information'] = $row->description;
-
 
89
                } else if (isset($elements['unicode-label'][0])) {
-
 
90
                        $elements['description'] = '"'.$elements['unicode-label'][0].'"';
-
 
91
                        $elements['information'] = $row->description;
-
 
92
                } else if (!empty($row->description)) {
-
 
93
                        $elements['description'] = $row->description;
-
 
94
                        $elements['information'] = '';
-
 
95
                } else {
-
 
96
                        $elements['description'] = '<i>No description available</i>';
-
 
97
                        $elements['information'] = '';
-
 
98
                }
-
 
99
 
-
 
100
                if ($elements['information'] != '') {
-
 
101
                        $elements['information'] .= '<br/><br/>';
-
 
102
                }
-
 
103
 
-
 
104
                $elements['information'] .= 'See <a href="'.OIDplus::system_url(false).'?goto='.urlencode($id).'">more information</a>.'; // TODO: system_url() geht nicht bei CLI
-
 
105
 
-
 
106
                if (explode(':',$id,2)[0] != 'oid') {
-
 
107
                        $elements['information'] = "Object: $id\n\n" . $elements['information'];
-
 
108
                }
-
 
109
 
-
 
110
                $elements['description'] = repair_relative_links($elements['description']);
-
 
111
                $elements['information'] = repair_relative_links($elements['information']);
-
 
112
 
-
 
113
                $elements['first-registrant']['first-name'] = '';
-
 
114
                $elements['first-registrant']['last-name'] = '';
-
 
115
                $elements['first-registrant']['address'] = '';
-
 
116
                $elements['first-registrant']['email'] = '';
-
 
117
                $elements['first-registrant']['phone'] = '';
-
 
118
                $elements['first-registrant']['fax'] = '';
-
 
119
                $elements['first-registrant']['creation-date'] = _formatdate($row->created);
-
 
120
 
-
 
121
                $elements['current-registrant']['first-name'] = $row2 ? $row2->ra_name : '';
-
 
122
                $elements['current-registrant']['last-name'] = '';
-
 
123
                $elements['current-registrant']['email'] = $row->ra_email;
-
 
124
 
-
 
125
                $elements['current-registrant']['phone'] = '';
-
 
126
                $elements['current-registrant']['fax'] = '';
-
 
127
                $elements['current-registrant']['address'] = '';
-
 
128
                if ($row2) {
-
 
129
                        $tmp = array();
-
 
130
                        if (!empty($row2->organization)  && ($row2->organization  != $row2->ra_name)) $tmp[] = $row2->organization;
-
 
131
                        if (!empty($row2->office)        && ($row2->office        != $row2->ra_name)) $tmp[] = $row2->office;
-
 
132
                        if (!empty($row2->personal_name) && ($row2->personal_name != $row2->ra_name)) $tmp[] = (!empty($row2->organization) ? 'c/o ' : '') . $row2->personal_name;
-
 
133
                        if (!$row2->privacy) {
-
 
134
                                if (!empty($row2->street))   $tmp[] = $row2->street;
-
 
135
                                if (!empty($row2->zip_town)) $tmp[] = $row2->zip_town;
-
 
136
                                if (!empty($row2->country))  $tmp[] = $row2->country;
-
 
137
                                $elements['current-registrant']['phone'] = !empty($row2->phone) ? $row2->phone : $row2->mobile;
-
 
138
                                $elements['current-registrant']['fax'] = $row2->fax;
-
 
139
                        }
-
 
140
                        $elements['current-registrant']['address'] = implode("<br/>", $tmp);
-
 
141
                }
-
 
142
                $elements['current-registrant']['modification-date'] = _formatdate($row->updated);
-
 
143
 
-
 
144
 
-
 
145
                // Request from O.D. 20 May 2019: First registrant should not be empty (especially for cases where Creation and Modify Dates are the same)
-
 
146
                // Actually, this is a problem because we don't know the first registrant.
-
 
147
                // However, since oidinfo gets their XML very fast (if using registration), it is likely that the reported RA is still the same...
-
 
148
                // ... and changes at the RA are not reported to oid-info.com anyways - the XML is only for creation
-
 
149
 
-
 
150
                $elements['first-registrant']['first-name'] = $elements['current-registrant']['first-name'];
-
 
151
                $elements['first-registrant']['last-name']  = $elements['current-registrant']['last-name'];
-
 
152
                $elements['first-registrant']['address']    = $elements['current-registrant']['address'];
-
 
153
                $elements['first-registrant']['email']      = $elements['current-registrant']['email'];
-
 
154
                $elements['first-registrant']['phone']      = $elements['current-registrant']['phone'];
-
 
155
                $elements['first-registrant']['fax']        = $elements['current-registrant']['fax'];
-
 
156
 
-
 
157
                $elements['current-registrant']['first-name'] = '';
-
 
158
                $elements['current-registrant']['last-name'] = '';
-
 
159
                $elements['current-registrant']['address'] = '';
-
 
160
                $elements['current-registrant']['email'] = '';
-
 
161
                $elements['current-registrant']['phone'] = '';
-
 
162
                $elements['current-registrant']['fax'] = '';
-
 
163
                $elements['current-registrant']['modification-date'] = '';
-
 
164
 
-
 
165
                // End request O.D. 20 May 2019
-
 
166
 
-
 
167
 
-
 
168
                $obj = OIDplusObject::parse($row->id);
-
 
169
                $oid = $obj->getOid();
-
 
170
                if (empty($oid)) continue; // e.g. if no system ID is available, then we cannot submit non-OID objects
-
 
171
                echo $oa->createXMLEntry($oid, $elements, $params, $comment=$obj->nodeId());
-
 
172
        }
-
 
173
 
-
 
174
        flush();
-
 
175
}
-
 
176
 
-
 
177
echo $oa->xmlAddFooter();
-
 
178
 
-
 
179
# ---
-
 
180
 
-
 
181
function _formatdate($str) {
-
 
182
        $str = explode(' ',$str)[0];
-
 
183
        if ($str == '0000-00-00') $str = '';
-
 
184
        return $str;
-
 
185
}
-
 
186
 
-
 
187
function repair_relative_links($str) {
-
 
188
        $str = preg_replace_callback('@(href\s*=\s*([\'"]))(.+)(\\2)@ismU', function($treffer) {
-
 
189
                $url = $treffer[3];
-
 
190
                if ((stripos($url,'http') === false) && (stripos($url,'ftp') === false)) {
-
 
191
                        if (stripos($url,'www') === 0) {
-
 
192
                                $url .= 'http://' . $url;
-
 
193
                        } else {
-
 
194
                                $url = OIDplus::system_url() . $url;
-
 
195
                        }
-
 
196
                }
-
 
197
                return $treffer[1].$url.$treffer[4];
-
 
198
        }, $str);
-
 
199
        return $str;
-
 
200
}
-
 
201
 
39