#!C:\Perl\bin\perl.exe

# Whoops!  If you see this message in your browser, your web hosting provider
# has not properly mapped the .cgi file extension to Perl.
#
# Please contact them for more information.  Mapping .cgi is easy for both
# Unix and NT servers, and usually only takes a few seconds.


# UBB.classic(tm) Program File
# Ultimate Bulletin Board Core
# $Id: ultimatebb.cgi,v 1.89.2.1 2004/05/25 22:58:40 cvscapps Exp $


# UBB.classic 6.x
# Official Release Date for UBB.classic 6.0: March 15, 2001
#
# First version of UBB created May 7, 1996 (by Ted O'Neill).
# This entire program is copyright Infopop Corporation, 2004.
# For more info on UBB.classic and other Infopop
# Products and Services, visit: http://www.infopop.com
#
# Program Author: Ted O'Neill, with assistance from Michael Farris, Dave Dreezer
#
# Special Thanks to: Rosemary O'Neill, Mark Badolato, Charles Capps,
# Graeme, Jesus de la Garza, Joe Siegler, Hal, Brett Harris, Kristi Miller,
# Celeste Combs, everyone who beta-tested, and all of our support moderators!
#
# UBB.classic 6.x is dedicated to Edward Kriz.
#
# You may not distribute this program in any manner, modified or otherwise,
# without the express, written consent from Infopop Corporation.
#
# You may make modifications, but only for your own use and within the confines
# of the UBB.classic License Agreement (see our website for the full license).
#
# You may not distribute "hacks" for UBB.classic without approval from Infopop.
#
# Note: If you modify ANY code within your UBB.classic, we at Infopop Corporation
# cannot offer you support -- thus modify at your own peril :)

#use warnings;
#our $warnhandler;
#$SIG{__WARN__} = sub { $warnhandler .= $_[0]; };
#close STDERR; open(STDERR, ">", \$warnhandler) or die "Content-type: text/plain\n\nSTDERR -> warnhandler failed: $!";
#($ENV{REQUEST_METHOD} eq "GET" || $ENV{REQUEST_METHOD} eq "POST") or die "Unknown REQUEST_METHOD";
# Sigh.  If only Sub::WrapPackages worked as I expected it to...

BEGIN {	# get our modules directory set up
	($0 =~ m!(.*)(\\|/)[^/\\]+!) && unshift(@INC, $1, "$1$2Modules");
	$| = 1;
};
END {
#	print qq~<hr /><pre>~ . UBBCGI::escapeHTML($warnhandler) . "</pre>";
	$filehandle && ref($filehandle) && $filehandle->cleanup();
};

use lib("./Modules", ".");	# if there's no $0, or it's not sane...

use strict;
use Fcntl ':flock';
use UBBCGI qw(:cgi);
use UBBCGI::Carp qw(fatalsToBrowser set_message);
#carpout(\*STDOUT);

BEGIN { # pull in the best copy of Digest::MD5 that we can find
	do "Digest/MD5.pm";
	if (!$Digest::MD5::VERSION) {
		require Digest::Perl::MD5;
		import Digest::Perl::MD5 'md5_hex';
	} else {
		import Digest::MD5 'md5_hex';
	} # end if
}; # end BEGIN

use constant SEVENSEVENSEVEN => 0777;
use constant SIXSIXSIX => 0666;

use vars qw(
	$filehandle $forum_threads $alpha_threads %forum_thread_data @alltheforums
	@allthecategories @memberslist_array %ProfileNumber %in %GotTime $vars_groups
	%vars_version_information %vars_style_reference %vars_wordlets_criterr
	%forum_recentmeta %forum_topics %todays_active_topics

	%vars_ci %vars_config $vars_graemlins %vars_misc %vars_mods %vars_cats
	%vars_registration %vars_forums %vars_styles %vars_display %vars_style
	%vars_email %vars_time %vars_search %vars_pm %vars_pntf %vars_poll

	%vars_wordlets %vars_wordlets_err %vars_wordlets_email %vars_wordlets_pntf
	%vars_wordlets_img %vars_wordlets_date %vars_wordlets_poll

	%template_html %template_match

	$user_permissions $username $password $last_login_dt
	$session_login_dt $last_login_j $session_login_j $days_prune
	$pubname $user_topic_view $user_number @ubber @login @session

	$Header_Popup $Footer_Popup $TBB_Popup $TBT_Popup $ThisHTML $HeaderClean
	$FooterClean $CurrentTab $Hiddens $direct_to $Legend $LoginWording
	$MainButtonsLine $ContactLine $TBT $TBB $Header $Footer $EmailHeader
	$show_logout $show_logout_noreg $instant_jscript $title_wording

	$poll $PNTF $pntf_cookie_data

	$ULTIMATEBB $CONTROLPANEL $trademark $trade $InfopopCopyright
	$version $version_number $masterCharset $release_j $exact_path
	@memberslist $memlistopen $summary %member_profile
	%FILE_CACHE %GENERIC_GLOBALS $frontend $backend %ULTIMATEBB

	@benches
);

##################################################################################
# NOTE TO USERS WHO ARE RUNNING UBB.classic IN THE NON-WRITABLE CGI-BIN SITUATION:
# Modify the path in the following 'do' line to reflect the VariablesPath!
# There is NO NEED to modify this line unless you are using a different
# VariablesPath.  PLEASE use the UBB's CGI directory as the VariablesPath
# if at all possible.  Thanks.
##################################################################################

