Rev 755 | Rev 757 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 755 | Rev 756 | ||
---|---|---|---|
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 | header('Content-Type:text/html; charset=UTF-8'); |
20 | header('Content-Type:text/html; charset=UTF-8'); |
21 | 21 | ||
22 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
22 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
23 | 23 | ||
24 | set_exception_handler(array('OIDplusGui', 'html_exception_handler')); |
24 | set_exception_handler(array('OIDplusGui', 'html_exception_handler')); |
25 | 25 | ||
26 | ob_start(); // allow cookie headers to be sent |
26 | ob_start(); // allow cookie headers to be sent |
27 | 27 | ||
28 | OIDplus::init(true); |
28 | OIDplus::init(true); |
29 | 29 | ||
30 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminOIDInfoExport', false)) { |
30 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminNostalgia', false)) { |
31 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
31 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
32 | } |
32 | } |
- | 33 | ||
- | 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 | } |
|
33 | 37 | ||
34 | if (!class_exists('ZipArchive')) { |
38 | if (!class_exists('ZipArchive')) { |
35 | 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.')); |
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.')); |
36 | } |
40 | } |
37 | 41 | ||
38 | $dos_ids = array(); |
42 | $dos_ids = array(); |
39 | $parent_oids = array(); |
43 | $parent_oids = array(); |
40 | $i = 0; |
44 | $i = 0; |
41 | $dos_ids[''] = '00000000'; |
45 | $dos_ids[''] = '00000000'; |
42 | $parent_oids[''] = ''; |
46 | $parent_oids[''] = ''; |
43 | 47 | ||
44 | $dos_ids[''] = str_pad($i++, 8, '0', STR_PAD_LEFT); |
48 | $dos_ids[''] = str_pad($i++, 8, '0', STR_PAD_LEFT); |
45 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
49 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
46 | while ($row = $res->fetch_object()) { |
50 | while ($row = $res->fetch_object()) { |
47 | $oid = substr($row->id, strlen('oid:')); |
51 | $oid = substr($row->id, strlen('oid:')); |
48 | $parent_oid = substr($row->parent, strlen('oid:')); |
52 | $parent_oid = substr($row->parent, strlen('oid:')); |
49 | $dos_ids[$oid] = str_pad($i++, 8, '0', STR_PAD_LEFT); |
53 | $dos_ids[$oid] = str_pad($i++, 8, '0', STR_PAD_LEFT); |
50 | if ($parent_oid == '') { |
54 | if ($parent_oid == '') { |
51 | $parent_oids[$oid] = ''; |
55 | $parent_oids[$oid] = ''; |
52 | } else { |
56 | } else { |
53 | $parent_oids[$oid] = $parent_oid; |
57 | $parent_oids[$oid] = $parent_oid; |
54 | } |
58 | } |
55 | } |
59 | } |
56 | 60 | ||
57 | $tmp_file = OIDplus::localpath().'userdata/windows_export.zip'; |
61 | $tmp_file = OIDplus::localpath().'userdata/windows_export.zip'; |
58 | 62 | ||
59 | $zip = new ZipArchive(); |
63 | $zip = new ZipArchive(); |
60 | if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) { |
64 | if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) { |
61 | throw new OIDplusException("cannot open <$tmp_file>"); |
65 | throw new OIDplusException("cannot open <$tmp_file>"); |
62 | } |
66 | } |
63 | 67 | ||
64 | $cont = ''; |
68 | $cont = ''; |
65 | 69 | ||
66 | foreach ($dos_ids as $oid => $dos_id) { |
70 | foreach ($dos_ids as $oid => $dos_id) { |
67 | $cont .= "[OID:$oid]\r\n"; |
71 | $cont .= "[OID:$oid]\r\n"; |
68 | 72 | ||
69 | $i = 1; |
73 | $i = 1; |
70 | foreach ($parent_oids as $child_oid => $parent_oid) { |
74 | foreach ($parent_oids as $child_oid => $parent_oid) { |
71 | if ($child_oid == '') continue; |
75 | if ($child_oid == '') continue; |
72 | if ($parent_oid == $oid) { |
76 | if ($parent_oid == $oid) { |
73 | $cont .= "delegate$i=OID:$child_oid\r\n"; |
77 | $cont .= "delegate$i=OID:$child_oid\r\n"; |
74 | $i++; |
78 | $i++; |
75 | } |
79 | } |
76 | } |
80 | } |
77 | $cont .= "delegates=".($i-1)."\n"; |
81 | $cont .= "delegates=".($i-1)."\n"; |
78 | 82 | ||
79 | if ($oid != '') { |
83 | if ($oid != '') { |
80 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
84 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
81 | $asnids = array(); |
85 | $asnids = array(); |
82 | while ($row = $res->fetch_object()) { |
86 | while ($row = $res->fetch_object()) { |
83 | $asn1 = $row->name; |
87 | $asn1 = $row->name; |
84 | $asnids[] = $asn1; |
88 | $asnids[] = $asn1; |
85 | } |
89 | } |
86 | $asnids = implode(',', $asnids); |
90 | $asnids = implode(',', $asnids); |
87 | if ($asnids != '') $cont .= "asn1id=$asnids\r\n"; |
91 | if ($asnids != '') $cont .= "asn1id=$asnids\r\n"; |
88 | 92 | ||
89 | /* |
93 | /* |
90 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
94 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
91 | $iris = array(); |
95 | $iris = array(); |
92 | while ($row = $res->fetch_object()) { |
96 | while ($row = $res->fetch_object()) { |
93 | $iri = $row->name; |
97 | $iri = $row->name; |
94 | $iris[] = $iri; |
98 | $iris[] = $iri; |
95 | } |
99 | } |
96 | $iris = implode(',', $iris); |
100 | $iris = implode(',', $iris); |
97 | if ($iris != '') $cont .= "iri=$iris\r\n"; |
101 | if ($iris != '') $cont .= "iri=$iris\r\n"; |
98 | */ |
102 | */ |
99 | 103 | ||
100 | $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';"); |
104 | $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';"); |
101 | $row = $res->fetch_object(); |
105 | $row = $res->fetch_object(); |
102 | 106 | ||
103 | if ($row->title != '') $cont .= "description=".$row->title."\r\n"; |
107 | if ($row->title != '') $cont .= "description=".$row->title."\r\n"; |
104 | 108 | ||
105 | if ($row->updated != '') $cont .= "updatedate=".explode(' ',$row->updated)[0]."\r\n"; |
109 | if ($row->updated != '') $cont .= "updatedate=".explode(' ',$row->updated)[0]."\r\n"; |
106 | if ($row->created != '') $cont .= "createdate=".explode(' ',$row->created)[0]."\r\n"; |
110 | if ($row->created != '') $cont .= "createdate=".explode(' ',$row->created)[0]."\r\n"; |
107 | 111 | ||
108 | $desc = $row->description; |
112 | $desc = $row->description; |
109 | $desc = strip_tags($desc); |
113 | $desc = strip_tags($desc); |
110 | $desc = trim($desc); |
114 | $desc = trim($desc); |
111 | if ($desc != '') { |
115 | if ($desc != '') { |
112 | $cont .= "information=$dos_id.TXT\r\n"; |
116 | $cont .= "information=$dos_id.TXT\r\n"; |
113 | $zip->addFromString("DB//$dos_id.TXT", $desc); |
117 | $zip->addFromString("DB//$dos_id.TXT", $desc); |
114 | } |
118 | } |
115 | } |
119 | } |
116 | } |
120 | } |
117 | 121 | ||
118 | //echo '<pre>'.$cont.'</pre>'; |
122 | //echo '<pre>'.$cont.'</pre>'; |
119 | //die(); |
123 | //die(); |
120 | 124 | ||
121 | $settings = array(); |
125 | $settings = array(); |
122 | $settings[] = '[SETTINGS]'; |
126 | $settings[] = '[SETTINGS]'; |
123 | $settings[] = 'DATA=DB\\'; |
127 | $settings[] = 'DATA=DB\\'; |
124 | $zip->addFromString("OIDPLUS.INI", implode("\r\n",$settings)."\r\n"); |
128 | $zip->addFromString("OIDPLUS.INI", implode("\r\n",$settings)."\r\n"); |
125 | 129 | ||
126 | 130 | ||
127 | $zip->addFromString('DB//OID.INI', $cont); |
131 | $zip->addFromString('DB//OID.INI', $cont); |
128 | 132 | ||
129 | $exe_url = 'https://github.com/danielmarschall/oidplus_win95/raw/master/OIDPLUS.exe'; |
133 | $exe_url = 'https://github.com/danielmarschall/oidplus_win95/raw/master/OIDPLUS.exe'; |
130 | $exe = @file_get_contents($exe_url); |
134 | $exe = @file_get_contents($exe_url); |
131 | if ($exe == '') { |
135 | if ($exe == '') { |
132 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
136 | throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url)); |
133 | } |
137 | } |
134 | $zip->addFromString('OIDPLS32.EXE', $exe); |
138 | $zip->addFromString('OIDPLS32.EXE', $exe); |
135 | 139 | ||
136 | $exe_url = 'https://github.com/danielmarschall/oidplus_win311/raw/master/OIDPLUS.exe'; |
140 | $exe_url = 'https://github.com/danielmarschall/oidplus_win311/raw/master/OIDPLUS.exe'; |
137 | $exe = @file_get_contents($exe_url); |
141 | $exe = @file_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('OIDPLS16.EXE', $exe); |
145 | $zip->addFromString('OIDPLS16.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_windows.zip'); |
151 | header('Content-Disposition: attachment; filename=oidplus_windows.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 |