reset_admin_password.sh 1.5 KB

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