diff options
Diffstat (limited to 'pkgapi/pkginfo.php')
-rw-r--r-- | pkgapi/pkginfo.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/pkgapi/pkginfo.php b/pkgapi/pkginfo.php new file mode 100644 index 0000000..d9301ed --- /dev/null +++ b/pkgapi/pkginfo.php @@ -0,0 +1,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)) + 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 +); |