#!/usr/local/bin/perl

###################################################################################
#                     Aneip GuestBook ver 0.9b
# COPYRIGHT NOTICE:
#
# Copyright 1999 Mohd Hanif Ibrahim.  All Rights Reserved.
# ©1999 Mohd Hanif Ibrahim.
###################################################################################
# This script was release as FReeware.
#
# By using this program you agree to indemnify me from any liability.
#
# Distributing the software and/or documentation with other products
# (commercial or otherwise) or by other than electronic means without
# my prior written permission is forbidden.
#
# http://aneip.hypermart.net/guestbook
#
####################################################################################
print "Content-type: text/html\n\n";

$mail_prog = '/var/qmail/bin/qmail-inject' ;
$datafail ='guestbook.dat'; 		# Guestbook data file
$viewperpage = '15';  				# Number of record to show per page
$sendtosigner = '0'; 				# Send thanx email  1 = enable 0 = disable
$sendtoadmin = '0'; 				# send email to admin when got new record
$adminemail = 'gand-khujli\@gand-khujli.com'; 	# admin email
@badwords = ("sucks");		# put your list of badwords
$LIFO = '1';   						# 1 - Display last record first 
									# 0 - Display first record first.


require ('cgi-lib.pl');
&ReadParse(*field);
$nama = $field{'nama'} ;	 
$email = $field{'email'} ;	 
$hp = $field{'hp'} ;	 
$urlhp = $field{'urlhp'} ;	 
$lokasi = $field{'lokasi'} ;	 
$komen = $field{'komen'} ;	 
$ip = $field{'ip'} ;	 
$date = $field{'date'} ;	 
$masa = $field{'masa'} ;	 
$page = $field{'page'};
if ($page eq '') {
	$page = '0';
}

if ($field{'action'} eq 'form'){
&PrintForm;
exit;
}

if ($field{'action'} eq 'preview'){
&preview;
exit;
}
 

if ($field{'action'} eq 'Confirm'){
&save;
exit;
}

if ($field{'action'} eq '' || $field{'action'} eq 'display'){
&display;
exit;
}

############################################################
#  Edit this section is you want to change the appearance  #
############################################################

