Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(!isset($_SERVER['HTTPS'])) {
- header('HTTP/1.1 301 Moved Permanently');
- header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
- exit();
- }
- $mimes = [
- 'tar' => 'application/x-tar',
- 'tar.gz' => 'application/x-gzip',
- 'tar.bz2' => 'application/x-bzip2',
- 'tar.xz' => 'application/x-xz',
- 'zip' => 'application/zip'
- ];
- $cmds = [
- 'tar' => 'tar c .',
- 'tar.gz' => 'tar c . |gzip -9',
- 'tar.bz2' => 'tar c . |bzip2 -9',
- 'tar.xz' => 'tar c . |xz -9',
- 'zip' => 'zip -qr9 - .'
- ];
- if(isset($_REQUEST['fmt'])) {
- $fmt = $_REQUEST['fmt'];
- if(!isset($mimes[$fmt]) || !isset($cmds[$fmt]))
- exit("Invalid format $fmt");
- $bkdate = date('Ymd_Hi');
- header("Content-Type: {$mimes[$fmt]}");
- header("Content-Disposition: attachment; filename=\"backup-{$_SERVER['HTTP_HOST']}-$bkdate.$fmt\"");
- set_time_limit(3600);
- passthru($cmds[$fmt]);
- exit();
- }
- ?>
- <html>
- <head>
- <title>Tar backup</title>
- </head>
- <body>
- <form action="<?php echo $_SERVER['REQUEST_URI']?>" method="POST">
- Archive format:
- <select name="fmt">
- <?php
- foreach($mimes as $type => $mime)
- echo "<option>$type</option>";
- ?>
- </select>
- <br>
- <input type="submit">
- <form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement