HowTo/Create Your Own DynDNS service

Index.py (Python-script) behind htaccess gets the IP from client via http and writes to /var/lib/noip/noip.log

index.py

 * 1) !/usr/bin/python

import os

print "Content-Type: text/plain\n\n"
 * 1) Required header that tells the browser how to render the text.

env = os.environ

outline = "S23-dyndns service \nupdated \n%s.aus.fnordanien.com should resolve to %s within a minute" % (env["REMOTE_USER"], env["REMOTE_ADDR"]) print outline handle = open("/var/lib/noip/noip.log", "a") line = env["REMOTE_USER"]+" "+env["REMOTE_ADDR"]+"\n" handle.write(line) handle.close

OR you can use a PHP script like this or any other cgi script:

S23 No-IP Service "; echo "

"; if ($_POST["IP"]) { $fp = fopen($logfile, "a"); $string = "$REMOTE_USER $IP\n"; echo " Ok, writing your manual input $IP instead. Thank you. Please close the page."; $write = fputs($fp, $string); fclose($fp); die; }

$fp = fopen($logfile, "a"); $string = "$REMOTE_USER $REMOTE_ADDR\n"; $write = fputs($fp, $string); fclose($fp);

?>

Once you have the client IP this or that way:

update_dns.pl (Perl) script (cron'ed) updates bind.


 * 1) !/usr/bin/perl -w
 * 2) Seti23 DNS Update script aus.fnordanien.com
 * 3) Author: seti23 d4 cr3w

my $noip_www_file = "/var/lib/noip/noip.log"; my $nsupdatetmpfile = "/tmp/nsupdate.txt"; my $private_key = "/etc/bind/Ksven.grewe.net.+157+39606.private";
 * 1) config

my $pid_file = "/var/run/update_dns.pid";
 * 1) Programm start
 * 2) setup a pid file...

if (-f $pid_file) { open (PID, "<$pid_file") or die("$0: Cannot open \"$pid_file\" :$!~\n"); while (){ chop; ($session_id) = split (/\n/); print "update_dns.pl appears to be already running --> PID $session_id\n"; print "If you're sure update_dns.pl is not running, whack (rm) $pid_file and try again\n"; } close PID; exit; }
 * 1) Make sure we're not already running...

else { open (PID, ">$pid_file") or die("$0: Cannot open \"$pid_file\" :$!~\n"); $session_id = $$; select PID; print "$session_id\n"; select STDOUT; close PID; }
 * 1) Write a pid file if we're not already running...

if (!open (NOIPLOG, "<$noip_www_file")) { unlink($pid_file); exit(0); }

open (NSUPDATETMP, ">$nsupdatetmpfile") or die("nsupdatetmpfile \"$nsupdatetmpfile\" could not be opened"); select NSUPDATETMP; print "server s23.org\nzone aus.fnordanien.com\n"; while() { chop; ($user, $ip) = split(/\s+/); print "update delete $user.aus.fnordanien.com. A\n"; print "update add $user.aus.fnordanien.com. 1 A $ip\n"; } print "send\n"; close NOIPLOG; close NSUPDATETMP; select STDOUT;

system("/usr/bin/nsupdate -k $private_key < $nsupdatetmpfile"); unlink($nsupdatetmpfile); unlink($noip_www_file); unlink($pid_file);