eval {
	do "vars_config.cgi";
};

&main::CheckDollarAt($@);

# No need to touch this now that we have the VariablesPath!
foreach my $file (qw(display misc email time search pm registration pntf poll ci template_match wordlets wordlets_err wordlets_img wordlets_date wordlets_pntf wordlets_poll)) {
	eval { require "$vars_config{VariablesPath}/vars_$file.cgi"; };
	&CheckDollarAt($@);
} # end foreach

eval {	require "$vars_config{CGIPath}/ubb_lib.cgi";	}; &CheckDollarAt($@);

#	&Bench("After vars_config & ubb_lib");

	&InitImportantStuff;	#ubb_lib

	&RequireCode("$vars_config{CGIPath}/ubb_lib_files.cgi");
	&RequireCode("$vars_config{CGIPath}/ubb_lib_time.cgi");
	&RequireCode("$vars_config{CGIPath}/ubb_lib_filehandler.cgi");
	&RequireCode("$vars_config{CGIPath}/ubb_lib_filehandle.cgi");

	# init our FileHandler object
	$filehandle = new UBB::FileHandler(\%vars_config, "global");

	# load our template routines
	&LoadTemplate("public_common");

#out in the middle of nowhere, we have a subroutine!
sub CheckDollarAt {
	my $error = shift;
	return unless $error;

	$masterCharset = "ISO-8859-1" unless $masterCharset;
	print header(
		-charset => "$masterCharset",
		-type    => "text/html",
	);

	print "<p><br />There was a compilation error while loading the UBB.classic"
	. " libraries and data files: <pre>\n$error</pre><br />"
	. " Please make sure that you uploaded the CGI and Variables files"
	. " to the proper directory, permissions are set properly on the files,"
	. " and that paths in the control panel are set correctly.</p>";
	exit;
}

tie(%ULTIMATEBB, 'UBB::TiedURL');

# Get our arguments
%in = map{
	my @z = param($_);
	( scalar(@z) > 1 ?
		( $_ => join(",", @z) ) :
		( $_ => $z[0] )
		)
	} param();

# See if we have any args in the path
my $pi = $ENV{PATH_INFO};
$pi = "" if($ENV{PATH_INFO} eq $ENV{SCRIPT_NAME});
if(!$pi && ($ENV{QUERY_STRING} =~ m/^\//)) {
	$pi = $ENV{QUERY_STRING};
} # end if
if($pi ne "") {
	my @args = split(/\//, $pi);
	shift @args; # first arg is always blank
	$args[-1] =~ s/\.html$// if @args;
	if(($args[0] eq "ubb") && (scalar(@args) % 2 == 0)) {
		# proper pairing
		%in = (@args, %in);
	} elsif(($args[0] eq "ubb") && (scalar(@args) % 2 == 1)) {
		# Sigh, we're missing an argument...
		pop @args; # so yank it
		%in = (@args, %in);
	} elsif($args[0] eq "topic") {
		%in = (
			ubb => "get_topic",
			f => $args[1],
			t => &Do6Digit($args[2]),
			p => $args[3],
			%in,
		);
	} elsif($args[0] eq "forum") {
		%in = (
			ubb => "forum",
			f => $args[1],
			hardset => $args[2],
			start_point => $args[3],
			%in,
		);
	} elsif($args[0] eq "profile") {
		%in = (
			ubb => "get_profile",
			u => &Do8Digit($args[1]),
			%in,
		);
	} elsif($args[0] eq "category") {
		%in = (
			ubb => "",
			category => $args[1],
			%in,
		);
	} elsif($args[0] eq "stnot") {
		%in = (
			ubb => "stop_notify",
			f => $args[1],
			t => &Do6Digit($args[2]),
			%in,
		);
	} # end if
} # end if

$backend = 0;
$frontend = 1;

my $templatefile = &DetermineDefaultTemplates($in{ubb});

#&Bench("After all reqs");

#print header;

if(defined $templatefile) {
#	print "TEMPLATEFILE: $templatefile<br />";
	$template_html{"CURRENT"} = $template_html{$templatefile};
	%vars_style = &LoadStyleTemplate($templatefile);
} else {
	$templatefile = "summary_page";
	%vars_style = &LoadStyleTemplate("summary_page");
} # end if
&LoadTemplate("public_common");
&InitImportantStuff;

# If we grabed a template file, reassign the character set
# Otherwise, $masterCharset is called in from ubb_lib
$masterCharset = $vars_style{thisCharset} if $vars_style{thisCharset};


# set main buttons options
$MainButtonsLine = &MainButtonOptions; # moved to public_common

# set date/time
&GetDateTime;

# counter
&hit_me;

# for misc actions --
$summary ||= 0;
my %deadhash = &LoadStyleTemplate("transition") if(($summary == 1) && ($template_match{"transition"} ne $template_match{"summary_page"}));
# intentional - just want to load it up

# now that we have our both our style template and
# public_common loaded, we can do nice errors again
set_message(\&StandardHTML2);

# check our Perl version
die &Template($vars_wordlets_criterr{old_perl}, {VERSION => $]}) if $] < 5.004;

