Rev 1050 | Rev 1064 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1050 | Rev 1053 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
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 | use ViaThinkSoft\OIDplus\OIDplus; |
20 | use ViaThinkSoft\OIDplus\OIDplus; |
21 | use ViaThinkSoft\OIDplus\OIDplusGui; |
21 | use ViaThinkSoft\OIDplus\OIDplusGui; |
22 | use ViaThinkSoft\OIDplus\OIDplusException; |
22 | use ViaThinkSoft\OIDplus\OIDplusException; |
23 | 23 | ||
24 | header('Content-Type:text/html; charset=UTF-8'); |
24 | header('Content-Type:text/html; charset=UTF-8'); |
25 | 25 | ||
26 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
26 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
27 | 27 | ||
28 | set_exception_handler(array(OIDplusGui::class, 'html_exception_handler')); |
28 | set_exception_handler(array(OIDplusGui::class, 'html_exception_handler')); |
29 | 29 | ||
30 | @set_time_limit(0); |
30 | @set_time_limit(0); |
31 | 31 | ||
32 | OIDplus::init(true); |
32 | OIDplus::init(true); |
33 | 33 | ||
34 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminNostalgia', false)) { |
34 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminNostalgia', false)) { |
35 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
35 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
36 | } |
36 | } |
37 | 37 | ||
38 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
38 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
39 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
39 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
40 | } |
40 | } |
41 | 41 | ||
42 | if (!class_exists('ZipArchive')) { |
42 | if (!class_exists('ZipArchive')) { |
43 | throw new OIDplusException(_L('The PHP extension "ZipArchive" needs to be installed to create a ZIP archive with an included database. Otherwise, you can just download the plain program without data.')); |
43 | throw new OIDplusException(_L('The PHP extension "ZipArchive" needs to be installed to create a ZIP archive with an included database. Otherwise, you can just download the plain program without data.')); |
44 | } |
44 | } |
45 | 45 | ||
46 | $dos_ids = array(); |
46 | $dos_ids = array(); |
47 | $parent_oids = array(); |
47 | $parent_oids = array(); |
48 | $i = 0; |
48 | $i = 0; |
49 | $dos_ids[''] = '00000000'; |
- | |
50 | $parent_oids[''] = ''; |
- | |
51 | 49 | ||
- | 50 | // Root node |
|
52 | $dos_ids[''] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
51 | $dos_ids[''] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
- | 52 | $parent_oids[''] = ''; |
|
- | 53 | $iri[''] = array(); |
|
- | 54 | $asn1[''] = array(); |
|
- | 55 | $title[''] = 'OID Root'; |
|
- | 56 | $description[''] = 'Exported by OIDplus 2.0'; |
|
- | 57 | $created[''] = ''; |
|
- | 58 | $updated[''] = ''; |
|
- | 59 | ||
- | 60 | // Now check all OIDs |
|
53 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
61 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
54 | while ($row = $res->fetch_object()) { |
62 | while ($row = $res->fetch_object()) { |
55 | $oid = substr($row->id, strlen('oid:')); |
63 | $oid = substr($row->id, strlen('oid:')); |
56 | $parent_oid = substr($row->parent, strlen('oid:')); |
64 | $parent_oid = substr($row->parent, strlen('oid:')); |
- | 65 | ||
57 | $dos_ids[$oid] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
66 | $dos_ids[$oid] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
- | 67 | fill_asn1($oid, $asn1); |
|
- | 68 | //fill_iri($oid, $iri); |
|
- | 69 | $title[$oid] = $row->title; |
|
- | 70 | $description[$oid] = $row->description; |
|
- | 71 | $created[$oid] = $row->created; |
|
- | 72 | $updated[$oid] = $row->updated; |
|
- | 73 | ||
58 | if ($parent_oid == '') { |
74 | if ((oid_len($oid) > 1) && ($parent_oid == '')) { |
- | 75 | do { |
|
- | 76 | $real_parent = oid_len($oid) > 1 ? oid_up($oid) : ''; |
|
59 | $parent_oids[$oid] = ''; |
77 | $parent_oids[$oid] = $real_parent; |
- | 78 | ||
- | 79 | if (isset($dos_ids[$real_parent])) break; // did we already handle this parent node? |
|
- | 80 | ||
- | 81 | $dos_ids[$real_parent] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
|
- | 82 | fill_asn1($real_parent, $asn1); // well-known OIDs? |
|
- | 83 | //fill_iri($real_parent, $iri); // well-known OIDs? |
|
- | 84 | $title[$real_parent] = ''; |
|
- | 85 | $description[$real_parent] = ''; |
|
- | 86 | $created[$real_parent] = ''; |
|
- | 87 | $updated[$real_parent] = ''; |
|
- | 88 | $res2 = OIDplus::db()->query("select * from ###objects where id = 'oid:$real_parent'"); |
|
- | 89 | while ($row2 = $res2->fetch_object()) { |
|
- | 90 | $title[$real_parent] = $row2->title; |
|
- | 91 | $description[$real_parent] = $row2->description; |
|
- | 92 | $created[$real_parent] = $row2->created; |
|
- | 93 | $updated[$real_parent] = $row2->updated; |
|
- | 94 | } |
|
- | 95 | ||
- | 96 | // next |
|
- | 97 | if ($real_parent == '') break; |
|
- | 98 | $oid = $real_parent; |
|
- | 99 | } while (true); |
|
60 | } else { |
100 | } else { |
61 | $parent_oids[$oid] = $parent_oid; |
101 | $parent_oids[$oid] = $parent_oid; |
62 | } |
102 | } |
63 | } |
103 | } |
64 | 104 | ||
65 | $tmp_file = OIDplus::localpath().'userdata/windows_export.zip'; |
105 | $tmp_file = OIDplus::localpath().'userdata/windows_export.zip'; |
66 | 106 | ||
67 | $zip = new ZipArchive(); |
107 | $zip = new ZipArchive(); |
68 | if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) { |
108 | if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) { |
69 | throw new OIDplusException("cannot open <$tmp_file>"); |
109 | throw new OIDplusException("cannot open <$tmp_file>"); |
70 | } |
110 | } |
71 | 111 | ||
72 | $cont = ''; |
112 | $cont = ''; |
73 | 113 | ||
74 | foreach ($dos_ids as $oid => $dos_id) { |
114 | foreach ($dos_ids as $oid => $dos_id) { |
75 | $cont .= "[OID:$oid]\r\n"; |
115 | $cont .= "[OID:$oid]\r\n"; |
76 | 116 | ||
77 | $i = 1; |
117 | $i = 1; |
78 | foreach ($parent_oids as $child_oid => $parent_oid) { |
118 | foreach ($parent_oids as $child_oid => $parent_oid) { |
79 | if ($child_oid == '') continue; |
119 | if ($child_oid == '') continue; |
80 | if ($parent_oid == $oid) { |
120 | if ($parent_oid == $oid) { |
81 | $cont .= "delegate$i=OID:$child_oid\r\n"; |
121 | $cont .= "delegate$i=OID:$child_oid\r\n"; |
82 | $i++; |
122 | $i++; |
83 | } |
123 | } |
84 | } |
124 | } |
85 | $cont .= "delegates=".($i-1)."\n"; |
125 | $cont .= "delegates=".($i-1)."\n"; |
86 | 126 | ||
87 | if ($oid != '') { |
127 | if ($oid != '') { |
88 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
- | |
89 | $asnids = array(); |
128 | $asnids = array(); |
90 | while ($row = $res->fetch_object()) { |
- | |
91 | $asn1 = $row->name; |
129 | foreach ($asn1[$oid] as $name) { |
92 | $asnids[] = $asn1; |
130 | $asnids[] = $name; |
93 | } |
131 | } |
94 | $asnids = implode(',', $asnids); |
132 | $asnids = implode(',', $asnids); |
95 | if ($asnids != '') $cont .= "asn1id=$asnids\r\n"; |
133 | if ($asnids != '') $cont .= "asn1id=$asnids\r\n"; |
96 | 134 | ||
97 | /* |
135 | /* |
98 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
- | |
99 | $iris = array(); |
136 | $iris = array(); |
100 | while ($row = $res->fetch_object()) { |
- | |
101 | $iri = $row->name; |
137 | foreach ($iri[$oid] as $name) { |
102 | $iris[] = $iri; |
138 | $iris[] = $name; |
103 | } |
139 | } |
104 | $iris = implode(',', $iris); |
140 | $iris = implode(',', $iris); |
105 | if ($iris != '') $cont .= "iri=$iris\r\n"; |
141 | if ($iris != '') $cont .= "iri=$iris\r\n"; |
106 | */ |
142 | */ |
107 | 143 | ||
108 | $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';"); |
- | |
109 | $row = $res->fetch_object(); |
- | |
110 | - | ||
111 | if ($row->title != '') $cont .= "description=".$row->title."\r\n"; |
144 | if ($title[$oid] != '') $cont .= "description=".$title[$oid]."\r\n"; |
112 | 145 | ||
113 | if ($row->updated != '') $cont .= "updatedate=".explode(' ',$row->updated)[0]."\r\n"; |
146 | if ($updated[$oid] != '') $cont .= "updatedate=".explode(' ',$updated[$oid])[0]."\r\n"; |
114 | if ($row->created != '') $cont .= "createdate=".explode(' ',$row->created)[0]."\r\n"; |
147 | if ($created[$oid] != '') $cont .= "createdate=".explode(' ',$created[$oid])[0]."\r\n"; |
115 | 148 | ||
116 | $desc = handleDesc($row->description); |
149 | $desc = handleDesc($description[$oid]); |
117 | if ($desc != '') { |
150 | if (trim($desc) != '') { |
118 | $cont .= "information=$dos_id.TXT\r\n"; |
151 | $cont .= "information=$dos_id.TXT\r\n"; |
119 | $zip->addFromString("DB//$dos_id.TXT", $desc); |
152 | $zip->addFromString("DB//$dos_id.TXT", $desc); |
120 | } |
153 | } |
121 | } |
154 | } |
122 | } |
155 | } |
123 | 156 | ||
124 | //echo '<pre>'.$cont.'</pre>'; |
157 | //echo '<pre>'.$cont.'</pre>'; |
125 | //die(); |
158 | //die(); |
126 | 159 | ||
127 | $settings = array(); |
160 | $settings = array(); |
128 | $settings[] = '[SETTINGS]'; |
161 | $settings[] = '[SETTINGS]'; |
129 | $settings[] = 'DATA=DB\\'; |
162 | $settings[] = 'DATA=DB\\'; |
130 | $zip->addFromString("OIDPLUS.INI", implode("\r\n",$settings)."\r\n"); |
163 | $zip->addFromString("OIDPLUS.INI", implode("\r\n",$settings)."\r\n"); |
131 | 164 | ||
132 | - | ||
133 | $zip->addFromString('DB//OID.INI', $cont); |
165 | $zip->addFromString('DB//OID.INI', $cont); |
134 | 166 | ||
135 | $exe_url = 'https://github.com/danielmarschall/oidplus_win95/raw/master/OIDPLUS.exe'; |
167 | $exe_url = 'https://github.com/danielmarschall/oidplus_win95/raw/master/OIDPLUS.exe'; |
136 | $exe = url_get_contents($exe_url); |
168 | $exe = url_get_contents($exe_url); |
137 | if (!$exe) { |
169 | if (!$exe) { |
138 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
170 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
139 | } |
171 | } |
140 | $zip->addFromString('OIDPLS32.EXE', $exe); |
172 | $zip->addFromString('OIDPLS32.EXE', $exe); |
141 | 173 | ||
142 | $exe_url = 'https://github.com/danielmarschall/oidplus_win311/raw/master/OIDPLUS.exe'; |
174 | $exe_url = 'https://github.com/danielmarschall/oidplus_win311/raw/master/OIDPLUS.exe'; |
143 | $exe = url_get_contents($exe_url); |
175 | $exe = url_get_contents($exe_url); |
144 | if (!$exe) { |
176 | if (!$exe) { |
145 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
177 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
146 | } |
178 | } |
147 | $zip->addFromString('OIDPLS16.EXE', $exe); |
179 | $zip->addFromString('OIDPLS16.EXE', $exe); |
148 | 180 | ||
149 | $zip->close(); |
181 | $zip->close(); |
150 | 182 | ||
151 | if (!headers_sent()) { |
183 | if (!headers_sent()) { |
152 | header('Content-Type: application/zip'); |
184 | header('Content-Type: application/zip'); |
153 | header('Content-Disposition: attachment; filename=oidplus_windows.zip'); |
185 | header('Content-Disposition: attachment; filename=oidplus_windows.zip'); |
154 | readfile($tmp_file); |
186 | readfile($tmp_file); |
155 | } |
187 | } |
156 | 188 | ||
157 | unlink($tmp_file); |
189 | unlink($tmp_file); |
158 | 190 | ||
159 | OIDplus::invoke_shutdown(); |
191 | OIDplus::invoke_shutdown(); |
160 | 192 | ||
161 | # --- |
193 | # --- |
162 | 194 | ||
- | 195 | function fill_asn1($oid, &$asn1) { |
|
- | 196 | if (!isset($asn1[$oid])) $asn1[$oid] = array(); |
|
- | 197 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
|
- | 198 | while ($row = $res->fetch_object()) { |
|
- | 199 | $asn1[$oid][] = $row->name; |
|
- | 200 | } |
|
- | 201 | } |
|
- | 202 | ||
- | 203 | /* |
|
- | 204 | function fill_iri($oid, &$iri) { |
|
- | 205 | if (!isset($iri[$oid])) $iri[$oid] = array(); |
|
- | 206 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
|
- | 207 | while ($row = $res->fetch_object()) { |
|
- | 208 | $iri[$oid][] = $row->name; |
|
- | 209 | } |
|
- | 210 | } |
|
- | 211 | */ |
|
- | 212 | ||
163 | function handleDesc($desc) { |
213 | function handleDesc($desc) { |
164 | $desc = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $desc); // br2nl |
214 | $desc = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $desc); // br2nl |
165 | $desc = strip_tags($desc); |
215 | $desc = strip_tags($desc); |
166 | $desc = str_replace(' ', ' ', $desc); |
216 | $desc = str_replace(' ', ' ', $desc); |
167 | $desc = html_entity_decode($desc); |
217 | $desc = html_entity_decode($desc); |
168 | $desc = str_replace("\r", "", $desc); |
218 | $desc = str_replace("\r", "", $desc); |
169 | $desc = str_replace("\n", "\r\n", $desc); |
219 | $desc = str_replace("\n", "\r\n", $desc); |
170 | $desc = trim($desc)."\r\n"; |
220 | $desc = trim($desc)."\r\n"; |
171 | return $desc; |
221 | return $desc; |
172 | } |
222 | } |
173 | 223 |