#!/usr/bin/perl --

###############################################################################
# YaBB.pl                                                                     #
###############################################################################
# YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2 RC 1                                                 #
# Released:       December 27, 2004                                           #
# Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== #
# Copyright (c) 2000-2005 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by: The YaBB Development Team                                      #
#              with assistance from the YaBB community.                       #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #
#               Your source for web hosting, web design, and domains.         #
###############################################################################


### Version Info ###
$YaBBversion = 'YaBB 2 RC 1';
$YaBBplver = 'YaBB 2 RC 1 $Revision: 1.26 $';

if($action eq 'detailedversion') { return 1; }


# Used for bundled perl modules, if they are not installed
# Some servers do not like one or the other.
# make sure one has a # before it, and the other one doesn't
# Using both at the same time can cause trouble...

push(@INC, "./Modules");
#use lib "./Modules";


if( $ENV{'SERVER_SOFTWARE'} =~ /IIS/ ) {
	$yyIIS = 1;
	$0 =~ m~(.*)(\\|/)~;
	$yypath = $1;
	$yypath =~ s~\\~/~g;
	chdir($yypath);
	push(@INC,$yypath);
}

### Requirements and Errors ###
require "Paths.pl";

if (eval "require Time::HiRes"){ 
	use Time::HiRes qw(time); #benchmarking
	$START_TIME = time;
}

require "Settings.pl";
require "$vardir/modsettings.txt";
require "$vardir/membergroups.txt";
require "$sourcedir/Subs.pl";
require "$sourcedir/DateTime.pl";
require "$sourcedir/Load.pl";


&LoadCookie;		# Load the user's cookie (or set to guest)
&LoadUserSettings;	# Load user settings
&WhatTemplate;		# Figure out which template to be using.
&WhatLanguage;		# Figure out which language file we should be using! :D

require "$sourcedir/Guardian.pl";
&guard;

if($referersecurity){
	&referer_check; 	# check if the action is allowed from an external domain
}
my $inactsize = -s "$memberdir/memberlist.inactive";
if ((-e "$memberdir/memberlist.inactive") && $inactsize > 2 && $preregister){
	require "$sourcedir/Register.pl";
	&activation_check;
}
require "$boardsdir/forum.master"; 
require "$sourcedir/Security.pl";
require "$vardir/Smilies.txt";

&banning;		# Check for banned people
&WriteLog;		# Write to the log
&LoadIMs;		# Load IM's

$action = $INFO{'action'};
$SIG{__WARN__} = sub { &fatal_error( "@_" ); };
eval { &yymain; };
if ($@) { &fatal_error("Untrapped Error:<br />$@"); }

sub yymain {
#### Choose what to do based on the form action ####
if ($maintenance == 1) {
 if ($action eq 'login2') { require "$sourcedir/LogInOut.pl"; &Login2; }
 if ( !$iamadmin ) { require "$sourcedir/Maintenance.pl"; &InMaintenance; }
}
### Guest can do the very few following actions.
if($iamguest && $guestaccess == 0) {
	if(!(($action eq 'login') || ($action eq 'login2') || ($action eq 'register') || ($action eq 'register2') || ($action eq 'reminder') || ($action eq 'reminder2') || ($action eq 'validate') || ($action eq 'activate') || ($action eq 'resetpass'))) { &KickGuest; }
}

if ($action ne "") {
	require "$sourcedir/SubList.pl";
	if ($director{$action}) {
		@act = split(/&/,$director{$action});
		$aa = $act[1];
		require "$sourcedir/$act[0]"; &$aa;
	} else { require "$sourcedir/BoardIndex.pl"; &BoardIndex; }
}
elsif($INFO{'num'} ne "") { require "$sourcedir/Display.pl"; &Display; }
elsif($currentboard eq "") { require "$sourcedir/BoardIndex.pl"; &BoardIndex; }
else { require "$sourcedir/MessageIndex.pl"; &MessageIndex; }

exit;
}
