ControlPanel: support network module manipulation

Fix #380
This commit is contained in:
Alexey Sokolov
2013-09-07 12:27:39 +04:00
parent 8bde1ff70a
commit 958e9ad61c
+130 -44
View File
@@ -991,35 +991,22 @@ class CAdminMod : public CModule {
PutModule("Error: [" + sCTCPRequest + "] not found for user [" + pUser->GetUserName() + "]!");
}
void LoadModuleForUser(const CString& sLine) {
CString sUsername = sLine.Token(1);
CString sModName = sLine.Token(2);
CString sArgs = sLine.Token(3, true);
CString sModRet;
if (sModName.empty()) {
PutModule("Usage: loadmodule <username> <modulename>");
return;
}
CUser* pUser = GetUser(sUsername);
if (!pUser)
return;
void LoadModuleFor(CModules& Modules, const CString& sModName, const CString& sArgs, CModInfo::EModuleType eType, CUser* pUser, CIRCNetwork* pNetwork) {
if (pUser->DenyLoadMod() && !m_pUser->IsAdmin()) {
PutModule("Loading modules has been disabled.");
return;
}
CModule *pMod = (pUser)->GetModules().FindModule(sModName);
CString sModRet;
CModule *pMod = Modules.FindModule(sModName);
if (!pMod) {
if (!(pUser)->GetModules().LoadModule(sModName, sArgs, CModInfo::UserModule, pUser, NULL, sModRet)) {
if (!Modules.LoadModule(sModName, sArgs, eType, pUser, pNetwork, sModRet)) {
PutModule("Unable to load module [" + sModName + "] [" + sModRet + "]");
} else {
PutModule("Loaded module [" + sModName + "]");
}
} else if (pMod->GetArgs() != sArgs) {
if (!(pUser)->GetModules().ReloadModule(sModName, sArgs, pUser, NULL, sModRet)) {
if (!Modules.ReloadModule(sModName, sArgs, pUser, pNetwork, sModRet)) {
PutModule("Unable to reload module [" + sModName + "] [" + sModRet + "]");
} else {
PutModule("Reloaded module [" + sModName + "]");
@@ -1029,11 +1016,69 @@ class CAdminMod : public CModule {
}
}
void UnLoadModuleForUser(const CString& sLine) {
void LoadModuleForUser(const CString& sLine) {
CString sUsername = sLine.Token(1);
CString sModName = sLine.Token(2);
CString sArgs = sLine.Token(3, true);
if (sModName.empty()) {
PutModule("Usage: loadmodule <username> <modulename> [<args>]");
return;
}
CUser* pUser = GetUser(sUsername);
if (!pUser)
return;
LoadModuleFor(pUser->GetModules(), sModName, sArgs, CModInfo::UserModule, pUser, NULL);
}
void LoadModuleForNetwork(const CString& sLine) {
CString sUsername = sLine.Token(1);
CString sNetwork = sLine.Token(2);
CString sModName = sLine.Token(3);
CString sArgs = sLine.Token(4, true);
if (sModName.empty()) {
PutModule("Usage: loadnetmodule <username> <network> <modulename> [<args>]");
return;
}
CUser* pUser = GetUser(sUsername);
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
if (!pNetwork) {
PutModule("Network not found");
return;
}
LoadModuleFor(pNetwork->GetModules(), sModName, sArgs, CModInfo::NetworkModule, pUser, pNetwork);
}
void UnLoadModuleFor(CModules& Modules, const CString& sModName, CUser* pUser) {
if (pUser->DenyLoadMod() && !m_pUser->IsAdmin()) {
PutModule("Loading modules has been disabled.");
return;
}
if (Modules.FindModule(sModName) == this) {
PutModule("Please use /znc unloadmod " + sModName);
return;
}
CString sModRet;
if (!Modules.UnloadModule(sModName, sModRet)) {
PutModule("Unable to unload module [" + sModName + "] [" + sModRet + "]");
} else {
PutModule("Unloaded module [" + sModName + "] [" + sModRet + "]");
}
}
void UnLoadModuleForUser(const CString& sLine) {
CString sUsername = sLine.Token(1);
CString sModName = sLine.Token(2);
if (sModName.empty()) {
PutModule("Usage: unloadmodule <username> <modulename>");
@@ -1044,38 +1089,37 @@ class CAdminMod : public CModule {
if (!pUser)
return;
if (pUser->DenyLoadMod() && !m_pUser->IsAdmin()) {
PutModule("Loading modules has been disabled.");
return;
}
if (pUser->GetModules().FindModule(sModName) == this) {
PutModule("Please use /znc unloadmod " + sModName);
return;
}
if (!(pUser)->GetModules().UnloadModule(sModName, sModRet)) {
PutModule("Unable to unload module [" + sModName + "] [" + sModRet + "]");
} else {
PutModule("Unloaded module [" + sModName + "] [" + sModRet + "]");
}
UnLoadModuleFor(pUser->GetModules(), sModName, pUser);
}
void ListModuleForUser(const CString& sLine) {
CString sUsername = sLine.Token(1, true);
void UnLoadModuleForNetwork(const CString& sLine) {
CString sUsername = sLine.Token(1);
CString sNetwork = sLine.Token(2);
CString sModName = sLine.Token(3);
CUser* pUser = GetUser(sUsername);
if (!pUser || (pUser != m_pUser && !m_pUser->IsAdmin())) {
PutModule("Usage: listmods <username of other user>");
if (sModName.empty()) {
PutModule("Usage: unloadnetmodule <username> <network> <modulename>");
return;
}
CModules& Modules = pUser->GetModules();
CUser* pUser = GetUser(sUsername);
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
if (!pNetwork) {
PutModule("Network not found");
return;
}
UnLoadModuleFor(pNetwork->GetModules(), sModName, pUser);
}
void ListModulesFor(CModules& Modules, const CString& sWhere) {
if (!Modules.size()) {
PutModule("User [" + pUser->GetUserName() + "] has no modules loaded.");
PutModule(sWhere + " has no modules loaded.");
} else {
PutModule("Modules loaded for user [" + pUser->GetUserName() + "]:");
PutModule("Modules loaded for " + sWhere + ":");
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Arguments");
@@ -1088,7 +1132,43 @@ class CAdminMod : public CModule {
PutModule(Table);
}
}
void ListModulesForUser(const CString& sLine) {
CString sUsername = sLine.Token(1);
if (sUsername.empty()) {
PutModule("Usage: listmods <username>");
return;
}
CUser* pUser = GetUser(sUsername);
if (!pUser)
return;
ListModulesFor(pUser->GetModules(), "User [" + pUser->GetUserName() + "]");
}
void ListModulesForNetwork(const CString& sLine) {
CString sUsername = sLine.Token(1);
CString sNetwork = sLine.Token(2);
if (sNetwork.empty()) {
PutModule("Usage: listnetmods <username> <network>");
return;
}
CUser* pUser = GetUser(sUsername);
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
if (!pNetwork) {
PutModule("Network not found");
return;
}
ListModulesFor(pNetwork->GetModules(), "Network [" + pNetwork->GetName() + "] of user [" + pUser->GetUserName() + "]");
}
public:
@@ -1122,11 +1202,17 @@ public:
AddCommand("Disconnect", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::DisconnectUser),
"username network", "Disconnects the user from their IRC server");
AddCommand("LoadModule", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::LoadModuleForUser),
"username modulename", "Loads a Module for a user");
"username modulename [args]", "Loads a Module for a user");
AddCommand("UnLoadModule", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::UnLoadModuleForUser),
"username modulename", "Removes a Module of a user");
AddCommand("ListMods", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::ListModuleForUser),
AddCommand("ListMods", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::ListModulesForUser),
"username", "Get the list of modules for a user");
AddCommand("LoadNetModule",static_cast<CModCommand::ModCmdFunc>(&CAdminMod::LoadModuleForNetwork),
"username network modulename [args]", "Loads a Module for a network");
AddCommand("UnLoadNetModule",static_cast<CModCommand::ModCmdFunc>(&CAdminMod::UnLoadModuleForNetwork),
"username network modulename", "Removes a Module of a network");
AddCommand("ListNetMods", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::ListModulesForNetwork),
"username network", "Get the list of modules for a network");
AddCommand("ListCTCPs", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::ListCTCP),
"username", "List the configured CTCP replies");
AddCommand("AddCTCP", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::AddCTCP),