#!/usr/bin/perl

$data = '/var/log/httpd/counter.mn.data';
$lockfile = '/tmp/counter.mn.LOCK';

&increment;

print << "STOP"
Content-Type: text/html

<html> <HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; Linux 2.1.130 ppc) [Netscape]">
   <TITLE>Welcome to Mairs.Net!</TITLE>
<SCRIPT LANGUAGE="JavaScript">
image1 = new Image();
image1.src = "mn0.gif";
</SCRIPT>
</HEAD>
<!-- Background gray, links blue (unvisited), navy (visited), red (active) -->
<BODY TEXT="#000000" BGCOLOR="#fcfcfc" LINK="#0000FF" VLINK="#0000ff" ALINK="#FF0000">
<center><A HREF="http://www.heartbomb.com" onmouseover="image1.src='abaw2.gif';" onmouseout="image1.src='mn0.gif';"><IMG SRC="mn0.gif" NAME="image1" BORDER=0 alt=heartbomb></A></center>
<center><br>
<br>Panic now, avoid the rush!
</center>
<br><br>
<!--Mairs.Net is split.  Now much is broken.  I'm fixing as I notice, but feel 
free to <a href="mailto:mmairs\@mairs.net">mention broken things</a>.  
<br>Woo hoo!  Finally got my  own SSL working.  Yeah, I've done it for clients 
for years, but the shoe maker's children 'n' all dat.  Anyway, it's
<a href="https://secure.mairs.net">working</a> well.  Wanna open a store? Drop 
me a <a href="mailto:mmairs\@mairs.net"> line.<a>  
<br>Uh oh.  We're all in serious trubba now... here's 
<a href="http://www.mairs.net/pn-0.7.2.1_Phoneix-E/html/index.php">post nuke</a>
.
<HR WIDTH="90%" SIZE="8">
Have you come to visit <a HREF="http://www.mairs.net/~mmairs">Matt Mairs</A>, 
 <A HREF="http://www.mairs.net/~mmairs/mannwitch.html">Mannwitch</a>,
 <A HREF="http://www.mairs.net/HayWire">HayWire</a>
 or <A HREF="http://www.mairs.net/hubris">hubris</a>?
<br>Beware!  Matt's developing again!  Witness that disaster at 
<a href="http://www.disorged.org">Disorged.Org</a>
</center>
<br>
<a href="http://w3.mairs.net/cgi-bin/who.cgi">Who's</a> on mairs.net?
<br>
<a href="http://w3.mairs.net/cgi-bin/dtl.cgi">Where did they come from?  What did they get?</a>
<br>
And other not so vital <a href="http://w3.mairs.net/cgi-bin/stats.cgi">statistics</a>.
<br><br>-->
<HR WIDTH="90%" SIZE="8">
<CENTER><A HREF="http://www.mairs.net/~mmairs"><IMG SRC="bassclef1.gif" 
ALT="[ What's Matt Up To Now? ]"><br>Matt's Place...</A></CENTER>

<CENTER><A HREF="http://www.apache.org/"><IMG SRC="apache_pb.gif" 
ALT="[ Poweredby Apache ]"><br>Get Apache or be sad.</A></CENTER>

<CENTER><!--Now I use<br>--><a href="http://yellowdoglinux.com">
<img src="banner_left.jpg" alt="[ Yellow Dog ]"><br>Get a Mac.  Get Yellow Dog. 
Be happy!</a></center>

<CENTER>This is an <a href="http://www.apple.com/imac">iMac.</a></CENTER>
<CENTER>RISC performance at a PC price!</CENTER>
  <form method="post" action="http://www.kartoo.com/perso.php3" name="kartoo" >
    <div align="center">Kartoo Is The Coolest (Meta) Search Engine:</div>
    <table border="0" cellpadding="0" cellspacing="0" bgcolor="00007D" width="326" align="center">
      <tr align="center" valign="middle"> 
        <td colspan="2" height="22"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Search 
          : </font></b> 
          <input type="text" name="q" size="25">
          <input type="submit" name="submit" value="OK">
        </td>
      </tr>      <tr align="center"> 
        <td colspan="2" valign="middle" height="8"> <b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"> 
          <input type="radio" name="lg" value="1" checked>
          english web &nbsp;&nbsp;&nbsp; 
          <input type="radio" name="lg" value="0">
          worldwide web </font></b></td>
      </tr>

    </table>
    <div align="center"></div>
    
<div align="center"> 
  <p> 
    <input type="hidden" name="fd" value="1">
    <input type="hidden" name="tr" value="3">
    <input type="hidden" name="bo" value="4">
    <input type="hidden" name="langue" value="en">
  </p>
    </div>
  </form>
<center>
<a href="http://www.itsassure.com"><img src=banner1.gif alt="Net Assure"></a><br> is the coolest ISP!
</center>
<br>
This counter has biffed it approximately 20 times because we weren't paying 
attention and the disk filled up or for other very peculiar reasons I'd tell 
you about if you cared.
<br>
This page has been accessed approximately 
$accesses
 times </body> </html>\n
<div align="right">Want email?  Need a website?  
<a href="mailto:mmairs\@mairs.net">Talk</a> to me.</div>
<!--<script language="JavaScript" type="text/javascript" src="http://tools.addme.com/servlet/pop?id=104417"></script>-->
STOP
;
sub increment {
  # read the data
  open(DATA,$data) || die "Can't open data file.\n";
  $accesses = <DATA>;
  $accesses++;
  close(DATA);
  # check for lock file
  while (-e $lockfile) {
    sleep 2;   # wait 2 seconds
  }
  # create lockfile
  open(LOCK,">$lockfile") || die "Can't create lockfile.\n";
  close(LOCK);
  # write new value
  open(DATA,">$data") || die "Can't create lockfile.\n";
  print DATA "$accesses";
  close(DATA);
  # delete lockfile
  unlink($lockfile);
}
