diff --git a/include/znc/Modules.h b/include/znc/Modules.h index 048646a0..159f0046 100644 --- a/include/znc/Modules.h +++ b/include/znc/Modules.h @@ -946,6 +946,7 @@ public: bool LoadRegistry(); bool SaveRegistry() const; + bool MoveRegistry(const CString& sPath); bool SetNV(const CString & sName, const CString & sValue, bool bWriteToDisk = true); CString GetNV(const CString & sName) const; bool DelNV(const CString & sName, bool bWriteToDisk = true); diff --git a/modules/data/webadmin/tmpl/add_edit_network.tmpl b/modules/data/webadmin/tmpl/add_edit_network.tmpl index 2fa0e61e..ed2af746 100644 --- a/modules/data/webadmin/tmpl/add_edit_network.tmpl +++ b/modules/data/webadmin/tmpl/add_edit_network.tmpl @@ -10,19 +10,17 @@
- +

Network Info

Nick, AltNick, Ident, RealName, BindHost can be left empty to use the value from the user.
-
Network Name:
- -
- +
Nickname:
diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index cf162a37..08b66d51 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -867,27 +867,31 @@ public: return true; } - CString sName = WebSock.GetParam("network").Trim_n(); + CString sName = WebSock.GetParam("name").Trim_n(); if (sName.empty()) { WebSock.PrintErrorPage("Network name is a required argument"); return true; } - - if (!pNetwork) { - if (!spSession->IsAdmin() && !pUser->HasSpaceForNewNetwork()) { - WebSock.PrintErrorPage("Network number limit reached. Ask an admin to increase the limit for you, or delete few old ones from Your Settings"); - return true; - } - if (!CIRCNetwork::IsValidNetwork(sName)) { - WebSock.PrintErrorPage("Network name should be alphanumeric"); - return true; - } + if (!pNetwork && !spSession->IsAdmin() && !pUser->HasSpaceForNewNetwork()) { + WebSock.PrintErrorPage("Network number limit reached. Ask an admin to increase the limit for you, or delete few old ones from Your Settings"); + return true; + } + if (!pNetwork || pNetwork->GetName() != sName) { CString sNetworkAddError; + CIRCNetwork* pOldNetwork = pNetwork; pNetwork = pUser->AddNetwork(sName, sNetworkAddError); if (!pNetwork) { WebSock.PrintErrorPage(sNetworkAddError); return true; } + if (pOldNetwork) { + for (CModule* pModule : pOldNetwork->GetModules()) { + CString sPath = pUser->GetUserPath() + "/networks/" + sName + "/moddata/" + pModule->GetModName(); + pModule->MoveRegistry(sPath); + } + pNetwork->Clone(*pOldNetwork, false); + pUser->DeleteNetwork(pOldNetwork->GetName()); + } } CString sArg; diff --git a/src/ClientCommand.cpp b/src/ClientCommand.cpp index 3ee1e865..431a50cb 100644 --- a/src/ClientCommand.cpp +++ b/src/ClientCommand.cpp @@ -635,14 +635,7 @@ void CClient::UserCommand(CString& sLine) { } } - CFile fOldNVFile = CFile(sOldModPath + "/.registry"); - if (!fOldNVFile.Exists()) { - continue; - } - if (!CFile::Exists(sNewModPath)) { - CDir::MakeDir(sNewModPath); - } - fOldNVFile.Copy(sNewModPath + "/.registry"); + (*i)->MoveRegistry(sNewModPath); } CString sNetworkAddError; diff --git a/src/Modules.cpp b/src/Modules.cpp index 90e92473..32c39276 100644 --- a/src/Modules.cpp +++ b/src/Modules.cpp @@ -221,6 +221,22 @@ bool CModule::SaveRegistry() const { return (m_mssRegistry.WriteToDisk(GetSavePath() + "/.registry", 0600) == MCString::MCS_SUCCESS); } +bool CModule::MoveRegistry(const CString& sPath) { + if (m_sSavePath != sPath) { + CFile fOldNVFile = CFile(m_sSavePath + "/.registry"); + if (!fOldNVFile.Exists()) { + return false; + } + if (!CFile::Exists(sPath) && !CDir::MakeDir(sPath)) { + return false; + } + fOldNVFile.Copy(sPath + "/.registry"); + m_sSavePath = sPath; + return true; + } + return false; +} + bool CModule::SetNV(const CString & sName, const CString & sValue, bool bWriteToDisk) { m_mssRegistry[sName] = sValue; if (bWriteToDisk) {