From 83d68f26f33a4b314ba6b71ec8ba755c640f6f20 Mon Sep 17 00:00:00 2001 From: jschwind Date: Thu, 25 Sep 2025 10:30:16 +0200 Subject: [PATCH 1/2] Fix trailing whitespace in container_name environment variable --- .github/workflows/image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 5a9971e..4c39c9b 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -31,7 +31,7 @@ jobs: run: | docker run --name $container_name -d ${{ steps.build.outputs.image }} env: - container_name: adminer_smoke + container_name: adminer_smoke - name: Verify a restart works. if: ${{ ! contains(steps.build.outputs.image, 'fastcgi') }} run: | From b6603f82bf86cde7d6608a559a991be78d78b7ef Mon Sep 17 00:00:00 2001 From: jschwind Date: Thu, 25 Sep 2025 10:32:40 +0200 Subject: [PATCH 2/2] Set default adminer login credentials using environment variables --- 4/fastcgi/index.php | 32 +++++++++++++++++++++++++++++++- 4/index.php | 32 +++++++++++++++++++++++++++++++- 5/fastcgi/index.php | 43 ++++++++++++++++++++++++++++++++++++++++++- 5/index.php | 43 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 146 insertions(+), 4 deletions(-) diff --git a/4/fastcgi/index.php b/4/fastcgi/index.php index a48629f..82056f0 100644 --- a/4/fastcgi/index.php +++ b/4/fastcgi/index.php @@ -10,7 +10,37 @@ function _callParent($function, $args) { $return = \Adminer::loginForm(); $form = ob_get_clean(); - echo str_replace('name="auth[server]" value="" title="hostname[:port]"', 'name="auth[server]" value="'.($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db').'" title="hostname[:port]"', $form); + $form = str_replace( + 'name="auth[server]" value="" title="hostname[:port]"', + 'name="auth[server]" value="'.(getenv('ADMINER_DEFAULT_SERVER') ?: 'db').'" title="hostname[:port]"', + $form + ); + + $form = str_replace( + 'name="auth[username]" id="username" value=""', + 'name="auth[username]" value="'.(getenv('ADMINER_DEFAULT_USER') ?: '').'"', + $form + ); + + $form = str_replace( + 'name="auth[password]"', + 'name="auth[password]" value="'.(getenv('ADMINER_DEFAULT_PASSWORD') ?: '').'"', + $form + ); + + $form = str_replace( + 'name="auth[db]"', + 'name="auth[db]" value="'.(getenv('ADMINER_DEFAULT_DB') ?: '').'"', + $form + ); + + $driver = $_ENV['ADMINER_DEFAULT_DRIVER'] ?? null; + $script = ''; + if ($driver !== null && $driver !== '') { + $script = ''; + } + + echo $form . $script; return $return; } diff --git a/4/index.php b/4/index.php index a48629f..82056f0 100644 --- a/4/index.php +++ b/4/index.php @@ -10,7 +10,37 @@ function _callParent($function, $args) { $return = \Adminer::loginForm(); $form = ob_get_clean(); - echo str_replace('name="auth[server]" value="" title="hostname[:port]"', 'name="auth[server]" value="'.($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db').'" title="hostname[:port]"', $form); + $form = str_replace( + 'name="auth[server]" value="" title="hostname[:port]"', + 'name="auth[server]" value="'.(getenv('ADMINER_DEFAULT_SERVER') ?: 'db').'" title="hostname[:port]"', + $form + ); + + $form = str_replace( + 'name="auth[username]" id="username" value=""', + 'name="auth[username]" value="'.(getenv('ADMINER_DEFAULT_USER') ?: '').'"', + $form + ); + + $form = str_replace( + 'name="auth[password]"', + 'name="auth[password]" value="'.(getenv('ADMINER_DEFAULT_PASSWORD') ?: '').'"', + $form + ); + + $form = str_replace( + 'name="auth[db]"', + 'name="auth[db]" value="'.(getenv('ADMINER_DEFAULT_DB') ?: '').'"', + $form + ); + + $driver = $_ENV['ADMINER_DEFAULT_DRIVER'] ?? null; + $script = ''; + if ($driver !== null && $driver !== '') { + $script = ''; + } + + echo $form . $script; return $return; } diff --git a/5/fastcgi/index.php b/5/fastcgi/index.php index f336caf..71f3451 100644 --- a/5/fastcgi/index.php +++ b/5/fastcgi/index.php @@ -12,7 +12,7 @@ public function __construct( public function loginFormField(...$args) { return (function (...$args) { $field = $this->loginFormField(...$args); - + return \str_replace( 'name="auth[server]" value="" title="hostname[:port]"', \sprintf('name="auth[server]" value="%s" title="hostname[:port]"', ($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db')), @@ -20,6 +20,47 @@ public function loginFormField(...$args) { ); })->call($this->adminer, ...$args); } + + public function loginForm(...$args) { + return (function (...$args) { + ob_start(); + $return = $this->loginForm(...$args); + $form = ob_get_clean(); + + $form = str_replace( + 'name="auth[server]" value="" title="hostname[:port]"', + 'name="auth[server]" value="'.(getenv('ADMINER_DEFAULT_SERVER') ?: 'db').'" title="hostname[:port]"', + $form + ); + + $form = str_replace( + 'name="auth[username]" id="username" value=""', + 'name="auth[username]" value="'.(getenv('ADMINER_DEFAULT_USER') ?: '').'"', + $form + ); + + $form = str_replace( + 'name="auth[password]"', + 'name="auth[password]" value="'.(getenv('ADMINER_DEFAULT_PASSWORD') ?: '').'"', + $form + ); + + $form = str_replace( + 'name="auth[db]"', + 'name="auth[db]" value="'.(getenv('ADMINER_DEFAULT_DB') ?: '').'"', + $form + ); + + $driver = $_ENV['ADMINER_DEFAULT_DRIVER'] ?? null; + $script = ''; + if ($driver !== null && $driver !== '') { + $script = ''; + } + + echo $form . $script; + return $return; + })->call($this->adminer, ...$args); + } } $plugins = []; diff --git a/5/index.php b/5/index.php index f336caf..71f3451 100644 --- a/5/index.php +++ b/5/index.php @@ -12,7 +12,7 @@ public function __construct( public function loginFormField(...$args) { return (function (...$args) { $field = $this->loginFormField(...$args); - + return \str_replace( 'name="auth[server]" value="" title="hostname[:port]"', \sprintf('name="auth[server]" value="%s" title="hostname[:port]"', ($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db')), @@ -20,6 +20,47 @@ public function loginFormField(...$args) { ); })->call($this->adminer, ...$args); } + + public function loginForm(...$args) { + return (function (...$args) { + ob_start(); + $return = $this->loginForm(...$args); + $form = ob_get_clean(); + + $form = str_replace( + 'name="auth[server]" value="" title="hostname[:port]"', + 'name="auth[server]" value="'.(getenv('ADMINER_DEFAULT_SERVER') ?: 'db').'" title="hostname[:port]"', + $form + ); + + $form = str_replace( + 'name="auth[username]" id="username" value=""', + 'name="auth[username]" value="'.(getenv('ADMINER_DEFAULT_USER') ?: '').'"', + $form + ); + + $form = str_replace( + 'name="auth[password]"', + 'name="auth[password]" value="'.(getenv('ADMINER_DEFAULT_PASSWORD') ?: '').'"', + $form + ); + + $form = str_replace( + 'name="auth[db]"', + 'name="auth[db]" value="'.(getenv('ADMINER_DEFAULT_DB') ?: '').'"', + $form + ); + + $driver = $_ENV['ADMINER_DEFAULT_DRIVER'] ?? null; + $script = ''; + if ($driver !== null && $driver !== '') { + $script = ''; + } + + echo $form . $script; + return $return; + })->call($this->adminer, ...$args); + } } $plugins = [];