###############################################################################
# backupcenter.pl #
###############################################################################
# YaBB XXL: Yet another Bulletin Board XXL #
# Beta Version - Please make a backup before using this Mod #
# by Homey beta 7/Beta 8 by DummyProof #
# #
###############################################################################
$backupcenterplver = "1 Gold - SP1.1";
#############################################################
%bckuptxt=(
'01' => "Absolute Path of the Dir you want to backup:",
'02' => "Absolute Path of the Dir where backup should be stored:",
'03' => "Add Time Stamp to Filename?",
'04' => "Backup Frequency:",
'05' => "Send Backup File Via E-Mail?",
'06' => "E-Mail Backup To:",
'07' => "OPEN",
'08' => "Delete Backup after E-Mail?",
'09' => "Backup Settings",
'10' => "Here you can edit the settings of your Backup System. Please enter the absolute path and not the URL for directories!!! Note: The E-Mail could be very large. Be sure your E-mail provider has allowable space.",
'11' => "Never",
'12' => "Daily",
'13' => "Weekly",
'14' => "Monthly",
'15' => "Backup Now?",
'16' => "Configure Backup Settings",
'17' => "Last Backup File Created On/Filename:",
'18' => "[ Return to Backup Center ]",
'19' => "does not exist! Please enter a valid directory.",
'20' => "Backup didn't happen. An error was returned by the System. Please check your settings.",
'21' => "Backup File",
'22' => "Attached is the Backup of",
'23' => "Error in Mailing Program! File Backup is done but not send via E-Mail",
'24' => "Ok, Backup is done and sent via E-Mail to",
'25' => "BACKUPFILE WAS DELETED FROM SERVER AFTER MAILING",
'26' => "Ok, Backup is done.
Files Archived to",
'27' => "Bytes",
'28' => "Filename:",
'29' => "File Size is",
'30' => "Files Archived to",
'31' => "Could not open",
'32' => "There are no Backup files in the designated Backup directory.",
'33' => "Delete",
'34' => "Delete All",
'35' => "Manage Backup Files",
'36' => "View and/or delete current backup files which are stored in your designated Backup directory. Download a Backup file by clicking on the desired \"Backup Filename\".",
'37' => "List of Backups Currently Available",
'38' => "Backup Filename",
'39' => "File Size",
'40' => "Date Created",
'41' => "Are you sure you want to Delete all Backups?",
'42' => "Yes",
'43' => "No",
'44' => "Current Settings for Backups"
);
#############################################################
require "$vardir/backupsettings.pl";
if(-e "$sourcedir/Lite.pm"){
require "$sourcedir/Lite.pm";
$yesmail = '';
} else {
$yesmail = " disabled";
$nolite = "(Lite.pm is missing from the Sources dir.)";
}
# =============================================================================
# Here we show the Backup Controlcenter
# =============================================================================
sub backupcenter {
&is_admin;
my($time_check, $via_mail_check, $backupdelcheck);
# figure out what to print
if ($time_stemp) { $time_check = "checked" }
if ($send_via_mail) { $via_mail_check = "checked" }
if ($backupdel) { $backupdelcheck = "checked" }
# Get date and filename of last backup
fopen(FILE, "$vardir/lastbackup.txt");
@backupinfo = ;
fclose(FILE);
($last_reminder, $ml_month, $ml_yearday, $lbinfo, $lfname) = split(/\|/, @backupinfo[0]);
if ($lbinfo eq '') {
$lbinfo2 = "N";
$lfname = "A";
} else {
$lbinfo2 = &timeformat($lbinfo);
}
$yymain .= qq~
~;
$yytitle = $bckuptxt{'09'};
&template;
exit;
}
# =============================================================================
# Here we update the settings File for Backupsystem
# =============================================================================
sub Modifybusettings {
&is_admin;
my @onoff = qw/time_stemp send_via_mail backupdel/;
# Set as 0 or 1 if box was checked or not
my $fi;
map { $fi = lc $_; ${$_} = $FORM{$fi} eq 'on' ? 1 : 0; } @onoff;
# If empty fields are submitted, set them to default-values to save yabb from crashing
$backupdir = $FORM{'backupdir'} || "$boarddir";
$backupto = $FORM{'backupto'} || "$boarddir/Backups";
$backup_frequency = $FORM{'busend_frequency'} || 0;
$backuptoemail = $FORM{'backuptoemail'} || "$webmaster_email";
#Lets make sure the dirs exist
if (!-d "$backupdir"){&fatal_error("$backupdir $bckuptxt{'19'}");}
if (!-d "$backupto"){&fatal_error("$backupto $bckuptxt{'19'}");}
my $filler = q~ ~;
my $setfile = << "EOF";
###############################################################################
# Backupsettings.pl #
###############################################################################
# Path and Config Settings
\$backupdir = '$backupdir';
\$backupto = '$backupto';
\$backup_frequency = $backup_frequency;
\$time_stemp = $time_stemp;
\$send_via_mail = $send_via_mail;
\$backupdel = $backupdel;
\$backuptoemail = q^$backuptoemail^;
1;
EOF
$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n " . $2~gem;
$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;
fopen(FILE, ">$vardir/backupsettings.pl");
print FILE $setfile;
fclose(FILE);
$yySetLocation = qq~$scripturl?action=backupmanage2~;
&redirectexit;
}
# =============================================================================
# Here we make a backup now if Checkbox for Direct update is enabled
# =============================================================================
sub backupnow {
&is_admin;
use Sources::Zip qw( :CONSTANTS );
use Sources::Tree;
$hitch = '';
($day, $month, $year) = (localtime)[3,4,5];
$year = $year + 1900; $month++;
if ($time_stemp) { $hitch = "_$month-$day-$year"; }
#lock the forum while doing backup
&dolock;
$fname = "backup$hitch.zip";
my $zip = Sources::Zip->new();
# add all readable files and directories below
$zip->addTree( "$backupdir");
# and write them into a file
$zip->writeToFileNamed("$backupto/$fname");
@mat = stat("$backupto/$fname");
&lastbackupinfo;
chmod (0777, "$backupto/$fname");
#re-open the forum because the backup is done
unlink "$vardir/backup.lock";
if ($mat[7] <= 0) { &fatal_error ("$bckuptxt{'20'}"); exit; }
#Lets pretty up the file size display
&formatfs($mat[7]);
# =============================================================================
# Here we send E-Mail if enabled
# =============================================================================
if ($send_via_mail == 1) {
if($mailtype == 0) {
Sources::Lite->send('sendmail', "$mailprog -t -oi");
} else {
Sources::Lite->send('smtp', "$smtp_server");
}
# #path to sendmail + -t -oi for attachments
# $mailprog2 = "$mailprog -t -oi";
#
# Sources::Lite->send('sendmail', "$mailprog2");
$msg = new Sources::Lite
From =>"$webmaster_email",
To =>"$backuptoemail",
Subject =>"$mbname $bckuptxt{'21'}",
Type =>'TEXT',
Data =>"$bckuptxt{'22'} $mbname:\n\n$bckuptxt{'28'}\n$fname\n$bckuptxt{'29'} $fsize $bckuptxt{'27'}\n\n";
# Attach a part:
attach $msg Type =>'BINARY',
Path =>"$backupto/$fname",
Filename =>"$fname";
$msg->send || &fatal_error("$bckuptxt{'23'}");
# =============================================================================
# Here we delete Backupfile if checked and Output Infos
# =============================================================================
if ($backupdel == 1) {
unlink "$backupto/$fname";
&yabb_alert ("$bckuptxt{'24'} $backuptoemail. $bckuptxt{'30'} $fname. $bckuptxt{'29'} $fsize $bckuptxt{'27'}.
$bckuptxt{'25'}");
} else {
&yabb_alert ("$bckuptxt{'24'} $backuptoemail. $bckuptxt{'30'} $fname. $bckuptxt{'29'} $fsize $bckuptxt{'27'}.");
}
} else {
&yabb_alert ("$bckuptxt{'26'} $fname. $bckuptxt{'29'} $fsize $bckuptxt{'27'}");
}
}
# =============================================================================
# Autobackupsystem - Here is the Code for the auto backup system
# =============================================================================
sub AutoBackup {
# Get date
&get_date;
# Open default Mailinglist Text
fopen(FILE, "$vardir/lastbackup.txt");
@lastbackup = ;
fclose(FILE);
# Get date
($last_reminder, $ml_month, $ml_yearday, $ml_date, $dummy) = split(/\|/, @lastbackup[0]);
# Check Frequency
# Daily (and not already send today)
if ($backup_frequency == 1 && $ml_yearday < $yday && $last_reminder != $yday) {
&AutoBackup2;
}
# Weekly (and not already send today)
if ($backup_frequency == 2 && ($ml_yearday + 7) <= $yday && $last_reminder != $yday) {
&AutoBackup2;
}
# Monthly (and not already send today)
elsif ($backup_frequency == 3 && $ml_month != $mon_num && $last_reminder != $yday) {
&AutoBackup2;
}
}
sub AutoBackup2 {
use Sources::Zip qw( :CONSTANTS );
use Sources::Tree;
$hitch = '';
($day, $month, $year) = (localtime)[3,4,5];
$year = $year + 1900; $month++;
if ($time_stemp) { $hitch = "_$month-$day-$year"; }
#lock the forum while doing backup
&dolock;
$fname = "backup$hitch.zip";
my $zip = Sources::Zip->new();
# add all readable files and directories below . as xyz/*
$zip->addTree( "$backupdir");
# and write them into a file
$zip->writeToFileNamed("$backupto/$fname");
@mat = stat("$backupto/$fname");
&lastbackupinfo;
chmod (0777, "$backupto/$fname");
#re-open the forum because the backup is done
unlink "$vardir/backup.lock";
#Lets pretty up the file size display
&formatfs($mat[7]);
if ($send_via_mail == 1) {
if($mailtype == 0) {
Sources::Lite->send('sendmail', "$mailprog -t -oi");
} else {
Sources::Lite->send('smtp', "$smtp_server");
}
# #path to sendmail + -t -oi for attachments
# $mailprog2 = "$mailprog -t -oi";
#
# Sources::Lite->send('sendmail', "$mailprog2");
$msg = new Sources::Lite
From =>"$webmaster_email",
To =>"$backuptoemail",
Subject =>"$mbname $bckuptxt{'21'}",
Type =>'TEXT',
Data =>"$bckuptxt{'22'} $mbname:\n\n$bckuptxt{'28'}\n$fname\n$bckuptxt{'29'} $fsize $bckuptxt{'27'}\n\n";
# Attach a part:
attach $msg Type =>'BINARY',
Path =>"$backupto/$fname",
Filename =>"$fname";
$msg->send;
if ($backupdel == 1) {
unlink "$backupto/$fname";
}
}
}
# =============================================================================
# Here we update the last Backup time info
# =============================================================================
sub lastbackupinfo {
unlink("$vardir/lastbackup.txt");
fopen(FILE, ">$vardir/lastbackup.txt");
print FILE "$yday|$mon_num|$yday|$date|$fname\n";
fclose(FILE);
}
sub dolock {
fopen(FILE, ">$vardir/backup.lock");
print FILE "\n";
fclose(FILE);
}
sub ViewBackups {
&is_admin;
# Get date and filename of last backup
fopen(FILE, "$vardir/lastbackup.txt");
@backupinfo = ;
fclose(FILE);
($last_reminder, $ml_month, $ml_yearday, $lbinfo, $lfname) = split(/\|/, @backupinfo[0]);
chomp $lfname;
if (-e "$backupto/$lfname"){
$lfnamelnk = "$lfname";
} else {
$lfnamelnk = $lfname;
}
if ($lbinfo eq '') {
$lbinfo2 = "N";
$lfnamelnk = "A";
} else {
$lbinfo2 = &timeformat($lbinfo);
}
$dstamp = "$bckuptxt{'43'}";
if ($time_stemp == 1) {$dstamp = "$bckuptxt{'42'}";}
$bkdel = "$bckuptxt{'43'}";
if ($backupdel == 1) {$bkdel = "$bckuptxt{'42'}";}
if ($backup_frequency == 0) {$freq = "$bckuptxt{'11'}";}
elsif ($backup_frequency == 1) {$freq = "$bckuptxt{'12'}";}
elsif ($backup_frequency == 2) {$freq = "$bckuptxt{'13'}";}
elsif ($backup_frequency == 3) {$freq = "$bckuptxt{'14'}";}
if ($send_via_mail){
$mailsetting = qq~