hourly, I call a server's url. if the server notices a change, it updates a DNS zone :
root@clic12:/etc/cron.hourly# cat wgk
#!/bin/sh
IP=`ifconfig -a|grep 192|head -n 1|sed -e 's/ */|/g'|cut -d\| -f3`
URL="http://www.yoursite.net/zone.php"
wget -o /dev/null -O /dev/null "$URL" 2>&1 >/dev/null
wget -o /dev/null -O /dev/null "$URL?n=guy&ip=$IP" 2>&1 >/dev/null
and the php side (can manage many dyndnses):
//print_r($_SERVER);
$n=preg_replace("/[^a-z]/","",$_REQUEST["n"]);
if ($n)
foreach(explode("\n",file_get_contents("zone.txt")) as $l)
if (preg_match("/ $n /",$l)) $m=preg_replace("/^.* $n /","",$l);
if ($_REQUEST["a"]) die(file_get_contents("zone.txt"));
if ($_REQUEST["d"])
die("ok".file_put_contents("zone.txt",strftime("%D %T reset
\n")));
\n")));
$q=strftime("%D %T $n ".$_REQUEST["ip"]." ".$_SERVER["REMOTE_ADDR"]."
");
");
file_put_contents("zone.txt",$q."\n",FILE_APPEND);
$q=preg_replace("/^.* $n /","",$q);
if ($q == $m) die("ok same ip");
file_put_contents("zone.txt","***********NEWIP*******\n".$q."\n",FILE_APPEND);
if ($n=="guy")
passthru("sudo /root/scripts/named_dyndns.sh yoursite.net adsl ".$_SERVER["REMOTE_ADDR"]);
?>.
and named_dyndns.sh + domain + subdomain + ip
#!/bin/sh
domain=$1
key=$2
ip=$3
if [ "$ip" = "" ];then echo "$0 domain key ip";exit;fi
dmx=/var/named/chroot//etc/named.xtra
sed -i $dmx -e "s/^$domain:$key IN A .*$/$domain:$key IN A $ip/"
/root/bin/named_make_domxtra2zon.pl $domain
after, this is your own domain/named/zone system,
that recreates a zonefile and reload named
Aucun commentaire:
Enregistrer un commentaire