#!/usr/bin/perl
# BoardMaster v1.82 by Aristotle Vathis (arnica@otenet.gr) 
# All rights reserved. © Beholder.Net (http://www.beholder.net)
# Date : 19-June-2000

require "forums/bm_config_ugly.txt";
require "forums/language.lib";
require "forums/cookie.lib";

#################################

$cname = "${id_cookie}_bmusername";      
&GetCookies($cname);
$username = "$Cookies{$cname}";
	
$cpass  = "${id_cookie}_bmpassword";    
&GetCookies($cpass);
$password = "$Cookies{$cpass}";

#################################

$query = $ENV{'QUERY_STRING'};
	@variables = split(/&/, $query);   
	if ($query =~ "sproxy") {&sproxy;}		

$color = $color1;
$title = "";
$preview = "<INPUT name=previewmessage type=submit value=\"Preview\"> &nbsp; ";

unless ($syntaxchecker eq "OFF") {
$spellchecker = "<INPUT TYPE = \"BUTTON\" VALUE = \"Spell Check\" onclick=\"var f=document.forms[0]; doSpell( '$spelanguage', f.message, '${scripts_url}bm_reply.pl?sproxy', true);\">";
$spellcode = "<script language=\"javascript\" src=\"${threads_url}spch.js\"></script>";
}

$script = "boardmaster.pl";
	if ($moderation eq "YES") {
		$script = "bm_moderate.pl";
	}

	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time+$addsecs);
	$year += 1900; 

	   if (length($hour) eq "1") {
   		$hour = "0$hour";} 
   	if (length($min) eq "1") {
   		$min = "0$min";}

	$daytime = "$hour:$min";
	
#	@Week_Days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
#	@Months = ('January','February','March','April','May','June','July','August','September','October','November','December');
	
#################################
print "Content-type: text/html\n\n";

$path = $ENV{'PATH_INFO'};
$meth = $ENV{'REQUEST_METHOD'};

	$contents{'act'} = $variables[0];
	$contents{'forum'} = $variables[1];	
			$actback = $variables[1];
	
	$contents{'number'} = $variables[2];
	$contents{'reply'} = $variables[3];
	$contents{'depth'} = $variables[4];
	
if ($ENV{'REQUEST_METHOD'} eq "POST")
{
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs)
	{
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

	if ($boardmaster_tags eq "ON") {
		$value =~ s/</[/g;	
		$value =~ s/>/]/g;
		}

	if ($html ne "ON") {
		$value =~ s/<([^>]|\n)*>//g;
		}
	
	
	
	$value =~ s/^\s+//;
	$value =~ s/\s+$//;
		$contents{$name} = $value;
	     
	}

}


###########################################

		$hiddendir = $contents{'forum'};
		
foreach $stegano (@private) {
	if ($stegano eq "$contents{'forum'}") {
		$hiddendir = $contents{'forum'};
		$contents{'forum'} .= "_${id_unique}";
		$private = "yes";
		}
	}

if ($private ne "yes") {
	$tempfile = "$contents{'forum'}/messages/$contents{'number'}\.$ssix";
	$private1 = "${threads_url}$contents{'forum'}/thread_closed.$ssix";
	$private2 = "${threads_url}$tempfile";

	$private_open = "${threads_url}$contents{'forum'}/thread_open.$ssix";
	$private_closed = "${threads_url}$contents{'forum'}/thread_closed.$ssix";
	$private_full = "${threads_url}$contents{'forum'}/thread_full.$ssix";
	}
else {
	if ($username eq "" || $password eq "") {
			&header;
			print "<P>This is a private forum and you are required to logon first before posting/editing any messages.";
			print "Please use the main page links to logon first. Thank you.";
			print "<P>Your Browser must have Cookies enabled.";
			print "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"15; URL=${threads_url}forums.shtml\">
				<P><A HREF=\"${threads_url}forums.shtml\">main page</A>";
			&footer;
			exit;
			}
	
		$contents{'username'} = $username;
		$contents{'password'} = $password;
		
	$private1 = "${scripts_url}bm_display.pl?$hiddendir&open&&";
	$private2 = "${scripts_url}bm_display.pl?$hiddendir&&$contents{'number'}&";

	$private_open = "${scripts_url}bm_display.pl?$hiddendir&open&&";
	$private_closed = "${scripts_url}bm_display.pl?$hiddendir&closed&&";
	$private_full = "${scripts_url}bm_display.pl?$hiddendir&full&&";
	}

############################################

