blob: 1061b31332c2652448625db4720760a8a4c2bb96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/bin/bash
subdomain=${SSH_REMOTE_FINGERPRINT//:/}
ip_address=${SSH_CLIENT%% *}
lan_address="$SSH_ORIGINAL_COMMAND"
domain=ssh.cryptonomic.net
sqlescape()
{
printf '%s' "'${1/\'/\'\'}'"
}
add()
{
local newdomain="$(sqlescape "$1.$domain")" ip_address="$(sqlescape "$2")" domain="$(sqlescape "$domain")"
sqlite3 /etc/powerdns/powerdns.sqlite3 <<END
BEGIN;
delete from records where type='A' and name=$newdomain;
insert into records
(domain_id,
name,
type,
content,
ttl,
prio)
select
id,
$newdomain,
'A',
$ip_address,
3600,
0
from domains
where name=$domain;
COMMIT;
END
if [ $? = 0 ]; then
printf '%s\n' "$1 $2"
fi
}
add "$subdomain" "$ip_address"
set -- $lan_address
while [ $# -ge 2 ]; do
d=$1
ip=$2
shift 2
case "$d" in
*.*) continue;;
esac
add "$d.$subdomain" "$ip"
done
|