123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #!/bin/bash
- # _____ _ _
- # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
- # | __| _| -_| -_| . | . | | . | . | | -_|
- # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
- #
- # Freedom in the Cloud
- #
- # Password functions
- #
- # License
- # =======
- #
- # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- # If this file exists it contains a global password used with
- # disk image installs. This simplifies password management for
- # deployment at scale
- IMAGE_PASSWORD_FILE=/root/login.txt
-
- # Minimum number of characters in a password
- MINIMUM_PASSWORD_LENGTH=10
-
- # The default password length used in images
- DEFAULT_PASSWORD_LENGTH=20
-
- function passwords_select_user {
- SELECTED_USERNAME=
-
- # shellcheck disable=SC2207
- users_array=($(ls /home))
-
- delete=(git)
- # shellcheck disable=SC2068
- for del in ${delete[@]}
- do
- # shellcheck disable=SC2206
- users_array=(${users_array[@]/$del})
- done
-
- i=0
- W=()
- name=()
- # shellcheck disable=SC2068
- for u in ${users_array[@]}
- do
- if [[ $(is_valid_user "$u") == "1" ]]; then
- i=$((i+1))
- W+=("$i" "$u")
- name+=("$u")
- fi
- done
-
- if [ $i -eq 1 ]; then
- SELECTED_USERNAME="${name[0]}"
- else
- # shellcheck disable=SC2068
- 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)
-
- # shellcheck disable=SC2181
- if [ $? -eq 0 ]; then
- # shellcheck disable=SC2034
- SELECTED_USERNAME="${name[$((user_index-1))]}"
- fi
- fi
- }
-
- function enforce_good_passwords {
- # because humans are generally bad at choosing passwords
- if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
- return
- fi
- apt-get -yq install libpam-cracklib
-
- 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
- mark_completed "${FUNCNAME[0]}"
- }
-
- function create_password {
- openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c "${1}" ; echo -n ''
- }
-
- # NOTE: deliberately no exit 0
|