Subversion Repositories oidplus

Rev

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