Example #1
0
	void ReleaseCommand(const CString& sLine) {
		if (sLine.Token(1).empty()) {
			PutModule("Syntax: release <nickname>");
		} else {
			DoNickCommand("ReleaseCmd", sLine.Token(1));
		}
	}
Example #2
0
    bool FromString(const CString& sLine) {
        m_sUsername = sLine.Token(0, false, "\t");
        m_sHostmask = sLine.Token(1, false, "\t");
        sLine.Token(2, false, "\t").Split(" ", m_ssChans);

        return !m_sHostmask.empty();
    }
Example #3
0
    bool OnLoad(const CString& sArgs, CString& sMessage) override {
        CString sReasonArg;

        // Load AwayWait
        CString sFirstArg = sArgs.Token(0);
        if (sFirstArg.Equals("-notimer")) {
            SetAwayWait(0);
            sReasonArg = sArgs.Token(1, true);
        } else if (sFirstArg.Equals("-timer")) {
            SetAwayWait(sArgs.Token(1).ToUInt());
            sReasonArg = sArgs.Token(2, true);
        } else {
            CString sAwayWait = GetNV("awaywait");
            if (!sAwayWait.empty()) SetAwayWait(sAwayWait.ToUInt(), false);
            sReasonArg = sArgs;
        }

        // Load Reason
        if (!sReasonArg.empty()) {
            SetReason(sReasonArg);
        } else {
            CString sSavedReason = GetNV("reason");
            if (!sSavedReason.empty()) SetReason(sSavedReason, false);
        }

        // MinClients
        CString sMinClients = GetNV("minclients");
        if (!sMinClients.empty()) SetMinClients(sMinClients.ToUInt(), false);

        // Set away on load, required if loaded via webadmin
        if (GetNetwork()->IsIRCConnected() && MinClientsConnected())
            SetAway(false);

        return true;
    }
Example #4
0
	virtual void OnModCommand(const CString& sLine) {
		CString sCommand = sLine.Token(0).AsLower();
		CString tk2 = sLine.Token(1).AsLower(); 
      
/*
 *   DNS Resolution
 */
		if(sCommand=="dns"||sCommand=="resolve") {
			hostent * record = gethostbyname(tk2.c_str());
			if(record == NULL) {
				PutModule(tk2 + "%s is unavailable.");
			} else {
				in_addr * address = (in_addr * )record->h_addr;
				CString ip_address = CString(inet_ntoa(* address));
				PutModule(tk2 + " resolves to: " + ip_address + ".");
			}
		}
/*
 *   Help command (todo: implement token-based help)
 */
		else if (sCommand == "help") {
			PutModule("DNS: This module includes a DNS resolver. Usage: dns/resolve hostname Ex: dns localhost");
			PutModule("      message. Prefix defaults to 'ZNC Global Message: ', and can be changed by the arguments.");
//			PutModule("ToDo: allow this module to override znc's dns resolution to deny users access to specific servers (can this be done?")
//			PutModule("1.0 - initial version");
//			PutModule("2.0 - changed around resolve code to fix a crashing error when host doesnt resolve");
			PutModule("0.01 - changed version number to a different scheme");
		}
	}
Example #5
0
	void OnModCommand(const CString& sCmdLine) override
	{
		CString sCommand = sCmdLine.Token(0);
		CString sArgs    = sCmdLine.Token(1, true);

		if (sCommand.Equals("dumpbuff")) {
			// for testing purposes - hidden from help
			CString sFile;
			CString sName;
			if (DecryptBuffer(GetPath(sArgs), sFile, sName))
			{
				VCString vsLines;
				VCString::iterator it;

				sFile.Split("\n", vsLines);

				for (it = vsLines.begin(); it != vsLines.end(); ++it) {
					CString sLine(*it);
					sLine.Trim();
					PutModule("[" + sLine + "]");
				}
			}
			PutModule("//!-- EOF " + sArgs);
		} else {
			HandleCommand(sCmdLine);
		}
	}
Example #6
0
File: schat.cpp Project: clem16/znc
	virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage) override
	{
		if (sMessage.Equals("DCC SCHAT ", false, 10)) {
			// chat ip port
			unsigned long iIP = sMessage.Token(3).ToULong();
			unsigned short iPort = sMessage.Token(4).ToUShort();

			if (iIP > 0 && iPort > 0) {
				pair<u_long, u_short> pTmp;
				CString sMask;

				pTmp.first = iIP;
				pTmp.second = iPort;
				sMask = "(s)" + Nick.GetNick() + "!" + "(s)" +
					Nick.GetNick() + "@" + CUtils::GetIP(iIP);

				m_siiWaitingChats["(s)" + Nick.GetNick()] = pTmp;
				SendToUser(sMask, "*** Incoming DCC SCHAT, Accept ? (yes/no)");
				CRemMarkerJob *p = new CRemMarkerJob(this, 60, 1,
						"Remove (s)" + Nick.GetNick(),
						"Removes this nicks entry for waiting DCC.");
				p->SetNick("(s)" + Nick.GetNick());
				AddTimer(p);
				return(HALT);
			}
		}

		return(CONTINUE);
	}
Example #7
0
	void BootStrap(T *pTarget, const CString& sContent)
	{
		if (!pTarget->GetBuffer().IsEmpty())
			return; // in this case the module was probably reloaded

		VCString vsLines;
		VCString::iterator it;

		sContent.Split("\n", vsLines);

		for (it = vsLines.begin(); it != vsLines.end(); ++it) {
			CString sLine(*it);
			sLine.Trim();
			if (sLine[0] == '@' && it+1 != vsLines.end())
			{
				CString sTimestamp = sLine.Token(0);
				sTimestamp.TrimLeft("@");
				timeval ts;
				ts.tv_sec = sTimestamp.Token(0, false, ",").ToLongLong();
				ts.tv_usec = sTimestamp.Token(1, false, ",").ToLong();

				CString sFormat = sLine.Token(1, true);

				CString sText(*++it);
				sText.Trim();

				pTarget->AddBuffer(sFormat, sText, &ts);
			} else
			{
				// Old format, escape the line and use as is.
				pTarget->AddBuffer(_NAMEDFMT(sLine));
			}
		}
	}
Example #8
0
	virtual void OnModCommand(const CString& sLine) {
		const CString sUser = sLine.Token(0);
		const CString sDirection = sLine.Token(1);
		CUser *pUser = CZNC::Get().FindUser(sUser);

		if (!pUser) {
			PutModule("User not found");
			PutModule("The expected format is: <user> [<in|out>] <line to send>");
			PutModule("Out (default): The line will be sent to the user's IRC server");
			PutModule("In: The line will be sent to the user's IRC client");
			return;
		}

		if (!sDirection.CaseCmp("in")) {
			pUser->PutUser(sLine.Token(2, true));
		} else if (!sDirection.CaseCmp("out")) {
			pUser->PutIRC(sLine.Token(2, true));
		} else {
			/* The user did not supply a direction, let's send the line out.
			We do this to preserve backwards compatibility. */
			pUser->PutIRC(sLine.Token(1, true));
		}

		PutModule("done");
	}
Example #9
0
	virtual EModRet OnRaw(CString& sLine)
	{
		CString sCmd = sLine.Token(1).AsUpper();
		size_t i = 0;

		if (!m_pReplies)
			return CONTINUE;

		// Is this a "not enough arguments" error?
		if (sCmd == "461") {
			// :server 461 nick WHO :Not enough parameters
			CString sOrigCmd = sLine.Token(3);

			if (m_sLastRequest.Token(0).Equals(sOrigCmd)) {
				// This is the reply to the last request
				if (RouteReply(sLine, true))
					return HALTCORE;
				return CONTINUE;
			}
		}

		while (m_pReplies[i].szReply != NULL) {
			if (m_pReplies[i].szReply == sCmd) {
				if (RouteReply(sLine, m_pReplies[i].bLastResponse, sCmd == "353"))
					return HALTCORE;
				return CONTINUE;
			}
			i++;
		}

		// TODO HALTCORE is wrong, it should not be passed to
		// the clients, but the core itself should still handle it!

		return CONTINUE;
	}
