Path: blob/main/databases/adminer/files/makephar.php
20810 views
<?php1/***********************************************************2*3* Merges adminer.php and it's plugins to a phar archive4*5***********************************************************/67$phar = new Phar(8$tmpFile = __DIR__ . '/adminer_' . bin2hex(random_bytes(8)) . '.phar',90,10'adminer.phar'11);1213$stub = <<<STUB14<?php15/******************************************************************************16*17* Adminer plugins are now included in this18* FreeBSD ports edition, no need to download19* them separately.20* https://www.adminer.org/en/plugins/21*22* copyright Paavo-Einari Kaipila (FreeBSD ports edition)23* copyright Jakub Vrana (Adminer)24* copyright MirLach (ForcedServer plugin)25* copyright Pematon (Collations, JsonPreview, LoginServers and SimpleMenu plugins)26*27* Licensed under the Apache License, Version 2.0 (the "License");28* you may not use this file except in compliance with the License.29* You may obtain a copy of the License at30*31* http://www.apache.org/licenses/LICENSE-2.032*33* Unless required by applicable law or agreed to in writing, software34* distributed under the License is distributed on an "AS IS" BASIS,35* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.36* See the License for the specific language governing permissions and37* limitations under the License.38*39******************************************************************************/40if (file_exists(\$adminerObjectFile = __DIR__ . '/adminer-object.php'))41{42require \$adminerObjectFile;43}44Phar::mapPhar('adminer.phar');45define('ADMINER_PLUGIN_CLASSMAP', json_decode('%s', true));46require 'phar://adminer.phar/autoload.php';47__HALT_COMPILER();48STUB;4950$classMap = [];51$plugins = [];5253foreach(new DirectoryIterator(__DIR__ . '/plugins') as $file)54{55if ($file->isFile())56{57$contents = php_strip_whitespace($file->getRealPath());58$fileName = $file->getFileName();59$pharFile = 'adminer-plugins/' . $fileName;6061if (62/**63* Skip affected plugin64* https://nvd.nist.gov/vuln/detail/CVE-2023-4519765*/66$fileName !== 'file-upload.php'67/**68* Adminer editor's plugins are only relevant69* in Adminer editor.70*/71&& !str_starts_with($fileName, 'editor')72&& preg_match('/class\s(A[a-zA-Z0-9]+)\s(extends\sAdminer|\{)/', $contents, $m)73) {74$plugins[$pharFile] = $contents;75$classMap[$m[1]] = $file->getFileName();76}77}78}7980ksort($classMap);8182$phar->setStub(83sprintf(84$stub,85json_encode($classMap, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)86)87);8889$autoLoader = <<<LOADER90<?php91spl_autoload_register(function(\$class)92{93if (isset(ADMINER_PLUGIN_CLASSMAP[\$class]))94{95require __DIR__ . '/adminer-plugins/' . ADMINER_PLUGIN_CLASSMAP[\$class];96return true;97}98});99require __DIR__ . '/adminer.php';100LOADER;101102$phar->addFromString(103'autoload.php',104$autoLoader105);106107foreach($plugins as $file => $contents)108{109$phar->addFromString(110$file,111$contents112);113}114$phar->compressFiles(Phar::GZ);115116$phar->addFromString(117'adminer.php',118php_strip_whitespace(__DIR__ . '/adminer.php'),119);120121rename($tmpFile, __DIR__ . '/index.php');122123124