IP searching in postgres, hackishly (compare text(address) to username, rather than comparing address to inet(username))

This commit is contained in:
Shish 2012-03-08 01:30:08 +00:00
parent f1eaa4f751
commit 34a7a558b3

View File

@ -60,16 +60,20 @@ class LogDatabase extends Extension {
if(!empty($_GET["user"])) { if(!empty($_GET["user"])) {
if($database->engine->name == "pgsql") { if($database->engine->name == "pgsql") {
if(preg_match("#\d+\.\d+\.\d+\.\d+(/\d+)?#", $_GET["user"])) { if(preg_match("#\d+\.\d+\.\d+\.\d+(/\d+)?#", $_GET["user"])) {
$wheres[] = "(username = :user OR address << :user)"; $wheres[] = "(username = :user1 OR text(address) = :user2)";
$args["user1"] = $_GET["user"];
$args["user2"] = $_GET["user"] . "/32";
} }
else { else {
$wheres[] = "lower(username) = lower(:user)"; $wheres[] = "lower(username) = lower(:user)";
$args["user"] = $_GET["user"];
} }
} }
else { else {
$wheres[] = "(username = :user OR address = :user)"; $wheres[] = "(username = :user1 OR address = :user2)";
$args["user1"] = $_GET["user"];
$args["user2"] = $_GET["user"];
} }
$args["user"] = $_GET["user"];
} }
if(!empty($_GET["priority"])) { if(!empty($_GET["priority"])) {
$wheres[] = "priority >= :priority"; $wheres[] = "priority >= :priority";