summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-10-13 14:54:18 -0400
committerAndrew Cady <d@jerkface.net>2020-10-13 14:54:18 -0400
commit6a02ec3617ec30c7b9e60f073df7af9432e38a0b (patch)
treebd29e90559e3aa0bbd19b08432cddf9fb242b60a
parent88efbeb87758a514f7b31bacbc6c2d1dd26bb50f (diff)
fix the subdomains
-rwxr-xr-xbin/cryptonomic-dyndns-command73
1 files changed, 51 insertions, 22 deletions
diff --git a/bin/cryptonomic-dyndns-command b/bin/cryptonomic-dyndns-command
index 8e97de7..348ed74 100755
--- a/bin/cryptonomic-dyndns-command
+++ b/bin/cryptonomic-dyndns-command
@@ -1,6 +1,8 @@
1#!/bin/bash 1#!/bin/bash
2 2
3die() { printf '%s\n' "$*" >&2; exit 1; } 3die() { printf 'Error: %s\n' "$*" >&2; exit 1; }
4
5warn() { printf 'Warning: %s\n' "$*" >&2; }
4 6
5sql_string() 7sql_string()
6{ 8{
@@ -9,13 +11,21 @@ sql_string()
9 11
10powerdns_sqlite_add_replace_record() 12powerdns_sqlite_add_replace_record()
11{ 13{
12 local fqdn="$1" 14 local sql_record_type="$(sql_string "$2")"
13 local record_type="$(sql_string "$2")"
14 local sql_ip_address="$(sql_string "$3")" 15 local sql_ip_address="$(sql_string "$3")"
15 16
16 fqdn=${fqdn: -64 : 64} 17 zone=${1#*.}
17 local sql_new_domain="$(sql_string "$fqdn")" 18 new_name=${label:+$label.}${1: -64 : 64}
18 local sql_domain="$(sql_string "${fqdn#*.}")" 19
20 local sql_new_name="$(sql_string "$new_name")"
21 local sql_zone="$(sql_string "$zone")"
22
23 if false
24 then
25 pdnsutil create-zone "$zone"
26 pdnsutil add-record "$zone" "$new_name" "$2" "$3"
27 return
28 fi
19 29
20 DBDIR=/etc/powerdns 30 DBDIR=/etc/powerdns
21 DBNAME=powerdns.sqlite3 31 DBNAME=powerdns.sqlite3
@@ -27,7 +37,7 @@ powerdns_sqlite_add_replace_record()
27 sqlite3 $DB <<END 37 sqlite3 $DB <<END
28${SQL_ECHO:+.echo on} 38${SQL_ECHO:+.echo on}
29BEGIN; 39BEGIN;
30 DELETE FROM records WHERE type=$record_type AND name=$sql_new_domain; 40 DELETE FROM records WHERE type=$sql_record_type AND name=$sql_new_name;
31 41
32 INSERT INTO records 42 INSERT INTO records
33 43
@@ -40,23 +50,29 @@ BEGIN;
40 50
41 SELECT 51 SELECT
42 id, 52 id,
43 $sql_new_domain, 53 $sql_new_name,
44 $record_type, 54 $sql_record_type,
45 $sql_ip_address, 55 $sql_ip_address,
46 3600, 56 3600,
47 0 57 0
48 FROM domains 58 FROM domains
49 WHERE name=$sql_domain; 59 WHERE name=$sql_zone;
50COMMIT; 60COMMIT;
51END 61END
52 r=$? 62 r=$?
53 [ $r = 0 ] || return $r 63 [ $r = 0 ] || return $r
54 64
55 printf '%s %s\n' "$fqdn" "$3" 65 printf '%s %s\n' "$new_name" "$3"
56} 66}
57 67
58add() 68add()
59{ 69{
70 local label=
71 if [ $# = 3 ]
72 then
73 label=$1
74 shift
75 fi
60 local record_type ip="$2" 76 local record_type ip="$2"
61 case "$ip" in 77 case "$ip" in
62 *.*.*.*) record_type=A ;; 78 *.*.*.*) record_type=A ;;
@@ -67,20 +83,33 @@ add()
67 powerdns_sqlite_add_replace_record "$domain" "$record_type" "$ip" 83 powerdns_sqlite_add_replace_record "$domain" "$record_type" "$ip"
68} 84}
69 85
86validate_dns_label()
87{
88 if [ $#1 -gt 64 ]
89 then
90 warn "ignored DNS label: too long"
91 return 1
92 fi
93 case "$1" in
94 -*|*--*|*-)
95 warn 'ignored DNS label: invalid use of hyphens'
96 return 2
97 ;;
98 *[^-A-Za-z0-9]*)
99 warn 'ignored DNS label: invalid character'
100 return 3
101 ;;
102 esac
103 true
104}
105
70main() 106main()
71{ 107{
72 add "$domain" "$ip_address" 108 add "$domain" "$ip_address"
73 109 for label in $SSH_ORIGINAL_COMMAND
74 set -- $SSH_ORIGINAL_COMMAND 110 do
75 while [ $# -ge 1 ]; do 111 validate_dns_label "$label" || continue
76 d=$1 112 add "$label" "$domain" "$ip_address"
77 shift
78
79 case "$d" in
80 *.*) continue;;
81 esac
82
83 add "$d.$domain" "$ip_address"
84 done 113 done
85} 114}
86 115