#!/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}";
	
if ($mpiskoto eq "YES") {
$cpass  = "${id_cookie}_bmpassword";    
&GetCookies($cpass);
$password = "$Cookies{$cpass}";}

#################################

$query = $ENV{'QUERY_STRING'};
$path = $ENV{'PATH_INFO'};
$meth = $ENV{'REQUEST_METHOD'};
$ip = $ENV{'REMOTE_ADDR'};
$isp = $ENV{'REMOTE_HOST'};
$host = $ENV{'HTTP_REFERER'};

########
	
if ($query =~ "read_dir") {
	&read_dir;
	}

if ($query =~ "boardmaster_tags") {
	&boardmaster_tags;
	exit;
	}

if ($query =~ "upload") {
	print "Content-type: text/html\n";
	&upload;
	}

if ($query =~ "upform") {
	print "Content-type: text/html\n";
	&upload_request;
	}

#################################

if ($authentication eq "OFF") {

	print "Content-type: text/html\n\n";
	print "Authentication is \"OFF\" - you do not need to register to post messages";
	exit;
	}

	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

	$year += 1900; 
	$day = "$mday.$mon";
	$daytime = "$hour.$min";
	$posted = "$Week_Days[$wday] $mday $Months[$mon] $year $hour:$min";

	$logtime = "$hour:$min:$sec - $mday-$mon-$year";

########


# Nothing below this point should need editing.
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;
		
		$value =~ tr/,/ /;
	                $value =~ s/Ž//g;	
	                $value =~ s/Š//g;
	                     
	                     $value =~ tr/==//;
	                     $value =~ s/,/ /g;
	                     	
		$value =~ s/<([^>]|\n)*>//g;
			
	$value =~ s/^\s+//;
	$value =~ s/\s+$//;
		$contents{$name} = $value;
	     
	}

}

	$contents{'icq'} =~ s/<//g;
	$contents{'icq'} =~ s/>//g;
	$contents{'email'} =~ s/<//g;
	$contents{'email'} =~ s/>//g;
	$contents{'connection'} =~ s/>//g;
	$contents{'connection'} =~ s/<//g;
	
	$contents{'signature'} =~ s/<([^>]|\n)*>//g;
	$contents{'signature'} =~ s/</[/g;
	$contents{'signature'} =~ s/>/]/g;
	$contents{'signature'} =~ s/\n\n/<P>/gs;
	$contents{'signature'} =~ s/\n/<BR>/gs;
	$contents{'signature'} =~ y/\013//d;
	$contents{'signature'} =~ s/\r//g;
	
##########
&fix_name;
##########

if ($contents{'forgot'} eq "yes") {
	
&more_characters unless (length($contents{'forgot_identify'}) >2);	

############
$contents{'forgot_identify'} = lc($contents{'forgot_identify'});
$contents{'forgot_identify'} =~ s/_/ /g;	
$nospaces = $contents{'forgot_identify'};	
$nospaces =~ s/ /_/g;	
$nospaces =~ s/\%20/_/g;

$id_username = lc(substr($contents{'forgot_identify'}, 0, 1));
unless ("abcdefghijklmnopqrstuvwxyz" =~ $id_username) { $id_username = "0";}

$phonebook3 = "$dir_passwords/$id_username/$nospaces.txt";	
############

$routine = "6: can not find file $id_username/$contents{'username'}.txt - please check the \$threads_dir path and the \$dir_passwords path";
open (BOOK, "${threads_dir}$phonebook3") || do {&no_open;};
@sorted = <BOOK>;
close(BOOK);
	
#
&header;

print <<"HTML";
<HTML>

<TABLE bgcolor=$bg1 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>

HTML
#	
	
foreach $pair (@sorted){
 @ok = split(/,/, $pair);   
 if (lc($ok[2]) eq lc($contents{'forgot_identify'}) || lc($ok[4]) eq lc($contents{'forgot_identify'}) || lc($ok[5]) eq lc($contents{'forgot_identify'}))    {   
	$contents{'email'} = $ok[5] ;
	$contents{'username'} = $ok[2];
	$contents{'password'} = $ok[3];
	$found = "1";
	&send_mail;
	
	print "<BR> Found user \"$contents{'username'} \" - password has been emailed";
	&footer;
	exit;
	}
}

if ($found ne "1") {
	print " \"$contents{'forgot_identify'}\" Not found ";
	}	
exit;
}

############################################
# check for banned isp, ip

$routine = "16: can not find file banned.txt - please check the \$threads_dir path and the \$dir_passwords path";
open (TEMPFILE, "${threads_dir}${dir_passwords}/banned.txt") || do {&no_open;};
@banned = <TEMPFILE>;
close (TEMPFILE);

$userban_info = "$isp - $ip\ - $contents{'email'}";

foreach $badguys (@banned) {

	$badguys =~ s/ //g;
	$badguys =~ s/\n//g;
	$badguys =~ s/\r//g;
	if (length($badguys) < 5) {
		next;
		}
	
#	$badguys =~ s/ //g;
#	$badguys =~ s/\n//g;
#	$badguys =~ s/\r//g;

if (length($badguys) < 3) {
	next;
	}

if (lc($isp) =~ lc($badguys) || $ip =~ $badguys || lc($contents{'email'}) =~ lc($badguys)) {
	
	print "Content-type: text/html\n\n";
	$userban_info =~ s/$badguys/<FONT COLOR=red><B>$badguys<\/B><\/FONT>/gi;
	print "<P>Sorry, you're not allowed to register ($userban_info). 
		<P>If you think an error has occured, contact the moderators.<P> ";

	$routine = "161: can not write to file banned.txt - please CHMOD the file & its directory properly";
	open (TEMPFILE, ">>${threads_dir}${dir_passwords}/badguys.txt") || do {&no_open;};
	print TEMPFILE "$isp,$ip,$logtime,\n";
	close (TEMPFILE);	
	
	exit;
	}


}	
############################################
if ($contents{'act'} eq "user_list") {

if ($lists ne "ON") {
	print "function is OFF";
	exit;
	}
	
	$routine = "56: error in buffer size - user_list";
	$length = length($buffer);
	&no_open unless ($length < $user_length);

&authenticate;

$real = $ok[2];

$filename = "user_lists/".lc($ok[2]);

$ext= "shtml";

$contents{'songs'}  =~ s/</[/g;
$contents{'songs'} =~ s/>/]/g;

$contents{'songs'} =~ s/\n\n/<p>/g;
$contents{'songs'} =~ s/\n/<br>/g;
	
	
	$routine = "46: can not find file $filename\.$ext - please check the \$threads_dir path or that the directory exists";
	
	if ($contents{'deletelist'} ne "yes") {
		open (NEWFILE, ">${threads_dir}$filename\.$ext") or do {&no_open;};
		chmod(0666, "${threads_dir}$filename\.$ext");
		print NEWFILE "<TITLE>$ok[2] : user's list - </TITLE>\n<P>\n ";
		print NEWFILE "$contents{'songs'}";
		close (NEWFILE);
			}
	else {
		unlink "${threads_dir}$filename\.$ext";
			}

&header;

print "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"4; URL=${scripts_url}bm_reply.pl?profile&$nospaces\">";
print "<P>Information added succesfully\n";
print "<P> \"$filename\.$ext\" \n";
print "<BR>You may change this info at any time\n";
print "<P><IMG SRC=\"${threads_url}graphics/mes-success\.jpg\"  ALIGN=RIGHT>";
&footer;
exit;

}


####################################
if ($contents{'SUBMIT'} eq "Edit") {
	$contents{'act'} = "editprofile";
	}

####################################
if ($contents{'act'} eq "editprofile") {
		
open (TEMPFILE, "${threads_dir}$phonebook3");
@main = <TEMPFILE>;
close (TEMPFILE);

&header;

&mod_check;
	
###

foreach $line(@main) {
		
 	@ok = split(/,/, $line);   
	
 	if (lc($ok[2]) eq lc($contents{'username'}) )  {   
		
		if (lc($ok[3]) ne lc($contents{'password'}) && $user_authenticated ne "1")  {   
			print "Error - wrong password";
			&footer;
			exit; 			
 			}
 		
 		$ok[9] =~ s/<P>/\n\n/ig;
 		$ok[9] =~ s/<BR>/\n/ig;

 		 $found = "1";		
 		 		
		$ext= "shtml";
		
		$filename = "user_lists/".lc($ok[2])."\.$ext";
				
		open (TEMPFILE, "${threads_dir}$filename");
		@song_data = <TEMPFILE>;
		close (TEMPFILE);
		foreach $line(@song_data) {

			unless ($line =~ "<TITLE>"){
				$songs .= $line;
			}
	
$line =~ s/\r//g;
$line =~ s/\n//g;
$songs =~ s/<([^>]|\n)*>//g;

			}

#############
if ($faces eq "ON") {
		
opendir(DIR, "${threads_dir}graphics/faces/");
@images = grep(/\.gif$/,readdir(DIR));
closedir(DIR);

foreach $icon (@images) {
	
	$nogif = $icon;
	$nogif =~ s/.gif//i;
	
	if ($forum_moderator ne "1" && $icon =~ "xx_") {next; }
		
	$opicon = "<option VALUE=\"${threads_url}graphics/faces/$icon\">$nogif</option>\n";
	push (@faces , $opicon);
	}

if ($ok[10] eq "" || $ok[10] eq "whatever" ) {
	$selected_face = "<option selected VALUE=\"${threads_url}graphics/faces/no_portait.gif\">no portrait</option>\n";	
	$postface = "${threads_url}graphics/faces/no_portait.gif";
	}
else {
	$postface = "$ok[10]";
	$damn_name = "$ok[10]";
	
	$damn_name =~ s/${threads_url}//i;
	$damn_name =~ s/\graphics\/faces\///i;
	$damn_name =~ s/\.gif//i;
	$selected_face = "<option selected VALUE=\"$ok[10]\">$damn_name</option>\n";	
	}
	

$face_choosen = "<script language=\"javascript\">
function showimage()
\{
if (!document.images)
return
document.images.faces.src=
document.REPLIER.userface.options[document.REPLIER.userface.selectedIndex].value
\}
</script>

<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>FACE</B></FONT></TD><TD vAlign=top> 	          
		
<font size=2>
<select name=\"userface\" size=\"3\" onChange=\"showimage()\">
$selected_face
@faces
</select>
<a href=\"javascript:linkrotate(document.REPLIER.userface.selectedIndex)\" onMouseover=\"window.status='';return true\">
<img src=\"$postface\" name=\"faces\" width=\"32\" height=\"32\" border=0 hspace=15></a>
	</font> 

<FONT SIZE=2>or view all faces <A HREF=\"${scripts_url}bm_register.pl?read_dir&faces\" target=_new>here</A>.</FONT>
	
		</FONT></FONT></TD></TR>     
	";         
	
        }
        
###############

 		&profile_print;
 		
 		if ($lists eq "ON") {
 			&mp3_print;
 			}
 		
 		&footer;
 		exit;
 		}
	}

if ($found ne "1") {
	print "Error <P> Username: \"$contents{'username'}\" not found";
	exit;
	}

print "OK";
&footer;

	exit;
}




