[Kareha] Ban only posters by IP? (14)

1 Name: Anonymous 2005-08-17 22:46 ID:U2bSlyNo [Del]

I'm pretty sure what I'm asking for is possible, but I don't want to cluelessly hack up the Kareha scripts to do it. ("Cluelessly" mainly because I don't speak much Perl at all.) What I'm looking for is a consistent way to keep troublemakers only from posting, not from reading or accessing. Can such a thing be done, and if so, what's the best way?

A concept I was toying with is making Kareha check a file with a list of addresses or ranges, and if either REMOTE_HOST or REMOTE_ADDR match, the script redirects the poster to a "you've been banned" page and quits instead of moving on to analyze and perform the post.

2 Name: !WAHa.06x36 2005-08-18 04:53 ID:I+qyC+s8 [Del]

This should be fairly easy to add - you could use the read_array() function to read in a text file as an array, and just look throught it for a match on REMOTE_ADDR. That's pretty much what Wakaba does, except with a database. Put it somewhere near the top of the post_stuff() function.

Now, the reason I didn't actually implement that is that I think you could do much the same with Apache... For instance, banning just POST requests form certain IPs. I must admit that I don't know exactly how to do that, though.

3 Name: Anonymous 2005-08-18 07:03 ID:8DPru6UY [Del]

Thanks for the insight, I truly appreciate it, but I'm seriously considering using thttpd instead: much lighter and easier to set up, and at least as secure out-of-box. The only way I could ban without a cgi script when using thttpd is with iptables, and that would ban all access, not just posting.

4 Name: !WAHa.06x36 2005-08-18 10:22 ID:tzIjPQGA [Del]

I see.

Here's a quick one-liner:

make_error("BANNED!") if(grep { $_ eq $ENV{REMOTE_ADDR} } read_array("ban.txt"));

You could of course make the $_ eq $ENV{REMOTE_ADDR} test more clever if you wanted IP ranges. wakautils.pl has a convenient dot_to_dec() function for converting IP addresses to integers, which would help with that.

5 Name: Anonymous 2005-08-18 18:50 ID:Heaven [Del]

This is, in essence, precisely what I was looking for. Thank you. ^^

6 Name: test!.CzKQna1OU 2005-08-19 03:47 ID:Heaven [Del]

test

7 Name: Anonymous 2005-08-22 12:40 ID:hRXyeQdS [Del]

>>4
This is what I decided to do, based on your input, starting from a stock Kareha 2.0.3 download. In kareha.pl, at the top of post_stuff(), I added the following lines:

# check for post by banned visitor, and fail before posting if found
make_error(S_BANNED) if(grep { $_ eq $ENV{REMOTE_ADDR} } read_array(BANLIST));

In the Error strings section of templates.pl, I added the following line:

use constant S_BANNED => 'You have been banned from posting.  Please contact the staff if you think this has been unjustly done.';

And in config.pl, I added the following line:

use constant BANLIST => 'banned.txt';                   #Make this file a symlink if you want to use a global ban file.

Thank you so much for your help.

8 Name: Anonymous : 2006-03-31 17:17 ID:h9KfmH3K [Del]

I get:

Software Error:

Couldn't write to file "" at wakautils.pl line 944.

Any idea what's causing this? Perhaps I'm just an idiot.

9 Name: !WAHa.06x36 : 2006-03-31 19:17 ID:Heaven [Del]

>>8

When you do what? I don't see what this has to do with the topic of the thread...

10 Name: Anonymous : 2006-03-31 19:33 ID:h9KfmH3K [Del]

>>9
I did everything in >>7 then rebuild cache via admin.pl and got that error.

It seems that the board updates fine but it still gives this error. Doesn't look like anything is borked, just find it weird to get an error like that.

11 Name: Anonymous : 2006-03-31 19:42 ID:h9KfmH3K [Del]

my friend helped me work this out for admin.pl:

added the following in <loop $posts>:
<a href="<var $path>admin.pl?task=banuser&amp;thread=<var $thread>&amp;num=<var $num>&amp;password=<var $adminpass>">ban</a>

then added:
# Banning a user
if($query->param("task") eq 'banuser')
{

my $num    = $query->param("num");
my $thread = $query->param("thread");

my $ip = decrypt_ip($log{$thread}{$num}->{"ip"});

# Write it out to the ban table.
open(BANTABLE, ">>", BAN_FILE) or die "Could not open the ban table.";
print BANTABLE "$ip\n";

}

you can also add banned.txt to the list of items included in the admin.pl edit list to allow manual editing of the banned ip list

12 Name: !WAHa.06x36 : 2006-03-31 20:02 ID:ja3ig2Lg [Del]

>>10

That seems pretty weird... Did you change some filename in config.pl to "", or something?

13 Name: Anonymous : 2006-03-31 21:56 ID:h9KfmH3K [Del]

>>12
nope.

14 Name: Anonymous : 2006-04-02 03:30 ID:pgw0Gr3E (Image: 1099x279 jpg, 46 kb) [Del]

src/1143970230208.jpg: 1099x279, 46 kb

got a simple ban system going for our boards now

Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: