2022-02-13 17:58:25 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# file: gsl__auth_manager
|
|
|
|
# Folder: /var/lib/gsl/scripts
|
|
|
|
# By echolib
|
|
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Manage Authors from DOMAIN
|
|
|
|
#=======================================================================
|
|
|
|
gsl__authors_check() {
|
|
|
|
gsl_save_dir_ndd=`grep "$gsl_find_domain" "$gsl_file_db_domains"`
|
|
|
|
gsl_file_auth_ndd="$gsl_save_dir_ndd/$gsl_filename_auth"
|
|
|
|
|
2022-02-16 14:11:41 +01:00
|
|
|
if [[ -f "$gsl_file_auth_ndd" ]];then
|
|
|
|
[[ -z `grep '[^[:space:]]' "$gsl_file_auth_ndd"` ]] \
|
|
|
|
&& echo "# Domain: $gsl_find_domain" \
|
|
|
|
&& echo "! No Registred authors yet..." \
|
|
|
|
&& return 1
|
|
|
|
fi
|
2022-02-15 17:56:45 +01:00
|
|
|
|
|
|
|
touch "$gsl_file_auth_ndd"
|
2022-02-13 17:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# List Authors from DOMAIN
|
|
|
|
#=======================================================================
|
|
|
|
gsl__authors_list() {
|
2022-02-15 17:56:45 +01:00
|
|
|
|
2022-02-13 17:58:25 +01:00
|
|
|
case "$1" in
|
2022-02-15 17:56:45 +01:00
|
|
|
check)
|
2022-02-16 14:11:41 +01:00
|
|
|
gsl__authors_check || return
|
2022-02-15 17:56:45 +01:00
|
|
|
return
|
|
|
|
;;
|
2022-02-16 14:11:41 +01:00
|
|
|
add)
|
|
|
|
gsl__authors_check || return
|
|
|
|
;;
|
|
|
|
remove)
|
|
|
|
gsl__authors_check || return
|
|
|
|
;;
|
2022-02-13 17:58:25 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
echo -e "\n# Authors Registred:"
|
|
|
|
while read -r "line_nbr" "author"
|
|
|
|
do
|
2022-02-15 17:56:45 +01:00
|
|
|
echo " $line_nbr: $author"
|
2022-02-13 17:58:25 +01:00
|
|
|
done < <(cat -n "$gsl_file_auth_ndd")
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Add Author(s) for DOMAIN to authors.db in Profile User
|
|
|
|
#=======================================================================
|
|
|
|
gsl__authors_add() {
|
2022-02-16 14:11:41 +01:00
|
|
|
gsl__authors_list add
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
printf '\n%s\n%s\n%s\n \n' \
|
|
|
|
"# You can add one or more Authors" \
|
|
|
|
" Use comma (,) delimiter (i.e. Joe Foo,Jane)" \
|
|
|
|
" || empty field to cancel"
|
|
|
|
|
|
|
|
echo -ne "# Add author(s) name : " && IFS="," read -a gsl_new_authors
|
|
|
|
[[ "$gsl_new_authors" ]] || return
|
|
|
|
|
|
|
|
gsl_nbr_authors=${#gsl_new_authors[@]}
|
|
|
|
for i in `seq 0 $(( gsl_nbr_authors - 1 ))`
|
|
|
|
do
|
2022-02-15 17:56:45 +01:00
|
|
|
echo "${gsl_new_authors[i]}" >> "$gsl_file_auth_ndd" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"Author" \
|
|
|
|
"Added" \
|
|
|
|
"${gsl_new_authors[i]} for domain $gsl_find_domain" \
|
|
|
|
"$gsl_file_auth_ndd"
|
2022-02-13 17:58:25 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
gsl__authors_list
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Remove Author(s) for DOMAIN from authors.db in Profile User
|
|
|
|
#=======================================================================
|
|
|
|
gsl__authors_remove() {
|
2022-02-16 14:11:41 +01:00
|
|
|
gsl__authors_list remove || exit 1
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
printf '\n%s\n%s\n%s\n \n' \
|
|
|
|
"# You can REMOVE one or more Authors" \
|
|
|
|
" Enter numbers (space delimiter)" \
|
|
|
|
" || empty field to cancel"
|
|
|
|
|
|
|
|
read -rp "! Which numbers author to REMOVE ? " gsl_rm_authors
|
|
|
|
gsl_rm_authors=($gsl_rm_authors)
|
|
|
|
|
|
|
|
gsl_nbr_authors=`cat $gsl_file_auth_ndd | wc -l`
|
|
|
|
for line in ${gsl_rm_authors[@]}
|
|
|
|
do
|
2022-02-15 17:56:45 +01:00
|
|
|
[[ $line =~ ^[0-9]+$ ]] || continue
|
|
|
|
(( $line < 1 )) && continue
|
|
|
|
(( $line > $gsl_nbr_authors )) && continue
|
|
|
|
|
|
|
|
if [[ $rm_line ]];then
|
|
|
|
! (( $line == 1 )) && line=$(( line - 1 ))
|
|
|
|
fi
|
|
|
|
gsl_rm_author=`awk -v n="$line" 'NR == n' "$gsl_file_auth_ndd"`
|
|
|
|
sed -i "${line}d" "$gsl_file_auth_ndd" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"Author" \
|
|
|
|
"Removed" \
|
|
|
|
"$gsl_rm_author for domain $gsl_find_domain" \
|
|
|
|
"$gsl_file_auth_ndd"
|
|
|
|
echo " - Removed > $gsl_rm_author <"
|
|
|
|
rm_line=true
|
2022-02-13 17:58:25 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
gsl__authors_list
|
|
|
|
}
|