3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2009 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
13 * PHP class responsible for ban-management.
\r
15 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
16 * @copyright Copyright (C) 2002-2009 The Nucleus Group
\r
17 * @version $Id: BAN.php 1525 2011-06-21 10:20:19Z sakamocchi $
\r
23 * Checks if a given IP is banned from commenting/voting
\r
25 * Returns 0 when not banned, or a BANINFO object containing the
\r
26 * message and other information of the ban
\r
28 function isBanned($blogid, $ip) {
\r
29 $blogid = intval($blogid);
\r
30 $query = 'SELECT * FROM '.sql_table('ban').' WHERE blogid='.$blogid;
\r
31 $res = sql_query($query);
\r
32 while ($obj = sql_fetch_object($res)) {
\r
33 $found = i18n::strpos ($ip, $obj->iprange);
\r
34 if (!($found === false))
\r
36 return new BANINFO($obj->iprange, $obj->reason);
\r
43 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
\r
45 * @param Integer $blogid ID for weblog
\r
46 * @param String $iprange IP range
\r
47 * @param String $reason reason for banning
\r
51 function addBan($blogid, $iprange, $reason)
\r
55 $blogid = intval($blogid);
\r
60 'blogid' => $blogid,
\r
61 'iprange' => &$iprange,
\r
62 'reason' => &$reason
\r
66 $query = "INSERT INTO %s (blogid, iprange, reason) VALUES (%d, '%s', '%s')";
\r
67 $query = sprintf($query, sql_table('ban'), $blogid, sql_real_escape_string($iprange), sql_real_escape_string($reason));
\r
68 $res = sql_query($query);
\r
73 'blogid' => $blogid,
\r
74 'iprange' => $iprange,
\r
78 return $res ? 1 : 0;
\r
82 * Removes a ban from the banlist (correct iprange is needed as argument)
\r
83 * Returns 1 on success, 0 on error
\r
85 function removeBan($blogid, $iprange) {
\r
87 $blogid = intval($blogid);
\r
89 $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
\r
91 $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .sql_real_escape_string($iprange). "'";
\r
94 $result = (sql_affected_rows() > 0);
\r
96 $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
\r
106 function BANINFO($iprange, $message) {
\r
107 $this->iprange = $iprange;
\r
108 $this->message = $message;
\r