Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
63 changes: 63 additions & 0 deletions adminer-dg/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,69 @@ fi

echo "[adminer] Loading Adminer..."

if [ -f /srv/index.php ]; then
cat > /srv/.adminer-env-bootstrap.php <<'PHP'
<?php
$adminerFields = [
'auth[driver]' => (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, '<html') === false) {
return $html;
}

$json = json_encode($adminerPayload, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
if ($json === false) {
return $html;
}

$script = '<script>(function(){var config=' . $json . ';var loginInput=document.querySelector(' . json_encode('input[name="auth[server]"]') . ');if(!loginInput||!loginInput.form){return;}var form=loginInput.form;Object.keys(config.fields).forEach(function(name){var field=form.querySelector("[name=\""+name+"\"]");if(field){field.value=config.fields[name];}});if(config.title){document.title=config.title;var heading=document.querySelector("h1");if(heading){heading.textContent=config.title;}}if(config.autologin){var attemptKey="dockette-adminer-autologin";var usernameField=form.querySelector(' . json_encode('[name="auth[username]"]') . ');if(usernameField&&usernameField.value&&loginInput.value&&!sessionStorage.getItem(attemptKey)){sessionStorage.setItem(attemptKey,"1");form.submit();}}})();</script>';

if (stripos($html, '</body>') !== false) {
return preg_replace('~</body>~i', $script . '</body>', $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'
<?php
require __DIR__ . '/.adminer-env-bootstrap.php';
require __DIR__ . '/.adminer-index-original.php';
PHP
fi

# Set default values if not provided
MEMORY=${MEMORY:-256M}
UPLOAD=${UPLOAD:-2048M}
Expand Down
63 changes: 63 additions & 0 deletions adminer-editor/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,69 @@ fi

echo "[adminer] Loading Adminer Editor..."

if [ -f /srv/index.php ]; then
cat > /srv/.adminer-env-bootstrap.php <<'PHP'
<?php
$adminerFields = [
'auth[driver]' => (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, '<html') === false) {
return $html;
}

$json = json_encode($adminerPayload, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
if ($json === false) {
return $html;
}

$script = '<script>(function(){var config=' . $json . ';var loginInput=document.querySelector(' . json_encode('input[name="auth[server]"]') . ');if(!loginInput||!loginInput.form){return;}var form=loginInput.form;Object.keys(config.fields).forEach(function(name){var field=form.querySelector("[name=\""+name+"\"]");if(field){field.value=config.fields[name];}});if(config.title){document.title=config.title;var heading=document.querySelector("h1");if(heading){heading.textContent=config.title;}}if(config.autologin){var attemptKey="dockette-adminer-autologin";var usernameField=form.querySelector(' . json_encode('[name="auth[username]"]') . ');if(usernameField&&usernameField.value&&loginInput.value&&!sessionStorage.getItem(attemptKey)){sessionStorage.setItem(attemptKey,"1");form.submit();}}})();</script>';

if (stripos($html, '</body>') !== false) {
return preg_replace('~</body>~i', $script . '</body>', $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'
<?php
require __DIR__ . '/.adminer-env-bootstrap.php';
require __DIR__ . '/.adminer-index-original.php';
PHP
fi

# Set default values if not provided
MEMORY=${MEMORY:-256M}
UPLOAD=${UPLOAD:-2048M}
Expand Down
63 changes: 63 additions & 0 deletions adminer-full/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,69 @@ fi

echo "[adminer] Loading Adminer..."

if [ -f /srv/index.php ]; then
cat > /srv/.adminer-env-bootstrap.php <<'PHP'
<?php
$adminerFields = [
'auth[driver]' => (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, '<html') === false) {
return $html;
}

$json = json_encode($adminerPayload, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
if ($json === false) {
return $html;
}

$script = '<script>(function(){var config=' . $json . ';var loginInput=document.querySelector(' . json_encode('input[name="auth[server]"]') . ');if(!loginInput||!loginInput.form){return;}var form=loginInput.form;Object.keys(config.fields).forEach(function(name){var field=form.querySelector("[name=\""+name+"\"]");if(field){field.value=config.fields[name];}});if(config.title){document.title=config.title;var heading=document.querySelector("h1");if(heading){heading.textContent=config.title;}}if(config.autologin){var attemptKey="dockette-adminer-autologin";var usernameField=form.querySelector(' . json_encode('[name="auth[username]"]') . ');if(usernameField&&usernameField.value&&loginInput.value&&!sessionStorage.getItem(attemptKey)){sessionStorage.setItem(attemptKey,"1");form.submit();}}})();</script>';

if (stripos($html, '</body>') !== false) {
return preg_replace('~</body>~i', $script . '</body>', $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'
<?php
require __DIR__ . '/.adminer-env-bootstrap.php';
require __DIR__ . '/.adminer-index-original.php';
PHP
fi

# Copy driver plugins from /srv/plugins/drivers to /srv/adminer-plugins
if [ -d "/srv/plugins/drivers" ]; then
cp -r /srv/plugins/drivers/* /srv/adminer-plugins/ 2>/dev/null || true
Expand Down
63 changes: 63 additions & 0 deletions adminer-mongo/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,69 @@ fi

echo "[adminer] Loading Adminer (MongoDB)..."

if [ -f /srv/index.php ]; then
cat > /srv/.adminer-env-bootstrap.php <<'PHP'
<?php
$adminerFields = [
'auth[driver]' => (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, '<html') === false) {
return $html;
}

$json = json_encode($adminerPayload, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
if ($json === false) {
return $html;
}

$script = '<script>(function(){var config=' . $json . ';var loginInput=document.querySelector(' . json_encode('input[name="auth[server]"]') . ');if(!loginInput||!loginInput.form){return;}var form=loginInput.form;Object.keys(config.fields).forEach(function(name){var field=form.querySelector("[name=\""+name+"\"]");if(field){field.value=config.fields[name];}});if(config.title){document.title=config.title;var heading=document.querySelector("h1");if(heading){heading.textContent=config.title;}}if(config.autologin){var attemptKey="dockette-adminer-autologin";var usernameField=form.querySelector(' . json_encode('[name="auth[username]"]') . ');if(usernameField&&usernameField.value&&loginInput.value&&!sessionStorage.getItem(attemptKey)){sessionStorage.setItem(attemptKey,"1");form.submit();}}})();</script>';

if (stripos($html, '</body>') !== false) {
return preg_replace('~</body>~i', $script . '</body>', $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'
<?php
require __DIR__ . '/.adminer-env-bootstrap.php';
require __DIR__ . '/.adminer-index-original.php';
PHP
fi

# Set default values if not provided
MEMORY=${MEMORY:-256M}
UPLOAD=${UPLOAD:-2048M}
Expand Down
63 changes: 63 additions & 0 deletions adminer-mysql/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,69 @@ fi

echo "[adminer] Loading Adminer (MySQL)..."

if [ -f /srv/index.php ]; then
cat > /srv/.adminer-env-bootstrap.php <<'PHP'
<?php
$adminerFields = [
'auth[driver]' => (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, '<html') === false) {
return $html;
}

$json = json_encode($adminerPayload, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
if ($json === false) {
return $html;
}

$script = '<script>(function(){var config=' . $json . ';var loginInput=document.querySelector(' . json_encode('input[name="auth[server]"]') . ');if(!loginInput||!loginInput.form){return;}var form=loginInput.form;Object.keys(config.fields).forEach(function(name){var field=form.querySelector("[name=\""+name+"\"]");if(field){field.value=config.fields[name];}});if(config.title){document.title=config.title;var heading=document.querySelector("h1");if(heading){heading.textContent=config.title;}}if(config.autologin){var attemptKey="dockette-adminer-autologin";var usernameField=form.querySelector(' . json_encode('[name="auth[username]"]') . ');if(usernameField&&usernameField.value&&loginInput.value&&!sessionStorage.getItem(attemptKey)){sessionStorage.setItem(attemptKey,"1");form.submit();}}})();</script>';

if (stripos($html, '</body>') !== false) {
return preg_replace('~</body>~i', $script . '</body>', $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'
<?php
require __DIR__ . '/.adminer-env-bootstrap.php';
require __DIR__ . '/.adminer-index-original.php';
PHP
fi

# Set default values if not provided
MEMORY=${MEMORY:-256M}
UPLOAD=${UPLOAD:-2048M}
Expand Down
Loading