####################################
if ($contents{'SUBMIT'} eq "Modify profile") {
	
	$username_fixed = $contents{'username'};
	$username_fixed =~ s/ /_/g;
	$redirect = "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"4; URL=${scripts_url}bm_reply.pl?profile&${username_fixed}\">";
			
open (TEMPFILE, "${threads_dir}$phonebook3");
@main = <TEMPFILE>;
close (TEMPFILE);

 print "Content-type: text/html\n";

&mod_check;

# Set a new cookie, if user is not a moderator
unless ($contents{'save_cookie'} eq "no") {
     $cname = "${id_cookie}_bmusername";                             #
     &SetCookies("$cname","$contents{'username'}");
     
if ($mpiskoto eq "YES" && $username) {
     $cpass  = "${id_cookie}_bmpassword";    
     &SetCookies("$cpass","$contents{'password'}");
	}
}

&header;

 	@ok = split(/,/, $main[0]);   
	
 	if (lc($ok[2]) eq lc($contents{'username'}) && lc($ok[3]) eq lc($contents{'old_password'}))  {   
 		$user_validated = 1;
 		}
 	if (lc($ok[2]) eq lc($contents{'username'}) && $forum_moderator eq "1")  {   
 		$user_validated = 1;
 		} 	
 	
if ($user_validated eq "1") {
		 		
 		$message = "Successfully modified data for \"$ok[2]\" ";
 		
 		$contents{'signature'} =~ s/\n//gs;
 		$contents{'signature'} =~ s/\r//gs;

	if ($forum_moderator ne "1") {
		$contents{'title'} = $ok[4];
		}

	if ($forum_moderator ne "1" && $contents{'userface'} =~ "xx_") {
		$contents{'userface'} = "";
		}

	$contents{'private_forums'} = " $contents{'private_forums'} ";
	$contents{'private_forums'} =~ s/  / /g;
	
	if ($forum_moderator eq "1") {
		$ok[12] = $contents{'private_forums'};
		$contents{'password'} = $ok[3];
		}
	
  		$main[0] = "$ok[0],$ok[1],$ok[2],$contents{'password'},$contents{'title'},$contents{'email'},$contents{'icq'},$contents{'connection'},$ok[8],$contents{'signature'},$contents{'userface'},$contents{'webmaster'},$ok[12],$ok[13],$ok[14],$ok[15],";
  		$main[0] =~ s/\n//gi;
  		$main[0] =~ s/\r//gi;
  		$main[0] .= "\n";
 		
 			if ($contents{'deletepost'} eq "yes") {
 				$main[0] = "";
 				$redirect = "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"4; URL=${threads_url}forums.$ssix\">";
 				
				$ext= "shtml";
 				unlink "${threads_dir}$phonebook3";
 				
 				$message = "Succefully deleted record:\"$ok[2]\" ";
 				} 		
 		}
	else {
		print "Authentication error <BR> $ip ";
		exit;
		}

unless ($contents{'deletepost'} eq "yes") {
	open (TEMPFILE, ">${threads_dir}$phonebook3");
	print TEMPFILE @main;
	close (TEMPFILE);
	}

	print "$redirect";
	print "$message";
&footer;

	exit;
}

####################################


$id_username = lc(substr($contents{'username'}, 0, 1));
unless ("0123456789abcdefghijklmnopqrstuvwxyz" =~ $id_username) { 
	print "Sorry, the first letter of the username , can NOT be a wild character. <P> Please use an alphanumeric character instead.";
	exit;
	}

# check if username/email already exists
	                
	                #$contents{'username'} =~ s/([^>]|\n)*//g;
	                #$contents{'username'} =~ s/(?:[^>'"]*|(['"]).*?\1)*//gs;
                         
                        $contents{'username'} =~ s/\?//g;
                        $contents{'username'} =~ s/\.//g;
                        $contents{'username'} =~ s/\*//g;
#                        $contents{'username'} =~ s/ /_/g;
                        $contents{'username'} =~ s/\,//g;
                        $contents{'username'} =~ s/\=//g;
                        $contents{'username'} =~ s/\://g;
 
