* {"maintainers": {"username": => {"packages" => ["package_name1", "package_name2"]}}} * * or * * {"packages": {"package_name": {"maintainers" => ["user1", "user2"]}}} * * * either specific, iurt format (use ?pkg=...&iurt in query string) * * user_name * * * * 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 = realpath(__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; $iurt = isset($_GET['iurt']) ? true : false; /** Returned data */ $return = array(); $s = file_get_contents($maintdb); if (null !== $uid) { $pkg = null; if (preg_match_all(sprintf('/(.*) %s\n?/', $uid), $s, $res)) { $return = array( 'maintainers' => array( $uid => array( 'packages' => $res[1] ) ) ); } } elseif (null !== $pkg) { $uid = null; // just in case, only keep the package name // x11-driver-video-ati-6.14.1-4.mga1.src.rpm => x11-driver-video-ati $ptemp = explode('-', $pkg); $pkg = array(); foreach ($ptemp as $pi) { if (is_numeric($pi[0])) break; $pkg[] = $pi; } $pkg = implode('-', $pkg); if (preg_match_all(sprintf('/%s (.*)\n?/', $pkg), $s, $res)) { $return = array( 'packages' => array( $pkg => array( 'maintainers' => array($res[1][0]) ) ) ); } } if ($iurt && $pkg) { header('Content-Type: text/plain; charset: utf-8'); if (isset($return['packages'])) echo $return['packages'][$pkg]['maintainers'][0], "\n"; else echo "\n"; } else { header('Content-Type: application/json; charset=utf-8'); echo json_encode($return); }