Advertisement
teknoraver

Untitled

Dec 19th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2. if(!isset($_SERVER['HTTPS'])) {
  3.     header('HTTP/1.1 301 Moved Permanently');
  4.     header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
  5.     exit();
  6. }
  7.  
  8. $mimes = [
  9.     'tar'       => 'application/x-tar',
  10.     'tar.gz'    => 'application/x-gzip',
  11.     'tar.bz2'   => 'application/x-bzip2',
  12.     'tar.xz'    => 'application/x-xz',
  13.     'zip'       => 'application/zip'
  14. ];
  15.  
  16. $cmds = [
  17.     'tar'       => 'tar c .',
  18.     'tar.gz'    => 'tar c . |gzip -9',
  19.     'tar.bz2'   => 'tar c . |bzip2 -9',
  20.     'tar.xz'    => 'tar c . |xz -9',
  21.     'zip'       => 'zip -qr9 - .'
  22. ];
  23.  
  24. if(isset($_REQUEST['fmt'])) {
  25.     $fmt = $_REQUEST['fmt'];
  26.     if(!isset($mimes[$fmt]) || !isset($cmds[$fmt]))
  27.         exit("Invalid format $fmt");
  28.  
  29.     $bkdate = date('Ymd_Hi');
  30.  
  31.     header("Content-Type: {$mimes[$fmt]}");
  32.     header("Content-Disposition: attachment; filename=\"backup-{$_SERVER['HTTP_HOST']}-$bkdate.$fmt\"");
  33.  
  34.     set_time_limit(3600);
  35.     passthru($cmds[$fmt]);
  36.     exit();
  37. }
  38.  
  39. ?>
  40. <html>
  41.     <head>
  42.         <title>Tar backup</title>
  43.     </head>
  44.     <body>
  45.         <form action="<?php echo $_SERVER['REQUEST_URI']?>" method="POST">
  46.             Archive format:
  47.             <select name="fmt">
  48.                 <?php
  49.                 foreach($mimes as $type => $mime)
  50.                     echo "<option>$type</option>";
  51.                 ?>
  52.  
  53.             </select>
  54.             <br>
  55.             <input type="submit">
  56.         <form>
  57.     </body>
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement