#!/usr/bin/perl
print "Content-type: text/html\n\n";
$sendmail="/usr/sbin/sendmail -t";
use CGI qw(:standard Vars);

#foreach $key (sort keys(%ENV)) {
#      print "$key = $ENV{$key}<p>"
#}


 
$data_file=(param('data'));
$current_page=(param('page'));
$from=(param('from'));
$message_raw=(param('message'));

unless ($from) {
    $from="Anonymous";
}


if (($from) && ($message_raw)) {
    $message=substr($message_raw,0,256);
    $message=~s/[\000-\037]//g;
    
    open (LOG,">>led.log");
    print LOG "$from: $message\n";
    close (LOG);

    use IO::Socket;
    $SerialFileName = '/dev/prolite';
    my $sock = new IO::Socket::INET (
				     PeerAddr => '192.168.1.1',
				     PeerPort => '7071',
				     Proto => 'tcp',
				     );
    
    $remote_message="\<FU\>\<FR\>$from: $message";
    $nc_push=`echo \"$remote_message\" | nc -v -v irritant 3000`;
    print $sock "$remote_message\n";
    close ($sock);

#mail led message to grrlmonkey and me
    
    open(SENDMAIL, "|$sendmail") or print "Cannot open $sendmail: $!"; 
    print SENDMAIL "Subject: Message from LED Sign\n"; 
    print SENDMAIL "To: spamgod\@monkeyhands.com, anamaria\@monkeyhands.com\n"; 
    print SENDMAIL "From: LEDSIGN\@monkeyhands.com\n";
    print SENDMAIL "$from just left this message: \"$message\"\n\n"; 
    print SENDMAIL $content; close(SENDMAIL);
}

#print "from = $from<br>\n";
#print "message = $message<br>\n";
#print "data_file_raw = $data_file_raw<br>\n";
$page_up=$current_page-1;
$page_down=$current_page+1;



if ($page_up < 0) {
    $page_up=0;
}

if ($page_down > 100) {
    $page_down=0;
}

print <<'TOP';
<html>
<head>
<title>I've got MonkeyHands and I can talk</title>
    


</head>
<body background="images/monkeyhands-splash-small_22.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (monkeyhands-splash-small.psd) -->
<center>
<table id="Table_01" width="910" height="667" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td colspan="15">
			<img src="images/monkeyhands-splash-small_01.jpg" width="909" height="21" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="21" alt=""></td>
	</tr>
	<tr>
		<td rowspan="14">
			<img src="images/monkeyhands-splash-small_02.jpg" width="37" height="645" alt=""></td>
		<td colspan="4" rowspan="4">
			<a href="http://www.monkeyhands.com/wordpress" border=0><img src="images/monkeyhands-splash-small_03.jpg" width="131" height="165" alt="" border=0></a></td>
		<td colspan="10">
			<img src="images/monkeyhands-splash-small_04.jpg" width="741" height="74" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="74" alt=""></td>
	</tr>
	<tr>
		<td colspan="2" rowspan="6">
			<img src="images/monkeyhands-splash-small_05.jpg" width="7" height="388" alt=""></td>
		<td colspan="5">
			<img src="images/monkeyhands-splash-small_06.jpg" width="580" height="17" alt=""></td>
		<td colspan="3" rowspan="2">
			<img src="images/monkeyhands-splash-small_07.jpg" width="154" height="54" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="17" alt=""></td>
	</tr>
	<tr>
		<td colspan="5">
			<img src="images/monkeyhands-splash-small_08.jpg" width="580" height="37" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="37" alt=""></td>
	</tr>
	<tr>
		<td rowspan="11">
			<img src="images/monkeyhands-splash-small_09.jpg" width="18" height="517" alt=""></td>


TOP

    print "<td colspan=\"5\" rowspan=\"5\" background=\"images/monkeyhands-splash-small_10.jpg\" width=\"687\" height=\"455\">";

if ($current_page) {
    $data_file="data-$current_page";
}

#print "data_file = $data_file\n";

if (($from) && ($message_raw)) {
    $last_messages=`tail -10 led.log`;
$last_messages=~s/\n/<br><br>\n/g;
    print "<center>\n";
    print "<table><td>\n";
    print "<b>Thank you for leaving these messages:</b><br>\n";
print "<font size=2>\n";
    print "\n";
    print "$last_messages\n";
    print "</td></table>\n";
}

