D:\my docs\My Received Files\Yabb\Yabb\YaBB_2.5_AEB\cgi-bin\yabb2_old\Admin\Backup.pl D:\WEBSITES\testbed\cgi-bin\yabb252\Admin\Backup.pl
############################################################################### ###############################################################################
# Backup.pl                                                                   # # Backup.pl                                                                   #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5 Anniversary Edition                                # # Version:        YaBB 2.5.2                                                  #
# Packaged:       July 04, 2010                                               # # Packaged:       September 30, 2012                                          #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2010 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               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.         #    
############################################################################### ###############################################################################
   
# Many thanks to AK108 (http://fkp.jkcsi.com/) for his contibution to the YaBB community # Many thanks to AK108 (http://fkp.jkcsi.com/) for his contibution to the YaBB community
   
$backupplver = 'YaBB 2.5 AE $Revision: 1.3 $'; $backupplver = 'YaBB 2.5.2 $Revision: 1.0 $';
if ($action eq 'detailedversion') { return 1; } if ($action eq 'detailedversion') { return 1; }
   
# Add in support for Archive::Tar in the Modules directory and binaries in different places # Add in support for Archive::Tar in the Modules directory and binaries in different places
@ENVpaths = split(/\:/, $ENV{'PATH'}); @ENVpaths = split(/\:/, $ENV{'PATH'});
   
&LoadLanguage('Backup'); &LoadLanguage('Backup');
$yytitle = $backup_txt{1}; $yytitle = $backup_txt{1};
$action_area = 'backupsettings'; $action_area = 'backupsettings';
   
my $curtime = CORE::time; # None of that Time::HiRes stuff my $curtime = CORE::time; # None of that Time::HiRes stuff
   
my %dirs = ( my %dirs = (
       'src' => "Admin/ $backup_txt{'and'} Sources/",        'src' => "Admin/ $backup_txt{'and'} Sources/",
       'bo' => "Boards/",        'bo' => "Boards/",
       'lan' => "Languages/ $backup_txt{'and'} Help/",        'lan' => "Languages/ $backup_txt{'and'} Help/",
       'mem' => "Members/",        'mem' => "Members/",
       'mes' => "Messages/",        'mes' => "Messages/",
       'temp' => "Templates/ $backup_txt{10}",        'temp' => "Templates/ $backup_txt{10}",
       'var' => "Variables/",        'var' => "Variables/",
       'html' => "yabbfiles",        'html' => "yabbfiles",
       'upld' => "yabbfiles/Attachments $backup_txt{'and'} yabbfiles/avatars/UserAvatars",        'upld' => "yabbfiles/Attachments $backup_txt{'and'} yabbfiles/avatars/UserAvatars",
       );        );
                 
&is_admin_or_gmod; &is_admin_or_gmod;
   
sub backupsettings { sub backupsettings {
   my ($module, $command, $tarcompress1, $tarcompress2, $allchecked, $item, %pathchecklist, %methodchecklist, $presetjavascriptcode, $file, @backups, $newcommand, $style, $disabledtext, $input);    my ($module, $command, $tarcompress1, $tarcompress2, $allchecked, $item, %pathchecklist, %methodchecklist, $presetjavascriptcode, $file, @backups, $newcommand, $style, $disabledtext, $input);
   
   $yymain .= qq~<b>$backup_txt{33} $INFO{'backupspendtime'} $backup_txt{34}</b><br /><br />~ if $INFO{'backupspendtime'};    $yymain .= qq~<b>$backup_txt{33} $INFO{'backupspendtime'} $backup_txt{34}</b><br /><br />~ if $INFO{'backupspendtime'};
   $yymain .= qq~<font color="green"><b>$backup_txt{'mailsuccess'}</b></font><br /><br />~ if $INFO{'mailinfo'} == 1;    $yymain .= qq~<font color="green"><b>$backup_txt{'mailsuccess'}</b></font><br /><br />~ if $INFO{'mailinfo'} == 1;
   $yymain .= qq~<font color="red"><b>$backup_txt{'mailfail'}</b></font><br /><br />~ if $INFO{'mailinfo'} == -1;    $yymain .= qq~<font color="red"><b>$backup_txt{'mailfail'}</b></font><br /><br />~ if $INFO{'mailinfo'} == -1;
   
   if (@backup_paths == 8) { $allchecked = 'checked="checked" '; }    if (@backup_paths == 8) { $allchecked = 'checked="checked" '; }
   
   # Yes, my checklists are really hashes. Oh well.    # Yes, my checklists are really hashes. Oh well.
   foreach $item (@backup_paths) { $pathchecklist{$item} = 'checked="checked" '; }    foreach $item (@backup_paths) { $pathchecklist{$item} = 'checked="checked" '; }
   $methodchecklist{$backupmethod} = 'checked="checked" ';    $methodchecklist{$backupmethod} = 'checked="checked" ';
   $methodchecklist{$compressmethod} = 'checked="checked" ';    $methodchecklist{$compressmethod} = 'checked="checked" ';
   
   # domodulecheck if we have a checked value    # domodulecheck if we have a checked value
   $presetjavascriptcode = qq~    domodulecheck("$backupmethod", 'init');~;    $presetjavascriptcode = qq~    domodulecheck("$backupmethod", 'init');~;
   
   # Javascript to make the behavior of the form buttons work better    # Javascript to make the behavior of the form buttons work better
   $yymain .= qq~    $yymain .= qq~
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
   function checkYaBB () {    function checkYaBB () {
       // See if the check all box should be checked or unchecked.        // See if the check all box should be checked or unchecked.
       // It should be checked only if all the other boxes are checked.        // It should be checked only if all the other boxes are checked.
       if (document.backupsettings.YaBB_bo.checked && document.backupsettings.YaBB_mes.checked && document.backupsettings.YaBB_mem.checked && document.backupsettings.YaBB_temp.checked && document.backupsettings.YaBB_lan.checked && document.backupsettings.YaBB_var.checked && document.backupsettings.YaBB_src.checked && document.backupsettings.YaBB_html.checked && document.backupsettings.YaBB_upld.checked) {        if (document.backupsettings.YaBB_bo.checked && document.backupsettings.YaBB_mes.checked && document.backupsettings.YaBB_mem.checked && document.backupsettings.YaBB_temp.checked && document.backupsettings.YaBB_lan.checked && document.backupsettings.YaBB_var.checked && document.backupsettings.YaBB_src.checked && document.backupsettings.YaBB_html.checked && document.backupsettings.YaBB_upld.checked) {
           document.backupsettings.YaBB_ALL.checked = 1;            document.backupsettings.YaBB_ALL.checked = 1;
       } else {        } else {
           document.backupsettings.YaBB_ALL.checked = 0;            document.backupsettings.YaBB_ALL.checked = 0;
       }        }
   }    }
   
   function masscheckYaBB (toggleboxstate) {    function masscheckYaBB (toggleboxstate) {
       if(!toggleboxstate) { // Uncheck all        if(!toggleboxstate) { // Uncheck all
           checkstate = 0;            checkstate = 0;
       } else if(toggleboxstate) { // Check all        } else if(toggleboxstate) { // Check all
           checkstate = 1;            checkstate = 1;
       }        }
       document.backupsettings.YaBB_bo.checked = checkstate;        document.backupsettings.YaBB_bo.checked = checkstate;
       document.backupsettings.YaBB_mes.checked = checkstate;        document.backupsettings.YaBB_mes.checked = checkstate;
       document.backupsettings.YaBB_mem.checked = checkstate;        document.backupsettings.YaBB_mem.checked = checkstate;
       document.backupsettings.YaBB_temp.checked = checkstate;        document.backupsettings.YaBB_temp.checked = checkstate;
       document.backupsettings.YaBB_lan.checked = checkstate;        document.backupsettings.YaBB_lan.checked = checkstate;
       document.backupsettings.YaBB_var.checked = checkstate;        document.backupsettings.YaBB_var.checked = checkstate;
       document.backupsettings.YaBB_src.checked = checkstate;        document.backupsettings.YaBB_src.checked = checkstate;
       document.backupsettings.YaBB_html.checked = checkstate;        document.backupsettings.YaBB_html.checked = checkstate;
       document.backupsettings.YaBB_upld.checked = checkstate;        document.backupsettings.YaBB_upld.checked = checkstate;
   }    }
   
   function domodulecheck (module, initstate) {    function domodulecheck (module, initstate) {
       if(module == "Archive::Tar") {        if(module == "Archive::Tar") {
           for(i = 0; document.getElementsByName("tarmodulecompress")[i]; i++) {            for(i = 0; document.getElementsByName("tarmodulecompress")[i]; i++) {
               document.getElementsByName("tarmodulecompress")[i].disabled = false;                document.getElementsByName("tarmodulecompress")[i].disabled = false;
           }            }
           if(!initstate) {            if(!initstate) {
               document.getElementsByName("tarmodulecompress")[0].checked = true;                document.getElementsByName("tarmodulecompress")[0].checked = true;
           }            }
       } else {        } else {
           for(i = 0; document.getElementsByName("tarmodulecompress")[i]; i++) {            for(i = 0; document.getElementsByName("tarmodulecompress")[i]; i++) {
               document.getElementsByName("tarmodulecompress")[i].disabled = true;                document.getElementsByName("tarmodulecompress")[i].disabled = true;
           }            }
       }        }
   
       if(module == "/usr/bin/tar") {        if(module == "/usr/bin/tar") {
           for(i = 0; document.getElementsByName("bintarcompress")[i]; i++) {            for(i = 0; document.getElementsByName("bintarcompress")[i]; i++) {
               document.getElementsByName("bintarcompress")[i].disabled = false;                document.getElementsByName("bintarcompress")[i].disabled = false;
           }            }
           if(!initstate) {            if(!initstate) {
               document.getElementsByName("bintarcompress")[0].checked = true;                document.getElementsByName("bintarcompress")[0].checked = true;
           }            }
       } else {        } else {
           for(i = 0; document.getElementsByName("bintarcompress")[i]; i++) {            for(i = 0; document.getElementsByName("bintarcompress")[i]; i++) {
               document.getElementsByName("bintarcompress")[i].disabled = true;                document.getElementsByName("bintarcompress")[i].disabled = true;
           }            }
       }        }
   }    }
--> -->
</script> </script>
<form action="$adminurl?action=backupsettings2" method="post" name="backupsettings"> <form action="$adminurl?action=backupsettings2" method="post" name="backupsettings">
<div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;"> <div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;">
  <table width="100%" cellspacing="1" cellpadding="4">   <table width="100%" cellspacing="1" cellpadding="4">
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="titlebg">       <td align="left" class="titlebg">
        <img src="$imagesdir/preferences.gif" alt="" border="0" /><b>$backup_txt{1}</b>         <img src="$imagesdir/preferences.gif" alt="" border="0" /><b>$backup_txt{1}</b>
      </td>       </td>
    </tr>~;     </tr>~;
   
   if(!$backupsettingsloaded) {    if(!$backupsettingsloaded) {
       $yymain .= qq~        $yymain .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="catbg">       <td align="left" class="catbg">
        <b>$backup_txt{2}</b>         <b>$backup_txt{2}</b>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left">       <td align="left">
        <!-- Empty td for a spacer -->         <!-- Empty td for a spacer -->
      </td>       </td>
    </tr>~;     </tr>~;
   }    }
   
   $yymain .= qq~    $yymain .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg">       <td align="left" class="windowbg">
        $backup_txt{3}         $backup_txt{3}
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="catbg">       <td align="left" class="catbg">
        <b>$backup_txt{4}</b>         <b>$backup_txt{4}</b>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg">       <td align="left" class="windowbg">
        <input type="checkbox" name="YaBB_ALL" id="YaBB_ALL" value="1" onclick="masscheckYaBB(this.checked)" $allchecked/> <label for="YaBB_ALL">$backup_txt{5}<br />         <input type="checkbox" name="YaBB_ALL" id="YaBB_ALL" value="1" onclick="masscheckYaBB(this.checked)" $allchecked/> <label for="YaBB_ALL">$backup_txt{5}<br />
        $backup_txt{6}</label>         $backup_txt{6}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_src" id="YaBB_src" value="1" $pathchecklist{'src'}/> <label for="YaBB_src">Admin/ $backup_txt{'and'} Sources/ $backup_txt{13}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_src" id="YaBB_src" value="1" $pathchecklist{'src'}/> <label for="YaBB_src">Admin/ $backup_txt{'and'} Sources/ $backup_txt{13}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_bo" id="YaBB_bo" value="1" $pathchecklist{'bo'}/> <label for="YaBB_bo">Boards/ $backup_txt{7}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_bo" id="YaBB_bo" value="1" $pathchecklist{'bo'}/> <label for="YaBB_bo">Boards/ $backup_txt{7}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_lan" id="YaBB_lan" value="1" $pathchecklist{'lan'}/> <label for="YaBB_lan">Languages/ $backup_txt{'and'} Help/ $backup_txt{11}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_lan" id="YaBB_lan" value="1" $pathchecklist{'lan'}/> <label for="YaBB_lan">Languages/ $backup_txt{'and'} Help/ $backup_txt{11}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_mem" id="YaBB_mem" value="1" $pathchecklist{'mem'}/> <label for="YaBB_mem">Members/ $backup_txt{9}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_mem" id="YaBB_mem" value="1" $pathchecklist{'mem'}/> <label for="YaBB_mem">Members/ $backup_txt{9}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_mes" id="YaBB_mes" value="1" $pathchecklist{'mes'}/> <label for="YaBB_mes">Messages/ $backup_txt{8}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_mes" id="YaBB_mes" value="1" $pathchecklist{'mes'}/> <label for="YaBB_mes">Messages/ $backup_txt{8}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_temp" id="YaBB_temp" value="1" $pathchecklist{'temp'}/> <label for="YaBB_temp">Templates/ $backup_txt{10} $backup_txt{'10a'}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_temp" id="YaBB_temp" value="1" $pathchecklist{'temp'}/> <label for="YaBB_temp">Templates/ $backup_txt{10} $backup_txt{'10a'}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_var" id="YaBB_var" value="1" $pathchecklist{'var'}/> <label for="YaBB_var">Variables/ $backup_txt{12}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_var" id="YaBB_var" value="1" $pathchecklist{'var'}/> <label for="YaBB_var">Variables/ $backup_txt{12}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_html" id="YaBB_html" value="1" $pathchecklist{'html'}/> <label for="YaBB_html">yabbfiles $backup_txt{14}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_html" id="YaBB_html" value="1" $pathchecklist{'html'}/> <label for="YaBB_html">yabbfiles $backup_txt{14}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <input type="checkbox" onclick="checkYaBB()" name="YaBB_upld" id="YaBB_upld" value="1" $pathchecklist{'upld'}/> <label for="YaBB_upld">yabbfiles/Attachments $backup_txt{'and'} yabbfiles/avatars/UserAvatars $backup_txt{'14a'}</label>         <input type="checkbox" onclick="checkYaBB()" name="YaBB_upld" id="YaBB_upld" value="1" $pathchecklist{'upld'}/> <label for="YaBB_upld">yabbfiles/Attachments $backup_txt{'and'} yabbfiles/avatars/UserAvatars $backup_txt{'14a'}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="catbg">       <td align="left" class="catbg">
        <b>$backup_txt{15}</b>         <b>$backup_txt{15}</b>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg">       <td align="left" class="windowbg">
        $backup_txt{16}         $backup_txt{16}
      </td>       </td>
    </tr>~;     </tr>~;
   
   # Make a list of modules that we can use with Tar::Archive    # Make a list of modules that we can use with Tar::Archive
   $tarcompress1 = qq~    $tarcompress1 = qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg">       <td align="left" class="windowbg">
        <input type="radio" name="tarmodulecompress" id="tarmodulecompress" value="none" $methodchecklist{'none'}/> <label for="tarmodulecompress">$backup_txt{17}</label>         <input type="radio" name="tarmodulecompress" id="tarmodulecompress" value="none" $methodchecklist{'none'}/> <label for="tarmodulecompress">$backup_txt{17}</label>
      </td>       </td>
    </tr>~;     </tr>~;
   
   my $label_id;    my $label_id;
   foreach $module qw(Compress::Zlib Compress::Bzip2) {    foreach $module (qw(Compress::Zlib Compress::Bzip2)) {
       $label_id++;        $label_id++;
       $input = qq~name="tarmodulecompress" id="label_$label_id" value="$module" $methodchecklist{$module}~;        $input = qq~name="tarmodulecompress" id="label_$label_id" value="$module" $methodchecklist{$module}~;
       eval "use $module();";        eval "use $module();";
       if ($@) {        if ($@) {
           $input = qq~disabled="disabled"~;            $input = qq~disabled="disabled"~;
           $style = qq~style="font-style:italic; color:grey"~;            $style = qq~style="font-style:italic; color:grey"~;
           $disabledtext = $backup_txt{41};            $disabledtext = $backup_txt{41};
       } else {        } else {
           ($style,$disabledtext) = ('','');            ($style,$disabledtext) = ('','');
       }        }
       $tarcompress1 .= qq~        $tarcompress1 .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg" $style>       <td align="left" class="windowbg" $style>
        <input type="radio" $input/> <label for="label_$label_id">$module $backup_txt{18} $disabledtext</label>         <input type="radio" $input/> <label for="label_$label_id">$module $backup_txt{18} $disabledtext</label>
      </td>       </td>
    </tr>~;     </tr>~;
   }    }
   
   $tarcompress1 .= qq~    $tarcompress1 .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg">       <td align="left" class="windowbg">
        &nbsp;         &nbsp;
      </td>       </td>
    </tr>~;     </tr>~;
   
   # Make a list of compression commands we can use with /usr/bin/tar    # Make a list of compression commands we can use with /usr/bin/tar
   $tarcompress2 = qq~    $tarcompress2 = qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg">       <td align="left" class="windowbg">
        <input type="radio" name="bintarcompress" id="bintarcompress" value="none" $methodchecklist{'none'}/> <label for="bintarcompress">$backup_txt{17}</label>         <input type="radio" name="bintarcompress" id="bintarcompress" value="none" $methodchecklist{'none'}/> <label for="bintarcompress">$backup_txt{17}</label>
      </td>       </td>
    </tr>~;     </tr>~;
   
   foreach $command qw(/bin/gzip /bin/bzip2) {    foreach $command (qw(/bin/gzip /bin/bzip2)) {
       $label_id++;        $label_id++;
       $input = qq~name="bintarcompress" id="label_$label_id" value="$command" $methodchecklist{$command}~;        $input = qq~name="bintarcompress" id="label_$label_id" value="$command" $methodchecklist{$command}~;
       $newcommand = &CheckPath($command);        $newcommand = &CheckPath($command);
       if (!$newcommand) {        if (!$newcommand) {
           $input = qq~disabled="disabled"~;            $input = qq~disabled="disabled"~;
           $style = qq~style="font-style:italic; color:grey"~;            $style = qq~style="font-style:italic; color:grey"~;
           $disabledtext = $backup_txt{41};            $disabledtext = $backup_txt{41};
           $newcommand = $command;            $newcommand = $command;
       } else {        } else {
           ($style,$disabledtext) = ('','');            ($style,$disabledtext) = ('','');
       }        }
       $tarcompress2 .= qq~        $tarcompress2 .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg" $style>       <td align="left" class="windowbg" $style>
        <input type="radio" $input/> <label for="label_$label_id">$newcommand $backup_txt{18} $disabledtext</label>         <input type="radio" $input/> <label for="label_$label_id">$newcommand $backup_txt{18} $disabledtext</label>
      </td>       </td>
    </tr>~;     </tr>~;
   }    }
   
   $tarcompress2 .= qq~    $tarcompress2 .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg">       <td align="left" class="windowbg">
        &nbsp;         &nbsp;
      </td>       </td>
    </tr>~;     </tr>~;
   
   # Display the commands we can use for compression    # Display the commands we can use for compression
   # Non-translated here, as I doubt there are words to describe "tar" in another language    # Non-translated here, as I doubt there are words to describe "tar" in another language
   $input = qq~name="backupmethod" id="backupmethod1" value="/usr/bin/tar" onclick="domodulecheck('/usr/bin/tar')" $methodchecklist{'/usr/bin/tar'}~;    $input = qq~name="backupmethod" id="backupmethod1" value="/usr/bin/tar" onclick="domodulecheck('/usr/bin/tar')" $methodchecklist{'/usr/bin/tar'}~;
   $newcommand = &CheckPath('/usr/bin/tar');    $newcommand = &CheckPath('/usr/bin/tar');
   if ($newcommand) {    if ($newcommand) {
       if (&ak_system("tar -cf $vardir/backuptest.$curtime.tar ./$yyexec.$yyext")) {        if (&ak_system("tar -cf $vardir/backuptest.$curtime.tar ./$yyexec.$yyext")) {
           ($style,$disabledtext) = ('','');            ($style,$disabledtext) = ('','');
           unlink("$vardir/backuptest.$curtime.tar");            unlink("$vardir/backuptest.$curtime.tar");
       } else {        } else {
           $input = qq~disabled="disabled"~;            $input = qq~disabled="disabled"~;
           $style = qq~style="font-style:italic; color:grey"~;            $style = qq~style="font-style:italic; color:grey"~;
           $disabledtext = ": Tar $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8);            $disabledtext = ": Tar $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8);
       }        }
   } else {    } else {
       $input = qq~disabled="disabled"~;        $input = qq~disabled="disabled"~;
       $style = qq~style="font-style:italic; color:grey"~;        $style = qq~style="font-style:italic; color:grey"~;
       $disabledtext = $backup_txt{41};        $disabledtext = $backup_txt{41};
   }    }
   $yymain .= qq~    $yymain .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2" $style>       <td align="left" class="windowbg2" $style>
        <input type="radio" $input/> <label for="backupmethod1">Tar ($newcommand) $disabledtext</label>         <input type="radio" $input/> <label for="backupmethod1">Tar ($newcommand) $disabledtext</label>
      </td>       </td>
    </tr>$tarcompress2~;     </tr>$tarcompress2~;
   
   $input = qq~name="backupmethod" id="backupmethod2" value="/usr/bin/zip" onclick="domodulecheck('/usr/bin/zip')" $methodchecklist{'/usr/bin/zip'}~;    $input = qq~name="backupmethod" id="backupmethod2" value="/usr/bin/zip" onclick="domodulecheck('/usr/bin/zip')" $methodchecklist{'/usr/bin/zip'}~;
   $newcommand = &CheckPath('/usr/bin/zip');    $newcommand = &CheckPath('/usr/bin/zip');
   if ($newcommand) {    if ($newcommand) {
       if (&ak_system("zip -gq $vardir/backuptest.$curtime.zip ./$yyexec.$yyext")) {        if (&ak_system("zip -gq $vardir/backuptest.$curtime.zip ./$yyexec.$yyext")) {
           ($style,$disabledtext) = ('','');            ($style,$disabledtext) = ('','');
           unlink("$vardir/backuptest.$curtime.zip");            unlink("$vardir/backuptest.$curtime.zip");
       } else {        } else {
           $input = qq~disabled="disabled"~;            $input = qq~disabled="disabled"~;
           $style = qq~style="font-style:italic; color:grey"~;            $style = qq~style="font-style:italic; color:grey"~;
           $disabledtext = ": Zip $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8);            $disabledtext = ": Zip $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8);
       }        }
   } else {    } else {
       $input = qq~disabled="disabled"~;        $input = qq~disabled="disabled"~;
       $style = qq~style="font-style:italic; color:grey"~;        $style = qq~style="font-style:italic; color:grey"~;
       $disabledtext = $backup_txt{41};        $disabledtext = $backup_txt{41};
   }    }
   $yymain .= qq~    $yymain .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2" $style>       <td align="left" class="windowbg2" $style>
        <input type="radio" $input/> <label for="backupmethod2">Zip ($newcommand) $disabledtext</label>         <input type="radio" $input/> <label for="backupmethod2">Zip ($newcommand) $disabledtext</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg">       <td align="left" class="windowbg">
        &nbsp;         &nbsp;
      </td>       </td>
    </tr>~;     </tr>~;
   
   # Display the modules that we can use    # Display the modules that we can use
   foreach $module qw(Archive::Tar Archive::Zip) {    foreach $module (qw(Archive::Tar Archive::Zip)) {
       $i++;        $i++;
       $input = qq~name="backupmethod" id="backupmethod3_$i" value="$module" onclick="domodulecheck('$module')" $methodchecklist{$module}~;        $input = qq~name="backupmethod" id="backupmethod3_$i" value="$module" onclick="domodulecheck('$module')" $methodchecklist{$module}~;
       eval "use $module();";        eval "use $module();";
       if ($@) {        if ($@) {
           $input = qq~disabled="disabled"~;            $input = qq~disabled="disabled"~;
           $style = qq~style="font-style:italic; color:grey"~;            $style = qq~style="font-style:italic; color:grey"~;
           $disabledtext = $backup_txt{41};            $disabledtext = $backup_txt{41};
       } else {        } else {
           ($style,$disabledtext) = ('','');            ($style,$disabledtext) = ('','');
       }        }
       $yymain .= qq~        $yymain .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2" $style>       <td align="left" class="windowbg2" $style>
        <input type="radio" $input/> <label for="backupmethod3_$i">$module $disabledtext</label>         <input type="radio" $input/> <label for="backupmethod3_$i">$module $disabledtext</label>
      </td>       </td>
    </tr>~;     </tr>~;
       if ($module eq 'Archive::Tar') { $yymain .= $tarcompress1; }        if ($module eq 'Archive::Tar') { $yymain .= $tarcompress1; }
   }    }
   
   # Last but not least, the submit button and the $backupdir path.    # Last but not least, the submit button and the $backupdir path.
   $backupdir ||= "$boarddir/Backups";    $backupdir ||= "$boarddir/Backups";
   if ($backupdir =~ s|^\./||) {    if ($backupdir =~ s|^\./||) {
       $ENV{'SCRIPT_FILENAME'} =~ /(.*\/)/;        $ENV{'SCRIPT_FILENAME'} =~ /(.*\/)/;
       $backupdir = "$1$backupdir";        $backupdir = "$1$backupdir";
   }    }
   $yymain .= qq~    $yymain .= qq~
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="catbg">       <td align="left" class="catbg">
        <b>$backup_txt{19}</b>         <b>$backup_txt{19}</b>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <label for="backupdir">$backup_txt{'19a'}</label>: <input type="text" name="backupdir" id="backupdir" value="$backupdir" size="80"/>         <label for="backupdir">$backup_txt{'19a'}</label>: <input type="text" name="backupdir" id="backupdir" value="$backupdir" size="80"/>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="catbg">       <td align="left" class="catbg">
        <b>$backup_txt{'19b'}</b>         <b>$backup_txt{'19b'}</b>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2">       <td align="left" class="windowbg2">
        <label for="rememberbackup">$backup_txt{'19c'}</label> <input type="text" name="rememberbackup" id="rememberbackup" value="~ . ($rememberbackup / 86400) . qq~" size="3"/> <label for="rememberbackup">$backup_txt{'19d'}</label>         <label for="rememberbackup">$backup_txt{'19c'}</label> <input type="text" name="rememberbackup" id="rememberbackup" value="~ . ($rememberbackup / 86400) . qq~" size="3"/> <label for="rememberbackup">$backup_txt{'19d'}</label>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="center" class="catbg">       <td align="center" class="catbg">
        <input type="submit" name="submit" value="$backup_txt{20}" class="button" />         <input type="submit" name="submit" value="$backup_txt{20}" class="button" />
      </td>       </td>
    </tr>     </tr>
  </table>   </table>
</div> </div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
$presetjavascriptcode $presetjavascriptcode
   
   function BackupNewest(lastbackup) {    function BackupNewest(lastbackup) {
       document.getElementsByName("backupnewest")[0].value = lastbackup;        document.getElementsByName("backupnewest")[0].value = lastbackup;
       if (!window.submitted) {        if (!window.submitted) {
           window.submitted = true;            window.submitted = true;
           document.runbackup.submit();            document.runbackup.submit();
       }        }
   }    }
//--> //-->
</script>~; </script>~;
   
   # Here we go again with another table. Here's the backup button area    # Here we go again with another table. Here's the backup button area
   if ($backupsettingsloaded) {    if ($backupsettingsloaded) {
       # Look for the files.        # Look for the files.
       opendir(BACKUPDIR, $backupdir);        opendir(BACKUPDIR, $backupdir);
       @backups = readdir(BACKUPDIR);        @backups = readdir(BACKUPDIR);
       closedir(BACKUPDIR);        closedir(BACKUPDIR);
       #@backup_paths = qw(Admin_Sources Boards Languages Members Messages Templates Variables yabbfiles);        #@backup_paths = qw(Admin_Sources Boards Languages Members Messages Templates Variables yabbfiles);
   
       my ($lastbackupfiletime,$filename);        my ($lastbackupfiletime,$filename);
       foreach $file (map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [$_, /(\d+)/, $_] } @backups) {        foreach $file (map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [$_, /(\d+)/, $_] } @backups) {
           if ($file !~ /\A(backup)(n?)\.(\d+)\.([^\.]+)\.(.+)/) { next; }            if ($file !~ /\A(backup)(n?)\.(\d+)\.([^\.]+)\.(.+)/) { next; }
           $lastbackupfiletime = $3 if !$lastbackupfiletime;            $lastbackupfiletime = $3 if !$lastbackupfiletime;
           my $filesize = -s "$backupdir/$file";            my $filesize = -s "$backupdir/$file";
           $filesize = int($filesize / 1024); # Measure it in kilobytes            $filesize = int($filesize / 1024); # Measure it in kilobytes
           if ($filesize > 1024 * 4) { $filesize = int($filesize / 1024) . ' MB'; } # Measure it in megabytes            if ($filesize > 1024 * 4) { $filesize = int($filesize / 1024) . ' MB'; } # Measure it in megabytes
           else { $filesize .= ' KB'; } # Label it            else { $filesize .= ' KB'; } # Label it
           my @dirs;            my @dirs;
           foreach (split(/_/, $4)) {            foreach (split(/_/, $4)) {
               push(@dirs, $dirs{$_});                push(@dirs, $dirs{$_});
           }            }
   
           $filename = "$1$2.$3.$4.$5";            $filename = "$1$2.$3.$4.$5";
           $filelist .= qq~          <tr><td align="left">~ . &timeformat($3) . qq~</td><td align="right">$filesize</td><td align="left">- ~ . join('<br />- ', @dirs) . qq~</td><td align="left">~ . ($2 ? "<acronym title='$backup_txt{62}'>$backup_txt{'62a'}</acronym><br />" : '') . qq~$5</td><td><a href="$adminurl?action=downloadbackup;backupid=$file">$backup_txt{60}</a></td><td><a href="$adminurl?action=emailbackup;backupid=$file">$backup_txt{52}</a></td><td><a href="$adminurl?action=runbackup;runbackup_again=$1$2.0.$4.$5">$backup_txt{61}</a><br /><a href="$adminurl?action=runbackup;runbackup_again=$filename">$backup_txt{62}</a></td><td align="center">~ . (($5 =~ /^a\.tar/|| $5 !~ /tar/) ? '-' : qq~<a href="$adminurl?action=recoverbackup1;recoverfile=$filename">$backup_txt{63}</a>~) . qq~</td><td><a href="$adminurl?action=deletebackup;backupid=$file">$backup_txt{53}</a></td></tr>\n~;            $filelist .= qq~          <tr><td align="left">~ . &timeformat($3) . qq~</td><td align="right">$filesize</td><td align="left">- ~ . join('<br />- ', @dirs) . qq~</td><td align="left">~ . ($2 ? "<acronym title='$backup_txt{62}'>$backup_txt{'62a'}</acronym><br />" : '') . qq~$5</td><td><a href="$adminurl?action=downloadbackup;backupid=$file">$backup_txt{60}</a></td><td><a href="$adminurl?action=emailbackup;backupid=$file">$backup_txt{52}</a></td><td><a href="$adminurl?action=runbackup;runbackup_again=$1$2.0.$4.$5">$backup_txt{61}</a><br /><a href="$adminurl?action=runbackup;runbackup_again=$filename">$backup_txt{62}</a></td><td align="center">~ . (($5 =~ /^a\.tar/|| $5 !~ /tar/) ? '-' : qq~<a href="$adminurl?action=recoverbackup1;recoverfile=$filename">$backup_txt{63}</a>~) . qq~</td><td><a href="$adminurl?action=deletebackup;backupid=$file">$backup_txt{53}</a></td></tr>\n~;
       }        }
   
       $filelist ||= qq~          <tr><td align="left" colspan="9"><i>$backup_txt{38}</i></td></tr>\n~;        $filelist ||= qq~          <tr><td align="left" colspan="9"><i>$backup_txt{38}</i></td></tr>\n~;
   
       $yymain .= qq~        $yymain .= qq~
<br /> <br />
<form action="$adminurl?action=runbackup" method="post" name="runbackup"> <form action="$adminurl?action=runbackup" method="post" name="runbackup">
<input type="hidden" name="backupnewest" value="0" /> <input type="hidden" name="backupnewest" value="0" />
<div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;"> <div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;">
  <table width="100%" cellspacing="1" cellpadding="4">   <table width="100%" cellspacing="1" cellpadding="4">
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="titlebg" colspan="2">       <td align="left" class="titlebg" colspan="2">
        <img src="$imagesdir/preferences.gif" alt="" border="0" /><b>$backup_txt{21}</b>         <img src="$imagesdir/preferences.gif" alt="" border="0" /><b>$backup_txt{21}</b>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2" colspan="2">       <td align="left" class="windowbg2" colspan="2">
        $backup_txt{22} <tt>$backupdir</tt> $backup_txt{23}<br />         $backup_txt{22} <tt>$backupdir</tt> $backup_txt{23}<br />
        <br />         <br />
        $backup_txt{24}         $backup_txt{24}
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="center" class="catbg" colspan="2">       <td align="center" class="catbg" colspan="2">
        <table width="100%"><tr><td align="center">         <table width="100%"><tr><td align="center">
        <input type="button" name="submit1" value="$backup_txt{25}" onclick="BackupNewest(0);" class="button" />~;         <input type="button" name="submit1" value="$backup_txt{25}" onclick="BackupNewest(0);" class="button" />~;
   
       if ($lastbackupfiletime && $lastbackup == $lastbackupfiletime) {        if ($lastbackupfiletime && $lastbackup == $lastbackupfiletime) {
           $lastbackupfiletime = &timeformat($lastbackup,1);            $lastbackupfiletime = &timeformat($lastbackup,1);
           $lastbackupfiletime =~ s/<.*?>//g;            $lastbackupfiletime =~ s/<.*?>//g;
           $lastbackupfiletime =~ s/ .+// if $backupmethod eq '/usr/bin/zip';             if ($backupmethod eq '/usr/bin/zip') { 
  #                            $lastbackupfiletime =~ s/ .+//;  
                         @lbt = split / /, $lastbackupfiletime;  
                         $lastbackupfiletime = join q{ }, $lbt[0],$lbt[1],$lbt[2];  
                         }  
           $yymain .= qq~</td></tr><tr><td align="center">            $yymain .= qq~</td></tr><tr><td align="center">
        <input type="button" name="submit2" value="$backup_txt{'25a'} $lastbackupfiletime" onclick="BackupNewest($lastbackup);" class="button" />~;         <input type="button" name="submit2" value="$backup_txt{'25a'} $lastbackupfiletime" onclick="BackupNewest($lastbackup);" class="button" />~;
       }        }
   
    $yymain .= qq~     $yymain .= qq~
        </td></tr></table>         </td></tr></table>
      </td>       </td>
    </tr>     </tr>
  </table>   </table>
</div> </div>
</form> </form>
   
<br /> <br />
   
<div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;"> <div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;">
  <table width="100%" cellspacing="1" cellpadding="4">   <table width="100%" cellspacing="1" cellpadding="4">
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="titlebg" colspan="2">       <td align="left" class="titlebg" colspan="2">
        <img src="$imagesdir/preferences.gif" alt="" border="0" /><b>$backup_txt{35}</b>         <img src="$imagesdir/preferences.gif" alt="" border="0" /><b>$backup_txt{35}</b>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2" colspan="2">       <td align="left" class="windowbg2" colspan="2">
        $backup_txt{37} <i>${$uid.$username}{'email'}</i> $backup_txt{'37a'}<br />         $backup_txt{37} <i>${$uid.$username}{'email'}</i> $backup_txt{'37a'}<br />
        $backup_txt{36} <tt>$backupdir</tt>         $backup_txt{36} <tt>$backupdir</tt>
        <table border="1" cellspacing="1" cellpadding="4">         <table border="1" cellspacing="1" cellpadding="4">
         <tr><td align="center">$backup_txt{70}</td><td align="center">$backup_txt{71}</td><td align="center">$backup_txt{72}</td><td align="center">$backup_txt{73}</td><td align="center" colspan="5">$backup_txt{74}</td></tr>          <tr><td align="center">$backup_txt{70}</td><td align="center">$backup_txt{71}</td><td align="center">$backup_txt{72}</td><td align="center">$backup_txt{73}</td><td align="center" colspan="5">$backup_txt{74}</td></tr>
         $filelist          $filelist
        </table>         </table>
      </td>       </td>
    </tr>     </tr>
  </table>   </table>
</div>~; </div>~;
   }    }
   
   &AdminTemplate;    &AdminTemplate;
} }
   
sub backupsettings2 { sub backupsettings2 {
   $backupmethod = $FORM{'backupmethod'};    $backupmethod = $FORM{'backupmethod'};
   $compressmethod = $FORM{'bintarcompress'} || $FORM{'tarmodulecompress'} || 'none';    $compressmethod = $FORM{'bintarcompress'} || $FORM{'tarmodulecompress'} || 'none';
   
   # Handle the paths.    # Handle the paths.
   @backup_paths = ();    @backup_paths = ();
   if ($FORM{'YaBB_ALL'}) { # handle the magic select all checkbox so Javascript can be disabled and it still work    if ($FORM{'YaBB_ALL'}) { # handle the magic select all checkbox so Javascript can be disabled and it still work
       @backup_paths = qw(src bo lan mem mes temp var html upld);        @backup_paths = qw(src bo lan mem mes temp var html upld);
   } else {    } else {
       foreach (qw(src bo lan mem mes temp var html upld)) {        foreach (qw(src bo lan mem mes temp var html upld)) {
           if ($FORM{'YaBB_'.$_}) { push(@backup_paths, $_); }            if ($FORM{'YaBB_'.$_}) { push(@backup_paths, $_); }
       }        }
   }    }
   
   &check_backup_settings;    &check_backup_settings;
   
   # Set $backupdir    # Set $backupdir
   if (!-w $FORM{'backupdir'}) { &admin_fatal_error("","$backup_txt{42} '$FORM{'backupdir'}'. $backup_txt{43}"); }    if (!-w $FORM{'backupdir'}) { &admin_fatal_error("","$backup_txt{42} '$FORM{'backupdir'}'. $backup_txt{43}"); }
   
   $backupdir = $FORM{'backupdir'};    $backupdir = $FORM{'backupdir'};
   $lastbackup = 0; # reset when saving settings new    $lastbackup = 0; # reset when saving settings new
   &print_BackupSettings;    &print_BackupSettings;
   
   # Set $rememberbackup for alert into Settings.pl    # Set $rememberbackup for alert into Settings.pl
   if ($rememberbackup != $FORM{'rememberbackup'}) {    if ($rememberbackup != $FORM{'rememberbackup'}) {
       $rememberbackup = $FORM{'rememberbackup'};        $rememberbackup = $FORM{'rememberbackup'};
       fopen(SETTINGS, "$vardir/Settings.pl");        fopen(SETTINGS, "$vardir/Settings.pl");
       @settings = <SETTINGS>;        @settings = <SETTINGS>;
       fclose(SETTINGS);        fclose(SETTINGS);
       for ($i = 0; $i < @settings; $i++) {        for ($i = 0; $i < @settings; $i++) {
           if ($settings[$i] =~ /\$rememberbackup = \d+;/) {            if ($settings[$i] =~ /\$rememberbackup = \d+;/) {
               $rememberbackup = 0 if !$rememberbackup;                $rememberbackup = 0 if !$rememberbackup;
               $rememberbackup *= 86400; # days in seconds                $rememberbackup *= 86400; # days in seconds
               $settings[$i] =~ s/\$rememberbackup = \d+;/\$rememberbackup = $rememberbackup;/;                $settings[$i] =~ s/\$rememberbackup = \d+;/\$rememberbackup = $rememberbackup;/;
           }            }
       }        }
       # if \$rememberbackup = is not allready in Settings.pl        # if \$rememberbackup = is not allready in Settings.pl
       if ($rememberbackup && $rememberbackup == $FORM{'rememberbackup'}) {        if ($rememberbackup && $rememberbackup == $FORM{'rememberbackup'}) {
           $rememberbackup *= 86400; # days in seconds            $rememberbackup *= 86400; # days in seconds
           unshift(@settings, "\$rememberbackup = $rememberbackup;\n");            unshift(@settings, "\$rememberbackup = $rememberbackup;\n");
       }        }
       fopen(SETTINGS, ">$vardir/Settings.pl");        fopen(SETTINGS, ">$vardir/Settings.pl");
       print SETTINGS @settings;        print SETTINGS @settings;
       fclose(SETTINGS);        fclose(SETTINGS);
   }    }
   
   $yySetLocation = qq~$adminurl?action=backupsettings~;    $yySetLocation = qq~$adminurl?action=backupsettings~;
   &redirectexit;    &redirectexit;
} }
   
sub check_backup_settings { sub check_backup_settings {
   if (!@backup_paths) { &admin_fatal_error("","$backup_txt{3}"); }    if (!@backup_paths) { &admin_fatal_error("","$backup_txt{3}"); }
   
   if (!$backupmethod) { &admin_fatal_error("","$backup_txt{29} ''"); }    if (!$backupmethod) { &admin_fatal_error("","$backup_txt{29} ''"); }
   
   if ($backupmethod =~ /::/) { # It's a module, test-require it    if ($backupmethod =~ /::/) { # It's a module, test-require it
       eval "use $backupmethod();";        eval "use $backupmethod();";
       if ($@) { &admin_fatal_error("","$backup_txt{39} $backupmethod $backup_txt{41}"); }        if ($@) { &admin_fatal_error("","$backup_txt{39} $backupmethod $backup_txt{41}"); }
   } else {    } else {
       my $newcommand = &CheckPath($backupmethod);        my $newcommand = &CheckPath($backupmethod);
       if (!$newcommand) { &admin_fatal_error("","$backup_txt{40} $backupmethod $backup_txt{41}"); }        if (!$newcommand) { &admin_fatal_error("","$backup_txt{40} $backupmethod $backup_txt{41}"); }
   }    }
   
   # If we're using /usr/bin/tar, check for the compression method.    # If we're using /usr/bin/tar, check for the compression method.
   if ($backupmethod eq '/usr/bin/tar' && $compressmethod ne 'none') {    if ($backupmethod eq '/usr/bin/tar' && $compressmethod ne 'none') {
       my $newcommand = &CheckPath($compressmethod);        my $newcommand = &CheckPath($compressmethod);
       if (!$newcommand) { &admin_fatal_error("","$backup_txt{40} $compressmethod $backup_txt{41}"); }        if (!$newcommand) { &admin_fatal_error("","$backup_txt{40} $compressmethod $backup_txt{41}"); }
   }    }
   # If we're using Archive::Tar, check for the compression method.    # If we're using Archive::Tar, check for the compression method.
   elsif ($backupmethod eq 'Archive::Tar' && $compressmethod ne 'none') {    elsif ($backupmethod eq 'Archive::Tar' && $compressmethod ne 'none') {
       eval "use $compressmethod();";        eval "use $compressmethod();";
       if ($@) { &admin_fatal_error("","$backup_txt{39} $compressmethod $backup_txt{41}"); }        if ($@) { &admin_fatal_error("","$backup_txt{39} $compressmethod $backup_txt{41}"); }
   } else {    } else {
       $compressmethod = 'none';        $compressmethod = 'none';
   }    }
} }
   
