Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/databases/adminer/files/makephar.php
18878 views
1
<?php
2
/***********************************************************
3
*
4
* Merges adminer.php and it's plugins to a phar archive
5
*
6
***********************************************************/
7
8
$phar = new Phar(
9
$tmpFile = __DIR__ . '/adminer_' . bin2hex(random_bytes(8)) . '.phar',
10
0,
11
'adminer.phar'
12
);
13
14
$stub = <<<STUB
15
<?php
16
/******************************************************************************
17
*
18
* All Adminer plugins are now included in this
19
* FreeBSD ports edition, no need to download
20
* them separately.
21
* https://www.adminer.org/en/plugins/
22
*
23
* copyright Paavo-Einari Kaipila (FreeBSD ports edition)
24
* copyright Jakub Vrana (original Adminer)
25
*
26
* Licensed under the Apache License, Version 2.0 (the "License");
27
* you may not use this file except in compliance with the License.
28
* You may obtain a copy of the License at
29
*
30
* http://www.apache.org/licenses/LICENSE-2.0
31
*
32
* Unless required by applicable law or agreed to in writing, software
33
* distributed under the License is distributed on an "AS IS" BASIS,
34
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35
* See the License for the specific language governing permissions and
36
* limitations under the License.
37
*
38
******************************************************************************/
39
if (file_exists(\$adminerObjectFile = __DIR__ . '/adminer-object.php'))
40
{
41
require \$adminerObjectFile;
42
}
43
Phar::mapPhar('adminer.phar');
44
define('ADMINER_PLUGIN_CLASSMAP', json_decode('%s', true));
45
require 'phar://adminer.phar/autoload.php';
46
__HALT_COMPILER();
47
STUB;
48
49
$classMap = [];
50
$plugins = [];
51
52
foreach(new DirectoryIterator(__DIR__ . '/plugins') as $file)
53
{
54
if ($file->isFile())
55
{
56
$contents = php_strip_whitespace($file->getRealPath());
57
$fileName = $file->getFileName();
58
$pharFile = 'adminer-plugins/' . $fileName;
59
60
if (
61
/**
62
* Skip affected plugin
63
* https://nvd.nist.gov/vuln/detail/CVE-2023-45197
64
*/
65
$fileName !== 'file-upload.php'
66
/**
67
* Adminer editor's plugins are only relevant
68
* in Adminer editor.
69
*/
70
&& !str_starts_with($fileName, 'editor')
71
&& preg_match('/class\s(A[a-zA-Z0-9]+)\sextends\sAdminer/', $contents, $m)
72
) {
73
$plugins[$pharFile] = $contents;
74
$classMap[$m[1]] = $file->getFileName();
75
}
76
}
77
}
78
79
ksort($classMap);
80
81
$phar->setStub(
82
sprintf(
83
$stub,
84
json_encode($classMap, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)
85
)
86
);
87
88
$autoLoader = <<<LOADER
89
<?php
90
spl_autoload_register(function(\$class)
91
{
92
if (isset(ADMINER_PLUGIN_CLASSMAP[\$class]))
93
{
94
require __DIR__ . '/adminer-plugins/' . ADMINER_PLUGIN_CLASSMAP[\$class];
95
return true;
96
}
97
});
98
require __DIR__ . '/adminer.php';
99
LOADER;
100
101
$phar->addFromString(
102
'autoload.php',
103
$autoLoader
104
);
105
106
foreach($plugins as $file => $contents)
107
{
108
$phar->addFromString(
109
$file,
110
$contents
111
);
112
}
113
114
$phar->addFromString(
115
'adminer.php',
116
php_strip_whitespace(__DIR__ . '/adminer.php'),
117
);
118
119
rename($tmpFile, __DIR__ . '/index.php');
120
121