Rev 991 | Rev 1053 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 991 | Rev 1050 | ||
---|---|---|---|
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; |
|
- | 21 | use ViaThinkSoft\OIDplus\OIDplusGui; |
|
- | 22 | use ViaThinkSoft\OIDplus\OIDplusException; |
|
- | 23 | ||
20 | header('Content-Type:text/html; charset=UTF-8'); |
24 | header('Content-Type:text/html; charset=UTF-8'); |
21 | 25 | ||
22 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
26 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
23 | 27 | ||
24 | set_exception_handler(array('OIDplusGui', 'html_exception_handler')); |
28 | set_exception_handler(array(OIDplusGui::class, 'html_exception_handler')); |
25 | 29 | ||
26 | @set_time_limit(0); |
30 | @set_time_limit(0); |
27 | 31 | ||
28 | OIDplus::init(true); |
32 | OIDplus::init(true); |
29 | 33 | ||
30 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminNostalgia', false)) { |
34 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminNostalgia', false)) { |
31 | 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!')); |
32 | } |
36 | } |
33 | 37 | ||
34 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
38 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
35 | 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'))); |
36 | } |
40 | } |
37 | 41 | ||
38 | if (!class_exists('ZipArchive')) { |
42 | if (!class_exists('ZipArchive')) { |
39 | 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.')); |
40 | } |
44 | } |
41 | 45 | ||
42 | $dos_ids = array(); |
46 | $dos_ids = array(); |
43 | $parent_oids = array(); |
47 | $parent_oids = array(); |
44 | $i = 0; |
48 | $i = 0; |
45 | $dos_ids[''] = '00000000'; |
49 | $dos_ids[''] = '00000000'; |
46 | $parent_oids[''] = ''; |
50 | $parent_oids[''] = ''; |
47 | 51 | ||
48 | $dos_ids[''] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
52 | $dos_ids[''] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
49 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
53 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
50 | while ($row = $res->fetch_object()) { |
54 | while ($row = $res->fetch_object()) { |
51 | $oid = substr($row->id, strlen('oid:')); |
55 | $oid = substr($row->id, strlen('oid:')); |
52 | $parent_oid = substr($row->parent, strlen('oid:')); |
56 | $parent_oid = substr($row->parent, strlen('oid:')); |
53 | $dos_ids[$oid] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
57 | $dos_ids[$oid] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
54 | if ($parent_oid == '') { |
58 | if ($parent_oid == '') { |
55 | $parent_oids[$oid] = ''; |
59 | $parent_oids[$oid] = ''; |
56 | } else { |
60 | } else { |
57 | $parent_oids[$oid] = $parent_oid; |
61 | $parent_oids[$oid] = $parent_oid; |
58 | } |
62 | } |
59 | } |
63 | } |
60 | 64 | ||
61 | $tmp_file = OIDplus::localpath().'userdata/dos_export.zip'; |
65 | $tmp_file = OIDplus::localpath().'userdata/dos_export.zip'; |
62 | 66 | ||
63 | $zip = new ZipArchive(); |
67 | $zip = new ZipArchive(); |
64 | if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) { |
68 | if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) { |
65 | throw new OIDplusException("cannot open <$tmp_file>"); |
69 | throw new OIDplusException("cannot open <$tmp_file>"); |
66 | } |
70 | } |
67 | 71 | ||
68 | function make_line($command, $data) { |
72 | function make_line($command, $data) { |
69 | return $command.$data."\r\n"; |
73 | return $command.$data."\r\n"; |
70 | } |
74 | } |
71 | 75 | ||
72 | // https://github.com/danielmarschall/oidplus_dos/blob/master/OIDFILE.PAS |
76 | // https://github.com/danielmarschall/oidplus_dos/blob/master/OIDFILE.PAS |
73 | define('CMD_VERSION', 'VERS'); |
77 | define('CMD_VERSION', 'VERS'); |
74 | define('CMD_OWN_ID', 'SELF'); |
78 | define('CMD_OWN_ID', 'SELF'); |
75 | define('CMD_PARENT', 'SUPR'); |
79 | define('CMD_PARENT', 'SUPR'); |
76 | define('CMD_CHILD', 'CHLD'); |
80 | define('CMD_CHILD', 'CHLD'); |
77 | define('CMD_ASN1_IDENTIFIER', 'ASN1'); |
81 | define('CMD_ASN1_IDENTIFIER', 'ASN1'); |
78 | define('CMD_UNICODE_LABEL', 'UNIL'); |
82 | define('CMD_UNICODE_LABEL', 'UNIL'); |
79 | define('CMD_DESCRIPTION', 'DESC'); |
83 | define('CMD_DESCRIPTION', 'DESC'); |
80 | 84 | ||
81 | foreach ($dos_ids as $oid => $dos_id) { |
85 | foreach ($dos_ids as $oid => $dos_id) { |
82 | $cont = ''; |
86 | $cont = ''; |
83 | 87 | ||
84 | $cont .= make_line(CMD_VERSION, 2022); |
88 | $cont .= make_line(CMD_VERSION, 2022); |
85 | 89 | ||
86 | $cont .= make_line(CMD_OWN_ID, $dos_id.$oid); |
90 | $cont .= make_line(CMD_OWN_ID, $dos_id.$oid); |
87 | 91 | ||
88 | $parent_oid = $parent_oids[$oid]; |
92 | $parent_oid = $parent_oids[$oid]; |
89 | $parent_id = $dos_ids[$parent_oid]; |
93 | $parent_id = $dos_ids[$parent_oid]; |
90 | $cont .= make_line(CMD_PARENT, $parent_id.$parent_oid); |
94 | $cont .= make_line(CMD_PARENT, $parent_id.$parent_oid); |
91 | 95 | ||
92 | foreach ($parent_oids as $child_oid => $parent_oid) { |
96 | foreach ($parent_oids as $child_oid => $parent_oid) { |
93 | if ($child_oid == '') continue; |
97 | if ($child_oid == '') continue; |
94 | if ($parent_oid == $oid) { |
98 | if ($parent_oid == $oid) { |
95 | $child_id = $dos_ids[$child_oid]; |
99 | $child_id = $dos_ids[$child_oid]; |
96 | $cont .= make_line(CMD_CHILD, $child_id.$child_oid); |
100 | $cont .= make_line(CMD_CHILD, $child_id.$child_oid); |
97 | } |
101 | } |
98 | } |
102 | } |
99 | 103 | ||
100 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
104 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
101 | while ($row = $res->fetch_object()) { |
105 | while ($row = $res->fetch_object()) { |
102 | $asn1 = $row->name; |
106 | $asn1 = $row->name; |
103 | $cont .= make_line(CMD_ASN1_IDENTIFIER, $asn1); |
107 | $cont .= make_line(CMD_ASN1_IDENTIFIER, $asn1); |
104 | } |
108 | } |
105 | 109 | ||
106 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
110 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
107 | while ($row = $res->fetch_object()) { |
111 | while ($row = $res->fetch_object()) { |
108 | $iri = $row->name; |
112 | $iri = $row->name; |
109 | $cont .= make_line(CMD_UNICODE_LABEL, $iri); |
113 | $cont .= make_line(CMD_UNICODE_LABEL, $iri); |
110 | } |
114 | } |
111 | 115 | ||
112 | if ($oid == '') { |
116 | if ($oid == '') { |
113 | // TODO: Split our OIDplus root OIDs into the real OID tree (1, 1.3, 1.3.6, ...) |
117 | // TODO: Split our OIDplus root OIDs into the real OID tree (1, 1.3, 1.3.6, ...) |
114 | $cont .= make_line(CMD_DESCRIPTION, 'Here, you can find the root OIDs'); |
118 | $cont .= make_line(CMD_DESCRIPTION, 'Here, you can find the root OIDs'); |
115 | } else { |
119 | } else { |
116 | $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';"); |
120 | $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';"); |
117 | $row = $res->fetch_object(); |
121 | $row = $res->fetch_object(); |
118 | $desc_ary1 = handleDesc($row->title); |
122 | $desc_ary1 = handleDesc($row->title); |
119 | $desc_ary2 = handleDesc($row->description); |
123 | $desc_ary2 = handleDesc($row->description); |
120 | $desc_ary = array_merge($desc_ary1, $desc_ary2); |
124 | $desc_ary = array_merge($desc_ary1, $desc_ary2); |
121 | $prev_line = ''; |
125 | $prev_line = ''; |
122 | foreach ($desc_ary as $line_idx => $line) { |
126 | foreach ($desc_ary as $line_idx => $line) { |
123 | if ($line == $prev_line) continue; |
127 | if ($line == $prev_line) continue; |
124 | if ($line_idx >= 10/*DESCEDIT_LINES*/) break; |
128 | if ($line_idx >= 10/*DESCEDIT_LINES*/) break; |
125 | $cont .= make_line(CMD_DESCRIPTION, $line); |
129 | $cont .= make_line(CMD_DESCRIPTION, $line); |
126 | $prev_line = $line; |
130 | $prev_line = $line; |
127 | } |
131 | } |
128 | } |
132 | } |
129 | 133 | ||
130 | //echo "****$dos_id.OID\r\n"; |
134 | //echo "****$dos_id.OID\r\n"; |
131 | //echo "$cont\r\n"; |
135 | //echo "$cont\r\n"; |
132 | 136 | ||
133 | $zip->addFromString("$dos_id.OID", $cont); |
137 | $zip->addFromString("$dos_id.OID", $cont); |
134 | } |
138 | } |
135 | 139 | ||
136 | $exe_url = 'https://github.com/danielmarschall/oidplus_dos/raw/master/OIDPLUS.EXE'; |
140 | $exe_url = 'https://github.com/danielmarschall/oidplus_dos/raw/master/OIDPLUS.EXE'; |
137 | $exe = url_get_contents($exe_url); |
141 | $exe = url_get_contents($exe_url); |
138 | if (!$exe) { |
142 | if (!$exe) { |
139 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
143 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
140 | } |
144 | } |
141 | $zip->addFromString('OIDPLUS.EXE', $exe); |
145 | $zip->addFromString('OIDPLUS.EXE', $exe); |
142 | 146 | ||
143 | $zip->close(); |
147 | $zip->close(); |
144 | 148 | ||
145 | if (!headers_sent()) { |
149 | if (!headers_sent()) { |
146 | header('Content-Type: application/zip'); |
150 | header('Content-Type: application/zip'); |
147 | header('Content-Disposition: attachment; filename=oidplus_dos.zip'); |
151 | header('Content-Disposition: attachment; filename=oidplus_dos.zip'); |
148 | readfile($tmp_file); |
152 | readfile($tmp_file); |
149 | } |
153 | } |
150 | 154 | ||
151 | unlink($tmp_file); |
155 | unlink($tmp_file); |
152 | 156 | ||
153 | OIDplus::invoke_shutdown(); |
157 | OIDplus::invoke_shutdown(); |
154 | 158 | ||
155 | # --- |
159 | # --- |
156 | 160 | ||
157 | function handleDesc($desc) { |
161 | function handleDesc($desc) { |
158 | $desc = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $desc); // br2nl |
162 | $desc = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $desc); // br2nl |
159 | $desc = strip_tags($desc); |
163 | $desc = strip_tags($desc); |
160 | $desc = str_replace(' ', ' ', $desc); |
164 | $desc = str_replace(' ', ' ', $desc); |
161 | $desc = html_entity_decode($desc); |
165 | $desc = html_entity_decode($desc); |
162 | $desc = str_replace("\r", "", $desc); |
166 | $desc = str_replace("\r", "", $desc); |
163 | $desc = str_replace("\n", " ", $desc); |
167 | $desc = str_replace("\n", " ", $desc); |
164 | $desc = str_replace("\t", " ", $desc); |
168 | $desc = str_replace("\t", " ", $desc); |
165 | $desc = trim($desc); |
169 | $desc = trim($desc); |
166 | $desc_ary = explode("\r\n", wordwrap($desc, 75, "\r\n", true)); |
170 | $desc_ary = explode("\r\n", wordwrap($desc, 75, "\r\n", true)); |
167 | if (implode('',$desc_ary) == '') $desc_ary = array(); |
171 | if (implode('',$desc_ary) == '') $desc_ary = array(); |
168 | return $desc_ary; |
172 | return $desc_ary; |
169 | } |
173 | } |
170 | 174 |