# special case

#my $shutdownmessage = q{
#<p>Sorry, this bulletin board is unavailable.</p>
#<p>The server is currently overloaded with requests.  The bulletin board has
#automatically turned itself off to help bring the server load back down.</p>
#<p>Please retry your request in a few minutes.  Thank you for your paitence!</p>
#};
#
#if($^O =~ m/^linux$/i) {	# if we're on a Linux box, we can enable basic load protection
#	if(-e "$vars_config{NonCGIPath}/forceclosed.cgi") {
#		my $untiltime = &OpenFileAsString("$vars_config{NonCGIPath}/forceclosed.cgi");
#		if(time() > $untiltime) {
#			unlink("$vars_config{NonCGIPath}/forceclosed.cgi");
#		} else {
#			&StandardHTML($shutdownmessage);
#			exit;
#		} # end if
#	} else {
#		if(-r "/proc/loadavg") {
#			open(LOADAVERAGE, "</proc/loadavg");
#			my @data = split(/ /, <LOADAVERAGE>);
#			close(LOADAVERAGE);
#			if(($data[0] > 12.5) && ($data[2] > 7)) {
#				my $value = int(time() + 120 + rand(120));
#				&WriteFileAsString("$vars_config{NonCGIPath}/forceclosed.cgi", $value);
#				&StandardHTML($shutdownmessage);
#				exit;
#			} # end if
#		} # end if
#	} # end if
#} # end if


# standard argument
my $ubb = $in{ubb};
my $skip_cookie_check = "";
my $logoff = "";

#&Bench("Before ifs");

# perform user logoff?
if ($ubb &&(
	   (($ubb eq 'logoff') && !$vars_config{OCServer})
    	|| (($ubb eq 'logoff') && $vars_config{OCServer} && $vars_config{Groupee})
    	|| (($ubb eq 'oc_logoff') && $vars_config{OCServer})
	)) {
	$skip_cookie_check = 'true';
	my $cookieA = cookie(
		-name    => "ubber$vars_config{Cookie_Number}",
		-value   => ['', ''],
		-path    => '/',
		-expires => '-2y'
	);
	my $cookieB = cookie(
		-name    => "session$vars_config{Cookie_Number}",
		-value   => ['', ''],
		-path    => '/',
		-expires => '-2y'
	);
	my $cookieC = cookie(
		-name    => "forumpw$vars_config{Cookie_Number}",
		-value   => ['', ''],
		-path    => '/',
		-expires => '-2y'
	);
	my $cookieD = cookie(
		-name    => "groupee$vars_config{Cookie_Number}",
		-value   => ['', ''],
		-path    => '/',
		-expires => '-2y'
	);

	#print header(-cookie=>[$cookieA, $cookieB, $cookieC]);
	print header(
		-cookie  => [$cookieA, $cookieB, $cookieC, $cookieD, $pntf_cookie_data],
		-charset => "$masterCharset",
	);



	# confirm logoff
	&set_page_elements;
	if($vars_config{OCServer} && ($vars_config{Groupee} || $in{ON_COMPLETION_URL})) {
		&Transition(($in{ON_COMPLETION_URL} || $ULTIMATEBB{FORM}), $vars_wordlets{logged_off});
	} else {
		&StandardHTML($vars_wordlets{logged_off});
	} # end if
	exit(0);

}    # end logoff

if ($ubb && ($ubb eq 'clearcookies')) {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&clear_cookies;
	exit(0);
}    #end clearcookies

if ($ubb && ($ubb eq 'dumpcookies')) {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&dump_cookies;
	exit(0);
}    #end clearcookies


&RequireCode("$vars_config{CGIPath}/ubb_lib_secgroups.cgi");
&GetForumRecord(0);
$vars_groups = new UBB::SecurityGroups({
		'CONFIG' => \%vars_config,
		'FILEHANDLER' => $filehandle,
		'VARSFORUMS' => \%vars_forums,
		'VARSDISPLAY' => \%vars_display,
		'IN' => \%in});
$vars_groups->load_groups();

if($vars_pntf{Enabled} eq "yes") { # if we have PNTF enabled
	&RequireCode("ubb_lib_pntf.cgi");
	&RequireCode("ubb_lib_dumper.cgi");
	import Data::ThatWhichDumps;
	$PNTF = UBB::PNTF->new(\%vars_config, $filehandle, \%vars_pntf, \%vars_forums);
	$PNTF->load();

	my @pntf_cookie = cookie("PnTf_$vars_config{Cookie_Number}");
	my @ubber_cookie = cookie("ubber$vars_config{Cookie_Number}");

	my $thischeck = 0;
	if($ubber_cookie[0] && $ubber_cookie[4]) {
		my @up = &OpenProfile2($ubber_cookie[4]);
		if(!@up) {
			&StandardHTML($vars_wordlets_err{member_gone2});
		} # end if
		$user_permissions = new UBB::SecurityToken($vars_groups, $ubber_cookie[4], \@up, \%vars_forums, \%in, \%vars_misc);
		$thischeck = 1;
	} elsif($vars_display{MembersOnlyAccess} eq "NO") {
		$thischeck = 1;
	} # end if

	if($thischeck) {
		my @pntf_cookie_append = $PNTF->append(&GetIPAddress, \@pntf_cookie, \@ubber_cookie, \%in, undef, undef, $user_permissions);

		if($pntf_cookie_append[0] && ($pntf_cookie_append[0] ne '') && 	# Cookie has something and
		(($pntf_cookie_append[0] ne $pntf_cookie[0]) ||  # UNIQID differs
		($pntf_cookie_append[5] != $pntf_cookie[5]) ||	 # or hidden value differs
		($pntf_cookie_append[1] ne $pntf_cookie[1]) || 	 # or IP differs
		($pntf_cookie_append[3] ne $pntf_cookie[3])) ) { # or usernumber differs
			# then set the new cookie
			$pntf_cookie_data = cookie(
				-name    => "PnTf_$vars_config{Cookie_Number}",
				-value   => \@pntf_cookie_append,
				-path    => '/',
				-expires => '+12h'
			);
		} # end if
	} # end $thischeck
	$PNTF->write();	# closes the file
} # end if



