Subversion Repositories oidplus

Rev

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