Add Fletcher Penney plugins to general.
[matthijs/upstream/blosxom-plugins.git] / general / blacklist
1 # Blosxom Plugin: blacklist
2 # Author: Fletcher T. Penney (http://fletcher.freeshell.org)
3 # Version: 0.1
4
5 package blacklist;
6  
7
8 # --- Configurable variables ---
9
10 # Where is the blacklist file?
11 $blacklist_file = "$blosxom::plugin_state_dir/blacklist";
12
13 # Where is the whitelist file?
14 $whitelist_file = "$blosxom::plugin_state_dir/whitelist";
15
16 # Both the black and white lists consist of one IP address per line
17 # you may also use regexp's to match more than one address
18 # Be careful that you don't accidentally block out the world!
19 # Examples:
20 # 192.168.1.102 - block this ip addy
21 # 192.168.1.* - block the whole subnet
22 # 192.* - blocks a whole bunch of addresses
23 # .* - blocks the world
24 # 192.168.1 - fails to match, as this is not a complete address
25 #
26
27 # What should I display for a page that isn't found
28 $message = "404 Not Found\n";
29
30 # ------------------------------
31 my ( @blacklist, @whitelist) = ();
32
33 sub start {
34         
35         if (open (BLACK, "< $blacklist_file")) {
36                 @blacklist = <BLACK>;
37                 close BLACK;
38                 
39                 if (open (WHITE, "< $whitelist_file")) {
40                         @whitelist = <WHITE>;
41                         close WHITE;
42                 }
43                 
44                         
45                 $remoteIP = $ENV{'REMOTE_ADDR'};
46                 foreach (@whitelist) {
47                         chomp $_;
48                         if (($_ !~ /^\s*$/) && ($remoteIP =~ /^$_$/)) {
49                                 return 0 ;
50                                 warn "IP address $_ is whitelisted\n";
51                         }
52                 }
53                 
54                 foreach (@blacklist) {
55                         chomp $_;
56                         if (($_ !~ /^\s*$/) && ($remoteIP =~ /^$_$/)) {
57                                 #$blosxom::output = "Status: 404", exit;
58                                 warn "IP address $_ is blacklisted\n";
59                                 
60                                 # You may want to disable certain plugins,
61                                 # such as writebacks here, as blosxom is still
62                                 # functioning - it just won't return any results
63                                 #$blosxom::plugins{'writebacks'} = 0;
64                                 
65                                 return 1;                               
66                         }
67                 }
68                 return 0;  # We're finished
69         }
70 }
71
72
73 sub last {
74         # We only end up here if we are blacklisting someone
75         
76         $blosxom::output = $message;
77         print "Status: 404\n";
78         
79         1;
80 }
81
82 1;
83
84
85 __END__
86
87 =head1 NAME
88
89 Blosxom Plug-in: blacklist
90
91 =head1 SYNOPSIS
92
93 Allows you to blacklist (or whitelist) certain IP addresses or IP ranges by using regexp's.  You create two files, consisting of one term per line.  The plugin compares the visitor's IP address to each term and quits when it finds a match.  Whitelists supercede blacklists.
94
95 This plugin does not prevent blosxom from performing all of its steps.  Instead, if a visitor is blacklisted, it erases all of the HTML just prior to sending it to the visitor's browser, and instead sends a 404 code, making it appear as if your web pages are no longer present.
96
97 =head1 VERSION
98
99 Version 0.1
100
101 =head2 VERSION HISTORY
102
103 0.1     - initial public release
104
105 =head1 AUTHOR
106
107 Fletcher T. Penney, http://fletcher.freeshell.org
108
109 =head1 LICENSE
110
111 Blosxom Blacklist Plug-in
112 Copyright 2003, by Fletcher T. Penney
113
114 Permission is hereby granted, free of charge, to any person obtaining a
115 copy of this software and associated documentation files (the "Software"),
116 to deal in the Software without restriction, including without limitation
117 the rights to use, copy, modify, merge, publish, distribute, sublicense,
118 and/or sell copies of the Software, and to permit persons to whom the
119 Software is furnished to do so, subject to the following conditions:
120
121 The above copyright notice and this permission notice shall be included
122 in all copies or substantial portions of the Software.
123
124 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
125 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
126 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
127 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
128 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
129 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
130 OTHER DEALINGS IN THE SOFTWARE.