summaryrefslogtreecommitdiff
path: root/httpdocs/index.php
blob: 3295c386cd46d94e90137ac6d28c3464c83a1f7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

if (isset($_GET['r'])) {

  if (base64_decode($_GET['r'],true)===false)
    die('Invalid base64');

  if (!is_dir('../work/repositories/' . $_GET['r'])) {
    $wish_list = fopen('../work/wish-list','a');
    if ($wish_list === false)
      die('Cannot open wish-list');
    fwrite($wish_list, $_GET['r'] . "\n");
    fclose($wish_list);
    die('I put repository on wish-list');
  }

  if (isset($_GET['tag'])) {
    if (base64_decode($_GET['tag'],true)===false)
      $_GET['tag'] = base64_encode($_GET['tag']);

    $commit_identifier = '$(' .
        'echo "' . $_GET['tag'] . '" | ' .
          'base64 -d' .
      ')';
  } elseif (isset($_GET['commit'])) {
    if (preg_match('/^[a-f0-9]{40}$/', $_GET['commit']))
      $commit_identifier = $_GET['commit'];
  }

  if (isset($commit_identifier)) {
    $handle = popen(
      'git -C "../work/repositories/' . $_GET['r'] . '" archive "' . $commit_identifier . '" | ' .
      'gzip -nc',
      'r'
    );
    if ($handle === false)
      die('Unable to create archive');
    header('Content-type: application/x-gzip');
    header('Content-Disposition: attachment; filename="archive.tar.gz"');
    fpassthru($handle);
    pclose($handle);
    die();
  }

  die('errrm, this is not yet implemented');

}