Last active
February 15, 2025 16:15
-
-
Save AreYouLoco/9dc62e7067c60107875903d2bd54e2e0 to your computer and use it in GitHub Desktop.
Posix script to use acme.sh with forpsi.com - DNS API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# FORPSI DNS API for acme.sh | |
# Based on https://gist.githubusercontent.com/patrikbeno/29b5e2746367acf0e1b587e02b8b3a50/raw/1e39790e1bc3e5455eb0e7d08abaa412de07d3b7/dns_forpsi.sh | |
# And modified by (me) Orest Worhacz with the help of ChatGPT | |
# Works! It could be easily adapted to forpsi.sk/.cz/.pl | |
# Usage: ./acme.sh --issue --dns dns_forpsi -d site.example.com | |
username="username" | |
password="password&1" | |
domain_id="12345" | |
domain="yourdomain.tld" | |
url="https://admin.forpsi.com/domain/domains-dns.php?id=${domain_id}" | |
fcookies=".cookies" | |
#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxp...5CPBs" | |
dns_forpsi_add() { | |
echo "dns_forpsi_add $@" | |
dns_forpsi_login | |
curl -sf "$url" \ | |
-XPOST -c "$fcookies" -b "$fcookies" \ | |
-d ak=record_add \ | |
-d type=TXT \ | |
-d ttl="60" \ | |
-d url="%2Fdomain%2Fdomains-dns.php%3Fid%3D${domain_id}" \ | |
-d name="$(echo "$1" | sed "s/.${domain}//")" \ | |
-d rdata="$2" | |
#rm "$fcookies" | |
} | |
#Usage: dns_forpsi_rm fulldomain txtvalue | |
dns_forpsi_rm() { | |
dns_forpsi_login | |
local id="$(curl -sf "$url" -c "$fcookies" -b "$fcookies" | grep "$1.*$2" | sed 's/.*delete_row(//; s/,.*//')" | |
echo "Found id: $id" | |
if [ "$id" != "" ]; then | |
curl -sf "$url" \ | |
-XPOST -c "$fcookies" -b "$fcookies" \ | |
-d ak=record_del -d r_ID="$id" \ | |
>/dev/null | |
fi | |
#rm "$fcookies" | |
} | |
dns_forpsi_login() { | |
encoded_username="$(urlencode "$username")" | |
encoded_password="$(urlencode "$password")" | |
curl -c "$fcookies" -b "$fcookies" 'https://admin.forpsi.com/index.php' -H 'Accept-Language: en' -H 'Referer: https://admin.forpsi.com/index.php' -H 'DNT: 1' > /dev/null | |
curl -c "$fcookies" -b "$fcookies" 'https://admin.forpsi.com/index.php' -X POST -H 'Accept-Language: en' -H 'Origin: https://admin.forpsi.com' -H 'DNT: 1' -H 'Referer: https://admin.forpsi.com/index.php' --data-raw "login_action=client_login&user_name=$encoded_username&password=$encoded_password&remember=1" > /dev/null | |
} | |
#Usage: urlencode "string to encode" | |
#Copyright© ChatGPT 2023 License MIT | |
urlencode() { | |
local string="$1" | |
local length="${#string}" | |
local encoded="" | |
local index=0 | |
while [ "$index" -lt "$length" ]; do | |
local char=$(expr substr "$string" "$((index + 1))" 1) | |
case "$char" in | |
[a-zA-Z0-9.~_-]) | |
encoded="${encoded}${char}" | |
;; | |
*) | |
encoded="${encoded}$(printf '%%%02X' "'$char")" | |
;; | |
esac | |
index=$((index + 1)) | |
done | |
echo "$encoded" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment