#!/usr/bin/perl

#use CGI::Carp qw(fatalsToBrowser);
use CGI::Carp "fatalsToBrowser";          # Output errors to browser
use CGI qw(:standard);                    # Saves loads of work
$CGI::POST_MAX=1024 * 150;                # limit post data
$CGI::DISABLE_UPLOADS = 1;                # Disable uploads

###############################################################################
# YaBB.pl                                                                     #
###############################################################################
# Yet another Bulletin Board (http://www.yabb.com.ru)                         #
# Open Source project started by Zef Hemel (zef@zefnet.com)                   #
# =========================================================================== #
# Copyright (c) The YaBB Programming team                                     #
# =========================================================================== #
# This file has been written by: Zef Hemel                                    #
###############################################################################
require "Settings.pl";
require "$settingsdir/optik.pl";
require "$settingsdir/einstell.pl";
require "$sourcedir/Subs.pl";
require "$sourcedir/Subsb.pl";
require "$vardir/newsontop.txt";
require "$vardir/memstat.pl";
require "$sourcedir/counter.cgi";
require "../Sources/german.lng";

$LOCK_EX = 2;
$LOCK_UN = 8;
$webmaster_email = "$webmaster_email1\@$webmaster_email2";

$Cookie_Exp_Date = 'Tue, 31-Jan-2034 12:00:00 GMT';
&get_date;
&readform;
$currentboard = $INFO{'board'};
if ($INFO{'board'} =~ /\//){ &fatal_error("The board field does not accept / in the query string" ); }
if ($INFO{'board'} =~ /\\/){ &fatal_error("The board field does not accept \\ in the query string" ); }
$cgi = "$boardurl/YaBB.pl\?board=$currentboard";
if ($poll_enabled eq "1") {
	open(CURRENTPOLL, "$boarddir/poll/current.poll");
	$poll_thema_cookie = <CURRENTPOLL>;
	close(CURRENTPOLL);
	$poll_thema_cookie =~ s/[\n\r]//g;
}
foreach (split(/; /,$ENV{'HTTP_COOKIE'})) {
        ($cookie,$value) = split(/=/);
        if($cookie eq "$cookieusername") { $username="$value"; }
        if($cookie eq "$cookiepassword") { $password="$value"; }
        if ($poll_enabled eq "1") {
        	if($cookie eq "$poll_thema_cookie") { $curr_poll_cookie="$value"; }
	}
}
if($username eq "") { $username = "Guest"; }

# Load user settings
if($username ne "Guest") {
        open(FILE, "$memberdir/$username.dat");
        &lock(FILE);
        @settings=<FILE>;
        &unlock(FILE);
        close(FILE);
        $settings[0] =~ s/\n//g;
        if($settings[0] ne $password) {
               if($action ne "logout") {&fatal_error("$txt{'39'}"); }
        }
                $settings[0] =~ s/[\n\r]//g;
                $settings[1] =~ s/[\n\r]//g;
                $settings[2] =~ s/[\n\r]//g;
                $settings[3] =~ s/[\n\r]//g;
                $settings[4] =~ s/[\n\r]//g;
                $settings[5] =~ s/[\n\r]//g;
                $settings[6] =~ s/[\n\r]//g;
                $settings[7] =~ s/[\n\r]//g;
                $settings[8] =~ s/[\n\r]//g;
                $settings[9] =~ s/[\n\r]//g;
                $settings[10] =~ s/[\n\r]//g;
                $settings[11] =~ s/[\n\r]//g;
                $settings[12] =~ s/[\n\r]//g;
                $settings[13] =~ s/[\n\r]//g;
                $settings[14] =~ s/[\n\r]//g;
                $settings[15] =~ s/[\n\r]//g;
        $realname="$username";
        $realemail = "$settings[2]";
}

# Write log
open(LOG, "$vardir/log.txt");
&lock(LOG);
@entries = <LOG>;
&unlock(LOG);
close(LOG);

open(LOG, ">$vardir/log.txt");
&lock(LOG);
$field="$username";
if($field eq "Guest") { $field = "$ENV{'REMOTE_ADDR'}"; }
print LOG "$field\|$logdate\|$date\|$username\|$INFO{'board'}\|$INFO{'action'}\|$INFO{'username'}\|$INFO{'num'}\n";
foreach $curentry (@entries) {
        $curentry =~ s/\n//g;
        ($name, $value, $name1, $name2, $name3, $name4, $name5, $name6) = split(/\|/, $curentry);
        $date1="$value";
        $date2="$logdate";
        &calctime;
        if($name ne "$field" && $result <= 2 && $result >= 0 && $name ne "$ENV{'REMOTE_ADDR'}") {
                print LOG "$curentry\n";
        }
}
&unlock(LOG);
close(LOG);

# Load board information
if($currentboard ne "") {

        open(FILE, "$boardsdir/$currentboard.dat");
        &lock(FILE);
        @boardinfo=<FILE>;
        &unlock(FILE);
        close(FILE);

        $boardinfo[0] =~ s/[\n\r]//g;
        $boardinfo[2] =~ s/[\n\r]//g;
        $boardname = "$boardinfo[0]";

        # Create Hash %moderators with all Moderators of the current board

        foreach(split(/\|/,$boardinfo[2])) {

                $moderators{$_} = "$_";
        }

}

# Depending on on the action field choose what to do
if ($action eq "setgen") { require "$sourcedir/setgen.pl"; &Setgen; }
if ($action eq "sendgen") { require "$sourcedir/setgen.pl"; &Sendgen; }
if ($action eq "setoptik") { require "$sourcedir/setoptik.pl"; &SetOptik; }
if ($action eq "sendoptik") { require "$sourcedir/setoptik.pl"; &SendOptik; }
if ($action eq "managecats") { require "$sourcedir/ManageCats.pl"; &ManageCats; }
if ($action eq "modifycatorder") { require "$sourcedir/ManageCats.pl"; &ReorderCats; }
if ($action eq "removecat") { require "$sourcedir/ManageCats.pl"; &RemoveCat; }
if ($action eq "createcat") { require "$sourcedir/ManageCats.pl"; &CreateCat; }
if ($action eq "modcat") { require "$sourcedir/ManageCats.pl"; &ModCat; }
if ($action eq "manageboards") { require "$sourcedir/ManageBoards.pl"; &ManageBoards; }
if ($action eq "reorderboards") { require "$sourcedir/ManageBoards.pl"; &ReorderBoards; }
if ($action eq "reorderboards2") { require "$sourcedir/ManageBoards.pl"; &ReorderBoards2; }
if ($action eq "modifyboard") { require "$sourcedir/ManageBoards.pl"; &ModifyBoard; }
if ($action eq "addboard") { require "$sourcedir/ManageBoards.pl"; &CreateBoard; }
if ($action eq "admin") { require "$sourcedir/Admin.pl"; &Admin; }
if ($action eq "viewmembers") { require "$sourcedir/Admin.pl"; &ViewMembers; }
if ($action eq "mailing") { require "$sourcedir/Admin.pl"; &MailingList; }
if ($action eq "ml") { require "$sourcedir/Admin.pl"; &ml; }
if ($action eq "editnews") { require "$sourcedir/Admin.pl"; &EditNews; }
if ($action eq "editnews2") { require "$sourcedir/Admin.pl"; &EditNews2; }
if ($action eq "editnews3") { require "$sourcedir/Subsb.pl"; &Edit_member_news; }
if ($action eq "editnews4") { require "$sourcedir/Subsb.pl"; &Edit_member_news2; }
if ($action eq "modmemgr") { require "$sourcedir/Admin.pl"; &EditMemberGroups; }
if ($action eq "modmemgr2") { require "$sourcedir/Admin.pl"; &EditMemberGroups2; }
if ($action eq "modmemgr3") { require "$sourcedir/Admin.pl"; &EditMemberGroups3; }
if ($action eq "modmemgr4") { require "$sourcedir/Admin.pl"; &EditMemberGroups4; }
if ($action eq "modmemgr5") { require "$sourcedir/Admin.pl"; &EditMemberGroups5; }
if ($action eq "setreserve") { require "$sourcedir/Admin.pl"; &SetReserve; }
if ($action eq "setreserve2") { require "$sourcedir/Admin.pl"; &SetReserve2; }
if ($maintenance == 1) { require "$sourcedir/Maintenance.pl"; &InMaintenance; }
if ($action eq "icqpager") { require "$sourcedir/ICQPager.pl"; &IcqPager; }
if ($action eq "reminder") { require "$sourcedir/Reminder.pl"; &Reminder; }
if ($action eq "reminder2") { require "$sourcedir/Reminder.pl"; &Reminder2; }
if ($action eq "display") { require "$sourcedir/Display.pl"; &Display; }
if ($action eq "copy") { require "$sourcedir/Copy.pl"; &Copy; }
if ($action eq "post") { require "$sourcedir/Post.pl"; &Post; }
if ($action eq "post2") { require "$sourcedir/Post.pl"; &Post2; }
if ($action eq "rewritten") { require "$sourcedir/rewritten.pl"; &rewritten; }
if ($action eq "setsmp") { &setsmp; }
if ($action eq "changemode") { &setmode; }
if ($action eq "changemv") { &setmv; }
if ($action eq "setcensor") { require "$sourcedir/Admin.pl"; &SetCensor; }
if ($action eq "setcensor2") { require "$sourcedir/Admin.pl"; &SetCensor2; }
if ($action eq "oldnews") { require "$sourcedir/Admin.pl"; &oldnews; }
if ($action eq "movethread") { require "$sourcedir/MoveThread.pl"; &MoveThread; }
if ($action eq "setmem") { require "$sourcedir/Subsb.pl"; &setmem; }
if ($action eq "sendmem") { require "$sourcedir/Subsb.pl"; &sendmem; }
if ($action eq "movethread2") { require "$sourcedir/MoveThread.pl"; &MoveThread2; }
if ($action eq "notify") { require "$sourcedir/Notify.pl"; &Notify; }
if ($action eq "notify2") { require "$sourcedir/Notify.pl"; &Notify2; }
if ($action eq "notify3") { require "$sourcedir/Notify.pl"; &Notify3; }
if ($action eq "removeoldthreads") { require "$sourcedir/RemoveOldThreads.pl"; &RemoveOldThreads; }
if ($action eq "lock") { require "$sourcedir/LockThread.pl"; &LockThread; }
if ($action eq "register") { require "$sourcedir/Register.pl"; &Register; }
if ($action eq "haftung") { require "$sourcedir/haftung.pl"; &haftung; }
if ($action eq "register2") { require "$sourcedir/Register.pl"; &Register2; }
if ($action eq "help") { require "$sourcedir/Help.pl"; &Help; }
if ($action eq "login") { require "$sourcedir/LogInOut.pl"; &Login; }
if ($action eq "login2") { require "$sourcedir/LogInOut.pl"; &Login2; }
if ($action eq "logout") { require "$sourcedir/LogInOut.pl"; &Logout; }
if ($action eq "removethread") { require "$sourcedir/RemoveThread.pl"; &RemoveThread; }
if ($action eq "removethread2") { require "$sourcedir/RemoveThread.pl"; &RemoveThread2; }
if ($action eq "modify") { require "$sourcedir/ModifyMessage.pl"; &ModifyMessage; }
if ($action eq "modify2") { require "$sourcedir/ModifyMessage.pl"; &ModifyMessage2; }
if ($action eq "profile") { require "$sourcedir/Profile.pl"; &ModifyProfile; }
if ($action eq "profile2") { require "$sourcedir/Profile.pl"; &ModifyProfile2; }
if ($action eq "viewprofile") { require "$sourcedir/Profile.pl"; &ViewProfile; }
if ($action eq "im") { require "$sourcedir/InstantMessage.pl"; &IMIndex; }
if ($action eq "imprefs") { require "$sourcedir/InstantMessage.pl"; &IMPreferences; }
if ($action eq "imprefs2") { require "$sourcedir/InstantMessage.pl"; &IMPreferences2; }
if ($action eq "imoutbox") { require "$sourcedir/InstantMessage.pl"; &IMOutbox; }
if ($action eq "imremove") { require "$sourcedir/InstantMessage.pl"; &IMRemove; }
if ($action eq "imsend") { require "$sourcedir/InstantMessage.pl"; &IMPost; }
if ($action eq "imsend2") { require "$sourcedir/InstantMessage.pl"; &IMPost2; }
if ($action eq "mlall") { require "$sourcedir/Memberlist.pl"; &MLAll; }
if ($action eq "mlletter") { require "$sourcedir/Memberlist.pl"; &MLByLetter; }
if ($action eq "mltop") { require "$sourcedir/Memberlist.pl"; &MLTop; }
if ($action eq "who") { require "$sourcedir/who.pl"; &who; }
if ($action eq "search") { require "$sourcedir/Search.pl"; &SearchForm; }
if ($action eq "search2") { require "$sourcedir/Search.pl"; &DoSearch; }
if ($action eq "search3") { require "$sourcedir/Search.pl"; &DisplayResults; }
if ($action eq "markasread") { require "$sourcedir/MessageIndex.pl"; &MarkRead; }
if ($action eq 'markallasread') { require "$sourcedir/Subsb.pl"; &MarkAllRead; }
if ($action eq "modifytemplate") { require "$sourcedir/modifytemplate.pl"; &modifytemplate; }
if ($action eq "savetemplate") { require "$sourcedir/modifytemplate.pl"; &savetemplate; }
if ($action eq "credits") { require "$sourcedir/credits.pl"; &credits; }
if ($action eq "meldung") { require "$sourcedir/Subsb.pl"; &meldung; }
if ($action eq "setup") { require "$sourcedir/Setup.pl"; &Setup; }
if ($action eq "Setsave") { require "$sourcedir/Setup.pl"; &Setsave; }
if ($action eq "poll") { require "$sourcedir/poll.pl"; }
if ($action eq "setpoll") { require "$sourcedir/setpoll.pl";}
if ($action eq "modifyKarma"){ require "$sourcedir/Karma.pl"; &modifyKarma; }

if ($action eq "chat") { require "$sourcedir/chat.pl"; &chat; }
#-----------------------------------------------------------------------------


&guest_login;
# In no board specified display board index
if ($currentboard eq "") { require "$sourcedir/BoardIndex.pl"; &BoardIndex; }
# No action? Show the message index
require "$sourcedir/MessageIndex.pl";
&MessageIndex;

exit;
