From b4c9cf27f187dffc1a0a525a73374428a6a27ba4 Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Mon, 26 Dec 2011 12:26:59 +0000 Subject: query maintdb data by uid or pkg --- maintdb.php | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 maintdb.php diff --git a/maintdb.php b/maintdb.php new file mode 100644 index 0000000..dbdf723 --- /dev/null +++ b/maintdb.php @@ -0,0 +1,79 @@ + + * package_name user_name + * package_name2 user_name2 + * + * + * either JSON format: + * + * {"user_name": ["package_name1", "package_name2"]} + * + * + * TODO check if preg_match_all() is more efficient than exec('grep ...') + * TODO if so, check security concerns for $uid and $pkg + * + * @copyright Copyright (C) 2011 Mageia.Org + * @author Romain d'Alverny + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License aspublished by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. +*/ + +/** Path to maintdb.txt */ +$maintdb = __DIR__ . '/data/maintdb.txt'; + +/** User name */ +$uid = isset($_GET['uid']) ? trim(htmlentities(strip_tags($_GET['uid']))) : null; + +/** Package name */ +$pkg = isset($_GET['pkg']) ? trim(htmlentities(strip_tags($_GET['pkg']))) : null; + +/** Return format */ +$json = isset($_GET['json']) ? true : false; + +/** Returned data */ +$return = null; + +if (null !== $uid) { + if (preg_match_all(sprintf('/(.*) %s\n?/', $uid), $s, $res)) { + $return = array($uid => $res[1]); + } +} elseif (null !== $pkg) { + if (preg_match_all(sprintf('/%s (.*)\n?/', $pkg), $s, $res)) { + $return = array($res[1][0] => $pkg); + } +} + +if ($json) { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode($return); +} +else { + header('Content-Type: text/plain; charset: utf-8'); + if (is_array($return)) { + foreach ($return as $u => $packages) { + foreach ($packages as $p) { + echo sprintf("%s %s\n", $p, $u); + } + } + } else { + echo ""; + } +} \ No newline at end of file -- cgit v1.2.1