&more_characters unless (length($contents{'username'}) >2);
                         
open (TEMPFILE, "${threads_dir}$phonebook3");
@main= <TEMPFILE>;
close (TEMPFILE);

foreach $line(@main) {
		
 	@ok = split(/,/, $line);   
			
 	if (lc($ok[2]) eq lc($contents{'username'}))    {   
 		&header;
		print "<P>Username \"$contents{'username'}\" already exists";
		print "<P>Try registering using a different username";
		print "</TD></TR></TABLE>";			
		exit;
		}
	}

# insert new data: 	posts,last post,Beholder,password,title,email,icq,syndesi,registration date,signature,whatever

##########

if ($random_password eq "YES" && $contents{'email'} =~ /.*\@.*\..*/) {
	&password_creation;
	&send_mail;
	}

if ($random_password eq "YES" && $contents{'email'} !~ /.*\@.*\..*/) {
	print "Content-type: text/html\n\n";
	print "error: invalid email address";
	exit;
	}

&more_characters unless (length($contents{'password'}) >2);

######################
######################

    print "Content-type: text/html\n";
	
     # Set a new cookie.                         
     $cname = "${id_cookie}_bmusername";                             #
     &SetCookies("$cname","$contents{'username'}");
     
if ($mpiskoto eq "YES" && $random_password eq "NO") {
     $cpass  = "${id_cookie}_bmpassword";    
     &SetCookies("$cpass","$contents{'password'}");
	}

    # End the headers sent to browser.                                       #
    print "\n";
    
######################
######################

$routine = "36: can not find file $id_username/$contents{'username'}.txt - please check the \$threads_dir path";
open (TEMPFILE, ">>${threads_dir}$phonebook3") || do {&no_open;};
chmod(0666, "${threads_dir}$phonebook3");
print TEMPFILE "0,last post,$contents{'username'},$contents{'password'},$contents{'title'},$contents{'email'},$contents{'icq'},$contents{'connection'},$posted,$contents{'signature'},$contents{'userface'},$contents{'webmaster'},$contents{'private_forums'},$contents{'mode'},whatever, \n \n \n \n ";
close (TEMPFILE);

$logip_file = "$dir_passwords/${id_username}/${id_username}_logip.txt";			

$routine = "361: can not write to file ${id_username}_logip.txt - please check the CHMOD properties of the file & its directory, and the \$dir_passwords path";
open (TEMPFILE, ">>${threads_dir}$logip_file") || do {&no_open;};
chmod(0666, "${threads_dir}$logip_file");
print TEMPFILE "$day,$contents{'username'},$ip,$isp,$logtime,\n";
close (TEMPFILE);
 
######################

$name_backup = $contents{'username'};
$contents{'username'} =~ s/ /_/g;

print "REGISTRATION OK";
print "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"4; URL=${scripts_url}bm_reply.pl?profile&$contents{'username'}\">
	<P><A HREF=\"bm_reply.pl?profile&$contents{'username'}\">$name_backup</A>";

exit;

#######################
# Random Password Creation
sub password_creation {

	    srand(time|$$);
	 $contents{'password'} = "";
	    $random = "abcdefghijklmnopqrstuvwxyz1234567890";
	for (1..8) {
	    $contents{'password'} .= substr($random,int(rand(36)),1);
	}
}

#######################
#  Mail Subscription Verification

sub send_mail {

    open (MAIL,"|$mailprog -t");
    print MAIL "To: $contents{'email'}\n";
    print MAIL "From: $contact ($reg_sender)\n";
    print MAIL "Subject: Password\n\n";
    print MAIL "From: $domain \n";
    print MAIL "Your username is: $contents{'username'}\n";  
    print MAIL "Your password is: $contents{'password'}\n\n";  
    print MAIL "You can use the \"Edit Profile\" form, to change your password, or the rest of your data\.\n\n";  
    print MAIL "$registration_message";  
    print MAIL "Thanks for registering\n\n";  
    print MAIL "Njoy the site\n\n";  
    print MAIL "$domain \n";
    close (MAIL);

}

