diff --git a/UserSock.cpp b/UserSock.cpp index 7e5756a4..2e275336 100644 --- a/UserSock.cpp +++ b/UserSock.cpp @@ -579,6 +579,33 @@ void CUserSock::UserCommand(const CString& sLine) { } } else if (sCommand.CaseCmp("VERSION") == 0) { PutStatus(CZNC::GetTag()); + } else if (sCommand.CaseCmp("MOTD") == 0) { + if (!SendMotd()) { + PutStatus("There is no MOTD set."); + } + } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SaveConfig") == 0) { + CZNC::Get().WriteConfig(); + } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SetMOTD") == 0) { + CString sMessage = sLine.Token(1, true); + + if (sMessage.empty()) { + PutStatus("Usage: SetMOTD "); + } else { + CZNC::Get().SetMotd(sMessage); + PutStatus("MOTD set to [" + sMessage + "]"); + } + } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("AddMOTD") == 0) { + CString sMessage = sLine.Token(1, true); + + if (sMessage.empty()) { + PutStatus("Usage: AddMOTD "); + } else { + CZNC::Get().AddMotd(sMessage); + PutStatus("Added [" + sMessage + "] to MOTD"); + } + } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("ClearMOTD") == 0) { + CZNC::Get().ClearMotd(); + PutStatus("Cleared MOTD"); } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("BROADCAST") == 0) { CZNC::Get().Broadcast(sLine.Token(1, true)); } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SHUTDOWN") == 0) { @@ -995,6 +1022,20 @@ void CUserSock::UserCommand(const CString& sLine) { } } +bool CUserSock::SendMotd() { + const VCString& vsMotd = CZNC::Get().GetMotd(); + + if (!vsMotd.size()) { + return false; + } + + for (unsigned int a = 0; a < vsMotd.size(); a++) { + PutStatusNotice(vsMotd[a]); + } + + return true; +} + void CUserSock::HelpUser() { CTable Table; Table.AddColumn("Command"); @@ -1017,14 +1058,18 @@ void CUserSock::HelpUser() { if (m_pUser) { if (!m_pUser->DenyLoadMod()) { - Table.AddRow(); Table.SetCell("Command", "LoadMod"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Load a module"); - Table.AddRow(); Table.SetCell("Command", "UnloadMod"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Unload a module"); - Table.AddRow(); Table.SetCell("Command", "ReloadMod"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Reload a module"); + Table.AddRow(); Table.SetCell("Command", "LoadMod"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Load a module"); + Table.AddRow(); Table.SetCell("Command", "UnloadMod"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Unload a module"); + Table.AddRow(); Table.SetCell("Command", "ReloadMod"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Reload a module"); } if (m_pUser->IsAdmin()) { - Table.AddRow(); Table.SetCell("Command", "Broadcast"); Table.SetCell("Arguments", "[message]"); Table.SetCell("Description", "Broadcast a message to all users"); - Table.AddRow(); Table.SetCell("Command", "Shutdown"); Table.SetCell("Arguments", "[message]"); Table.SetCell("Description", "Shutdown znc completely"); + Table.AddRow(); Table.SetCell("Command", "SaveConfig"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Save the current settings to disk"); + Table.AddRow(); Table.SetCell("Command", "SetMOTD"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Set the message of the day"); + Table.AddRow(); Table.SetCell("Command", "AddMOTD"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Append to MOTD"); + Table.AddRow(); Table.SetCell("Command", "ClearMOTD"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Clear the MOTD"); + Table.AddRow(); Table.SetCell("Command", "Broadcast"); Table.SetCell("Arguments", "[message]"); Table.SetCell("Description", "Broadcast a message to all users"); + Table.AddRow(); Table.SetCell("Command", "Shutdown"); Table.SetCell("Arguments", "[message]"); Table.SetCell("Description", "Shutdown znc completely"); } } @@ -1073,6 +1118,8 @@ void CUserSock::AuthUser() { m_pUser->UserConnected(this); } + SendMotd(); + CZNC::Get().GetModules().SetUserSock(this); VOIDMODULECALL(OnUserAttached()); CZNC::Get().GetModules().SetUserSock(NULL); diff --git a/UserSock.h b/UserSock.h index e89895d0..a131b153 100644 --- a/UserSock.h +++ b/UserSock.h @@ -49,6 +49,7 @@ public: void PutModNotice(const CString& sModule, const CString& sLine); virtual void ReadLine(const CString& sData); + bool SendMotd(); void HelpUser(); void AuthUser(); virtual void Connected(); diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index 7b8cbebe..ca81c1bd 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -402,13 +402,18 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) { if (!GetParam("submitted").ToUInt()) { sPageRet = Header("Settings"); - CString sVHosts; + CString sVHosts, sMotd; const VCString& vsVHosts = CZNC::Get().GetVHosts(); for (unsigned int a = 0; a < vsVHosts.size(); a++) { sVHosts += vsVHosts[a] + "\r\n"; } + const VCString& vsMotd = CZNC::Get().GetMotd(); + for (unsigned int b = 0; b < vsMotd.size(); b++) { + sMotd += vsMotd[b] + "\r\n"; + } + sPageRet += "
\r\n" "\r\n" "
Global Settings
\r\n" @@ -421,6 +426,9 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) { "
ISpoofFormat:
\r\n" "
\r\n" + "
MOTD:
\r\n" + "
\r\n" + "
VHosts:
\r\n" "
\r\n" @@ -443,7 +451,6 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) { } sPageRet += "


\r\n" - "


\r\n" "\r\n" "
\r\n"; @@ -457,10 +464,17 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) { sArg = GetParam("ispoofformat"); CZNC::Get().SetISpoofFormat(sArg); //sArg = GetParam(""); if (!sArg.empty()) { CZNC::Get().Set(sArg); } - VCString vsArgs = GetParam("vhosts").Split("\n"); - CZNC::Get().ClearVHosts(); + VCString vsArgs = GetParam("motd").Split("\n"); + CZNC::Get().ClearMotd(); unsigned int a = 0; + for (a = 0; a < vsArgs.size(); a++) { + CZNC::Get().AddMotd(vsArgs[a].TrimRight_n()); + } + + vsArgs = GetParam("vhosts").Split("\n"); + CZNC::Get().ClearVHosts(); + for (a = 0; a < vsArgs.size(); a++) { CZNC::Get().AddVHost(vsArgs[a].Trim_n()); } diff --git a/znc.cpp b/znc.cpp index fe3e8f6c..acf761dc 100644 --- a/znc.cpp +++ b/znc.cpp @@ -347,6 +347,10 @@ bool CZNC::WriteConfig() { if (!m_sPidFile.empty()) { File.Write("PidFile = " + m_sPidFile + "\r\n"); } if (!m_sStatusPrefix.empty()) { File.Write("StatusPrefix = " + m_sStatusPrefix + "\r\n"); } + for (unsigned int m = 0; m < m_vsMotd.size(); m++) { + File.Write("Motd = " + m_vsMotd[m] + "\r\n"); + } + for (unsigned int v = 0; v < m_vsVHosts.size(); v++) { File.Write("VHost = " + m_vsVHosts[v] + "\r\n"); } @@ -492,6 +496,7 @@ bool CZNC::WriteNewConfig(const CString& sConfig) { CUtils::GetInput("Ident", sAnswer, sNick); vsLines.push_back("\tIdent = " + sAnswer); CUtils::GetInput("Real Name", sAnswer, "Got ZNC?"); vsLines.push_back("\tRealName = " + sAnswer); CUtils::GetInput("VHost", sAnswer, "", "optional"); if (!sAnswer.empty()) { vsLines.push_back("\tVHost = " + sAnswer); } + // todo: Possibly add motd if (CUtils::GetBoolInput("Would you like ZNC to keep trying for your primary nick?", true)) { vsLines.push_back("\tKeepNick = true"); @@ -1008,6 +1013,9 @@ bool CZNC::ParseConfig(const CString& sConfig) { } else if (sName.CaseCmp("ISpoofFile") == 0) { m_sISpoofFile = sValue; continue; + } else if (sName.CaseCmp("MOTD") == 0) { + AddMotd(sValue); + continue; } else if (sName.CaseCmp("VHost") == 0) { AddVHost(sValue); continue; diff --git a/znc.h b/znc.h index 6d7113e8..abb2a8b3 100644 --- a/znc.h +++ b/znc.h @@ -85,6 +85,13 @@ public: bool AddUser(CUser* pUser); const map & GetUserMap() const { return( m_msUsers ); } + // Message of the Day + void SetMotd(const CString& sMessage) { ClearMotd(); AddMotd(sMessage); } + void AddMotd(const CString& sMessage) { if (!sMessage.empty()) { m_vsMotd.push_back(sMessage); } } + void ClearMotd() { m_vsMotd.clear(); } + const VCString& GetMotd() const { return m_vsMotd; } + // !MOTD + private: protected: unsigned short m_uListenPort; @@ -107,6 +114,7 @@ protected: CString m_sISpoofFormat; CString m_sPidFile; VCString m_vsVHosts; + VCString m_vsMotd; CLockFile m_LockFile; bool m_bISpoofLocked; bool m_bSSL;