Rev 757 | 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); |
754 | daniel-mar | 27 | |
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/windows_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 | |||
68 | $cont = ''; |
||
69 | |||
70 | foreach ($dos_ids as $oid => $dos_id) { |
||
71 | $cont .= "[OID:$oid]\r\n"; |
||
72 | |||
73 | $i = 1; |
||
74 | foreach ($parent_oids as $child_oid => $parent_oid) { |
||
75 | if ($child_oid == '') continue; |
||
76 | if ($parent_oid == $oid) { |
||
77 | $cont .= "delegate$i=OID:$child_oid\r\n"; |
||
78 | $i++; |
||
79 | } |
||
80 | } |
||
81 | $cont .= "delegates=".($i-1)."\n"; |
||
82 | |||
83 | if ($oid != '') { |
||
84 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
||
85 | $asnids = array(); |
||
86 | while ($row = $res->fetch_object()) { |
||
87 | $asn1 = $row->name; |
||
88 | $asnids[] = $asn1; |
||
89 | } |
||
90 | $asnids = implode(',', $asnids); |
||
91 | if ($asnids != '') $cont .= "asn1id=$asnids\r\n"; |
||
92 | |||
93 | /* |
||
94 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
||
95 | $iris = array(); |
||
96 | while ($row = $res->fetch_object()) { |
||
97 | $iri = $row->name; |
||
98 | $iris[] = $iri; |
||
99 | } |
||
100 | $iris = implode(',', $iris); |
||
101 | if ($iris != '') $cont .= "iri=$iris\r\n"; |
||
102 | */ |
||
103 | |||
104 | $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';"); |
||
105 | $row = $res->fetch_object(); |
||
106 | |||
107 | if ($row->title != '') $cont .= "description=".$row->title."\r\n"; |
||
108 | |||
109 | if ($row->updated != '') $cont .= "updatedate=".explode(' ',$row->updated)[0]."\r\n"; |
||
110 | if ($row->created != '') $cont .= "createdate=".explode(' ',$row->created)[0]."\r\n"; |
||
111 | |||
112 | $desc = $row->description; |
||
113 | $desc = strip_tags($desc); |
||
114 | $desc = trim($desc); |
||
115 | if ($desc != '') { |
||
116 | $cont .= "information=$dos_id.TXT\r\n"; |
||
117 | $zip->addFromString("DB//$dos_id.TXT", $desc); |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | |||
122 | //echo '<pre>'.$cont.'</pre>'; |
||
123 | //die(); |
||
124 | |||
125 | $settings = array(); |
||
126 | $settings[] = '[SETTINGS]'; |
||
127 | $settings[] = 'DATA=DB\\'; |
||
128 | $zip->addFromString("OIDPLUS.INI", implode("\r\n",$settings)."\r\n"); |
||
129 | |||
130 | |||
131 | $zip->addFromString('DB//OID.INI', $cont); |
||
132 | |||
133 | $exe_url = 'https://github.com/danielmarschall/oidplus_win95/raw/master/OIDPLUS.exe'; |
||
963 | daniel-mar | 134 | $exe = url_get_contents($exe_url); |
135 | if (!$exe) { |
||
754 | daniel-mar | 136 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
137 | } |
||
138 | $zip->addFromString('OIDPLS32.EXE', $exe); |
||
139 | |||
140 | $exe_url = 'https://github.com/danielmarschall/oidplus_win311/raw/master/OIDPLUS.exe'; |
||
963 | daniel-mar | 141 | $exe = url_get_contents($exe_url); |
142 | if (!$exe) { |
||
754 | daniel-mar | 143 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
144 | } |
||
145 | $zip->addFromString('OIDPLS16.EXE', $exe); |
||
146 | |||
147 | $zip->close(); |
||
148 | |||
149 | if (!headers_sent()) { |
||
150 | header('Content-Type: application/zip'); |
||
151 | header('Content-Disposition: attachment; filename=oidplus_windows.zip'); |
||
152 | readfile($tmp_file); |
||
153 | } |
||
154 | |||
155 | unlink($tmp_file); |
||
156 | |||
157 | OIDplus::invoke_shutdown(); |