summaryrefslogtreecommitdiff
path: root/src/dyndns-command.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/dyndns-command.sh')
-rwxr-xr-xsrc/dyndns-command.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/dyndns-command.sh b/src/dyndns-command.sh
new file mode 100755
index 0000000..1061b31
--- /dev/null
+++ b/src/dyndns-command.sh
@@ -0,0 +1,59 @@
1#!/bin/bash
2subdomain=${SSH_REMOTE_FINGERPRINT//:/}
3ip_address=${SSH_CLIENT%% *}
4lan_address="$SSH_ORIGINAL_COMMAND"
5
6domain=ssh.cryptonomic.net
7
8sqlescape()
9{
10 printf '%s' "'${1/\'/\'\'}'"
11}
12
13add()
14{
15 local newdomain="$(sqlescape "$1.$domain")" ip_address="$(sqlescape "$2")" domain="$(sqlescape "$domain")"
16
17 sqlite3 /etc/powerdns/powerdns.sqlite3 <<END
18BEGIN;
19 delete from records where type='A' and name=$newdomain;
20
21 insert into records
22
23 (domain_id,
24 name,
25 type,
26 content,
27 ttl,
28 prio)
29
30 select
31 id,
32 $newdomain,
33 'A',
34 $ip_address,
35 3600,
36 0
37 from domains
38 where name=$domain;
39COMMIT;
40END
41 if [ $? = 0 ]; then
42 printf '%s\n' "$1 $2"
43 fi
44}
45
46add "$subdomain" "$ip_address"
47
48set -- $lan_address
49while [ $# -ge 2 ]; do
50 d=$1
51 ip=$2
52 shift 2
53
54 case "$d" in
55 *.*) continue;;
56 esac
57
58 add "$d.$subdomain" "$ip"
59done