]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chanlog.cpp
Show a better warning when certtool/openssl are missing.
[user/henk/code/inspircd.git] / src / modules / m_chanlog.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
5  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22
23 /* $ModDesc: Logs snomask output to channel(s). */
24
25 class ModuleChanLog : public Module
26 {
27  private:
28         /*
29          * Multimap so people can redirect a snomask to multiple channels.
30          */
31         typedef std::multimap<char, std::string> ChanLogTargets;
32         ChanLogTargets logstreams;
33
34  public:
35         void init()
36         {
37                 Implementation eventlist[] = { I_OnRehash, I_OnSendSnotice };
38                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
39
40                 OnRehash(NULL);
41         }
42
43         virtual ~ModuleChanLog()
44         {
45         }
46
47         virtual void OnRehash(User *user)
48         {
49                 std::string snomasks;
50                 std::string channel;
51
52                 logstreams.clear();
53
54                 ConfigTagList tags = ServerInstance->Config->ConfTags("chanlog");
55                 for (ConfigIter i = tags.first; i != tags.second; ++i)
56                 {
57                         channel = i->second->getString("channel");
58                         snomasks = i->second->getString("snomasks");
59
60                         if (channel.empty() || snomasks.empty())
61                         {
62                                 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
63                                 continue;
64                         }
65
66                         for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
67                         {
68                                 logstreams.insert(std::make_pair(*it, channel));
69                                 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
70                         }
71                 }
72
73         }
74
75         virtual ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
76         {
77                 std::pair<ChanLogTargets::const_iterator, ChanLogTargets::const_iterator> itpair = logstreams.equal_range(sno);
78                 if (itpair.first == itpair.second)
79                         return MOD_RES_PASSTHRU;
80
81                 char buf[MAXBUF];
82                 snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
83
84                 for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it)
85                 {
86                         Channel *c = ServerInstance->FindChan(it->second);
87                         if (c)
88                         {
89                                 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
90                                 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
91                         }
92                 }
93
94                 return MOD_RES_PASSTHRU;
95         }
96
97         virtual Version GetVersion()
98         {
99                 return Version("Logs snomask output to channel(s).", VF_VENDOR);
100         }
101 };
102
103
104 MODULE_INIT(ModuleChanLog)
105
106
107
108
109
110
111
112
113
114 /*
115  * This is for the "old" chanlog module which intercepted messages going to the logfile..
116  * I don't consider it all that useful, and it's quite dangerous if setup incorrectly, so
117  * this is defined out but left intact in case someone wants to develop it further someday.
118  *
119  * -- w00t (aug 23rd, 2008)
120  */
121 #define OLD_CHANLOG 0
122
123 #if OLD_CHANLOG
124 class ChannelLogStream : public LogStream
125 {
126  private:
127         std::string channel;
128
129  public:
130         ChannelLogStream(int loglevel, const std::string &chan) : LogStream(loglevel), channel(chan)
131         {
132         }
133
134         virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
135         {
136                 Channel *c = ServerInstance->FindChan(channel);
137                 static bool Logging = false;
138
139                 if (loglevel < this->loglvl)
140                         return;
141
142                 if (Logging)
143                         return;
144
145                 if (c)
146                 {
147                         Logging = true; // this avoids (rare chance) loops with logging server IO on networks
148                         char buf[MAXBUF];
149                         snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
150
151                         c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
152                         ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
153                         Logging = false;
154                 }
155         }
156 };
157 #endif
158