reset_admin_password.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. #move to script directory so all relative paths work
  3. cd "$(dirname "$0")"
  4. #includes
  5. . ./config.sh
  6. . ./colors.sh
  7. . ./environment.sh
  8. #count the users
  9. admin_users=$(sudo -u postgres psql fusionpbx -Atc "select count(*) from v_users JOIN v_user_groups USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'")
  10. if [ .$admin_users = .'0' ]; then
  11. error "i could not find the user '$system_username' in the database, check your resources/config.sh is correct"
  12. elif [ .$admin_users = .'' ]; then
  13. error "something went wrong, see errors above";
  14. else
  15. admin_uuids=$(sudo -u postgres psql fusionpbx -Atc "select v_users.user_uuid from v_users JOIN v_user_groups USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'")
  16. for admin_uuid in $admin_uuids; do
  17. user_salt=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php);
  18. if [ .$system_password = .'random' ]; then
  19. user_password=$(dd if=/dev/urandom bs=1 count=12 2>/dev/null | base64 | sed 's/[=\+//]//g')
  20. else
  21. user_password=$system_password
  22. fi
  23. password_hash=$(php -r "echo md5('$user_salt$user_password');");
  24. sudo -u postgres psql fusionpbx -c "update v_users SET password='$password_hash', salt='$user_salt' where user_uuid='$admin_uuid'"
  25. admin_domain=$(sudo -u postgres psql fusionpbx -Atc "select domain_name from v_users JOIN v_domains USING (domain_uuid) where username='$system_username'")
  26. verbose " $system_username@$admin_domain has had it's password reset."
  27. verbose " password: $user_password"
  28. done
  29. fi