Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/pkgapi/pkginfo.php
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-12-10 10:35:50 +0100
committerErich Eckner <git@eckner.net>2018-12-10 10:35:50 +0100
commit40e8a209189913461203722ae0c6789f887907b9 (patch)
treeb2dd97de01aa619d86acdfcd26ac57a176fd3674 /pkgapi/pkginfo.php
parentf4ca5a658696aaaec035b626653473c44f4de5d5 (diff)
pkgapi/ new
Diffstat (limited to 'pkgapi/pkginfo.php')
-rw-r--r--pkgapi/pkginfo.php53
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
+);