summaryrefslogtreecommitdiff
path: root/src/dyndns-command.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/dyndns-command.sh')
-rwxr-xr-xsrc/dyndns-command.sh92
1 files changed, 0 insertions, 92 deletions
diff --git a/src/dyndns-command.sh b/src/dyndns-command.sh
deleted file mode 100755
index 375d50b..0000000
--- a/src/dyndns-command.sh
+++ /dev/null
@@ -1,92 +0,0 @@
1#!/bin/bash
2
3die() { printf '%s\n' "$*" >&2; exit 1; }
4
5sql_string()
6{
7 printf '%s' "'${1//\'/\'\'}'"
8}
9
10powerdns_sqlite_add_replace_record()
11{
12 local sql_new_domain="$(sql_string "$1.$3")"
13 local sql_ip_address="$(sql_string "$2")"
14 local sql_domain="$(sql_string "$3")"
15 local record_type="$(sql_string "$4")"
16
17 DBDIR=/etc/powerdns
18 DBNAME=powerdns.sqlite3
19 DB=$DBDIR/$DBNAME
20
21 test -r $DB && test -w $DB || die "Wrong permissions on $DB"
22 test -r $DBDIR && test -w $DBDIR || die "Wrong permissions on $DBDIR"
23
24 sqlite3 $DB <<END
25${SQL_ECHO:+.echo on}
26BEGIN;
27 DELETE FROM records WHERE type=$record_type AND name=$sql_new_domain;
28
29 INSERT INTO records
30
31 (domain_id,
32 name,
33 type,
34 content,
35 ttl,
36 prio)
37
38 SELECT
39 id,
40 $sql_new_domain,
41 $record_type,
42 $sql_ip_address,
43 3600,
44 0
45 FROM domains
46 WHERE name=$sql_domain;
47COMMIT;
48END
49}
50
51add()
52{
53 local record_type
54 case "$2" in
55 *.*.*.*) record_type=A ;;
56 *:*) record_type=AAAA ;;
57 *) exit 1 ;;
58 esac
59
60 powerdns_sqlite_add_replace_record "$1" "$2" "$domain" "$record_type" \
61 && printf '%s %s\n' "$1.$domain $2"
62}
63
64main()
65{
66 add "$subdomain" "$ip_address"
67
68 set -- $SSH_ORIGINAL_COMMAND
69 while [ $# -ge 2 ]; do
70 d=$1
71 ip=$2
72 shift 2
73
74 case "$d" in
75 *.*) continue;;
76 esac
77
78 add "$d.$subdomain" "$ip"
79 done
80}
81
82PEM_DEST=$HOME/public_rsync
83
84PATH=$HOME/bin:$PATH
85
86eval "$(samizdat-ssh-uid --copy-pem "$PEM_DEST")"
87
88domain=${SSH_CLIENT_DOMAIN}
89subdomain=${SSH_CLIENT_FINGERPRINT}
90ip_address=${SSH_CLIENT%% *}
91
92main "$@"