Skip to content

Instantly share code, notes, and snippets.

Last active Sep 21, 2022
What would you like to do?
Adminer MongoDB docker image
FROM adminer:4.7.1
USER root
RUN apk add autoconf gcc g++ make libffi-dev openssl-dev
RUN pecl install mongodb
RUN echo "" > /usr/local/etc/php/conf.d/docker-php-ext-mongodb.ini
# MongoDB allows connections without password.
# But that doesn't fly with Adminer which prints 'Database does not support password.' for such case.
# Jakub Vrana (Adminer author says): (
# This is what Adminer does:
# 1. Connect with password.
# 2. If it fails, report the error.
# 3. If it succeeds, try to connect without the password.
# 4. If it succeeds, report "Database does not support password." because otherwise anyone can connect to your database using Adminer.
# 5. If it fails, continue normally.
# So it's clearly expected and documented behaviour that Adminer refuses to log in even
# if the credentials are fine as long as it's also possible to log in without password.
# To combat this, we would remove the empty password check in the minified adminer.php version.
# In the source file, it's these two lines that would be removed
# This is a part of the minified adminer.php file which contains those two lines:
# Min_DB;list($N,$V,$F)=$b->credentials();$yf=array();if($V.$F!=""){$yf["username"]=$V;$yf["password"]=$F;}$m=$b->database();if($m!="")$yf["db"]=$m;try{$h->_link=$h->connect("mongodb://$N",$yf);if($F!=""){$yf["password"]="";try{$h->connect("mongodb://$N",$yf);return
# lang(22);}catch(Exception$Ac){}}return$h;}catch(Exception$Ac){return$Ac->getMessage();}}function
# and by the sed below, we remove the contents of the try catch block:
# Min_DB;list($N,$V,$F)=$b->credentials();$yf=array();if($V.$F!=""){$yf["username"]=$V;$yf["password"]=$F;}$m=$b->database();if($m!="")$yf["db"]=$m;try{$h->_link=$h->connect("mongodb://$N",$yf);if($F!=""){$yf["password"]="";try{
# }catch(Exception$Ac){}}return$h;}catch(Exception$Ac){return$Ac->getMessage();}}function
RUN sed -i "s|{\$h->connect(\"mongodb://\$N\",\$yf);return|{|" adminer.php
RUN sed -i "s|lang(22);}|}|" adminer.php
USER adminer
Copy link

ahmetilhann commented Apr 22, 2022

Thank youuuuuuuuuuu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment