Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathquery.php
More file actions
284 lines (252 loc) · 10.9 KB
/
Copy pathquery.php
File metadata and controls
284 lines (252 loc) · 10.9 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
use App\Repository\PackageRepository;
$errors = [];
$warnings = [];
$order_options = [
'' => 'relevance',
'id' => 'ID',
'ts1' => 'date',
'ts2' => 'last modified',
'package_name' => 'package',
'bug_type' => 'bug_type',
'status' => 'status',
'php_version' => 'php_version',
'php_os' => 'os',
'sdesc' => 'summary',
'assign' => 'assignment',
'avg_score' => 'avg. vote score',
'votes_count' => 'number of votes',
'RAND()' => 'random',
];
// Fetch pseudo packages
$packageRepository = $container->get(PackageRepository::class);
$pseudo_pkgs = $packageRepository->findAll();
// Setup input variables..
$boolean_search = isset($_GET['boolean']) ? (int) $_GET['boolean'] : 0;
$status = !empty($_GET['status']) ? (string)$_GET['status'] : 'Open';
$search_for = !empty($_GET['search_for']) ? trim((string)$_GET['search_for']) : '';
$bug_type = (!empty($_GET['bug_type']) && $_GET['bug_type'] != 'All') ? (string)$_GET['bug_type'] : '';
$bug_age = (int) (isset($_GET['bug_age']) ? $_GET['bug_age'] : 0);
$bug_updated = (int) (isset($_GET['bug_updated']) ? $_GET['bug_updated'] : 0);
$php_os = (!empty($_GET['php_os']) && is_string($_GET['php_os'])) ? $_GET['php_os'] : '';
$php_os_not = !empty($_GET['php_os_not']) ? 'not' : '';
$phpver = (!empty($_GET['phpver']) && is_string($_GET['phpver'])) ? $_GET['phpver'] : '';
$cve_id = (!empty($_GET['cve_id']) && is_string($_GET['cve_id'])) ? $_GET['cve_id'] : '';
$cve_id_not = !empty($_GET['cve_id_not']) ? 'not' : '';
$patch = (!empty($_GET['patch']) && is_string($_GET['patch'])) ? $_GET['patch'] : '';
$pull = (!empty($_GET['pull']) && is_string($_GET['pull'])) ? $_GET['pull'] : '';
$private = (!empty($_GET['private']) && is_string($_GET['private'])) ? $_GET['private'] : '';
$begin = (int) ((!empty($_GET['begin']) && $_GET['begin'] > 0) ? $_GET['begin'] : 0);
$limit = (defined('MAX_BUGS_RETURN')) ? MAX_BUGS_RETURN : 30;
$project = (!empty($_GET['project']) && $_GET['project'] != 'All') ? $_GET['project'] : '';
if (!empty($_GET['limit'])) {
$limit = ($_GET['limit'] == 'All') ? 'All' : (($_GET['limit'] > 0) ? (int) $_GET['limit'] : $limit);
}
$direction = (!empty($_GET['direction']) && $_GET['direction'] != 'DESC') ? 'ASC' : 'DESC';
$order_by = (!empty($_GET['order_by']) && array_key_exists($_GET['order_by'], $order_options)) ? $_GET['order_by'] : '';
$reorder_by = (!empty($_GET['reorder_by']) && array_key_exists($_GET['reorder_by'], $order_options)) ? $_GET['reorder_by'] : '';
$assign = (!empty($_GET['assign']) && is_string($_GET['assign'])) ? $_GET['assign'] : '';
$author_email = !empty($_GET['author_email']) ? spam_protect($_GET['author_email'], 'reverse') : '';
$package_name = (isset($_GET['package_name']) && is_array($_GET['package_name'])) ? $_GET['package_name'] : [];
$package_nname = (isset($_GET['package_nname']) && is_array($_GET['package_nname'])) ? $_GET['package_nname'] : [];
$commented_by = !empty($_GET['commented_by']) ? spam_protect($_GET['commented_by'], 'reverse') : '';
if (isset($_GET['cmd']) && $_GET['cmd'] == 'display')
{
$query = '
SELECT SQL_CALC_FOUND_ROWS
bugdb.*,
TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) AS unchanged,
UNIX_TIMESTAMP(ts1) AS submitted,
UNIX_TIMESTAMP(ts2) AS modified
FROM bugdb
';
if (in_array($order_by, ['votes_count', 'avg_score'])) {
$query .= 'LEFT JOIN bugdb_votes v ON bugdb.id = v.bug';
}
if ($commented_by != '') {
$query .= ' LEFT JOIN bugdb_comments c ON bugdb.id = c.bug';
}
$where_clause = ' WHERE 1 = 1 ';
if (isset($user_flags) && ($user_flags & (BUGS_SECURITY_DEV | BUGS_TRUSTED_DEV))) {
if ($private != '') {
$where_clause .= ' AND bugdb.private = "Y" ';
}
} else {
/* Non trusted developer should see the Security related bug report just when it is public */
$where_clause .= ' AND (bugdb.bug_type <> "Security" OR private = "N") ';
}
if (!empty($package_name)) {
$where_clause .= ' AND bugdb.package_name';
if (count($package_name) > 1) {
$items = array_map([$dbh, 'quote'], $package_name);
$where_clause .= " IN (" . join(", ", $items) . ")";
} else {
$where_clause .= ' = ' . $dbh->quote($package_name[0]);
}
}
if (!empty($package_nname)) {
$where_clause .= ' AND bugdb.package_name';
if (count($package_nname) > 1) {
$items = array_map([$dbh, 'quote'], $package_nname);
$where_clause .= " NOT IN (" . join(", ", $items) . ")";
} else {
$where_clause .= ' <> ' . $dbh->quote($package_nname[0]);
}
}
// Ensure status is valid and tweak search clause to treat assigned, analyzed, critical and verified bugs as open
switch ($status) {
case 'All':
break;
case 'Closed':
case 'Re-Opened':
case 'Duplicate':
case 'Critical':
case 'Assigned':
case 'Analyzed':
case 'Verified':
case 'Suspended':
case 'Wont fix':
case 'No Feedback':
case 'Feedback':
case 'Not a bug':
$where_clause .= " AND bugdb.status='$status'";
break;
case 'Old Feedback':
$where_clause .= " AND bugdb.status='Feedback'
AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) > 60";
break;
case 'Fresh':
$where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Not a bug')
AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) < 30";
break;
case 'Stale':
$where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Not a bug')
AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) > 30";
break;
case 'Not Assigned':
$where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Not a bug', 'Assigned', 'Wont Fix', 'Suspended')";
break;
case 'OpenFeedback':
$where_clause .= " AND bugdb.status IN ('Open', 'Re-Opened', 'Assigned','Analyzed', 'Critical', 'Verified', 'Feedback')";
break;
default:
case 'Open':
$where_clause .= " AND bugdb.status IN ('Open', 'Re-Opened', 'Assigned', 'Analyzed', 'Critical', 'Verified')";
}
if ($search_for != '') {
list($sql_search, $ignored) = format_search_string($search_for, $boolean_search);
$where_clause .= $sql_search;
if (count($ignored) > 0 ) {
$warnings[] = 'The following words were ignored: ' . implode(', ', array_unique($ignored));
}
}
if ($bug_type != '') {
if ($bug_type == 'Bugs') {
$where_clause .= ' AND (bugdb.bug_type = "Bug" OR bugdb.bug_type="Documentation Problem")';
} else {
$where_clause .= ' AND bugdb.bug_type = ' . $dbh->quote($bug_type);
}
}
if ($bug_age > 0) {
$where_clause .= " AND bugdb.ts1 >= DATE_SUB(NOW(), INTERVAL $bug_age DAY)";
}
if ($bug_updated > 0) {
$where_clause .= " AND bugdb.ts2 >= DATE_SUB(NOW(), INTERVAL $bug_updated DAY)";
}
if ($php_os != '') {
$where_clause .= " AND bugdb.php_os {$php_os_not} LIKE " . $dbh->quote('%'.$php_os.'%');
}
if ($phpver != '') {
$where_clause .= " AND bugdb.php_version LIKE " . $dbh->quote($phpver.'%');
}
if ($project != '') {
$where_clause .= " AND EXISTS (SELECT 1 FROM bugdb_pseudo_packages b WHERE b.name = bugdb.package_name AND b.project = ". $dbh->quote($project) ." LIMIT 1)";
}
if ($cve_id != '') {
$where_clause .= " AND bugdb.cve_id {$cve_id_not} LIKE " . $dbh->quote($cve_id.'%');
}
/* A search for patch&pull should be (patch or pull) */
if ($patch != '' || $pull != '') {
$where_clause .= " AND (1=2";
}
if ($patch != '') {
$where_clause .= " OR EXISTS (SELECT 1 FROM bugdb_patchtracker WHERE bugdb_id = bugdb.id LIMIT 1)";
}
if ($pull != '') {
$where_clause .= " OR EXISTS (SELECT 1 FROM bugdb_pulls WHERE bugdb_id = bugdb.id LIMIT 1)";
}
if ($patch != '' || $pull != '') {
$where_clause .= ")";
}
if ($assign != '') {
$where_clause .= ' AND bugdb.assign = ' . $dbh->quote($assign);
}
if ($author_email != '') {
$where_clause .= ' AND bugdb.email = ' . $dbh->quote($author_email);
}
if ($commented_by != '') {
$where_clause .= ' AND c.email = ' . $dbh->quote($commented_by);
}
$where_clause .= ' AND (1=1';
if ($pseudo = array_intersect(array_keys($pseudo_pkgs), $package_name)) {
$where_clause .= " OR bugdb.package_name";
if (count($pseudo) > 1) {
$pseudo = array_map([$dbh, 'quote'], $pseudo);
$where_clause .= " IN (" . join(", ", $pseudo) . ")";
} else {
$where_clause .= " = " . $dbh->quote(reset($pseudo));
}
} else {
$items = array_map([$dbh, 'quote'], array_keys($pseudo_pkgs));
$where_clause .= " OR bugdb.package_name IN (" . join(", ", $items) . ")";
}
$query .= "$where_clause )";
if ($reorder_by != '') {
if ($order_by == $reorder_by) {
$direction = $direction == 'ASC' ? 'DESC' : 'ASC';
} else {
$direction = $reorder_by == 'ts2' ? 'DESC' : 'ASC';
$order_by = $reorder_by;
}
}
$order_by_clauses = [];
if (in_array($order_by, ['votes_count', 'avg_score'])) {
$query .= ' GROUP BY bugdb.id';
switch ($order_by) {
case 'avg_score':
$order_by_clauses = [
"IFNULL(AVG(v.score), 0)+3 $direction",
"COUNT(v.bug) DESC"
];
break;
case 'votes_count':
$order_by_clauses = ["COUNT(v.bug) $direction"];
break;
}
} elseif ($order_by != '') {
$order_by_clauses = ["$order_by $direction"];
}
if ($status == 'Feedback') {
$order_by_clauses[] = "bugdb.ts2 $direction";
}
if (count($order_by_clauses)) {
$query .= ' ORDER BY ' . implode(', ', $order_by_clauses);
}
if ($limit != 'All' && $limit > 0) {
$query .= " LIMIT $begin, $limit";
}
if (stristr($query, ';')) {
$errors[] = 'BAD HACKER!! No database cracking for you today!';
} else {
try {
$result = $dbh->prepare($query)->execute()->fetchAll();
$rows = count($result);
$total_rows = $dbh->prepare('SELECT FOUND_ROWS()')->execute()->fetch(\PDO::FETCH_NUM)[0];
} catch (Exception $e) {
$errors[] = 'Invalid query' /*. $e->getMessage() */;
}
if (defined('MAX_BUGS_RETURN') && $total_rows > $rows) {
$warnings[] = 'The search was too general, only ' . MAX_BUGS_RETURN . ' bugs will be returned';
}
}
}
You can’t perform that action at this time.
