mirror of
https://github.com/hoellen/dockerfiles.git
synced 2025-04-20 04:19:18 +00:00
update ngxpasswd
This commit is contained in:
parent
ef3c04060d
commit
0bc0bd5839
@ -1,29 +1,32 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
NAME="$1"
|
|
||||||
USER="$2"
|
echo ""
|
||||||
PASSWORD="$3"
|
echo "Welcome to ngxpasswd utility."
|
||||||
|
echo "We're about to create a password file."
|
||||||
|
echo ""
|
||||||
|
|
||||||
cd /passwds || exit 1
|
cd /passwds || exit 1
|
||||||
|
|
||||||
if [ -z "$NAME" ]; then
|
while [ "$NAME" == "" ]; do
|
||||||
echo "Service name must be defined" 1>&2
|
read -p "Name: " NAME
|
||||||
exit 1
|
if [ -f "/passwds/$NAME.htpasswd" ]; then
|
||||||
elif [ -f $NAME.htpasswd ]; then
|
echo "ERROR: /passwds/$NAME.htpasswd already exists."
|
||||||
echo "$NAME.htpasswd exists, aborting" 1>&2
|
exit 1
|
||||||
exit 1
|
fi
|
||||||
fi
|
done
|
||||||
|
|
||||||
if [ -z "$USER" ]; then
|
while [ "$USER" == "" ]; do
|
||||||
echo "User must be defined" 1>&2
|
read -p "User: " USER
|
||||||
exit 1
|
done
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$PASSWORD" ]; then
|
read -p "Password (leave blank to generate one): " PASSWORD
|
||||||
PASSWORD=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1`
|
|
||||||
|
if [ "$PASSWORD" == "" ]; then
|
||||||
echo "Password was not defined, generating a random one..."
|
echo "Password was not defined, generating a random one..."
|
||||||
|
PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n $USER:`openssl passwd -apr1 $PASSWORD` >> $NAME.htpasswd
|
echo -n $USER:$(openssl passwd -apr1 $PASSWORD) >> $NAME.htpasswd
|
||||||
chown $UID:$GID $NAME.htpasswd
|
chown $UID:$GID $NAME.htpasswd
|
||||||
chmod 640 $NAME.htpasswd
|
chmod 640 $NAME.htpasswd
|
||||||
|
|
||||||
@ -33,6 +36,23 @@ echo "- Service : $NAME"
|
|||||||
echo "- User : $USER"
|
echo "- User : $USER"
|
||||||
echo "- Password : $PASSWORD"
|
echo "- Password : $PASSWORD"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
if [ -f "/sites-enabled/$NAME.conf" ]; then
|
||||||
|
echo "vhost at /sites-enabled/$NAME.conf detected."
|
||||||
|
|
||||||
|
while [[ "$ADD" != "y" && "$ADD" != "n" ]]; do
|
||||||
|
read -p "Add authentication to $NAME.conf? [y/n]: " ADD
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$ADD" == "y" ]; then
|
||||||
|
cd /etc/nginx/conf
|
||||||
|
sed -i "/location/r vhost_passwd.conf" /sites-enabled/$NAME.conf
|
||||||
|
sed -i "s/<NAME>/$NAME/g" /sites-enabled/$NAME.conf
|
||||||
|
echo "Automatically added, please verify. Otherwise follow these instructions."
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Paste this to your vhost in order to enable auth :"
|
echo "Paste this to your vhost in order to enable auth :"
|
||||||
echo " auth_basic \"Who's this?\";"
|
echo " auth_basic \"Who's this?\";"
|
||||||
echo " auth_basic_user_file /passwds/$NAME.htpasswd;"
|
echo " auth_basic_user_file /passwds/$NAME.htpasswd;"
|
||||||
|
2
boring-nginx/vhost_passwd.conf
Normal file
2
boring-nginx/vhost_passwd.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
auth_basic "Who's this?";
|
||||||
|
auth_basic_user_file /passwds/<NAME>.htpasswd;
|
Loading…
x
Reference in New Issue
Block a user