Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/pkgapi/pkginfo.php
blob: 083481a858f901fcf33ff1067763bebbd129bd00 (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
49
50
51
52
53
<?php
require_once "../init.php";

include BASE . "/lib/http.php";

foreach (array('arch', 'repo', 'pkgname') as $must_have_key) {
  if (!array_key_exists($must_have_key, $_GET))
    throw_http_error(400, 'Malformed request', 'Key ' . $must_have_key . ' was not given.');
  if (!preg_match('/^[-+_.a-zA-Z0-9]+$/', $_GET[$must_have_key]))
    throw_http_error(400, 'Malformed request', 'Value for ' . $must_have_key . ' is invalid.');
}

if (($_GET['arch'] != 'i486') && ($_GET['arch'] != 'i686'))
  throw_http_error(400, 'Malformed request', 'Architecture ' . $_GET['arch'] . ' is unkown.');

$infos = trim(
  shell_exec(
    'pacinfo' .
      ' --config=' . BASE . '/pkgapi/pacman-' . $_GET['arch'] . '.conf ' . 
      $_GET['repo'] . '/' .
      $_GET['pkgname'] .
      ' | grep "^Build Date:"; ' .
    'pacinfo' .
      ' --raw' .
      ' --config=' . BASE . '/pkgapi/pacman-' . $_GET['arch'] . '.conf ' . 
      $_GET['repo'] . '/' .
      $_GET['pkgname'] .
      ' | grep -v "^Build Date:"'
  )
);

if (!isset($infos) || empty($infos))
  throw_http_error(404, 'Package not found.');

function parse_pacinfo_line($line) {
  return preg_split('/: +/', $line, 2);
}

function extract_first($array) {
  return $array[0];
}

$infos = explode("\n", $infos);
$infos = array_map('parse_pacinfo_line', $infos);
$merged_infos = array();
foreach ($infos as $info)
  $merged_infos = array_merge_recursive($merged_infos, array($info[0] => $info[1]));

header ("Content-type: application/json");
print json_encode(
  $merged_infos,
  JSON_UNESCAPED_SLASHES
);