"application/x-tar", "iso" => "application/x-iso", "img" => "application/octet-stream", "gz" => "application/octet-stream", "exe" => "application/octet-stream", "other" => "application/octet-stream"); $ln = "cp"; if (preg_match("/customized/", $_GET['file'])) { // Benutzerdefiniertes ISO require_once("templates/download.inc.php"); session_start(); if (empty($_SESSION['customize'])) { header(true, true, 406); exit("Veralteter Download Link!"); } $custompath = $config['download'] . "/custom/"; $tmppath = $custompath . session_id(); `cd $custompath; find -maxdepth 1 -mmin +60 -type d ! -name .. ! -name . -exec rm -r "{}" ";" 2>/dev/null`; `rm -rf "$tmppath"`; mkdir("$tmppath") || die("Can't create temp dir!"); mkdir("$tmppath/iso") || die("Can't create temp dir!"); mkdir("$tmppath/log"); `tar -xzf {$_SESSION['customize']['base']} -C $tmppath/iso`; # echo "tar -xzf {$_SESSION['customize']['base']} -C $tmppath/iso"; # exit; if ($_SESSION['customize']['path'] >= "4.0.0") { $download = new Download($_SESSION['customize']['path']); $version = 0; if ($_SESSION['customize']['path'] >= "5") { $files = $download->getFiles("", $_SESSION['customize']['class'], $_SESSION['customize']['arch']); $destDir = "$tmppath/iso/dpkg/"; $arch = preg_replace("/.*(_.*)\..*/", "\\1", $_SESSION['customize']['base']); } else { $files = $download->getFiles("base/packages", $_SESSION['customize']['class']); $files = array_merge($files, $download->getFiles("libs/packages", $_SESSION['customize']['class'])); $destDir = "$tmppath/iso/opkg/"; } $deps = $download->dependencies; @mkdir($destDir); function addPackage($package) { global $version, $tmppath, $files, $deps, $destDir, $ln; if (isset ($files[$package])) { $src = $files[$package]['path'] . $files[$package]['filename']; $dest = $destDir . $files[$package]['filename']; if (!file_exists($dest) && !in_array($package, $deps['initramfs'])) { `$ln "$src" "$dest"`; if (!file_exists($dest)) { return; } $version += $files[$package]['revision']; if ($deps[$package]) { foreach ($deps[$package] as $package) { addPackage($package); } } } } } if (isset ($_COOKIE['addons'])) { foreach ($_COOKIE['addons'] as $package => $state) { addPackage($package); `echo "$package" >> $tmppath/log/selection`; } `ls $destDir > $tmppath/log/packages`; } // log information about the customized image $base = preg_replace("/.*\//", "", $_SESSION['customize']['base']); `echo "$base" >> $tmppath/log/base`; $logfile = tempnam("{$config['data']}logs", ""); umask(0); chmod($logfile, 0644); $logkey = preg_replace("/.*\//", "-", $logfile); `cd $tmppath/log; tar -czf $logfile *`; } else { 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']['class']); 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']['class']); $files = $files ? $files : $download->getFiles("vdrapi-", $_SESSION['customize']['class']); $files = array_merge($files, $download->getFiles("system", $_SESSION['customize']['class'])); @mkdir("$tmppath/iso/addons"); @mkdir("$tmppath/iso/addons/inactive"); function addAddon($addon, $state) { global $version, $tmppath, $files, $deps, $ln; if (isset ($files[$addon])) { $src = $files[$addon]['path'] . $files[$addon]['filename']; $dest = "$tmppath/iso/addons/" . ($state == -1 ? "inactive/" : "") . $files[$addon]['filename']; if (!file_exists($dest)) { `$ln "$src" "$dest"`; if (!file_exists($dest)) { return; } 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']); $class = $_SESSION['customize']['class']==1 ? "stable" : ($_SESSION['customize']['class'] ? $_SESSION['customize']['class'] : "testing"); $version = $_SESSION['customize']['path']; $imagetype = $version >= "5.4" ? (preg_match("/.iso/", $_GET['file']) ? "iso" : "img") : (is_dir("$tmppath/iso/boot/grub/") || is_dir("$tmppath/iso/boot/isolinux/") || is_dir("$tmppath/iso/syslinux/") ? "iso" : ($version < "5.3" ? (is_file("$tmppath/iso/u-boot.bin") ? "img.gz" : "tgz") : "img")); $type = $types[$imagetype]; $date = date("Y.m.d"); $name = "{$basePrefix}_customized_{$date}-{$baseVersion}+{$version}{$logkey}{$arch}.{$imagetype}"; // $name = "{$basePrefix}_customized-{$class}_{$date}-{$baseVersion}+{$version}{$arch}.{$imagetype}"; $file = "$tmppath/$name"; $logname = preg_replace("/.*\/(.*)_base([-_])(.*)/", "\\1_customize\\2\\3", $_SESSION['customize']['base']); if ($imagetype == "iso") { // x86 if (is_dir("$tmppath/iso/boot/grub/")) { // MLD-2 `genisoimage -R -J -V "MLD-$version" -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o $file $tmppath/iso &>$tmppath/log/build.log`; } else if (is_dir("$tmppath/iso/boot/isolinux/")) { // MLD-3 `genisoimage -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 &>$tmppath/log/build.log`; `isohybrid $file >>$tmppath/log/build.log 2>&1`; } else if ($version < "5.4") { // MLD-5 `genisoimage -R -J -V "MLD-$version" -b syslinux/isolinux.bin -c syslinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o $file $tmppath/iso &>$tmppath/log/build.log`; `isohybrid $file >>$tmppath/log/build.log 2>&1`; } else { // MLD-5.4 $timestamp = time(); `sed -e "s|root=\S*|root=UUID=\$(date -d @$timestamp '+%Y-%m-%d-%H-%M-%S-00') ro|g" $tmppath/iso/syslinux/syslinux.cfg > $tmppath/iso/syslinux/isolinux.cfg`; `genisoimage -R -J -V "MLD-$version" -modification-date=\$(date -d @$timestamp '+%Y%m%d%H%M%S00') -b syslinux/isolinux.bin -c syslinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o $file $tmppath/iso >$tmppath/log/build.log 2>&1`; `isohybrid $file >>$tmppath/log/build.log 2>&1`; } } else if ($imagetype == "tgz") { // RPI, WeTek as tgz bis MLD-5.1 `cd $tmppath/iso; tar -czf $file * &>$tmppath/log/build.log`; } else { // BPI, (RPI, WeTek ab MLD-5.3), MLD-5.4 exec(" cd $tmppath ( PATH=/usr/local/bin:\$PATH size=\$((\$(du -s iso/ | cut -f1)/1024+2)) truncate -s\$((\$size+2))M $file echo \"n\np\n1\n\n+\${size}M\n t\nb\n w\" | fdisk -u -c -C100 $file truncate -s\${size}M image.p1 mkfs.vfat -n 'MLD-$version' image.p1 uuid=\$(blkid image.p1 -o value -s UUID) test -e iso/syslinux && sed -e \"s|root=\S*|root=UUID=\$uuid|g\" -i iso/syslinux/syslinux.cfg test -e iso/efi/boot && sed -e \"s|root=\S*|root=UUID=\$uuid|g\" -i iso/efi/boot/syslinux.cfg test -e iso/cmdline && sed -e \"s|root=\S*|root=UUID=\$uuid|g\" -i iso/cmdline test -e iso/uEnv.txt && sed -e \"s|root=\S*|root=UUID=\$uuid|g\" -i iso/uEnv.txt mcopy -i image.p1 -s iso/* :: sync #test -e iso/syslinux && syslinux --directory /syslinux/ --install image.p1 test -e iso/syslinux && syslinux --zip --install image.p1 sync dd if=image.p1 of=$file bs=1024 seek=1024 conv=notrunc >/dev/null test -e iso/syslinux && dd if=iso/syslinux/mbr.bin of=$file bs=1024 conv=notrunc >/dev/null test -e iso/u-boot.bin && dd if=iso/u-boot.bin of=$file bs=1024 seek=8 conv=notrunc >/dev/null sync test $imagetype = img.gz && gzip -9 $file rm -f image.p1 ) >log/build.log 2>&1 "); } 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("/ /", "+", preg_replace("/\.{2,}/", "", $_GET['file'])); $type = preg_replace("/.*\.([^.]+)$|.*/", "\\1", $file); $type = isset ($types[$type]) ? $types[$type] : $types['other']; $name = preg_replace("/.*\/(.*)|.*/", "\\1", $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 (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], "mac")) { header("Content-Type: application/x-macbinary"); } else { header("Content-Type: application/force-download"); } if (isset($_SERVER['HTTP_USER_AGENT']) && 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"); if ($fd) { while (!feof($fd)) { echo fread($fd, 4096); flush(); } fclose($fd); } ?>