-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathentrypoint.sh
More file actions
100 lines (82 loc) · 4.06 KB
/
entrypoint.sh
File metadata and controls
100 lines (82 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -Eeo pipefail
if [ "${ADMINER_DEBUG}" = "1" ]; then
set -o xtrace
fi
# Banner
if [ "${ADMINER_BANNER}" != "0" ] && [ "${ADMINER_BANNER}" != "false" ] && [ "${ADMINER_BANNER}" != "no" ] && [ "${ADMINER_BANNER}" != "off" ]; then
cat << 'EOF'
█████╗ ██████╗ ███╗ ███╗██╗███╗ ██╗███████╗██████╗
██╔══██╗██╔══██╗████╗ ████║██║████╗ ██║██╔════╝██╔══██╗
███████║██║ ██║██╔████╔██║██║██╔██╗ ██║█████╗ ██████╔╝
██╔══██║██║ ██║██║╚██╔╝██║██║██║╚██╗██║██╔══╝ ██╔══██╗
██║ ██║██████╔╝██║ ╚═╝ ██║██║██║ ╚████║███████╗██║ ██║
╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
EOF
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}
echo "[adminer] Starting PHP server (http://0.0.0.0:80 in Docker):"
echo "-> memory_limit=${MEMORY}"
echo "-> upload_max_filesize=${UPLOAD}"
echo "-> post_max_size=${UPLOAD}"
# Execute PHP server
exec php \
-d "memory_limit=${MEMORY}" \
-d "upload_max_filesize=${UPLOAD}" \
-d "post_max_size=${UPLOAD}" \
-S 0.0.0.0:80