failirc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/failbot +162 -0
- data/bin/failircd +61 -0
- data/lib/failirc.rb +25 -0
- data/lib/failirc/client.rb +227 -0
- data/lib/failirc/client/channel.rb +98 -0
- data/lib/failirc/client/channels.rb +85 -0
- data/lib/failirc/client/client.rb +59 -0
- data/lib/failirc/client/clients.rb +43 -0
- data/lib/failirc/client/dispatcher.rb +209 -0
- data/lib/failirc/client/dispatcher/connectiondispatcher.rb +410 -0
- data/lib/failirc/client/dispatcher/event.rb +113 -0
- data/lib/failirc/client/dispatcher/eventdispatcher.rb +203 -0
- data/lib/failirc/client/module.rb +103 -0
- data/lib/failirc/client/modules/Base.rb +361 -0
- data/lib/failirc/client/modules/Logger.rb +89 -0
- data/lib/failirc/client/server.rb +89 -0
- data/lib/failirc/client/user.rb +66 -0
- data/lib/failirc/client/users.rb +100 -0
- data/lib/failirc/errors.rb +339 -0
- data/lib/failirc/extensions.rb +124 -0
- data/lib/failirc/mask.rb +117 -0
- data/lib/failirc/modes.rb +54 -0
- data/lib/failirc/responses.rb +360 -0
- data/lib/failirc/server.rb +266 -0
- data/lib/failirc/server/channel.rb +122 -0
- data/lib/failirc/server/channels.rb +84 -0
- data/lib/failirc/server/client.rb +100 -0
- data/lib/failirc/server/clients.rb +54 -0
- data/lib/failirc/server/dispatcher.rb +219 -0
- data/lib/failirc/server/dispatcher/connectiondispatcher.rb +477 -0
- data/lib/failirc/server/dispatcher/event.rb +113 -0
- data/lib/failirc/server/dispatcher/eventdispatcher.rb +196 -0
- data/lib/failirc/server/link.rb +50 -0
- data/lib/failirc/server/links.rb +49 -0
- data/lib/failirc/server/module.rb +103 -0
- data/lib/failirc/server/modules/Base.rb +2545 -0
- data/lib/failirc/server/modules/Cloaking.rb +170 -0
- data/lib/failirc/server/modules/Firewall.rb +104 -0
- data/lib/failirc/server/modules/Netlog.rb +67 -0
- data/lib/failirc/server/modules/Roulette.rb +78 -0
- data/lib/failirc/server/modules/TinyURL.rb +98 -0
- data/lib/failirc/server/modules/Translate.rb +62 -0
- data/lib/failirc/server/modules/WordFilter.rb +144 -0
- data/lib/failirc/server/user.rb +72 -0
- data/lib/failirc/server/users.rb +103 -0
- data/lib/failirc/sslutils.rb +74 -0
- data/lib/failirc/utils.rb +53 -0
- metadata +107 -0
@@ -0,0 +1,170 @@
|
|
1
|
+
# failirc, a fail IRC library.
|
2
|
+
#
|
3
|
+
# Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
|
4
|
+
#
|
5
|
+
# This file is part of failirc.
|
6
|
+
#
|
7
|
+
# failirc is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Affero General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# failirc is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Affero General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Affero General Public License
|
18
|
+
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'failirc/server/module'
|
21
|
+
|
22
|
+
module IRC
|
23
|
+
|
24
|
+
class Server
|
25
|
+
|
26
|
+
module Modules
|
27
|
+
|
28
|
+
class Cloaking < Module
|
29
|
+
def initialize (server)
|
30
|
+
@aliases = {
|
31
|
+
:output => {
|
32
|
+
:NAMES => /:.*? 353 /,
|
33
|
+
},
|
34
|
+
|
35
|
+
:input => {
|
36
|
+
:DISGUISEAS => /^DISGUISEAS( |$)/i,
|
37
|
+
},
|
38
|
+
}
|
39
|
+
|
40
|
+
@events = {
|
41
|
+
:custom => {
|
42
|
+
:message => Event::Callback.new(self.method(:received_message), -100),
|
43
|
+
:notice => Event::Callback.new(self.method(:received_notice), -100),
|
44
|
+
:ctcp => Event::Callback.new(self.method(:received_ctcp), -100),
|
45
|
+
|
46
|
+
:topic_change => Event::Callback.new(self.method(:topic_change), -100),
|
47
|
+
},
|
48
|
+
|
49
|
+
:output => {
|
50
|
+
:NAMES => Event::Callback.new(self.method(:hide), -100),
|
51
|
+
},
|
52
|
+
|
53
|
+
:input => {
|
54
|
+
:DISGUISEAS => self.method(:disguiseas),
|
55
|
+
},
|
56
|
+
}
|
57
|
+
|
58
|
+
@disguises = {}
|
59
|
+
|
60
|
+
super(server)
|
61
|
+
end
|
62
|
+
|
63
|
+
def disguiseas (thing, string)
|
64
|
+
match = string.match(/DISGUISEAS\s+(.+?)$/i)
|
65
|
+
|
66
|
+
if !thing.modes[:operator]
|
67
|
+
thing.send :numeric, ERR_NOPRIVILEGES
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
71
|
+
if !match
|
72
|
+
@disguises.delete(thing)
|
73
|
+
else
|
74
|
+
mask = match[1].strip
|
75
|
+
|
76
|
+
if mask.match(/^.+!.+@.+$/)
|
77
|
+
@disguises[thing] = Mask::parse(mask)
|
78
|
+
else
|
79
|
+
@disguises[thing] = mask
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def disguise (fromRef)
|
85
|
+
from = fromRef.value
|
86
|
+
|
87
|
+
if from.modes[:operator]
|
88
|
+
if @disguises[from].is_a?(Mask)
|
89
|
+
fromRef.value = Client.new(server, @disguises[from])
|
90
|
+
elsif tmp = server.clients[@disguises[from]]
|
91
|
+
fromRef.value = tmp
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def received_message (chain, fromRef, toRef, message, level=nil)
|
97
|
+
if chain != :input
|
98
|
+
return
|
99
|
+
end
|
100
|
+
|
101
|
+
disguise(fromRef)
|
102
|
+
end
|
103
|
+
|
104
|
+
def received_notice (chain, fromRef, toRef, message, level=nil)
|
105
|
+
if chain != :input || fromRef.value.is_a?(Server)
|
106
|
+
return
|
107
|
+
end
|
108
|
+
|
109
|
+
disguise(fromRef)
|
110
|
+
end
|
111
|
+
|
112
|
+
def received_ctcp (chain, kind, fromRef, toRef, type, message, level)
|
113
|
+
if chain != :input || fromRef.value.is_a?(Server)
|
114
|
+
return
|
115
|
+
end
|
116
|
+
|
117
|
+
disguise(fromRef)
|
118
|
+
end
|
119
|
+
|
120
|
+
def topic_change (channel, topic, fromRef)
|
121
|
+
disguise(fromRef)
|
122
|
+
end
|
123
|
+
|
124
|
+
def hide (thing, string)
|
125
|
+
match = string.match(/:.*? (\d+)/)
|
126
|
+
|
127
|
+
if !match
|
128
|
+
return
|
129
|
+
end
|
130
|
+
|
131
|
+
self.method("_#{match[1]}".to_sym).call(thing, string) rescue nil
|
132
|
+
end
|
133
|
+
|
134
|
+
def _353 (thing, string)
|
135
|
+
if thing.modes[:operator]
|
136
|
+
return
|
137
|
+
end
|
138
|
+
|
139
|
+
match = string.match(/353 .*?:(.*)$/)
|
140
|
+
|
141
|
+
names = match[1].split(/\s+/)
|
142
|
+
list = ''
|
143
|
+
|
144
|
+
names.each {|original|
|
145
|
+
if Base::User::levels.has_value(original[0, 1])
|
146
|
+
name = original[1, original.length]
|
147
|
+
else
|
148
|
+
name = original
|
149
|
+
end
|
150
|
+
|
151
|
+
if !server.clients[name]
|
152
|
+
next
|
153
|
+
end
|
154
|
+
|
155
|
+
client = server.clients[name]
|
156
|
+
|
157
|
+
if !(client.modes[:operator] && client.modes[:extended][:hide])
|
158
|
+
list << " #{original}"
|
159
|
+
end
|
160
|
+
}
|
161
|
+
|
162
|
+
string.sub!(/ :(.*)$/, " :#{list[1, list.length]}")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# failirc, a fail IRC library.
|
2
|
+
#
|
3
|
+
# Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
|
4
|
+
#
|
5
|
+
# This file is part of failirc.
|
6
|
+
#
|
7
|
+
# failirc is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Affero General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# failirc is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Affero General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Affero General Public License
|
18
|
+
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'failirc/server/module'
|
21
|
+
|
22
|
+
module IRC
|
23
|
+
|
24
|
+
class Server
|
25
|
+
|
26
|
+
module Modules
|
27
|
+
|
28
|
+
class Firewall < Module
|
29
|
+
@@version = '0.0.1'
|
30
|
+
|
31
|
+
def self.version
|
32
|
+
return @@version
|
33
|
+
end
|
34
|
+
|
35
|
+
def description
|
36
|
+
"Firewall-#{Firewall.version}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize (server)
|
40
|
+
@events = {
|
41
|
+
:pre => Event::Callback.new(self.method(:dispatch), -9001),
|
42
|
+
:post => Event::Callback.new(self.method(:dispatch), -9001),
|
43
|
+
|
44
|
+
:custom => {
|
45
|
+
:log => self.method(:log),
|
46
|
+
:kill => Event::Callback.new(self.method(:logKill), -9001),
|
47
|
+
},
|
48
|
+
}
|
49
|
+
|
50
|
+
super(server)
|
51
|
+
end
|
52
|
+
|
53
|
+
def rehash
|
54
|
+
if @log && @log != $stdout
|
55
|
+
@log.close
|
56
|
+
end
|
57
|
+
|
58
|
+
file = @server.config.elements['config/modules/module[@name="Firewall"]/file']
|
59
|
+
|
60
|
+
if file
|
61
|
+
@log = File.open(file.text)
|
62
|
+
else
|
63
|
+
@log = $stdout
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def finalize
|
68
|
+
if @log != $stdout
|
69
|
+
@log.close
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def dispatch (event, thing, string)
|
74
|
+
if (event.chain == :input && event.special == :pre) || (event.chain == :output && event.special == :post)
|
75
|
+
@log.puts "[#{Time.now}] #{target(thing)} #{(event.chain == :input) ? '>' : '<'} #{string.inspect}"
|
76
|
+
@log.flush
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def log (string)
|
81
|
+
@log.puts "[#{Time.now}] #{string}"
|
82
|
+
@log.flush
|
83
|
+
end
|
84
|
+
|
85
|
+
def logKill (thing, message)
|
86
|
+
log "#{target(thing)} KILL :#{message}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def target (thing)
|
90
|
+
if thing.is_a?(Client) || thing.is_a?(User)
|
91
|
+
target = "#{thing.nick || '*'}!#{thing.user || '*'}@#{thing.ip || '*'}"
|
92
|
+
else
|
93
|
+
target = thing.to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
return target
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# failirc, a fail IRC library.
|
2
|
+
#
|
3
|
+
# Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
|
4
|
+
#
|
5
|
+
# This file is part of failirc.
|
6
|
+
#
|
7
|
+
# failirc is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Affero General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# failirc is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Affero General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Affero General Public License
|
18
|
+
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'uri'
|
21
|
+
|
22
|
+
require 'failirc/server/module'
|
23
|
+
|
24
|
+
module IRC
|
25
|
+
|
26
|
+
class Server
|
27
|
+
|
28
|
+
module Modules
|
29
|
+
|
30
|
+
class Netlog < Module
|
31
|
+
def initialize (server)
|
32
|
+
@events = {
|
33
|
+
:custom => {
|
34
|
+
:message => Event::Callback.new(self.method(:netlog), -101),
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
super(server)
|
39
|
+
end
|
40
|
+
|
41
|
+
def netlog (chain, fromRef, toRef, message, level=nil)
|
42
|
+
if chain != :input
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
from = fromRef.value
|
47
|
+
to = toRef.value
|
48
|
+
|
49
|
+
URI.extract(message).each {|uri|
|
50
|
+
if match = uri.match('http://(beta\.)?(\w+?)\.netlog.com.*photo.*?(\d+)')
|
51
|
+
country = match[2]
|
52
|
+
url = match[3]
|
53
|
+
code = "000000000#{url}".match(/(\d{3})(\d{3})\d{3}$/)
|
54
|
+
|
55
|
+
message.gsub!(/#{Regexp.escape(uri)}/, "http://#{country}.netlogstatic.com/p/oo/#{code[1]}/#{code[2]}/#{url}.jpg")
|
56
|
+
elsif match = uri.match(/netlogstatic/)
|
57
|
+
message.gsub!(/#{Regexp.escape(uri)}/, uri.sub(/\/[to]{2}\//, '/oo/'))
|
58
|
+
end
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# failirc, a fail IRC library.
|
2
|
+
#
|
3
|
+
# Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
|
4
|
+
#
|
5
|
+
# This file is part of failirc.
|
6
|
+
#
|
7
|
+
# failirc is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Affero General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# failirc is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Affero General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Affero General Public License
|
18
|
+
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'failirc/server/module'
|
21
|
+
|
22
|
+
module IRC
|
23
|
+
|
24
|
+
class Server
|
25
|
+
|
26
|
+
module Modules
|
27
|
+
|
28
|
+
class Roulette < Module
|
29
|
+
def initialize (server)
|
30
|
+
@aliases = {
|
31
|
+
:input => {
|
32
|
+
:ROULETTE => /^ROULETTE( |$)/i,
|
33
|
+
},
|
34
|
+
}
|
35
|
+
|
36
|
+
@events = {
|
37
|
+
:input => {
|
38
|
+
:ROULETTE => self.method(:roulette),
|
39
|
+
},
|
40
|
+
}
|
41
|
+
|
42
|
+
super(server)
|
43
|
+
end
|
44
|
+
|
45
|
+
def rehash
|
46
|
+
if tmp = @server.config.elements['config/modules/module[@name="Roulette"]/death']
|
47
|
+
@death = tmp.text
|
48
|
+
else
|
49
|
+
@death = 'BOOM, dickshot'
|
50
|
+
end
|
51
|
+
|
52
|
+
if tmp = @server.config.elements['config/modules/module[@name="Roulette"]/life']
|
53
|
+
@life = tmp.text
|
54
|
+
else
|
55
|
+
@life = '#{user.nick} shot but survived :('
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def roulette (thing, string)
|
60
|
+
user = thing
|
61
|
+
|
62
|
+
if rand(3) == 1
|
63
|
+
@server.kill thing, eval(@death.inspect.gsub(/\\#/, '#'))
|
64
|
+
else
|
65
|
+
@server.clients.each_value {|client|
|
66
|
+
if client.modes[:registered]
|
67
|
+
@server.dispatcher.execute :notice, @server, client, eval(@life.inspect.gsub(/\\#/, '#'))
|
68
|
+
end
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# failirc, a fail IRC library.
|
2
|
+
#
|
3
|
+
# Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
|
4
|
+
#
|
5
|
+
# This file is part of failirc.
|
6
|
+
#
|
7
|
+
# failirc is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Affero General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# failirc is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Affero General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Affero General Public License
|
18
|
+
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'net/http'
|
21
|
+
require 'uri'
|
22
|
+
require 'timeout'
|
23
|
+
|
24
|
+
require 'failirc/extensions'
|
25
|
+
require 'failirc/server/module'
|
26
|
+
|
27
|
+
module IRC
|
28
|
+
|
29
|
+
class Server
|
30
|
+
|
31
|
+
module Modules
|
32
|
+
|
33
|
+
class TinyURL < Module
|
34
|
+
def initialize (server)
|
35
|
+
@events = {
|
36
|
+
:custom => {
|
37
|
+
:message => Event::Callback.new(self.method(:tinyurl), -100),
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
super(server)
|
42
|
+
end
|
43
|
+
|
44
|
+
def rehash
|
45
|
+
if tmp = @server.config.elements['config/modules/module[@name="TinyURL"]/length']
|
46
|
+
@length = tmp.text.to_i
|
47
|
+
else
|
48
|
+
@length = 42
|
49
|
+
end
|
50
|
+
|
51
|
+
if tmp = @server.config.elements['config/modules/module[@name="TinyURL"]/timeout']
|
52
|
+
@timeout = tmp.text.to_i
|
53
|
+
else
|
54
|
+
@timeout = 5
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def tinyurl (chain, fromRef, toRef, message, level=nil)
|
59
|
+
if chain != :input
|
60
|
+
return
|
61
|
+
end
|
62
|
+
|
63
|
+
from = fromRef.value
|
64
|
+
to = toRef.value
|
65
|
+
|
66
|
+
URI.extract(message).each {|uri|
|
67
|
+
if uri.length <= @length
|
68
|
+
next
|
69
|
+
end
|
70
|
+
|
71
|
+
if tiny = tinyurlify(uri) rescue nil
|
72
|
+
message.gsub!(/#{Regexp.escape(uri)}/, tiny)
|
73
|
+
end
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def tinyurlify (url)
|
78
|
+
begin
|
79
|
+
content = timeout @timeout do
|
80
|
+
Net::HTTP.post_form(URI.parse('http://tinyurl.com/create.php'), { 'url' => url }).body
|
81
|
+
end
|
82
|
+
|
83
|
+
match = content.match('<blockquote><b>(http://tinyurl.com/\w+)</b>')
|
84
|
+
|
85
|
+
if match
|
86
|
+
return match[1]
|
87
|
+
end
|
88
|
+
rescue Timeout::Error
|
89
|
+
return nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|