Upgrading to CZNC::Get()

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@508 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-09-19 04:09:37 +00:00
parent ba951747f9
commit 89e5079ce9
13 changed files with 100 additions and 139 deletions
+1 -1
View File
@@ -123,7 +123,7 @@ void CDCCBounce::PutPeer(const CString& sLine) {
unsigned short CDCCBounce::DCCRequest(const CString& sNick, unsigned long uLongIP, unsigned short uPort, const CString& sFileName, bool bIsChat, CUser* pUser, const CString& sLocalIP, const CString& sRemoteIP) {
CDCCBounce* pDCCBounce = new CDCCBounce(pUser, uLongIP, uPort, sFileName, sNick, sRemoteIP, sLocalIP, bIsChat);
unsigned short uListenPort = pUser->GetManager()->ListenAllRand("DCC::" + CString((bIsChat) ? "Chat" : "Xfer") + "::Local::" + sNick, false, SOMAXCONN, pDCCBounce, 120);
unsigned short uListenPort = CZNC::Get().GetManager().ListenAllRand("DCC::" + CString((bIsChat) ? "Chat" : "Xfer") + "::Local::" + sNick, false, SOMAXCONN, pDCCBounce, 120);
return uListenPort;
}
+3 -2
View File
@@ -4,6 +4,7 @@
#include "main.h"
#include "Utils.h"
#include "User.h"
#include "znc.h"
class CDCCBounce : public Csock {
public:
@@ -14,7 +15,7 @@ public:
m_sFileName = sFileName;
m_sRemoteNick = sRemoteNick;
m_pUser = pUser;
m_pManager = pUser->GetManager();
m_pManager = &(CZNC::Get().GetManager());
m_bIsChat = bIsChat;
m_sLocalIP = sLocalIP;
m_pPeer = NULL;
@@ -28,7 +29,7 @@ public:
CDCCBounce(const CString& sHostname, unsigned short uPort, CUser* pUser, const CString& sRemoteNick, const CString& sRemoteIP, const CString& sFileName, int iTimeout = 60, bool bIsChat = false) : Csock(sHostname, uPort, iTimeout) {
m_uRemotePort = 0;
m_bIsChat = bIsChat;
m_pManager = pUser->GetManager();
m_pManager = &(CZNC::Get().GetManager());
m_pUser = pUser;
m_pPeer = NULL;
m_sRemoteNick = sRemoteNick;
+12 -29
View File
@@ -161,8 +161,7 @@ const CString& CSocket::GetLabel() const { return m_sLabel; }
CModule::CModule(void* pDLL, CUser* pUser, const CString& sModName) {
m_pDLL = pDLL;
m_pZNC = (pUser) ? pUser->GetZNC() : NULL;
m_pManager = (pUser) ? pUser->GetManager() : NULL;
m_pManager = &(CZNC::Get().GetManager());;
m_pUser = pUser;
m_sModName = sModName;
@@ -172,17 +171,14 @@ CModule::CModule(void* pDLL, CUser* pUser, const CString& sModName) {
}
}
CModule::CModule(void* pDLL, CZNC* pZNC, const CString& sModName) {
CModule::CModule(void* pDLL, const CString& sModName) {
m_pDLL = pDLL;
m_pZNC = pZNC;
m_pManager = (pZNC) ? &pZNC->GetManager() : NULL;
m_pManager = &(CZNC::Get().GetManager());
m_pUser = NULL;
m_sModName = sModName;
if (m_pZNC) {
m_sSavePath = m_pZNC->GetZNCPath() + "/moddata/" + m_sModName;
LoadRegistry();
}
m_sSavePath = CZNC::Get().GetZNCPath() + "/moddata/" + m_sModName;
LoadRegistry();
}
CModule::~CModule() {
@@ -201,19 +197,11 @@ void CModule::SetUser(CUser* pUser) { m_pUser = pUser; }
void CModule::Unload() { throw UNLOAD; }
bool CModule::LoadRegistry() {
if (!m_pZNC) {
return false;
}
//CString sPrefix = (m_pUser) ? m_pUser->GetUserName() : ".global";
return (m_mssRegistry.ReadFromDisk(GetSavePath() + "/.registry", 0600) == MCString::MCS_SUCCESS);
}
bool CModule::SaveRegistry() {
if (!m_pZNC) {
return false;
}
//CString sPrefix = (m_pUser) ? m_pUser->GetUserName() : ".global";
return (m_mssRegistry.WriteToDisk(GetSavePath() + "/.registry", 0600) == MCString::MCS_SUCCESS);
}
@@ -505,8 +493,7 @@ bool CModule::PutModNotice(const CString& sLine, const CString& sIdent, const CS
///////////////////
CModule::EModRet CGlobalModule::OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan) { return CONTINUE; }
CModules::CModules(CZNC* pZNC) {
m_pZNC = pZNC;
CModules::CModules() {
m_pUser = NULL;
}
@@ -775,7 +762,7 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p
pModule = Load(p, pUser, sModule);
} else {
typedef CModule* (*fp)(void*, CZNC* pZNC, const CString& sModName);
typedef CModule* (*fp)(void*, const CString& sModName);
fp Load = (fp) dlsym(p, "Load");
if (!Load) {
@@ -784,7 +771,7 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p
return false;
}
pModule = Load(p, m_pZNC, sModule);
pModule = Load(p, sModule);
}
pModule->SetDescription(GetDesc());
@@ -876,11 +863,7 @@ CString CModules::FindModPath(const CString& sModule, CUser* pUser) {
return pUser->FindModPath(sModule);
}
if (!m_pZNC) {
DEBUG_ONLY(cerr << "CModules::FindModPath() m_pZNC is NULL!" << endl);
}
return (m_pZNC) ? m_pZNC->FindModPath(sModule) : "";
return CZNC::Get().FindModPath(sModule);
}
bool CModules::GetModInfo(CModInfo& ModInfo, const CString& sModule) {
@@ -939,13 +922,13 @@ bool CModules::GetModInfo(CModInfo& ModInfo, const CString& sModule) {
return true;
}
void CModules::GetAvailableMods(set<CModInfo>& ssMods, CZNC* pZNC, bool bGlobal) {
void CModules::GetAvailableMods(set<CModInfo>& ssMods, bool bGlobal) {
ssMods.clear();
unsigned int a = 0;
CDir Dir;
Dir.FillByWildcard(pZNC->GetCurPath() + "/modules", "*.so");
Dir.FillByWildcard(CZNC::Get().GetCurPath() + "/modules", "*.so");
for (a = 0; a < Dir.size(); a++) {
CFile& File = *Dir[a];
CString sName = File.GetShortName();
@@ -960,7 +943,7 @@ void CModules::GetAvailableMods(set<CModInfo>& ssMods, CZNC* pZNC, bool bGlobal)
}
}
Dir.FillByWildcard(pZNC->GetModPath(), "*.so");
Dir.FillByWildcard(CZNC::Get().GetModPath(), "*.so");
for (a = 0; a < Dir.size(); a++) {
CFile& File = *Dir[a];
CString sName = File.GetShortName();
+8 -11
View File
@@ -36,15 +36,15 @@ using std::set;
// Global Module Macros
#define GLOBALMODCONSTRUCTOR(CLASS) \
CLASS(void *pDLL, CZNC* pZNC, const CString& sModName) : CGlobalModule(pDLL, pZNC, sModName)
CLASS(void *pDLL, const CString& sModName) : CGlobalModule(pDLL, sModName)
#define GLOBALMODULEDEFS(CLASS, DESCRIPTION) \
extern "C" { \
CString GetDescription() { return DESCRIPTION; } \
bool IsGlobal() { return true; } \
CGlobalModule* Load(void* p, CZNC* pZNC, const CString& sModName); \
CGlobalModule* Load(void* p, const CString& sModName); \
void Unload(CGlobalModule* pMod); double GetVersion(); } \
double GetVersion() { return VERSION; } \
CGlobalModule* Load(void* p, CZNC* pZNC, const CString& sModName) { return new CLASS(p, pZNC, sModName); } \
CGlobalModule* Load(void* p, const CString& sModName) { return new CLASS(p, sModName); } \
void Unload(CGlobalModule* pMod) { if (pMod) { delete pMod; } \
}
// !Global Module Macros
@@ -177,7 +177,7 @@ protected:
class CModule {
public:
CModule(void* pDLL, CUser* pUser, const CString& sModName);
CModule(void* pDLL, CZNC* pZNC, const CString& sModName);
CModule(void* pDLL, const CString& sModName);
virtual ~CModule();
typedef enum {
@@ -286,7 +286,6 @@ public:
// Getters
const CString& GetDescription() const { return m_sDescription; }
const CString& GetArgs() const { return m_sArgs; }
CZNC* GetZNC() { return m_pZNC; }
CUser* GetUser() { return m_pUser; }
TSocketManager<Csock>* GetManager() { return m_pManager; }
// !Getters
@@ -298,7 +297,6 @@ protected:
void* m_pDLL;
TSocketManager<Csock>* m_pManager;
CUser* m_pUser;
CZNC* m_pZNC;
CString m_sModName;
CString m_sSavePath;
CString m_sArgs;
@@ -308,7 +306,7 @@ private:
class CModules : public vector<CModule*> {
public:
CModules(CZNC* pZNC);
CModules();
virtual ~CModules();
void SetUser(CUser* pUser) { m_pUser = pUser; }
@@ -364,16 +362,15 @@ public:
CString FindModPath(const CString& sModule, CUser* pUser = NULL);
bool GetModInfo(CModInfo& ModInfo, const CString& sModule);
void GetAvailableMods(set<CModInfo>& ssMods, CZNC* pZNC, bool bGlobal = false);
void GetAvailableMods(set<CModInfo>& ssMods, bool bGlobal = false);
protected:
CZNC* m_pZNC;
CUser* m_pUser;
};
class CGlobalModule : public CModule {
public:
CGlobalModule(void* pDLL, CZNC* pZNC, const CString& sModName) : CModule(pDLL, pZNC, sModName) {}
CGlobalModule(void* pDLL, const CString& sModName) : CModule(pDLL, sModName) {}
virtual ~CGlobalModule() {}
virtual EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan);
@@ -382,7 +379,7 @@ private:
class CGlobalModules : public CModules {
public:
CGlobalModules(CZNC* pZNC) : CModules(pZNC) {}
CGlobalModules() : CModules() {}
virtual ~CGlobalModules() {}
virtual bool OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan);
+1 -1
View File
@@ -71,7 +71,7 @@ protected:
}
}
m_pUser->GetZNC()->GetManager().DelCronByAddr(this);
CZNC::Get().GetManager().DelCronByAddr(this);
}
CUser* m_pUser;
+17 -31
View File
@@ -9,16 +9,15 @@
#include "MD5.h"
#include "Timers.h"
CUser::CUser(const CString& sUserName, CZNC* pZNC) {
CUser::CUser(const CString& sUserName) {
m_uConnectTime = 0;
m_sUserName = sUserName;
m_sNick = sUserName;
m_sIdent = sUserName;
m_sRealName = sUserName;
m_uServerIdx = 0;
m_pZNC = pZNC;
#ifdef _MODULES
m_pModules = new CModules(pZNC);
m_pModules = new CModules;
#endif
m_bBounceDCCs = true;
m_bPassHashed = false;
@@ -31,9 +30,9 @@ CUser::CUser(const CString& sUserName, CZNC* pZNC) {
m_bAutoCycle = true;
m_pKeepNickTimer = new CKeepNickTimer(this);
m_pJoinTimer = new CJoinTimer(this);
m_pZNC->GetManager().AddCron(m_pKeepNickTimer);
m_pZNC->GetManager().AddCron(m_pJoinTimer);
m_sUserPath = m_pZNC->GetUserPath() + "/" + sUserName;
CZNC::Get().GetManager().AddCron(m_pKeepNickTimer);
CZNC::Get().GetManager().AddCron(m_pJoinTimer);
m_sUserPath = CZNC::Get().GetUserPath() + "/" + sUserName;
m_sDLPath = GetUserPath() + "/downloads";
}
@@ -49,8 +48,8 @@ CUser::~CUser() {
delete m_vChans[b];
}
m_pZNC->GetManager().DelCronByAddr(m_pKeepNickTimer);
m_pZNC->GetManager().DelCronByAddr(m_pJoinTimer);
CZNC::Get().GetManager().DelCronByAddr(m_pKeepNickTimer);
CZNC::Get().GetManager().DelCronByAddr(m_pJoinTimer);
}
bool CUser::OnBoot() {
@@ -69,7 +68,7 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet) {
}
if (GetUserName() != User.GetUserName()) {
if (m_pZNC->FindUser(User.GetUserName())) {
if (CZNC::Get().FindUser(User.GetUserName())) {
sErrorRet = "New username already exists";
return false;
}
@@ -537,17 +536,9 @@ bool CUser::CheckPass(const CString& sPass) {
return (m_sPass.CaseCmp((char*) CMD5(sPass)) == 0);
}
TSocketManager<Csock>* CUser::GetManager() {
return &m_pZNC->GetManager();
}
CZNC* CUser::GetZNC() {
return m_pZNC;
}
CUserSock* CUser::GetUserSock() {
// Todo: optimize this by saving a pointer to the sock
TSocketManager<Csock>& Manager = m_pZNC->GetManager();
TSocketManager<Csock>& Manager = CZNC::Get().GetManager();
CString sSockName = "USR::" + m_sUserName;
for (unsigned int a = 0; a < Manager.size(); a++) {
@@ -559,7 +550,7 @@ CUserSock* CUser::GetUserSock() {
}
}
return (CUserSock*) m_pZNC->GetManager().FindSockByName(sSockName);
return (CUserSock*) CZNC::Get().GetManager().FindSockByName(sSockName);
}
bool CUser::IsUserAttached() {
@@ -574,7 +565,7 @@ bool CUser::IsUserAttached() {
CIRCSock* CUser::GetIRCSock() {
// Todo: optimize this by saving a pointer to the sock
return (CIRCSock*) m_pZNC->GetManager().FindSockByName("IRC::" + m_sUserName);
return (CIRCSock*) CZNC::Get().GetManager().FindSockByName("IRC::" + m_sUserName);
}
CString CUser::GetLocalIP() {
@@ -638,7 +629,7 @@ bool CUser::PutModule(const CString& sModule, const CString& sLine) {
}
bool CUser::ResumeFile(const CString& sRemoteNick, unsigned short uPort, unsigned long uFileSize) {
TSocketManager<Csock>& Manager = m_pZNC->GetManager();
TSocketManager<Csock>& Manager = CZNC::Get().GetManager();
for (unsigned int a = 0; a < Manager.size(); a++) {
if (strncasecmp(Manager[a]->GetSockName().c_str(), "DCC::LISTEN::", 13) == 0) {
@@ -659,7 +650,7 @@ bool CUser::ResumeFile(const CString& sRemoteNick, unsigned short uPort, unsigne
}
bool CUser::SendFile(const CString& sRemoteNick, const CString& sFileName, const CString& sModuleName) {
CString sFullPath = CUtils::ChangeDir(GetDLPath(), sFileName, GetHomePath());
CString sFullPath = CUtils::ChangeDir(GetDLPath(), sFileName, CZNC::Get().GetHomePath());
CDCCSock* pSock = new CDCCSock(this, sRemoteNick, sFullPath, sModuleName);
CFile* pFile = pSock->OpenFile(false);
@@ -669,7 +660,7 @@ bool CUser::SendFile(const CString& sRemoteNick, const CString& sFileName, const
return false;
}
unsigned short uPort = GetManager()->ListenAllRand("DCC::LISTEN::" + sRemoteNick, false, SOMAXCONN, pSock, 120);
unsigned short uPort = CZNC::Get().GetManager().ListenAllRand("DCC::LISTEN::" + sRemoteNick, false, SOMAXCONN, pSock, 120);
if (GetNick().CaseCmp(sRemoteNick) == 0) {
PutUser(":" + GetStatusPrefix() + "status!znc@znc.com PRIVMSG " + sRemoteNick + " :\001DCC SEND " + pFile->GetShortName() + " " + CString::ToString(CUtils::GetLongIP(GetLocalIP())) + " "
@@ -696,7 +687,7 @@ bool CUser::GetFile(const CString& sRemoteNick, const CString& sRemoteIP, unsign
return false;
}
if (!GetManager()->Connect(sRemoteIP, uRemotePort, "DCC::GET::" + sRemoteNick, 60, false, GetLocalIP(), pSock)) {
if (!CZNC::Get().GetManager().Connect(sRemoteIP, uRemotePort, "DCC::GET::" + sRemoteNick, 60, false, GetLocalIP(), pSock)) {
PutModule(sModuleName, "DCC <- [" + sRemoteNick + "][" + sFileName + "] - Unable to connect.");
return false;
}
@@ -772,12 +763,12 @@ const CString& CUser::GetPass() const { return m_sPass; }
bool CUser::IsPassHashed() const { return m_bPassHashed; }
CString CUser::FindModPath(const CString& sModule) const {
CString sModPath = GetCurPath() + "/modules/" + sModule;
CString sModPath = CZNC::Get().GetCurPath() + "/modules/" + sModule;
sModPath += (sModule.find(".") == CString::npos) ? ".so" : "";
if (!CFile::Exists(sModPath)) {
DEBUG_ONLY(cout << "[" << sModPath << "] Not found..." << endl);
sModPath = GetModPath() + "/" + sModule;
sModPath = CZNC::Get().GetModPath() + "/" + sModule;
sModPath += (sModule.find(".") == CString::npos) ? ".so" : "";
if (!CFile::Exists(sModPath)) {
@@ -809,11 +800,6 @@ bool CUser::ConnectPaused() {
return true;
}
const CString& CUser::GetCurPath() const { return m_pZNC->GetCurPath(); }
const CString& CUser::GetModPath() const { return m_pZNC->GetModPath(); }
const CString& CUser::GetHomePath() const { return m_pZNC->GetHomePath(); }
CString CUser::GetPemLocation() const { return m_pZNC->GetPemLocation(); }
bool CUser::UseClientIP() const { return m_bUseClientIP; }
bool CUser::GetKeepNick() const { return m_bKeepNick; }
bool CUser::DenyLoadMod() const { return m_bDenyLoadMod; }
+1 -8
View File
@@ -24,7 +24,7 @@ class CJoinTimer;
class CUser {
public:
CUser(const CString& sUserName, CZNC* pZNC);
CUser(const CString& sUserName);
virtual ~CUser();
bool PrintLine(CFile& File, const CString& sName, const CString& sValue);
@@ -98,8 +98,6 @@ public:
// Getters
CUserSock* GetUserSock();
CIRCSock* GetIRCSock();
TSocketManager<Csock>* GetManager();
CZNC* GetZNC();
const CString& GetUserName() const;
const CString& GetNick() const;
const CString& GetAltNick() const;
@@ -112,9 +110,6 @@ public:
const set<CString>& GetAllowedHosts() const;
CString FindModPath(const CString& sModule) const;
const CString& GetCurPath() const;
const CString& GetModPath() const;
const CString& GetHomePath() const;
const CString& GetUserPath() const { if (!CFile::Exists(m_sUserPath)) { CUtils::MakeDir(m_sUserPath); } return m_sUserPath; }
const CString& GetDLPath() const { if (!CFile::Exists(m_sDLPath)) { CUtils::MakeDir(m_sDLPath); } return m_sDLPath; }
CString GetPemLocation() const;
@@ -137,8 +132,6 @@ public:
// !Getters
private:
protected:
CZNC* m_pZNC;
time_t m_uConnectTime;
CString m_sUserName;
CString m_sNick;
+1 -1
View File
@@ -165,7 +165,7 @@ void CUserSock::ReadLine(const CString& sData) {
CString sModule = sTarget;
sModule.LeftChomp(m_pUser->GetStatusPrefix().length());
CModule* pModule = m_pUser->GetZNC()->GetModules().FindModule(sModule);
CModule* pModule = CZNC::Get().GetModules().FindModule(sModule);
if (pModule) {
pModule->OnModNotice(sMsg);
+3 -3
View File
@@ -10,7 +10,7 @@
#ifdef _MODULES
#define VOIDMODULECALL(func) \
if (m_pUser) { \
CGlobalModules& GMods = m_pUser->GetZNC()->GetModules(); \
CGlobalModules& GMods = CZNC::Get().GetModules(); \
GMods.SetUser(m_pUser); \
GMods.func; \
m_pUser->GetModules().func; \
@@ -23,7 +23,7 @@
#ifdef _MODULES
#define MODULECALLRET(func) \
if (m_pUser) { \
CGlobalModules& GMods = m_pUser->GetZNC()->GetModules(); \
CGlobalModules& GMods = CZNC::Get().GetModules(); \
GMods.SetUser(m_pUser); \
if (GMods.func || m_pUser->GetModules().func) { \
return; \
@@ -37,7 +37,7 @@
#ifdef _MODULES
#define MODULECALL(func) \
if (m_pUser) { \
CGlobalModules& GMods = m_pUser->GetZNC()->GetModules(); \
CGlobalModules& GMods = CZNC::Get().GetModules(); \
GMods.SetUser(m_pUser); \
if (GMods.func || m_pUser->GetModules().func) { \
return true; \
+7 -7
View File
@@ -208,7 +208,7 @@ public:
DestroyAllSocks();
if ( m_pPerl )
{
const map<CString,CUser*> & msUsers = m_pZNC->GetUserMap();
const map<CString,CUser*> & msUsers = CZNC::Get().GetUserMap();
for( map<CString,CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); it++ )
{ // need to set it on all of these
@@ -230,7 +230,7 @@ public:
void SetupZNCScript()
{
CString sModule = m_pZNC->FindModPath( "modperl.pm" );
CString sModule = CZNC::Get().FindModPath( "modperl.pm" );
if ( !sModule.empty() )
{
CString sBuffer, sScript;
@@ -279,7 +279,7 @@ public:
if ( sUsername.empty() )
return( m_pUser );
CUser *pUser = m_pZNC->GetUser( sUsername );
CUser *pUser = CZNC::Get().GetUser( sUsername );
if ( bSetUserContext )
m_pUser = pUser;
@@ -688,10 +688,10 @@ XS(XS_ZNC_GetString)
else if ( sName == "RealName" ) sReturn = pUser->GetRealName();
else if ( sName == "VHost" ) sReturn = pUser->GetVHost();
else if ( sName == "Pass" ) sReturn = pUser->GetPass();
else if ( sName == "CurPath" ) sReturn = pUser->GetCurPath();
else if ( sName == "CurPath" ) sReturn = CZNC::Get().GetCurPath();
else if ( sName == "DLPath" ) sReturn = pUser->GetDLPath();
else if ( sName == "ModPath" ) sReturn = pUser->GetModPath();
else if ( sName == "HomePath" ) sReturn = pUser->GetHomePath();
else if ( sName == "ModPath" ) sReturn = CZNC::Get().GetModPath();
else if ( sName == "HomePath" ) sReturn = CZNC::Get().GetHomePath();
//else if ( sName == "DataPath" ) sReturn = pUser->GetDataPath();
else if ( sName == "StatusPrefix" ) sReturn = pUser->GetStatusPrefix();
else if ( sName == "DefaultChanModes" ) sReturn = pUser->GetDefaultChanModes();
@@ -1028,7 +1028,7 @@ void CModPerl::LoadPerlMod( const CString & sModule )
return;
}
CString sModPath = m_pZNC->FindModPath( sModule );
CString sModPath = CZNC::Get().FindModPath( sModule );
if ( sModPath.empty() )
PutStatus( "No such module " + sModule );
else
+6 -5
View File
@@ -6,6 +6,7 @@
#include "Chan.h"
#include "Utils.h"
#include "FileUtils.h"
#include "znc.h"
#include <sys/wait.h>
// Forward Declaration
@@ -87,7 +88,7 @@ public:
class CShellMod : public CModule {
public:
MODCONSTRUCTOR(CShellMod) {
m_sPath = pUser->GetHomePath();
m_sPath = CZNC::Get().GetHomePath();
}
virtual ~CShellMod() {
@@ -100,7 +101,7 @@ public:
virtual void OnModCommand(const CString& sCommand) {
if ((strcasecmp(sCommand.c_str(), "cd") == 0) || (strncasecmp(sCommand.c_str(), "cd ", 3) == 0)) {
CString sPath = CUtils::ChangeDir(m_sPath, ((sCommand.length() == 2) ? CString(m_pUser->GetHomePath()) : CString(sCommand.substr(3))), m_pUser->GetHomePath());
CString sPath = CUtils::ChangeDir(m_sPath, ((sCommand.length() == 2) ? CString(CZNC::Get().GetHomePath()) : CString(sCommand.substr(3))), CZNC::Get().GetHomePath());
CFile Dir(sPath);
if (Dir.IsDir()) {
@@ -119,7 +120,7 @@ public:
if ((sToNick.empty()) || (sFile.empty())) {
PutShell("usage: Send <nick> <file>");
} else {
sFile = CUtils::ChangeDir(m_sPath, sFile, m_pUser->GetHomePath());
sFile = CUtils::ChangeDir(m_sPath, sFile, CZNC::Get().GetHomePath());
if (!CFile::Exists(sFile)) {
PutShell("get: no such file [" + sFile + "]");
@@ -135,7 +136,7 @@ public:
if (sFile.empty()) {
PutShell("usage: Get <file>");
} else {
sFile = CUtils::ChangeDir(m_sPath, sFile, m_pUser->GetHomePath());
sFile = CUtils::ChangeDir(m_sPath, sFile, CZNC::Get().GetHomePath());
if (!CFile::Exists(sFile)) {
PutShell("get: no such file [" + sFile + "]");
@@ -161,7 +162,7 @@ public:
virtual EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) {
if (strcasecmp(RemoteNick.GetNick().c_str(), CString(GetModNick()).c_str()) == 0) {
CString sLocalFile = CUtils::ChangeDir(m_sPath, sFile, m_pUser->GetHomePath());
CString sLocalFile = CUtils::ChangeDir(m_sPath, sFile, CZNC::Get().GetHomePath());
m_pUser->GetFile(m_pUser->GetCurNick(), CUtils::GetIP(uLongIP), uPort, sLocalFile, uFileSize, GetModName());
+36 -36
View File
@@ -96,7 +96,7 @@ protected:
class CWebAdminMod : public CGlobalModule {
public:
CWebAdminMod(void *pDLL, CZNC* pZNC, const CString& sModName) : CGlobalModule(pDLL, pZNC, sModName) {
CWebAdminMod(void *pDLL, const CString& sModName) : CGlobalModule(pDLL, sModName) {
m_uPort = 8080;
}
@@ -135,7 +135,7 @@ public:
#ifdef HAVE_LIBSSL
if (bSSL) {
pListenSock->SetPemLocation(m_pZNC->GetPemLocation());
pListenSock->SetPemLocation(CZNC::Get().GetPemLocation());
}
#endif
@@ -180,7 +180,7 @@ CString CWebAdminSock::Header(const CString& sTitle) {
}
CString CWebAdminSock::Footer() {
return "</td></tr><tr><td colspan='2' align='right' valign='bottom'>" + m_pModule->GetZNC()->GetTag() + "</td></tr>\r\n"
return "</td></tr><tr><td colspan='2' align='right' valign='bottom'>" + CZNC::Get().GetTag() + "</td></tr>\r\n"
"</table></body>\r\n</html>\r\n";
}
@@ -190,7 +190,7 @@ bool CWebAdminSock::OnLogin(const CString& sUser, const CString& sPass) {
return true;
}
CUser* pUser = m_pModule->GetZNC()->FindUser(GetUser());
CUser* pUser = CZNC::Get().FindUser(GetUser());
if (pUser && pUser->CheckPass(GetPass())) {
m_pUser = pUser;
@@ -201,7 +201,7 @@ bool CWebAdminSock::OnLogin(const CString& sUser, const CString& sPass) {
}
void CWebAdminSock::ListUsersPage(CString& sPageRet) {
const map<CString,CUser*>& msUsers = m_pModule->GetZNC()->GetUserMap();
const map<CString,CUser*>& msUsers = CZNC::Get().GetUserMap();
sPageRet = Header("List Users");
if (!msUsers.size()) {
@@ -285,7 +285,7 @@ bool CWebAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) {
}
} else if (sURI == "/edituser") {
if (!m_pUser) {
m_pUser = m_pModule->GetZNC()->FindUser(GetParam("user"));
m_pUser = CZNC::Get().FindUser(GetParam("user"));
}
if (m_pUser) {
@@ -298,7 +298,7 @@ bool CWebAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) {
}
} else if (sURI == "/editchan") {
if (!m_pUser) {
m_pUser = m_pModule->GetZNC()->FindUser(GetParam("user"));
m_pUser = CZNC::Get().FindUser(GetParam("user"));
}
if (!m_pUser) {
@@ -319,7 +319,7 @@ bool CWebAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) {
}
} else if (sURI == "/addchan") {
if (!m_pUser) {
m_pUser = m_pModule->GetZNC()->FindUser(GetParam("user"));
m_pUser = CZNC::Get().FindUser(GetParam("user"));
}
if (m_pUser) {
@@ -332,7 +332,7 @@ bool CWebAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) {
}
} else if (sURI == "/delchan") {
if (!m_pUser) {
m_pUser = m_pModule->GetZNC()->FindUser(GetParam("user"));
m_pUser = CZNC::Get().FindUser(GetParam("user"));
}
if (m_pUser) {
@@ -354,7 +354,7 @@ bool CWebAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) {
return false;
}
if (m_pModule->GetZNC()->DeleteUser(GetParam("user"))) {
if (CZNC::Get().DeleteUser(GetParam("user"))) {
DEBUG_ONLY(cout << "- 302 Redirect" << endl);
Redirect("/listusers");
return false;
@@ -379,7 +379,7 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
CString sVHosts;
const VCString& vsVHosts = m_pModule->GetZNC()->GetVHosts();
const VCString& vsVHosts = CZNC::Get().GetVHosts();
for (unsigned int a = 0; a < vsVHosts.size(); a++) {
sVHosts += vsVHosts[a] + "\r\n";
}
@@ -389,12 +389,12 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
"<div style='white-space: nowrap; margin-top: -8px; margin-right: 8px; margin-left: 8px; padding: 1px 5px 1px 5px; float: left; border: 1px solid #000; font-size: 16px; font-weight: bold; background: #ff9;'>Global Settings</div><div style='padding: 25px 5px 5px 15px; border: 2px solid #000; background: #cc9;'><div style='clear: both;'>\r\n"
"<div><small><b>Status Prefix:</b></small><br>\r\n"
"<input type='text' name='statusprefix' value='" + m_pModule->GetZNC()->GetStatusPrefix().Escape_n(CString::EHTML) + "' size='32' maxlength='128'></div><br>\r\n"
"<input type='text' name='statusprefix' value='" + CZNC::Get().GetStatusPrefix().Escape_n(CString::EHTML) + "' size='32' maxlength='128'></div><br>\r\n"
"<div style='float: left; margin-right: 10px;'><small><b>ISpoofFile:</b></small><br>\r\n"
"<input type='text' name='ispooffile' value='" + m_pModule->GetZNC()->GetISpoofFile().Escape_n(CString::EHTML) + "' size='32' maxlength='128'></div>\r\n"
"<input type='text' name='ispooffile' value='" + CZNC::Get().GetISpoofFile().Escape_n(CString::EHTML) + "' size='32' maxlength='128'></div>\r\n"
"<div><small><b>ISpoofFormat:</b></small><br>\r\n"
"<input type='text' name='ispoofformat' value='" + m_pModule->GetZNC()->GetISpoofFormat().Escape_n(CString::EHTML) + "' size='32' maxlength='128'></div>\r\n"
"<input type='text' name='ispoofformat' value='" + CZNC::Get().GetISpoofFormat().Escape_n(CString::EHTML) + "' size='32' maxlength='128'></div>\r\n"
"<br><div><small><b>VHosts:</b></small><br>\r\n"
"<textarea name='vhosts' cols='40' rows='5'>" + sVHosts.Escape_n(CString::EHTML) + "</textarea></div>\r\n"
@@ -406,13 +406,13 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
"<tr style='font-weight: bold; background: #ff9;'><td style='border: 1px solid #000;'>Name</td><td style='border: 1px solid #000;'>Arguments</td><td style='border: 1px solid #000;'>Description</td></tr>\r\n";
set<CModInfo> ssGlobalMods;
m_pModule->GetZNC()->GetModules().GetAvailableMods(ssGlobalMods, m_pModule->GetZNC(), true);
CZNC::Get().GetModules().GetAvailableMods(ssGlobalMods, true);
unsigned int uIdx = 0;
for (set<CModInfo>::iterator it = ssGlobalMods.begin(); it != ssGlobalMods.end(); it++) {
const CModInfo& Info = *it;
sPageRet += "<tr style='background: " + CString((uIdx++ %2) ? "#ffc" : "#cc9") + "'><td style='border: 1px solid #000;'><label><input type='checkbox' name='loadmod' value='" + Info.GetName().Escape_n(CString::EHTML) + "'" + CString((m_pModule->GetZNC()->GetModules().FindModule(Info.GetName())) ? " CHECKED" : "") + CString((Info.GetName() == m_pModule->GetModName()) ? " DISABLED" : "") + "> " + Info.GetName().Escape_n(CString::EHTML) + "</label></td>"
sPageRet += "<tr style='background: " + CString((uIdx++ %2) ? "#ffc" : "#cc9") + "'><td style='border: 1px solid #000;'><label><input type='checkbox' name='loadmod' value='" + Info.GetName().Escape_n(CString::EHTML) + "'" + CString((CZNC::Get().GetModules().FindModule(Info.GetName())) ? " CHECKED" : "") + CString((Info.GetName() == m_pModule->GetModName()) ? " DISABLED" : "") + "> " + Info.GetName().Escape_n(CString::EHTML) + "</label></td>"
"<td style='border: 1px solid #000;'><input type='text' name='modargs_" + Info.GetName().Escape_n(CString::EHTML) + "' value='" + GetModArgs(Info.GetName(), true) + "'" + CString((Info.GetName() == m_pModule->GetModName()) ? " DISABLED" : "") + "></td>"
"<td style='border: 1px solid #000;'>" + Info.GetDescription().Escape_n(CString::EHTML) + "</td></tr>";
}
@@ -427,17 +427,17 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
}
CString sArg;
sArg = GetParam("statusprefix"); m_pModule->GetZNC()->SetStatusPrefix(sArg);
sArg = GetParam("ispooffile"); m_pModule->GetZNC()->SetISpoofFile(sArg);
sArg = GetParam("ispoofformat"); m_pModule->GetZNC()->SetISpoofFormat(sArg);
//sArg = GetParam(""); if (!sArg.empty()) { m_pModule->GetZNC()->Set(sArg); }
sArg = GetParam("statusprefix"); CZNC::Get().SetStatusPrefix(sArg);
sArg = GetParam("ispooffile"); CZNC::Get().SetISpoofFile(sArg);
sArg = GetParam("ispoofformat"); CZNC::Get().SetISpoofFormat(sArg);
//sArg = GetParam(""); if (!sArg.empty()) { CZNC::Get().Set(sArg); }
VCString vsArgs = GetParam("vhosts").Split("\n");
m_pModule->GetZNC()->ClearVHosts();
CZNC::Get().ClearVHosts();
unsigned int a = 0;
for (a = 0; a < vsArgs.size(); a++) {
m_pModule->GetZNC()->AddVHost(vsArgs[a].Trim_n());
CZNC::Get().AddVHost(vsArgs[a].Trim_n());
}
set<CString> ssArgs;
@@ -451,8 +451,8 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
CString sArgs = GetParam("modargs_" + sModName);
try {
if (!m_pModule->GetZNC()->GetModules().FindModule(sModName)) {
if (!m_pModule->GetZNC()->GetModules().LoadModule(sModName, sArgs, NULL, sModRet)) {
if (!CZNC::Get().GetModules().FindModule(sModName)) {
if (!CZNC::Get().GetModules().LoadModule(sModName, sArgs, NULL, sModRet)) {
DEBUG_ONLY(cerr << "Unable to load module [" << sModName << "] [" << sModRet << "]" << endl);
}
} else {
@@ -464,7 +464,7 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
}
}
const CModules& vCurMods = m_pModule->GetZNC()->GetModules();
const CModules& vCurMods = CZNC::Get().GetModules();
set<CString> ssUnloadMods;
for (a = 0; a < vCurMods.size(); a++) {
@@ -476,10 +476,10 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
}
for (set<CString>::iterator it2 = ssUnloadMods.begin(); it2 != ssUnloadMods.end(); it2++) {
m_pModule->GetZNC()->GetModules().UnloadModule(*it2);
CZNC::Get().GetModules().UnloadModule(*it2);
}
if (!m_pModule->GetZNC()->WriteConfig()) {
if (!CZNC::Get().WriteConfig()) {
GetErrorPage(sPageRet, "Settings changed, but config was not written");
return true;
}
@@ -568,7 +568,7 @@ bool CWebAdminSock::ChanPage(CString& sPageRet, CChan* pChan) {
}
}
if (!m_pModule->GetZNC()->WriteConfig()) {
if (!CZNC::Get().WriteConfig()) {
GetErrorPage(sPageRet, "Channel added/modified, but config was not written");
return true;
}
@@ -593,7 +593,7 @@ bool CWebAdminSock::DelChan(CString& sPageRet) {
m_pUser->DelChan(sChan);
m_pUser->PutIRC("PART " + sChan);
if (!m_pModule->GetZNC()->WriteConfig()) {
if (!CZNC::Get().WriteConfig()) {
GetErrorPage(sPageRet, "Channel deleted, but config was not written");
return true;
}
@@ -665,7 +665,7 @@ bool CWebAdminSock::UserPage(CString& sPageRet, CUser* pUser) {
"<div><small><b>RealName:</b></small><br>\r\n"
"<input type='text' name='realname' value='" + CString((pUser) ? pUser->GetRealName().Escape_n(CString::EHTML) : "") + "' size='68' maxlength='256'></div><br>\r\n";
const VCString& vsVHosts = m_pModule->GetZNC()->GetVHosts();
const VCString& vsVHosts = CZNC::Get().GetVHosts();
if (vsVHosts.size()) {
sPageRet += "<small><b>VHost:</b></small><br>\r\n"
@@ -689,7 +689,7 @@ bool CWebAdminSock::UserPage(CString& sPageRet, CUser* pUser) {
"<tr style='font-weight: bold; background: #ff9;'><td style='border: 1px solid #000;'>Name</td><td style='border: 1px solid #000;'>Arguments</td><td style='border: 1px solid #000;'>Description</td></tr>\r\n";
set<CModInfo> ssUserMods;
m_pModule->GetZNC()->GetModules().GetAvailableMods(ssUserMods, m_pModule->GetZNC());
CZNC::Get().GetModules().GetAvailableMods(ssUserMods);
unsigned int uIdx = 0;
@@ -787,7 +787,7 @@ bool CWebAdminSock::UserPage(CString& sPageRet, CUser* pUser) {
}
CString sUsername = GetParam("user");
if (!pUser && m_pModule->GetZNC()->FindUser(sUsername)) {
if (!pUser && CZNC::Get().FindUser(sUsername)) {
GetErrorPage(sPageRet, "Invalid Submission [User " + sUsername + " already exists]");
return true;
}
@@ -807,8 +807,8 @@ bool CWebAdminSock::UserPage(CString& sPageRet, CUser* pUser) {
return true;
}
m_pModule->GetZNC()->AddUser(pNewUser);
if (!m_pModule->GetZNC()->WriteConfig()) {
CZNC::Get().AddUser(pNewUser);
if (!CZNC::Get().WriteConfig()) {
GetErrorPage(sPageRet, "User added, but config was not written");
return true;
}
@@ -821,7 +821,7 @@ bool CWebAdminSock::UserPage(CString& sPageRet, CUser* pUser) {
}
delete pNewUser;
if (!m_pModule->GetZNC()->WriteConfig()) {
if (!CZNC::Get().WriteConfig()) {
GetErrorPage(sPageRet, "User edited, but config was not written");
return true;
}
@@ -855,7 +855,7 @@ CUser* CWebAdminSock::GetNewUser(CString& sPageRet, CUser* pUser) {
return NULL;
}
CUser* pNewUser = new CUser(sUsername, m_pModule->GetZNC());
CUser* pNewUser = new CUser(sUsername);
if (!sArg.empty()) {
pNewUser->SetPass(sArg.MD5(), true);
+4 -4
View File
@@ -15,7 +15,7 @@
CZNC::CZNC() {
#ifdef _MODULES
m_pModules = new CGlobalModules(this);
m_pModules = new CGlobalModules();
#endif
m_uListenPort = 0;
m_bISpoofLocked = false;
@@ -397,7 +397,7 @@ bool CZNC::WriteNewConfig(const CString& sConfig) {
#ifdef _MODULES
set<CModInfo> ssGlobalMods;
GetModules().GetAvailableMods(ssGlobalMods, this, true);
GetModules().GetAvailableMods(ssGlobalMods, true);
if (ssGlobalMods.size()) {
CUtils::PrintMessage("");
@@ -482,7 +482,7 @@ bool CZNC::WriteNewConfig(const CString& sConfig) {
#ifdef _MODULES
set<CModInfo> ssUserMods;
GetModules().GetAvailableMods(ssUserMods, this);
GetModules().GetAvailableMods(ssUserMods);
if (ssUserMods.size()) {
vsLines.push_back("");
@@ -737,7 +737,7 @@ bool CZNC::ParseConfig(const CString& sConfig) {
return false;
}
pUser = new CUser(sValue, this);
pUser = new CUser(sValue);
CUtils::PrintMessage("Loading user [" + sValue + "]");
if (!m_sStatusPrefix.empty()) {