Ejemplo n.º 1
0
Archivo: alias.cpp Proyecto: 54lman/znc
	void ClearCommand(const CString& sLine)
	{
		CString name = sLine.Token(1, false, " ");
		CAlias clear_alias;
		if (CAlias::AliasGet(clear_alias, this, name))
		{
			clear_alias.AliasCmds().clear();
			clear_alias.Commit();
			PutModule("Modified alias.");
		}
		else PutModule("Alias does not exist.");
	}
Ejemplo n.º 2
0
	void Swap(const CString& sCommand) {
		u_int iNumA = sCommand.Token(1).ToUInt();
		u_int iNumB = sCommand.Token(2).ToUInt();

		if (iNumA > m_vPerform.size() || iNumA <= 0 || iNumB > m_vPerform.size() || iNumB <= 0) {
			PutModule("Illegal # Requested");
		} else {
			std::iter_swap(m_vPerform.begin() + (iNumA - 1), m_vPerform.begin() + (iNumB - 1));
			PutModule("Commands Swapped.");
			Save();
		}
	}
Ejemplo n.º 3
0
	virtual void OnModCommand(const CString& sCommand) {
		CString sResult;
		VCString vsResult;
		CString sCmd = sCommand;

		if (sCmd.Token(0).CaseCmp(".tcl") == 0)
			sCmd = sCmd.Token(1,true);

		if (sCmd.Left(1).CaseCmp(".") == 0)
			sCmd = "Binds::ProcessDcc - - {" + sCmd + "}";

		Tcl_Eval(interp, sCmd.c_str());

		sResult = CString(Tcl_GetStringResult(interp));
		if (!sResult.empty()) {
			sResult.Split("\n", vsResult);
			unsigned int a = 0;
			for (a = 0; a < vsResult.size(); a++)
				PutModule(vsResult[a].TrimRight_n());
		}
	}
Ejemplo n.º 4
0
    void HandleAdd(const CString& sLine) {
        CString sMsg = sLine.Token(1, true);
        bool bHelp = false;
        bool bNegated = sMsg.TrimPrefix("!");
        CString sChan = sMsg.Token(0);
        CString sSearch = sMsg.Token(1);
        CString sHost = sMsg.Token(2);

        if (sChan.empty()) {
            bHelp = true;
        } else if (Add(bNegated, sChan, sSearch, sHost)) {
            PutModule("Added to list");
        } else {
            PutModule(sLine.Token(1, true) + " is already added");
            bHelp = true;
        }
        if (bHelp) {
            PutModule("Usage: Add [!]<#chan> <search> <host>");
            PutModule("Wildcards are allowed");
        }
    }
Ejemplo n.º 5
0
	void Del(const CString& sCommand) {
		u_int iNum = sCommand.Token(1, true).ToUInt();

		if (iNum > m_vPerform.size() || iNum <= 0) {
			PutModule("Illegal # Requested");
			return;
		} else {
			m_vPerform.erase(m_vPerform.begin() + iNum - 1);
			PutModule("Command Erased.");
		}
		Save();
	}
Ejemplo n.º 6
0
	void OnDelChansCommand(const CString& sLine) {
		CString sUser = sLine.Token(1);
		CString sChans = sLine.Token(2, true);

		if (sChans.empty()) {
			PutModule("Usage: DelChans <user> <channel> [channel] ...");
			return;
		}

		CAutoVoiceUser* pUser = FindUser(sUser);

		if (!pUser) {
			PutModule("No such user");
			return;
		}

		pUser->DelChans(sChans);
		PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]");

		SetNV(pUser->GetUsername(), pUser->ToString());
	}
Ejemplo n.º 7
0
bool CIRCNetwork::AddServer(const CString& sName) {
    if (sName.empty()) {
        return false;
    }

    bool bSSL = false;
    CString sLine = sName;
    sLine.Trim();

    CString sHost = sLine.Token(0);
    CString sPort = sLine.Token(1);

    if (sPort.TrimPrefix("+")) {
        bSSL = true;
    }

    unsigned short uPort = sPort.ToUShort();
    CString sPass = sLine.Token(2, true);

    return AddServer(sHost, uPort, sPass, bSSL);
}
Ejemplo n.º 8
0
	void Add(const CString& sCommand) {
		CString sPerf = sCommand.Token(1, true);

		if (sPerf.empty()) {
			PutModule("Usage: add <command>");
			return;
		}

		m_vPerform.push_back(ParsePerform(sPerf));
		PutModule("Added!");
		Save();
	}
