3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
12 * PHP class responsible for ban-management.
18 * Checks if a given IP is banned from commenting/voting
20 * Returns 0 when not banned, or a BANINFO object containing the
21 * message and other information of the ban
23 function isBanned($blogid, $ip) {
24 $blogid = intval($blogid);
25 $query = 'SELECT * FROM '.sql_table('ban').' WHERE blogid='.$blogid;
26 $res = sql_query($query);
27 while ($obj = sql_fetch_object($res)) {
28 $found = strpos ($ip, $obj->iprange);
29 if (!($found === false))
31 return new BANINFO($obj->iprange, $obj->reason);
37 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
39 function addBan($blogid, $iprange, $reason) {
42 $blogid = intval($blogid);
46 'iprange' => &$iprange,
49 $manager->notify('PreAddBan', $param);
51 $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES "
52 . "($blogid,'".sql_real_escape_string($iprange)."','".sql_real_escape_string($reason)."')";
53 $res = sql_query($query);
57 'iprange' => $iprange,
60 $manager->notify('PostAddBan', $param);
66 * Removes a ban from the banlist (correct iprange is needed as argument)
67 * Returns 1 on success, 0 on error
69 function removeBan($blogid, $iprange) {
71 $blogid = intval($blogid);
77 $manager->notify('PreDeleteBan', $param);
79 $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .sql_real_escape_string($iprange). "'";
82 $result = (sql_affected_rows() > 0);
88 $manager->notify('PostDeleteBan', $param);
98 function BANINFO($iprange, $message) {
99 $this->iprange = $iprange;
100 $this->message = $message;