Skip to content

Commit f481991

Browse files
authored
Merge pull request #8 from ssl/master
Fixes
2 parents 6efb365 + c1a46a6 commit f481991

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

app/controllers/Api.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ private function parseCookies($cookies)
277277
public function reports()
278278
{
279279
$id = $this->getPostValue('id');
280+
$archive = $this->getPostValue('archive') == '1' ? 1 : 0;
280281

281282
// Check payload permissions
282283
$payloadList = $this->payloadList();
@@ -288,7 +289,7 @@ public function reports()
288289
if (+$id === 0) {
289290
if ($this->isAdmin()) {
290291
// Show all reports
291-
$reports = $this->model('Report')->getAll();
292+
$reports = $this->model('Report')->getAllByArchive($archive);
292293
} else {
293294
// Show all reports of allowed payloads
294295
$reports = [];
@@ -299,7 +300,7 @@ public function reports()
299300
if (strpos($payload['payload'], '/') === false) {
300301
$payloadUri .= '/%';
301302
}
302-
$reports = array_merge($reports, $this->model('Report')->getAllByPayload($payloadUri));
303+
$reports = array_merge($reports, $this->model('Report')->getAllByPayload($payloadUri, $archive));
303304
}
304305
}
305306
}
@@ -311,20 +312,7 @@ public function reports()
311312
if (strpos($payload['payload'], '/') === false) {
312313
$payloadUri .= '/%';
313314
}
314-
$reports = $this->model('Report')->getAllByPayload($payloadUri);
315-
}
316-
317-
// Remove or keep reports depending the requested archive value
318-
$archive = $this->getPostValue('archive') == '1' ? true : false;
319-
foreach ($reports as $key => $value) {
320-
$reports[$key]['ip'] = substr($reports[$key]['ip'], 0, 25);
321-
$reports[$key]['payload'] = substr($reports[$key]['payload'], 0, 50);
322-
323-
if (($reports[$key]['archive'] == '0' && $archive) ||
324-
($reports[$key]['archive'] == '1' && !$archive)
325-
) {
326-
unset($reports[$key]);
327-
}
315+
$reports = $this->model('Report')->getAllByPayload($payloadUri, $archive);
328316
}
329317

330318
return json_encode(["data" => array_values($reports)]);

app/controllers/Payload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ private function setBlacklist($id, $domain)
251251
$payload = $this->model('Payload')->getById($id);
252252

253253
// Validate domain string
254-
if (!preg_match('/^(?!\-)(?:(?:[a-zA-Z\d][a-zA-Z\d\-]{0,61})?[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', $domain)) {
254+
if (!preg_match('/^(?:(?:(?!\*)[a-zA-Z\d][a-zA-Z\d\-*]{0,61})?[a-zA-Z\d]\.){0,1}(?!\d+)(?!.*\*\*)[a-zA-Z\d*]{1,63}(?:\.(?:(?:(?!\*)[a-zA-Z\d][a-zA-Z\d\-*]{0,61})?[a-zA-Z\d]\.){0,1}(?!\d+)(?!.*\*\*)[a-zA-Z\d*]{1,63})*$/', $domain)) {
255255
throw new Exception('This does not look like a valid domain');
256-
}
256+
}
257257

258258
$newString = $payload['blacklist'] . '~' . $domain;
259259
$this->model('Payload')->setSingleValue($id, "blacklist", $newString);

app/models/Report.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ public function getAll()
2525
return $data;
2626
}
2727

28+
/**
29+
* Get all reports by archive status
30+
*
31+
* @param string $archive Archive status
32+
* @return array
33+
*/
34+
public function getAllByArchive($archive)
35+
{
36+
$database = Database::openConnection();
37+
$database->prepare('SELECT id,uri,ip,payload,shareid FROM reports WHERE archive = :archive ORDER BY id DESC');
38+
$database->bindValue(':archive', $archive);
39+
$database->execute();
40+
41+
$data = $database->fetchAll();
42+
43+
return $data;
44+
}
45+
2846
/**
2947
* Get report by share id
3048
*
@@ -51,13 +69,15 @@ public function getByShareId($id)
5169
/**
5270
* Get report by payload
5371
* @param string $payload The payload
72+
* @param string $archive Archive status
5473
* @throws Exception
5574
* @return array
5675
*/
57-
public function getAllByPayload($payload)
76+
public function getAllByPayload($payload, $archive)
5877
{
5978
$database = Database::openConnection();
60-
$database->prepare('SELECT id,uri,ip,payload,archive,shareid FROM reports WHERE payload LIKE :payload ORDER BY id DESC');
79+
$database->prepare('SELECT id,uri,ip,payload,shareid FROM reports WHERE payload LIKE :payload AND archive = :archive ORDER BY id DESC');
80+
$database->bindValue(':archive', $archive);
6181
$database->bindValue(':payload', $payload);
6282

6383
if (!$database->execute()) {

system/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,6 @@ public function setTitle($title)
459459
*/
460460
public function setContentType($type)
461461
{
462-
header('Content-Type: ' . $type);
462+
header('Content-Type: ' . $type . '; charset=UTF-8');
463463
}
464464
}

0 commit comments

Comments
 (0)