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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<?php
/**
* Mageia maintdb quick filter.
* Make use of http://pkgsubmit.mageia.org/data/maintdb.txt data.
*
* This only supports mapping 1 user to several packages
* or 1 package to 1 user.
*
* @param string $uid (GET param) user id
* @param string $pkg (GET param) package name
* @param mixed $txt (GET param) whether to return result in text or JSON (default)
* @param string $iurt (GET param) return a iurt-specific response format: only the username
*
* @return string
*
* Returned format is JSON format as a default:
* <code>
* {"user_name": {"packages" => ["package_name1", "package_name2"]}}
* </code>
*
* either text format (use ?txt in query string)
* <code>
* package_name user_name
* package_name2 user_name2
* </code>
*
* either specific, iurt format (use ?pkg=...&iurt in query string)
* <code>
* user_name
* </code>
*
*
* 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;
/** Return format */
$txt = isset($_GET['txt']) ? true : false;
$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;
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[$pkg]))
echo $return[$pkg]['uid'], "\n";
else
echo '';
}
elseif ($txt) {
header('Content-Type: text/plain; charset: utf-8');
if (is_array($return)) {
if (null !== $uid) {
foreach ($return as $u => $data) {
foreach ($data['packages'] as $p) {
echo sprintf("%s %s\n", $p, $u);
}
}
} else {
echo sprintf('%s %s', $pkg, $return[$pkg]['uid']);
}
} else {
echo $return;
}
}
else {
header('Content-Type: application/json; charset=utf-8');
echo json_encode($return);
}
|