#! /usr/bin/env sh ####################################################### # GeoScaling DNS2 hook script for acme.sh # # Environment variables: # # - $GEOS_Username (your geoscaling.com username) # - $GEOS_Password (your geoscaling.com password) # # Author: Jinhill # GEOS DNS: https://www.geoscaling.com # Git repo: https://github.com/jinhill/acme.sh ####################################################### COOKIE_FILE="/tmp/.geos.cookie" _CURL="curl -c ${COOKIE_FILE} -b ${COOKIE_FILE} -A 'Mozilla/5.0;Chrome/92.0.4515.107;Safari/537.36'" SESSION_TIMEOUT=300 log(){ echo "$@" 1>&2 } #$1:url url_encode() { echo "$1" | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | while read -r l; do case "$l" in [-_.~a-zA-Z0-9] ) printf '%s' "$l" ;; "" ) printf '%%20' ;; * ) printf '%%%02X' "'$l" esac done } #$1:string,$2:char, if $2 not set return array len,$ret:count count() { if [ -n "$2" ];then echo "$1" | awk -F"$2" '{print NF-1}' else echo "$1" | wc -w fi } contains() { echo "$1" | grep -- "$2" >/dev/null 2>&1 } #$1:seesion mode,$2:username,$3:password login() { if [ -n "$1" ] && [ "$1" = "1" ] && [ -f "${COOKIE_FILE}" ];then c_t=$(date -r "${COOKIE_FILE}" "+%s") now=$(date "+%s") s_t=$(( now - c_t )) if [ ${s_t} -lt ${SESSION_TIMEOUT} ];then return 0 fi fi GEOS_Username="${GEOS_Username:-$(_readaccountconf_mutable GEOS_Username)}" GEOS_Password="${GEOS_Password:-$(_readaccountconf_mutable GEOS_Password)}" if [ -z "${GEOS_Username}" ] || [ -z "${GEOS_Password}" ]; then GEOS_Username= GEOS_Password= _err "No auth details provided. Please set user credentials using the \$GEOS_Username and \$GEOS_Password environment variables." return 1 fi enc_username=$(url_encode "${GEOS_Username}") enc_password=$(url_encode "${GEOS_Password}") body="username=${enc_username}&password=${enc_password}" http_code=$($_CURL -X POST -d "$body" -o /dev/null -w "%{http_code}" "https://www.geoscaling.com/dns2/index.php?module=auth") log "$body,$http_code" if [ "${http_code}" = "302" ]; then return 0 fi _err "geoscaling login failed for user ${GEOS_Username} bad RC from post" return 1 } #$1:full domain name,_acme-challenge.www.domain.com #ret: # sub_domain=_acme-challenge.www # zone_id=xxxxxx get_zone() { resp=$($_CURL "https://www.geoscaling.com/dns2/index.php?module=domains") table=$(echo "${resp}" | grep -oE "