blob: 8530058a61e812df8c1147c0423ae2da9592a8f9 (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/bin/bash
die() { printf '%s\n' "$*" >&2; exit 1; }
sql_string()
{
printf '%s' "'${1//\'/\'\'}'"
}
powerdns_sqlite_add_replace_record()
{
local sql_new_domain="$(sql_string "$1.$3")"
local sql_ip_address="$(sql_string "$2")"
local sql_domain="$(sql_string "$3")"
local record_type="$(sql_string "$4")"
sqlite3 /etc/powerdns/powerdns.sqlite3 <<END
BEGIN;
DELETE FROM records WHERE type=$record_type AND name=$sql_new_domain;
INSERT INTO records
(domain_id,
name,
type,
content,
ttl,
prio)
SELECT
id,
$sql_new_domain,
$record_type,
$sql_ip_address,
3600,
0
FROM domains
WHERE name=$sql_domain;
COMMIT;
END
}
add()
{
local record_type
case "$2" in
*.*.*.*) record_type=A ;;
*:*) record_type=AAAA ;;
*) exit 1 ;;
esac
powerdns_sqlite_add_replace_record "$1" "$2" "$domain" "$record_type" \
&& printf '%s %s\n' "$1.$domain $2"
}
main()
{
add "$subdomain" "$ip_address"
set -- $SSH_ORIGINAL_COMMAND
while [ $# -ge 2 ]; do
d=$1
ip=$2
shift 2
case "$d" in
*.*) continue;;
esac
add "$d.$subdomain" "$ip"
done
}
PEM_DEST=$HOME/public_rsync
PATH=$HOME/bin:$PATH
eval "$(samizdat-ssh-uid --copy-pem "$PEM_DEST")"
domain=${SSH_CLIENT_DOMAIN}
subdomain=${SSH_CLIENT_FINGERPRINT}
ip_address=${SSH_CLIENT%% *}
main "$@"
|