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