Ejemplo n.º 9
0
Archivo: log.cpp Proyecto: Adam-/znc
void CLogMod::SetRulesCmd(const CString& sLine) {
    VCString vsRules = SplitRules(sLine.Token(1, true));

    if (vsRules.empty()) {
        PutModule("Usage: SetRules <rules>");
        PutModule("Wildcards are allowed");
    } else {
        SetRules(vsRules);
        SetNV("rules", JoinRules(","));
        ListRulesCmd();
    }
}
Ejemplo n.º 10
0
	void OnMethodCommand(const CString& sCommand) {
		const CString& sArg = sCommand.Token(1, true).AsLower();

		if (sArg != "notice" && sArg != "message" && sArg != "off") {
			PutModule("Usage: Method <message|notice|off>");
			return;
		}

		m_sMethod = sArg;
		SaveSettings();
		PutModule("Saved.");
	}
Ejemplo n.º 11
0
	void OnDisconnectCommand(const CString& sCommand) {
		const CString& sArg = sCommand.Token(1, true).AsLower();

		if (sArg.empty()) {
			PutModule("Usage: OnDisconnect <on|off>");
			return;
		}

		m_bOnDisconnect = sArg.ToBool();
		SaveSettings();
		PutModule("Saved.");
	}
Ejemplo n.º 12
0
	void OnNewOnlyCommand(const CString& sCommand) {
		const CString& sArg = sCommand.Token(1, true).AsLower();

		if (sArg.empty()) {
			PutModule("Usage: NewOnly <on|off>");
			return;
		}

		m_bNewOnly = sArg.ToBool();
		SaveSettings();
		PutModule("Saved.");
	}
