Change passwords from control panel

This commit is contained in:
Bob Mottram 2016-11-19 15:45:15 +00:00
parent d128a5f762
commit ebf91c686d
2 changed files with 157 additions and 37 deletions

View File

@ -108,6 +108,95 @@ function any_key {
read -n1 -r -p $"Press any key to continue..." key
}
function passwords_select_user {
SELECTED_USERNAME=
users_array=($(ls /home))
delete=(mirrors git)
for del in ${delete[@]}
do
users_array=(${users_array[@]/$del})
done
i=0
W=()
name=()
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
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)
if [ $? -eq 0 ]; then
SELECTED_USERNAME="${name[$((user_index-1))]}"
fi
fi
}
function passwords_show_apps {
SELECTED_APP=
select_all_apps=$1
applist=""
n=1
app_index=0
for a in "${APPS_AVAILABLE[@]}"
do
applist="$applist $n $a off"
n=$[n+1]
app_index=$[app_index+1]
done
selected_app_index=$(dialog --backtitle $"Freedombone Control Panel" --title $"Select App" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3)
if [ $? -eq 0 ]; then
SELECTED_APP="${name[$((selected_app_index-1))]}"
fi
}
function view_or_change_passwords {
passwords_select_user
if [ ! $SELECTED_USER ]; then
return
fi
detect_installed_apps
passwords_show_apps
if [ ! $SELECTED_APP ]; then
return
fi
CURR_PASSWORD=$(${PROJECT_NAME}-pass -u ${SELECTED_USER} -a ${SELECTED_APP})
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"View or Change Password" \
--backtitle $"Freedombone Control Panel" \
--inputbox $"${SELECTED_APP} password for ${SELECTED_USER}. Copy or change it if you wish." 8 60 "$CURR_PASSWORD" 2>$data
sel=$?
case $sel in
0)
CURR_PASSWORD=$(<$data)
if [ ${#CURR_PASSWORD} -gt 8 ]; then
if [[ $(function_exists change_password_${SELECTED_APP}) == "1" ]]; then
${PROJECT_NAME}-pass -u ${SELECTED_USER} -a ${SELECTED_APP} -p ${CURR_PASSWORD}
change_password_${SELECTED_APP} ${SELECTED_USER} "${CURR_PASSWORD}"
dialog --title $"Change password" \
--msgbox $"The password was changed" 6 40
fi
fi
;;
esac
}
function check_for_updates {
if [ ! -f /etc/cron.weekly/$UPGRADE_SCRIPT_NAME ]; then
dialog --title $"Check for updates" \
@ -1809,26 +1898,27 @@ function menu_top_level {
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Control Panel" \
--radiolist $"Choose an operation:" 27 70 20 \
--radiolist $"Choose an operation:" 28 70 21 \
1 $"About this system" off \
2 $"Backup and Restore" off \
3 $"Show Firewall" off \
4 $"Reset Tripwire" off \
5 $"App Settings" off \
6 $"Add/Remove Apps" off \
7 $"Logging on/off" off \
8 $"Ping enable/disable" off \
9 $"Manage Users" off \
10 $"Email Menu" off \
11 $"Security Settings" off \
12 $"Set the main repository (repo mirrors)" off \
13 $"Change the name of this system" off \
14 $"Set a static local IP address" off \
15 $"Wifi menu" off \
16 $"Check for updates" off \
17 $"Power off the system" off \
18 $"Restart the system" off \
19 $"Exit" on 2> $data
2 $"Passwords" off \
3 $"Backup and Restore" off \
4 $"Show Firewall" off \
5 $"Reset Tripwire" off \
6 $"App Settings" off \
7 $"Add/Remove Apps" off \
8 $"Logging on/off" off \
9 $"Ping enable/disable" off \
10 $"Manage Users" off \
11 $"Email Menu" off \
12 $"Security Settings" off \
13 $"Set the main repository (repo mirrors)" off \
14 $"Change the name of this system" off \
15 $"Set a static local IP address" off \
16 $"Wifi menu" off \
17 $"Check for updates" off \
18 $"Power off the system" off \
19 $"Restart the system" off \
20 $"Exit" on 2> $data
sel=$?
case $sel in
1) exit 1;;
@ -1836,24 +1926,25 @@ function menu_top_level {
esac
case $(cat $data) in
1) show_about;;
2) menu_backup_restore;;
3) show_firewall;;
4) reset_tripwire;;
5) menu_app_settings;;
6) ${PROJECT_NAME}-addremove;;
7) logging_on_off;;
8) ping_enable_disable;;
9) menu_users;;
10) menu_email;;
11) security_settings;;
12) set_main_repo;;
13) change_system_name;;
14) set_static_IP;;
15) menu_wifi;;
16) check_for_updates;;
17) shut_down_system;;
18) restart_system;;
19) break;;
2) view_or_change_passwords;;
3) menu_backup_restore;;
4) show_firewall;;
5) reset_tripwire;;
6) menu_app_settings;;
7) ${PROJECT_NAME}-addremove;;
8) logging_on_off;;
9) ping_enable_disable;;
10) menu_users;;
11) menu_email;;
12) security_settings;;
13) set_main_repo;;
14) change_system_name;;
15) set_static_IP;;
16) menu_wifi;;
17) check_for_updates;;
18) shut_down_system;;
19) restart_system;;
20) break;;
esac
done
}

View File

@ -320,6 +320,35 @@ function detect_installable_apps {
done
}
function detect_installed_apps {
FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
APPS_AVAILABLE=()
APPS_INSTALLED=()
APPS_INSTALLED_NAMES=()
function_check app_variants
function_check app_is_installed
function_check item_in_array
# for all the app scripts
for filename in $FILES
do
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
if [[ $(app_is_installed $app_name) ]]; then
item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"
if [[ $? != 0 ]]; then
variants_list=$(app_variants $filename)
if [ ${#variants_list} -gt 0 ]; then
APPS_AVAILABLE+=("${app_name}")
APPS_INSTALLED_NAMES+=("$app_name")
fi
fi
fi
done
}
# creates the APPS_AVAILABLE and APPS_CHOSEN arrays based on
# the given variant name
function choose_apps_for_variant {