###############################################################################
# Subs.pl #
###############################################################################
# YaBB: Yet another Bulletin Board #
# Open-Source Community Software for Webmasters #
# Version: YaBB 2.4 #
# Packaged: April 12, 2009 #
# Distributed by: http://www.yabbforum.com #
# =========================================================================== #
# Copyright (c) 2000-2009 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. #
###############################################################################
$subsplver = 'YaBB 2.4 $Revision$';
if ($debug) { &LoadLanguage('Debug'); }
use subs 'exit';
$yymain = '';
$yyjavascript = '';
$langopt = '';
# set line wrap limit in Display.
$linewrap = 80;
$newswrap = 0;
# get the current date/time
$date = int(time() + $timecorrection);
# check if browser accepts encoded output
$gzaccept = $ENV{'HTTP_ACCEPT_ENCODING'} =~ /\bgzip\b/ || $gzforce;
# parse the query string
&readform;
$uid = substr($date, length($date) - 3, 3);
$session_id = $cookiesession_name;
$randaction = substr($date,0,length($date)-2);
$user_ip = $ENV{'REMOTE_ADDR'};
if ($user_ip eq "127.0.0.1") {
if ($ENV{'HTTP_CLIENT_IP'} && $ENV{'HTTP_CLIENT_IP'} ne "127.0.0.1") { $user_ip = $ENV{'HTTP_CLIENT_IP'}; }
elsif ($ENV{'X_CLIENT_IP'} && $ENV{'X_CLIENT_IP'} ne "127.0.0.1") { $user_ip = $ENV{'X_CLIENT_IP'}; }
elsif ($ENV{'HTTP_X_FORWARDED_FOR'} && $ENV{'HTTP_X_FORWARDED_FOR'} ne "127.0.0.1") { $user_ip = $ENV{'HTTP_X_FORWARDED_FOR'}; }
}
# comment out (#) the next line if you have problems with
# 'Reverse DNS lookup timeout causes slow page loads'
# Search Engine identification and display will be turned off
$user_host = (gethostbyaddr(pack("C4", split(/\./, $user_ip)), 2))[0];
if (-e "$GLOBAL::EXEC.cgi") { $yyext = "cgi"; }
else { $yyext = "pl"; }
if (-e "AdminIndex.cgi") { $yyaext = "cgi"; }
else { $yyaext = "pl"; }
sub automaintenance {
my $maction = $_[0];
my $mreason = $_[1];
if (lc($maction) eq "on") {
&write_DBorFILE(0,'',$vardir,'maintenance','lock',(qq~Remove this file if your board is in maintenance for no reason\n~));
if ($mreason eq "low_disk"){
&LoadLanguage('Error');
&alertbox($error_txt{'low_diskspace'});
}
$GLOBAL::SETTING::maintenance = 2 if !$GLOBAL::SETTING::maintenance;
} elsif (lc($maction) eq "off") {
&delete_DBorFILE("$vardir/maintenance.lock") || &fatal_error("cannot_open_dir","$vardir/maintenance.lock");
$GLOBAL::SETTING::maintenance = 0 if $GLOBAL::SETTING::maintenance == 2;
}
}
sub exit {
local $| = 1;
local $\ = '';
print '';
wait if $child_pid;
CORE::exit($_[0] || 0);
}
sub print_output_header {
$headerstatus ||= '200 OK';
$contenttype ||= 'text/html';
my $ret = $yyIIS ? "HTTP/1.0 $headerstatus\n" : "Status: $headerstatus\n";
foreach ($yySetCookies1,$yySetCookies2,$yySetCookies3) { $ret .= "Set-Cookie: $_\n" if $_; }
if ($yySetLocation) {
$ret .= "Location: $yySetLocation";
} else {
$ret .= "Cache-Control: no-cache, must-revalidate\nPragma: no-cache\n" if !$cachebehaviour;
$ret .= "ETag: \"$ETag\"\n" if $ETag;
$ret .= "Last-Modified: $LastModified\n" if $LastModified;
$ret .= "Content-Encoding: gzip\n" if $gzcomp && $gzaccept;
$ret .= "Content-Type: $contenttype";
$ret .= "; charset=$yycharset" if $yycharset;
}
print $ret . "\r\n\r\n";
}
sub print_HTML_output_and_finish {
if ($gzcomp && $gzaccept) {
my $filehandle_exists = fileno GZIP;
if ($gzcomp == 1 || $filehandle_exists) {
$| = 1;
open(GZIP, "| gzip -f") unless $filehandle_exists;
print GZIP $output;
close(GZIP);
} else {
require Compress::Zlib;
binmode STDOUT;
print Compress::Zlib::memGzip($output);
}
} else {
print $output;
}
exit;
}
sub write_cookie {
my %params = @_;
if ($params{'-expires'} =~ /\+(\d+)m/) {
my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($date + $1 * 60);
$year += 1900;
my @mos = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
my @dys = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
$mon = $mos[$mon];
$wday = $dys[$wday];
$params{'-expires'} = sprintf("%s, %02i-%s-%04i %02i:%02i:%02i GMT", $wday, $mday, $mon, $year, $hour, $min, $sec);
}
$params{'-path'} = " path=$params{'-path'};" if $params{'-path'};
$params{'-expires'} = " expires=$params{'-expires'};" if $params{'-expires'};
"$params{'-name'}=$params{'-value'};$params{'-path'}$params{'-expires'}";
}
sub redirectexit {
$headerstatus = '302 Moved Temporarily';
&print_output_header;
exit;
}
sub redirectinternal {
if ($currentboard) {
if ($INFO{'num'}) { require "$sourcedir/Display.pl"; &Display; }
else { require "$sourcedir/MessageIndex.pl"; &MessageIndex; }
} else {
require "$sourcedir/BoardIndex.pl";
&BoardIndex;
}
}
sub template {
&print_output_header;
if ($yytitle ne $maintxt{'error_description'}) {
if (!$iamguest || ($iamguest && $guestaccess == 1)) { $yyforumjump = &jumpto; }
}
$yyposition = $yytitle;
$yytitle = "$mbname - $yytitle";
$yyimages = $imagesdir;
$yydefaultimages = $defaultimagesdir;
my $forumstylesurl = "$yyhtml_root/$templatesdir/Forum";
$yystyle = qq~\n~;
$yystyle =~ s~$usestyle\/~~g;
$yystyle .= qq~\n~;
$yystyle .= $yyinlinestyle; # This is for the Help Center and anywhere else that wants to add inline CSS.
$yysyntax_js = qq~
~;
# add 'back to top' Button on the end of each page
$yynavback .= qq~
~ if !$yynavback;
$yynavback .= qq~ $img_txt{'102'}
~;
if (!$usehead) { $usehead = "default"; }
$output = join('', &read_DBorFILE(0,'',"$templatesdir/$usehead",$usehead,'html'));
if ($iamadmin || $iamgmod) {
if ($GLOBAL::SETTING::maintenance) { $yyadmin_alert .= qq~
$load_txt{'616'}~; }
if ($iamadmin && $rememberbackup) {
if ($lastbackup && $date > $rememberbackup + $lastbackup) {
$yyadmin_alert .= qq~
$load_txt{'617'} ~ . &timeformat($lastbackup) . qq~~;
}
}
}
$yyboardname = "$mbname";
$yyboardlink = qq~$mbname~;
# static/dynamic clock
$yytime = &timeformat($date, 1);
if ($mytimeselected != 7 && (($iamguest && $dynamic_clock) || ${$uid.$username}{'dynamic_clock'})) {
$yytime =~ /(.*?)\d+:\d+((\w+)|:\d+)?/;
my ($a,$b) = ($1,$3);
$a =~ s/<.+?>//g;
$b = ' ' if $mytimeselected == 6;
$yytime = qq~ ~;
$yyjavascript .= qq~\n\nvar OurTime = ~ . sprintf("%d", ($date + (3600 * $toffs))) . qq~000;\nvar YaBBTime = new Date();\nvar TimeDif = YaBBTime.getTime() - (YaBBTime.getTimezoneOffset() * 60000) - OurTime - 1000; // - 1000 compromise to transmission time~;
}
if ($output =~ /\{yabb tabmenu\}/) {
require "$sourcedir/TabMenu.pl";
&mainMenu;
} else {
$yymenu = qq~$img{'home'}$menusep$img{'help'}~;
# remove search from menu if disabled by the admin
if ($maxsearchdisplay > -1) {
$yymenu .= qq~$menusep$img{'search'}~;
}
if (!$ML_Allowed || ($ML_Allowed == 1 && !$iamguest) || ($ML_Allowed == 2 && $staff) || ($ML_Allowed == 3 && ($iamadmin || $iamgmod))) {
$yymenu .= qq~$menusep$img{'memberlist'}~;
}
# EventCal START
if ($Show_EventButton == 2 || (!$iamguest && $Show_EventButton == 1)) {
$yymenu .= qq~$menusep$img{'eventcal'}~;
}
if ($Show_BirthdayButton == 2 || (!$iamguest && $Show_BirthdayButton == 1)) {
$yymenu .= qq~$menusep$img{'birthdaylist'}~;
}
# EventCal END
if ($iamadmin) { $yymenu .= qq~$menusep$img{'admin'}~; }
if ($iamgmod) {
if (-e ("$vardir/gmodsettings.txt")) {
require "$vardir/gmodsettings.txt";
}
if ($allow_gmod_admin) { $yymenu .= qq~$menusep$img{'admin'}~; }
}
if ($sessionvalid == 0 && !$iamguest) {
my $sesredir;
unless (!$testenv || $GLOBAL::ACTION eq "revalidatesession" || $GLOBAL::ACTION eq "revalidatesession2") {
$sesredir = $testenv;
$sesredir =~ s/\=/\~/g;
$sesredir =~ s/;/x3B/g;
$sesredir = qq~;sesredir=$sesredir~;
}
$yymenu .= qq~$menusep$img{'sessreval'}~;
}
if ($iamguest) {
my $sesredir;
if ($testenv) {
$sesredir = $testenv;
$sesredir =~ s/\=/\~/g;
$sesredir =~ s/;/x3B/g;
$sesredir = qq~;sesredir=$sesredir~;
}
$yymenu .= qq~$menusep1)alert('$maintxt{'35'}');jumptologin++;window.scrollTo(0,10000);document.loginform.username.focus();" : "$scripturl?action=login$sesredir") . qq~">$img{'login'}~;
if ($regtype != 0) { $yymenu .= qq~$menusep$img{'register'}~; }
if ($PMenableGuestButton && $PM_level > 0 && $PMenableBm_level > 0) {
$yymenu .= qq~$menusep$img{'pmadmin'}~; }
} else {
## pointing towards pm now
$yymenu .= qq~$menusep$img{'mycenter'}~;
$yymenu .= qq~$menusep$img{'logout'}~;
}
}
$yylangChooser = "";
if (($iamguest && !$guestLang) && $enable_guestlanguage && $guestaccess) {
if (!$langopt) {&guestLangSel;}
if ($morelang > 1) {
$yylangChooser = qq~$guest_txt{'sellanguage'}: