Revision 14697fe6 common.sh
b/common.sh | ||
---|---|---|
215 | 215 |
fi |
216 | 216 |
|
217 | 217 |
} |
218 |
|
|
219 |
|
|
220 |
# DDNS related functions |
|
221 |
|
|
222 |
# ommit zone statement |
|
223 |
# nsupdate will attempt determine the correct zone to update based on the rest of the input |
|
224 |
send_command () { |
|
225 |
|
|
226 |
local command="$1" |
|
227 |
hooks-log dnshook "$command" |
|
228 |
nsupdate -k $KEYFILE > /dev/null << EOF |
|
229 |
server $SERVER |
|
230 |
$command |
|
231 |
send |
|
232 |
EOF |
|
233 |
|
|
234 |
} |
|
235 |
|
|
236 |
|
|
237 |
update_arecord () { |
|
238 |
|
|
239 |
local action=$1 |
|
240 |
local command= |
|
241 |
if [ -n "$IP" ]; then |
|
242 |
command="update $action $GANETI_INSTANCE_NAME.$FZONE $TTL A $IP" |
|
243 |
send_command "$command" |
|
244 |
fi |
|
245 |
|
|
246 |
} |
|
247 |
|
|
248 |
|
|
249 |
update_aaaarecord () { |
|
250 |
|
|
251 |
local action=$1 |
|
252 |
local command= |
|
253 |
if [ -n "$EUI64" ]; then |
|
254 |
command="update $action $GANETI_INSTANCE_NAME.$FZONE $TTL AAAA $EUI64" |
|
255 |
send_command "$command" |
|
256 |
fi |
|
257 |
|
|
258 |
} |
|
259 |
|
|
260 |
|
|
261 |
update_ptrrecord () { |
|
262 |
|
|
263 |
local action=$1 |
|
264 |
local command= |
|
265 |
if [ -n "$IP" ]; then |
|
266 |
command="update $action $RLPART.$RZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE" |
|
267 |
send_command "$command" |
|
268 |
fi |
|
269 |
|
|
270 |
} |
|
271 |
|
|
272 |
update_ptr6record () { |
|
273 |
|
|
274 |
local action=$1 |
|
275 |
local command= |
|
276 |
if [ -n "$EUI64" ]; then |
|
277 |
command="update $action $R6LPART$R6ZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE" |
|
278 |
send_command "$command" |
|
279 |
fi |
|
280 |
|
|
281 |
} |
|
282 |
|
|
283 |
update_all () { |
|
284 |
|
|
285 |
local action=$1 |
|
286 |
update_arecord $action |
|
287 |
update_aaaarecord $action |
|
288 |
update_ptrrecord $action |
|
289 |
update_ptr6record $action |
|
290 |
|
|
291 |
} |
|
292 |
|
|
293 |
|
|
294 |
# first argument is an eui64 (IPv6) |
|
295 |
# sets GLOBAL args R6REC, R6ZONE, R6LPART |
|
296 |
# lets assume eui64=2001:648:2ffc:1::1 |
|
297 |
# the following commands produce: |
|
298 |
# R6REC=1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.c.f.f.2.8.4.6.0.1.0.0.2.ip6.arpa |
|
299 |
# R6ZONE=1.0.0.0.c.f.f.2.8.4.6.0.1.0.0.2.ip6.arpa |
|
300 |
# R6LPART=1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0. |
|
301 |
get_rev6_info () { |
|
302 |
|
|
303 |
local eui64=$1 |
|
304 |
if [ -z "$eui64" ]; then |
|
305 |
R6REC= ; R6ZONE= ; R6LPART= ; |
|
306 |
else |
|
307 |
R6REC=$(host $eui64 | egrep -o '([[:alnum:]]\.){32}ip6.arpa' ) |
|
308 |
R6ZONE=$(echo $R6REC | awk -F. 'BEGIN{rpart="";} { for (i=32;i>16;i=i-1) rpart=$i "." rpart; } END{print rpart "ip6.arpa";}') |
|
309 |
R6LPART=$(echo $R6REC | awk -F. 'BEGIN{lpart="";} { for (i=16;i>0;i=i-1) lpart=$i "." lpart; } END{print lpart;}') |
|
310 |
fi |
|
311 |
|
|
312 |
} |
|
313 |
|
|
314 |
|
|
315 |
# first argument is an ipv4 |
|
316 |
# sets args RZONE, RLPART |
|
317 |
# lets assume IP=203.0.113.1 |
|
318 |
# RZONE="113.0.203.in-add.arpa" |
|
319 |
# RLPART="1" |
|
320 |
get_rev4_info () { |
|
321 |
|
|
322 |
local ip=$1 |
|
323 |
if [ -z "$ip" ]; then |
|
324 |
RZONE= ; RLPART= ; |
|
325 |
else |
|
326 |
OLDIFS=$IFS |
|
327 |
IFS=". " |
|
328 |
set -- $ip |
|
329 |
a=$1 ; b=$2; c=$3; d=$4; |
|
330 |
IFS=$OLDIFS |
|
331 |
RZONE="$c.$b.$a.in-addr.arpa" |
|
332 |
RLPART="$d" |
|
333 |
fi |
|
334 |
|
|
335 |
} |
|
336 |
|
|
337 |
|
|
338 |
# Query nameserver for entries related to the specific instance |
|
339 |
# An example output is the following: |
|
340 |
# www.google.com has address 173.194.113.114 |
|
341 |
# www.google.com has address 173.194.113.115 |
|
342 |
# www.google.com has address 173.194.113.116 |
|
343 |
# www.google.com has address 173.194.113.112 |
|
344 |
# www.google.com has address 173.194.113.113 |
|
345 |
# www.google.com has IPv6 address 2a00:1450:4001:80b::1012 |
|
346 |
query_dns () { |
|
347 |
|
|
348 |
HOSTQ="host -s -R 3 -W 3" |
|
349 |
HOST_IP_ALL=$($HOSTQ $GANETI_INSTANCE_NAME.$FZONE $SERVER | sed -n 's/.*has address //p') |
|
350 |
HOST_IP6_ALL=$($HOSTQ $GANETI_INSTANCE_NAME.$FZONE $SERVER | sed -n 's/.*has IPv6 address //p') |
|
351 |
|
|
352 |
} |
Also available in: Unified diff