Browse Source

shfmt again

pull/4773/head
Travis Neely 1 year ago
parent
commit
da8082c2bd
  1. 96
      dnsapi/dns_nfs.sh

96
dnsapi/dns_nfs.sh

@ -12,28 +12,28 @@
# Usage: dns_nfs_add _acme-challenge.domain.com "KjiayTfXPHmnHmOdevsOtJyzsU9AHw2T6R0lNVCl_oi"
dns_nfs_add() {
FULLDOMAIN=$1
ROOTDOMAIN=$(echo "$FULLDOMAIN" | awk -F '.' '{print $(NF-1)"."$NF}')
SUBDOMAIN=$(echo "$FULLDOMAIN" | sed 's/.'"$ROOTDOMAIN"'//g')
FULLDOMAIN=$1
ROOTDOMAIN=$(echo "$FULLDOMAIN" | awk -F '.' '{print $(NF-1)"."$NF}')
SUBDOMAIN=$(echo "$FULLDOMAIN" | sed 's/.'"$ROOTDOMAIN"'//g')
if [ "$SUBDOMAIN" = "$FULLDOMAIN" ]; then
unset SUBDOMAIN
fi
if [ "$SUBDOMAIN" = "$FULLDOMAIN" ]; then
unset SUBDOMAIN
fi
_nfs_rest "/dns/$ROOTDOMAIN/addRR" "name=$SUBDOMAIN" 'type=TXT' "data=$2"
_nfs_rest "/dns/$ROOTDOMAIN/addRR" "name=$SUBDOMAIN" 'type=TXT' "data=$2"
}
# Usage: dns_nfs_rm domain.com "KjiayTfXPHmnHmOdevsOtJyzsU9AHw2T6R0lNVCl_oi"
dns_nfs_rm() {
FULLDOMAIN=$1
ROOTDOMAIN=$(echo "$FULLDOMAIN" | awk -F '.' '{print $(NF-1)"."$NF}')
SUBDOMAIN=$(echo "$FULLDOMAIN" | sed 's/.'"$ROOTDOMAIN"'//g')
FULLDOMAIN=$1
ROOTDOMAIN=$(echo "$FULLDOMAIN" | awk -F '.' '{print $(NF-1)"."$NF}')
SUBDOMAIN=$(echo "$FULLDOMAIN" | sed 's/.'"$ROOTDOMAIN"'//g')
if [ "$SUBDOMAIN" = "$FULLDOMAIN" ]; then
unset SUBDOMAIN
fi
if [ "$SUBDOMAIN" = "$FULLDOMAIN" ]; then
unset SUBDOMAIN
fi
_nfs_rest "/dns/$ROOTDOMAIN/removeRR" "name=$SUBDOMAIN" 'type=TXT' "data=$2"
_nfs_rest "/dns/$ROOTDOMAIN/removeRR" "name=$SUBDOMAIN" 'type=TXT' "data=$2"
}
#################### Private functions below ##################################
@ -41,38 +41,38 @@ dns_nfs_rm() {
# remove: _nfs_rest "/dns/domain.com/removeRR" "name=www" 'type=TXT' "data=KjiayTfXPHmnHmOdevsOtJyzsU9AHw2T6R0lNVCl_oi"
_nfs_rest() {
# Make sure NFS_ACCOUNT is set else exit
if [ -z "$NFS_ACCOUNT" ]; then
echo "NFS_ACCOUNT is not set, run 'export NFS_ACCOUNT=\"your_nearly_free_speech_account\" and rerun."
exit 1
fi
# Make sure NFS_API_KEY is set else exit
if [ -z "$NFS_API_KEY" ]; then
echo "NFS_API_KEY is not set, run 'export NFS_API_KEY=\"your_nearly_free_speech_api_key\" and rerun."
exit 1
fi
TIMESTAMP=$(date +%s)
SALT=$(tr -dc 'a-zA-Z0-9' </dev/urandom | head -c 16)
REQUEST_URI="$1"
if [ "$#" -gt "1" ]; then
PARAMETERS="$2"
fi
COUNT=3
while test $COUNT -le $#; do
eval "PARAMETER=\$$COUNT"
# shellcheck disable=SC2153
PARAMETERS="$PARAMETERS&$PARAMETER"
COUNT=$((COUNT + 1))
done
BODY=$PARAMETERS
BODY_HASH=$(printf "%s" "$BODY" | sha1sum | awk '{print $1}')
HASH_STRING=$(printf "%s" "$NFS_ACCOUNT;$TIMESTAMP;$SALT;$NFS_API_KEY;$REQUEST_URI;$BODY_HASH")
HASH=$(printf "%s" "$HASH_STRING" | sha1sum | awk '{print $1}')
printf "%s" "$(curl -s -o - -k -X POST -H "X-NFSN-Authentication: $NFS_ACCOUNT;$TIMESTAMP;$SALT;$HASH" -d "$BODY" "https://api.nearlyfreespeech.net$REQUEST_URI")"
# Make sure NFS_ACCOUNT is set else exit
if [ -z "$NFS_ACCOUNT" ]; then
echo "NFS_ACCOUNT is not set, run 'export NFS_ACCOUNT=\"your_nearly_free_speech_account\" and rerun."
exit 1
fi
# Make sure NFS_API_KEY is set else exit
if [ -z "$NFS_API_KEY" ]; then
echo "NFS_API_KEY is not set, run 'export NFS_API_KEY=\"your_nearly_free_speech_api_key\" and rerun."
exit 1
fi
TIMESTAMP=$(date +%s)
SALT=$(tr -dc 'a-zA-Z0-9' </dev/urandom | head -c 16)
REQUEST_URI="$1"
if [ "$#" -gt "1" ]; then
PARAMETERS="$2"
fi
COUNT=3
while test $COUNT -le $#; do
eval "PARAMETER=\$$COUNT"
# shellcheck disable=SC2153
PARAMETERS="$PARAMETERS&$PARAMETER"
COUNT=$((COUNT + 1))
done
BODY=$PARAMETERS
BODY_HASH=$(printf "%s" "$BODY" | sha1sum | awk '{print $1}')
HASH_STRING=$(printf "%s" "$NFS_ACCOUNT;$TIMESTAMP;$SALT;$NFS_API_KEY;$REQUEST_URI;$BODY_HASH")
HASH=$(printf "%s" "$HASH_STRING" | sha1sum | awk '{print $1}')
printf "%s" "$(curl -s -o - -k -X POST -H "X-NFSN-Authentication: $NFS_ACCOUNT;$TIMESTAMP;$SALT;$HASH" -d "$BODY" "https://api.nearlyfreespeech.net$REQUEST_URI")"
}
Loading…
Cancel
Save