if ($contents{'act'} eq "profile"){ 

$contents{'username'} = $variables[1];

		$contents{'username'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

		$ext= "shtml";
		$user_list = "1";
		$filename = "user_lists/".lc($contents{'username'})."\.$ext";

		$write_secs = (stat($filename))[9];
		$file_time = scalar localtime($write_secs);
		
		open (TEMPFILE, "${threads_dir}$filename") || &user_list;
		close (TEMPFILE);


##########
&fix_name;
##########

$routine = "14";
open (TEMPFILE, "${threads_dir}$phonebook3") || do {&no_open;};
@main= <TEMPFILE>;
close (TEMPFILE);

foreach $line(@main) {

 	@ok = split(/,/, $line);   
	
 	if (lc($ok[2]) eq lc($contents{'username'}))    {   

	if ($us_req eq "1"){ 		 	
		open (MP3, ">>${threads_dir}$dir_passwords/contact_requests.txt");
		print MP3 "$user_requesting -> $contents{'username'}\n";
		close(MP3); 		 	
		}
 		 		
		&header;
		&profile;
		&footer;
		exit;
		}
	}

print "<BR>Username \"$contents{'username'}\" $rep18";
print "<BR>\"$id_username/$contents{'username'}.txt\" $rep18";

exit;
}

####################################

if ($contents{'act'} ne "edit" && $contents{'act'} ne "new"){ 
	$contents{'depth'}++;
}

$depth_back = ($contents{'depth'} - 1);

if ($moderation eq "YES") {
	$moded = "$rep1";
	$preview = "";
	}

if ($authentication eq "ON") {
	$posters = "$rep2 - <FONT size=1><A HREF=\"${threads_url}forum-register.$ssix\">$rep3 \?</A></FONT> ";
	$optional = "<FONT SIZE=2>*required</FONT> - <FONT size=1><A HREF=\"bm_reply.pl?forgot\">$rep5 \?</A></FONT>";
	}

if ($authentication eq "BOTH") {
	$posters = "$rep4 - <FONT size=1><A HREF=\"${threads_url}forum-register.$ssix\">$rep3 \?</A></FONT> ";
	$optional = "<FONT SIZE=2>\*optional</FONT> - <FONT size=1><A HREF=\"bm_reply.pl?forgot\">$rep5 \?</A></FONT>";
	}

$show_password = "<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Your Password:</B></FONT></TD>
          <TD colspan=2 vAlign=top><INPUT maxLength=50 name=password value=\"$password\" size=13 type=password>&nbsp;&nbsp;$optional<FONT size=1></TD></TR>";

if ($contents{'act'} eq "new") {
	$lock_replies = "<INPUT name=lockreplies type=checkbox value=yes> $rep6";  	}

if ($uploading eq "YES") {
	$upload_link = "<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <B>Upload:</B> want to <A HREF=\"${scripts_url}bm_register.pl?upform\" target=_new>upload</A> a file ?";       
	}

if ($emailnotify eq "YES") {
	if ($contents{'act'} eq "new" || $contents{'act'} eq "reply" ) {
		$send_email = "<INPUT name=taxydromio type=checkbox value=yes> $rep7 <BR>";       
		}
	}

if ($smilies eq "ON") {
	$emoticons =  "<INPUT name=emoticons type=checkbox value=yes> <B>Emoticons:</B> disable 
	<A HREF=\"${scripts_url}bm_register.pl?read_dir&emoticons\" target=_new>smilies</A>
	in this post.<BR>";       
}

$show_signature = "<INPUT name=sign type=checkbox value=yes checked> $rep8<BR>";

if ($authentication eq "OFF") {
	$posters = "$rep9";
	$optional = "";
	$show_password = "";
	$show_signature = "";
	}

############################################

if ($contents{'act'} eq "authenticate"){ 
	&authenticate;
	$contents{'act'} = "profile"; 
	
	$user_requesting = $contents{'username'};
	$us_req = "1";

###
$id_username = lc(substr($actback, 0, 1));
&fix_name;
##########

open (BOOK, "${threads_dir}$phonebook3") || do {&no_open;};
@sorted = <BOOK>;
close(BOOK);
foreach $pair (@sorted){
 @ok = split(/,/, $pair);   
 if (lc($ok[2]) eq lc($actback)) {
	last; 	
 	}
 }
###

	&header;
	&profile;
	&footer;
	exit;
	}

############################################

if ($contents{'act'} eq "forgot"){ 
	&present_forgot_form;
	}


############################################

if ($contents{'act'} ne "new"){ 

$tempfile = "$contents{'forum'}/messages/$contents{'number'}\.$ssix";

$routine = "12";
open (TEMPFILE, "${threads_dir}$tempfile") || do {&no_open;};
@main= <TEMPFILE>;
close (TEMPFILE);

foreach $line(@main) {

	unless ($line =~ "<!--=="){
		next;
		}

##################################
	
if ($contents{'act'} eq "edit") {	
	
	if ($line =~ "==text==begin==" && $catch eq "1"){
		@ok = split(/==-->/, $line);   
		$replied_text = $ok[1];
			
		$check = "1";
		}
	
	if ($line =~ "==$depth_back==" && $check ne "1"){
		$replied_text = "";
		$catch = "1";
			
		}


$show_password = "<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Your Password:</B></FONT></TD>
          <TD colspan=2 vAlign=top><INPUT maxLength=30 name=password size=13 value=\"$password\" type=password>&nbsp;&nbsp;$optional<FONT size=1></TD></TR>";
				
}

##################################
		
	if ($line =~ "==$contents{'number'}==$contents{'reply'}==start==") {
		@more = split(/==/, $line);   	
		$title = $more[4];
		
			$icon_normal = $more[10];
			@normal_image = split(/icons\//, $more[10]);   
			$normal_image[1] =~ s/.gif//i;
			
			if ($icon_normal =~ "http") {
				$selected_icon = "<option selected VALUE=\"$icon_normal\">$normal_image[1]</option>\n";			
				}
			else {
				$selected_icon = "<option selected VALUE=\"${threads_url}$icon_normal\">$normal_image[1]</option>\n";			
				}
			
			$posticon = "$icon_normal";
				
		if ($authentication eq "ON") {
			$titleby =  "by <A HREF=\"${scripts_url}bm_reply.pl?profile&$more[5]\">$more[5]</A>";
			}
		else {
			$titleby =  "by $more[5]";
			}
		
		if ($contents{'act'} eq "edit") {	
			$username = $more[5];
			}
		
#		if ($more[11] eq "ok"){
#			$mode = "1";
#			}
		
		@pday = split(/\./, $more[7]); 
		@ptime = split(/\./, $more[8]); 
		
#		@Week_Days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
#		@Months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
		$posted = "$more[9] $pday[0] $Months[$pday[1]] $ptime[0]:$ptime[1]";
						
		$icon = $more[10];
		
		$text = "1";
		
		$check = "1";
		$catch = "";
		
		}   
	
#	if ($line =~ "bgcolor=\#"&& $text eq "1"){
#		@ok = split(/\#/, $line);   
#		@piece = split(/\>/, $ok[1]);   
#		$color = $piece[0];
#		}

	if ($line =~ "==quote==" && $text eq "1" && $contents{'act'} eq "edit"){
		@qook = split(/==-->/, $line);   
		$quote = $qook[1];
		$check_quote++;
		}

	if ($line =~ "==replies==locked==" && $contents{'act'} eq "reply"){
		print "$rep10";
		exit;	
		}			

	if ($line =~ "==replies==locked==" && $contents{'act'} eq "edit"){
		$lockselected = "checked";
		}	

	 if ($line =~ "==icon=="){
		 @track = split(/==/, $line);   	
		 
		 unless ($track[2] =~ "http") {
		 	$track[2] = "${threads_url}$track[2]";
		 	}
		 
		 $originalicon = "\n <INPUT name=\"originalicon\" type=hidden value=\"$track[2]\"> ";	
		

		#	@id_image = split(/\//, $track[2]);   
		#	$id_image[2] =~ s/.gif//i;
		#$selected_icon = "<option selected VALUE=\"$track[2]\">$id_image[2]</option>\n";
			
		}		
			
	if ($line =~ "==track_closed=="){
		@track = split(/==/, $line);   	
		$track_closed = "\n <INPUT name=\"info_closed\" type=hidden value=\"$track[2]\"> ";		
		}		
	if ($line =~ "==track_open=="){
		@track= split(/==/, $line);   	
		$track_open = "\n <INPUT name=\"info_open\" type=hidden value=\"$track[2]\"> ";		
		}		
	if ($line =~ "==track_full=="){
		@track = split(/==/, $line);   	
		$track_full = "\n <INPUT name=\"info_full\" type=hidden value=\"$track[2]\"> ";		
		}		
	
	if ($line =~ "==track_frame=="){
		@track = split(/==/, $line);   	
		$track_frame = "\n <INPUT name=\"info_frame\" type=hidden value=\"$track[2]\"> ";		
		}		
					
	if ($line =~ "==text==begin==" && $text eq "1" && $contents{'act'} ne "new"){
		@ok = split(/==-->/, $line);   
		$message = $ok[1];
		$text= "";
		}
			
	}

}


### invert tags
if ($contents{'act'} eq "edit"){ 
	&convert;
	}

$message =~ s/<p>/\n\n/g;
$message =~ s/<br>/\n/g;
$message =~ s/<([^>]|\n)*>//g;

###

if ($contents{'act'} eq "new"){ 
	$user_info = "<INPUT maxLength=25 name=username size=25 value=\"$username\">";
	}

if ($contents{'act'} eq "reply"){ 
	$user_info = "<INPUT maxLength=25 name=username size=25 value=\"$username\">";

	@count_re = split(/\(/, $title);   
	$counted = substr($count_re[1], 0, 1);

	$count = ($title =~ s/Re\(.\)\://gi);
		if ($count eq "") { $count = "1";}
	$title =~ s/Re\(.\)\://g;
	$count = $count + $counted;
	
	$re = "Re($count):";
	}


if ($contents{'act'} eq "edit"){ 
	$user_info = "<INPUT name=username type=hidden value=\"$username\">$username";
	}

if ($contents{'act'} eq "reply"){
		$hidden = "<INPUT type=hidden name=notify value=\"$more[5]\">\n";
		$quote = $message;
		$message = "";
	}
	
if ($quote ne "" && $contents{'act'} ne "reply"){
		$selected = "<OPTION value=yes>Yes";
	}
	
if ($contents{'act'} ne "new"){ 
	$quote =~ s/<([^>]|\n)*>//g;
	$blockquote = "
	<TABLE border=0 cellPadding=0 cellSpacing=0 width=\"95%\"><TR><TD bgColor=#000000>
	
	<TABLE border=0 cellPadding=4 cellSpacing=1 width=\"100%\"><TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Include quote ?</B><P>
          		<SELECT NAME=quote>
          		$selected
		<OPTION value=no>No
		<OPTION value=yes>Yes
		</SELECT></FONT></TD><TD><CENTER><TEXTAREA cols=65 name=\"quote_message\" rows=5 wrap=VIRTUAL>$quote</TEXTAREA> 
          		<BR><FONT size=1>$rep11</FONT> </TD></TR></TABLE>
          	</TD></TR></TABLE>";
	}

if ($contents{'act'} eq "edit" && $quote eq ""){
	$quote = $replied_text;
	$quote =~ s/<p>/\n\n/g;
	$quote =~ s/<br>/\n/g;
	$quote =~ s/<([^>]|\n)*>//g;
	$blockquote = "
	<TABLE border=0 cellPadding=0 cellSpacing=0 width=\"95%\"><TBODY><TR><TD bgColor=#000000>
	<TABLE border=0 cellPadding=4 cellSpacing=1 width=\"100%\"><TR bgColor=$color2>
          		<TD vAlign=top>
          		<FONT size=2><B>Include quote ?:</B><P>
          		<SELECT NAME=quote>
          		$selected
		<OPTION value=no>No
		<OPTION value=yes>Yes
		</SELECT></FONT> 
          		</TD><TD><TEXTAREA cols=65 name=\"quote_message\" rows=5 wrap=VIRTUAL>$quote</TEXTAREA> 
          		<BR><FONT size=1>$rep11</FONT> 
          		</TD></TR></TABLE>          	</TD></TR></TABLE>	
          		<P>";
	}

#if ($contents{'act'} eq "edit" && $mode ne "1"){
#	print "<P>Sorry , you can not edit/delete this message";
#	exit;
#	}
	

if ($contents{'act'} eq "edit"){
	$deletepost = "<TR bgColor=$color1><TD colSpan=3><FONT size=1>
	<INPUT name=deletepost type=checkbox value=yes>$rep12<BR>
	<INPUT name=deletesubthread type=checkbox value=yes>$rep13</FONT></TD></TR>";
	}

if ($contents{'act'} eq "edit" && $contents{'reply'} eq "0" && $contents{'depth'} eq "0") {
	$lock_replies = "<INPUT name=lockreplies type=checkbox value=yes $lockselected> $rep6";    	}

###############################

opendir(DIR, "${threads_dir}graphics/icons/");
@images = grep(/\.gif$/,readdir(DIR));
closedir(DIR);

foreach $icon (@images) {
	
	$nogif = $icon;
	$nogif =~ s/.gif//i;
	
	$opicon = "<option VALUE=\"${threads_url}graphics/icons/$icon\">$nogif</option>\n";
	push (@icons , $opicon);
	}

if ($posticon eq "" || $contents{'act'} eq "reply") {
	$selected_icon = "<option selected VALUE=\"${threads_url}graphics/icons/posticon.gif\">posticon</option>\n";	
	$posticon = "${threads_url}graphics/icons/posticon.gif";
	}

if ($icon_mode eq "ON") {
	$icon_selection = "<script language=\"javascript\">
function showimage()
\{
if (!document.images)
return
document.images.icons.src=
document.REPLIER.icon.options[document.REPLIER.icon.selectedIndex].value
\}
</script>

<font size=1>Icon selection:<BR></FONT>
<font size=2>
<select name=\"icon\" size=\"3\" onChange=\"showimage()\">
$selected_icon
@icons
</select>
<a href=\"javascript:linkrotate(document.REPLIER.icon.selectedIndex)\" onMouseover=\"window.status='';return true\">
<img src=\"$posticon\" name=\"icons\" width=\"15\" height=\"15\" border=0 hspace=15></a>
	</font>    

<BR><FONT SIZE=1>or view all icons <A HREF=\"${scripts_url}bm_register.pl?read_dir&icons\" target=_new>here</A>.</FONT>";   
	   
            }

#####
# v1.6 icon incompatabilities

if ($contents{'act'} ne "new" && $originalicon eq "") {
	$originalicon = "\n <INPUT name=\"originalicon\" type=hidden value=\"${threads_url}graphics/icons/posticon.gif\"> ";	
	}

#####

print <<"HTML";

<HTML><HEAD><TITLE>${site_name} - $copyright</TITLE>
$spellcode
</HEAD>
<BODY background="$bg_img" leftmargin=0 topmargin=0 bgcolor="$bg1" style="$font_family; $font_color;" vlink="$vlink" link="$ulink" text="$text_color"><FONT size=2></FONT>

<TABLE cellspacing="0" cellpadding="0" border=0 width="100%">
  <TBODY>
  <TR>
    <TD>
<IMG SRC="${threads_url}graphics/$logo" WIDTH="$logo_width" HEIGHT="$logo_height"><P>
<FONT SIZE=2><P><A HREF="${scripts_url}bm_reply.pl?new&$hiddendir">$post_new</A>
 <A HREF="$private_closed">$icon_closed</A>
 <A HREF="$private_open">$icon_open</A>
 <A HREF="$private_full">$icon_full</A>
 <A HREF="${threads_url}forums.$ssix">$all_forums</A>
<A href="${threads_url}faq.$ssix">$icon_faq</A> 
<P></FONT>

      </TD>
</TBODY></TABLE>

<FORM action=$script method=post name=REPLIER>
<CENTER>

<TABLE border=0 cellPadding=0 cellSpacing=0 width="95%">
  <TBODY>
  
  <TR>
    <TD bgColor=#000000>
      <TABLE border=0 cellPadding=4 cellSpacing=1 width="100%">
        <TBODY>
        <TR bgColor=$color1><TD COLSPAN=3>
                <FONT SIZE=2>$posters </FONT>
        </TD></TR>
        
        <TR bgColor=$color2>
          <TD vAlign=top><FONT size=2>Topic </FONT></TD>
          <TD vAlign=top>&nbsp;<FONT size=2><A HREF="$private2">$title</A> $titleby</FONT></TD>
          
          <TD ROWSPAN=3 align=middle>
          <TABLE border=0 cellPadding=3 cellSpacing=0>
                    <TBODY><TR><TD bgColor=$color2><CENTER>
                        <TABLE border=1 cellPadding=3 cellSpacing=0 width=65>
                          <TBODY><TR>
                            <TD align=middle bgColor=#666688><I>
                            <FONT color=#bbbbdd size=-1>$daytime &nbsp;</FONT></I></TD></TR>
                            </TBODY></TABLE></CENTER></TD></TR>
                    <TR><TD align=middle bgColor=$color2><TABLE border=1 cellPadding=3 cellSpacing=0 width=65>
                          <TBODY><TR>
                            <TD bgColor=#ffffff><CENTER>
                            <FONT color=#000000 size=-4>$Week_Days[$wday]</FONT><BR>
                            <FONT color=#000000 size=4>$mday</FONT><BR>
                            <FONT color=#000000 size=-4>$Months[$mon]</FONT></CENTER></TD></TR></TBODY></TABLE>
                        <CENTER></CENTER></TD></TR></TBODY></TABLE>
          </TD></TR>
        <TR bgColor=$color2>
          <TD vAlign=top><FONT size=2>Forum</FONT></TD>
          <TD vAlign=top><FONT size=2><A HREF="$private1">$hiddendir</A> $moded </FONT>
          </TD></TR>
        <TR bgColor=$color1>
          <TD vAlign=top><FONT size=2><B>Your UserName:</B></FONT></TD>
          <TD colspan=1 vAlign=top>$user_info
          
          </TD></TR>
 
 $show_password
          
<TR bgColor=$color1>
            <TD vAlign=top><FONT size=2><B>Message Title:</B></FONT></TD>
          <TD colspan=2 vAlign=top><INPUT maxLength=45 name=title size=45 value="$re$title"> </TD></TR>
       
        <TR bgColor=$color1>
          <TD vAlign=top><FONT size=2><B>Your message:</B></FONT> 
            <BR><FONT color=#000080 size=1>
            <BR>HTML code: $html
            <BR><A HREF=\"${scripts_url}bm_register.pl?boardmaster_tags&\" target=_new>BoardMaster tags</A>: $boardmaster_tags
           <P>
           
$icon_selection        

            
            </FONT></TD>
            
          <TD colspan=2><TEXTAREA cols=65 name=message rows=10 wrap=VIRTUAL>$message</TEXTAREA> 
          
          </TD></TR>
          
          $deletepost

<TR bgColor=$color2><TD vAlign=top>
<A HREF="http://www.beholder.net" target=_new><IMG SRC=${threads_url}graphics/beholder_logo.gif border=0 width=88 height=31></A>
<BR><FONT size=1>powered by <A HREF="http://www.beholder.net" target=_new>BoardMaster</A> v$version</FONT> 
</TD>
<TD colspan=2 vAlign=top><FONT size=1>            
$send_email 
$show_signature
$emoticons 
$lock_replies
$upload_link
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER>

<TR><TD bgColor=$color2 colspan=3>         
<INPUT name=act type=hidden value=$contents{'act'} > 
<INPUT name=number type=hidden value=$contents{'number'}> 
<INPUT name=reply type=hidden value=$contents{'reply'}> 
<INPUT name=forum type=hidden value=$hiddendir> 
<INPUT name=color type=hidden value="$color"> 
<INPUT name=depth type=hidden value=$contents{'depth'}> 

<INPUT name=posted type=hidden value="$posted"> 

<INPUT name=day type=hidden value="$more[7]"> 
<INPUT name=time type=hidden value="$more[8]"> 
<INPUT name=weekday type=hidden value="$more[9]"> 
$hidden
$originalicon

$track_closed
$track_open
$track_full 
$track_frame


<CENTER><FONT size=2>
<BR><INPUT name=SUBMIT type=submit value="Post"> &nbsp;
$preview
$spellchecker
<INPUT name=RESET type=reset value="Undo"> 
</TD></TR></TABLE><P>
$blockquote
</TD></TR></table><P>
</td></TR></table>
         
</FORM>
       
</BODY></HTML>



HTML

##########################
	
exit;



###################
# The top portion of the web pages. Edit as desired.
sub header {
print <<"HTML";
<HTML><HEAD><TITLE> ${site_name} </TITLE></HEAD>
<BODY background="$bg_img" bgcolor="$bg1" style="$font_family; $font_color;" vlink="$vlink" link="$ulink" text="$text_color">
<TABLE WIDTH=750 BORDER=0><TR><TD width=50></TD><TD WIDTH=700>
HTML
}


###################
# The bottom portion of the web pages. Edit as desired.
sub footer {
print <<"HTML";
</TD></TR></TABLE>
</BODY>
</HTML> 
HTML
}


###################
sub no_open {

$routine =~ s/${id_unique}/\$id_unique/gi;
&header;
print <<"HTML";
<H1> Error! Could not open the database!</H1>
<P>routine: "$routine" 
<P>contents{'act'}  : "$contents{'act'}"

<P><IMG SRC="${threads_url}graphics/mes-error.jpg" ALIGN=RIGHT>
HTML
&footer;
exit;
}

###################
# The top portion of the web pages. Edit as desired.
# insert new data: 	posts,last post,Beholder,password,title,email,icq,syndesi,registration date,signature,whatever

sub profile {

&hide_email_icq;

if ($us_req eq "1") {
	$contents{'username'} = $actback;
	}

if ($faces eq "ON") {
	
	if ($ok[10] eq "whatever" || $ok[10] eq "") {
		$ok[10] = "${threads_url}graphics/faces/no_portait.gif";
		}
	
	$show_faces = "<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Face:</B></FONT></TD><TD vAlign=top> 	          
	<IMG SRC=\"$ok[10]\" border=0></FONT></FONT></TD></TR>";
}
	
print <<"HTML";

<TABLE width=100%><TR><TD><IMG SRC=\"${threads_url}graphics/$logo\" ALIGN=left VALIGN=TOP WIDTH="$logo_width" HEIGHT="$logo_height"><P><BR></TD></TR><TR><TD><FONT SIZE=2><P> <A HREF=\"${threads_url}forums.$ssix\">$all_forums</A> <A HREF=\"${threads_url}forum-search.$ssix\">$search</A> <A href=\"${threads_url}faq.$ssix\">$icon_faq</A> <P></TD></TR></TABLE>

<TABLE border=0 cellPadding=0 cellSpacing=0 width="95%">
  <TBODY>
  
  <TR>
    <TD bgColor=#000000>
      <P><TABLE border=0 cellPadding=4 cellSpacing=1 width="100%">
        <TBODY>
      <TR bgColor=$color1><TD vAlign=top COLSPAN=2><H2>User's profile</H2>	</TD></TR>          
<TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Username:</B></FONT></TD><TD  WIDTH=100% vAlign=top> 	          
	$contents{'username'}</FONT></FONT></TD></TR>
<TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Title:</B></FONT></TD><TD vAlign=top> 	          
	$ok[4] &nbsp;</FONT></FONT></TD></TR>	

$hide_contact

$user_data
	
<TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Total posts:</B></FONT></TD><TD vAlign=top> 	          
	$ok[0]</FONT></FONT></TD></TR>	
<TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Last posted:</B></FONT></TD><TD vAlign=top> 	          
	$ok[1]</FONT></FONT></TD></TR>		
<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Connection:</B></FONT></TD><TD vAlign=top> 	          
	$ok[7]</FONT></FONT></TD></TR>	

$show_faces

<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Signature:</B></FONT></TD><TD vAlign=top> 	          
	$ok[9] &nbsp;</FONT></FONT></TD></TR>
<TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Registration date:</B></FONT></TD><TD vAlign=top> 	          
	$ok[8]</FONT></FONT></TD></TR>				

<TR bgColor=$color1><TD colspan=2>
<FORM action="bm_register.pl?editprofile&$contents{'forum'}" method=post  name=REPLIER><FONT SIZE=2>
<INPUT name="username" type=hidden value="$contents{'username'}">
<INPUT name="act" type=hidden value="editprofile">
$rep20: </FONT><INPUT maxLength=45 name=password  type=password size=15 value="$password"><INPUT name=SUBMIT type=submit value="Edit profile"> </FORM>
</TD></TR></TABLE>

</TD></TR></TABLE>

<P><BR><P><A HREF=\"javascript:history.go(-1)\"><IMG SRC=\"${threads_url}graphics/back.gif\" BORDER=\"0\"></A><FONT SIZE=2>previous page</FONT>

HTML
}

###################################
sub hide_email_icq {

if ($user_list eq "1") {	
	$user_data = "<TR  bgColor=$color1><TD vAlign=top><FONT size=2><B>Special:</B></FONT></TD><TD vAlign=top> 	          
		<A HREF=\"${threads_url}$filename\">user's list data</A> <IMG SRC=${threads_url}graphics/special.gif> <FONT SIZE=2>(last updated: $file_time)</FONT></FONT></TD></TR>";
	}	

if (length($ok[6]) > 4) {
	$icqpager = " $ok[6] <img src=\"http://wwp.icq.com/scripts/online.dll?icq=$ok[6]&img=1\" border=0>";
	}

if ($ok[5] =~ /.*\@.*\..*/) {
	$mailto = "<A HREF=\"mailto:$ok[5]\">$ok[5]</A>";
	}
	
if ($user_authenticated ne "1" && $protect_info ne "NO") {
	$hide_contact = "<TR  bgColor=$color1><TD vAlign=top><FONT size=2><B>Email:</B></FONT></TD><TD align=right  ROWSPAN=2 vAlign=top> 	          
		<FORM action=\"bm_reply.pl?profile&$ok[2]\" method=POST  name=REPLIER><FONT SIZE=2>
				
		<BR>Your username: <INPUT name=\"username\" type=text value=\"\">
		<BR>Your password: <INPUT name=\"password\" type=password  value=\"\">
		<INPUT name=\"act\" type=hidden value=\"authenticate\">
		
		<BR>Enter your password & username to view user's email & icq: <INPUT name=SUBMIT type=submit value=\"View profile\"> </FORM>
		</FONT></FONT></TD></TR><TR bgColor=$color1><TD vAlign=top><FONT size=2><B>ICQ:</B></FONT></TD></FONT></FONT></TD></TR>";
		}
	
else {
	$hide_contact = "<TR  bgColor=$color1><TD vAlign=top><FONT size=2><B>Email:</B></FONT></TD><TD vAlign=top> 	          
		$mailto &nbsp;</FONT></FONT></TD></TR><TR bgColor=$color1><TD vAlign=top><FONT size=2><B>ICQ:</B></FONT></TD><TD vAlign=top> 	          
		$icqpager &nbsp;</FONT></FONT></TD></TR>";
		}

}

############################################
# Authenticate User

sub authenticate {

	$name_backup = $contents{'username'};
	$contents{'username'} =~ s/^\s+//;
	$contents{'username'} =~ s/\s+$//;

$error = $phonebook3;
$routine = 29;


##########
&fix_name;
##########

open (BOOK, "${threads_dir}$phonebook3") || do {&no_open;};

@sorted = <BOOK>;
close(BOOK);
	
foreach $pair (@sorted){

 @ok = split(/,/, $pair);   

 if (lc($ok[2]) eq lc($contents{'username'}) && lc($ok[3]) eq lc($contents{'password'}))    {   
 	 $user_allowed_forums = $ok[12];
	 $contents{'username'} = $name_backup;
	 $usertitle = $ok[4];
	 $user_authenticated = 1;
	 		if ($contents{'sign'} eq "yes") {
	 			$signature = $ok[9];
	 			$signature = " \n		<P><!-- ==sign==--> $signature ";
	 			}
	 last; }

elsif (lc($ok[2]) eq lc($contents{'username'}) && lc($ok[3]) ne lc($contents{'password'}))    {   
 	 print "<H1>Error !<BR></H1>"; 
 	 print "Username: \"<font color=\"#ff9933\"><b>$contents{'username'}</B></font>\" $rep14</H1>\n"; 
	 print "$rep15\n"; 
 	 print "</BODY></HTML>"; 
	 print "<P><IMG SRC=\"${threads_url}graphics/mes-error\.jpg\" ALIGN=RIGHT>";	
	 exit;
 	}

}

if ($user_authenticated != 1) {

	&header;
 	 print "<H1>Error !<BR></H1>"; 
 	 print "Username: \"<font color=\"#ff9933\"><b>$contents{'username'}</B></font>\" $rep18</H1>\n"; 
 	 print "<BR>$rep16\n"; 
	 print "<P><IMG SRC=\"${threads_url}graphics/mes-error\.jpg\" ALIGN=RIGHT>"; 
 	 
	&footer;
	 exit;
			}


}



#######################
sub user_list {
	$user_list = "0";
	$user_data = "<TR  bgColor=$color1><TD vAlign=top><FONT size=2><B>Special:</B></FONT></TD><TD vAlign=top> 	          
		no data stored</FONT></FONT></TD></TR>";
	}
	
	
#######################

sub present_forgot_form {

&header;
	
print <<"HTML";

<TABLE width=100%><TR><TD><IMG SRC=\"${threads_url}graphics/$logo\" ALIGN=left VALIGN=TOP WIDTH="$logo_width" HEIGHT="$logo_height"><P><BR></TD></TR><TR><TD><FONT SIZE=2><P> <A HREF=\"${threads_url}forums.$ssix\">$all_forums</A> <A HREF=\"${threads_url}forum-search.$ssix\">$search</A> <A href=\"${threads_url}faq.$ssix\">$icon_faq</A> <P></TD></TR></TABLE>

<TABLE border=0 cellPadding=0 cellSpacing=0 width="95%">
  <TBODY>
  
  <TR>
    <TD bgColor=$bg1>

<FONT SIZE=2>
<P>$rep17

<FORM action=bm_register.pl method=post name=FORGOT>
<INPUT type=hidden name="forgot" value="yes">
<INPUT type=text name=forgot_identify value="">

<INPUT type=submit value=submit>
</FORM>

</TD></TR></TABLE>

HTML
	
&footer;
exit;	
}	


################################

sub fix_name {
	
$contents{'username'} =~ s/_/ /g;	
$nospaces = lc($contents{'username'});	
$nospaces =~ s/ /_/g;	
$nospaces =~ s/\%20/_/g;

$id_username = lc(substr($contents{'username'}, 0, 1));
unless ("abcdefghijklmnopqrstuvwxyz" =~ $id_username) { $id_username = "0";}

$phonebook3 = "$dir_passwords/$id_username/$nospaces.txt";

}	

################################

sub convert {
	
$message =~ s/(<A HREF=")(http|https|ftp)(:\/\/)(\S+)(" TARGET=_blank>)(.+?)(<\/A>)/\[URL=$2:\/\/$4\]$6\[\/URL\]/isg;
$message =~ s/(<A HREF="mailto:)(\S+)(">)(\S+)(<\/A>)/\[EMAIL\]$2\[\/EMAIL\]/isg;
$message =~ s/(<BLOCKQUOTE><font size="1" face=".+?">quote:<\/font><HR>)(.+?)(<HR><\/BLOCKQUOTE>)/\[QUOTE\]$2\[\/QUOTE\]/isg;
$message =~ s/(<BLOCKQUOTE><font size="1" face=".+?">code:<\/font><HR><pre>)(.+?)(<\/pre><HR><\/BLOCKQUOTE>)/\[code\]$2\[\/code\]/isg;
$message =~ s/(<IMG SRC="${threads_url}graphics\/emoticons\/)(\S+)(.gif">)/:$2:/isg;
$message =~ s/(<IMG SRC=")(\S+)(">)/\[IMG\]$2\[\/IMG\]/isg;
$message =~ s/(<FONT SIZE=")(\S+)(">)(\S+)(<\/FONT>)/\[size=$2\]$4\[\/size\]/isg;
$message =~ s/(<FONT COLOR=")(\S+)(">)(\S+)(<\/FONT>)/\[color=$2\]$4\[\/color\]/isg;
$message =~ s/(<i>)(.+?)(<\/i>)/\[i\]$2\[\/i\]/isg;
$message =~ s/(<b>)(.+?)(<\/b>)/\[b\]$2\[\/b\]/isg;
}	

################################

sub sproxy {


print "Content-type: text/html; charset=UTF-8\n\n<html>";

$SPROXY_VER = "SPROXY.pl(Perl) v.1.12 (c) SpellChecker.Net 2000";

%data = &ParseInput();

$data{"text"} =~ s/\"/&quot;/g;
$data{"text"} =~ s/\r/&#13;/g;
$data{"text"} =~ s/\n/&#10;/g;
$data{"text"} =~ s/\t/&#9;/g;
        
$template = "<html>
<head>

<script>

var s = '$SPROXY_VER<br><br><b>SCRIPT_FILENAME:</b> $ENV{SCRIPT_FILENAME}';
var frmslen = parent.frames.length;

function doload() {
	if (!parent.opener.document) {
		parent.close();
		return;
	}
	if (frmslen != 0) {
		var f_src = document.forms[0];
		var ctrl = eval(
			'parent.opener.' + 
			f_src.txt_ctrl.value);
		if (ctrl.value)
			ctrl.value = f_src.msg_body.value;
		else
			if (ctrl.innerHTML)
        		ctrl.innerHTML = f_src.msg_body.value;
		document.forms[1].submit();
		parent.close();
	}
}

</script>

</head>
<body bgcolor=white onload=\"doload();\">
<script>if (frmslen == 0) document.write(s);</script>
<center>
<form>
<input type=hidden name=msg_body value=\"<#text#>\">
<input type=hidden name=txt_ctrl value=\"<#txt_ctrl#>\">
</form>
<form method=post action=\"<#word#>\">
<input type=hidden name=cmd value=\"eos\">
<input type=hidden name=customerid value=\"<#customerid#>\">
<input type=hidden name=sessionid  value=\"<#sessionid#>\">
</form>
</body></html>";

$template =~ s/<#(\w+)#>/$data{$1}/g;

print $template;

sub ParseInput() {

    (*fval) = @_ if @_ ;

	if ($ENV{'REQUEST_METHOD'} eq 'POST') {
		read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
	}
	else {
		$buf=$ENV{'QUERY_STRING'};
	}
	if ($buf eq "") {
            return 0;
		}
	else {
 		@fval=split(/&/,$buf);
		foreach $i (0 .. $#fval){
			($name,$val)=split (/=/,$fval[$i],2);
			$val=~tr/+/ /;
			$val=~ s/%(..)/pack("c",hex($1))/ge;
			$val=~ s/\\//g;
			$val=~ s/\`//g;
			$name=~tr/+/ /;
			$name=~ s/%(..)/pack("c",hex($1))/ge;
			$name=~ s/\\//g;
			$name=~ s/\`//g;

			if (!defined($field{$name})) {
				$field{$name}=$val;
			}
			else {
				$field{$name} .= ",$val";
			}
	   }
	}
return %field;
}


exit;
}	