Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: znc/znc
base: 8bde1ff70adc
...
head fork: znc/znc
compare: 04b2d8fabf9b
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Aug 20, 2013
@dgw dgw Implement permission inheritance in log module
Quick-and-dirty matching of permissions when new log directories are
created. Currently gets tripped up by the umask with some perms.
3e1a2d9
Commits on Sep 07, 2013
@DarthGandalf DarthGandalf ControlPanel: support network module manipulation
Fix #380
958e9ad
@DarthGandalf DarthGandalf Merge commit 'refs/pull/396/head' of github.com:znc/znc 04b2d8f
Showing with 121 additions and 33 deletions.
  1. +118 −32 modules/controlpanel.cpp
  2. +3 −1 modules/log.cpp
View
150 modules/controlpanel.cpp
@@ -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,14 +1016,13 @@ 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);
- CString sModRet;
if (sModName.empty()) {
- PutModule("Usage: unloadmodule <username> <modulename>");
+ PutModule("Usage: loadmodule <username> <modulename> [<args>]");
return;
}
@@ -1044,38 +1030,96 @@ class CAdminMod : public CModule {
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 (pUser->GetModules().FindModule(sModName) == this) {
+ if (Modules.FindModule(sModName) == this) {
PutModule("Please use /znc unloadmod " + sModName);
return;
}
- if (!(pUser)->GetModules().UnloadModule(sModName, sModRet)) {
+ CString sModRet;
+ if (!Modules.UnloadModule(sModName, sModRet)) {
PutModule("Unable to unload module [" + sModName + "] [" + sModRet + "]");
} else {
PutModule("Unloaded module [" + sModName + "] [" + sModRet + "]");
}
}
- void ListModuleForUser(const CString& sLine) {
- CString sUsername = sLine.Token(1, true);
+ void UnLoadModuleForUser(const CString& sLine) {
+ CString sUsername = sLine.Token(1);
+ CString sModName = sLine.Token(2);
+
+ if (sModName.empty()) {
+ PutModule("Usage: unloadmodule <username> <modulename>");
+ return;
+ }
CUser* pUser = GetUser(sUsername);
- if (!pUser || (pUser != m_pUser && !m_pUser->IsAdmin())) {
- PutModule("Usage: listmods <username of other user>");
+ if (!pUser)
+ return;
+
+ UnLoadModuleFor(pUser->GetModules(), sModName, pUser);
+ }
+
+ void UnLoadModuleForNetwork(const CString& sLine) {
+ CString sUsername = sLine.Token(1);
+ CString sNetwork = sLine.Token(2);
+ CString sModName = sLine.Token(3);
+
+ 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 @@ class CAdminMod : public CModule {
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),
View
4 modules/log.cpp
@@ -97,7 +97,9 @@ void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/
CFile LogFile(sPath);
CString sLogDir = LogFile.GetDir();
- if (!CFile::Exists(sLogDir)) CDir::MakeDir(sLogDir);
+ struct stat ModDirInfo;
+ CFile::GetInfo(GetSavePath(), ModDirInfo);
+ if (!CFile::Exists(sLogDir)) CDir::MakeDir(sLogDir, ModDirInfo.st_mode);
if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
{
LogFile.Write(CUtils::FormatTime(curtime, "[%H:%M:%S] ", m_pUser->GetTimezone()) + (m_bSanitize ? sLine.StripControls_n() : sLine) + "\n");

No commit comments for this range

Something went wrong with that request. Please try again.