#!/usr/bin/perl
# --- Send Email ---
$emailaddress = '';
$emailaddresscc = '';
$email= 0;
# --- Fuse.net ---
$fusename = '';
$fusepass = '';
$fuse = 0;
# --- ChangeIP ---
$chIPname = '';
$chIPpass = '';
$chIP = 1;
# --- Setings ---- 
$file = '/tmp/index.html';

`touch $file`;

use HTTP::Request::Common qw(POST);
use LWP::Simple;
use LWP::UserAgent;

$ua=new LWP::UserAgent(timeout=>4);
$ua->agent("Mozilla/4.5" . $ua->agent);
$ua->timeout(4);

$content = get('http://www.fuse.net/cgi-bin/ztip.cgi');
($junk, $ip) = split(/<b>/, $content);
($ip, $junk) = split(/</, $ip);
chop($ip);

if ($ip == "") { print "No IP"; die;}	

open(NEW, "$file") or die "can't open $new: $!";
$old_ip = <NEW>;
close(NEW);
chop $old_ip;

if ($old_ip ne $ip){
	$sysinfo = `uptime`;	
	$currentd = `date`;

	open(NEW, "> $file") or die "can't open $new: $!";
	print NEW "$ip
	<html>
	<head>
	<title>You'll love the Hinterland like it was your own.</title>
	</head>
	<body bgcolor=#000000 text=#000000 link=#9999CC vlink=9999CC>
	<font face=Arial size=2 color=#999999>
	<br><img src=A.jpg>
	<p>
	<br><b>LAST UPDATE: </b> $currentd
	<br><b>UPTIME: </b> $sysinfo
	<br><b>IP: </b> <a href=http://$ip>$ip</a><BR>
	";

	close(NEW);


	if ($email == 1){
		use Net::SMTP;
    
		$smtp = Net::SMTP->new('localhost');
    
#    		$smtp->mail('root@ohioposse.net');
    		$smtp->to($emailaddress);
    		$smtp->cc($emailaddresscc);
    
    		$smtp->data();
    		$smtp->datasend("Subject: New IP\n");
    		$smtp->datasend("\n");
    		$smtp->datasend("$ip\n\n");
    		$smtp->dataend();
    
    		$smtp->quit;  

		print "Email Sent.\n";

	}

	if ($fuse == 1){
		`/usr/bin/lftp -u $fusename,$fusepass -e "put $file index.html; put /home/johnd/www/html/hinterland/00/A.jpg A.jpg; exit" home.fuse.net`;

#		$req = POST 'http://home.fuse.net/publish/publish.cgi',
#		Content_Type => 'multipart/form-data',
#		Content      => [init   => ["$file"],];
#
#		$req->authorization_basic($fusename, $fusepass);
#		$ua->request($req)->as_string;  

		print "fuse.net Update.\n";

	}

        if ($chIP == 1){
                use Crypt::SSLeay;
                $req = HTTP::Request->new(GET => "https://www.changeIP.com/dynamic/dns/update.asp?u=$chIPname&p=$chIPpass&cmd=update&set=1&ip=$ip&ofline=0");
                $res = $ua->request($req); 
                print "changeIP update.\n";
                
        } 

	print "$ip\n";
}

else {
#	 print "No Change\n";
}
