fix LE - JSON pretty

This commit is contained in:
Serghey Rodin 2016-06-27 01:38:01 +03:00
commit 5edfe8dd32
2 changed files with 40 additions and 37 deletions

View file

@ -29,7 +29,7 @@ encode_base64() {
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN'
validate_format 'user' 'domain'
is_format_valid 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -48,7 +48,7 @@ fi
source $USER_DATA/ssl/le.conf
api='https://acme-v01.api.letsencrypt.org'
r_domain=$(echo "$check_domain" |cut -f 2 -d \'|tail -n1)
r_domain=$(echo "$check_domain" |cut -f 2 -d \')
key="$USER_DATA/ssl/user.key"
exponent="$EXPONENT"
modulus="$MODULUS"
@ -77,7 +77,6 @@ answer=$(curl -s -i -d "$data" "$api/acme/new-authz")
# Checking http answer status
status=$(echo "$answer" |grep HTTP/1.1 |tail -n1 |cut -f2 -d ' ')
if [[ "$status" -ne "201" ]]; then
echo -e "$(date) $domain $status\n$answer\n$(dig @8.8.8.8 $domain +short)" >> /tmp/le-log.txt
check_result $E_CONNECT "LetsEncrypt challenge request $status"
fi
@ -96,7 +95,6 @@ if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
echo ' return 200 "$1.'$thumb'";' >> $conf
echo '}' >> $conf
fi
echo $conf
else
acme="$HOMEDIR/$user/web/$r_domain/public_html/.well-known/acme-challenge"
echo "$token" > $acme/$token.$thumb
@ -112,7 +110,6 @@ else
$BIN/v-restart-web
check_result $? "Web restart failed" >/dev/null
fi
sleep 30
# Defining ACME query (request validation)
@ -145,6 +142,6 @@ fi
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -16,33 +16,36 @@ format=${2-shell}
# Includes
source $VESTA/func/main.sh
# Json function
json_list_conf() {
lines=$(wc -l $USER_DATA/ssl/le.conf | cut -f 1 -d ' ')
i='0'
IFS=$'\n'
echo -e "{\n\t\"LETSENCRYPT\": {"
for str in $(cat $USER_DATA/ssl/le.conf); do
(( ++i))
key=${str%%=*}
value=${str#*=}
if [ "$i" -lt "$lines" ]; then
echo -e "\t\t\"$key\": \"${value//\'/}\","
else
echo -e "\t\t\"$key\": \"${value//\'/}\""
fi
done
echo -e "\t}\n}"
# JSON list function
json_list() {
echo '{'
echo ' "'$user'": {
"EMAIL": "'$EMAIL'",
"EXPONENT": "'$EXPONENT'",
"MODULUS": "'$MODULUS'",
"THUMB: "'$THUMB'"
}'
echo '}'
}
# Shell function
shell_list_conf() {
IFS=$'\n'
for str in $(cat $USER_DATA/ssl/le.conf); do
key=${str%%=*}
value=${str#*=}
echo "$key: ${value//\'/}"
done
# SHELL list function
shell_list() {
echo "USER: $user"
echo "EMAIL: $EMAIL"
echo "THUMB: $THUMB"
echo "EXPONENT: $EXPONENT"
echo "MODULUS: $MODULUS"
}
# PLAIN list function
plain_list() {
echo -e "$user\t$EMAIL\t$EXPONENT\t$MODULUS\t$THUMB"
}
# CSV list function
csv_list() {
echo "USER,EMAIL,EXPONENT,MODULUS,THUMB"
echo "$user,$EMAIL,$EXPONENT,$MODULUS,$THUMB"
}
@ -61,11 +64,14 @@ fi
# Action #
#----------------------------------------------------------#
# Listing system config
source $USER_DATA/ssl/le.conf
# Listing data
case $format in
json) json_list_conf ;;
plain) shell_list_conf ;;
shell) shell_list_conf | column -t ;;
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list ;;
esac