if(($ubb eq 'markallread') || ($ubb eq "update_post_indicators")) {
	# This doesn't really mark all read
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&mark_all_read;
	exit(0);
}    #end update_post_indicators


if ($ubb eq 'forum_pw_check') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_forum.cgi");
	&forum_pw_check;
	exit(0);
}    #end forum_pw_check

# perform user login?
@ubber = (); # nuke cookie
if ($ubb eq 'do_login') {
	&GetOrPost("POST");
	my $ip_number = &GetIPAddress;
	&check_ip_bans($ip_number);

	$skip_cookie_check = 'true';

	&RequireCode("$vars_config{CGIPath}/ubb_lib_2.cgi");

	my @user_info = &verify_id("$in{username}", "$in{password}"); # -> lib_2!
	my $pubname   = $user_info[0];
	my $dp        = $user_info[1];
	my $profile_number = $user_info[2];
	my $mod_q          = $user_info[3];
	my @temp_profile = &OpenProfile($profile_number);
	my($writeadmin,$this_un,$this_pw) = @temp_profile[4,0,1];

	# Make sure user is approved...
	if ($mod_q eq 'Q') {
		print header(
			-charset => "$masterCharset",
			-type    => "text/html",
		);
		&StandardHTML("$vars_wordlets_err{awaiting_approval}");
		exit(0);
	} # end if

	# Make sure user is not banned
	if ($writeadmin !~ /Write/) {
		print header(
			-charset => "$masterCharset",
			-type    => "text/html",
		);
		&StandardHTML("$vars_wordlets_err{user_not_approved}");
		exit(0);
	} # end if

	# Update the user last login time & date
	my @last_seen = split(/\|\^\|/, $temp_profile[40]);
	if($last_seen[0] < $GotTime{YMDRunonDate}) {
		$last_seen[0] = $last_seen[2] = $GotTime{YMDRunonDate};
		$last_seen[1] = $last_seen[3] = &GetIPAddress;
		$temp_profile[40] = join("|^|", @last_seen);
		&WriteMemberProfile($profile_number, @temp_profile);
		&UpdateActDexLine($profile_number, $temp_profile[40], $temp_profile[30], $temp_profile[10], $temp_profile[33]);
	} # end if

	my $cookie = &MakeUBBERCookie($profile_number, \@temp_profile, ($in{remember_me} ? 0 : 1));
	$username = $in{username};

	# Make sure user feels logged in
	@ubber = $cookie->value;
	$user_number = $profile_number;
	print header(
		-cookie  => [$cookie, $pntf_cookie_data],
		-charset => "$masterCharset"
	);

	# display refer page
	my $clean_cgi = quotemeta("$vars_config{CGIURL}/ultimatebb.cgi");
	my $clean_non = quotemeta($ULTIMATEBB); # Accelerator
	if (($in{refer} ne '') && ($in{refer} !~ m/register|age/i) && ($in{refer} !~ /(logoff|cookies|find_lost|password)/)
		# Comment out the following line to allow redirects back to anywhere
		&& ($in{refer} =~ /^($clean_cgi|$clean_non)/)

		) {

		# take viewer back to topic
		&set_page_elements;
		&Transition("$in{refer}", "$vars_wordlets{thanks_for_login}", "$in{refer}");
		exit(0);
	} else {
		$ubb = '';
	}
}    # end do login

# retrieve cookies unless we just set'em
@ubber = @ubber ? @ubber : cookie("ubber$vars_config{Cookie_Number}");
if(@ubber && ($ubber[0])) {
	my @junk;
	($username, $password, $pubname, $user_topic_view, $user_number, @junk) = @ubber;
	$user_number =~ m/^(\d{8})$/; $user_number = $1; # untaint
} # end if


