############################################################################### # 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~
$bckuptxt{'09'}

$bckuptxt{'10'}
$bckuptxt{'01'}
$bckuptxt{'02'}
$bckuptxt{'04'} ~; # Autosend Frequency: Never if ($backup_frequency == 0) { $yymain .= qq~  $bckuptxt{'11'}  $bckuptxt{'12'}  $bckuptxt{'13'}  $bckuptxt{'14'} ~; } # Autosend Frequency: Daily elsif ($backup_frequency == 1) { $yymain .= qq~  $bckuptxt{'11'}  $bckuptxt{'12'}  $bckuptxt{'13'}  $bckuptxt{'14'} ~; } # Autosend Frequency: Weekly elsif ($backup_frequency == 2) { $yymain .= qq~  $bckuptxt{'11'}  $bckuptxt{'12'}  $bckuptxt{'13'}  $bckuptxt{'14'} ~; } # Autosend Frequency: Monthly elsif ($backup_frequency == 3) { $yymain .= qq~  $bckuptxt{'11'}  $bckuptxt{'12'}  $bckuptxt{'13'}  $bckuptxt{'14'} ~; } $yymain .= qq~
$bckuptxt{'03'}

$bckuptxt{'05'} $nolite
$bckuptxt{'08'}
$bckuptxt{'06'}

$bckuptxt{'18'}
~; $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~ $bckuptxt{'05'}Yes $bckuptxt{'08'}$bkdel $bckuptxt{'06'}$backuptoemail~; } else { $mailsetting = qq~$bckuptxt{'05'}No~; } opendir (BUP, "$backupto") || &fatal_error("$bckuptxt{'31'} $backupto!"); @contents = readdir(BUP); closedir(BUP); $i = 0; foreach $line (@contents){ ($name, $extension) = split (/\./, $line); @mat = stat("$backupto/$line"); if ($extension eq "zip"){ @backupfs[$i] = ("$line|$mat[7]|$mat[9]"); $i++; } } if (1 > @backupfs) { $viewbackups .= qq~
$bckuptxt{'32'}
~; } else { @sortback = map {$_->[0]} sort{($b->[3])<=>($a->[3])} map { [ $_, (split /\|/)[0..2] ] } (@backupfs); foreach $line (@sortback) { ($fname, $fsize, $fdate) = split (/\|/, $line); $budate = &formatdate($fdate); $budate = &timeformat($budate); &formatfs($fsize); $viewbackups .= qq~ $fname $fsize  $budate $bckuptxt{'33'}\n~; } } $yymain .= qq~
  $bckuptxt{'35'}

$bckuptxt{'36'}
$bckuptxt{'17'}   $lbinfo2 / $lfnamelnk

$viewbackups ~; unless (1 > @backupfs) { $yymain .= qq~ ~; } $yymain .= qq~
$bckuptxt{'37'}
 $bckuptxt{'38'} $bckuptxt{'39'} $bckuptxt{'40'} $bckuptxt{'33'}
  $bckuptxt{'34'}

$mailsetting
$bckuptxt{'44'}
$bckuptxt{'01'}$backupdir
$bckuptxt{'02'}$backupto
$bckuptxt{'03'}$dstamp
$bckuptxt{'04'}$freq
[ $bckuptxt{'16'} ]
~; $yytitle = "$bckuptxt{'35'}"; &template; exit; } sub DeleteBackups { &is_admin; my $filename = $INFO{'filename'}; my $dlast = $INFO{'dellast'}; if ($filename eq 'all') { opendir (BUP, "$backupto") || &fatal_error("$bckuptxt{'31'} $backupto!"); @contents = readdir(BUP); closedir(BUP); $i = 0; foreach $killfile (@contents){ ($name, $extension) = split (/\./, $killfile); if ($extension eq "zip"){ unlink("$backupto/$killfile"); $i++; } } fopen(BUP, ">$vardir/lastbackup.txt"); fclose(BUP); $yySetLocation = qq~$scripturl?action=backupmanage2~; &redirectexit; } else { unlink("$backupto/$filename"); $yySetLocation = qq~$scripturl?action=backupmanage2~; &redirectexit; } } sub formatfs { $fsize = $_[0]; if ($fsize > '1000000') { $fsize = sprintf("%.2f",($fsize/1048576)); $fsize .=" MB"; } else { $fsize = sprintf("%.0f",($fsize/1024)); $fsize .=" KB"; } return $fsize; } sub formatdate { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($_[0]); $mon_num = $mon+1; $savehour = $hour; $hour = "0$hour" if ($hour < 10); $min = "0$min" if ($min < 10); $sec = "0$sec" if ($sec < 10); $saveyear = ($year % 100); $year = 1900 + $year; $mon_num = "0$mon_num" if ($mon_num < 10); $mday = "0$mday" if ($mday < 10); $saveyear = "0$saveyear" if ($saveyear < 10); $date = "$mon_num/$mday/$saveyear $txt{'107'} $hour\:$min\:$sec"; return $date; } sub Download { &is_admin; $file = $INFO{'file'}; $filename = "$backupto/$file"; @mat = stat("$backupto/$file"); $filesize = $mat[7]; # print full header print "Content-disposition: inline; filename=$file\n"; print "Content-Length: $filesize\n"; print "Content-Type: application/x-zip-compressed; name=$file\n\n"; # open in binmode open(READ,"$filename") || die; binmode READ; # stream it out binmode STDOUT; while () { print; } close(READ); # should always return true return(1); } 1;