The script.php
$ cat /usr/local/bin/update.php
<?
//* Package: changeip.com Auto IP updater
//* Version 1.1
//* System Requirements: Linux, (PHP 3, PHP 4 >= 4.0.0)
//* and the ability to run crontabs
//* File: update.php
//* Author: Don Jobes -
webmaster@internet-demon.com
//* Last Modified: 01.21.2002
//*
//* YOU CAN REDISTRIBUTE THIS SOFTWARE. You can modify it for
//* your own personal use provided that this header remains intact.
//*
//* This software is provided as is, without a warranty of any kind.
//* Neither Don Jobes nor Internet-Demon.com take responsibility for
//* any damages suffered as a result of using or modifying this software.
//* In no event will Don Jobes or Internet-Demon.com be held liable
//* for any lost revenue, profit, data, or punitive damages, however
//* caused and regardless of theory of liability, arising out of the use
//* of or inability to use this software, even if Don Jobes and/or
//* Internet-Demon.com has been advised of the possibility of such
//* damages.
//*
//* Donations are not necessary but welcomed through Paypal
//*
djobes@internet-demon.com
//*
//* Entire contents � Copyright 2001-2002 Internet-Demon.com.
//* All rights reserved.
//*
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////BRIEF OVERVIEW PLEASE READ //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*
//*
//* This script will update your dynamic ip address by the use of a cron job. There are two ways this script can
//* be used.
//*
//* 1. No Router, This is if your PC Running Linux is connected directly to your ISP. Using this setup option will
//* allow you to set the cron job to run every few minutes. Only when your IP changes an update will be sent.
//*
//* NOTE: IF YOUR CRON JOB IS SET TO EVERY FEW MINUTES SET YOUR EMAIL OPTIONS TO "0" Or you will fill the log file
//* along with your email box.
//*
//*
//* 2. Router, This is if your PC Running Linux is connected to a router. for example, a LINKSYS. When using a router
//* your IP address on your linux PC would not be the true IP assigned by your ISP. The IP would be assigned by the
//* router and would more than likely be 192.168.1.* If you have this type of connection you will have to USE the
//* bypass feature and send out updates whether you need them or not.
//*
//* NOTE: If you are on a CABLE MODEM or DSL your IP almost never changes. So you should not set your cron job to run
//* every few minutes. More like once every few hours is sufficaint. Some will find that two to three times
//* a day will work fine. After a week or so you will find that you can tailor the cron for a longer duration
//* between updates.
//*
//* IF YOUR CRON JOB IS SET TO EVERY FEW MINUTES SET YOUR EMAIL OPTIONS TO "0" Or you will fill the log file
//* along with your email box.
//*
//*
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////CHECK YOUR CHANGEIP.COM SETTINGS ////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*
//*
//* 1. Make Changes to your domains so that ALL Options update on SET 1. The first column of check boxes.
//*
//*
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// SETUP INSTRUCTIONS ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*
//* 1. Edit the variables below in this file to match your server and your needs.
//* 2. Upload update.php and updatedns.log to your root web.
//* 3. chmod updatedns.log to 666
//* 3. Create a cron job to execute update.php. See the following example.
//*
//* Telnet into your server create a new cronjob. The following would
//* run every night at 12:59pm. Depending on your needs you will have
//* to modify the run time variables.
//*
//* 59 23 * * * wget -q
http://www.yoursite.com/update.php
//*
//* minute (0-59)
//* hour (0-23)
//* day of the month (1-31)
//* month of the year (1-12)
//* day of the week (0-6 with 0=Sunday)
//*
//* NOTE: A cron can also be setup using WEBMIN if you have it installed. This is easyier for most.
//*
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// SETUP OPTION DESCRIPTIONS DO NOT EDIT THESE HERE //////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*
//*
//* $username = "changeip.com login username";
//* $password = "changeip.com login password";
//*
//* $Adminemail = "you@yourdomain.com";
//* $Sendmail = "/path/to/sendmail -t -i";
//*
//* $Logfile = "/full/server/path/to/updatedns.log";
//*
//*
////////////////////////////////////////// IF USING A ROUTER ////////////////////////////////////////////////
//*
//* $Bypass = "0"; SET TO "1" if you are behind a router and your PC is assigned an IP by your router.
//* $Log3 = "0"; No log file output
//* $Log3 = "1"; Appends a new line to the log file when a update is sent to changeip.com
//*
//*
//*
////////////////////////////////////// NO ROUTER, DIRECT CONNECTION /////////////////////////////////////////
//*
//*
//*
//* $Log1 = "0"; No log file output
//* $Log1 = "1"; Appends a new line to the log file ONLY when a update is sent to changeip.com
//* $Log2 = "0"; No log file output
//* $Log2 = "1"; Appends a new line to the log file even when there is no update sent to changeip.com
//* $Email1 = "0"; No Email Will be sent
//* $Email1 = "1"; Sends an email to the address specified. when a update is sent to changeip.com
//* $Email2 = "0"; No Email Will be sent
//* $Email2 = "1"; Sends an email to the address specified. when a update is sent to changeip.com
//*
//* $IPfile = "/full/server/path/to/updatednsIP.log"; <--- This is not an option if using direct connect
//* $Logfile = "/full/server/path/to/updatedns.log";
//*
//*
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////<-------- EDIT USER VARIABLES HERE --------> ////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$Bypass = "0";
$username = "username";
$password = "password";
$Adminemail = "you@yourdomain.com";
$Sendmail = "/path/to/sendmail -t -i";
$IPlogfile = "/full/server/path/to/updatednsIP.log";
$Logfile = "/full/server/path/to/updatedns.log";
$Log1 = "1";
$Email1 = 1;
$Log2 = "1";
$Email2 = 1;
$Log3 = "1";
$Email3 = "1";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////<--------- END USER VARIABLES --------> /////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING//////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$UPDATEURL = "https://www.changeip.com/dynamic/dns/update.asp?u=$username&p=$password&cmd=update&set=1&offline=0";
if ($REMOTE_ADDR == "") $Boxaddress = "Server address Unknown";
else $Boxaddress = $REMOTE_ADDR;
$tdate = date("h:i:s");
$datecode = date("m-d-Y");
if($Bypass == "0"){
if (file_exists($IPlogfile)){
$file=file("$IPlogfile","r");
foreach($file as $line){
list($Lastip,$blank) = split("\:",chop($line));
if($Lastip != $REMOTE_ADDR){
header("location: $UPDATEURL");
$createFile = fopen("$IPlogfile", "w");
fwrite($createFile,"$REMOTE_ADDR:\r\n");
fclose($createFile);
if($Log1 == "1"){
$filelog = fopen("$Logfile", "a");
flock($filelog, 2);
fputs($filelog,"DNS Update set 1, Current IP: $REMOTE_ADDR, Previous IP: $Lastip, Date: $datecode, Time: $tdate. Update Successful\r\n");
flock($filelog, 3);
fclose($filelog);
}
if($Email1=="1"){
$to = "$Adminemail";
$subject = "IP Auto update Report";
$body ="Hello, $username\r\n\r\nYour IP address has changed and an update request was sent to changeip.com.\r\n\r\n Current IP: $REMOTE_ADDR\r\n Previous IP: $Lastip\r\n Time: $tdate\r\n Date: $datecode\r\n\r\nChangeip.com IP Auto Updater by
Djobes@Internet-demon.com";
$mailer = popen($Sendmail,"w") or die ("error writing");
fwrite ($mailer,"Subject: $subject\nFrom: \"Changeip-AutoUpdater\" $Adminemail\nTo: $to\n\n$body");
pclose($mailer);
}
}
}
}
else
{
header("location: $UPDATEURL");
$createFile = fopen("$IPlogfile", "w");
fwrite($createFile,"$REMOTE_ADDR:\r\n");
fclose($createFile);
if($Log1 == "1"){
$filelog = fopen("$Logfile", "a");
flock($filelog, 2);
fputs($filelog,"DNS Update set 1, Current IP: $REMOTE_ADDR, Previous IP: Unknown, Date: $datecode, Time: $tdate. Update Successful\r\n");
flock($filelog, 3);
fclose($filelog);
}
if($Email1=="1"){
$to = "$Adminemail";
$subject = "IP Auto update Report";
$body ="Hello, $username\r\n\r\nYour IP address has changed and an update request was sent to changeip.com.\r\n\r\n Current IP: $REMOTE_ADDR\r\n Previous IP: Either this is the first time you run this script or you deleted the updatednsip.log. This is normal\r\n Time: $tdate\r\n Date: $datecode\r\n\r\nChangeip.com IP Auto Updater by
Djobes@Internet-demon.com";
$mailer = popen($Sendmail,"w") or die ("error writing");
fwrite ($mailer,"Subject: $subject\nFrom: \"Changeip-AutoUpdater\" $Adminemail\nTo: $to\n\n$body");
pclose($mailer);
}
}
if($Lastip == $REMOTE_ADDR){
if($Log2 == "1"){
$filelog = fopen("$Logfile", "a");
flock($filelog, 2);
fputs($filelog,"DNS Update set 1, Current IP: $REMOTE_ADDR, Previous IP: $REMOTE_ADDR, Date: $datecode, Time: $tdate. No Update Required\r\n");
flock($filelog, 3);
fclose($filelog);
}
if($Email2=="1"){
$to = "$Adminemail";
$subject = "IP Auto update Report";
$body ="Hello, $username\r\n\r\nYour IP address did not change since the last update.\r\nThere was no need to send a update request to changeip.com\r\n\r\n Current IP: $REMOTE_ADDR\r\n Previous IP: $Lastip\r\n Time: $tdate\r\n Date: $datecode\r\n\r\nChangeip.com IP Auto Updater by
Djobes@Internet-demon.com";
$mailer = popen($Sendmail,"w") or die ("error writing");
fwrite ($mailer,"Subject: $subject\nFrom: \"Changeip-AutoUpdater\" $Adminemail\nTo: $to\n\n$body");
pclose($mailer);
}
}
}
if($Bypass == "1"){
header("location: $UPDATEURL");
if($Log3 == "1"){
$filelog = fopen("$Logfile", "a");
flock($filelog, 2);
fputs($filelog,"DNS Update set 1, Current IP: $REMOTE_ADDR, Date: $datecode, Time: $tdate. Update Successful\r\n");
flock($filelog, 3);
fclose($filelog);
}
if($Email3=="1"){
$to = "$Adminemail";
$subject = "IP Auto update Report";
$body ="Hello, $username\r\n\r\nYour IP has been updated,\r\n\r\n Current IP: $REMOTE_ADDR\r\n Time: $tdate\r\n Date: $datecode\r\n\r\nChangeip.com IP Auto Updater by
Djobes@Internet-demon.com";
$mailer = popen($Sendmail,"w") or die ("error writing");
fwrite ($mailer,"Subject: $subject\nFrom: \"Changeip-AutoUpdater\" $Adminemail\nTo: $to\n\n$body");
pclose($mailer);
}
}
?>s