lib/PurpleWiki/ACL.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 71 CC 8 SCAR 37.4
CC
8
Cov
0%
canEdit
72.0
new
2.0
canRead
2.0
CRAP 42.0
1 # PurpleWiki::ACL.pm
2 #
3 # $Id: ACL.pm 464 2004-08-09 01:38:51Z cdent $
4 #
5 # Copyright (c) Blue Oxen Associates 2002-2004. All rights reserved.
6 #
7 # This file is part of PurpleWiki. PurpleWiki is derived from:
8 #
9 # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001
10 # AtisWiki v0.3 (c) Markus Denker 1998
11 # CVWiki CVS-patches (c) Peter Merel 1997
12 # The Original WikiWikiWeb (c) Ward Cunningham
13 #
14 # PurpleWiki is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the
26 # Free Software Foundation, Inc.
27 # 59 Temple Place, Suite 330
28 # Boston, MA 02111-1307 USA
29  
30 package PurpleWiki::ACL;
31  
32 use 5.005;
33 use strict;
34 use PurpleWiki::Config;
35  
36 our $VERSION;
37 $VERSION = sprintf("%d", q$Id: ACL.pm 464 2004-08-09 01:38:51Z cdent $ =~ /\s(\d+)\s/);
38  
39 ### constructor
40  
41 sub new {
42 my $this = shift;
43 my (%options) = @_;
44 my $self;
45  
46 my $config = PurpleWiki::Config->instance;
47 $self->{config} = $config;
48  
49 bless($self, $this);
50 return $self;
51 }
52  
53 ### methods
54  
55 sub canRead {
56 my $self = shift;
57 my ($user, $pageId) = @_;
58  
59 return 1;
60 }
61  
62 sub canEdit {
63 my $self = shift;
64 my ($user, $pageId) = @_;
65  
66 if ($self->{config}->LoginToEdit) {
67 (defined $user) ? return 1 : return 0;
68 }
69  
70 # check ban list
71 my ($status, $data) = PurpleWiki::Database::ReadFile($self->{config}->DataDir . "/banlist");
72 return 1 if (!$status); # No file exists, so no ban
73 my $ip = $ENV{'REMOTE_ADDR'};
74 my $host = $ENV{REMOTE_HOST};
75 if ($host eq "") {
76 # Catch errors (including bad input) without aborting the script
77 eval 'use Socket; my $iaddr = inet_aton($ip});' .
78 '$host = gethostbyaddr($iaddr, AF_INET)';
79 }
80 foreach (split(/\n/, $data)) {
81 next if ((/^\s*$/) || (/^#/)); # Skip empty, spaces, or comments
82 return 0 if ($ip =~ /$_/i);
83 return 0 if ($host =~ /$_/i);
84 }
85 return 1;
86 }
87  
88 sub canAdmin {
89 my $self = shift;
90 my ($user, $pageId) = @_;
91  
92 return 0;
93 }
94  
95 1;
96 __END__