| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #!/bin/bash
- # info: listing ssl certificates
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument defenition
- user=$1
- format=${2-shell}
- # Importing variables
- source $VESTA/conf/vars.conf
- source $V_FUNC/shared.func
- # Json function
- json_list_cert() {
- # Print top bracket
- echo '['
- # Checking certificates number
- certificates=$(ls $V_USERS/$user/ssl/ |grep '.crt' )
- certificates_count=$(echo "$certificates" | wc -l)
- i=1
- # Listing files by mask
- for cert in $certificates; do
- if [ $i -eq $certificates_count ]; then
- echo -e "\t\"${cert//.crt/}\""
- else
- echo -e "\t\"${cert//.crt/}\","
- fi
- (( ++i))
- done
- # Printing bottom bracket
- echo -e "]"
- }
- # Shell function
- shell_list_cert() {
- if [ -z "$nohead" ] ; then
- # Print brief info
- echo "Certificate"
- echo "----------"
- fi
- # Listing files by mask
- for cert in $(ls $V_USERS/$user/ssl/ | grep '.crt'); do
- # Print result
- echo "${cert//.crt/}"
- done
- }
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- # Checking args
- check_args '1' "$#" 'user [format] [limit] [offset]'
- # Checking argument format
- format_validation 'user'
- # Checking user
- is_user_valid
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Listing domains
- case $format in
- json) json_list_cert ;;
- plain) nohead=1; shell_list_cert ;;
- shell) shell_list_cert | column -t ;;
- *) check_args '1' '0' 'user [format]' ;;
- esac
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- exit
|