diff options
Diffstat (limited to 'src/dyndns-command.sh')
-rwxr-xr-x | src/dyndns-command.sh | 59 |
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 | ||
2 | subdomain=${SSH_REMOTE_FINGERPRINT//:/} | ||
3 | ip_address=${SSH_CLIENT%% *} | ||
4 | lan_address="$SSH_ORIGINAL_COMMAND" | ||
5 | |||
6 | domain=ssh.cryptonomic.net | ||
7 | |||
8 | sqlescape() | ||
9 | { | ||
10 | printf '%s' "'${1/\'/\'\'}'" | ||
11 | } | ||
12 | |||
13 | add() | ||
14 | { | ||
15 | local newdomain="$(sqlescape "$1.$domain")" ip_address="$(sqlescape "$2")" domain="$(sqlescape "$domain")" | ||
16 | |||
17 | sqlite3 /etc/powerdns/powerdns.sqlite3 <<END | ||
18 | BEGIN; | ||
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; | ||
39 | COMMIT; | ||
40 | END | ||
41 | if [ $? = 0 ]; then | ||
42 | printf '%s\n' "$1 $2" | ||
43 | fi | ||
44 | } | ||
45 | |||
46 | add "$subdomain" "$ip_address" | ||
47 | |||
48 | set -- $lan_address | ||
49 | while [ $# -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" | ||
59 | done | ||