#!/usr/bin/perl

# $Id: ip-down,v 1.15 1998/06/09 23:07:00 czyborra Exp $

open (WWWCONF, "+</usr/www/etc/httpd");
print WWWCONF grep(/^CacheNoConnect/&&s/off/on/||seek(WWWCONF,0,0),<WWWCONF>);
close WWWCONF;

$_ = $Z = localtime; 
s/^(...) ... .. (..):.*/$1$2/;
s/Sat|Sun/ /;
s/Mon|Tue|Wed|Thu|Fri//;

if ($ARGV[4] =~ /^194.109/)

{
    # We zijn in Amsterdam

    s/^(09|1[0-7])/08/ || s/ ?\d\d/18/;
    $N = /08/ ? "Standaard" : "Daal"; $T = 60;
    $E = /08/ ? 6.5 : /BelPlus/ ? 2.5 : 3.25; $W = "¢";
}

else

{
    # Berlin Berlin

    s/0[678]/05/;
    s/1[^89]/09/;
    s/19|20/18/;
    s/22|23/21/;
    s/0[01234]/21/; 
    s/ 09/05/;
    s/ 18/05/;

    $N = /21/ ? "Nachts" : /05|18/ ? "Freizeits" : "Tages";
    $T = /21/ ? 240 : /05|18/ ? 150 : 90;
    $E = 0.12; $W = "DM"
}

$U = int (30 + 86400 * -M "/etc/ppp/connect-time");
$C = int (1+$U/$T);

$ENV{"DISPLAY"}=":0.0"; $ENV{"HOME"}="/home/czyborra";

fork || exec "killall -HUP tail pppd fetchmail ip-up .ip-up xnetload tcpdump";

exec "/usr/X11/bin/xmessage", 
    sprintf ("ip-down %s
Seit %d Uhr gilt der %starif mit %d-Sekunden-Takt.
%d x %1.2f %s = %1.2f %s für %d Minuten.",
	     $Z, $_, $N, $T, $C, $E, $W, $C * $E, $W, $U/60);
