summaryrefslogtreecommitdiff
path: root/includes/ban.inc
blob: 98f39be6d6cd1b77007e84bda37970c0d836a5ef (plain)
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
<?php

$type2index = array("addresses" => 0x01,
                    "profanity" => 0x02,
                    "hostnames" => 0x03,
                    "usernames" => 0x04);

$index2type = array(0x01 => "addresses",
                    0x02 => "profanity",
                    0x03 => "hostnames",
                    0x04 => "usernames");

function ban_match($mask, $category) {
  // Perform query:
  $result = db_query("SELECT * FROM bans WHERE type = '$category' AND LOWER('$mask') LIKE LOWER(mask)");

  // Return result:
  return db_fetch_object($result);
}

// TODO --> $message by reference
function ban_add($mask, $category, $reason, $message = 0) {
  global $index2type;

  if (empty($mask)) {
    $message = "failed: empty banmasks are not allowed.<P>\n";
  }
  else if ($ban = db_fetch_object(db_query("SELECT * FROM bans WHERE type = '$category' AND '$mask' LIKE mask"))) {
    $message = "failed: ban is already matched by '$ban->mask'.<P>\n";
  }
  else {
    $result = db_query("INSERT INTO bans (mask, type, reason, timestamp) VALUES ('$mask', '$category', '$reason', '". time() ."')");
    $message = "added new ban with mask '$mask'.<P>\n";

    // Add log entry:
    watchdog("message", "added new ban '$mask' to category '". $index2type[$category] ."' with reason '$reason'.");
  }
}

function ban_delete($id) {
  global $index2type;

  $result = db_query("SELECT * FROM bans WHERE id = '$id'");

  if ($ban = db_fetch_object($result)) {
    // Perform query:
    $result = db_query("DELETE FROM bans WHERE id = '$id'");

    // Deleted log entry:
    watchdog("message", "removed ban '$ban->mask' from category '". $index2type[$ban->type] ."'.");
  }
}

?>