sub header {
print qq|





<style> 

a:active{text-decoration:none; color:#000000;}

a:link{text-decoration:none; color:#000000;}

a:visited{text-decoration:none; color:#000000;}

a:hover{text-decoration:none; color:#0080C0;}

</style> 

<STYLE>BODY {

	SCROLLBAR-FACE-COLOR: #0080c0; SCROLLBAR-HIGHLIGHT-COLOR: #000000; SCROLLBAR-SHADOW-COLOR: #000000; SCROLLBAR-3DLIGHT-COLOR: #c8cdcf; SCROLLBAR-ARROW-COLOR: #000000; SCROLLBAR-TRACK-COLOR: #ffffff; SCROLLBAR-DARKSHADOW-COLOR: #c8cdcf

}

</STYLE>

<center>

<img border="0" src="http://www.gand-khujli.com/title.gif" width="485" height="50">
<br>
<font face="Tahoma" size="2"><a href=\"guestbook.pl?action=form\">Sign the guestbook</a>
</center><br>

<center>

<table border="1" cellpadding="0" cellspacing="0" width="477" bgcolor="#000000" height="72" style="border-collapse: collapse" bordercolor="#111111">

<tr>

<td bgcolor="#0080C0" height="4" width="493">

<p align="center"><font face="Tahoma" size="2" color="#FFFFFF">Gand-Khujli.com 
Guestbook</font></td>

</tr>

<tr>

<td bgcolor="#FFFFFF" height="67" width="493">

<center>



|;
}

sub footer {
print qq|



<style> 

a:active{text-decoration:none; color:#000000;}

a:link{text-decoration:none; color:#000000;}

a:visited{text-decoration:none; color:#000000;}

a:hover{text-decoration:none; color:#0080C0;}

</style> 

<STYLE>BODY {

	SCROLLBAR-FACE-COLOR: #0080c0; SCROLLBAR-HIGHLIGHT-COLOR: #000000; SCROLLBAR-SHADOW-COLOR: #000000; SCROLLBAR-3DLIGHT-COLOR: #c8cdcf; SCROLLBAR-ARROW-COLOR: #000000; SCROLLBAR-TRACK-COLOR: #ffffff; SCROLLBAR-DARKSHADOW-COLOR: #c8cdcf

}

</STYLE>




<center><Font size=1> <br><a href="http://www.gand-khujli.com/index2.htm">http://www.gand-khujli.com/index2.htm</a></font>
|;
}


#Print HTML form. Edit this to change the GUESTBOOK appearance. Make sure you
#didn't change the field name or the script will not work.

sub PrintRecord {
$num--;
print qq|





<style> 

a:active{text-decoration:none; color:#000000;}

a:link{text-decoration:none; color:#000000;}

a:visited{text-decoration:none; color:#000000;}

a:hover{text-decoration:none; color:#0080C0;}

</style> 

<STYLE>BODY {

	SCROLLBAR-FACE-COLOR: #0080c0; SCROLLBAR-HIGHLIGHT-COLOR: #000000; SCROLLBAR-SHADOW-COLOR: #000000; SCROLLBAR-3DLIGHT-COLOR: #c8cdcf; SCROLLBAR-ARROW-COLOR: #000000; SCROLLBAR-TRACK-COLOR: #ffffff; SCROLLBAR-DARKSHADOW-COLOR: #c8cdcf

}

</STYLE>











<center>
<table border="0" width="400" height="53" bgcolor="#000000" cellspacing="1"
cellpadding="2">
  <tr>
    <td width="120" height="94" rowspan="2" bgcolor="#FFFFFF"><p align="center"><strong>$num</strong><br>
    <font face="Tahoma" size="1">$date<br>$masa</font></td>
    <td width="436" height="1" bgcolor="#FFFFFF"><strong><font face="Tahoma" size="2"><a
    href="mailto:$email" style="text-decoration: none; color: rgb(0,0,0)">$nama</a><br>
    </font><a href="$urlhp" style="text-decoration: none; color: rgb(0,0,0)"><font
    face="Tahoma" size="1">$hp</font></a></strong></td>
  </tr>
  <tr>
    <td width="320" height="56" bgcolor="#FFFFFF"><small><font face="Tahoma">
    $komen
    <strong>.</strong></font></small><p><font face="Tahoma" size="1">$lokasi<br>
    $ip<font></td>
  </tr>
</table>
<br>
|;

}

####################

#Print HTML form. Edit this to change the FORM appearance. Make sure you
#didn't change the field name or the script will not work.

sub PrintForm {
&header;
print qq|


<center>

</center>

<br><br>


<center>
















<form method="POST" action="guestbook.pl" align="center">
  <div align="center"><center><table border="0" width="420" height="87" bgcolor="#FFFFFF"
  cellspacing="1" cellpadding="2">
    <tr>
      <td width="33" height="87" rowspan="8" bgcolor="#FFFFFF"><div align="center"><center><p><strong><font
      face="Tahoma">

</font></strong></td>
      <td width="389" height="17" colspan="2" bgcolor="#FFFFFF" align="center"><div align="left"><p><center><font
      face="Tahoma" size="2">Please Fill the following.<br>
      </font></center></td>
    </tr>
    <tr align="center">
      <td width="114" height="15" bgcolor="#FFFFFF" align="right"><font face="Tahoma" size="2">Name</font></td>
      <td width="275" height="15" bgcolor="#FFFFFF" align="left"><font face="Tahoma" size="2"><input
      type="text" name="nama" size="25"></font></td>
    </tr>
    <tr align="center">
      <td width="114" height="21" bgcolor="#FFFFFF" align="right"><font face="Tahoma" size="2">Email</font></td>
      <td width="275" height="21" bgcolor="#FFFFFF" align="left"><font face="Tahoma" size="2"><input
      type="text" name="email" size="25"></font></td>
    </tr>
    <tr align="center">
      <td width="114" height="9" bgcolor="#FFFFFF" align="right"><font face="Tahoma" size="2">Homepage
      Title</font></td>
      <td width="275" height="9" bgcolor="#FFFFFF" align="left"><font face="Tahoma" size="2"><input
      type="text" name="hp" size="25"></font></td>
    </tr>
    <tr align="center">
      <td width="114" height="25" bgcolor="#FFFFFF" align="right"><font face="Tahoma" size="2">Homepage
      URL</font></td>
      <td width="275" height="25" bgcolor="#FFFFFF" align="left"><font face="Tahoma" size="2"><input
      type="text" name="urlhp" value="http://" size="25"></font></td>
    </tr>
    <tr align="center">
      <td width="114" height="4" bgcolor="#FFFFFF" align="right"><font face="Tahoma" size="2">Location</font></td>
      <td width="275" height="4" bgcolor="#FFFFFF" align="left"><font face="Tahoma" size="2"><input
      type="text" name="lokasi" size="25"></font></td>
    </tr>
    <tr align="center">
      <td width="114" height="14" bgcolor="#FFFFFF" align="right" valign="top"><font
      face="Tahoma" size="2">Comment</font></td>
      <td width="275" height="14" bgcolor="#FFFFFF" align="left"><font face="Tahoma" size="2"><textarea
      rows="4" name="komen" cols="27" wrap="virtual"></textarea></font></td>
    </tr>
    <tr align="center">
      <td width="114" height="1" bgcolor="#FFFFFF"></td>
      <td width="275" height="1" bgcolor="#FFFFFF" align="left">
      <input type="hidden" name="action" value="preview">
      <input type="reset" value="Reset" name="reset"><input type="submit" value="Submit" name="submit"></td>
    </tr>
  </table>
  </center></div>
</form>






















</center>

</td>

</tr>

</table></center>



|;
&footer;
}









############################################################
# Edit above section if you want to change the appearance  #
############################################################



sub display {
&header;
print "<center><a href=\"guestbook.pl?action=form\"> </a><p>";
open ("data", "$datafail") || &CgiDie ("Cannot open Guestbook Database");
open ("a","count.txt")|| &CgiDie ("Cannot open count file");
$bil = <a>;
$bil++;
close (a);
@data = <data>;
if ($LIFO) {
@data = reverse(@data);
}
close (data);
foreach (@data) {
($num, $nama, $email, $hp, $urlhp, $lokasi, $komen, $ip, $date, $masa) = split ('[|]',$_);
chop ($masa);
$num++;
if ($LIFO) {
$anum = $bil-$num; 
$anum++;
} else {
$anum = $num;
}
$d = ($page + 1) * $viewperpage;
if ($anum > ($d-$viewperpage) && $anum <= $d) {
&PrintRecord;
}
}
print "<center>";
if ($page ne '0'){
print "[<a href=\"guestbook.pl?action=display&page=".($page-1)."\">Previus<\/a>]";
}

if ($d < $bil && $d ne ''){
print "[<a href=\"guestbook.pl?action=display&page=".($page+1)."\">Next<\/a>]";
}
print "</center>";
&footer;
exit;
}


sub preview {
$message = "" ;
$found_err = "" ;

$errmsg = "<p>Please enter your name</p>\n" ;

if ($nama eq "") {
	$message = $message.$errmsg ;
	$found_err = 1 ; }


$errmsg = "<p>Please enter a valid email address</p>\n" ;

if (length($email) && ($email !~ /.+\@.+\..+/)) {
	$message = $message.$errmsg ;
	$found_err = 1 ; }


$errmsg = "<p>Please write something in the comment field</p>\n" ;

if ($komen eq "") {
	$message = $message.$errmsg ;
	$found_err = 1 ; }

if ($found_err) {
	&PrintError; }
&ckomen;
$ip = $ENV{'REMOTE_ADDR'};
($date,$masa) = &get_date;
open ("a","count.txt") || &CgiDie ("Cannot open count file");
$num = <a>;
$num += 2;
close (a);

&PrintRecord;
print qq|
<form method="POST" action="guestbook.pl">
  <input type="hidden" name="nama" value="$nama">
  <input type="hidden" name="email" value="$email">
  <input type="hidden" name="hp" value="$hp">
  <input type="hidden" name="urlhp" value="$urlhp">
  <input type="hidden" name="lokasi" value="$lokasi">
  <input type="hidden" name="komen" value="$komen">
  <input type="hidden" name="ip" value="$ip">
  <input type="hidden" name="date" value="$date">
  <input type="hidden" name="masa" value="$masa">
  <input type="submit" value="Confirm" name="action"></p>
  <p>&nbsp;</p>
</form>
|;
exit;
}

sub save {
open ("a","count.txt")|| &CgiDie ("Cannot open Count file");
$num = <a>;
close (a);
$num++;
$line = join('|', $num, $nama, $email, $hp, $urlhp, $lokasi, $komen, $ip, $date, $masa);
$line .= "\n";
open ("data",">>$datafail")|| &CgiDie ("Cannot open Guestbook Database");
print data "$line";
close (data);
open ("masuk",">count.txt")|| &CgiDie ("Cannot open count file");
print masuk "$num";
close (masuk);

# send mail to admin if new entry

if ($sendtoadmin) {
	$recip = $adminemail ;
	open (MAIL, "|$mail_prog -t") || &CgiDie ("Cannot open MAIL Program");
	print MAIL "To: $recip\n";
	print MAIL "From: $guestbookname\n";
	print MAIL "Subject: You have new entry in you guestbook\n";
	print MAIL "\n\n";
	print MAIL "You have new entry in you guestbook.\n" ;
	print MAIL "\n" ;
	print MAIL "Name : ".$nama."\n" ;
	print MAIL "Email : ".$email."\n" ;
	print MAIL "Homepage Name : ".$hp."\n" ;
	print MAIL "Homepage URL : ".$urlhp."\n" ;
	print MAIL "Location : ".$lokasi."\n" ;
	print MAIL "Komem : ".$komen."\n" ;
	print MAIL "\n\n";
	close (MAIL);
}

if ($sendtosigner && email ne '') {
	$recip = $email ;
	open (MAIL, "|$mail_prog -t") || &CgiDie ("Cannot open MAIL program");
	print MAIL "To: $recip\n";
	print MAIL "From: $guesbookname\n";
	print MAIL "Subject: Thank for signing our guestbook.\n";
	print MAIL "\n\n";
	print MAIL "Thank you for signing our guestbook.\n" ;
	print MAIL "\n\n";
	close (MAIL);
}

&display;
}



# end form checking. Let's do the job

sub ckomen {
$komen =~ s/</&lt;/g;   	
$komen =~ s/>/&gt;/g;		
$komen =~ s/\cM//g;
$komen =~ s/\n\n/<P>/g;		
$komen =~ s/\n/<br>/g;	
# Remove any badword
foreach (@badwords) {
      $komen =~ s/$_/****/gi;
}
}






#get time and date in nice format
sub get_date
{

   local($date,$localtime);
   
   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

   if ($sec < 10) {
      $sec = "0$sec";
   }
   if ($min < 10) {
      $min = "0$min";
   }
   if ($hour < 10) {
      $hour = "0$hour";
   }
   if ($mon < 10) {
      $mon = "0$mon";
   }
   if ($mday < 10) {
      $mday = "0$mday";
   }
   @months = ("January","February","March","April","May","June","July","August","September","October","November","December");
	$year = $year + 1900;
   $localtime = "$hour\:$min\:$sec";
   $date = "$mday "."$months[$mon]"." $year";
   chop($date) if ($date =~ /\n$/);
   chop($local) if ($local =~ /\n$/);

   ($date,$localtime);
   
}




#sent thank you message to you signer



# Print error message
sub PrintError { 
print $message ;
exit 0 ;
return 1 ; 
}
