diff --git a/README.md b/README.md index 3769777..8307d2a 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,30 @@ docker run \ dockette/adminer:dg ``` +You can also prefill login credentials through environment variables. + +- `ADMINER_DRIVER` (example: `pgsql`, `mysql`, `sqlite`, ...) +- `ADMINER_SERVER` (hostname or host:port) +- `ADMINER_USERNAME` +- `ADMINER_PASSWORD` +- `ADMINER_DB` (default database) +- `ADMINER_AUTOLOGIN=1` (submit the login form automatically once) +- `ADMINER_NAME` (overrides page title and heading) + +```sh +docker run \ + --rm \ + -p 8000:80 \ + -e ADMINER_DRIVER=pgsql \ + -e ADMINER_SERVER=postgres \ + -e ADMINER_USERNAME=adminer \ + -e ADMINER_PASSWORD=adminer \ + -e ADMINER_DB=adminer \ + -e ADMINER_AUTOLOGIN=1 \ + -e ADMINER_NAME="Staging DB" \ + dockette/adminer:full +``` + ## Versions | Image | Technologies | Size | Docker Hub | diff --git a/adminer-dg/entrypoint.sh b/adminer-dg/entrypoint.sh index 74f102f..dad07f3 100644 --- a/adminer-dg/entrypoint.sh +++ b/adminer-dg/entrypoint.sh @@ -19,6 +19,69 @@ fi echo "[adminer] Loading Adminer..." +if [ -f /srv/index.php ]; then + cat > /srv/.adminer-env-bootstrap.php <<'PHP' + (string) getenv('ADMINER_DRIVER'), + 'auth[server]' => (string) getenv('ADMINER_SERVER'), + 'auth[username]' => (string) getenv('ADMINER_USERNAME'), + 'auth[password]' => (string) getenv('ADMINER_PASSWORD'), + 'auth[db]' => (string) getenv('ADMINER_DB'), +]; +$adminerFields = array_filter($adminerFields, static fn ($value) => $value !== ''); +$adminerTitle = (string) getenv('ADMINER_NAME'); +$adminerAutologin = in_array( + strtolower((string) getenv('ADMINER_AUTOLOGIN')), + ['1', 'true', 'yes', 'on'], + true +); + +if (!empty($_GET['file'])) { + return; +} + +if ($adminerFields === [] && $adminerTitle === '' && !$adminerAutologin) { + return; +} + +$adminerPayload = [ + 'fields' => $adminerFields, + 'title' => $adminerTitle, + 'autologin' => $adminerAutologin, +]; + +ob_start(static function ($html) use ($adminerPayload) { + if (!is_string($html) || stripos($html, ''; + + if (stripos($html, '') !== false) { + return preg_replace('~~i', $script . '', $html, 1) ?? ($html . $script); + } + + return $html . $script; +}); +PHP + + if [ ! -f /srv/.adminer-index-original.php ]; then + cp /srv/index.php /srv/.adminer-index-original.php + fi + + cat > /srv/index.php <<'PHP' + /srv/.adminer-env-bootstrap.php <<'PHP' + (string) getenv('ADMINER_DRIVER'), + 'auth[server]' => (string) getenv('ADMINER_SERVER'), + 'auth[username]' => (string) getenv('ADMINER_USERNAME'), + 'auth[password]' => (string) getenv('ADMINER_PASSWORD'), + 'auth[db]' => (string) getenv('ADMINER_DB'), +]; +$adminerFields = array_filter($adminerFields, static fn ($value) => $value !== ''); +$adminerTitle = (string) getenv('ADMINER_NAME'); +$adminerAutologin = in_array( + strtolower((string) getenv('ADMINER_AUTOLOGIN')), + ['1', 'true', 'yes', 'on'], + true +); + +if (!empty($_GET['file'])) { + return; +} + +if ($adminerFields === [] && $adminerTitle === '' && !$adminerAutologin) { + return; +} + +$adminerPayload = [ + 'fields' => $adminerFields, + 'title' => $adminerTitle, + 'autologin' => $adminerAutologin, +]; + +ob_start(static function ($html) use ($adminerPayload) { + if (!is_string($html) || stripos($html, ''; + + if (stripos($html, '') !== false) { + return preg_replace('~~i', $script . '', $html, 1) ?? ($html . $script); + } + + return $html . $script; +}); +PHP + + if [ ! -f /srv/.adminer-index-original.php ]; then + cp /srv/index.php /srv/.adminer-index-original.php + fi + + cat > /srv/index.php <<'PHP' + /srv/.adminer-env-bootstrap.php <<'PHP' + (string) getenv('ADMINER_DRIVER'), + 'auth[server]' => (string) getenv('ADMINER_SERVER'), + 'auth[username]' => (string) getenv('ADMINER_USERNAME'), + 'auth[password]' => (string) getenv('ADMINER_PASSWORD'), + 'auth[db]' => (string) getenv('ADMINER_DB'), +]; +$adminerFields = array_filter($adminerFields, static fn ($value) => $value !== ''); +$adminerTitle = (string) getenv('ADMINER_NAME'); +$adminerAutologin = in_array( + strtolower((string) getenv('ADMINER_AUTOLOGIN')), + ['1', 'true', 'yes', 'on'], + true +); + +if (!empty($_GET['file'])) { + return; +} + +if ($adminerFields === [] && $adminerTitle === '' && !$adminerAutologin) { + return; +} + +$adminerPayload = [ + 'fields' => $adminerFields, + 'title' => $adminerTitle, + 'autologin' => $adminerAutologin, +]; + +ob_start(static function ($html) use ($adminerPayload) { + if (!is_string($html) || stripos($html, ''; + + if (stripos($html, '') !== false) { + return preg_replace('~~i', $script . '', $html, 1) ?? ($html . $script); + } + + return $html . $script; +}); +PHP + + if [ ! -f /srv/.adminer-index-original.php ]; then + cp /srv/index.php /srv/.adminer-index-original.php + fi + + cat > /srv/index.php <<'PHP' +/dev/null || true diff --git a/adminer-mongo/entrypoint.sh b/adminer-mongo/entrypoint.sh index 2b652d2..1e607f6 100644 --- a/adminer-mongo/entrypoint.sh +++ b/adminer-mongo/entrypoint.sh @@ -19,6 +19,69 @@ fi echo "[adminer] Loading Adminer (MongoDB)..." +if [ -f /srv/index.php ]; then + cat > /srv/.adminer-env-bootstrap.php <<'PHP' + (string) getenv('ADMINER_DRIVER'), + 'auth[server]' => (string) getenv('ADMINER_SERVER'), + 'auth[username]' => (string) getenv('ADMINER_USERNAME'), + 'auth[password]' => (string) getenv('ADMINER_PASSWORD'), + 'auth[db]' => (string) getenv('ADMINER_DB'), +]; +$adminerFields = array_filter($adminerFields, static fn ($value) => $value !== ''); +$adminerTitle = (string) getenv('ADMINER_NAME'); +$adminerAutologin = in_array( + strtolower((string) getenv('ADMINER_AUTOLOGIN')), + ['1', 'true', 'yes', 'on'], + true +); + +if (!empty($_GET['file'])) { + return; +} + +if ($adminerFields === [] && $adminerTitle === '' && !$adminerAutologin) { + return; +} + +$adminerPayload = [ + 'fields' => $adminerFields, + 'title' => $adminerTitle, + 'autologin' => $adminerAutologin, +]; + +ob_start(static function ($html) use ($adminerPayload) { + if (!is_string($html) || stripos($html, ''; + + if (stripos($html, '') !== false) { + return preg_replace('~~i', $script . '', $html, 1) ?? ($html . $script); + } + + return $html . $script; +}); +PHP + + if [ ! -f /srv/.adminer-index-original.php ]; then + cp /srv/index.php /srv/.adminer-index-original.php + fi + + cat > /srv/index.php <<'PHP' + /srv/.adminer-env-bootstrap.php <<'PHP' + (string) getenv('ADMINER_DRIVER'), + 'auth[server]' => (string) getenv('ADMINER_SERVER'), + 'auth[username]' => (string) getenv('ADMINER_USERNAME'), + 'auth[password]' => (string) getenv('ADMINER_PASSWORD'), + 'auth[db]' => (string) getenv('ADMINER_DB'), +]; +$adminerFields = array_filter($adminerFields, static fn ($value) => $value !== ''); +$adminerTitle = (string) getenv('ADMINER_NAME'); +$adminerAutologin = in_array( + strtolower((string) getenv('ADMINER_AUTOLOGIN')), + ['1', 'true', 'yes', 'on'], + true +); + +if (!empty($_GET['file'])) { + return; +} + +if ($adminerFields === [] && $adminerTitle === '' && !$adminerAutologin) { + return; +} + +$adminerPayload = [ + 'fields' => $adminerFields, + 'title' => $adminerTitle, + 'autologin' => $adminerAutologin, +]; + +ob_start(static function ($html) use ($adminerPayload) { + if (!is_string($html) || stripos($html, ''; + + if (stripos($html, '') !== false) { + return preg_replace('~~i', $script . '', $html, 1) ?? ($html . $script); + } + + return $html . $script; +}); +PHP + + if [ ! -f /srv/.adminer-index-original.php ]; then + cp /srv/index.php /srv/.adminer-index-original.php + fi + + cat > /srv/index.php <<'PHP' + /srv/.adminer-env-bootstrap.php <<'PHP' + (string) getenv('ADMINER_DRIVER'), + 'auth[server]' => (string) getenv('ADMINER_SERVER'), + 'auth[username]' => (string) getenv('ADMINER_USERNAME'), + 'auth[password]' => (string) getenv('ADMINER_PASSWORD'), + 'auth[db]' => (string) getenv('ADMINER_DB'), +]; +$adminerFields = array_filter($adminerFields, static fn ($value) => $value !== ''); +$adminerTitle = (string) getenv('ADMINER_NAME'); +$adminerAutologin = in_array( + strtolower((string) getenv('ADMINER_AUTOLOGIN')), + ['1', 'true', 'yes', 'on'], + true +); + +if (!empty($_GET['file'])) { + return; +} + +if ($adminerFields === [] && $adminerTitle === '' && !$adminerAutologin) { + return; +} + +$adminerPayload = [ + 'fields' => $adminerFields, + 'title' => $adminerTitle, + 'autologin' => $adminerAutologin, +]; + +ob_start(static function ($html) use ($adminerPayload) { + if (!is_string($html) || stripos($html, ''; + + if (stripos($html, '') !== false) { + return preg_replace('~~i', $script . '', $html, 1) ?? ($html . $script); + } + + return $html . $script; +}); +PHP + + if [ ! -f /srv/.adminer-index-original.php ]; then + cp /srv/index.php /srv/.adminer-index-original.php + fi + + cat > /srv/index.php <<'PHP' + /srv/.adminer-env-bootstrap.php <<'PHP' + (string) getenv('ADMINER_DRIVER'), + 'auth[server]' => (string) getenv('ADMINER_SERVER'), + 'auth[username]' => (string) getenv('ADMINER_USERNAME'), + 'auth[password]' => (string) getenv('ADMINER_PASSWORD'), + 'auth[db]' => (string) getenv('ADMINER_DB'), +]; +$adminerFields = array_filter($adminerFields, static fn ($value) => $value !== ''); +$adminerTitle = (string) getenv('ADMINER_NAME'); +$adminerAutologin = in_array( + strtolower((string) getenv('ADMINER_AUTOLOGIN')), + ['1', 'true', 'yes', 'on'], + true +); + +if (!empty($_GET['file'])) { + return; +} + +if ($adminerFields === [] && $adminerTitle === '' && !$adminerAutologin) { + return; +} + +$adminerPayload = [ + 'fields' => $adminerFields, + 'title' => $adminerTitle, + 'autologin' => $adminerAutologin, +]; + +ob_start(static function ($html) use ($adminerPayload) { + if (!is_string($html) || stripos($html, ''; + + if (stripos($html, '') !== false) { + return preg_replace('~~i', $script . '', $html, 1) ?? ($html . $script); + } + + return $html . $script; +}); +PHP + + if [ ! -f /srv/.adminer-index-original.php ]; then + cp /srv/index.php /srv/.adminer-index-original.php + fi + + cat > /srv/index.php <<'PHP' + /srv/.adminer-env-bootstrap.php <<'PHP' + (string) getenv('ADMINER_DRIVER'), + 'auth[server]' => (string) getenv('ADMINER_SERVER'), + 'auth[username]' => (string) getenv('ADMINER_USERNAME'), + 'auth[password]' => (string) getenv('ADMINER_PASSWORD'), + 'auth[db]' => (string) getenv('ADMINER_DB'), +]; +$adminerFields = array_filter($adminerFields, static fn ($value) => $value !== ''); +$adminerTitle = (string) getenv('ADMINER_NAME'); +$adminerAutologin = in_array( + strtolower((string) getenv('ADMINER_AUTOLOGIN')), + ['1', 'true', 'yes', 'on'], + true +); + +if (!empty($_GET['file'])) { + return; +} + +if ($adminerFields === [] && $adminerTitle === '' && !$adminerAutologin) { + return; +} + +$adminerPayload = [ + 'fields' => $adminerFields, + 'title' => $adminerTitle, + 'autologin' => $adminerAutologin, +]; + +ob_start(static function ($html) use ($adminerPayload) { + if (!is_string($html) || stripos($html, ''; + + if (stripos($html, '') !== false) { + return preg_replace('~~i', $script . '', $html, 1) ?? ($html . $script); + } + + return $html . $script; +}); +PHP + + if [ ! -f /srv/.adminer-index-original.php ]; then + cp /srv/index.php /srv/.adminer-index-original.php + fi + + cat > /srv/index.php <<'PHP' +