diff options
| author | luccioman <luccioman@users.noreply.github.com> | 2018-11-27 11:41:00 +0100 |
|---|---|---|
| committer | luccioman <luccioman@users.noreply.github.com> | 2018-11-27 11:41:00 +0100 |
| commit | ede5cc0a2b076fcfa624fee90d5a6c1b33466f24 (patch) | |
| tree | f9cededbe20dac1eb26e7d58cd370c64b5e57dae | |
| parent | 106bfd0e5f7cc9cabf32a5c2110db44e9200bdd3 (diff) | |
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
| -rwxr-xr-x | bin/passwd.sh | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/bin/passwd.sh b/bin/passwd.sh index 45335853e..39640bc05 100755 --- a/bin/passwd.sh +++ b/bin/passwd.sh @@ -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)
\ No newline at end of file |
