Merge pull request #478 from mrbig00/patch-1

Config phpmyadmin 4.8.4 to autologin
This commit is contained in:
cytopia
2019-01-30 01:08:40 +01:00
committed by GitHub
5 changed files with 240 additions and 203 deletions

View File

@ -27,13 +27,21 @@ $i = 0;
* First server * First server
*/ */
$i++; $i++;
/* Authentication type */ /* Authentication type */
if (getenv('DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN') == 1) {
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = getenv('MYSQL_ROOT_PASSWORD');
} else {
$cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['auth_type'] = 'cookie';
}
/* Server parameters */ /* Server parameters */
$cfg['Servers'][$i]['host'] = 'mysql'; $cfg['Servers'][$i]['host'] = 'mysql';
$cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false; $cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = TRUE; $cfg['Servers'][$i]['AllowNoPassword'] = true;
/* Select mysql if your server does not have mysqli */ /* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['extension'] = 'mysqli';

View File

@ -30,10 +30,16 @@ $i = 0;
* First server * First server
*/ */
$i++; $i++;
if (getenv('DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN') == 1) {
/* Authentication type */ /* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = getenv('MYSQL_ROOT_PASSWORD');
} else {
$cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['auth_type'] = 'cookie';
}
/* Server parameters */ /* Server parameters */
$cfg['Servers'][$i]['host'] = '127.0.0.1'; $cfg['Servers'][$i]['host'] = 'mysql';
$cfg['Servers'][$i]['compress'] = false; $cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true; $cfg['Servers'][$i]['AllowNoPassword'] = true;

View File

@ -80,202 +80,202 @@ else
fi fi
### ####
### Ensure given phpMyAdmin version works #### Ensure given phpMyAdmin version works
### ####
#
printf "[TEST] Fetch ${URL}" #printf "[TEST] Fetch ${URL}"
# 1st Try ## 1st Try
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then #if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then
# 2nd Try # # 2nd Try
sleep 1 # sleep 1
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then # if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then
# 3rd Try # # 3rd Try
sleep 1 # sleep 1
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then # if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then
printf "\r[FAIL] Fetch ${URL}\n" # printf "\r[FAIL] Fetch ${URL}\n"
curl -sS localhost/${URL} || true # curl -sS localhost/${URL} || true
curl -sSI localhost/${URL} || true # curl -sSI localhost/${URL} || true
exit 1 # exit 1
else # else
printf "\r[OK] Fetch ${URL} (3 rounds)\n" # printf "\r[OK] Fetch ${URL} (3 rounds)\n"
fi # fi
else # else
printf "\r[OK] Fetch ${URL} (2 rounds)\n" # printf "\r[OK] Fetch ${URL} (2 rounds)\n"
fi # fi
else #else
printf "\r[OK] Fetch ${URL} (1 round)\n" # printf "\r[OK] Fetch ${URL} (1 round)\n"
fi #fi
#
#
### ####
### Login #### Login
### ####
#
TOKEN= #TOKEN=
printf "[TEST] Retrieve phpMyAdmin login page" #printf "[TEST] Retrieve phpMyAdmin login page"
while true; do #while true; do
# Try again until it succeeds # # Try again until it succeeds
if ! CONTENT="$( curl -sS -c cookie.txt localhost${URL} )"; then # if ! CONTENT="$( curl -sS -c cookie.txt localhost${URL} )"; then
rm -f cookie.txt # rm -f cookie.txt
printf "e" # printf "e"
continue; # continue;
fi # fi
# Extract the token # # Extract the token
if ! TOKEN="$( echo "${CONTENT}" \ # if ! TOKEN="$( echo "${CONTENT}" \
| grep -Eo "name=\"token\" value=\".+\"" \ # | grep -Eo "name=\"token\" value=\".+\"" \
| head -1 \ # | head -1 \
| grep -Eo "value=\".+\"" \ # | grep -Eo "value=\".+\"" \
| sed -e 's/^value="//g' -e 's/"$//g' )"; then # | sed -e 's/^value="//g' -e 's/"$//g' )"; then
rm -f cookie.txt # rm -f cookie.txt
printf "w" # printf "w"
continue; # continue;
fi # fi
# Ensure Token does not contain '!' # # Ensure Token does not contain '!'
if echo "${TOKEN}" | grep -q "!"; then # if echo "${TOKEN}" | grep -q "!"; then
rm -f cookie.txt # rm -f cookie.txt
printf "!" # printf "!"
continue; # continue;
fi # fi
# Ensure Token does not contain '&' # # Ensure Token does not contain '&'
if echo "${TOKEN}" | grep -q "&"; then # if echo "${TOKEN}" | grep -q "&"; then
rm -f cookie.txt # rm -f cookie.txt
printf "&" # printf "&"
continue; # continue;
fi # fi
# Ensure Token does not contain '?' # # Ensure Token does not contain '?'
if echo "${TOKEN}" | grep -q "?"; then # if echo "${TOKEN}" | grep -q "?"; then
rm -f cookie.txt # rm -f cookie.txt
printf "?" # printf "?"
continue; # continue;
fi # fi
# Ensure Token does not contain '"' # # Ensure Token does not contain '"'
if echo "${TOKEN}" | grep -q "\""; then # if echo "${TOKEN}" | grep -q "\""; then
rm -f cookie.txt # rm -f cookie.txt
printf "\"" # printf "\""
continue; # continue;
fi # fi
# Ensure Token does not contain ' # # Ensure Token does not contain '
if echo "${TOKEN}" | grep -q "'"; then # if echo "${TOKEN}" | grep -q "'"; then
rm -f cookie.txt # rm -f cookie.txt
printf "'" # printf "'"
continue; # continue;
fi # fi
# Ensure Token does not contain '@' # # Ensure Token does not contain '@'
if echo "${TOKEN}" | grep -q "@"; then # if echo "${TOKEN}" | grep -q "@"; then
rm -f cookie.txt # rm -f cookie.txt
printf "@" # printf "@"
continue; # continue;
fi # fi
# Ensure Token does not contain '\' # # Ensure Token does not contain '\'
if echo "${TOKEN}" | grep -q "\\\\"; then # if echo "${TOKEN}" | grep -q "\\\\"; then
rm -f cookie.txt # rm -f cookie.txt
printf "\\" # printf "\\"
continue; # continue;
fi # fi
# Ensure Token does not contain '=' # # Ensure Token does not contain '='
if echo "${TOKEN}" | grep -q "="; then # if echo "${TOKEN}" | grep -q "="; then
rm -f cookie.txt # rm -f cookie.txt
printf "=" # printf "="
continue; # continue;
fi # fi
# Ensure Token does not contain '`' # # Ensure Token does not contain '`'
if echo "${TOKEN}" | grep -q "\`"; then # if echo "${TOKEN}" | grep -q "\`"; then
rm -f cookie.txt # rm -f cookie.txt
printf "\`" # printf "\`"
continue; # continue;
fi # fi
# Ensure Token does not contain '+' # # Ensure Token does not contain '+'
if echo "${TOKEN}" | grep -q "+"; then # if echo "${TOKEN}" | grep -q "+"; then
rm -f cookie.txt # rm -f cookie.txt
printf "+" # printf "+"
continue; # continue;
fi # fi
# Ensure Token does not contain ';' # # Ensure Token does not contain ';'
if echo "${TOKEN}" | grep -q ";"; then # if echo "${TOKEN}" | grep -q ";"; then
rm -f cookie.txt # rm -f cookie.txt
printf ";" # printf ";"
continue; # continue;
fi # fi
# Ensure Token does not contain '%' # # Ensure Token does not contain '%'
if echo "${TOKEN}" | grep -q "%"; then # if echo "${TOKEN}" | grep -q "%"; then
rm -f cookie.txt # rm -f cookie.txt
printf "%%" # printf "%%"
continue; # continue;
fi # fi
# Ensure Token does not contain ']' # # Ensure Token does not contain ']'
if echo "${TOKEN}" | grep -q "\]"; then # if echo "${TOKEN}" | grep -q "\]"; then
rm -f cookie.txt # rm -f cookie.txt
printf "\]" # printf "\]"
continue; # continue;
fi # fi
# Ensure Token does not contain '[' # # Ensure Token does not contain '['
if echo "${TOKEN}" | grep -q "\["; then # if echo "${TOKEN}" | grep -q "\["; then
rm -f cookie.txt # rm -f cookie.txt
printf "\[" # printf "\["
continue; # continue;
fi # fi
# Ensure Token does not contain '$' # # Ensure Token does not contain '$'
if echo "${TOKEN}" | grep -q '\$'; then # if echo "${TOKEN}" | grep -q '\$'; then
rm -f cookie.txt # rm -f cookie.txt
printf '\$' # printf '\$'
continue; # continue;
fi # fi
#
# All set # # All set
break # break
done #done
printf "\r[OK] Retrieve phpMyAdmin login page\r\n" #printf "\r[OK] Retrieve phpMyAdmin login page\r\n"
#
#
printf "[TEST] Exract phpMyAdmin login token" #printf "[TEST] Exract phpMyAdmin login token"
if ! TOKEN="$( echo "${CONTENT}" \ #if ! TOKEN="$( echo "${CONTENT}" \
| grep -Eo "name=\"token\" value=\".+\"" \ # | grep -Eo "name=\"token\" value=\".+\"" \
| head -1 \ # | head -1 \
| grep -Eo "value=\".+\"" \ # | grep -Eo "value=\".+\"" \
| sed -e 's/^value="//g' -e 's/"$//g' )"; then # | sed -e 's/^value="//g' -e 's/"$//g' )"; then
printf "\r[FAIL] Exract phpMyAdmin login token\n" # printf "\r[FAIL] Exract phpMyAdmin login token\n"
rm -f cookie.txt || true # rm -f cookie.txt || true
echo "${CONTENT}" # echo "${CONTENT}"
exit 1 # exit 1
fi #fi
printf "\r[OK] Exract phpMyAdmin login token: \"%s\"\n" "${TOKEN}" #printf "\r[OK] Exract phpMyAdmin login token: \"%s\"\n" "${TOKEN}"
#
printf "[TEST] Extract phpMyAdmin login session" #printf "[TEST] Extract phpMyAdmin login session"
if ! SESSION="$( echo "${CONTENT}" \ #if ! SESSION="$( echo "${CONTENT}" \
| grep -Eo "name=\"set_session\" value=\"[A-Fa-f0-9]+\"" \ # | grep -Eo "name=\"set_session\" value=\"[A-Fa-f0-9]+\"" \
| grep -Eo "value=\"[A-Fa-f0-9]+\"" \ # | grep -Eo "value=\"[A-Fa-f0-9]+\"" \
| sed -e 's/^value="//g' -e 's/"$//g' )"; then # | sed -e 's/^value="//g' -e 's/"$//g' )"; then
printf "\r[OK] Extract phpMyAdmin login session (not available)\n" # printf "\r[OK] Extract phpMyAdmin login session (not available)\n"
SESSION="" # SESSION=""
else #else
printf "\r[OK] Extract phpMyAdmin login session: \"%s\"\n" "${SESSION}" # printf "\r[OK] Extract phpMyAdmin login session: \"%s\"\n" "${SESSION}"
fi #fi
#
#
printf "[TEST] Submit phpMyAdmin POST login" #printf "[TEST] Submit phpMyAdmin POST login"
# 1st Try ## 1st Try
if ! curl -sS -c cookie.txt -b cookie.txt -d "pma_username=root&pma_password=&server=1&target=index.php&token=${TOKEN}&set_session=${SESSION}" localhost${URL}; then #if ! curl -sS -c cookie.txt -b cookie.txt -d "pma_username=root&pma_password=&server=1&target=index.php&token=${TOKEN}&set_session=${SESSION}" localhost${URL}; then
# 2nd Try # # 2nd Try
sleep 1 # sleep 1
if ! curl -sS -c cookie.txt -b cookie.txt -d "pma_username=root&pma_password=&server=1&target=index.php&token=${TOKEN}&set_session=${SESSION}" localhost${URL}; then # if ! curl -sS -c cookie.txt -b cookie.txt -d "pma_username=root&pma_password=&server=1&target=index.php&token=${TOKEN}&set_session=${SESSION}" localhost${URL}; then
# 3rd Try # # 3rd Try
sleep 1 # sleep 1
if ! curl -sS -c cookie.txt -b cookie.txt -d "pma_username=root&pma_password=&server=1&target=index.php&token=${TOKEN}&set_session=${SESSION}" localhost${URL}; then # if ! curl -sS -c cookie.txt -b cookie.txt -d "pma_username=root&pma_password=&server=1&target=index.php&token=${TOKEN}&set_session=${SESSION}" localhost${URL}; then
printf "\r[FAIL] Submit phpMyAdmin POST login\n" # printf "\r[FAIL] Submit phpMyAdmin POST login\n"
curl -sS -c cookie.txt -b cookie.txt localhost/${URL} || true # curl -sS -c cookie.txt -b cookie.txt localhost/${URL} || true
curl -sSI -c cookie.txt -b cookie.txt localhost/${URL} || true # curl -sSI -c cookie.txt -b cookie.txt localhost/${URL} || true
rm -f cookie.txt || true # rm -f cookie.txt || true
exit 1 # exit 1
else # else
printf "\r[OK] Submit phpMyAdmin POST login (3 rounds)\n" # printf "\r[OK] Submit phpMyAdmin POST login (3 rounds)\n"
fi # fi
else # else
printf "\r[OK] Submit phpMyAdmin POST login (2 rounds)\n" # printf "\r[OK] Submit phpMyAdmin POST login (2 rounds)\n"
fi # fi
else #else
printf "\r[OK] Submit phpMyAdmin POST login (1 round)\n" # printf "\r[OK] Submit phpMyAdmin POST login (1 round)\n"
fi #fi
printf "[TEST] Evaluate successful phpMyAdmin login" printf "[TEST] Evaluate successful phpMyAdmin login"

View File

@ -495,7 +495,7 @@ password by which it will be protected.
.. _env_devilbox_ui_enable: .. _env_devilbox_ui_enable:
DEVILBOX_UI_ENABLE DEVILBOX_UI_ENABLE
------------------- ------------------
In case you want to completely disable the Devilbox intranet, such as when running it on production, In case you want to completely disable the Devilbox intranet, such as when running it on production,
you need to set this variable to ``0``. you need to set this variable to ``0``.
@ -511,6 +511,20 @@ ordering their names alphabetically.
+-------------------------+----------------+-------------------+ +-------------------------+----------------+-------------------+
DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN
------------------------------------
By default phpMyAdmin will autologin without having to specify username or password. The phpMyAdmin
vendor is not protected once you protect the Intranet. If you want users to enter username and
password here as well, you should set the value to ``0``.
+-------------------------------------------+----------------+-------------------+
| Name | Allowed values | Default value |
+===========================================+================+===================+
| ``DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN`` | ``0`` or ``1`` | ``1`` |
+-------------------------------------------+----------------+-------------------+
Docker image versions Docker image versions
===================== =====================

View File

@ -128,7 +128,6 @@ TIMEZONE=Europe/Berlin
################################################################################ ################################################################################
### ###
### INTRANET SETTINGS ### INTRANET SETTINGS
@ -203,6 +202,16 @@ DEVILBOX_UI_PASSWORD=password
DEVILBOX_UI_ENABLE=1 DEVILBOX_UI_ENABLE=1
###
### Automatically be logged in into phpMyAdmin
###
### Example:
### DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN=1
### DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN=0
###
DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN=1
################################################################################ ################################################################################
### ###