]>
Commit | Line | Data |
---|---|---|
5975999e | 1 | # This file is part of SurrealServices. |
2 | # | |
3 | # SurrealServices is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # SurrealServices is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with SurrealServices; if not, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | package services; | |
17 | use strict; | |
2eef9154 | 18 | use Data::Dumper; |
5975999e | 19 | use SrSv::Conf::Parameters services => [ |
20 | [noexpire => undef], | |
21 | [nickexpire => 21], | |
22 | [vacationexpire => 90], | |
23 | [nearexpire => 7], | |
24 | [chanexpire => 21], | |
25 | [validate_email => undef], | |
26 | [validate_expire => 1], | |
27 | [clone_limit => 3], | |
28 | [chankilltime => 86400], | |
29 | ||
30 | [default_protect => 'normal'], | |
31 | [default_chanbot => undef], | |
32 | [old_user_age => 300], | |
33 | ||
34 | [log_overrides => 0], | |
35 | ||
36 | [botserv => undef], | |
37 | [nickserv => undef], | |
38 | [chanserv => undef], | |
39 | [memoserv => undef], | |
40 | [adminserv => undef], | |
41 | [operserv => undef], | |
42 | [hostserv => undef], | |
43 | ]; | |
44 | ||
45 | use DBI; | |
46 | use SrSv::MySQL qw($dbh); | |
47 | use SrSv::Conf qw(main services sql); | |
48 | use SrSv::Conf2Consts qw(main services sql); | |
49 | use SrSv::Timer qw(add_timer); | |
50 | use SrSv::Agent; | |
51 | use SrSv::IRCd::Event qw(addhandler); | |
52 | use SrSv::Log; | |
53 | use SrSv::User qw( :flood __flood_expire ); | |
54 | ||
55 | use modules::serviceslibs::adminserv; | |
56 | use modules::serviceslibs::nickserv; | |
57 | use modules::serviceslibs::chanserv; | |
58 | use modules::serviceslibs::operserv; | |
59 | use modules::serviceslibs::botserv; | |
60 | use modules::serviceslibs::memoserv; | |
61 | use modules::serviceslibs::hostserv; | |
62 | ||
63 | *conf = \%services_conf; # only used in some help docs | |
64 | ||
65 | our @agents = ( | |
66 | [$nickserv::nsnick_default, '+opqzBHS', 'Nick Registration Agent'], | |
67 | [$chanserv::csnick_default, '+pqzBS', 'Channel Registration Agent'], | |
68 | [$operserv::osnick_default, '+opqzBHS', 'Operator Services Agent'], | |
69 | [$memoserv::msnick_default, '+pqzBS', 'Memo Exchange Agent'], | |
70 | [$botserv::bsnick_default, '+pqzBS', 'Channel Bot Control Agent'], | |
71 | [$adminserv::asnick_default, '+pqzBS', 'Services\' Administration Agent'], | |
72 | [$hostserv::hsnick_default, '+pqzBS', 'vHost Agent'] | |
73 | ); | |
74 | if(services_conf_nickserv) { | |
75 | push @agents, [services_conf_nickserv, '+opqzBHS', 'Nick Registration Agent']; | |
76 | $nickserv::nsnick = services_conf_nickserv; | |
77 | } | |
78 | if(services_conf_chanserv) { | |
79 | push @agents, [services_conf_chanserv, '+pqzBS', 'Channel Registration Agent']; | |
80 | $chanserv::csnick = services_conf_nickserv; | |
81 | } | |
82 | if(services_conf_operserv) { | |
83 | push @agents, [services_conf_operserv, '+opqzBHS', 'Operator Services Agent']; | |
84 | $operserv::osnick = services_conf_operserv; | |
85 | } | |
86 | if(services_conf_memoserv) { | |
87 | push @agents, [services_conf_memoserv, '+pqzBS', 'Memo Exchange Agent']; | |
88 | $memoserv::msnick = services_conf_memoserv; | |
89 | } | |
90 | if(services_conf_botserv) { | |
91 | push @agents, [services_conf_botserv, '+pqzBS', 'Channel Bot Control Agent']; | |
92 | $botserv::bsnick = services_conf_botserv; | |
93 | } | |
94 | if(services_conf_adminserv) { | |
95 | push @agents, [services_conf_adminserv, '+pqzBS', 'Services\' Administration Agent']; | |
96 | $adminserv::asnick = services_conf_adminserv; | |
97 | } | |
98 | if(services_conf_hostserv) { | |
99 | push @agents, [services_conf_hostserv, '+pqzBS', 'vHost Agent']; | |
100 | $hostserv::hsnick = services_conf_hostserv; | |
101 | } | |
102 | ||
103 | our $qlreason = 'Reserved for Services'; | |
104 | ||
105 | foreach my $a (@agents) { | |
2eef9154 | 106 | print "AGENT " . Dumper($a); |
5975999e | 107 | agent_connect($a->[0], 'services', undef, $a->[1], $a->[2]); |
108 | ircd::sqline($a->[0], $qlreason); | |
109 | agent_join($a->[0], main_conf_diag); | |
2eef9154 | 110 | my $rsUser = { NICK => $main::rsnick, ID => ircd::getUuid($main::rsnick) }; |
111 | my $agent = { NICK => $a->[0], ID => ircd::getUuid ($a->[0]) }; | |
112 | ircd::setmode($agent, main_conf_diag, '+o', $agent); | |
5975999e | 113 | } |
114 | ||
115 | addhandler('ENDBURST', undef, undef, 'services::ev_connect'); | |
116 | sub ev_connect { | |
117 | botserv::eos(); | |
118 | nickserv::cleanup_users(); | |
119 | nickserv::fix_vhosts(); | |
120 | chanserv::eos(); | |
121 | operserv::expire(); | |
122 | } | |
123 | ||
124 | addhandler('ENDBURST', undef, undef, 'services::eos'); | |
125 | sub eos { | |
126 | chanserv::eos($_[0]); | |
127 | } | |
128 | ||
129 | addhandler('KILL', undef, undef, 'nickserv::killhandle'); | |
130 | ||
131 | addhandler('NICKCONN', undef, undef, 'services::ev_nickconn'); | |
132 | sub ev_nickconn { | |
133 | nickserv::nick_create(@_[0,2..4,8,5..7,9,10,11]); | |
134 | } | |
135 | ||
136 | # NickServ | |
137 | addhandler('NICKCHANGE', undef, undef, 'nickserv::nick_change'); | |
138 | addhandler('QUIT', undef, undef, 'nickserv::nick_delete'); | |
139 | addhandler('UMODE', undef, undef, 'nickserv::umode'); | |
140 | addhandler('CHGHOST', undef, undef, 'nickserv::chghost'); | |
141 | addhandler('CHGIDENT', undef, undef, 'nickserv::chgident'); | |
142 | addhandler('USERIP', undef, undef, 'nickserv::userip'); | |
143 | addhandler('SQUIT', undef, undef, 'nickserv::squit') if ircd::NOQUIT(); | |
2eef9154 | 144 | addhandler("OPERUP", undef, undef, 'nickserv::handle_oper'); |
145 | addhandler('PRIVMSG', undef, undef, 'nickserv::dispatch'); | |
5975999e | 146 | addhandler('PRIVMSG', undef, lc services_conf_nickserv, 'nickserv::dispatch') if services_conf_nickserv; |
147 | ||
148 | addhandler('BACK', undef, undef, 'nickserv::notify_auths'); | |
149 | ||
150 | # ChanServ | |
151 | addhandler('JOIN', undef, undef, 'chanserv::user_join'); | |
152 | addhandler('SJOIN', undef, undef, 'chanserv::handle_sjoin'); | |
153 | addhandler('PART', undef, undef, 'chanserv::user_part'); | |
154 | addhandler('KICK', undef, undef, 'chanserv::process_kick'); | |
155 | addhandler('MODE', undef, qr/^#/, 'chanserv::chan_mode'); | |
156 | addhandler('TOPIC', undef, undef, 'chanserv::chan_topic'); | |
157 | ||
2eef9154 | 158 | addhandler('PRIVMSG', undef, undef, 'chanserv::dispatch'); |
5975999e | 159 | addhandler('PRIVMSG', undef, lc services_conf_chanserv, 'chanserv::dispatch') if services_conf_chanserv; |
160 | ||
161 | # OperServ | |
2eef9154 | 162 | addhandler('PRIVMSG', undef, undef, 'operserv::dispatch'); |
5975999e | 163 | addhandler('PRIVMSG', undef, lc services_conf_operserv, 'operserv::dispatch') if services_conf_operserv; |
164 | ||
165 | add_timer('flood_expire', 10, __PACKAGE__, 'services::flood_expire'); | |
166 | ||
167 | sub flood_expire(;$) { | |
168 | add_timer('flood_expire', 10, __PACKAGE__, 'services::flood_expire'); | |
169 | __flood_expire(); | |
170 | } | |
171 | ||
172 | # MemoServ | |
2eef9154 | 173 | addhandler('PRIVMSG', undef, undef, 'memoserv::dispatch'); |
5975999e | 174 | addhandler('PRIVMSG', undef, lc services_conf_memoserv, 'memoserv::dispatch') if services_conf_memoserv; |
175 | addhandler('BACK', undef, undef, 'memoserv::notify'); | |
176 | ||
177 | # BotServ | |
178 | addhandler('PRIVMSG', undef, undef, 'botserv::dispatch'); | |
179 | # botserv takes all PRIVMSG and NOTICEs, so no special dispatch is needed. | |
180 | addhandler('NOTICE', undef, qr/^#/, 'botserv::chan_msg'); | |
181 | ||
182 | # AdminServ | |
2eef9154 | 183 | addhandler('PRIVMSG', undef, undef, 'adminserv::dispatch'); |
5975999e | 184 | addhandler('PRIVMSG', undef, lc services_conf_adminserv, 'adminserv::dispatch') if services_conf_adminserv; |
185 | ||
186 | add_timer('', 30, __PACKAGE__, 'services::maint'); | |
187 | #add_timer('', 20, __PACKAGE__, 'nickserv::cleanup_users'); | |
188 | add_timer('', 60, __PACKAGE__, 'nickserv::expire_silence_timed'); | |
189 | ||
190 | # HostServ | |
2eef9154 | 191 | addhandler('PRIVMSG', undef, undef, 'hostserv::dispatch'); |
5975999e | 192 | addhandler('PRIVMSG', undef, lc services_conf_hostserv, 'hostserv::dispatch') if services_conf_hostserv; |
193 | ||
194 | # $nick should be a registered root nick, if applicable | |
195 | # $src is the nick or nickid that sent the command | |
196 | sub ulog($$$$;$$) { | |
197 | my ($service, $level, $text) = splice(@_, 0, 3); | |
198 | ||
199 | my $hostmask = nickserv::get_hostmask($_[0]); | |
200 | ||
201 | # TODO - Record this in the database | |
202 | ||
203 | wlog($service, $level, "$hostmask - $text"); | |
204 | } | |
205 | ||
206 | sub maint { | |
207 | wlog($main::rsnick, LOG_INFO(), " -- Running maintenance routines."); | |
208 | add_timer('', 3600, __PACKAGE__, 'services::maint'); | |
209 | ||
210 | nickserv::expire(); | |
211 | chanserv::expire(); | |
212 | ||
213 | wlog($main::rsnick, LOG_INFO(), " -- Maintenance routines complete."); | |
214 | } | |
215 | ||
216 | sub init { | |
217 | my $tmpdbh = DBI->connect("DBI:mysql:".sql_conf_mysql_db, sql_conf_mysql_user, sql_conf_mysql_pass, { AutoCommit => 1, RaiseError => 1 }); | |
218 | ||
219 | $tmpdbh->do("TRUNCATE TABLE chanuser"); | |
220 | $tmpdbh->do("TRUNCATE TABLE nickchg"); | |
221 | $tmpdbh->do("TRUNCATE TABLE chan"); | |
222 | $tmpdbh->do("TRUNCATE TABLE chanban"); | |
223 | $tmpdbh->do("UPDATE user SET online=0, quittime=".time()); | |
224 | ||
225 | $tmpdbh->disconnect; | |
226 | } | |
227 | ||
228 | sub begin { | |
229 | nickserv::init(); | |
230 | chanserv::init(); | |
231 | operserv::init(); | |
232 | botserv::init(); | |
233 | adminserv::init(); | |
234 | memoserv::init(); | |
235 | hostserv::init(); | |
236 | } | |
237 | ||
238 | sub end { | |
239 | $dbh->disconnect; | |
240 | } | |
241 | ||
242 | sub unload { } | |
243 | ||
244 | 1; |