C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\nucleus\nucleus\libs\BAN.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/*
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
  * Copyright (C) 2002-2005 The Nucleus Group
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
  * (see nucleus/documentation/index.html#license for more info)
 */
/**
  * PHP class responsible for ban-management. 
  *
 * @license http://nucleuscms.org/license.txt GNU General Public License
 * @copyright Copyright (C) 2002-2005 The Nucleus Group
 * @version $Id: BAN.php,v 1.9.2.1 2005/08/15 10:50:12 dekarma Exp $
  */
  
class BAN {
    
    
/**
      * Checks if a given IP is banned from commenting/voting
      *
      * Returns 0 when not banned, or a BANINFO object containing the
      * message and other information of the ban
      */
    
function isBanned($blogid$ip) {
        
$blogid intval($blogid);
        
$query 'SELECT * FROM '.sql_table('ban').' WHERE blogid='.$blogid;
        
$res sql_query($query);
        while (
$obj mysql_fetch_object($res)) {
            
$found strpos ($ip$obj->iprange);
            if (!(
$found === false)) 
                
// found a match!
                    
return new BANINFO($obj->iprange$obj->reason);
        }
        return 
0;
    }
    
    
/**
      * Adds a new ban to the banlist. Returns 1 on success, 0 on error
      */
    
function addBan($blogid$iprange$reason) {
        global 
$manager;
        
        
$blogid intval($blogid);
    
        
$manager->notify(
            
'PreAddBan',
            array(
                
'blogid' => $blogid,
                
'iprange' => &$iprange,
                
'reason' => &$reason
            
)
        );
    
        
$query 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES "
               
"($blogid,'".addslashes($iprange)."','".addslashes($reason)."')";
        
$res sql_query($query);
        
        
$manager->notify(
            
'PostAddBan',
            array(
                
'blogid' => $blogid,
                
'iprange' => $iprange,
                
'reason' => $reason
            
)
        );
        
        return 
$res 0;
    }
    
    
/**
      * Removes a ban from the banlist (correct iprange is needed as argument)
      * Returns 1 on success, 0 on error
      */
    
function removeBan($blogid$iprange) {
        global 
$manager;
        
$blogid intval($blogid);
        
        
$manager->notify('PreDeleteBan', array('blogid' => $blogid'range' => $iprange));
        
        
$query 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .addslashes($iprange). "'";
        
sql_query($query);
        
        
$result = (mysql_affected_rows() > 0);
        
        
$manager->notify('PostDeleteBan', array('blogid' => $blogid'range' => $iprange));
        
        return 
$result;
    }
}

class 
BANINFO {
    var 
$iprange;
    var 
$message;
    
    function 
BANINFO($iprange$message) {
        
$this->iprange $iprange;
        
$this->message $message;
    }
}


?>