#make sure the user is not forging his cookie to get into a protected area
#if (($vars_display{MembersOnlyAccess} eq 'YES') && (@ubber)) {
if ((@ubber) && ($ubb ne "do_login")) {
	my @checkTheProfile = &verify_id_num_2($username, $password, $user_number);
	unless ($checkTheProfile[4] =~ /Write/) {
		print header(
			-charset => "$masterCharset",
		);
		&StandardHTML($vars_wordlets_err{user_not_approved});
	}

	# Yeah, really.
	my @temp_profile = &OpenProfile($user_number);
	my @last_seen = split(/\|\^\|/, $temp_profile[40]);
	if($last_seen[2] < $GotTime{YMDRunonDate}) {
		$last_seen[2] = $GotTime{YMDRunonDate};
		$last_seen[3] = &GetIPAddress;
		$last_seen[0] ||= $last_seen[2];
		$last_seen[1] ||= $last_seen[3];
		$temp_profile[40] = join("|^|", @last_seen);
		&WriteMemberProfile($user_number, @temp_profile);
		&UpdateActDexLine($user_number, $temp_profile[40], $temp_profile[30], $temp_profile[10], $temp_profile[33]);
	} # end if
} # end if

@login = cookie("login$vars_config{Cookie_Number}");
if ($login[0] ne '') { $last_login_dt = $login[0]; }
if ($login[1] ne '') { $last_login_j  = $login[1]; }

@session = cookie("session$vars_config{Cookie_Number}");
if ($session[0] ne '') { $session_login_dt = $session[0]; }
if ($session[1] ne '') { $session_login_j  = $session[1]; }

# in case this is a new visitor!
if ($last_login_dt eq '') { $last_login_dt = 'NEW'; }

# members only access check - OCServer
if(($vars_display{MembersOnlyAccess} eq 'YES') && $vars_config{OCServer}) {
	if(($username eq '') && !$in{ACTION}) {
		unless ($ubb =~ m/logout|logoff|login/) {
			my $qs = join("&", map { "$_=$in{$_}" } keys %in);
			$qs ||= "FORM";
			my $mrf = UBBCGI::escape($ULTIMATEBB{$qs});
			print redirect($ULTIMATEBB{"ubb=login&AUTO_LOGIN=N&ON_COMPLETION_URL=$mrf&__SHORT=1"});
			exit;
		} # end unless
	} # end if
} # end if

my $groupee_cookie = undef;
if($vars_config{OCServer}) {

	if($vars_config{Groupee} && ($ubb !~ m/login/) && ($ubb !~ m/logout/) && (!$in{ACTION})) {
		my @groupee_check = cookie("groupee$vars_config{Cookie_Number}");
		if(!$groupee_check[0] && $ubber[0] && !$ubber[10]) {
			# User is logged in, but lacks the Groupee verification cookie...
			&RequireCode("$vars_config{CGIPath}/ubb_occlient.cgi");
			my $v = &oc_groupee_remember_me_check;
			if($v == 1) {
				$skip_cookie_check = "";
				$groupee_cookie = cookie(
					-name  => "groupee$vars_config{Cookie_Number}",
					-value => [1],
					-path  => '/'
				);
			} else {
				# Redir user to login...
			} # end if
		} # end if
	} # end if

	if($ubb eq "login") {
		&RequireCode("$vars_config{CGIPath}/ubb_occlient.cgi");
		&oc_login;
	} elsif(($ubb eq "logoff") && !$vars_config{Groupee}) {
		&RequireCode("$vars_config{CGIPath}/ubb_occlient.cgi");
		&oc_logout;
	} elsif($in{ACTION} eq "LOGIN") {
		&RequireCode("$vars_config{CGIPath}/ubb_occlient.cgi");
		&oc_ping_ocserver;
	} elsif($in{ACTION} eq "GROUPEE_LOGIN") {
		&RequireCode("$vars_config{CGIPath}/ubb_occlient.cgi");
		&oc_ping_groupeeserver;
	} elsif($in{ACTION} eq "VERSION") {
		print header() . "20001105";
		exit;
	} elsif($in{ACTION} eq "PROFILE") {
		&RequireCode("$vars_config{CGIPath}/ubb_occlient.cgi");
		&oc_edit_profile;
	} elsif($ubb eq "agree") {
		&RequireCode("$vars_config{CGIPath}/ubb_occlient.cgi");
		&oc_register;
	} elsif($ubb =~ m/^do_login|check_age|register_page|underage_register_page|submit_registration|lost_password|find_lost$/) {
		# Do not wordletize
		&StandardHTML("That feature is not currently available.");
	} # end if
} # end if

# Ensure that the user has passed the TOS check...
if(@ubber && $user_number) {
	my @profile = &OpenProfile2($user_number);
	if($profile[0]) {
		my $prefs = unflatten_hash($profile[42]);
		if(($vars_registration{BBRulesEnforce} eq "ON") && ($in{ACTION} ne "LOGIN") && ($in{ubb} ne "agree_check") && ($in{ubb} ne "edit_my_profile") && ($in{ubb} ne "edit_profile") && ($in{ubb} ne "logoff") && ($in{ubb} ne "login")) {
			if($prefs->{tos_date} < $vars_registration{BBRulesDate}) {
				&Transition($ULTIMATEBB{"ubb=agree_check"},
				$vars_wordlets{agree_review_now}, $vars_wordlets{rules_title}, $vars_wordlets{transition_wording2});
				exit;
			} # end if
		} # end if
	} # end if
} # end if

# Allow to login before checking board status (thus allow admin to get in if admin-only mode)
if ($ubb eq 'login') {
	print header(
		-charset => "$masterCharset",
		-type    => "text/html",
	);
	&set_page_elements;
	&LoadTemplate("public_login");
	exit(0);
} # end if

