                                                                                                                                                        

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
  include "/home/waggacwc/public_html/refurb/RETRO-GLOBALS.php";

  include "$LIBRARYPATH/fnRetrovoxStartHtml.php";

  $bNewFile = false;
  $sFilePath = '';
  $sFilePath = $_GET['directory'];

  if (substr($sFilePath, 0, 1) != "/")
  {
    $sFilePath = "/$sFilePath";  
  }
  
  /*
  if (!strstr($sFilePath, "/usr50/home/retrovox"))
  {
    $sFilePath = "/usr50/home/retrovox".$sFilePath;
  }
  */ 
  
  if (substr($sFilePath, -1) != "/")
  {
    $sFilePath = "$sFilePath/";  
  }

  $sFilePathEncoded = htmlspecialchars($sFilePath);
  $sFilePathUrlEncoded = htmlspecialchars(urlencode($sFilePath));
  $sWebFilePathEncoded = htmlspecialchars(str_replace("public_html", "", $sFilePath));

  
  if ($sFilePath == '/usr50/home/retrovox/')
  {
    echo fnRetrovoxStartHtml("No folder name was specified");
    echo "
     <p>You did not specify any folder to be backed up</p>
     <br>
     <a href = 'backup-directory-form.php'>
          Re-enter the folder name</a>
     </body>
     </html>";
     exit; 
  } //-- if no file specified
 
  if (!file_exists($sFilePath))
  {
    echo fnRetrovoxStartHtml("The folder does not exist");
    echo "
       <br>
       <ol  type = 'a'>
       <li>
   <a href = \"backup-directory-form.php?file=$sFilePathUrlEncoded\">
           Re-enter the folder name</a></li>
          <li>
          </ol>
           
      </body>
      </html>";
      exit; 
  } //-- if file doesn't exist
  
  
  if (!is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }
    
    echo fnRetrovoxStartHtml("No path is not a directory");
    echo "
      <p>
       The folder-name<br>
       &nbsp;&nbsp;<em>$sFilePathEncoded</em><br>
       which you just specified is not a directory (folder).
      </p>
      <br>
       <ol>
        <li>
   <a href = \"backup-directory-form.php?folder=$sFilePathUrlEncoded\">
       Re-enter the file name</a></li>
          
	</ol>";

        echo "  
        </body>
        </html>";
      
     exit;
  } //-- if file is not a directory

  //$sBackupFileName = "junk.tar.gz";
  $sLeafFolderName = preg_replace('#^.*/([^/]+)/$#', '$1', $sFilePath); 
  $sBackupFileName = "retrovox-$sLeafFolderName-dir.tar.gz";
  $sBackupFilePath = "$WEBROOT/retrovox-$sLeafFolderName-dir.tar.gz";

  $sCommandResult = 
     shell_exec('tar -zcvf '.$sBackupFilePath.' '.$sFilePath.' 2>&1');
//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>

<?=fnRetrovoxStartHtml("The server directory has been backed up")?>

  <strong>The directory:</strong>
    <br>&nbsp;&nbsp;<em><?=$sFilePath?></em> 
  <br><strong>should have been backed up to the file:</strong>
    <br><a href = '/<?=$sBackupFileName?>'>/<?=$sBackupFileName?></a>
  <br>
  The backup command returned the following messages (if these messages
  only contain a list of file names, then the backup worked).
  <br>
  <pre>
    <?=htmlspecialchars($sCommandResult)?>
  </pre>
</body>
</html>



                                                                                                                                                        