Merge pull request #634 from jpnurmi/webadmin

Fix #624: Can´t rename network via webinterface
This commit is contained in:
Alexey Sokolov
2014-09-06 23:24:43 +01:00
5 changed files with 36 additions and 24 deletions
+1
View File
@@ -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);
@@ -10,19 +10,17 @@
<div class="section">
<input type="hidden" name="submitted" value="1" />
<input type="hidden" name="user" value="<? VAR Username ?>" />
<? IF Edit ?><input type="hidden" name="network" value="<? VAR Name ?>" /><? ENDIF ?>
<input type="hidden" name="network" value="<? VAR Name ?>" />
<h3>Network Info</h3>
<span class="info">Nick, AltNick, Ident, RealName, BindHost can be left empty to use the value from the user.</span>
<div class="sectionbg">
<div class="sectionbody">
<? IF !Edit ?>
<div class="subsection">
<div class="inputlabel">Network Name:</div>
<input type="text" name="network" value="<? VAR Name ?>" class="half" maxlength="128"
<input type="text" name="name" value="<? VAR Name ?>" class="half" maxlength="128"
title="The name of the IRC network." />
</div>
<? ENDIF ?>
</div>
<div class="subsection">
<div class="inputlabel">Nickname:</div>
+15 -11
View File
@@ -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;
+1 -8
View File
@@ -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;
+16
View File
@@ -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) {