#!/usr/bin/perl my $DEBUG=0; use strict; my $domain = "wolfteck.com"; my $host = $ARGV[0]; my $fqdn = "$host.$domain"; my $d='/etc/tinydns/root'; my $ttl = 1800; my $e; unless ($e = $ENV{SSH_CONNECTION}){ die "cannot get connection environment variable\n"; } unless ($host) { die "did not receive hostname\n"; } if (my ($client_ip) = $e =~ /^(\S+)/){ my $f=qq[$d/dynamic.data]; my $t=$f . 'tmp'; my $flag = undef; my $old_ip = undef; open(READ, "<$f") or die "cannot read file $f. $!\n"; my $dyndata; while() { if($_ =~ /^.$fqdn\:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/) { # If line has our fqdn $old_ip = $_; $old_ip =~ s/.*\:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\:.*/$1/; # Grab our old IP address chomp($old_ip); print "old address was: $old_ip\nnew address is: $client_ip\n"; $flag++; } print "olip -- $old_ip\n" if $DEBUG; print "orig -- $_\n" if $DEBUG; if($old_ip) { $_ =~ s/$old_ip/$client_ip/ } # Replace old IP with new IP print "newl -- $_\n" if $DEBUG; $dyndata .= $_; } close(READ); if(!$flag) {$dyndata .= qq[=$fqdn:${client_ip}:$ttl\n]} open(F, ">$t") or die "cannot open file $t for writing. $!\n"; print F $dyndata; close F or die "cannot close file $t. $!\n"; rename $t, $f or die "cannot rename file $t to $f. $!\n"; chdir($d) or die "cannot chdir to $d. $!\n"; exec '/usr/bin/make -s'; } else { warn "cannot get client ip\n"; exit 1; }