ChangeSet ID: 30234 CVSROOT: /opt/cvs-commit Module name: tools Changes by: jnewman@winehq.org 2006/12/01 10:34:15
Added files: . : download.inc.php
Log message: Jonathan Ernst jonathan@ernstfamily.ch - refactor Wine downloader scripts
Patch: http://cvs.winehq.org/patch.py?id=30234
Old revision New revision Changes Path Added 1.1 +0 -0 tools/download.inc.php
Index: tools/download.inc.php diff -u -p /dev/null tools/download.inc.php:1.1 --- /dev/null 1 Dec 2006 16:34:15 -0000 +++ tools/download.inc.php 1 Dec 2006 16:34:15 -0000 @@ -0,0 +1,76 @@ +<?php +/** + * Common code for Wine downloader scripts. + * + * Copyright (c) 2006 Jonathan Ernst + */ + +// List of common locations for files +$aList += array("http://switch.dl.sourceforge.net/sourceforge/wine/", + "http://surfnet.dl.sourceforge.net/sourceforge/wine/", + "http://citkit.dl.sourceforge.net/sourceforge/wine/", + "http://keihanna.dl.sourceforge.net/sourceforge/wine/", + "http://heanet.dl.sourceforge.net/sourceforge/wine/", + "http://easynews.dl.sourceforge.net/sourceforge/wine/", + "http://ovh.dl.sourceforge.net/sourceforge/wine/", + "http://jaist.dl.sourceforge.net/sourceforge/wine/", + "http://puzzle.dl.sourceforge.net/sourceforge/wine/", + "http://nchc.dl.sourceforge.net/sourceforge/wine/", + "http://switch.dl.sourceforge.net/sourceforge/wine/", + "http://kent.dl.sourceforge.net/sourceforge/wine/", + "http://optusnet.dl.sourceforge.net/sourceforge/wine/", + "http://mesh.dl.sourceforge.net/sourceforge/wine/", + "http://internap.dl.sourceforge.net/sourceforge/wine/", + "http://superb-east.dl.sourceforge.net/sourceforge/wine/", + "http://optusnet.dl.sourceforge.net/sourceforge/wine/", + "http://superb-west.dl.sourceforge.net/sourceforge/wine/", + "http://nchc.dl.sourceforge.net/sourceforge/wine/", + "http://umn.dl.sourceforge.net/sourceforge/wine/", + "http://belnet.dl.sourceforge.net/sourceforge/wine/", + "http://ufpr.dl.sourceforge.net/sourceforge/wine/" + ); + + +function is_downloadable($sUrl){ + global $iFileSize; + $parse = parse_url($sUrl); + // open a socket connection + if($fp = @fsockopen($parse['host'], 80, $errno, $errstr, 10)){ + // set request + $get = "HEAD ".$parse['path']." HTTP/1.1\r\n". + "Host: ".$parse['host']."\r\n". + "Connection: close\r\n\r\n"; + fputs($fp, $get); + while(!feof($fp)){ + // get ONLY header informations + $header .= fgets($fp, 128); + } + fclose($fp); + // match file size + preg_match('/Content-Length:\s([0-9].+?)\s/', $header, $matches); + $iSize = intval($matches[1]); + if($iSize == $iFileSize) return TRUE; + } + return FALSE; +} + + +if($_REQUEST['action']=="showlist") { + echo "<h2>List of mirrors available for file ".$sFileName." (".$iFileSize." bytes)</h2>"; + foreach($aList as $sLocation) { + echo $sLocation.": "; + if(is_downloadable($sLocation.$sFileName)) { + echo "<font color=\"green\">online</font>"; + } else { + echo "<font color=\"red\">offline</font>"; + } + echo "\n<br />"; + } +} else { + while(!is_downloadable($sUrl)) { + $iRand = rand(0, (sizeof($aList)-1)); + $sUrl = $aList[$iRand].$sFileName; + } + header("Location: ".$sUrl); +} +?>