Rev 755 | Go to most recent revision | Details | 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 | |||
26 | OIDplus::init(true); |
||
27 | |||
28 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminOIDInfoExport', false)) { |
||
29 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
||
30 | } |
||
31 | |||
32 | $dos_ids = array(); |
||
33 | $parent_oids = array(); |
||
34 | $i = 0; |
||
35 | $dos_ids[''] = '00000000'; |
||
36 | $parent_oids[''] = ''; |
||
37 | |||
38 | $dos_ids[''] = str_pad($i++, 8, '0', STR_PAD_LEFT); |
||
39 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
||
40 | while ($row = $res->fetch_object()) { |
||
41 | $oid = substr($row->id, strlen('oid:')); |
||
42 | $parent_oid = substr($row->parent, strlen('oid:')); |
||
43 | $dos_ids[$oid] = str_pad($i++, 8, '0', STR_PAD_LEFT); |
||
44 | if ($parent_oid == '') { |
||
45 | $parent_oids[$oid] = ''; |
||
46 | } else { |
||
47 | $parent_oids[$oid] = $parent_oid; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | $tmp_file = OIDplus::localpath().'userdata/dos_export.zip'; |
||
52 | |||
53 | $zip = new ZipArchive(); |
||
54 | if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) { |
||
55 | throw new OIDplusException("cannot open <$tmp_file>"); |
||
56 | } |
||
57 | |||
58 | foreach ($dos_ids as $oid => $dos_id) { |
||
59 | $cont = ''; |
||
60 | |||
61 | $cont .= "VERS2022\r\n"; |
||
62 | |||
63 | $cont .= "SELF$dos_id$oid\r\n"; |
||
64 | |||
65 | $parent_oid = $parent_oids[$oid]; |
||
66 | $parent_id = $dos_ids[$parent_oid]; |
||
67 | $cont .= "SUPR$parent_id$parent_oid\r\n"; |
||
68 | |||
69 | foreach ($parent_oids as $child_oid => $parent_oid) { |
||
70 | if ($child_oid == '') continue; |
||
71 | if ($parent_oid == $oid) { |
||
72 | $child_id = $dos_ids[$child_oid]; |
||
73 | $cont .= "CHLD$child_id$child_oid\r\n"; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
||
78 | while ($row = $res->fetch_object()) { |
||
79 | $asn1 = $row->name; |
||
80 | $cont .= "ASN1$asn1\r\n"; |
||
81 | } |
||
82 | |||
83 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
||
84 | while ($row = $res->fetch_object()) { |
||
85 | $iri = $row->name; |
||
86 | $cont .= "UNIL$iri\r\n"; |
||
87 | } |
||
88 | |||
89 | if ($oid == '') { |
||
90 | // TODO: Split in single parent OIDs |
||
91 | $cont .= "DESCHere, you can find the root OIDs.\r\n"; |
||
92 | } else { |
||
93 | $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';"); |
||
94 | $row = $res->fetch_object(); |
||
95 | $desc = trim(trim(strip_tags($row->description))); |
||
96 | $desc = str_replace("\r", "", $desc); |
||
97 | $desc = str_replace("\n", " ", $desc); |
||
98 | $desc_ary1 = explode("\r\n", wordwrap($desc, 80/*TREEVIEW_WIDTH*/, "\r\n", true)); |
||
99 | $desc_ary2 = explode("\r\n", wordwrap($row->title, 80/*TREEVIEW_WIDTH*/, "\r\n", true)); |
||
100 | if (implode('',$desc_ary1) == '') $desc_ary1 = array(); |
||
101 | if (implode('',$desc_ary2) == '') $desc_ary2 = array(); |
||
102 | $desc_ary = array_merge($desc_ary1, $desc_ary2); |
||
103 | foreach ($desc_ary as $line_idx => $line) { |
||
104 | if ($line_idx >= 10/*DESCEDIT_LINES*/) break; |
||
105 | $cont .= "DESC$line\r\n"; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | //echo "****$dos_id.OID\r\n"; |
||
110 | //echo "$cont\r\n"; |
||
111 | |||
112 | $zip->addFromString("$dos_id.OID", $cont); |
||
113 | } |
||
114 | |||
115 | $exe_url = 'https://github.com/danielmarschall/oidplus_dos/raw/master/OIDPLUS.EXE'; |
||
116 | $exe = @file_get_contents($exe_url); |
||
117 | if ($exe == '') { |
||
118 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
||
119 | } |
||
120 | $zip->addFromString('OIDPLUS.EXE', $exe); |
||
121 | |||
122 | $zip->close(); |
||
123 | |||
124 | if (!headers_sent()) { |
||
125 | header('Content-Type: application/zip'); |
||
126 | header('Content-Disposition: attachment; filename=oidplus_dos.zip'); |
||
127 | readfile($tmp_file); |
||
128 | } |
||
129 | |||
130 | unlink($tmp_file); |
||
131 | |||
132 | OIDplus::invoke_shutdown(); |