File: Security.pm

package info (click to toggle)
pnopaste 1.4-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 356 kB
  • sloc: perl: 1,043; sh: 45; sql: 37; makefile: 5
file content (90 lines) | stat: -rw-r--r-- 1,804 bytes parent folder | download | duplicates (2)
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
package Security;

# This file is part of the pnopaste program
# Copyright (C) 2008-2010 Patrick Matthäi <pmatthaei@debian.org>
#
# 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.

use warnings;
use strict;
use lib::Database;
use lib::Hits;


### Check if the IP is blacklisted.
sub Blacklist_Host {
	my($IP) = @_;

	my $Query = 'SELECT id FROM blacklist_ip WHERE ip = ? LIMIT 1';
	$Query = $Database::dbh->prepare($Query);
	$Query->execute($IP);

	my $List = $Query->fetchrow_hashref();

	if($List->{'id'}){
		Hits::Inc_Badhost($List->{'id'});
		return 1;
	}

	# Not blacklisted.
	return 0;
}


### Returns the bad Hosts as array.
sub Get_Blacklist_Hosts {
	my $Query = 'SELECT ip FROM blacklist_ip ORDER by id';
	$Query = $Database::dbh->prepare($Query);
	$Query->execute();

	my @Result;

	while(my $List = $Query->fetchrow_hashref()){
		push(@Result, $List->{'ip'});
	}

	return @Result
}


### Check codes for badwords.
sub Blacklist_Words {
	my($Code) = @_;

	my $Query = 'SELECT id,word FROM blacklist_word';
	$Query = $Database::dbh->prepare($Query);
	$Query->execute();

	while(my $List = $Query->fetchrow_hashref()){
		my $Match = $List->{'word'};
		if($Code =~ /$Match/i){
			Hits::Inc_Badword($List->{'id'});
			# Blacklisted.
			return 1;
		}
	}

	# Nothing evil found.
	return 0;
}


### Returns the badwords as array.
sub Get_Blacklist_Words {
	my $Query = 'SELECT word FROM blacklist_word ORDER by id';
	$Query = $Database::dbh->prepare($Query);
	$Query->execute();

	my @Result;

	while(my $List = $Query->fetchrow_hashref()){
		push(@Result, $List->{'word'});
	}

	return @Result;
}

1;