#!/usr/bin/perl

###################################################################
#                                                                 #
# CuteCast(R) V2.0 Beta 2                                         #
# Written by Danny Damianus                                       #
# Copyright (c) 2001-2003 ArtsCore Studios                        #
# All Rights Reserved.                                            #
# Visit us at http://www.artscore.net                             #
# _______________________________________________________________ #
#                                                                 #
# Policies:                                                       #
# By using this software, you agree to the terms outlined in our  #
# policies located at our website.                                #
#                                                                 #
# All third party modifications is unsupported. This is NOT an    #
# open source software product.                                   #
#                                                            .... #
# Technical Support:                                              #
# If you have any question, opinion, suggestions, or any other    #
# comments, please visit our community forums at:                 #
#                                                                 #
# http://www.artscore.net/cgi-bin/cutecast/cutecast.pl            #
#                                                            .... #
# Liability:                                                      #
# The author of this software will not take responsibility for    #
# any damage that may result from the use of this software.       #
# The files contained in CuteCast are distributed "as is" and     #
# without any expressed and implied warranties. The user assumes  #
# the entire risk of using the software.                          #
#                                                                 #
###################################################################

$cutecast_fullpath = '.';

#$cookie_path = '/cgi-bin/cutecast/';

$dir_languages = "$cutecast_fullpath/languages";
$dir_data = "$cutecast_fullpath/data/forum";
$dir_data_sub = "$cutecast_fullpath/data/subthreads/";
$dir_data_pm = "$cutecast_fullpath/data/private/";
$dir_data_newsletters = "$cutecast_fullpath/data/newsletters/";
$dir_hits = "$cutecast_fullpath/data/hits/";
$dir_temp = "$cutecast_fullpath/data/temp";
$dir_txt = "$cutecast_fullpath/txt";
$dir_users = "$cutecast_fullpath/users/";
$dir_users_backup = "$cutecast_fullpath/users/backup";
require "$cutecast_fullpath/lib/ac_lib.cgi";
require "$cutecast_fullpath/lib/ac_input.cgi";
require "$cutecast_fullpath/lib/ac_output.cgi";
require "$cutecast_fullpath/lib/ac_visual.cgi";
&decode_input;
&loading;
require "$dir_languages/$myprofile{language}/ac_words.var";
# -------------------------- Begin XTC Usercrash Hack ------------------------- #
# Setup: Wie oft soll automatisch geprüft werden?
# Angabe erfolgt in Tagen z.b. alle "2" Tage = $crashcheck= 2;

$crashcheck= 1;

# ----------------------------------------------------------------------------- #
# Begin crashfiles check
# ----------------------------------------------------------------------------- #

use File::Copy;

if (-f "$dir_txt/crashboard.txt") {

$crashcheck1=24*60*60;
$crashcheck2=$crashcheck*$crashcheck1;

@crashtime = stat("$dir_txt/crashboard.txt");
$crashrd = time();
$crashrd-= $crashtime[9];

@crashdate = (localtime($crashtime[9]))[3..5];
$crashdatum1 = sprintf("%02s.%02s.%04s",$crashdate[0],$crashdate[1]+1,$crashdate[2]+1900);
$xrd=int($crashrd/$crashcheck1);
if($xrd >= $crashcheck) {

# Grep users
opendir(DIR,"$dir_users");
@usr_files = grep {/^.*(\.user$)/i} readdir DIR;
closedir(DIR);

	foreach $datei (@usr_files) {
	$groesse = -s "$dir_users$datei";

		if ((!-f "$dir_users_backup/$datei") && (-f "$dir_users$datei") && ($groesse > 500)) {
		copy("$dir_users$datei","$dir_users_backup/$datei");
		}

		if ($groesse <= 500) {
		copy("$dir_users_backup/$datei","$dir_users$datei");
		}
	}
&file_kill("$dir_txt/crashboard.txt");
$timenow = &decode_time(0,$thetime,1);
&file_write("$dir_txt/crashboard.txt");
print FILE "$crashdatum1|$timenow\n";
&file_close(1);
}
}

# ----------------------------------------------------------------------------- #
# End crashfiles check
# ----------------------------------------------------------------------------- #

# Backup option II
if (-f "$dir_txt/crashboard.txt") { $crashboard = 1; }

my $xtcuserid = &get_userid($myprofile{username});
&get_data('xtctmpsession',"$dir_users_backup/$xtcuserid.user");
my $xtctmpsession = "$xtctmpsession{session}";
my $xtcsession = "$myprofile{session}";

# ----------------------------------------------------------------------------- #
# Begin backup option II
# ----------------------------------------------------------------------------- #

if (($myprofile{username} ne "Guest") && ($xtcsession ne $xtctmpsession) && ($crashboard eq "1")) {
unless (-d "$dir_users_backup") {
mkdir("$dir_users_backup") || &message(cutecast_error);
chmod(0777, "$dir_users_backup");

# Backup all users
opendir(DIR,"$dir_users");
@files = grep {/^.*(\.user$)/i} readdir DIR;
closedir(DIR);

foreach (@files) {
copy("$dir_users$_","$dir_users_backup/$_");
chmod(0666, "$dir_users_backup/$_");
}
}

# Backup userfile
copy("$dir_users$xtcuserid.user","$dir_users_backup/$xtcuserid.user");

# Chmod backup userfile
chmod(0666, "$dir_users_backup/$xtcuserid.user");
}

# ----------------------------------------------------------------------------- #
# End backup option II
# ----------------------------------------------------------------------------- #


# --------------------------- End XTC Usercrash Hack -------------------------- #
if (-e "$cutecast_fullpath/whyoff.txt" && $input{action} !~ /^admin$/i) {
	@data = &read_data("$cutecast_fullpath/whyoff.txt");
	$data[1] = &decode_html($data[1]);
#	$data[1] = &decode_emoticons($data[1]);
	$data[1] = &decode_cutecode($data[1]);
	$print_html_two = qq~
		<TR>
			<TD>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=100%>
	<TBODY>
		<TR>
			<TD><font class=hbtext>$data[0]</font></TD>
		</TR>
	</TBODY>
</TABLE>
			</TD>
		</TR>
~;
	$print_html_three = qq~
		<TR>
			<TD class=boxb>
<TABLE border=0 cellPadding=4 cellSpacing=1 width=100%>
	<TBODY>
		<TR>
			<TD class=boxone><font class=ntext>$data[1]</font></TD>
		</TR>
	</TBODY>
</TABLE>
			</TD>
		</TR>
~;
$print_html_six = "<a href=\"$cutecast{bbsurl}?session=$input{session}&action=admin\">$var_word{admin_enter_here}</a>";
$print_html_eight = "$cutecast{bbsname} - CuteCast Message";
&print_cutecast;
}
elsif ($cutecast{memberonly} && $myprofile{whoareyou} && $input{action} !~ /^register$/i && $input{action} !~ /^help$/i) {&message('not_login','#0#');}
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
	if (!-e "$cutecast_fullpath/lib/ac_x$input{action}.cgi") {&message(cutecast_error);}
	require "$cutecast_fullpath/lib/ac_x$input{action}.cgi";
	&input;
}
else {
	if ($input{action}) {
		if (!-e "$cutecast_fullpath/lib/ac_x$input{action}.cgi") {&message(cutecast_error);}
		require "$cutecast_fullpath/lib/ac_x$input{action}.cgi";
	}
	else {
		if ($input{forum}) {
			if ($input{thread}) {require "$cutecast_fullpath/lib/ac_thread.cgi";}
			else {require "$cutecast_fullpath/lib/ac_forum.cgi";}
		}
		else {require "$cutecast_fullpath/lib/ac_forums.cgi";}
	}
	&output;
}