###########################
sub profile_print {
	

if ($forum_moderator eq "1") {
	$user_title = "<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Title</B></FONT></TD><TD vAlign=top> 	          
	<INPUT name=title size=20 maxlength=20 value=\"$ok[4]\">
	</FONT> </TD></TR>";
	
	$private_forums = "<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Forums</B></FONT></TD><TD vAlign=top> 	          
	<INPUT name=private_forums size=50 maxlength=80 value=\"$ok[12]\">
	<BR><FONT SIZE=1>insert forum directories separated by spaces
	</FONT></TD></TR>";
	
	$ok[3] = $contents{'password'};
	}

	
print <<"HTML";
<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>

<FORM action=bm_register.pl 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 vAlign=top colspan=2>

<H2>Modify your data</H2>
	</TD></TR>          
          
<TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Username:</B></FONT></TD><TD vAlign=top> 	          
	$ok[2]
	<INPUT name="username" type=hidden value="$ok[2]">
	</FONT></FONT></TD></TR>
                             
<TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Password:</B></FONT></TD><TD vAlign=top> 	          
	<INPUT name=password type=password size=20 value="$ok[3]">
	<INPUT name=old_password type=hidden value="$ok[3]">
	</FONT></FONT></TD></TR>

$user_title
$private_forums 

<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>email</B></FONT></TD><TD vAlign=top> 	          
	<INPUT name=email size=60 maxlength=60 value="$ok[5]">
	</FONT></FONT></TD></TR>          

<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>ICQ</B></FONT></TD><TD vAlign=top> 	          
	<INPUT name=icq size=12 maxlength=12 value="$ok[6]">
	</FONT></FONT></TD></TR>          
	
<TR bgColor=$color2><TD vAlign=top><FONT size=2><B>Connection</B></FONT></TD><TD vAlign=top> 	      	
 <SELECT NAME="connection">
<OPTION SELECTED  value="$ok[7]">$ok[7]
<OPTION VALUE="28 k">28k modem
<OPTION VALUE="56 k">56k modem
<OPTION VALUE="ISDN">ISDN
<OPTION VALUE="T1">T1
<OPTION VALUE="T3">T3
<OPTION VALUE="Cable">Cable
</SELECT>
</FONT></FONT></TD></TR>          

$face_choosen

<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Signature</B></FONT></TD><TD vAlign=top> 	      
<BR> <textarea COLS=40 ROWS=5 name="signature" Maxsize=30>$ok[9]</textarea><p>
            	</FONT></FONT></TD></TR>          

$upload_link

<TR bgColor=$color1><TD>&nbsp;</TD><TD><FONT SIZE=2>
<INPUT TYPE=checkbox Name=webmaster value="checked" $ok[11]>Allow the webmaster to send you email notifications, announcements, etc. You can change this at any time.<BR>
</FONT></TD></TR>

<TR bgColor=$color1><TD>&nbsp;</TD><TD><FONT SIZE=2>
<INPUT name=deletepost type=checkbox value=yes>Delete? To delete your profile, check this box.<BR>
</FONT></TD></TR>

<TR bgColor=$color1><TD>&nbsp;</TD><TD>
<INPUT name=SUBMIT type=submit value="Modify profile"> -
<INPUT name=RESET type=reset value="Undo">           
<INPUT name=save_cookie type=hidden value="$save_cookie">           

</FORM>

</TD></TR>
            </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER>
                     
HTML
	
}

###################
# The top portion of the web pages. Edit as desired.
sub header {
	
print "Content-type: text/html\n\n";

print <<"HTML";
<HTML>
<HEAD><TITLE> ${site_name}: User Info </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 "<FONT COLOR=RED>ERROR <P>routine: \"$routine\"</FONT> ";

	&footer;
	exit;
}


############################################
# Authenticate User

sub authenticate {

&more_characters unless (length($contents{'username'}) >3 && length($contents{'password'}) >3);

	$name_backup = $contents{'username'};
	$contents{'username'} =~ s/^\s+//;
	$contents{'username'} =~ s/\s+$//;

$error = "have you registered ?";
$routine = "27: can not find file $id_username.txt .please check the \$dir_passwords path , the \$threads_dir, or that the file exists. 
	<BR>Do the /a-z directories exist as well, and have you chmoded them correctly ? ";
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'}))    {   
	 $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'}))    {   
 	&header;
 	 print "<H1>Error !<BR></H1>"; 
 	 print "Username: \"<font color=\"#ff9933\"><b>$contents{'username'}</B></font>\" has been registered with a different password</H1>\n"; 
#	print "<BR>\"$ok[3]\" - \"$contents{'password'}\" - <P>\"$buffer\" ";
 	 print "Press BACK and insert correct password or choose a different username\n"; 
# 	 print "<P>Visit the <A HREF=\"http://www.beholder.net/hideout/body_database.$ssix\">Greek Mp3 Database</A> &copy; to register your own name\n"; 
 	 print "</BODY></HTML>"; 
	 print "<P><IMG SRC=\"${threads_url}graphics/mes-error.jpg\"  ALIGN=RIGHT>";	
	 
	 &footer;
	 
	 exit;
 	}

}

if ($user_authenticated != 1) {

	&header;
 	 print "<H1>Error !<BR></H1>"; 
 	 print "Username: \"<font color=\"#ff9933\"><b>$contents{'username'}</B></font>\" not found</H1>\n"; 
 	 print "<BR>Press BACK and insert correct username\n"; 
# 	 print "<P>Visit the <A HREF=\"http://www.beholder.net/hideout/body_database.$ssix\">Greek Mp3 Database</A> &copy; to register your own name\n"; 
 	 print "<P><IMG SRC=\"${threads_url}graphics/mes-error.jpg\"  ALIGN=RIGHT>"; 
 	 
	&footer;
	 exit;
			}


}



#################################
sub more_characters {

&header;
print <<"HTML";
<H1> Error! <BR> Password ($contents{'password'}) & Username ($contents{'username'}) have to be at least 3 characters long each!</H1>
<H2> Please press the BACK button and try again</H1> 
<CENTER>
<P><IMG SRC="${threads_url}graphics/mes-error.jpg"  ALIGN=RIGHT>
</CENTER>
HTML
&footer;
exit;
}


###########################
sub mp3_print {
	
print <<"HTML";
<HTML>

<P><BR><P>
<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=2>
<H2>$title<BR></H2>
<FORM ACTION="bm_register.pl" METHOD="POST">
<P><FONT SIZE=-1>Insert text below (up to $user_length bytes in size)</FONT>:
<BR> <textarea COLS=40 ROWS=5 name="songs" Maxsize=30>$songs</textarea><p>
<FONT SIZE=2><INPUT name=deletelist type=checkbox value=yes>Delete? To delete completely your list, check this box.<BR></FONT>
<BR>
<INPUT TYPE="submit" value="Modify list">
 - <INPUT name=RESET type=reset value="Undo">       
<INPUT TYPE="hidden" NAME="act" VALUE="user_list">

<INPUT TYPE="hidden" NAME="username" VALUE="$ok[2]">
<INPUT TYPE="hidden" NAME="password" VALUE="$ok[3]">

</FORM>
</TD></TR>
            
            </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER>
          
            
HTML
	
}

######################################

sub read_dir {

if ($query =~ "faces" || $query =~ "icons" || $query =~ "emoticons") {
	@lask = split(/&/, $query);   
	$dir = $lask[1];
	}
else {
	exit;
	}

opendir(DIR, "${threads_dir}graphics/$dir/");
@images = grep(/\.gif$/,readdir(DIR));
closedir(DIR);

	print "Content-type: text/html\n\n";
	
foreach $icon (@images) {
	$pqow++;
	
	$icon_name = $icon;
	$icon_name =~ s/\.gif//i;
	
	if ($icon_name =~ "xx_") {
		$icon_bg = "bgcolor=$color1";
		$icon_name = "<FONT COLOR=red>** $icon_name ** </FONT>";
		}
	
	
	$all_faces .= "<TD $icon_bg><IMG src=\"${threads_url}graphics/$dir/$icon\" hspace=5><BR><FONT SIZE=2>$icon_name</TD>\n";
	
	if ($pqow =~ "5"){	
		$total = $total + $pqow;
		$pqow = "";
		$all_faces .= "</TR><TR>";
		}
		
	$icon_bg	= "";
	}

if ($query =~ "emoticons") {
	$more_info = "To use emoticons you need to use the format :name: <BR> eg :smile: , :cool: , :smile2: , etc<P>";
	}

print "<HTML><BODY background=\"$bg_img\" leftmargin=0 topmargin=0 bgcolor=\"$bg1\" style=\"$font_family; $font_color;\" vlink=\"$vlink\" link=\"$ulink\" text=\"$text_color\"><TITLE>BoardMaster $version: gallery (total $dir: $total)</TITLE>
	
	<BR><A HREF=\"http://www.beholder.net\" target=_new><IMG SRC=${threads_url}graphics/beholder_logo.gif border=0 width=88 height=31 hspace=10></A>
	&nbsp;&nbsp;<B>BoardMaster v$version</B> <BR> by  Aristotle Vathis (arnica\@otenet.gr)
		
	<P>$dir gallery:<P>$more_info<TABLE border=0><TR>$all_faces </TR></TABLE><P><B>Total $dir</B>: $total </BODY></HTML>";

exit;

}


###################################

