freedombone-utils-passwords 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Password functions
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. # If this file exists it contains a global password used with
  29. # disk image installs. This simplifies password management for
  30. # deployment at scale
  31. IMAGE_PASSWORD_FILE=/root/login.txt
  32. # Minimum number of characters in a password
  33. MINIMUM_PASSWORD_LENGTH=10
  34. # The default password length used in images
  35. DEFAULT_PASSWORD_LENGTH=20
  36. function passwords_select_user {
  37. SELECTED_USERNAME=
  38. # shellcheck disable=SC2207
  39. users_array=($(ls /home))
  40. delete=(git)
  41. # shellcheck disable=SC2068
  42. for del in ${delete[@]}
  43. do
  44. # shellcheck disable=SC2206
  45. users_array=(${users_array[@]/$del})
  46. done
  47. i=0
  48. W=()
  49. name=()
  50. # shellcheck disable=SC2068
  51. for u in ${users_array[@]}
  52. do
  53. if [[ $(is_valid_user "$u") == "1" ]]; then
  54. i=$((i+1))
  55. W+=("$i" "$u")
  56. name+=("$u")
  57. fi
  58. done
  59. if [ $i -eq 1 ]; then
  60. SELECTED_USERNAME="${name[0]}"
  61. else
  62. # shellcheck disable=SC2068
  63. user_index=$(dialog --backtitle $"Freedombone Control Panel" --title $"Select User" --menu $"Select one of the following:" 24 40 17 ${W[@]} 3>&2 2>&1 1>&3)
  64. # shellcheck disable=SC2181
  65. if [ $? -eq 0 ]; then
  66. # shellcheck disable=SC2034
  67. SELECTED_USERNAME="${name[$((user_index-1))]}"
  68. fi
  69. fi
  70. }
  71. function enforce_good_passwords {
  72. # because humans are generally bad at choosing passwords
  73. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  74. return
  75. fi
  76. apt-get -yq install libpam-cracklib
  77. sed -i 's/password.*requisite.*pam_cracklib.so.*/password required pam_cracklib.so retry=2 dcredit=-1 ucredit=-1 ocredit=0 lcredit=0 minlen=10 reject_username/g' /etc/pam.d/common-password
  78. mark_completed "${FUNCNAME[0]}"
  79. }
  80. function create_password {
  81. openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c "${1}" ; echo -n ''
  82. }
  83. # NOTE: deliberately no exit 0