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