# is forum closed?
if(($vars_misc{BBStatus} !~ /^ON/) && ((($ubb ne "avatar_select") || ($ubb ne "find_lost")) && ($in{cp} ne "cp"))) {
	my $isadm = ($username && &boolean_is_admin_or_mod(0, &OpenProfile($user_number) )) ? 1 : 0;
	my $isacl = ($vars_misc{BBStatus} =~ /ADMIN/) ? 1 : 0;
	my $ok = ($isadm && $isacl) ? 1 : 0;
	if(!$ok) {
		%vars_style = &LoadStyleTemplate("summary_page");
		&set_page_elements;

		print header(
			-charset => "$masterCharset",
			-type    => "text/html",
		);

		&StandardHTML("$vars_misc{BBClosedMessage}");
		exit(0);
	} # end if
} # end off check

# Once again...
%vars_style = &LoadStyleTemplate($templatefile);
&set_page_elements;

# set login cookie, if necessary

if ($skip_cookie_check ne 'true') {

	if ($session_login_dt eq '') {

		# set session cookie:
		# this is a temp cookie that stores previous last login

		my $cookie1 = cookie(
			-name  => "session$vars_config{Cookie_Number}",
			-value => [$last_login_dt, $last_login_j],
			-path  => '/'
		);

		# set new last login
		my $cookie2 = cookie(
			-name    => "login$vars_config{Cookie_Number}",
			-value   => [$GotTime{LastLoginDT}, $GotTime{LastLoginJulian}],
			-path    => '/',
			-expires => '+1y'
		);

		my $cookie3;
		if(@ubber && $username && $user_number) {
			if($ubber[11] ne $GENERIC_GLOBALS{ubber_cookie_version}) {
				my @prof = &OpenProfile($user_number);
				$cookie3 = &MakeUBBERCookie($user_number, \@prof, ($ubber[10] ? 1 : 0));
			} # end if
		} # end if

		#print header(-cookie=>[$cookie1, $cookie2, $cookie3]);
		print header(
			-cookie  => [$cookie1, $cookie2, $cookie3, $pntf_cookie_data, $groupee_cookie],
			-charset => "$masterCharset"
		);

	} elsif(@ubber && $username && $user_number && ($ubber[11] ne $GENERIC_GLOBALS{ubber_cookie_version})) {
		my @prof = &OpenProfile($user_number);
		my $cookie3 = &MakeUBBERCookie($user_number, \@prof, ($ubber[10] ? 1 : 0));

		print header(
			-cookie  => [$cookie3, $pntf_cookie_data, $groupee_cookie],
			-charset => "$masterCharset"
		);
	} else {

		unless ($ubb =~ m/^(check_age|agree_check|submit_new_reply|submit_new_topic|submit_registration|edit_profile)$/) {

			#print qq%Content-type: text/html\n\n%;
			print header(
				-cookie  => [$pntf_cookie_data, $groupee_cookie],
				-charset => "$masterCharset",
				-type    => "text/html",
			);
		} # end unless
	} # end if
}    #if not do_login

# members only access check
if ($vars_display{MembersOnlyAccess} eq 'YES') {
	if (($username eq '') || ($logoff eq 'true')) {
		unless ($ubb =~ m/^(avatar_select|check_age|agree|register_page|underage_register_page|submit_registration|lost_password|find_lost)$/) {
			%vars_style = &LoadStyleTemplate("transition");
			&set_page_elements;
			&LoadTemplate("public_login");
			exit(0);
		}
	}
}

# all ubb options:
$ubb = "" unless $ubb;

if(($username && $user_number) && (!$user_permissions)) {
	# Yay, security groups!
	my @ur = &OpenProfile($user_number);
	$user_permissions = new UBB::SecurityToken($vars_groups, $user_number, \@ur, \%vars_forums, \%in, \%vars_misc);
} # end if

#die $user_permissions->has_permission("user_title", "define");

# forum summary
if ($ubb eq '') {
	if(defined $vars_display{UseForumAsFsum}) {
		$ubb = "forum";
		$in{f} = $vars_display{UseForumAsFsum};
	} else {
		&RequireCode("$vars_config{CGIPath}/ubb_forum_summary.cgi");
		&forum_summary;
		exit(0);
	} # end if
} # end if

if ($ubb eq 'agree') {
	&RequireCode("$vars_config{CGIPath}/ubb_registration.cgi");
	&do_agree;
	exit(0);
}    #end agree

if ($ubb eq 'agree_review') {
	&RequireCode("$vars_config{CGIPath}/ubb_registration.cgi");
	&agree_review;
	exit(0);
}    #end agree

if ($ubb eq 'agree_check') {
	&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
	&agree_check;
	exit(0);
}    #end agree

if ($ubb eq 'check_age') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_registration.cgi");
	&check_age;
	exit(0);
}    #end check_age

if ($ubb eq 'register_page') {
#	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_registration.cgi");
	&register_page("no");
	exit(0);
}    #end register_page

if ($ubb eq 'underage_register_page') {
	&GetOrPost("POST");
	if ($vars_registration{COPPAType} eq 'COPPADenied') {
		&StandardHTML("$vars_wordlets_err{age_deny}");
	} elsif ($vars_registration{COPPACheck} ne 'ON') {
		&StandardHTML("$vars_wordlets_err{coppa_turned_off}");
	} else {
		&RequireCode("$vars_config{CGIPath}/ubb_registration.cgi");
		&show_coppa_form();
	} # end if
	exit(0);
}    #end underage_register_page

if ($ubb eq 'show_coppa_form') {
	if ($vars_registration{COPPAType} eq 'COPPADenied') {
		&StandardHTML("$vars_wordlets_err{age_deny}");
	} elsif ($vars_registration{COPPACheck} ne 'ON') {
		&StandardHTML("$vars_wordlets_err{coppa_turned_off}");
	} else {
		&RequireCode("$vars_config{CGIPath}/ubb_registration.cgi");
		&show_coppa_form();
	} # end if

	exit(0);
}    #end show_coppa_form

if ($ubb eq 'submit_registration') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_registration.cgi");
	&submit_registration;
	exit(0);
}    #end submit_reg

if ($ubb eq 'forum') {

	if ($in{f} =~ /CAT:/) {

		my($j, $cat_number) = split (/:/, $in{f});
		$in{category} = $cat_number;
		delete $in{f};
		&RequireCode("$vars_config{CGIPath}/ubb_forum_summary.cgi");
		&forum_summary;
	} else {
		&RequireCode("$vars_config{CGIPath}/ubb_forum.cgi");
		&get_forum;
	}
	exit(0);
}    # end forum

if ($ubb eq 'rate_member') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
	&rate_member;
	exit(0);
}    #end rate_member

if ($ubb eq 'email') {
	&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
	&email_user;
	exit(0);
}    #end email

if ($ubb eq 'edit_my_profile') {
	&RequireCode( "$vars_config{CGIPath}/ubb_profile.cgi");
	&edit_my_profile;
	exit(0);
}    #end edit_my_profile

if ($ubb eq 'my_profile') {
	&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
	&my_profile;
	exit(0);
}    #end my_profile

if ($ubb eq 'my_rating_list') {
	&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
	&my_rating_list;
	exit(0);
}    #end my_rating_list

if ($ubb eq "recent_user_posts") {
	&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
	&recent_user_posts;
	exit(0);
}    #end recent_user_posts

if ($ubb eq 'get_profile') {
	&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
	&get_profile;
	exit(0);
}    #end get_profile

if ($ubb eq 'edit_profile') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
	&edit_profile;
	exit(0);
}    #end edit_profile

if ($ubb eq 'avatar_select') {
	&GetOrPost("GET");
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&avatar_select_menu;
	exit(0);
}    #end avatar_select



if ($ubb eq 'preview_post') {
	#&GetOrPost("GET");
	&RequireCode("$vars_config{CGIPath}/ubb_lib_posting.cgi");
	&preview_post;
	exit(0);
}    #end submit_new_topic

if($ubb eq "poll") {
	&RequireCode("$vars_config{CGIPath}/ubb_poll.cgi");
	&poll_dispatch;
	exit(0);
} # end poll

if ($ubb eq 'newtopic') {
	&RequireCode("$vars_config{CGIPath}/ubb_new_topic.cgi");
	&new_topic_page;
	exit(0);
}    #end newtopic

if ($ubb eq 'submit_new_topic') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_new_topic.cgi");
	&submit_new_topic;
	exit(0);
}    #end submit_new_topic

if ($ubb eq 'get_topic') {
	&RequireCode("$vars_config{CGIPath}/ubb_get_topic.cgi");
	&get_topic($in{f}, $in{t});
	exit(0);
}    #end get_topic

if ($ubb eq 'print_topic') {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&this_is_not_print_preview($in{f}, $in{t});
	exit(0);
}    #end get_topic

if ($ubb eq 'reply') {
	&RequireCode("$vars_config{CGIPath}/ubb_new_reply.cgi");
	&reply_page;
	exit(0);
}    #end reply

if ($ubb eq 'submit_new_reply') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_new_reply.cgi");
	&submit_new_reply;
	exit(0);
}    #end submit_new_reply

if ($ubb eq 'get_pm') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&get_pm;
	exit(0);
}    #end get_pm

if ($ubb eq 'sent_pms') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&sent_pm_box;
	exit(0);
}    #end get_pm


if ($ubb eq 'private_message') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&private_message;
	exit(0);
}    #end private_message

if ($ubb eq 'submit_private_message') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&submit_pm;
	exit(0);
}    #end submit_pm

if ($ubb eq 'pm_prune') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_prune;
	exit(0);
}    #end pm_prune

if ($ubb eq 'pm_delete') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_delete;
	exit(0);
}    #end pm_delete

if ($ubb eq 'pm_reply') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_reply;
	exit(0);
}    # end pm_reply

if ($ubb eq 'submit_pm_reply') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&submit_pm_reply;
	exit(0);
}    #end submit_pm_reply

if ($ubb eq 'ignore_list') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_list('ignore');
	exit(0);
}    #end ignore_list

if ($ubb eq 'buddy_list') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_list('buddy');
	exit(0);
}    #end buddy_list

if ($ubb eq 'do_ignore') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_do_list('ignore');
	exit(0);
}    #end do_ignore

if ($ubb eq 'do_buddy') {
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_do_list('buddy');
	exit(0);
}    #end do_buddy

if ($ubb eq 'update_ignore') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_update_list('ignore');
	exit(0);
}    #end update_ignore

if ($ubb eq 'update_buddy') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_pm.cgi");
	&pm_update_list('buddy');
	exit(0);
}    #end update_buddy

if ($ubb eq 'get_ip') {
	&RequireCode("$vars_config{CGIPath}/ubb_get_topic.cgi");
	&get_ip;
	exit(0);
}    #end get_ip

if ($ubb eq 'delete_topic') {
	&RequireCode("$vars_config{CGIPath}/ubb_topic_maint.cgi");
	&delete_topic;
	exit(0);
}    #end delete_topic

if (($ubb eq 'close_topic') || ($ubb eq 'open_topic')) {
	&RequireCode("$vars_config{CGIPath}/ubb_topic_maint.cgi");
	&topic_open_close;
	exit(0);
}    #end close_topic/open_topic

if ($ubb eq 'stick_topic') {
	&RequireCode("$vars_config{CGIPath}/ubb_topic_maint.cgi");
	&stick_topic;
	exit(0);
}    #end stick topic

if ($ubb eq 'unstick_topic') {
	&RequireCode("$vars_config{CGIPath}/ubb_topic_maint.cgi");
	&unstick_topic;
	exit(0);
}    #end unstick topic


if ($ubb eq 'next_topic') {
	&RequireCode("$vars_config{CGIPath}/ubb_get_topic.cgi");
	&next_topic;
	exit(0);
}    #end next_topic

if (($ubb eq 'transfer') || ($ubb eq 'transfer_topic')) {
	&RequireCode("$vars_config{CGIPath}/ubb_topic_maint.cgi");
	&transfer_topic;
	exit(0);
}    #end transfer

if ($ubb eq 'edit_post') {
	&RequireCode("$vars_config{CGIPath}/ubb_edit_post.cgi");
	&edit_post;
	exit(0);
}    #end edit_post

if ($ubb eq 'submit_edit') {
	&GetOrPost("POST");
	&RequireCode("$vars_config{CGIPath}/ubb_edit_post.cgi");
	&submit_edit;
	exit(0);
}    #end submit_edit

if ($ubb eq 'get_daily') {
	&RequireCode("$vars_config{CGIPath}/ubb_search.cgi");
	&get_daily;
	exit(0);
}    #end get_daily

unless($vars_search{AllowSearch} ne "TRUE") {
	if ($ubb eq 'search') {
		&RequireCode("$vars_config{CGIPath}/ubb_search.cgi");
		&search;
		exit(0);
	} elsif($ubb eq 'search_tng') {
		&RequireCode("$vars_config{CGIPath}/ubb_search.cgi");
		&search_tng_dispatch;
		exit(0);
	}    #end search
} #end check for search disabled

if ($ubb eq 'send_topic') {
	&GetOrPost("POST") if $in{send_it};
	&RequireCode("$vars_config{CGIPath}/ubb_friend.cgi");
	&send_topic;
	exit(0);
}    #end send_topic

if ($ubb eq 'faq') {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&faq;
	exit(0);
}    #end faq

if ($ubb eq 'ubb_code_page') {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&ubb_code_page;
	exit(0);
}    #end ubb_code_page

if ($ubb eq 'lost_password') {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&lost_password;
	exit(0);
}    #end lost_password

if ($ubb eq 'find_lost') {
	&GetOrPost("POST") unless(($in{cp} eq "cp") && ($ENV{HTTP_REFERER} =~ m/$CONTROLPANEL/));
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&find_lost;
	exit(0);
}    #end find_lost

if ($ubb eq 'report_a_post') {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&report_a_post;
	exit(0);
}    #end report_a_post

if ($ubb eq 'stop_notify') {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&stop_notify;
	exit(0);
}    #end stop_notify

if ($ubb eq 'edit_notify') {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&edit_notify;
	exit(0);
}    #end edit_notify

if ($ubb eq 'graemlin_list') {
	&RequireCode("$vars_config{CGIPath}/ubb_lib_misc.cgi");
	&graemlin_list;
	exit(0);
}    #end graemlin_list

if($vars_pntf{Enabled} eq "yes") {
	# Standard display
	if($ubb eq "pntf") {
		&RequireCode("$vars_config{CGIPath}/ubb_pntf.cgi");
		&pntf_html;
	} # end pntf

	# The *GOOD* stuff!
	if($ubb eq "pntf_admin") {
		&RequireCode("$vars_config{CGIPath}/ubb_pntf.cgi");
		&pntf_admin;
	} # end pntf
} # end if

if($vars_display{EnableDirectory} ne "no") {
	if($ubb eq "directory") {
		&RequireUserLogin if $vars_display{EnableDirectory} eq "regonly";
		&RequireCode("$vars_config{CGIPath}/ubb_profile.cgi");
		&member_directory;
	} # end if
} # end if

%vars_style = &LoadStyleTemplate("transition");
# default error-- obviously they do not know where they are going
&StandardHTML("$vars_wordlets_err{dead_end}");

exit(0);    # comply with SafePerl

#END {
#	print header();
#	print "<hr /><pre>" . &DeBench . "</pre><hr />";
#}

# $Id: ultimatebb.cgi,v 1.89.2.1 2004/05/25 22:58:40 cvscapps Exp $
