Subversion Repositories oidplus

Rev

Rev 991 | Rev 1053 | 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
 
1050 daniel-mar 20
use ViaThinkSoft\OIDplus\OIDplus;
21
use ViaThinkSoft\OIDplus\OIDplusGui;
22
use ViaThinkSoft\OIDplus\OIDplusException;
23
 
754 daniel-mar 24
header('Content-Type:text/html; charset=UTF-8');
25
 
26
require_once __DIR__ . '/../../../../includes/oidplus.inc.php';
27
 
1050 daniel-mar 28
set_exception_handler(array(OIDplusGui::class, 'html_exception_handler'));
754 daniel-mar 29
 
757 daniel-mar 30
@set_time_limit(0);
754 daniel-mar 31
 
32
OIDplus::init(true);
33
 
1050 daniel-mar 34
if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminNostalgia', false)) {
754 daniel-mar 35
        throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
36
}
37
 
756 daniel-mar 38
if (!OIDplus::authUtils()->isAdminLoggedIn()) {
39
        throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
40
}
41
 
755 daniel-mar 42
if (!class_exists('ZipArchive')) {
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.'));
44
}
45
 
754 daniel-mar 46
$dos_ids = array();
47
$parent_oids = array();
48
$i = 0;
49
$dos_ids[''] = '00000000';
50
$parent_oids[''] = '';
51
 
757 daniel-mar 52
$dos_ids[''] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT);
754 daniel-mar 53
$res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id'));
54
while ($row = $res->fetch_object()) {
55
        $oid = substr($row->id, strlen('oid:'));
56
        $parent_oid = substr($row->parent, strlen('oid:'));
757 daniel-mar 57
        $dos_ids[$oid] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT);
754 daniel-mar 58
        if ($parent_oid == '') {
59
                $parent_oids[$oid] = '';
60
        } else {
61
                $parent_oids[$oid] = $parent_oid;
62
        }
63
}
64
 
65
$tmp_file = OIDplus::localpath().'userdata/windows_export.zip';
66
 
67
$zip = new ZipArchive();
68
if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) {
69
        throw new OIDplusException("cannot open <$tmp_file>");
70
}
71
 
72
$cont = '';
73
 
74
foreach ($dos_ids as $oid => $dos_id) {
75
        $cont .= "[OID:$oid]\r\n";
76
 
77
        $i = 1;
78
        foreach ($parent_oids as $child_oid => $parent_oid) {
79
                if ($child_oid == '') continue;
80
                if ($parent_oid == $oid) {
81
                        $cont .= "delegate$i=OID:$child_oid\r\n";
82
                        $i++;
83
                }
84
        }
85
        $cont .= "delegates=".($i-1)."\n";
86
 
87
        if ($oid != '') {
88
                $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'");
89
                $asnids = array();
90
                while ($row = $res->fetch_object()) {
91
                        $asn1 = $row->name;
92
                        $asnids[] = $asn1;
93
                }
94
                $asnids = implode(',', $asnids);
95
                if ($asnids != '') $cont .= "asn1id=$asnids\r\n";
96
 
97
                /*
98
                $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'");
99
                $iris = array();
100
                while ($row = $res->fetch_object()) {
101
                        $iri = $row->name;
102
                        $iris[] = $iri;
103
                }
104
                $iris = implode(',', $iris);
105
                if ($iris != '') $cont .= "iri=$iris\r\n";
106
                */
107
 
108
                $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';");
109
                $row = $res->fetch_object();
110
 
111
                if ($row->title != '') $cont .= "description=".$row->title."\r\n";
112
 
113
                if ($row->updated != '') $cont .= "updatedate=".explode(' ',$row->updated)[0]."\r\n";
114
                if ($row->created != '') $cont .= "createdate=".explode(' ',$row->created)[0]."\r\n";
115
 
991 daniel-mar 116
                $desc = handleDesc($row->description);
754 daniel-mar 117
                if ($desc != '') {
118
                        $cont .= "information=$dos_id.TXT\r\n";
119
                        $zip->addFromString("DB//$dos_id.TXT", $desc);
120
                }
121
        }
122
}
123
 
124
//echo '<pre>'.$cont.'</pre>';
125
//die();
126
 
127
$settings = array();
128
$settings[] = '[SETTINGS]';
129
$settings[] = 'DATA=DB\\';
130
$zip->addFromString("OIDPLUS.INI", implode("\r\n",$settings)."\r\n");
131
 
132
 
133
$zip->addFromString('DB//OID.INI', $cont);
134
 
135
$exe_url = 'https://github.com/danielmarschall/oidplus_win95/raw/master/OIDPLUS.exe';
963 daniel-mar 136
$exe = url_get_contents($exe_url);
137
if (!$exe) {
754 daniel-mar 138
        throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url));
139
}
140
$zip->addFromString('OIDPLS32.EXE', $exe);
141
 
142
$exe_url = 'https://github.com/danielmarschall/oidplus_win311/raw/master/OIDPLUS.exe';
963 daniel-mar 143
$exe = url_get_contents($exe_url);
144
if (!$exe) {
754 daniel-mar 145
        throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url));
146
}
147
$zip->addFromString('OIDPLS16.EXE', $exe);
148
 
149
$zip->close();
150
 
151
if (!headers_sent()) {
152
        header('Content-Type: application/zip');
153
        header('Content-Disposition: attachment; filename=oidplus_windows.zip');
154
        readfile($tmp_file);
155
}
156
 
157
unlink($tmp_file);
158
 
159
OIDplus::invoke_shutdown();
991 daniel-mar 160
 
161
# ---
162
 
163
function handleDesc($desc) {
164
        $desc = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $desc); // br2nl
165
        $desc = strip_tags($desc);
166
        $desc = str_replace('&nbsp;', ' ', $desc);
167
        $desc = html_entity_decode($desc);
168
        $desc = str_replace("\r", "", $desc);
169
        $desc = str_replace("\n", "\r\n", $desc);
170
        $desc = trim($desc)."\r\n";
171
        return $desc;
172
}