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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
package ASM::Util;
use Array::Utils qw(:all);
use POSIX qw(strftime);
use warnings;
use strict;
use Term::ANSIColor qw (:constants);
%::RISKS =
(
'disable'=> -1, #this isn't really an alert
'debug' => 10,
'info' => 20,
'low' => 30,
'medium' => 40,
'high' => 50,
'opalert'=> 9001 #OVER NINE THOUSAND!!!
);
#leaves room for more levels if for some reason we end up needing more
#theoretically, you should be able to change those numbers without any damage
%::COLORS =
(
'white' => '00',
'black' => '01',
'blue' => '02',
'green' => '03',
'red' => '04',
'brown' => '05',
'purple' => '06',
'orange' => '07',
'yellow' => '08',
'ltgreen' => '09',
'teal' => '10',
'ltcyan' => '11',
'ltblue' => '12',
'pink' => '13',
'grey' => '14',
'ltgrey' => '15',
);
%::RCOLOR =
(
$::RISKS{debug} => $::COLORS{purple},
$::RISKS{info} => $::COLORS{blue},
$::RISKS{low} => $::COLORS{green},
$::RISKS{medium} => $::COLORS{orange},
$::RISKS{high} => $::COLORS{red},
);
sub new
{
my $module = shift;
my $self = {};
bless ($self);
return $self;
}
sub maxlen {
my ($a, $b) = @_;
my ($la, $lb) = (length($a), length($b));
return $la if ($la > $lb);
return $lb;
}
#cs: returns the xml settings for the specified chan, or default if there aren't any settings for that chan
sub cs {
my ($module, $chan) = @_;
$chan = lc $chan;
return $::channels->{channel}->{default} unless defined($::channels->{channel}->{$chan});
if ( defined($::channels->{channel}->{$chan}->{link}) ) {
return $::channels->{channel}->{ $::channels->{channel}->{$chan}->{link} };
}
return $::channels->{channel}->{$chan};
}
sub getLink
{
my ($module, $chan) = @_;
$chan = lc $chan;
my $link = $::channels->{channel}->{$chan}->{link};
if ( defined($link) ) {
return $link;
}
return $chan;
}
sub speak
{
my ($module, $chan) = @_;
$chan = lc $chan;
if ( defined($::channels->{channel}->{$chan}->{silence}) ) {
if ($::channels->{channel}->{$chan}->{silence} eq "no") {
return 1;
}
elsif ($::channels->{channel}->{$chan}->{silence} eq "yes") {
return 0;
}
}
if ( defined($::channels->{channel}->{default}->{silence}) ) {
if ( $::channels->{channel}->{default}->{silence} eq "no" ) {
return 1;
}
elsif ( $::channels->{channel}->{default}->{silence} eq "yes" ) {
return 0;
}
}
return 1;
}
#this item is a stub, dur
sub hostip {
return gethostbyname($_[0]);
}
# If $tgts="#antispammeta" that's fine, and if $tgts = ["#antispammeta", "##linux-ops"] that's cool too
sub sendLongMsg {
my ($module, $conn, $tgts, $txtz) = @_;
if (length($txtz) <= 380) {
$conn->privmsg($tgts, $txtz);
} else {
my $splitpart = rindex($txtz, " ", 380);
$conn->privmsg($tgts, substr($txtz, 0, $splitpart));
$conn->privmsg($tgts, substr($txtz, $splitpart));
}
}
sub getAlert {
my ($module, $c, $risk, $t) = @_;
my @disable = ();
my @x = ();
$c = lc $c;
foreach my $prisk ( keys %::RISKS) {
if ( $::RISKS{$risk} >= $::RISKS{$prisk} ) {
push( @x, @{$::channels->{channel}->{master}->{$t}->{$prisk}} ) if defined $::channels->{channel}->{master}->{$t}->{$prisk};
push( @x, @{cs($module, $c)->{$t}->{$prisk}} ) if defined cs($module, $c)->{$t}->{$prisk};
}
}
push( @disable, @{$::channels->{channel}->{master}->{$t}->{disable}} ) if defined $::channels->{channel}->{master}->{$t}->{disable};
push( @disable, @{cs($module, $c)->{$t}->{disable}} ) if defined cs($module, $c)->{$t}->{disable};
@x = unique(@x);
@x = array_diff(@x, @disable);
return @x;
}
sub commaAndify {
my $module = shift;
my @seq = @_;
my $len = ($#seq);
my $last = $seq[$len];
return '' if $len eq -1;
return $seq[0] if $len eq 0;
return join( ' and ', $seq[0], $seq[1] ) if $len eq 1;
return join( ', ', splice(@seq,0,$len) ) . ', and ' . $last;
}
sub leq {
my ($s1, $s2) = @_;
return (lc $s1 eq lc $s2);
}
sub seq {
my ($n1, $n2) = @_;
return 0 unless defined($n1);
return 0 unless defined($n2);
return ($n1 eq $n2);
}
#I last worked on this function while having way too many pain meds, if it's fucked up, that's why.
sub dprint {
my ($module, $text, $type) = @_;
if (!defined($type)) {
die "old method for dprint called!\n";
}
if (!defined($::debugx{$type})) {
die "dprint called with invalid type!\n";
}
if ($::debugx{$type} eq 0) {
return;
}
print STDERR strftime("%F %T ", gmtime);
print STDERR GREEN, 'DEBUG', RESET, '(', $::debugx{$type}, $type, RESET, ') ';
print STDERR $text, "\n";
}
sub notRestricted {
my ($module, $nick, $restriction) = @_;
$nick = lc $nick;
my $host = $::sn{$nick}{host};
my $account = lc $::sn{$nick}{account};
my $ret = 1;
if (defined($::restrictions->{nicks}->{nick}->{$nick})) {
if (defined($::restrictions->{nicks}->{nick}->{$nick}->{$restriction})) {
$ret= 0;
}
}
if ((defined($host)) && (defined($account))) {
if (defined($::restrictions->{accounts}->{account}->{$account})) {
if (defined($::restrictions->{accounts}->{account}->{$account}->{$restriction})) {
$ret= 0;
}
}
if (defined($::restrictions->{hosts}->{host}->{$host})) {
if (defined($::restrictions->{hosts}->{host}->{$host}->{$restriction})) {
$ret= 0;
}
}
}
if ($ret == 0) {
dprint("blah", "Restriction $restriction found for $nick", "restrictions");;
}
return $ret;
}
return 1;
|