Ejemplo n.º 13
0
	virtual bool OnLoad(const CString& sArgs, CString& sMessage) override {
		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 sSearch = sAdd.Token(1);
			CString sHost = sAdd.Token(2, true);

			if (!Add(bNegated, sChan, sSearch, 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 sSearch = sAdd.Token(1);
			CString sHost = sAdd.Token(2, true);

			Add(bNegated, sChan, sSearch, sHost);
		}

		return true;
	}
Ejemplo n.º 14
0
	void GetChan(const CString& sLine) {
		const CString var  = sLine.Token(1).AsLower();
		CString username   = sLine.Token(2);
		CString chan = sLine.Token(3, true);

		if (var.empty()) {
			PutModule("Usage: getchan <variable> [username] <chan>");
			return;
		}
		if (chan.empty()) {
			chan = username;
			username = "";
		}
		if (username.empty()) {
			username = m_pUser->GetUserName();
		}

		CUser* user = GetUser(username);
		if (!user)
			return;

		CChan* pChan = user->FindChan(chan);
		if (!pChan) {
			PutModule("Error: Channel not found: " + chan);
			return;
		}

		if (var == "defmodes")
			PutModule("DefModes = " + pChan->GetDefaultModes());
		else if (var == "buffer")
			PutModule("Buffer = " + CString(pChan->GetBufferCount()));
		else if (var == "inconfig")
			PutModule("InConfig = " + pChan->InConfig());
		else if (var == "keepbuffer")
			PutModule("KeepBuffer = " + pChan->KeepBuffer());
		else if (var == "detached")
			PutModule("Detached = " + pChan->IsDetached());
		else
			PutModule("Error: Unknown variable");
	}
Ejemplo n.º 15
0
void CIdentServerMod::OnModCommand(const CString& sLine)
{
	CString sCommand = sLine.Token(0);

	if(sCommand.Equals("HELP"))
	{
		CTable Table;
		Table.AddColumn("Command");
		Table.AddColumn("Description");

		Table.AddRow();
		Table.SetCell("Command", "Status");
		Table.SetCell("Description", "Displays status information about IdentServer");

		PutModule(Table);
		return;
	}
	else if(sCommand.Equals("STATUS"))
	{
		if(m_identServer)
		{
			PutModule("IdentServer is listening on: " + m_identServer->GetLocalIP() + ":" + CString(m_serverPort));

			if(m_pUser->IsAdmin())
			{
				PutModule("List of active users/networks:");

				for(CIRCNetwork* pNetwork : m_identServer->GetActiveUsers())
				{
					PutModule("* " + pNetwork->GetUser()->GetCleanUserName() + "/" + pNetwork->GetName());
				}
			}
		}
		else
		{
			if(m_listenFailed)
			{
				PutModule("WARNING: Opening the listening socket failed!");
			}
			PutModule("IdentServer isn't listening.");
		}
		if(m_pUser->IsAdmin())
		{
			PutModule("Last IDENT request: " + m_sLastRequest);
			PutModule("Last IDENT reply: " + m_sLastReply);
		}
	}
	else
	{
		PutModule("Unknown command [" + sCommand + "] try 'Help'");
	}
}
Ejemplo n.º 16
0
    EModRet OnRaw(CString& sLine) override {
        const CString sCmd = sLine.Token(1);

        if ((sCmd == "375" /* begin of MOTD */ || sCmd == "372" /* MOTD */) &&
            !ShouldTemporarilyAcceptMotd())
            return HALT;

        if (sCmd == "376" /* End of MOTD */) {
            if (!ShouldTemporarilyAcceptMotd()) {
                sLine = sLine.Token(0) + " 422 " + sLine.Token(2) + " :" +
                        t_s("MOTD blocked by ZNC");
            }
            StopTemporarilyAcceptingMotd();
        }

        if (sCmd == "422") {
            // Server has no MOTD
            StopTemporarilyAcceptingMotd();
        }

        return CONTINUE;
    }
Ejemplo n.º 17
0
	void CreateUserCommand(const CString &sLine) {
		CString sCreate = sLine.Token(1);

		if (!sCreate.empty()) {
			SetNV("CreateUser", sCreate);
		}

		if (CreateUser()) {
			PutModule("We will create users on their first login");
		} else {
			PutModule("We will not create users on their first login");
		}
	}
Ejemplo n.º 18
0
bool CUser::AddServer(const CString& sName) {
	if (sName.empty()) {
		return false;
	}

	bool bSSL = false;
	CString sLine = sName;
	sLine.Trim();

	CString sHost = sLine.Token(0);
	CString sPort = sLine.Token(1);

	if (sPort.Left(1) == "+") {
		bSSL = true;
		sPort.LeftChomp();
	}

	unsigned short uPort = sPort.ToUShort();
	CString sPass = sLine.Token(2, true);

	return AddServer(sHost, uPort, sPass, bSSL);
}
Ejemplo n.º 19
0
	virtual void OnModCommand(const CString& sCommand) {
		const CString sCmd = sCommand.Token(0);
		const CString sArgs = sCommand.Token(1, true);

		if (sCmd.Equals("silent")) {
			if (sArgs.Equals("yes")) {
				SetNV("silent_timeouts", "yes");
				PutModule("Disabled timeout messages");
			} else if (sArgs.Equals("no")) {
				DelNV("silent_timeouts");
				PutModule("Enabled timeout messages");
			} else if (sArgs.empty()) {
				if (GetNV("silent_timeouts") == "yes")
					PutModule("Timeout messages are disabled");
				else
					PutModule("Timeout message are enabled");
			} else
				PutModule("Invalid argument");
		} else {
			PutModule("Available commands: silent [yes/no], silent");
		}
	}
Ejemplo n.º 20
0
	virtual void OnModCommand(const CString& sCmdLine)
	{
		CString sCommand = sCmdLine.Token(0);
		CString sArgs    = sCmdLine.Token(1, true);

		if (sCommand.Equals("setpass"))
		{
			PutModule("Password set to [" + sArgs + "]");
			m_sPassword = CBlowfish::MD5(sArgs);

		} else if (sCommand.Equals("dumpbuff"))
		{
			CString sFile;
			if (DecryptChannel(sArgs, sFile))
			{
				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 if (sCommand.Equals("replay"))
		{
			Replay(sArgs);
			PutModule("Replayed " + sArgs);

		} else if (sCommand.Equals("save"))
		{
			SaveBufferToDisk();
			PutModule("Done.");
		} else
			PutModule("Unknown command [" + sCommand + "]");
	}
Ejemplo n.º 21
0
	void CloneUserCommand(const CString &sLine) {
		CString sUsername = sLine.Token(1);

		if (!sUsername.empty()) {
			SetNV("CloneUser", sUsername);
		}

		if (ShouldCloneUser()) {
			PutModule("We will clone [" + CloneUser() + "]");
		} else {
			PutModule("We will not clone a user");
		}
	}
Ejemplo n.º 22
0
    void SilentCommand(const CString& sLine) {
        const CString sArg = sLine.Token(1, true);

        if (!sArg.empty()) {
            SetNV("silent", CString(sArg.ToBool()));
        }

        if (GetNV("silent").ToBool()) {
            PutModule(t_s("Module messages are disabled"));
        } else {
            PutModule(t_s("Module messages are enabled"));
        }
    }
Ejemplo n.º 23
0
    void LinesCommand(const CString& sLine) {
        const CString sArg = sLine.Token(1, true);

        if (sArg.empty()) {
            PutModule(t_f("Lines limit is {1}")(m_iThresholdMsgs));
        } else {
            m_iThresholdMsgs = sArg.ToUInt();
            if (m_iThresholdMsgs == 0) m_iThresholdMsgs = 2;

            PutModule(t_f("Set lines limit to {1}")(m_iThresholdMsgs));
            Save();
        }
    }
Ejemplo n.º 24
0
bool CModule::HandleCommand(const CString& sLine) {
    const CString& sCmd = sLine.Token(0);
    const CModCommand* pCmd = FindCommand(sCmd);

    if (pCmd) {
        pCmd->Call(this, sLine);
        return true;
    }

    OnUnknownModCommand(sLine);

    return false;
}
Ejemplo n.º 25
0
    EModRet OnUserRaw(CString& sLine) override {
        // We dont care if we are not connected to IRC
        if (!GetNetwork()->IsIRCConnected()) return CONTINUE;

        // We are trying to get the config nick and this is a /nick?
        if (!m_pTimer || !sLine.Token(0).Equals("NICK")) return CONTINUE;

        // Is the nick change for the nick we are trying to get?
        CString sNick = sLine.Token(1);

        // Don't even think of using spaces in your nick!
        if (sNick.Left(1) == ":") sNick.LeftChomp();

        if (!sNick.Equals(GetNick())) return CONTINUE;

        // Indeed trying to change to this nick, generate a 433 for it.
        // This way we can *always* block incoming 433s from the server.
        PutUser(":" + GetNetwork()->GetIRCServer() + " 433 " +
                GetNetwork()->GetIRCNick().GetNick() + " " + sNick +
                " :ZNC is already trying to get this nickname");
        return CONTINUE;
    }
Ejemplo n.º 26
0
	virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
		if (sArgs.Trim_n().empty()) {
			return true; // use defaults
		}

		m_sServer = sArgs.Token(0);
		CString sPort = sArgs.Token(1);
		m_sUserFormat = sArgs.Token(2);

		if (sPort.Left(1) == "+") {
			m_bSSL = true;
			sPort.LeftChomp();
		}

		unsigned short uPort = sPort.ToUShort();

		if (uPort) {
			m_uPort = uPort;
		}

		return true;
	}
Ejemplo n.º 27
0
    // Unblocks a user from the blocked list.
    void OnUnblockCommand(const CString& sCommand) {
        CString sUser = sCommand.Token(1, true);

        if (sUser.empty()) {
            PutModule("Usage: Unblock <user>");
            return;
        }

        if (DelNV(sUser))
            PutModule("Unblocked [" + sUser + "]");
        else
            PutModule("This user is not blocked");
    }
Ejemplo n.º 28
0
	void OnDelKeyCommand(const CString& sCommand) {
		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>");
		}
	}
Ejemplo n.º 29
0
 void AddCmd(const CString& sCommand) {
     CString sPattern = sCommand.Token(1);
     
     if (IsValid(sPattern)) {
         if (Add(sPattern)) {
             PutModule("Pattern added");
         } else {
             PutModule("Pattern already exists");
         }
     } else {
         PutModule("Pattern has errors");
     }
 }
Ejemplo n.º 30
0
	void HandleIgnoreCommand(const CString& sLine) {
		CString sHostmask = sLine.Token(1);
		CString sType = sLine.Token(2);

		if (sType.empty()) {
			sType = "all";
		} else if (sType.Equals("*")) {
			sType = "all";
		}

		if (!(sType.Equals("all") || sType.Equals("privmsg") || sType.Equals("notice") || sType.Equals("ctcp"))) {
			PutModule("Unknown type");
			return;
		}

		CIgnore Ignore(sHostmask, sType);
		m_vIgnores.push_back(Ignore);

		Save();

		PutModule("Ignore added (" + Ignore.GetHostmask() + ")");
	}