-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.php
70 lines (60 loc) · 2.37 KB
/
check.php
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
<?php
require_once './inc/page.php';
class Check {
public function run($name, $from) {
$page = new Page("check", false);
$column = "name"; // Safe user input (constants only)
// validate user input
if ($page->is_uuid($name) && preg_match($page->settings->uuid_regex_pattern, $name)) {
$column = "uuid";
$name = $page->uuid_dashify($name);
} else if (strlen($name) > 16 || !preg_match($page->settings->username_regex_pattern, $name)) {
$this->println($page->t("error.name.invalid"));
return;
} else if (preg_match('/^#(ban|kick|mute|warn)-(\d+)$/', $name, $matches)) {
$type = $matches[1];
$id = $matches[2];
}
$table = $page->settings->table['history']; // Not user input
try {
$stmt = $page->conn->prepare("SELECT name,uuid FROM $table WHERE $column=:val ORDER BY date DESC LIMIT 1");
$stmt->bindParam(':val', $name, PDO::PARAM_STR);
if ($stmt->execute()) {
if ($row = $stmt->fetch()) {
$name = $row['name'];
$uuid = $row['uuid'];
}
}
$stmt->closeCursor();
// sanitize $_POST['table'] ($from)
$info = $page->type_info($from);
//$type = $info['type'];
if (!isset($uuid)) {
if (filter_var($name, FILTER_VALIDATE_FLOAT)) {
echo "<br>";
redirect($page->link("info.php?type=$type&id=$id"));
return;
}
$name = htmlspecialchars($name, ENT_QUOTES);
$this->println(str_replace("{name}", $name, $page->t("error.name.unseen")));
return;
}
$uuid = $page->uuid_undashify($uuid);
$href = "history.php?uuid=$uuid";
if ($type !== null) {
$href .= "&from=$type";
}
echo "<br>";
redirect($page->link($href));
} catch (PDOException $ex) {
$page->db->handle_error($page->settings, $ex);
}
}
function println($line) {
echo "<br>$line<br>";
}
}
if (isset($_GET['name'], $_GET['table']) && is_string($_GET['name']) && is_string($_GET['table'])) {
$check = new Check();
$check->run($_GET['name'], $_GET['table']);
}