if ($data_file=~/[a-z0-9]/) {
    open (IN,"<$data_file.dat") || warn "can't open $data_file ($!)<br>\n"; 
    while (<IN>) {
	print "$_";
    }
}

#print "i've got monkeyhands and i can talk\n";
print "<td>";

print <<'BOTTOM_ONE';
		<td colspan="2" rowspan="7">
			<img src="images/monkeyhands-splash-small_11.jpg" width="29" height="475" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="37" alt=""></td>
	</tr>
	<tr>
		<td colspan="4">
			<img src="images/monkeyhands-splash-small_12.jpg" width="131" height="64" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="64" alt=""></td>
	</tr>
	<tr>
		<td colspan="2" rowspan="2">
			<img src="images/monkeyhands-splash-small_13.jpg" width="33" height="233" alt=""></td>

BOTTOM_ONE
    
    print "<td background=\"images/monkeyhands-splash-small_14.jpg\" width=\"69\" height=\"177\">";
print "<a href=\"index.cgi?page=$page_up\"><img src=\"images/up-arrow.jpg\" border=0></a>\n";
print "<a href=\"index.cgi?page=$page_down\"><img src=\"images/down-arrow.jpg\" border=0></a>";
print "</td>\n";

print <<'BOTTOM_TWO';

		<td rowspan="2">
			<img src="images/monkeyhands-splash-small_15.jpg" width="29" height="233" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="177" alt=""></td>
	</tr>
	<tr>
		<td>
			<img src="images/monkeyhands-splash-small_16.jpg" width="69" height="56" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="56" alt=""></td>
	</tr>
	<tr>
		<td rowspan="7">
			<img src="images/monkeyhands-splash-small_17.jpg" width="1" height="183" alt=""></td>
		<td colspan="4" rowspan="5">


<a href="index.cgi?data=led" border=0><img src="images/monkeyhands-splash-small_18.jpg" width="131" height="174" alt="" border=0></a></td>


		<td rowspan="7">
			<img src="images/monkeyhands-splash-small_19.jpg" width="6" height="183" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="121" alt=""></td>
	</tr>
	<tr>
		<td colspan="5">
			<img src="images/monkeyhands-splash-small_20.jpg" width="687" height="10" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="10" alt=""></td>
	</tr>
	<tr>
		<td rowspan="5">
			<img src="images/monkeyhands-splash-small_21.jpg" width="204" height="52" alt=""></td>
		<td rowspan="4">
			<img src="images/monkeyhands-splash-small_22.jpg" width="299" height="47" alt=""></td>
		<td colspan="3">
			<img src="images/monkeyhands-splash-small_23.jpg" width="184" height="10" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="10" alt=""></td>
	</tr>
	<tr>


		<td rowspan="4"><img src="images/monkeyhands-splash-small_24.jpg" width="24" height="42" alt=""></td>


		<td colspan="3">
		<a href="index.cgi?data=dr_j" border=0><img src="images/monkeyhands-splash-small_25.jpg" width="162" height="30" alt="" border=0></a></td>
		<td rowspan="4">
			<img src="images/monkeyhands-splash-small_26.jpg" width="27" height="42" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="30" alt=""></td>
	</tr>
	<tr>
		<td colspan="3" rowspan="3">
			<img src="images/monkeyhands-splash-small_27.jpg" width="162" height="12" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="3" alt=""></td>
	</tr>
	<tr>
		<td colspan="4" rowspan="2">
			<img src="images/monkeyhands-splash-small_28.jpg" width="131" height="9" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="4" alt=""></td>
	</tr>
	<tr>
		<td>
			<img src="images/monkeyhands-splash-small_29.jpg" width="299" height="5" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="5" alt=""></td>
	</tr>
	<tr>
		<td>
			<img src="images/spacer.gif" width="37" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="32" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="69" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="29" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="1" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="6" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="18" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="204" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="299" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="24" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="35" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="125" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="2" height="1" alt=""></td>
		<td>
			<img src="images/spacer.gif" width="27" height="1" alt=""></td>
		<td></td>
	</tr>
</table>
</center>
<!-- End ImageReady Slices -->
</body>
</html>

BOTTOM_TWO