Example #10
0
	virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
		VCString vsChans;
		sArgs.Split(" ", vsChans, false);

		for (VCString::const_iterator it = vsChans.begin(); it != vsChans.end(); ++it) {
			CString sAdd = *it;
			bool bNegated = sAdd.TrimPrefix("!");
			CString sChan = sAdd.Token(0);
			CString sHost = sAdd.Token(1, true);

			if (!Add(bNegated, sChan, sHost)) {
				PutModule("Unable to add [" + *it + "]");
			}
		}

		// Load our saved settings, ignore errors
		MCString::iterator it;
		for (it = BeginNV(); it != EndNV(); ++it) {
			CString sAdd = it->first;
			bool bNegated = sAdd.TrimPrefix("!");
			CString sChan = sAdd.Token(0);
			CString sHost = sAdd.Token(1, true);

			Add(bNegated, sChan, sHost);
		}

		return true;
	}
Example #11
0
	void GroupCommand(const CString& sLine) {
		if (sLine.Token(1).empty()) {
			PutModule("Syntax: group <nickname>");
		} else {
			DoNickCommand("GroupCmd", sLine.Token(1));
		}
	}
Example #12
0
 void OnMinClientsCommand(const CString& sLine) {
     if (sLine.Token(1).empty()) {
         PutModule(t_f("Current MinClients setting: {1}")(m_iMinClients));
     } else {
         SetMinClients(sLine.Token(1).ToUInt());
         PutModule(t_f("MinClients set to {1}")(m_iMinClients));
     }
 }
Example #13
0
	EModRet OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage)
	{
		if(sMessage.Token(0).Equals("ACTION"))
		{
			SendIRCMsgToSkype("", Channel.GetName(), Nick.GetNick() + " " + sMessage.Token(1, true));
		}
		return CONTINUE;
	}
Example #14
0
void CClient::StatusCTCP(const CString& sLine) {
    CString sCommand = sLine.Token(0);

    if (sCommand.Equals("PING")) {
        PutStatusNotice("\001PING " + sLine.Token(1, true) + "\001");
    } else if (sCommand.Equals("VERSION")) {
        PutStatusNotice("\001VERSION " + CZNC::GetTag() + "\001");
    }
}
Example #15
0
	virtual void OnModCommand(const CString& sCommand) {
		if (!GetUser()->IsAdmin()) {
			PutModule("Access denied");
			return;
		}

		CString sCmd = sCommand.Token(0);

		if (sCmd.Equals("target")) {
			CString sArg = sCommand.Token(1, true);
			CString sTarget;
			CString sMessage;
			LogMode mode;

			if (sArg.Equals("file")) {
				sTarget = "file";
				sMessage = "Now only logging to file";
				mode = LOG_TO_FILE;
			} else if (sArg.Equals("syslog")) {
				sTarget = "syslog";
				sMessage = "Now only logging to syslog";
				mode = LOG_TO_SYSLOG;
			} else if (sArg.Equals("both")) {
				sTarget = "both";
				sMessage = "Now logging to file and syslog";
				mode = LOG_TO_BOTH;
			} else {
				PutModule("Unknown target");
				return;
			}

			Log(sMessage);
			SetNV("target", sTarget);
			m_eLogMode = mode;
			PutModule(sMessage);
		} else if (sCmd.Equals("show")) {
			CString sTarget;

			switch (m_eLogMode)
			{
			case LOG_TO_FILE:
				sTarget = "file";
				break;
			case LOG_TO_SYSLOG:
				sTarget = "syslog";
				break;
			case LOG_TO_BOTH:
				sTarget = "both, file and syslog";
				break;
			}

			PutModule("Logging is enabled for " + sTarget);
			if (m_eLogMode != LOG_TO_SYSLOG)
				PutModule("Log file will be written to [" + m_sLogFile + "]");
		} else
			PutModule("Commands: show, target <file|syslog|both>");
	}
Example #16
0
	virtual EModRet OnUserRaw(CString& sLine)
	{
		CString sCmd = sLine.Token(0).AsUpper();

		if (!m_pNetwork->GetIRCSock())
			return CONTINUE;

		if (sCmd.Equals("MODE")) {
			// Check if this is a mode request that needs to be handled

			// If there are arguments to a mode change,
			// we must not route it.
			if (!sLine.Token(3, true).empty())
				return CONTINUE;

			// Grab the mode change parameter
			CString sMode = sLine.Token(2);

			// If this is a channel mode request, znc core replies to it
			if (sMode.empty())
				return CONTINUE;

			// Check if this is a mode change or a specific
			// mode request (the later needs to be routed).
			sMode.TrimPrefix("+");
			if (sMode.length() != 1)
				return CONTINUE;

			// Now just check if it's one of the supported modes
			switch (sMode[0]) {
			case 'I':
			case 'b':
			case 'e':
				break;
			default:
				return CONTINUE;
			}

			// Ok, this looks like we should route it.
			// Fall through to the next loop
		}

		for (size_t i = 0; vRouteReplies[i].szRequest != NULL; i++) {
			if (vRouteReplies[i].szRequest == sCmd) {
				struct queued_req req = {
					sLine, vRouteReplies[i].vReplies
				};
				m_vsPending[m_pClient].push_back(req);
				SendRequest();

				return HALTCORE;
			}
		}

		return CONTINUE;
	}
Example #17
0
void CIRCSock::ParseISupport(const CMessage& Message) {
    const VCString vsParams = Message.GetParams();

    for (size_t i = 1; i < vsParams.size() - 1; ++i) {
        const CString& sParam = vsParams[i];
        CString sName = sParam.Token(0, false, "=");
        CString sValue = sParam.Token(1, true, "=");

        if (0 < sName.length() && ':' == sName[0]) {
            break;
        }

        m_mISupport[sName] = sValue;

        if (sName.Equals("PREFIX")) {
            CString sPrefixes = sValue.Token(1, false, ")");
            CString sPermModes = sValue.Token(0, false, ")");
            sPermModes.TrimLeft("(");

            if (!sPrefixes.empty() && sPermModes.size() == sPrefixes.size()) {
                m_sPerms = sPrefixes;
                m_sPermModes = sPermModes;
            }
        } else if (sName.Equals("CHANTYPES")) {
            m_pNetwork->SetChanPrefixes(sValue);
        } else if (sName.Equals("NICKLEN")) {
            unsigned int uMax = sValue.ToUInt();

            if (uMax) {
                m_uMaxNickLen = uMax;
            }
        } else if (sName.Equals("CHANMODES")) {
            if (!sValue.empty()) {
                m_mueChanModes.clear();

                for (unsigned int a = 0; a < 4; a++) {
                    CString sModes = sValue.Token(a, false, ",");

                    for (unsigned int b = 0; b < sModes.size(); b++) {
                        m_mueChanModes[sModes[b]] = (EChanModeArgs) a;
                    }
                }
            }
        } else if (sName.Equals("NAMESX")) {
            if (m_bNamesx)
                continue;
            m_bNamesx = true;
            PutIRC("PROTOCTL NAMESX");
        } else if (sName.Equals("UHNAMES")) {
            if (m_bUHNames)
                continue;
            m_bUHNames = true;
            PutIRC("PROTOCTL UHNAMES");
        }
    }
}
Example #18
0
    void ModCommand(const CString &sLine) {
        CString sKey(sLine.Token(1));
        CString sValue(sLine.Token(2, true));

        if (AddNote(sKey, sValue)) {
            PutModule("Set note for [" + sKey + "]");
        } else {
            PutModule("Unable to add note [" + sKey + "]");
        }
    }
Example #19
0
    void RequireAuthCommand(const CString& sLine) {
        if (!sLine.Token(1).empty()) {
            SetNV(NV_REQUIRE_AUTH, sLine.Token(1));
        }

        if (GetNV(NV_REQUIRE_AUTH).ToBool()) {
            PutModule("We require SASL negotiation to connect");
        } else {
            PutModule("We will connect even if SASL fails");
        }
    }
Example #20
0
	void HandleDel(const CString& sLine) {
		CString sMsg  = sLine.Token(1, true);
		bool bNegated = sMsg.TrimPrefix("!");
		CString sChan = sMsg.Token(0);
		CString sHost = sMsg.Token(1);

		if (Del(bNegated, sChan, sHost)) {
			PutModule("Removed " + sChan + " from list");
		} else {
			PutModule("Usage: Del [!]<#chan> <host>");
		}
	}
Example #21
0
    void AddNoteCommand(const CString &sLine) {
        CString sKey(sLine.Token(1));
        CString sValue(sLine.Token(2, true));

        if (!GetNV(sKey).empty()) {
            PutModule("That note already exists.  Use MOD <key> <note> to overwrite.");
        } else if (AddNote(sKey, sValue)) {
            PutModule("Added note [" + sKey + "]");
        } else {
            PutModule("Unable to add note [" + sKey + "]");
        }
    }
Example #22
0
	virtual EModRet OnRaw(CString &sLine) {
		const CString sCmd = sLine.Token(1);

		if (sCmd == "375" /* begin of MOTD */
				|| sCmd == "372" /* MOTD */)
			return HALT;
		if (sCmd == "376" /* End of MOTD */) {
			sLine = sLine.Token(0) + " 422 " +
				sLine.Token(2) + " :MOTD blocked by ZNC";
		}
		return CONTINUE;
	}
Example #23
0
File: Chan.cpp Project: BtbN/znc
CChan::CChan(const CString& sName, CIRCNetwork* pNetwork, bool bInConfig,
             CConfig* pConfig)
    : m_bDetached(false),
      m_bIsOn(false),
      m_bAutoClearChanBuffer(pNetwork->GetUser()->AutoClearChanBuffer()),
      m_bInConfig(bInConfig),
      m_bDisabled(false),
      m_bHasBufferCountSet(false),
      m_bHasAutoClearChanBufferSet(false),
      m_sName(sName.Token(0)),
      m_sKey(sName.Token(1)),
      m_sTopic(""),
      m_sTopicOwner(""),
      m_ulTopicDate(0),
      m_ulCreationDate(0),
      m_pNetwork(pNetwork),
      m_Nick(),
      m_uJoinTries(0),
      m_sDefaultModes(""),
      m_msNicks(),
      m_Buffer(),
      m_bModeKnown(false),
      m_mcsModes() {
    if (!m_pNetwork->IsChan(m_sName)) {
        m_sName = "#" + m_sName;
    }

    m_Nick.SetNetwork(m_pNetwork);
    m_Buffer.SetLineCount(m_pNetwork->GetUser()->GetChanBufferSize(), true);

    if (pConfig) {
        CString sValue;
        if (pConfig->FindStringEntry("buffer", sValue))
            SetBufferCount(sValue.ToUInt(), true);
        if (pConfig->FindStringEntry("autoclearchanbuffer", sValue))
            SetAutoClearChanBuffer(sValue.ToBool());
        if (pConfig->FindStringEntry("keepbuffer", sValue))
            // XXX Compatibility crap, added in 0.207
            SetAutoClearChanBuffer(!sValue.ToBool());
        if (pConfig->FindStringEntry("detached", sValue))
            SetDetached(sValue.ToBool());
        if (pConfig->FindStringEntry("disabled", sValue))
            if (sValue.ToBool()) Disable();
        if (pConfig->FindStringEntry("autocycle", sValue))
            if (sValue.Equals("true"))
                CUtils::PrintError(
                    "WARNING: AutoCycle has been removed, instead try -> "
                    "LoadModule = autocycle " +
                    sName);
        if (pConfig->FindStringEntry("key", sValue)) SetKey(sValue);
        if (pConfig->FindStringEntry("modes", sValue)) SetDefaultModes(sValue);
    }
}
Example #24
0
	virtual void OnModCommand(const CString& sCommand) {
		CString sCmd = sCommand.Token(0);

		if (sCmd.Equals("DELKEY")) {
			CString sTarget = sCommand.Token(1);

			if (!sTarget.empty()) {
				if (DelNV(sTarget.AsLower())) {
					PutModule("Target [" + sTarget + "] deleted");
				} else {
					PutModule("Target [" + sTarget + "] not found");
				}
			} else {
				PutModule("Usage DelKey <#chan|Nick>");
			}
		} else if (sCmd.Equals("SETKEY")) {
			CString sTarget = sCommand.Token(1);
			CString sKey = sCommand.Token(2, true);

			// Strip "cbc:" from beginning of string incase someone pastes directly from mircryption
			sKey.TrimPrefix("cbc:");

			if (!sKey.empty()) {
				SetNV(sTarget.AsLower(), sKey);
				PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]");
			} else {
				PutModule("Usage: SetKey <#chan|Nick> <Key>");
			}
		} else if (sCmd.Equals("LISTKEYS")) {
			if (BeginNV() == EndNV()) {
				PutModule("You have no encryption keys set.");
			} else {
				CTable Table;
				Table.AddColumn("Target");
				Table.AddColumn("Key");

				for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
					Table.AddRow();
					Table.SetCell("Target", it->first);
					Table.SetCell("Key", it->second);
				}

				PutModule(Table);
			}
		} else if (sCmd.Equals("HELP")) {
			PutModule("Try: SetKey, DelKey, ListKeys");
		} else {
			PutModule("Unknown command, try 'Help'");
		}
	}
