Commit | Line | Data |
---|---|---|
8a1b4b56 | 1 | <?php |
9086c806 S |
2 | $args = explode(";", $_SERVER["QUERY_STRING"]); |
3 | foreach($args as $arg) { | |
4 | $arg = explode("=", $arg, 2); | |
5 | $_GET[$arg[0]] = $arg[1]; | |
6 | } | |
7b5266f1 S |
7 | |
8 | function scandir_replace($folder,$arg){ | |
9 | $out = array(); | |
10 | if($content = opendir($folder)){ | |
11 | while(false !== ($file = readdir($content))){ | |
12 | if(is_dir("$folder/$file") && $file != "." && $file != ".." && $file != ".git"){ | |
13 | scandir_replace("$folder/$file",$arg); | |
14 | } elseif($file != "." && $file != ".." && $file != ".git"){ | |
15 | $out[] = "$folder/$file"; | |
16 | } | |
17 | } | |
18 | closedir($content); | |
19 | } | |
20 | foreach($out as $id => $v) { | |
21 | chmod($v,0777); | |
22 | $maincode=file_get_contents($v); | |
23 | $maincode = str_replace('$__GIT__', '"'.$arg.'"', $maincode); // replace $__GIT__ with the git version | |
24 | $fp = fopen($v, 'w'); | |
25 | fwrite($fp, $maincode); | |
26 | fclose($fp); | |
27 | } | |
28 | } | |
3171c56f S |
29 | function gen_id($len = 6) |
30 | { | |
31 | $r = ''; | |
32 | for($i=0; $i<$len; $i++) { | |
33 | $r .= chr(rand(0, 25) + ord('a')); | |
34 | } | |
35 | return $r; | |
36 | } | |
8a1b4b56 S |
37 | if(isset($_GET['p'])){ |
38 | if(file_exists("/home/git/".$_GET['p'])){ | |
39 | $hash = shell_exec("git --git-dir=/home/git/".$_GET["p"]." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'"); | |
40 | $con= shell_exec('git --git-dir=/home/git/'.$_GET["p"].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"'); | |
41 | if(!$hash){ | |
0c0738da | 42 | echo "No Download available"; |
8a1b4b56 S |
43 | }else{ |
44 | $name=substr($_GET["p"],0,strlen($_GET["p"])-4); | |
5500a695 | 45 | echo "<a href='http://git.nexus-irc.de/git_download.php?build=".$_GET["p"]."'>".$name."-".substr($hash, 0, -1)." (tar.gz)</a>"; |
8a1b4b56 S |
46 | } |
47 | }else{ | |
48 | echo "unknown project"; | |
49 | } | |
50 | }elseif(isset($_GET['build'])){ | |
5500a695 | 51 | |
8a1b4b56 S |
52 | if(file_exists("/home/git/".$_GET['build'])){ |
53 | $name=substr($_GET['build'],0,strlen($_GET['build'])-4); | |
5500a695 S |
54 | if(isset($_GET['h'])){ |
55 | if(strtolower($_GET['h']) == "head") { | |
56 | $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); | |
57 | }else{ | |
58 | $hash = substr($_GET['h'], 0, 7); | |
feacd354 | 59 | } |
9086c806 | 60 | }else{ |
5500a695 | 61 | $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); |
9086c806 | 62 | } |
3171c56f | 63 | $id = sha1(gen_id()); |
6649978d S |
64 | $b = shell_exec("cd /usr/share/gitweb/dl/; git clone git://git.nexus-irc.de/".$_GET['build']); |
65 | $c = shell_exec("cd /usr/share/gitweb/dl/".$name."/; git reset ".$_GET['h']); | |
66 | $con= shell_exec('git --git-dir=/home/git/'.$_GET['build'].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"'); | |
67 | if($_GET['build'] != "gitweb.git") { | |
68 | scandir_replace("/usr/share/gitweb/dl/".$name,"git-".substr($con, 0, -1)."-".$hash); | |
8a1b4b56 | 69 | } |
6649978d S |
70 | $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$id." ".$name); |
71 | $d = shell_exec("rm -r /usr/share/gitweb/dl/".$name); | |
72 | header("Content-Type: application/x-gzip"); | |
73 | header("Content-Disposition: attachment; filename=".$name."-".$hash.".tar.gz"); | |
74 | readfile("/usr/share/gitweb/dl/".$id); | |
75 | unlink("/usr/share/gitweb/dl/".$id); | |
76 | ||
8a1b4b56 S |
77 | }else{ |
78 | echo "unknown project"; | |
79 | } | |
80 | }else{ | |
5500a695 S |
81 | echo "<table class='project_list'>"; |
82 | echo "<tr><th>Project</th><th>Download</th></tr>"; | |
8a1b4b56 S |
83 | $a = file_get_contents("http://git.nexus-irc.de/index.cgi?a=project_index2"); |
84 | $b = explode("\n",$a); | |
85 | foreach($b as $id => $v) { | |
86 | if($v == ""){ }else{ | |
87 | $hash = shell_exec("git --git-dir=/home/git/".$v." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'"); | |
88 | $con= shell_exec('git --git-dir=/home/git/'.$v.' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"'); | |
89 | if(!$hash){ | |
5500a695 | 90 | echo "<tr><td>".$v."</td><td>No Download available</td></tr>"; |
8a1b4b56 S |
91 | }else{ |
92 | $name=substr($v,0,strlen($v)-4); | |
5500a695 | 93 | 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>"; |
8a1b4b56 S |
94 | } |
95 | } | |
96 | } | |
5500a695 | 97 | echo "</table>"; |
8a1b4b56 S |
98 | } |
99 | ?> |