"application/x-tar", "iso" => "application/x-iso", "gz" => "application/octet-stream", "exe" => "application/octet-stream", "other" => "application/octet-stream"); if ($_GET['file'] == "customized") { // Benutzerdefiniertes ISO require_once("templates/download.inc.php"); session_start(); $custompath = $config['download'] . "/custom/"; $tmppath = $custompath . session_id(); `cd $custompath; find -maxdepth 1 -mmin +60 -type d ! -name .. ! -name . -exec rm -r "{}" ";"`; `rm -rf "$tmppath"`; mkdir("$tmppath") || die("Can't create temp dir!"); mkdir("$tmppath/iso") || die("Can't create temp dir!"); `tar -xzf {$_SESSION['customize']['base']} -C $tmppath/iso`; # echo "tar -xzf {$_SESSION['customize']['base']} -C $tmppath/iso"; # exit; if (is_dir("$tmppath/iso/boot/grub/")) { chmod("$tmppath/iso/boot/grub/stage2_eltorito", 0644); } @mkdir("$tmppath/iso/etc"); $download = new Download($_SESSION['customize']['path']); $files = $download->getFiles("base", $_SESSION['customize']['stable']); if (isset($files['kernel'])) { $old = "$tmppath/iso/boot/*kernel*"; $src = $files['kernel']['path'] . $files['kernel']['filename']; `rm $old`; `ln "$src" "$tmppath/iso/boot/kernel"`; `touch "$tmppath/iso/boot/{$files['kernel']['filename']}"`; } $version = 0; $deps = $download->dependencies; $files = $download->getFiles("vdr-", $_SESSION['customize']['stable']); $files = $files ? $files : $download->getFiles("vdrapi-", $_SESSION['customize']['stable']); $files = array_merge($files, $download->getFiles("system", $_SESSION['customize']['stable'])); @mkdir("$tmppath/iso/addons"); @mkdir("$tmppath/iso/addons/inactive"); function addAddon($addon, $state) { global $version, $tmppath, $files, $deps; if (isset ($files[$addon])) { $src = $files[$addon]['path'] . $files[$addon]['filename']; $desc = "$tmppath/iso/addons/" . ($state == -1 ? "inactive/" : "") . $files[$addon]['filename']; if (!file_exists($desc)) { `ln "$src" "$desc"`; if ($state != -1 && is_file("$tmppath/iso/addons/inactive/" . $files[$addon]['filename'])) { unlink("$tmppath/iso/addons/inactive/" . $files[$addon]['filename']); } else { $version += $files[$addon]['revision']; } if ($deps[$addon]) { foreach ($deps[$addon] as $addon) { addAddon($addon, $state); } } } } } if (isset ($_COOKIE['addons'])) { foreach ($_COOKIE['addons'] as $addon => $state) { addAddon($addon, $state); } } if (preg_match("/^3\./", $_SESSION['customize']['path'])) { `cd $tmppath/iso; mv addons etc/; cd etc/addons; ls MLD* > active; mv inactive/MLD* . 2>/dev/null; rm -r inactive`; } $basePrefix = preg_replace("/.*\/([^_]*).*/", "\\1", $_SESSION['customize']['base']); $baseVersion = preg_replace("/.*_(\d+)\.tgz/", "\\1", $_SESSION['customize']['base']); $unstable = $_SESSION['customize']['stable'] ? "" : "-latest"; $imagetype = is_dir("$tmppath/iso/boot/grub/") || is_dir("$tmppath/iso/boot/isolinux/") ? "iso" : "tgz"; $type = $types[$imagetype]; $name = "{$basePrefix}_customized{$unstable}-{$version}_{$baseVersion}.{$imagetype}"; $file = "$tmppath/$name"; $logname = preg_replace("/.*\/(.*)_base-(.*)/", "\\1_customize-\\2", $_SESSION['customize']['base']); $version = $_SESSION['customize']['path']; if (is_dir("$tmppath/iso/boot/grub/")) { `mkisofs -R -J -V "MLD-$version" -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o $file $tmppath/iso 2>/dev/null`; } else if (is_dir("$tmppath/iso/boot/isolinux/")) { `mkisofs -R -J -V "MLD-$version" -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o $file $tmppath/iso 2>/dev/null`; `isohybrid $file`; } else { `tar -czf $file -C $tmppath/iso . 2>/dev/null`; } ignore_user_abort(true); if ($fp = @fopen("{$config['logs']}customize.txt", "r+")) { if (flock($fp, LOCK_EX)) { $customize = unserialize(fread($fp, filesize("{$config['logs']}customize.txt") + 1)); $customize['all'] = isset ($customize['all']) ? $customize['all'] + 1 : 1; if (isset ($_COOKIE['addons'])) { foreach ($_COOKIE['addons'] as $addon => $state) { if (isset ($files[$addon])) { $customize[$addon] = isset ($customize[$addon]) ? $customize[$addon] + 1 : 1; } } } rewind($fp); fwrite($fp, serialize($customize)); flock($fp, LOCK_UN); } fclose($fp); } else { @touch("{$config['logs']}customize.txt"); } ignore_user_abort(false); session_write_close(); } else { // Normale Datei if (empty($_GET['file'])) { header(true, true, 406); exit("Dateiname fehlt!"); } $file = $config['download'] . preg_replace("/\.{2,}/", "", $_GET['file']); $type = preg_replace("/.*\.([^.]+)$|.*/", "\\1", $_GET['file']); $type = isset ($types[$type]) ? $types[$type] : $types['other']; $name = preg_replace("/.*\/(.*)|.*/", "\\1", $_GET['file']); $logname = $name; if (!$name || !file_exists($file)) { header(true, true, 404); exit("Unbekannte Datei!"); } } if (preg_match("#/docs/|\.txt$#", $_GET['file'])) { // show file header("Content-Type: text/plain; charset=UTF8"); header("Content-Disposition: filename=" . $name); header("Content-Length: " . filesize($file)); } else { // download file if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private"); // IE6 bug fix header("Content-Type: $type"); if (strstr($_SERVER['HTTP_USER_AGENT'], "mac")) { header("Content-Type: application/x-macbinary"); } else { header("Content-Type: application/force-download"); } if (strstr($_SERVER['HTTP_USER_AGENT'], "msie") && strstr($_SERVER['HTTP_USER_AGENT'], "win")) { header("Content-Disposition: filename=" . $name); } else { header("Content-Disposition: attachment; filename=" . $name); } header("Content-Description: File Transfer"); header("Content-Length: " . filesize($file)); // Download Statistik $db = new Database("data", $GLOBALS['config']['db']); $db->query("UPDATE state SET access=access+1 WHERE filename='$logname'"); } $fd = fopen($file, "rb"); while ($fd && !feof($fd)) { echo fread($fd, 4096); flush(); } fclose($fd); ?>