remove bugtrack functions
[gitweb.git] / git_download.php
index 64f16ae613fc4de6c2d9cc79a877d95c8818c46d..fc729861e51c52dc9ea603c7ffd26a3f28ee68b7 100644 (file)
@@ -1,4 +1,39 @@
 <?php
+$args = explode(";", $_SERVER["QUERY_STRING"]);
+foreach($args as $arg) {
+    $arg = explode("=", $arg, 2);
+    $_GET[$arg[0]] = $arg[1];
+}
+
+function scandir_replace($folder,$arg){
+       $out = array();
+       if($content = opendir($folder)){
+               while(false !== ($file = readdir($content))){
+                       if(is_dir("$folder/$file") && $file != "." && $file != ".." && $file != ".git"){
+                               scandir_replace("$folder/$file",$arg);
+                       } elseif($file != "." && $file != ".." && $file != ".git"){
+                               $out[] = "$folder/$file";      
+                       }
+               }
+               closedir($content);
+       }
+       foreach($out as $id => $v) {
+               chmod($v,0777);
+               $maincode=file_get_contents($v);
+               $maincode = str_replace('$__GIT__', '"'.$arg.'"', $maincode); // replace $__GIT__ with the git version
+               $fp = fopen($v, 'w');
+               fwrite($fp, $maincode);
+               fclose($fp);
+       }
+}
+function gen_id($len = 6)
+{
+    $r = '';
+    for($i=0; $i<$len; $i++) {
+        $r .= chr(rand(0, 25) + ord('a'));
+       }
+    return $r;
+}
 if(isset($_GET['p'])){
        if(file_exists("/home/git/".$_GET['p'])){
                $hash = shell_exec("git --git-dir=/home/git/".$_GET["p"]." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
@@ -7,81 +42,44 @@ if(isset($_GET['p'])){
                        echo "No Download available";
                }else{
                        $name=substr($_GET["p"],0,strlen($_GET["p"])-4);  
-                       if(file_exists("/usr/share/gitweb/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz")) {
-                               echo "<a href='http://git.nexus-irc.de/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz'>git-".substr($con, 0, -1)."-".substr($hash, 0, -1)." (tar.gz)</a>";
-                       } else {
-                               echo "No Download available (<a href='http://git.nexus-irc.de/git_download.php?build2=".$_GET["p"]."'>Build snapshot</a>)";
-                       }
-               }
-       }else{
-               echo "unknown project";
-       }
-}elseif(isset($_GET['git'])){
-       if(file_exists("/home/git/".$_GET['git'])){
-               $hash = shell_exec("git --git-dir=/home/git/".$_GET["git"]." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
-               $con= shell_exec('git --git-dir=/home/git/'.$_GET["git"].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
-               if(!$hash){
-                       echo "<p>".$_GET["git"].": No Download available</p>";
-               }else{
-                       $name=substr($_GET["git"],0,strlen($_GET["git"])-4);  
-                       if(file_exists("/usr/share/gitweb/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz")) {
-                               echo "<p><a href='http://git.nexus-irc.de/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz'>git-".substr($con, 0, -1)."-".substr($hash, 0, -1)." (tar.gz)</a></p>";
-                       } else {
-                               echo "<p>No Download available (<a href='http://git.nexus-irc.de/git_download.php?build3=".$_GET["git"]."'>Build snapshot</a>)</p>";
-                       }
+                       echo "<a href='http://git.nexus-irc.de/git_download.php?build=".$_GET["p"]."'>".$name."-".substr($hash, 0, -1)." (tar.gz)</a>";
                }
        }else{
                echo "unknown project";
        }
 }elseif(isset($_GET['build'])){
+       
        if(file_exists("/home/git/".$_GET['build'])){
                $name=substr($_GET['build'],0,strlen($_GET['build'])-4);
-               if(file_exists("/usr/share/gitweb/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz")) {
-                       echo '<meta http-equiv="refresh" content="0; URL=http://git.nexus-irc.de/?a=downloads"> ';
+               if(isset($_GET['h'])){
+                       if(strtolower($_GET['h']) == "head") {
+                               $hash = substr(shell_exec("git --git-dir=/home/git/".$_GET['build']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'"), 0, -1);
+                       }else{
+                               $hash = substr($_GET['h'], 0, 7);
+                       }
                }else{
-                       $hash = shell_exec("git --git-dir=/home/git/".$_GET['build']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
-                       $con= shell_exec('git --git-dir=/home/git/'.$_GET['build'].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
-                       $b = shell_exec("cd /usr/share/gitweb/dl; git clone git://git.nexus-irc.de/".$_GET['build']);
-                       $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz ".$name);
-                       $d = shell_exec("rm -r /usr/share/gitweb/dl/".$name);
-                       echo '<meta http-equiv="refresh" content="0; URL=http://git.nexus-irc.de/?a=downloads"> ';
+                       $hash = substr(shell_exec("git --git-dir=/home/git/".$_GET['build']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'"), 0, 7);
                }
-       }else{
-               echo "unknown project";
-       }
-}elseif(isset($_GET['build2'])){
-       if(file_exists("/home/git/".$_GET['build2'])){
-               $name=substr($_GET['build2'],0,strlen($_GET['build2'])-4);
-               if(file_exists("/usr/share/gitweb/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz")) {
-                       echo '<meta http-equiv="refresh" content="0; URL=http://git.nexus-irc.de/?p='.$_GET['build2'].';a=summary"> ';
-               }else{
-               $hash = shell_exec("git --git-dir=/home/git/".$_GET['build2']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
-               $con= shell_exec('git --git-dir=/home/git/'.$_GET['build2'].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
-               $b = shell_exec("cd /usr/share/gitweb/dl/; git clone git://git.nexus-irc.de/".$_GET['build2']);
-               $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz ".$name);
-               $d = shell_exec("rm -r /usr/share/gitweb/dl/".$name);
-               echo '<meta http-equiv="refresh" content="0; URL=http://git.nexus-irc.de/?p='.$_GET['build2'].';a=summary"> ';
+               $id = sha1(gen_id());
+               $b = shell_exec("cd /usr/share/gitweb/dl/; git clone git://git.nexus-irc.de/".$_GET['build']);
+               $c = shell_exec("cd /usr/share/gitweb/dl/".$name."/; git reset ".$_GET['h']);
+               $con= shell_exec('git --git-dir=/home/git/'.$_GET['build'].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
+               if($_GET['build'] != "gitweb.git") {
+                       scandir_replace("/usr/share/gitweb/dl/".$name,"git-".substr($con, 0, -1)."-".$hash);
                }
-       }else{
-               echo "unknown project";
-       }
-}elseif(isset($_GET['build3'])){
-       if(file_exists("/home/git/".$_GET['build3'])){
-               $name=substr($_GET['build3'],0,strlen($_GET['build3'])-4);
-               if(file_exists("/usr/share/gitweb/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz")) {
-                       echo '<meta http-equiv="refresh" content="0; URL=http://stats.nexus-irc.de/"> ';
-               }else{
-               $hash = shell_exec("git --git-dir=/home/git/".$_GET['build3']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
-               $con= shell_exec('git --git-dir=/home/git/'.$_GET['build3'].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
-               $b = shell_exec("cd /usr/share/gitweb/dl/; git clone git://git.nexus-irc.de/".$_GET['build3']);
-               $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz ".$name);
+               $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$id." ".$name);
                $d = shell_exec("rm -r /usr/share/gitweb/dl/".$name);
-               echo '<meta http-equiv="refresh" content="0; URL=http://stats.nexus-irc.de/"> ';
-               }
+               header("Content-Type: application/x-gzip");
+               header("Content-Disposition: attachment; filename=".$name."-".$hash.".tar.gz");
+               $file = readfile("/usr/share/gitweb/dl/".$id);
+               unlink("/usr/share/gitweb/dl/".$id);
+               echo $file;
        }else{
                echo "unknown project";
        }
 }else{
+       echo "<table class='project_list'>";
+       echo "<tr><th>Project</th><th>Download</th></tr>";
        $a = file_get_contents("http://git.nexus-irc.de/index.cgi?a=project_index2");
        $b = explode("\n",$a);
        foreach($b as $id => $v) {
@@ -89,16 +87,13 @@ if(isset($_GET['p'])){
                        $hash = shell_exec("git --git-dir=/home/git/".$v." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
                        $con= shell_exec('git --git-dir=/home/git/'.$v.' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
                        if(!$hash){
-                               echo "<p>".$v.": No Download available</p>";
+                               echo "<tr><td>".$v."</td><td>No Download available</td></tr>";
                        }else{
                                $name=substr($v,0,strlen($v)-4);
-                               if(file_exists("/usr/share/gitweb/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz")) {
-                                       echo "<p>".$v.": Download <a href='http://git.nexus-irc.de/dl/".$name."-git-".substr($con, 0, -1)."-".substr($hash, 0, -1).".tar.gz'>git-".substr($con, 0, -1)."-".substr($hash, 0, -1)."</a></p>";
-                               } else {
-                                       echo "<p>".$v.": No Download available (<a href='http://git.nexus-irc.de/git_download.php?build=".$v."'>Build snapshot</a>)</p>";       
-                               }
+                               echo "<tr><td>".$v."</td><td><a href='http://git.nexus-irc.de/git_download.php?build=".$v."'>".$name."-".substr($hash, 0, -1)." (tar.gz)</a></td></tr>";
                        }
                }
        }
+       echo "</table>";
 }
 ?>
\ No newline at end of file