sub print_BackupSettings { sub print_BackupSettings {
   my @newpaths;    my @newpaths;
   foreach my $path qw(src bo lan mem mes temp var html upld) {    foreach my $path (qw(src bo lan mem mes temp var html upld)) {
       foreach (@backup_paths) {        foreach (@backup_paths) {
           if ($_ eq $path) { push(@newpaths, $path); last; }            if ($_ eq $path) { push(@newpaths, $path); last; }
       }        }
   }    }
   @backup_paths = @newpaths;    @backup_paths = @newpaths;
   $backupsettingsloaded = 1;    $backupsettingsloaded = 1;
   
   require "$admindir/NewSettings.pl";    require "$admindir/NewSettings.pl";
   &SaveSettingsTo('Settings.pl');    &SaveSettingsTo('Settings.pl');
} }
   
# This routine actually does the backup. # This routine actually does the backup.
sub runbackup { sub runbackup {
   my(@settings, $prevmainsetting, $prevmaintext, $newmaintext, %pathconvert);    my(@settings, $prevmainsetting, $prevmaintext, $newmaintext, %pathconvert);
   
   if ($INFO{'runbackup_again'}) {    if ($INFO{'runbackup_again'}) {
       &admin_fatal_error("","$backup_txt{32} \$INFO{'runbackup_again'}=$INFO{'runbackup_again'}") if $INFO{'runbackup_again'} !~ /^backup/;        &admin_fatal_error("","$backup_txt{32} \$INFO{'runbackup_again'}=$INFO{'runbackup_again'}") if $INFO{'runbackup_again'} !~ /^backup/;
   
       my @again = split(/\./, $INFO{'runbackup_again'});        my @again = split(/\./, $INFO{'runbackup_again'});
       $FORM{'backupnewest'} = $again[1];        $FORM{'backupnewest'} = $again[1];
       @backup_paths = split(/_/, $again[2]);        @backup_paths = split(/_/, $again[2]);
       if ($again[3] eq 'a') {        if ($again[3] eq 'a') {
           $backupmethod = $again[4] eq 'tar' ? 'Archive::Tar' : 'Archive::Zip';            $backupmethod = $again[4] eq 'tar' ? 'Archive::Tar' : 'Archive::Zip';
           $compressmethod = $again[5] ? ($again[5] eq 'gz' ? 'Compress::Zlib' : 'Compress::Bzip2') : 'none';            $compressmethod = $again[5] ? ($again[5] eq 'gz' ? 'Compress::Zlib' : 'Compress::Bzip2') : 'none';
       } else {        } else {
           $backupmethod = $again[3] eq 'tar' ? '/usr/bin/tar' : '/usr/bin/zip';            $backupmethod = $again[3] eq 'tar' ? '/usr/bin/tar' : '/usr/bin/zip';
           $compressmethod = $again[4] ? ($again[4] eq 'gz' ? '/bin/gzip' : '/bin/bzip2') : 'none';            $compressmethod = $again[4] ? ($again[4] eq 'gz' ? '/bin/gzip' : '/bin/bzip2') : 'none';
       }        }
       &check_backup_settings;        &check_backup_settings;
   }    }
   
   my $backuptime = $INFO{'backuptime'} || time();    my $backuptime = $INFO{'backuptime'} || time();
   
   my $time_to_jump = time() + $max_process_time;    my $time_to_jump = time() + $max_process_time;
   
   $curtime = $INFO{'curtime'} || $curtime;    $curtime = $INFO{'curtime'} || $curtime;
   $FORM{'backupnewest'} ||= $INFO{'backupnewest'};    $FORM{'backupnewest'} ||= $INFO{'backupnewest'};
   $backuptype = 'n' if $FORM{'backupnewest'};    $backuptype = 'n' if $FORM{'backupnewest'};
   if ($FORM{'backupnewest'} && $backupmethod eq '/usr/bin/zip') {    if ($FORM{'backupnewest'} && $backupmethod eq '/usr/bin/zip') {
       my ($day, $mon, $year);        my ($day, $mon, $year);
       (undef, undef, undef, $day, $mon, $year, undef, undef, undef) = gmtime($FORM{'backupnewest'});        (undef, undef, undef, $day, $mon, $year, undef, undef, undef) = gmtime($FORM{'backupnewest'});
       $FORM{'backupnewest'} = sprintf("%02d", ($mon+1)) . sprintf("%02d", $day) . (1900 + $year);        $FORM{'backupnewest'} = sprintf("%02d", ($mon+1)) . sprintf("%02d", $day) . (1900 + $year);
   
   } elsif ($FORM{'backupnewest'} && $backupmethod =~ /::/) {    } elsif ($FORM{'backupnewest'} && $backupmethod =~ /::/) {
       $FORM{'backupnewest'} = ($curtime - $FORM{'backupnewest'}) / 86400;        $FORM{'backupnewest'} = ($curtime - $FORM{'backupnewest'}) / 86400;
   }    }
   my $filedirs = join('_', @backup_paths);    my $filedirs = join('_', @backup_paths);
   
   # Verify that our method is possible, and load it if it's a module    # Verify that our method is possible, and load it if it's a module
   &BackupMethodInit($filedirs);    &BackupMethodInit($filedirs);
   
   # Handle the conversion of the informal backup_paths stored in the settings file to the real ones    # Handle the conversion of the informal backup_paths stored in the settings file to the real ones
   # I'll build a hash to quickly match them.    # I'll build a hash to quickly match them.
   # A pipe separates them in the case of needing multiple real paths to handle one informal path    # A pipe separates them in the case of needing multiple real paths to handle one informal path
   %pathconvert = (    %pathconvert = (
       'src', "$admindir|$sourcedir|$boarddir/Modules|!$boarddir",        'src', "$admindir|$sourcedir|$boarddir/Modules|!$boarddir",
       'bo', $boardsdir,        'bo', $boardsdir,
       'lan', "$langdir|$helpfile",        'lan', "$langdir|$helpfile",
       'mem', $memberdir,        'mem', $memberdir,
       'mes', $datadir,        'mes', $datadir,
       'temp', "$templatesdir|$forumstylesdir|$adminstylesdir",        'temp', "$templatesdir|$forumstylesdir|$adminstylesdir",
       'var', $vardir,        'var', $vardir,
       'html', "!$htmldir|!$htmldir/avatars|$htmldir/Buttons|$htmldir/googiespell|$htmldir/greybox|$htmldir/ModImages|$htmldir/Smilies|$htmldir/Templates",        'html', "!$htmldir|!$htmldir/avatars|$htmldir/Buttons|$htmldir/googiespell|$htmldir/greybox|$htmldir/ModImages|$htmldir/Smilies|$htmldir/Templates",
       'upld', "$htmldir/Attachments|$htmldir/avatars/UserAvatars",        'upld', "$htmldir/Attachments|$htmldir/avatars/UserAvatars",
   );    );
   
   # Set the forum to maintenance mode.    # Set the forum to maintenance mode.
   &automaintenance('on');    &automaintenance('on');
   
   # Looping to prevent runt into browser/server timeout    # Looping to prevent runt into browser/server timeout
   my ($i,$j,$key,$path);    my ($i,$j,$key,$path);
   foreach $key (@backup_paths) {    foreach $key (@backup_paths) {
       $i++;        $i++;
       if ($i >= $INFO{'loop1'}) {        if ($i >= $INFO{'loop1'}) {
           $j = 0;            $j = 0;
           foreach $path (split(/\|/, $pathconvert{$key})) {            foreach $path (split(/\|/, $pathconvert{$key})) {
               $j++;                $j++;
               if ($j > $INFO{'loop2'}) {                if ($j > $INFO{'loop2'}) {
                   $INFO{'loop2'} = 0;                    $INFO{'loop2'} = 0;
   
                   # To keep this simple, I'll just point to a generic subroutine that takes care of                    # To keep this simple, I'll just point to a generic subroutine that takes care of
                   # handling the differences in backup methods.                    # handling the differences in backup methods.
                   if ($path =~ s|^\./||) {                    if ($path =~ s|^\./||) {
                       $ENV{'SCRIPT_FILENAME'} =~ /(.*\/)/;                        $ENV{'SCRIPT_FILENAME'} =~ /(.*\/)/;
                       $path = "$1$path";                        $path = "$1$path";
                   }                    }
                   &BackupDirectory($path,$filedirs);                    &BackupDirectory($path,$filedirs);
   
                   if (time() > $time_to_jump) {                    if (time() > $time_to_jump) {
                       &BackupMethodFinalize($filedirs,1);                        &BackupMethodFinalize($filedirs,1);
                       &runbackup_loop($i,$j,$curtime,$FORM{'backupnewest'},$backuptime);                        &runbackup_loop($i,$j,$curtime,$FORM{'backupnewest'},$backuptime);
                   }                    }
               }                }
           }            }
           $INFO{'loop2'} = 0;            $INFO{'loop2'} = 0;
       }        }
   }    }
   
   # Last, we'll finalize the archive. If it's a tar, we compress them,    # Last, we'll finalize the archive. If it's a tar, we compress them,
   # if requested. This can NOT be done with the forum out of maintenance mode    # if requested. This can NOT be done with the forum out of maintenance mode
   # due to the maintenance.lock file that is removed with &automaintenance('off')    # due to the maintenance.lock file that is removed with &automaintenance('off')
   &BackupMethodFinalize($filedirs,0);    &BackupMethodFinalize($filedirs,0);
   
   # Undo maintenance mode.    # Undo maintenance mode.
   &automaintenance('off');    &automaintenance('off');
   
   $lastbackup = $curtime; # save the last backup time with the actual settings    $lastbackup = $curtime; # save the last backup time with the actual settings
   &print_BackupSettings;    &print_BackupSettings;
   
   # Display the amount of time it took to be nice ;)    # Display the amount of time it took to be nice ;)
   $yySetLocation = qq~$adminurl?action=backupsettings;backupspendtime=~ . sprintf("%.4f", (time() - $backuptime));    $yySetLocation = qq~$adminurl?action=backupsettings;backupspendtime=~ . sprintf("%.4f", (time() - $backuptime));
   &redirectexit;    &redirectexit;
} }
   
# Checks once more that we can use the command or module given. If we can, we load module(s) here. # Checks once more that we can use the command or module given. If we can, we load module(s) here.
sub BackupMethodInit { sub BackupMethodInit {
   my $filedirs = shift;    my $filedirs = shift;
   
   # Check module types and load them at runtime (not compilation)    # Check module types and load them at runtime (not compilation)
   if($backupmethod eq 'Archive::Tar') {    if($backupmethod eq 'Archive::Tar') {
       eval 'use Archive::Tar;'; # Everything is exported at once        eval 'use Archive::Tar;'; # Everything is exported at once
       if ($@) { &admin_fatal_error("","$backup_txt{28} Archive::Tar: $@"); }        if ($@) { &admin_fatal_error("","$backup_txt{28} Archive::Tar: $@"); }
       if ($compressmethod eq 'Compress::Zlib') { # Also using Zlib        if ($compressmethod eq 'Compress::Zlib') { # Also using Zlib
           eval 'use Compress::Zlib;'; # Zlib exports everything at once            eval 'use Compress::Zlib;'; # Zlib exports everything at once
           if ($@) { &admin_fatal_error("","$backup_txt{28} Compres::Zlib: $@"); }            if ($@) { &admin_fatal_error("","$backup_txt{28} Compres::Zlib: $@"); }
   
       } elsif ($compressmethod eq 'Compress::Bzip2') {        } elsif ($compressmethod eq 'Compress::Bzip2') {
           eval 'use Compress::Bzip2 qw(:utilities);'; # Finally, something I can export just some code with            eval 'use Compress::Bzip2 qw(:utilities);'; # Finally, something I can export just some code with
           if ($@) { &admin_fatal_error("","$backup_txt{28} Compress::Bzip2: $@"); }            if ($@) { &admin_fatal_error("","$backup_txt{28} Compress::Bzip2: $@"); }
   
       } else { $compressmethod = 'none'; }        } else { $compressmethod = 'none'; }
   
       $tarball = Archive::Tar->new;        $tarball = Archive::Tar->new;
   
       # We need this for the loops, when preventing to run into browser/server timeout.        # We need this for the loops, when preventing to run into browser/server timeout.
       if (-e "$backupdir/backup$backuptype.$curtime.$filedirs.a.tar") {        if (-e "$backupdir/backup$backuptype.$curtime.$filedirs.a.tar") {
           $tarball->read("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar", 0);            $tarball->read("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar", 0);
           unlink("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar");            unlink("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar");
       }        }
   
   } elsif ($backupmethod eq 'Archive::Zip') {    } elsif ($backupmethod eq 'Archive::Zip') {
       eval 'use Archive::Zip;'; # Everything's exported by default here too        eval 'use Archive::Zip;'; # Everything's exported by default here too
       if ($@) { &admin_fatal_error("","$backup_txt{28} Archive::Zip: $@"); }        if ($@) { &admin_fatal_error("","$backup_txt{28} Archive::Zip: $@"); }
       $zipfile = Archive::Zip->new;        $zipfile = Archive::Zip->new;
   
       # We need this for the loops, when preventing to run into browser/server timeout.        # We need this for the loops, when preventing to run into browser/server timeout.
       if (-e "$backupdir/backup$backuptype.$curtime.$filedirs.a.zip") {        if (-e "$backupdir/backup$backuptype.$curtime.$filedirs.a.zip") {
           $zipfile->read("$backupdir/backup$backuptype.$curtime.$filedirs.a.zip");            $zipfile->read("$backupdir/backup$backuptype.$curtime.$filedirs.a.zip");
       }        }
   
   } else {    } else {
       unless (&CheckPath($backupmethod)) { &admin_fatal_error("","$backup_txt{29} $backupmethod."); }        unless (&CheckPath($backupmethod)) { &admin_fatal_error("","$backup_txt{29} $backupmethod."); }
       if ($compressmethod ne 'none' && !&CheckPath($compressmethod)) {        if ($compressmethod ne 'none' && !&CheckPath($compressmethod)) {
           &admin_fatal_error("","$backup_txt{30} $compressmethod.");            &admin_fatal_error("","$backup_txt{30} $compressmethod.");
       }        }
   }    }
} }
   
sub BackupDirectory { sub BackupDirectory {
   # Handles all the fun of directly archiving a directory.    # Handles all the fun of directly archiving a directory.
   my ($dir,$filedirs) = @_;    my ($dir,$filedirs) = @_;
   my ($recursemode, $cr, $Nt);    my ($recursemode, $cr, $Nt);
   $recursemode = 1;    $recursemode = 1;
   if ($dir =~ s/^!//) { $recursemode = 0; }    if ($dir =~ s/^!//) { $recursemode = 0; }
   
   if ($backupmethod eq '/usr/bin/tar') {    if ($backupmethod eq '/usr/bin/tar') {
       $cr = ($tarcreated || $INFO{'curtime'}) ? '-r' : '-c';        $cr = ($tarcreated || $INFO{'curtime'}) ? '-r' : '-c';
       $tarcreated = 1;        $tarcreated = 1;
       if (!$recursemode) { $dir .= '/*.*'; }        if (!$recursemode) { $dir .= '/*.*'; }
       if ($FORM{'backupnewest'}) { $Nt = "-N \@$FORM{'backupnewest'}"; }        if ($FORM{'backupnewest'}) { $Nt = "-N \@$FORM{'backupnewest'}"; }
       $dir =~ s|^/||; # needet not to get server log messages like "Removing leading `/' from ..."        $dir =~ s|^/||; # needet not to get server log messages like "Removing leading `/' from ..."
       &ak_system("tar $cr -C / -f $backupdir/backup$backuptype.$curtime.$filedirs.tar $Nt $dir") || &admin_fatal_error("","'tar $cr -C / -f $backupdir/backup$backuptype.$curtime.$filedirs.tar $Nt $dir' $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8));        &ak_system("tar $cr -C / -f $backupdir/backup$backuptype.$curtime.$filedirs.tar $Nt $dir") || &admin_fatal_error("","'tar $cr -C / -f $backupdir/backup$backuptype.$curtime.$filedirs.tar $Nt $dir' $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8));
   
   } elsif ($backupmethod eq '/usr/bin/zip') {    } elsif ($backupmethod eq '/usr/bin/zip') {
       my $recurseoption;        my $recurseoption;
       if (!$recursemode) { $dir .= '/*.*'; }        if (!$recursemode) { $dir .= '/*.*'; }
       else { $recurseoption = 'r'; }        else { $recurseoption = 'r'; }
       if ($FORM{'backupnewest'}) { $Nt = "-t $FORM{'backupnewest'}"; }        if ($FORM{'backupnewest'}) { $Nt = "-t $FORM{'backupnewest'}"; }
       &ak_system("zip -gq$recurseoption $Nt $backupdir/backup$backuptype.$curtime.$filedirs.zip $dir") || &admin_fatal_error("","'zip -gq$recurseoption $Nt $backupdir/backup$backuptype.$curtime.$filedirs.zip $dir' $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8));        &ak_system("zip -gq$recurseoption $Nt $backupdir/backup$backuptype.$curtime.$filedirs.zip $dir") || &admin_fatal_error("","'zip -gq$recurseoption $Nt $backupdir/backup$backuptype.$curtime.$filedirs.zip $dir' $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8));
   
   } elsif ($backupmethod eq 'Archive::Tar') {    } elsif ($backupmethod eq 'Archive::Tar') {
       $tarball->add_files(&RecurseDirectory($dir, $recursemode));        $tarball->add_files(&RecurseDirectory($dir, $recursemode));
   
   } elsif ($backupmethod eq 'Archive::Zip') {    } elsif ($backupmethod eq 'Archive::Zip') {
       map { $zipfile->addFile($_) } &RecurseDirectory($dir, $recursemode);        map { $zipfile->addFile($_) } &RecurseDirectory($dir, $recursemode);
   }    }
} }
   
sub RecurseDirectory { sub RecurseDirectory {
   # Simple subroutine to run through every entry in a directory and return a giant list of the files/subdirs.    # Simple subroutine to run through every entry in a directory and return a giant list of the files/subdirs.
   my ($dir,$recursemode) = @_;    my ($dir,$recursemode) = @_;
   my ($item, @dirlist, @newcontents);    my ($item, @dirlist, @newcontents);
   
   opendir(RECURSEDIR, $dir);    opendir(RECURSEDIR, $dir);
   @dirlist = readdir(RECURSEDIR);    @dirlist = readdir(RECURSEDIR);
   closedir(RECURSEDIR);    closedir(RECURSEDIR);
   
   foreach $item (@dirlist) {    foreach $item (@dirlist) {
       if ($recursemode && $item ne '.' && $item ne '..' && -d "$dir/$item") { push(@newcontents, &RecurseDirectory("$dir/$item", $recursemode)); }        if ($recursemode && $item ne '.' && $item ne '..' && -d "$dir/$item") { push(@newcontents, &RecurseDirectory("$dir/$item", $recursemode)); }
       elsif (-f "$dir/$item" && (!$FORM{'backupnewest'} || $FORM{'backupnewest'} > -M "$dir/$item")) {        elsif (-f "$dir/$item" && (!$FORM{'backupnewest'} || $FORM{'backupnewest'} > -M "$dir/$item")) {
           push(@newcontents, "$dir/$item");            push(@newcontents, "$dir/$item");
       }        }
   }    }
   @newcontents;    @newcontents;
} }
   
# Compresses the tar # Compresses the tar
sub BackupMethodFinalize { sub BackupMethodFinalize {
   my ($filedirs,$loop) = @_;    my ($filedirs,$loop) = @_;
   if (!$loop && $backupmethod eq '/usr/bin/tar') {    if (!$loop && $backupmethod eq '/usr/bin/tar') {
       if ($compressmethod eq '/bin/bzip2') {        if ($compressmethod eq '/bin/bzip2') {
           &ak_system("bzip2 -z $backupdir/backup$backuptype.$curtime.$filedirs.tar") || &admin_fatal_error("","'bzip2 -z $backupdir/backup$backuptype.$curtime.$filedirs.tar.bz2' $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8));            &ak_system("bzip2 -z $backupdir/backup$backuptype.$curtime.$filedirs.tar") || &admin_fatal_error("","'bzip2 -z $backupdir/backup$backuptype.$curtime.$filedirs.tar.bz2' $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8));
   
       } elsif ($compressmethod eq '/bin/gzip') {        } elsif ($compressmethod eq '/bin/gzip') {
           &ak_system("gzip $backupdir/backup$backuptype.$curtime.$filedirs.tar") || &admin_fatal_error("","'gzip $backupdir/backup$backuptype.$curtime.$filedirs.tar.gz' $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8));            &ak_system("gzip $backupdir/backup$backuptype.$curtime.$filedirs.tar") || &admin_fatal_error("","'gzip $backupdir/backup$backuptype.$curtime.$filedirs.tar.gz' $backup_txt{31}: $!. $backup_txt{32} " . ($? >> 8));
       }        }
   
   } elsif ($backupmethod eq 'Archive::Tar') {    } elsif ($backupmethod eq 'Archive::Tar') {
       if ($loop || $compressmethod eq 'none') {        if ($loop || $compressmethod eq 'none') {
           $tarball->write("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar", 0);            $tarball->write("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar", 0);
   
       } elsif ($compressmethod eq 'Compress::Zlib') { # Gzip as a module        } elsif ($compressmethod eq 'Compress::Zlib') { # Gzip as a module
           my ($gzip) = gzopen("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar.gz", 'wb');            my ($gzip) = gzopen("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar.gz", 'wb');
           $gzip->gzwrite($tarball->write);            $gzip->gzwrite($tarball->write);
           $gzip->gzclose();            $gzip->gzclose();
           unlink("$backupdir/backup$backuptype.$curtime.$filedirs.tar");            unlink("$backupdir/backup$backuptype.$curtime.$filedirs.tar");
   
       } elsif ($compressmethod eq 'Compress::Bzip2') { # Bzip2 as a module        } elsif ($compressmethod eq 'Compress::Bzip2') { # Bzip2 as a module
           my ($bzip2) = bzopen("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar.bz2", 'wb');            my ($bzip2) = bzopen("$backupdir/backup$backuptype.$curtime.$filedirs.a.tar.bz2", 'wb');
           $bzip2->bzwrite($tarball->write);            $bzip2->bzwrite($tarball->write);
           $bzip2->bzclose();            $bzip2->bzclose();
           unlink("$backupdir/backup$backuptype.$curtime.$filedirs.tar");            unlink("$backupdir/backup$backuptype.$curtime.$filedirs.tar");
       }        }
   
   } elsif ($backupmethod eq 'Archive::Zip') {    } elsif ($backupmethod eq 'Archive::Zip') {
       $zipfile->overwriteAs("$backupdir/backup$backuptype.$curtime.$filedirs.a.zip");        $zipfile->overwriteAs("$backupdir/backup$backuptype.$curtime.$filedirs.a.zip");
   }    }
} }
   
sub ak_system { # Returns a success code. The system's code returned is $? >> 8 sub ak_system { # Returns a success code. The system's code returned is $? >> 8
   CORE::system(@_);    CORE::system(@_);
   if ($? == -1) { return ''; } # Failed to execute; return a null string.    if ($? == -1) { return ''; } # Failed to execute; return a null string.
   elsif ($? & 127) { return 0; } # Died, return 0.    elsif ($? & 127) { return 0; } # Died, return 0.
   1; # Success; return 1.    1; # Success; return 1.
} }
   
sub runbackup_loop { sub runbackup_loop {
   my ($i,$j,$curtime,$backupnewest,$backuptime) = @_;    my ($i,$j,$curtime,$backupnewest,$backuptime) = @_;
   
   $yymain .= qq~</b>    $yymain .= qq~</b>
   <p id="memcontinued">    <p id="memcontinued">
       $admin_txt{'542'} <a href="$adminurl?action=runbackup;loop1=$i;loop2=$j;curtime=$curtime;backupnewest=$backupnewest;backuptime=$backuptime;runbackup_again=$INFO{'runbackup_again'}" onclick="PleaseWait();">$admin_txt{'543'}</a>.<br />        $admin_txt{'542'} <a href="$adminurl?action=runbackup;loop1=$i;loop2=$j;curtime=$curtime;backupnewest=$backupnewest;backuptime=$backuptime;runbackup_again=$INFO{'runbackup_again'}" onclick="PleaseWait();">$admin_txt{'543'}</a>.<br />
       $backup_txt{'90'}        $backup_txt{'90'}
   </p>    </p>
   
   <script type="text/javascript">    <script type="text/javascript">
    <!--     <!--
       function PleaseWait() {        function PleaseWait() {
           document.getElementById("memcontinued").innerHTML = '<font color="red"><b>$backup_txt{'91'}</b></font><br />&nbsp;<br />&nbsp;';            document.getElementById("memcontinued").innerHTML = '<font color="red"><b>$backup_txt{'91'}</b></font><br />&nbsp;<br />&nbsp;';
       }        }
   
       function stoptick() { stop = 1; }        function stoptick() { stop = 1; }
   
       stop = 0;        stop = 0;
       function membtick() {        function membtick() {
           if (stop != 1) {            if (stop != 1) {
               PleaseWait();                PleaseWait();
               location.href="$adminurl?action=runbackup;loop1=$i;loop2=$j;curtime=$curtime;backupnewest=$backupnewest;backuptime=$backuptime;runbackup_again=$INFO{'runbackup_again'}";                location.href="$adminurl?action=runbackup;loop1=$i;loop2=$j;curtime=$curtime;backupnewest=$backupnewest;backuptime=$backuptime;runbackup_again=$INFO{'runbackup_again'}";
           }            }
       }        }
   
       setTimeout("membtick()",2000);        setTimeout("membtick()",2000);
    // -->     // -->
   </script>~;    </script>~;
   
   &AdminTemplate;    &AdminTemplate;
} }
   
sub CheckPath { sub CheckPath {
   my ($path, $file);    my ($path, $file);
   $file = $_[0];    $file = $_[0];
   
   if (-e $file) { return $file; }    if (-e $file) { return $file; }
   
   $file =~ s~\A.*\/~~;    $file =~ s~\A.*\/~~;
   
   foreach $path (@ENVpaths) {    foreach $path (@ENVpaths) {
       $path =~ s~\/\Z~~;        $path =~ s~\/\Z~~;
       if (-e "$path/$file") { return "$path/$file"; }        if (-e "$path/$file") { return "$path/$file"; }
   }    }
} }
   
# Thanks to BBQ at PerlMonks for the basis of this routine: http://www.perlmonks.org/?node_id=9277 # Thanks to BBQ at PerlMonks for the basis of this routine: http://www.perlmonks.org/?node_id=9277
sub downloadbackup { sub downloadbackup {
   chdir($backupdir) || &admin_fatal_error("","$backup_txt{44} $backupdir",1);    chdir($backupdir) || &admin_fatal_error("","$backup_txt{44} $backupdir",1);
   my $filename = $INFO{'backupid'};    my $filename = $INFO{'backupid'};
   if ($filename !~ /\Abackup/ || $filename !~ /\d{9,10}/) { &admin_fatal_error("",$backup_txt{'45'}); }    if ($filename !~ /\Abackup/ || $filename !~ /\d{9,10}/) { &admin_fatal_error("",$backup_txt{'45'}); }
   my $filesize = -s $filename;    my $filesize = -s $filename;
   
   # print full header    # print full header
   print "Content-disposition: inline; filename=$filename\n";    print "Content-disposition: inline; filename=$filename\n";
   print "Content-Length: $filesize\n";    print "Content-Length: $filesize\n";
   print "Content-Type: application/octet-stream\n\n";    print "Content-Type: application/octet-stream\n\n";
   
   # open in binmode    # open in binmode
   fopen(READ, $filename) || &admin_fatal_error("","$backup_txt{46} $filename",1);    fopen(READ, $filename) || &admin_fatal_error("","$backup_txt{46} $filename",1);
   binmode READ;    binmode READ;
   
   # stream it out    # stream it out
   binmode STDOUT;    binmode STDOUT;
   while (<READ>) {print;}    while (<READ>) {print;}
   fclose(READ);    fclose(READ);
} }
   
sub deletebackup { sub deletebackup {
   my $filename = $INFO{'backupid'};    my $filename = $INFO{'backupid'};
   if ($filename !~ /\Abackup/ || $filename !~ /\d{9,10}/) { &admin_fatal_error("",$backup_txt{'45'}); }    if ($filename !~ /\Abackup/ || $filename !~ /\d{9,10}/) { &admin_fatal_error("",$backup_txt{'45'}); }
   
   $yymain = qq~    $yymain = qq~
$backup_txt{47} $filename $backup_txt{48} $backup_txt{47} $filename $backup_txt{48}
<br /> <br />
<br /><a href="$adminurl?action=deletebackup2;backupid=$filename">$backup_txt{49}</a> | <a href="$adminurl?action=backupsettings">$backup_txt{50}</a> <br /><a href="$adminurl?action=deletebackup2;backupid=$filename">$backup_txt{49}</a> | <a href="$adminurl?action=backupsettings">$backup_txt{50}</a>
~; ~;
   
   &AdminTemplate;    &AdminTemplate;
} }
   
sub deletebackup2 { sub deletebackup2 {
   my $filename = $INFO{'backupid'};    my $filename = $INFO{'backupid'};
   if ($filename !~ /\Abackup/ || $filename !~ /\d{9,10}/) { &admin_fatal_error("",$backup_txt{'45'}); }    if ($filename !~ /\Abackup/ || $filename !~ /\d{9,10}/) { &admin_fatal_error("",$backup_txt{'45'}); }
   
   # Just remove it!    # Just remove it!
   unlink("$backupdir/$filename") || &admin_fatal_error("","$backup_txt{51} $backupdir/$filename",1);    unlink("$backupdir/$filename") || &admin_fatal_error("","$backup_txt{51} $backupdir/$filename",1);
   
   $yySetLocation = "$adminurl?action=backupsettings";    $yySetLocation = "$adminurl?action=backupsettings";
   &redirectexit();    &redirectexit();
} }
   
sub emailbackup { sub emailbackup {
   # Unfourtantly, we can't use &sendmail() for this.    # Unfourtantly, we can't use &sendmail() for this.
   # So, we'll load MIME::Lite and try that, as it should work.    # So, we'll load MIME::Lite and try that, as it should work.
   # If not, we'll email out a download link.    # If not, we'll email out a download link.
   my ($mainmessage, $filename);    my ($mainmessage, $filename);
   
   $filename = $INFO{'backupid'};    $filename = $INFO{'backupid'};
   if ($filename !~ /\Abackup/ || $filename !~ /\d{9,10}/) { &admin_fatal_error("",$backup_txt{'45'}); }    if ($filename !~ /\Abackup/ || $filename !~ /\d{9,10}/) { &admin_fatal_error("",$backup_txt{'45'}); }
   
   # Try to safely load MIME::Lite    # Try to safely load MIME::Lite
   eval 'use MIME::Lite;';    eval 'use MIME::Lite;';
   if (!$@ && !$INFO{'linkmail'}) { # We can use MIME::Lite.    if (!$@ && !$INFO{'linkmail'}) { # We can use MIME::Lite.
       my $filesize = -s "$backupdir/$filename";        my $filesize = -s "$backupdir/$filename";
       $filesize = int($filesize / 1024); # Measure it in kilobytes        $filesize = int($filesize / 1024); # Measure it in kilobytes
       if (!$INFO{'passwarning'} && $filesize > 1024 * 4) { # Warn if the file-size is to big for email (> 4 MB)        if (!$INFO{'passwarning'} && $filesize > 1024 * 4) { # Warn if the file-size is to big for email (> 4 MB)
           if ($filesize > 1024 * 4) { $filesize = int($filesize / 1024) . ' MB'; } # Measure it in megabytes            if ($filesize > 1024 * 4) { $filesize = int($filesize / 1024) . ' MB'; } # Measure it in megabytes
           else { $filesize .= ' KB'; } # Label it            else { $filesize .= ' KB'; } # Label it
   
           $yymain = qq~            $yymain = qq~
$backup_txt{54}?<br /> $backup_txt{54}?<br />
$backup_txt{55} <b>$filesize</b>!<br /> $backup_txt{55} <b>$filesize</b>!<br />
<br /> <br />
<a href="$adminurl?action=emailbackup;backupid=$INFO{'backupid'};passwarning=1">$backup_txt{56} <i>${$uid.$username}{'email'}</i></a><br /> <a href="$adminurl?action=emailbackup;backupid=$INFO{'backupid'};passwarning=1">$backup_txt{56} <i>${$uid.$username}{'email'}</i></a><br />
<a href="$adminurl?action=emailbackup;backupid=$INFO{'backupid'};linkmail=1">$backup_txt{57}</a><br /> <a href="$adminurl?action=emailbackup;backupid=$INFO{'backupid'};linkmail=1">$backup_txt{57}</a><br />
<a href="$adminurl?action=downloadbackup;backupid=$INFO{'backupid'}">$backup_txt{58}</a><br /> <a href="$adminurl?action=downloadbackup;backupid=$INFO{'backupid'}">$backup_txt{58}</a><br />
<a href="$adminurl?action=backupsettings">$backup_txt{59}</a> <a href="$adminurl?action=backupsettings">$backup_txt{59}</a>
~; ~;
           &AdminTemplate;            &AdminTemplate;
       }        }
   
       $mainmessage = $backup_txt{'mailmessage1'};        $mainmessage = $backup_txt{'mailmessage1'};
       $mainmessage =~ s~USERNAME~${$uid.$username}{'realname'}~g;        $mainmessage =~ s~USERNAME~${$uid.$username}{'realname'}~g;
       $mainmessage =~ s~LINK~$adminurl?action=downloadbackup;backupid=$filename~g;        $mainmessage =~ s~LINK~$adminurl?action=downloadbackup;backupid=$filename~g;
       $mainmessage =~ s~FILENAME~$filename~g;        $mainmessage =~ s~FILENAME~$filename~g;
   
       eval q^        eval q^
           my $msg = MIME::Lite->new(            my $msg = MIME::Lite->new(
               To      => ${$uid.$username}{'email'},                To      => ${$uid.$username}{'email'},
               From    => $backup_txt{'mailfrom'},                From    => $backup_txt{'mailfrom'},
               Subject => $backup_txt{'mailsubject'},                Subject => $backup_txt{'mailsubject'},
               Type    => 'multipart/mixed'                 Type    => 'multipart/mixed' 
               );                );
           $msg->attach(            $msg->attach(
               Type => 'TEXT',                Type => 'TEXT',
               Data => $mainmessage                Data => $mainmessage
           );            );
           $msg->attach(            $msg->attach(
               Type     => 'AUTO', # Let it be auto-detected.                Type     => 'AUTO', # Let it be auto-detected.
               Filename => $filename,                Filename => $filename,
               Path     => "$backupdir/$filename",                Path     => "$backupdir/$filename",
           );            );
           if (!$mailtype) {            if (!$mailtype) {
               $msg->send();                $msg->send();
           } else {            } else {
               my @arg = ("$smtp_server", Hello => "$smtp_server", Timeout => 30);                my @arg = ("$smtp_server", Hello => "$smtp_server", Timeout => 30);
               push(@arg, AuthUser => "$authuser") if $authuser;                push(@arg, AuthUser => "$authuser") if $authuser;
               push(@arg, AuthPass => "$authpass") if $authpass;                push(@arg, AuthPass => "$authpass") if $authpass;
               $msg->send('smtp', @arg);                $msg->send('smtp', @arg);
           }            }
       ^;        ^;
   }    }
   
   if ($@ || $INFO{'linkmail'}) {    if ($@ || $INFO{'linkmail'}) {
       $mainmessage = ($INFO{'linkmail'} && !$@) ? $backup_txt{'mailmessage2'} : $backup_txt{'mailmessage3'};        $mainmessage = ($INFO{'linkmail'} && !$@) ? $backup_txt{'mailmessage2'} : $backup_txt{'mailmessage3'};
       $mainmessage =~ s~USERNAME~${$uid.$username}{'realname'}~;        $mainmessage =~ s~USERNAME~${$uid.$username}{'realname'}~;
       $mainmessage =~ s~LINK~$adminurl?action=downloadbackup;backupid=$filename~;        $mainmessage =~ s~LINK~$adminurl?action=downloadbackup;backupid=$filename~;
       $mainmessage =~ s~FILENAME~$filename~;        $mainmessage =~ s~FILENAME~$filename~;
       $mainmessage =~ s~SYSTEMINFO~$@~;        $mainmessage =~ s~SYSTEMINFO~$@~;
   
       require "$sourcedir/Mailer.pl";        require "$sourcedir/Mailer.pl";
       &sendmail(${$uid.$username}{'email'}, $backup_txt{'mailsubject'}, $mainmessage, $backup_txt{'mailfrom'});        &sendmail(${$uid.$username}{'email'}, $backup_txt{'mailsubject'}, $mainmessage, $backup_txt{'mailfrom'});
   
       $yySetLocation = "$adminurl?action=backupsettings&mailinfo=-1";        $yySetLocation = "$adminurl?action=backupsettings&mailinfo=-1";
   } else {    } else {
       $yySetLocation = "$adminurl?action=backupsettings&mailinfo=1";        $yySetLocation = "$adminurl?action=backupsettings&mailinfo=1";
   }    }
   
   &redirectexit();    &redirectexit();
} }
   
sub recoverbackup1 { sub recoverbackup1 {
   $INFO{'recoverfile'} =~ /\A(backup)(n?)\.(\d+)\.([^\.]+)\.(.+)/;    $INFO{'recoverfile'} =~ /\A(backup)(n?)\.(\d+)\.([^\.]+)\.(.+)/;
   
   my @dirs;    my @dirs;
   foreach (split(/_/, $4)) {    foreach (split(/_/, $4)) {
       push(@dirs, $dirs{$_});        push(@dirs, $dirs{$_});
   }    }
   
   $yymain .= qq~    $yymain .= qq~
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
   function CheckCHMOD (v,min,t) {    function CheckCHMOD (v,min,t) {
       if (v == '') {        if (v == '') {
           return;            return;
       } else if (/\\D/.test(v)) {        } else if (/\\D/.test(v)) {
           alert('$backup_txt{112}');            alert('$backup_txt{112}');
           t.value = '';            t.value = '';
       } else if (v < min) {        } else if (v < min) {
           alert('$backup_txt{110} ' + min);            alert('$backup_txt{110} ' + min);
           t.value = min;            t.value = min;
       } else if (v > 7) {        } else if (v > 7) {
           alert('$backup_txt{111}');            alert('$backup_txt{111}');
           t.value = 7;            t.value = 7;
       }        }
   }    }
--> -->
</script> </script>
<div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;"> <div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;">
  <form action="$adminurl?action=recoverbackup2" method="post" name="recover">   <form action="$adminurl?action=recoverbackup2" method="post" name="recover">
  <table width="100%" cellspacing="1" cellpadding="10">   <table width="100%" cellspacing="1" cellpadding="10">
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="titlebg" colspan="2">       <td align="left" class="titlebg" colspan="2">
        <img src="$imagesdir/preferences.gif" alt="" border="0" /><b>$backup_txt{100}</b>         <img src="$imagesdir/preferences.gif" alt="" border="0" /><b>$backup_txt{100}</b>
      </td>       </td>
    </tr>     </tr>
    <tr valign="middle">     <tr valign="middle">
      <td align="left" class="windowbg2" colspan="2">       <td align="left" class="windowbg2" colspan="2">
        $backup_txt{101}<br />         $backup_txt{101}<br />
        <br />         <br />
        - ~ . join('<br />- ', @dirs) . qq~<br />         - ~ . join('<br />- ', @dirs) . qq~<br />
        <br />         <br />
        $backup_txt{102}<br />         $backup_txt{102}<br />
        <br />         <br />
        <i>$INFO{'recoverfile'}</i>~ . ($2 ? " (<b>$backup_txt{62}</b>)" : '') . qq~ $backup_txt{103} ~ . &timeformat($3) . qq~<br />         <i>$INFO{'recoverfile'}</i>~ . ($2 ? " (<b>$backup_txt{62}</b>)" : '') . qq~ $backup_txt{103} ~ . &timeformat($3) . qq~<br />
        <br />         <br />
        <input type="button" onclick="window.location.href='$adminurl?action=backupsettings'" value="$backup_txt{125}" /><br />         <input type="button" onclick="window.location.href='$adminurl?action=backupsettings'" value="$backup_txt{125}" /><br />
        <br />         <br />
        $backup_txt{104},<br />         $backup_txt{104},<br />
        <br />         <br />
        <input type="checkbox" name="originalrestore" value="1" /> $backup_txt{105}<br />         <input type="checkbox" name="originalrestore" value="1" /> $backup_txt{105}<br />
        <br />         <br />
        $backup_txt{106}<br />         $backup_txt{106}<br />
        <table cellpadding="3">         <table cellpadding="3">
          <tr><td align="center" valign="middle"><b>$backup_txt{107}</b></td><td align="center" valign="middle"><b>$backup_txt{108}</b></td></tr>\n~;           <tr><td align="center" valign="middle"><b>$backup_txt{107}</b></td><td align="center" valign="middle"><b>$backup_txt{108}</b></td></tr>\n~;
   
   $INFO{'recoverfile'} =~ /\.tar(.*)$/;    $INFO{'recoverfile'} =~ /\.tar(.*)$/;
   my $recovertype = $1 eq '.gz' ? "tar -tzf $backupdir/$INFO{'recoverfile'} -C $backupdir/" : "tar -tf $backupdir/$INFO{'recoverfile'} -C $backupdir/";    my $recovertype = $1 eq '.gz' ? "tar -tzf $backupdir/$INFO{'recoverfile'} -C $backupdir/" : "tar -tf $backupdir/$INFO{'recoverfile'} -C $backupdir/";
   
   my %checkdir;    my %checkdir;
   foreach (split(/\n/, qx($recovertype))) {    foreach (split(/\n/, qx($recovertype))) {
       next if -d "/$_/";        next if -d "/$_/";
       $_ =~ /(.*\/)(.*)/;        $_ =~ /(.*\/)(.*)/;
       if (!$checkdir{$1} && $2) {