Subversion Repositories oidplus

Rev

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