Subversion Repositories SvarDOS

Rev

Rev 213 | Rev 323 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 213 Rev 216
Line 8... Line 8...
8
  ?a=pull&p=PACKAGE           downloads the zip archive containing PACKAGE
8
  ?a=pull&p=PACKAGE           downloads the zip archive containing PACKAGE
9
  ?a=search&p=PHRASE          list packages that match PHRASE
9
  ?a=search&p=PHRASE          list packages that match PHRASE
10
  ?a=checkup&p=PACKAGE&v=ver  check if package available in version > v
10
  ?a=checkup&p=PACKAGE&v=ver  check if package available in version > v
11
*/
11
*/
12
 
12
 
-
 
13
 
-
 
14
function nicesize($bytes) {
-
 
15
  if ($bytes < 1024) return(round($bytes / 1024, 1) . "K");
-
 
16
  if ($bytes < 1024 * 1024) return(round($bytes / 1024) . "K");
-
 
17
  return(round($bytes / 1024 / 1024, 1) . "M");
-
 
18
}
-
 
19
 
-
 
20
 
13
if (empty($_GET['a']) {
21
if (empty($_GET['a'])) {
14
  http_response_code(404);
22
  http_response_code(404);
-
 
23
  echo "ERROR: no action specified\r\n";
15
  exit 0;
24
  exit(0);
16
}
25
}
17
 
26
 
18
$a = $_GET['a'];
27
if (empty($_GET['p'])) {
-
 
28
  http_response_code(404);
-
 
29
  echo "ERROR: no package specified\r\n";
19
$p = '';
30
  exit(0);
-
 
31
}
-
 
32
 
-
 
33
$a = strtolower($_GET['a']);
20
$v = '';
34
$p = strtolower($_GET['p']);
21
 
35
 
22
if (!empty($_GET['p'])) $p = $_GET['p'];
36
$v = '';
23
if (!empty($_GET['v'])) $v = $_GET['v'];
37
if (!empty($_GET['v'])) $v = $_GET['v'];
24
 
38
 
-
 
39
// pull action is easy (does not require looking into pkg list), do it now
-
 
40
 
-
 
41
if ($a === 'pull') {
-
 
42
  if (file_exists($p . '.zip')) {
-
 
43
    readfile($p . '.zip');
-
 
44
  } else {
-
 
45
    http_response_code(404);
-
 
46
    echo "ERROR: package not found on server\r\n";
-
 
47
  }
-
 
48
  exit(0);
-
 
49
}
-
 
50
 
-
 
51
// is action valid?
-
 
52
 
-
 
53
if (($a !== 'search') && ($a !== 'checkup')) {
-
 
54
  http_response_code(404);
-
 
55
  echo "ERROR: invalid action\r\n";
-
 
56
  exit(0);
-
 
57
}
-
 
58
 
-
 
59
// iterate over packages now
-
 
60
 
-
 
61
$handle = fopen("index.tsv", "rb");
-
 
62
if ($handle === FALSE) {
-
 
63
  http_response_code(404);
25
echo "I received a='{$a}' p='{$p}' v='{$v}'\n";
64
  echo "ERROR: Server-side internal error\r\n";
-
 
65
  exit(0);
-
 
66
}
-
 
67
 
-
 
68
if ($a === 'search') {
-
 
69
  $matches = 0;
-
 
70
  while (($pkg = fgetcsv($handle, 1024, "\t")) !== FALSE) {
-
 
71
    if ((stristr($pkg[0], $p)) || (stristr($pkg[2], $p))) {
-
 
72
      echo str_pad(strtoupper($pkg[0]), 12) . str_pad("ver: {$pkg[1]}", 13) . str_pad("size: " . nicesize(filesize($pkg[0] . '.zip')), 13) . "BSUM: {$pkg[3]}\r\n";
-
 
73
      echo wordwrap($pkg[2], 79, "\r\n", true);
-
 
74
      echo "\r\n\r\n";
-
 
75
      $matches++;
-
 
76
    }
-
 
77
  }
-
 
78
  if ($matches == 0) echo "No matching package found.\r\n";
-
 
79
}
-
 
80
 
-
 
81
if ($a === 'checkup') {
-
 
82
  while (($pkg = fgetcsv($handle, 1024, "\t")) !== FALSE) {
-
 
83
    if (strcasecmp($pkg[0], $p)) {
-
 
84
      echo "found package {$pkg[0]} ver {$pkg[1]} -> is it newer than '{$v}' ?\r\n";
-
 
85
      break;
-
 
86
    }
-
 
87
  }
-
 
88
}
-
 
89
fclose($handle);
-
 
90
 
26
 
91
 
27
?>
92
?>