Improvements to passwd.sh script

- Use the configured administrator user name instead of always
defaulting to "admin"
 - Do not echo the password in clear text
 - Check the password minimum size as will be applied in
ConfigAccounts_p
 - Let user type a password when not provided as a parameter
pull/258/head
luccioman 6 years ago
parent 106bfd0e5f
commit ede5cc0a2b

@ -1,12 +1,34 @@
#!/usr/bin/env sh
cd "`dirname $0`"
. ./checkDataFolder.sh
. ./checkConfFile.sh
echo "Setting new YaCy administrator password..."
# take the administrator user name from the config file
YACY_ADMIN_USER_NAME=$(grep ^adminAccountUserName= "$YACY_DATA_PATH/SETTINGS/yacy.conf" | cut -d= -f2 | tr -d '\r\n')
if [ -z "$YACY_ADMIN_USER_NAME" ]; then
# administrator user name should not be empty : by the way, in that case use the same default value as in YaCy application
YACY_ADMIN_USER_NAME="admin"
fi
if [ -z "$1" ]; then
echo "Usage : ./passwd.sh NEW_PASSWORD"
exit 2
printf "Please enter the new password for user '$YACY_ADMIN_USER_NAME' :"
stty -echo # Do not echo typed characters when typing password
read YACY_ADMIN_PASSWORD
stty echo # Restore echo
printf "\n"
else
YACY_ADMIN_PASSWORD="$1"
fi
if [ ${#YACY_ADMIN_PASSWORD} -le 2 ]; then
echo "Please enter a password with more than 2 characters."
exit 1
fi
(./protectedPostApiCall.sh "ConfigAccounts_p.html" "setAdmin=&adminuser=admin&adminpw1=$1&adminpw2=$1&access=" && \
echo "Password for User Name 'admin' set to '$1'") || \
(echo "Password setting failed" && \
(./protectedPostApiCall.sh "ConfigAccounts_p.html" "setAdmin=&adminuser=$YACY_ADMIN_USER_NAME&adminpw1=$YACY_ADMIN_PASSWORD&adminpw2=$YACY_ADMIN_PASSWORD&access=" && \
echo "Password successfully changed for User Name '$YACY_ADMIN_USER_NAME'.") || \
(echo "Password setting failed." && \
exit 1)
Loading…
Cancel
Save