Files
znc/modules/send_raw.cpp
Alexey Sokolov b2dcad5fd4 Change ZNC license to Apache 2.0
The following people agreed with the change, in alphabetical order:
(people who approved in several ways are listed only once)
By email:
- Adam (from Anope)
- Austin Morton
- Brian Campbell
- Christian Walde
- Daniel Holbert
- Daniel Wallace
- Falk Seidel
- Heiko Hund
- Ingmar Runge
- Jim Hull
- Kyle Fuller
- Lee Aylward
- Martin Martimeo
- Matt Harper
- Michael J Edgar
- Michael Ziegler
- Nick Bebout
- Paul Driver
- Perry Nguyen
- Philippe (cycomate)
- Reuben Morais
- Roland Hieber
- Sebastian Ramacher
- Stefan Rado
- Stéphan Kochen
- Thomas Ward
- Toon Schoenmakers
- Veit Wahlich
- Wulf C. Krueger

By IRC:
- CNU
- Jonas Gorski
- Joshua M. Clulow
- Prozac/SHiZNO
- SilverLeo
- Uli Schlachter

At https://github.com/znc/znc/issues/311 :
- Alexey Sokolov
- Elizabeth Myers
- flakes
- Jens-Andre Koch
- Jyzee
- KindOne/ineedalifetoday
- Lee Williams
- Mantas Mikulėnas
- md-5
- Reed Loden

At the last few pull requests' comments:
- Allan Odgaard
- Jacob Baines
- Lluís Batlle i Rossell
- ravomavain
- protomouse

The following commits' authors didn't respond:
Trivial changes:
- f70f1086fd
- 4ca8b50e45

The changes which are not presented in master anymore:
- 5512ed2ea0
- 960a4498f7
- 0f739de2c0
- 7f53cc810b

Fix #311
Fix #218
2013-06-14 00:43:34 +04:00

144 lines
4.6 KiB
C++

/*
* Copyright (C) 2004-2013 ZNC, see the NOTICE file for details.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <znc/User.h>
#include <znc/IRCNetwork.h>
using std::vector;
using std::map;
class CSendRaw_Mod: public CModule {
void SendClient(const CString& sLine) {
CUser *pUser = CZNC::Get().FindUser(sLine.Token(1));
if (pUser) {
CIRCNetwork *pNetwork = pUser->FindNetwork(sLine.Token(2));
if (pNetwork) {
pNetwork->PutUser(sLine.Token(3, true));
PutModule("Sent [" + sLine.Token(3, true) + "] to " + pUser->GetUserName() + "/" + pNetwork->GetName());
} else {
PutModule("Network [" + sLine.Token(2) + "] not found for user [" + sLine.Token(1) + "]");
}
} else {
PutModule("User [" + sLine.Token(1) + "] not found");
}
}
void SendServer(const CString& sLine) {
CUser *pUser = CZNC::Get().FindUser(sLine.Token(1));
if (pUser) {
CIRCNetwork *pNetwork = pUser->FindNetwork(sLine.Token(2));
if (pNetwork) {
pNetwork->PutIRC(sLine.Token(3, true));
PutModule("Sent [" + sLine.Token(3, true) + "] to IRC Server of " + pUser->GetUserName() + "/" + pNetwork->GetName());
} else {
PutModule("Network [" + sLine.Token(2) + "] not found for user [" + sLine.Token(1) + "]");
}
} else {
PutModule("User [" + sLine.Token(1) + "] not found");
}
}
void CurrentClient(const CString& sLine) {
CString sData = sLine.Token(1, true);
m_pClient->PutClient(sData);
}
public:
virtual ~CSendRaw_Mod() {}
virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) {
if (!m_pUser->IsAdmin()) {
sErrorMsg = "You must have admin privileges to load this module";
return false;
}
return true;
}
virtual CString GetWebMenuTitle() { return "Send Raw"; }
virtual bool WebRequiresAdmin() { return true; }
virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
if (sPageName == "index") {
if (WebSock.IsPost()) {
CUser *pUser = CZNC::Get().FindUser(WebSock.GetParam("network").Token(0, false, "/"));
if (!pUser) {
WebSock.GetSession()->AddError("User not found");
return true;
}
CIRCNetwork *pNetwork = pUser->FindNetwork(WebSock.GetParam("network").Token(1, false, "/"));
if (!pNetwork) {
WebSock.GetSession()->AddError("Network not found");
return true;
}
bool bToServer = WebSock.GetParam("send_to") == "server";
const CString sLine = WebSock.GetParam("line");
Tmpl["user"] = pUser->GetUserName();
Tmpl[bToServer ? "to_server" : "to_client"] = "true";
Tmpl["line"] = sLine;
if (bToServer) {
pNetwork->PutIRC(sLine);
} else {
pNetwork->PutUser(sLine);
}
WebSock.GetSession()->AddSuccess("Line sent");
}
const map<CString,CUser*>& msUsers = CZNC::Get().GetUserMap();
for (map<CString,CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); ++it) {
CTemplate& l = Tmpl.AddRow("UserLoop");
l["Username"] = (*it->second).GetUserName();
vector<CIRCNetwork*> vNetworks = (*it->second).GetNetworks();
for (vector<CIRCNetwork*>::const_iterator it2 = vNetworks.begin(); it2 != vNetworks.end(); ++it2) {
CTemplate& NetworkLoop = l.AddRow("NetworkLoop");
NetworkLoop["Username"] = (*it->second).GetUserName();
NetworkLoop["Network"] = (*it2)->GetName();
}
}
return true;
}
return false;
}
MODCONSTRUCTOR(CSendRaw_Mod) {
AddHelpCommand();
AddCommand("Client", static_cast<CModCommand::ModCmdFunc>(&CSendRaw_Mod::SendClient),
"[user] [network] [data to send]", "The data will be sent to the user's IRC client(s)");
AddCommand("Server", static_cast<CModCommand::ModCmdFunc>(&CSendRaw_Mod::SendServer),
"[user] [network] [data to send]", "The data will be sent to the IRC server the user is connected to");
AddCommand("Current", static_cast<CModCommand::ModCmdFunc>(&CSendRaw_Mod::CurrentClient),
"[data to send]", "The data will be sent to your current client");
}
};
template<> void TModInfo<CSendRaw_Mod>(CModInfo& Info) {
Info.SetWikiPage("send_raw");
}
USERMODULEDEFS(CSendRaw_Mod, "Lets you send some raw IRC lines as/to someone else")