Path: blob/main/databases/adminer/files/makephar.php
18878 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* All 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 (original Adminer)24*25* Licensed under the Apache License, Version 2.0 (the "License");26* you may not use this file except in compliance with the License.27* You may obtain a copy of the License at28*29* http://www.apache.org/licenses/LICENSE-2.030*31* Unless required by applicable law or agreed to in writing, software32* distributed under the License is distributed on an "AS IS" BASIS,33* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.34* See the License for the specific language governing permissions and35* limitations under the License.36*37******************************************************************************/38if (file_exists(\$adminerObjectFile = __DIR__ . '/adminer-object.php'))39{40require \$adminerObjectFile;41}42Phar::mapPhar('adminer.phar');43define('ADMINER_PLUGIN_CLASSMAP', json_decode('%s', true));44require 'phar://adminer.phar/autoload.php';45__HALT_COMPILER();46STUB;4748$classMap = [];49$plugins = [];5051foreach(new DirectoryIterator(__DIR__ . '/plugins') as $file)52{53if ($file->isFile())54{55$contents = php_strip_whitespace($file->getRealPath());56$fileName = $file->getFileName();57$pharFile = 'adminer-plugins/' . $fileName;5859if (60/**61* Skip affected plugin62* https://nvd.nist.gov/vuln/detail/CVE-2023-4519763*/64$fileName !== 'file-upload.php'65/**66* Adminer editor's plugins are only relevant67* in Adminer editor.68*/69&& !str_starts_with($fileName, 'editor')70&& preg_match('/class\s(A[a-zA-Z0-9]+)\sextends\sAdminer/', $contents, $m)71) {72$plugins[$pharFile] = $contents;73$classMap[$m[1]] = $file->getFileName();74}75}76}7778ksort($classMap);7980$phar->setStub(81sprintf(82$stub,83json_encode($classMap, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)84)85);8687$autoLoader = <<<LOADER88<?php89spl_autoload_register(function(\$class)90{91if (isset(ADMINER_PLUGIN_CLASSMAP[\$class]))92{93require __DIR__ . '/adminer-plugins/' . ADMINER_PLUGIN_CLASSMAP[\$class];94return true;95}96});97require __DIR__ . '/adminer.php';98LOADER;99100$phar->addFromString(101'autoload.php',102$autoLoader103);104105foreach($plugins as $file => $contents)106{107$phar->addFromString(108$file,109$contents110);111}112113$phar->addFromString(114'adminer.php',115php_strip_whitespace(__DIR__ . '/adminer.php'),116);117118rename($tmpFile, __DIR__ . '/index.php');119120121