Last active
February 10, 2024 06:49
-
-
Save lincolnthalles/ff19020626557cf26e677b40e8efe22a to your computer and use it in GitHub Desktop.
Run official Adminer Docker with auto-login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "3.0" | |
| name: adminer | |
| services: | |
| adminer: | |
| image: adminer | |
| environment: | |
| ADMINER_DEFAULT_DRIVER: sqlite # server=mysql, pgsql, sqlite, sqlite2, oracle, mssql, mongo, elastic | |
| ADMINER_DEFAULT_DB: /data/database.db # path to SQLite database or DBMS database name | |
| ADMINER_DEFAULT_SERVER: # DBMS IP or hostname | |
| ADMINER_DEFAULT_USERNAME: | |
| ADMINER_DEFAULT_PASSWORD: | |
| ADMINER_DESIGN: dracula # use 'pepa-linha' for a nice light theme. https://www.adminer.org/#extras | |
| ADMINER_PLUGINS: tables-filter table-structure edit-textarea dump-json # https://www.adminer.org/en/plugins/ | |
| volumes: | |
| - datavolume:/data # set-up volumes or mounts, if using SQLite | |
| ports: [127.0.0.1:8091:8080] # binding to localhost restricts access to local network | |
| configs: [{ source: adminer-index.php, target: /var/www/html/index.php }] | |
| configs: | |
| adminer-index.php: | |
| # Patched version of index.php to set default values for adminer and to | |
| # allow passwordless login whenever ADMINER_DEFAULT_DRIVER is sqlite. | |
| content: | | |
| <?php | |
| namespace docker { | |
| function adminer_object() { | |
| require_once('plugins/plugin.php'); | |
| class Adminer extends \AdminerPlugin { | |
| function _callParent($$function, $$args) { | |
| if ($$function === 'loginForm') { | |
| ob_start(); | |
| $$return = \Adminer::loginForm(); | |
| $$form = ob_get_clean(); | |
| $$driver = $$_ENV["ADMINER_DEFAULT_DRIVER"] ?: "server"; | |
| $$server = $$_ENV["ADMINER_DEFAULT_SERVER"] ?: "db"; | |
| $$username = $$_ENV["ADMINER_DEFAULT_USERNAME"]; | |
| $$password = $$_ENV["ADMINER_DEFAULT_PASSWORD"]; | |
| $$db = $$_ENV["ADMINER_DEFAULT_DB"]; | |
| $$form = preg_replace('/ name="auth\[server\]" value="(.*)"/', ' name="auth[server]" value="' . $$server . '"', $$form); | |
| $$form = str_replace(' id="username" value="" ', ' id="username" value="' . $$username . '" ', $$form); | |
| $$form = str_replace('name="auth[db]" value=""', 'name="auth[db]" value="' . $$db . '" ', $$form); | |
| $$form = str_replace('type="password"', 'type="password" value="' . $$password . '"', $$form); | |
| $$form = preg_replace('/<option value="(.*)" selected/', '/<option value="$$1"/', $$form); | |
| $$form = preg_replace('/<option value="' . $$driver . '"/', '<option value="' . $$driver . '" selected', $$form); | |
| echo $$form; | |
| return $$return; | |
| } | |
| return parent::_callParent($$function, $$args); | |
| } | |
| } | |
| $$plugins = []; | |
| foreach (glob('plugins-enabled/*.php') as $$plugin) { | |
| $$plugins[] = require($$plugin); | |
| } | |
| class AdminerSoftware extends Adminer { | |
| function login($$login, $$password) { | |
| return substr($$_ENV["ADMINER_DEFAULT_DRIVER"], 0, 6) == 'sqlite' ? true : parent::login($$login, $$password); | |
| } | |
| } | |
| return new AdminerSoftware($$plugins); | |
| } | |
| } | |
| namespace { | |
| if (basename($$_SERVER['DOCUMENT_URI'] ?? $$_SERVER['REQUEST_URI']) === 'adminer.css' && is_readable('adminer.css')) { | |
| header('Content-Type: text/css'); | |
| readfile('adminer.css'); | |
| exit; | |
| } | |
| function adminer_object() { | |
| return \docker\adminer_object(); | |
| } | |
| require('adminer.php'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment