F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\YaBB.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\YaBB.pl
#!/usr/bin/perl -- #!/usr/bin/perl --
  # $Id: YaBB Main$
  # $HeadURL: YaBB $
  # $Revision: 1651 $
  # $Source: /YaBB.pl $
############################################################################### ###############################################################################
# YaBB.pl                                                                     # # YaBB.pl                                                                     #
  # $Date: 01.05.16 $                                                           #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5.2                                                  # # Version:        YaBB 2.6.12                                                 #
# Packaged:       October 21, 2012                                            # # Packaged:       January 5, 2016                                             #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2016 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
############################################################################### ###############################################################################
  #use strict;
  no warnings qw(uninitialized once redefine);
  use CGI::Carp qw(fatalsToBrowser);
  use English qw(-no_match_vars);
  our $VERSION = '2.6.12';
   
### Version Info ### ### Version Info ###
$YaBBversion = 'YaBB 2.5.2';  $YaBBversion = 'YaBB 2.6.12'; 
$YaBBplver = 'YaBB 2.5.2 $Revision: 1.1 $'; $yabbplver   = 'YaBB 2.6.12 $Revision: 1651 $';
   
if ($action eq 'detailedversion') { return 1; }  
   
# use CGI::Carp qw(fatalsToBrowser); # used only for tests  if ( $action eq 'detailedversion' ) { return 1; } 
   
BEGIN { BEGIN {
     # Make sure the module path is present  
     push(@INC, "./Modules");  
   
     if ($ENV{'SERVER_SOFTWARE'} =~ /IIS/) {     # Make sure the module path is present 
           $yyIIS = 1;     push @INC, './Modules'; 
           $0 =~ m~(.*)(\\|/)~;  
     if ( $ENV{'SERVER_SOFTWARE'} =~ /IIS/sm ) {
         $yyIIS = 1;
         if ( $PROGRAM_NAME =~ m{(.*)(\\|/)}xsm ) {
           $yypath = $1;            $yypath = $1;
           $yypath =~ s~\\~/~g;         } 
           chdir($yypath);         $yypath =~ s/\\/\//gxsm; 
           push(@INC, $yypath);         chdir $yypath; 
     }         push @INC, $yypath; 
     }
     $yyexec = "YaBB";  
     $script_root = $ENV{'SCRIPT_FILENAME'};     $yyexec      = 'YaBB'; 
     if( ! $script_root ) {     $script_root = $ENV{'SCRIPT_FILENAME'}; 
     if ( !$script_root ) {
       $script_root = $ENV{'PATH_TRANSLATED'};        $script_root = $ENV{'PATH_TRANSLATED'};
       $script_root =~ s/\\/\//gxsm;     } 
     }     $script_root =~ s/\/$yyexec\.(pl|cgi)//igxsm; 
     $script_root =~ s/\/$yyexec\.(pl|cgi)//ig;  
     require Paths;
     require "Paths.pl";     require Variables::Settings; 
     require "$vardir/Settings.pl";  
     # Check for Time::HiRes if debugmodus is on
     # Check for Time::HiRes if debugmodus is on     if ($debug) { 
     if ($debug) { eval { require Time::HiRes; import Time::HiRes qw(time); }; }         eval { require Time::HiRes; import Time::HiRes qw(time); }; 
     $START_TIME = time();     } 
     $START_TIME = time;
     require "$sourcedir/Subs.pl";  
     require "$sourcedir/System.pl";     require './Sources/Subs.pm'; 
     require "$sourcedir/DateTime.pl";     require Sources::System; 
     require "$sourcedir/Load.pl";     require Sources::DateTime; 
     require Sources::Load;
     require "$sourcedir/Guardian.pl";  
     require "$boardsdir/forum.master";     require Sources::Guardian; 
} # END of BEGIN block     get_forum_master(); 
  }    # END of BEGIN block
   
# If enabled: check if hard drive has enough space to safely operate the board # If enabled: check if hard drive has enough space to safely operate the board
my $hostchecked = &freespace;  if ($checkspace) { 
     require Sources::Freespace;
     $hostchecked = freespace();
  }
   
# Auto Maintenance Hook # Auto Maintenance Hook
$maintenance = 2 if !$maintenance && -e "$vardir/maintenance.lock";  if ( !$maintenance && -e "$vardir/maintenance.lock" ) { $maintenance = 2; } 
   
&LoadCookie;       # Load the user's cookie (or set to guest) LoadCookie();          # Load the user's cookie (or set to guest)
&LoadUserSettings; # Load user settings LoadUserSettings();    # Load user settings
&WhatTemplate;     # Figure out which template to be using. WhatTemplate();        # Figure out which template to be using.
&WhatLanguage;     # Figure out which language file we should be using! :D WhatLanguage();        # Figure out which language file we should be using! :D
   
# Do this now that language is available # Do this now that language is available
$yyfreespace = $hostchecked < 0 ? $error_txt{'module_missing'} : (($yyfreespace && (($debug == 1 && !$iamguest) || ($debug == 2 && $iamgmod) || $iamadmin)) ? qq~<div>~ . ($hostchecked > 0 ? $maintxt{'freeuserspace'} : $maintxt{'freediskspace'}) . qq~ $yyfreespace</div>~ : '');  $yyfreespace = 
     $hostchecked < 0
   ? $error_txt{'module_missing'}
   : (
     (
         $yyfreespace && ( ( $debug == 1 && !$iamguest )
             || ( $debug == 2 && $iamgmod )
             || $iamadmin )
     )
     ? q~<div>~
       . (
         $hostchecked > 0 ? $maintxt{'freeuserspace'} : $maintxt{'freediskspace'}
       )
       . qq~ $yyfreespace</div>~
     : q{}
   );
   
if (-e "$vardir/gmodsettings.txt" && $iamgmod) { require "$vardir/gmodsettings.txt"; }  if ( -e "$vardir/gmodsettings.txt" && $iamgmod ) { 
if (!$masterkey) {     require "$vardir/gmodsettings.txt"; 
     if ($iamadmin || ($iamgmod && $allow_gmod_admin eq 'on' && $gmod_access{"newsettings\;page\=security"} eq 'on')) {  } 
           $yyadmin_alert = $reg_txt{'no_masterkey'};  if ( !$masterkey ) { 
     }     if ( 
     $masterkey = $mbname;         $iamadmin 
         || (   $iamgmod
             && $allow_gmod_admin eq 'on' 
             && $gmod_access{'newsettings;page=security'} eq 'on' )
       )
     {
         $yyadmin_alert = $reg_txt{'no_masterkey'};
     }
     $masterkey = $mbname;
} }
   
$formsession = &cloak("$mbname$username");  $formsession = cloak("$mbname$username"); 
   
# check for valid form sessionid in any POST request # check for valid form sessionid in any POST request
if ($ENV{REQUEST_METHOD} =~ /post/i) { if ( $ENV{REQUEST_METHOD} =~ /post/ism ) {
     if ($CGI_query && $CGI_query->cgi_error()) { &fatal_error("denial_of_service", $CGI_query->cgi_error()); }     if ( $CGI_query && $CGI_query->cgi_error() ) { 
     if (&decloak($FORM{'formsession'}) ne "$mbname$username") {         fatal_error( 'denial_of_service', $CGI_query->cgi_error() ); 
           &fatal_error("logged_in_already",$username) if $action eq 'login2' && $username ne 'Guest';     } 
           &fatal_error("form_spoofing",$user_ip);     if ( decloak( $FORM{'formsession'} ) ne "$mbname$username" ) { 
     }         if ( $action eq 'login2' && $username ne 'Guest' ) { 
             fatal_error( 'logged_in_already', $username );
         }
         fatal_error( 'form_spoofing', $user_ip );
     }
} }
   
if ($is_perm && $accept_permalink) { if ( $is_perm && $accept_permalink ) {
     &fatal_error("no_topic_found","$permtitle|C:$permachecktime|T:$threadpermatime") if $permtopicfound == 0;     if ( $permtopicfound == 0 ) { 
     &fatal_error("no_board_found","$permboard|C:$permachecktime|T:$threadpermatime") if $permboardfound == 0;         fatal_error( 'no_topic_found', 
             "$permtitle|C:$permachecktime|T:$threadpermatime" );
     }
     if ( $permboardfound == 0 ) {
         fatal_error( 'no_board_found',
             "$permboard|C:$permachecktime|T:$threadpermatime" );
     }
} }
   
&guard;  guard(); 
   
# Check if the action is allowed from an external domain # Check if the action is allowed from an external domain
if ($referersecurity) { &referer_check; } if ($referersecurity) { referer_check(); }
   
if ($regtype == 1 || $regtype == 2) { if ( $regtype == 1 || $regtype == 2 ) {
     if (-s "$memberdir/memberlist.inactive" > 2) {     $inactive = -s "$memberdir/memberlist.inactive"; 
           &RegApprovalCheck; &activation_check;     $approve = -s "$memberdir/memberlist.approve"; 
     } elsif (-s "$memberdir/memberlist.approve" > 2) {    if ( $inactive > 2 ) {
           &RegApprovalCheck;         RegApprovalCheck(); 
     }         activation_check(); 
     }
     elsif ( $approve > 2 ) {
         RegApprovalCheck();
     }
} }
   
require "$sourcedir/Security.pl";  require Sources::Security; 
   
&banning;  # Check for banned people  
&LoadIMs;  # Load IM's  
&WriteLog; # write into the logfile  
   
$SIG{__WARN__} = sub { &fatal_error("error_occurred","@_"); };  banning();     # Check for banned people 
eval { &yymain; };  LoadIMs();     # Load IM's 
if ($@) { &fatal_error("untrapped",":<br />$@"); }  WriteLog();    # write into the logfile 
  SearchAccess();
   
  local $SIG{__WARN__} = sub { fatal_error( 'error_occurred', "@_" ); };
  eval { yymain(); };
  if ($@) { fatal_error( 'untrapped', ":<br />$@" ); }
   
sub yymain { sub yymain {
     # Choose what to do based on the form action  
     if ($maintenance) {     # Choose what to do based on the form action 
     #admin login issues with sessions and maintenance mode fix.     if ($maintenance) { 
           if ( ($iamadmin || $iamgmod ) && $sessionvalid == 0 ) {&UpdateCookie("delete"); require "$sourcedir/LogInOut.pl"; &InMaintenance; };  
           if    ($action eq 'login2')    { require "$sourcedir/LogInOut.pl"; &Login2; }         #admin login issues with sessions and maintenance mode fix. 
           if (!$iamadmin) { require "$sourcedir/LogInOut.pl"; &InMaintenance; }         if ( $staff && $sessionvalid == 0 ) { 
     }             UpdateCookie('delete'); 
             require Sources::LogInOut;
     # Guest can do the very few following actions             InMaintenance(); 
     &KickGuest if $iamguest && !$guestaccess && $action !~ /^(login|register|reminder|validate|activate|resetpass|guestpm|checkavail|$randaction)2?$/;         } 
         if ( $action eq 'login2' ) {
     if ($action ne "") {             require Sources::LogInOut; 
           if ($action eq $randaction) {             Login2(); 
                 require "$sourcedir/Decoder.pl"; &convert;         } 
           } else {         if ( !$iamadmin ) { require Sources::LogInOut; InMaintenance(); } 
                 require "$sourcedir/SubList.pl";     } 
                 if ($director{$action}) {  
                       my @act = split(/&/, $director{$action});     # Guest can do the very few following actions 
                       require "$sourcedir/$act[0]";     if (   $iamguest 
                       &{$act[1]};         && !$guestaccess 
                 } else {         && $action !~ 
                       require "$sourcedir/BoardIndex.pl";  /^(login|register|reminder|validate|activate|resetpass|guestpm|checkavail|$randaction)2?$/xsm 
                       &BoardIndex;       ) 
                 }     { 
         KickGuest();
     }
   
     if ( $action ne q{} ) {
         if ( $action eq $randaction ) {
             require Sources::Decoder;
             convert();
         }
         else {
             require Sources::SubList;
             if ( $director{$action} ) {
                 my @act = split /&/xsm, $director{$action};
                 require "$sourcedir/$act[0]";
                 &{ $act[1] };
             }
             else {
                 require Sources::BoardIndex;
                 BoardIndex();
           }            }
     } elsif ($INFO{'num'} ne "") {         } 
           require "$sourcedir/Display.pl";     } 
           &Display;     elsif ( $INFO{'num'} ne q{} ) { 
     } elsif ($currentboard eq "") {         require Sources::Display; 
           require "$sourcedir/BoardIndex.pl";         Display(); 
           &BoardIndex;     } 
     } else {    elsif ( $currentboard eq q{} ) {
           require "$sourcedir/MessageIndex.pl";         require Sources::BoardIndex; 
           &MessageIndex;         BoardIndex(); 
     }    }
     else {
         require Sources::MessageIndex;
         MessageIndex();
     }
     return;
} }
   
# Those who write software only for pay should go hurt some other field.  1; 
# - Erik Naggum  
   
1;