Example #25
0
	virtual void OnModCommand(const CString& sCommand) {
		const CString& sCmd = sCommand.Token(0);

		if (sCmd.Equals("SHOW")) {
			PutModule("Current reply is: " + GetNV("Reply")
					+ " (" + GetReply() + ")");
		} else if (sCmd.Equals("SET")) {
			SetReply(sCommand.Token(1, true));
			PutModule("New reply set");
		} else {
			PutModule("Available commands are:");
			PutModule("Show        - Displays the current query reply");
			PutModule("Set <reply> - Sets a new reply");
		}
	}
Example #26
0
    void Set(const CString& sLine) {
        if (sLine.Token(1).empty()) {
            CString sUsername = GetNV("username");
            CString sPassword = GetNV("password");

            PutModule("Username is currently " + (sUsername.empty() ? "not set" : "set to '" + sUsername + "'") +
                      ", a password was " + (sPassword.empty() ? "not " : "") + "supplied.");
            return;
        }

        SetNV("username", sLine.Token(1));
        SetNV("password", sLine.Token(2));

        PutModule("Username has been set to [" + GetNV("username") + "]");
        PutModule("Password has been set to [" + GetNV("password") + "]");
    }
Example #27
0
	void OnReplayCommand(const CString& sCmdLine)
	{
		CString sArgs = sCmdLine.Token(1, true);

		Replay(sArgs);
		PutModule("Replayed " + sArgs);
	}
Example #28
0
	bool BootStrap(CChan *pChan)
	{
		CString sFile;
		if (DecryptChannel(pChan->GetName(), sFile))
		{
			if (!pChan->GetBuffer().IsEmpty())
				return(true); // reloaded a module probably in this case, so just verify we can decrypt the file

			VCString vsLines;
			VCString::iterator it;

			sFile.Split("\n", vsLines);

			for (it = vsLines.begin(); it != vsLines.end(); ++it) {
				CString sLine(*it);
				sLine.Trim();
				if (sLine[0] == '@' && it+1 != vsLines.end())
				{
					CString sTimestamp = sLine.Token(0);
					sTimestamp.TrimLeft("@");
					timeval ts;
					ts.tv_sec = sTimestamp.Token(0, false, ",").ToLongLong();
					ts.tv_usec = sTimestamp.Token(1, false, ",").ToLong();

					CString sFormat = sLine.Token(1, true);

					CString sText(*++it);
					sText.Trim();

					pChan->AddBuffer(sFormat, sText, &ts);
				} else
				{
					// Old format, escape the line and use as is.
					pChan->AddBuffer(_NAMEDFMT(sLine));
				}
			}
		} else
		{
			m_sPassword = "";
			CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt [" + pChan->GetName() + "]");
			return(false);
		}

		return(true);
	}
Example #29
0
    void DelCommand(const CString &sLine) {
        CString sKey(sLine.Token(1));

        if (DelNote(sKey)) {
            PutModule("Deleted note [" + sKey + "]");
        } else {
            PutModule("Unable to delete note [" + sKey + "]");
        }
    }
Example #30
0
    void GetCommand(const CString &sLine) {
        CString sNote = GetNV(sLine.Token(1, true));

        if (sNote.empty()) {
            PutModule("This note doesn't exist.");
        } else {
            PutModule(sNote);
        }
    }