sub upload {
	
print "Content-type: text/html\n\n";

	if ($uploading ne "YES") {
		print "<BR>error - uploading not allowed - IP:<B><FONT COLOR=red>$ip</B></FONT> logged ($isp)";
		exit;
		}

use CGI; 

 $req = new CGI; 
 $file = $req->param("FILE"); 
if ($file ne "") {
 $fileName = $file; 
$fileName =~ s!^.*(\\|\/)!!; 
$newmain = $fileName;


    $count = ($fileName =~ tr/\.//);
    
if ($count ne "1") {
	print "<BR>error - filename not accepted: <B><FONT COLOR=red>$ip</B></FONT> logged ($isp)";
	exit;
	}    

## log IP of user

open (TEMPFILE, ">>${threads_dir}$dir_passwords/upload.txt") || do {&no_open;};
print TEMPFILE "$ip $isp $newmain\n";
close (TEMPFILE);	

##

@extensions = split(/ /, $extensions);   

foreach $theext (@extensions) {
	if (lc(substr($newmain,length($newmain) - 4,4)) eq lc($theext)){
	$filegood = "yes";
	$ext = $theext;
	last;
	}
}

if ($filegood eq "yes") { 
	open (OUTFILE, ">${upload_path}$fileName"); 
	chmod(0666, "${upload_path}$fileName");

	while ($bytes_read = read($file, $buffer, 1024)) { 
	binmode( OUTFILE); 
	print OUTFILE $buffer; 
	        $size += $bytes_read;
	
	} 
	close (OUTFILE); 
	
	print "<BR>$size > $upload_length - $bytes_read";
	if ($size > $upload_length) {
		print "<BR>error - file size ($size) greater than allowed: (${upload_length})";
		unlink"${upload_path}$fileName$ext";
		exit;
		}
	
}
else {
	print "<BR>error - file extension not accepted";
	exit;
	}
}	

print " <P>File uploaded";
exit;

}
	
	
###################################

sub upload_request {
	
print "Content-type: text/html\n\n";

	if ($uploading ne "YES") {
		print "<BR>error - uploading not allowed - IP:<B><FONT COLOR=red>$ip</B></FONT> logged ($isp)";
		exit;
		}
	
print <<"HTML";
 <HTML><BODY background="$bg_img" leftmargin=0 topmargin=0 bgcolor="$bg1" style="$font_family; $font_color;" vlink="$vlink" link="$ulink" text="$text_color">
 <TABLE width="100%" bgcolor=$bg1 border=0 cellspacing=5 cellpadding=2>
  <TR><TD>
<IMG SRC="${threads_url}graphics/$logo" ALIGN=left VALIGN=TOP WIDTH="$logo_width" HEIGHT="$logo_height">
 </TD></TR><TR><TD><FONT SIZE=2>
<P><form method="POST" action="${scripts_url}bm_register.pl?upload" ENCTYPE="multipart/form-data">
  
<P>filetypes supported: $extensions
<BR>maximum filesize: $upload_length bytes
<P>$guidelines

<P>File: 
<input type="file" name="FILE" size=40> 
<br>
<input type="submit" value="Upload! ">
</form>

</TD></TR></TABLE></BODY></HTML>

HTML

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 boardmaster_tags {
	
print "Content-type: text/html\n\n";	
print <<"HTML";

<HTML><title>Boardmaster Tags Guide</title><BODY background="$bg_img" leftmargin=0 topmargin=0 bgcolor="$bg1" style="$font_family; $font_color;" vlink="$vlink" link="$ulink" text="$text_color">
<TABLE cellspacing="0" cellpadding="5" border=5 align="center" width=95%><TR><TD>
<tr> 
<td colspan=2 bgcolor="#CCCCCC"><br>
<center>
<h1><font color="#FF0000" face="Verdana, Arial, Helvetica, sans-serif">Boardmaster Tag User Guide</font>
<A HREF="http://www.beholder.net" target=_new border=0><IMG hspace=20 SRC=${threads_url}graphics/beholder_logo.gif border=0 width=88 height=31></A></h1>
</center>
</td>
</tr>
<TR>
<TD width=50% bgcolor="#CCCCCC">
<center><font size="5" face="Verdana, Arial, Helvetica, sans-serif">Boardmaster Tag Example</font></center>
</TD>
<TD bgcolor="#CCCCCC">
<center><font size="5" face="Verdana, Arial, Helvetica, sans-serif">Result</font></center></TD></TR>
<TR bordercolor="#000000"> 
<TD COLSPAN=2 bgcolor="#FFFFCC"> 
<center><font size="3" color="#000000"><b><font face="Verdana, Arial, Helvetica, sans-serif"> Text Effects
</font></b><font face="Verdana, Arial, Helvetica, sans-serif"> - Use these tags to modify your text</font></font></center>
</TD></TR>
<TR>
<TD><font size=2> <FONT COLOR="#FF0000">[b]</FONT>Bold Text<FONT COLOR="#FF0000">[/b]</FONT><BR>
<FONT COLOR="#FF0000">[i]</font>Italic Text<FONT COLOR="#FF0000">[/i]<br><br>
[color=red]<font color="#000000">Red Text</font>[/color]<br>
[color=#ff0000]<font color="#000000">Red Hex Text</font>[/color]<p>
[size=1]<font color="#000000">Mini Text</font>[/size]<br>
</font></font></TD>
<TD bgcolor="#eeeeee"> 
<div align="center"><font size=2> <b>Bold Text</b><BR><i>Italic Text</i><br><br>
<font color="#FF0000">Red Text<br>
Red Hex Text</font>
</font>
<P><font size=1>Mini text<br></div>
</TD></TR>
<tr bgcolor="#FFFFCC"> 
<td colspan=2> 
<center><font size="3" color="#000000"><b><font face="Verdana, Arial, Helvetica, sans-serif">URL 
Hyperlinking</font></b><font face="Verdana, Arial, Helvetica, sans-serif"> 
 - Use this tag to include a hyperlink to another website or webpage</font></font></center>
</td></tr>

<TR><TD><font size=2>
<FONT COLOR="#FF0000">[url]</FONT>www.beholder.net<FONT COLOR="#FF0000">[/url]</FONT><BR>
<FONT COLOR="#FF0000">[url=http://www.beholder.net]</font>Beholder.net<FONT COLOR="#FF0000">[/url]</font>
</font></TD>
<TD bgcolor="#eeeeee"> 
<center><font size=2> <A HREF="http://www.beholder.net" target=_new>www.beholder.net</A><BR>
<A HREF="http://www.beholder.net" target=_new>Beholder.net</A> </font></center></TD></TR>
<TR> <TD COLSPAN=2 bgcolor="#FFFFCC"> 
<center><font size="3"><b><font face="Verdana, Arial, Helvetica, sans-serif">Email 
Hyperlinking</font></b><font face="Verdana, Arial, Helvetica, sans-serif"> 
- use this tag to include an email address</font></font></center></TD></TR>
<TR><TD><font size=2>
<FONT COLOR="#FF0000">[email]</FONT>arnica\@otenet.gr<FONT COLOR="#FF0000">[/email]</FONT><BR>
<FONT COLOR="#FF0000">[email=Beholder]</FONT>arnica\@otenet.gr<FONT COLOR="#FF0000">[/email]</FONT>
</font></TD><TD bgcolor="#eeeeee"> 
<center><font size=2> <A HREF="mailto:arnica\@otenet.gr">arnica\@otenet.gr</A><BR>
<A HREF="mailto:arnica\@otenet.gr">Beholder</A> </font></center></TD></TR>

<TR> <TD COLSPAN=2 bgcolor="#FFFFCC"> 
<center><b><font face="Verdana, Arial, Helvetica, sans-serif" size=3>Images</font></b><font face="Verdana, Arial, Helvetica, sans-serif"> - use this tag to include an image</font></center></TD></TR>
<TR>
<TD><font size="2" COLOR="#FF0000"> [img]</FONT><font size="2">http://www.beholder.net/scripts/boardmaster/boardmaster.gif<FONT COLOR="#FF0000">[/img]</FONT></font></TD>
<TD bgcolor="#eeeeee"> 
<center><IMG src=http://www.beholder.net/scripts/boardmaster/boardmaster.gif></center></TD></TR>

<TR> 
<TD COLSPAN=2 bgcolor="#FFFFCC"> 
<center><font size="3"><b><font face="Verdana, Arial, Helvetica, sans-serif">Code</font></b><font face="Verdana, Arial, Helvetica, sans-serif"> - use this tag to display code safely</font></font></center></TD></TR>
<TR><TD><font size=2>
<FONT COLOR="#FF0000">[code]</FONT>
<BR>unless ($data eq "\$authenticate") {
<BR>print "WRONG ADMIN PASSWORD";
<BR>&unlock;
<BR>exit;
<BR>}
<FONT COLOR="#FF0000">[/code]</FONT>
</font></TD>
<TD bgcolor="#eeeeee"> 
<BLOCKQUOTE><FONT size=1>code:<HR><BR>
unless ($data eq "\$authenticate") { <BR>
print "WRONG ADMIN PASSWORD"; <BR>
&unlock; <BR>
exit; <BR>
}<HR></FONT></BLOCKQUOTE>
</TD>
</TR>

<TR> 
<TD COLSPAN=2 bgcolor="#FFFFCC"> 
<div align="center"><font size=2><b><font size="3" face="Verdana, Arial, Helvetica, sans-serif">Quotes 
</font></b><font size="3" face="Verdana, Arial, Helvetica, sans-serif">- 
use this tag to quote from another source</font></font></div></TD></TR>
<TR><TD valign=top><font size=2>
<BR><FONT COLOR="#FF0000">[quote]</FONT>PLEASE, let me know if you install Boardmaster on your website. I like to see my work in action... 	
Feel free to send me any comments/suggestions you may have..<FONT COLOR="#FF0000">[/quote]</FONT>
</font></TD>
<TD bgcolor="#eeeeee"><font size=2> 
<BLOCKQUOTE><FONT size=1>quote:<HR>
PLEASE, let me know if you install Boardmaster on your website. I like 
to see my work in action... Feel free to send me any comments/suggestions 
you may have.<HR></FONT></BLOCKQUOTE></font></TD></TR>
</TABLE></BODY></HTML>         
HTML
}   


############

sub mod_check {
	
open (BOOK, "${threads_dir}jumps.txt") || do {&no_open;};
@overide = <BOOK>;
close(BOOK);

foreach $line (@overide) {
	@moderators = split(/\"/, $line);   		
		if ($moderators[1] ne "") {
		push (@demigods, $moderators[1]);
		}
	}

foreach $modfile (@demigods) {
$error = $phonebook2;
$routine = "26: can not find file \"$modfile/moderators_\${id_unique}.txt\" - please check the \$threads_dir path parameter (full unix path to the main directory) or that the file exists";
open (BOOK, "${threads_dir}$modfile/$phonebook2") || do {&no_open;};
@overide = <BOOK>;
close(BOOK);

foreach $pair (@overide){

	@metablites = split(/\|/, $pair);   		
	$pair = $metablites[0];
	if (lc($pair) eq lc($contents{'password'}) || lc($pair) eq lc("$contents{'username'}==$contents{'password'}") ) {

		$user_authenticated = 1;		
		$forum_moderator = 1;
		$save_cookie = "no";
		last;
		}
	}
	
if ($uploading eq "YES") {
	$upload_link = "<TR bgColor=$color1><TD vAlign=top><FONT size=2><B>Uploading</B></FONT></TD><TD vAlign=top> 	          
		<FONT SIZE=2>want to <A HREF=\"${scripts_url}bm_register.pl?upform\" target=_new>upload</A> a file ?</TD></TR>";
		}	
	
}

}
