Commit 3def69d9057f4051b32bd1578422719771fdf377

Authored by root
1 parent 368f4fc6

working test run - it worked

.gitignore
1 1 *~
2 2 config.cfg
3 3 src/
4   -certbot.log
5 4 \ No newline at end of file
  5 +certbot.log
  6 +auth.log
... ...
README.md
1 1 # certbot-hook
2 2 certbot validation bash script hooks for updating a DNS server via http://docs.routing.net/api
3 3  
4   -##Stage
5   - testing
  4 +## usage:
  5 + 1. install certbot like apt-gt install certbot
  6 + 2. rename default-config.cfg to config.cfg
  7 + 3. set your API Key into config.cfg
  8 + 4. run ./certbot.sh foo.bar.com
  9 +
  10 +
6 11  
... ...
1 1 #!/bin/bash
2   -source config.cfg
3   -
  2 +dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3 +echo "start" > auth.log
  4 +source "${dir}/config.cfg"
  5 +domain="${CERTBOT_DOMAIN}"
  6 +val="${CERTBOT_VALIDATION}"
  7 +acme="_acme-challenge.${CERTBOT_DOMAIN}"
  8 +zone=$(expr match "${CERTBOT_DOMAIN}" '.*\.\(.*\..*\)')
  9 +echo "token: $token" >> auth.log
  10 +echo "domain: $domain" >> auth.log
  11 +echo "val: $val" >> auth.log
  12 +echo "acme: $acme" >> auth.log
  13 +echo "DIR: $dir" >> auth.log
4 14  
5 15 GET=$(cat <<EOF
6 16 {
... ... @@ -22,10 +32,34 @@ GET=$(cat &lt;&lt;EOF
22 32 EOF
23 33 )
24 34  
25   -OLD=$(curl -d "$GET" -s 'https://partner.routing.net/api/dns/v1/json/zonesFind' | tac | sed -nE '/"'$acme'"/, /addDate/p ' | sed -n -e 's/"content":\(.*\),/\1/p')
26   -
27   -#echo $OLD
  35 +echo "GET: $GET" >> auth.log
  36 +OLD=$(curl -d "$GET" -s 'https://partner.routing.net/api/dns/v1/json/zonesFind' | tac | sed -nE '/"'$acme'"/, /addDate/p ' | sed -n -e 's/"content":\(.*\),/\1/p' )
  37 +#OLD=${OLD//\"}
  38 +OLD=${OLD// }
  39 +#OLD=${OLD//\\}
  40 +echo "OLD: $OLD" >> auth.log
28 41  
  42 +if [ -z "$OLD" ]
  43 +then
  44 +DATA=$(cat <<EOF
  45 +{
  46 + "authToken": "$token",
  47 + "zoneConfig": {
  48 + "name": "$zone"
  49 + },
  50 + "recordsToAdd": [
  51 + {
  52 + "name": "$acme",
  53 + "type": "TXT",
  54 + "content": "$val",
  55 + "ttl": 86000
  56 + }
  57 + ]
  58 +}
  59 +EOF
  60 +)
  61 +
  62 +else
29 63 DATA=$(cat <<EOF
30 64 {
31 65 "authToken": "$token",
... ... @@ -36,7 +70,7 @@ DATA=$(cat &lt;&lt;EOF
36 70 {
37 71 "name": "$acme",
38 72 "type": "TXT",
39   - "content": "\"hello22\"",
  73 + "content": "$val",
40 74 "ttl": 86000
41 75 }
42 76 ],
... ... @@ -50,8 +84,13 @@ DATA=$(cat &lt;&lt;EOF
50 84 }
51 85 EOF
52 86 )
  87 +fi
53 88  
  89 +echo "DATA: $DATA" >> auth.log
54 90  
55   -#curl -X POST https://partner.routing.net/api/dns/v1/json/zoneUpdate -d "$DATA"
  91 +UPDATE=$(curl -d "$DATA" -s 'https://partner.routing.net/api/dns/v1/json/zoneUpdate')
56 92  
  93 +echo "Update: $UPDATE" >> auth.log
57 94  
  95 +echo "end" >> auth.log
  96 +sleep 30
... ...
certbot.sh 0 → 100755
  1 +#!/bin/bash
  2 +if [ $# -eq 0 ]
  3 +then
  4 + echo "missing domain parameter!"
  5 + echo " example: "
  6 + echo " ./certbot.sh foo.bar.com"
  7 +
  8 + echo $DOMAIN
  9 +else
  10 +certbot certonly \
  11 + --manual \
  12 + --manual-auth-hook ./auth.sh \
  13 + --preferred-challenges=dns \
  14 + --register-unsafely-without-email \
  15 + --agree-tos --manual-public-ip-logging-ok \
  16 + -d $1
  17 +fi
... ...
renew.sh deleted
1   -#!/bin/bash
2   -certbot certonly --manual --manual-auth-hook ./auth.sh --preferred-challenges=dns --register-unsafely-without-email --agree-tos --manual-public-ip-logging-ok -d api.salamander-jewelry.net
3   -