91
90
enum ConfigState GetConfigState() const { return m_eConfigState; }
92
91
CSockManager& GetManager() { return m_Manager; }
93
92
const CSockManager& GetManager() const { return m_Manager; }
95
93
CGlobalModules& GetModules() { return *m_pModules; }
96
94
size_t FilterUncommonModules(set<CModInfo>& ssModules);
95
CString GetSkinName() const { return m_sSkinName; }
98
96
const CString& GetStatusPrefix() const { return m_sStatusPrefix; }
99
97
const CString& GetCurPath() const { if (!CFile::Exists(m_sCurPath)) { CDir::MakeDir(m_sCurPath); } return m_sCurPath; }
100
98
const CString& GetHomePath() const { if (!CFile::Exists(m_sHomePath)) { CDir::MakeDir(m_sHomePath); } return m_sHomePath; }
101
99
const CString& GetZNCPath() const { if (!CFile::Exists(m_sZNCPath)) { CDir::MakeDir(m_sZNCPath); } return m_sZNCPath; }
102
CString GetConfPath() const;
100
CString GetConfPath(bool bAllowMkDir = true) const;
103
101
CString GetUserPath() const;
104
102
CString GetModPath() const;
105
103
CString GetPemLocation() const { return GetZNCPath() + "/znc.pem"; }
115
113
// Static allocator
116
114
static CZNC& Get();
117
115
CUser* FindUser(const CString& sUsername);
116
CModule* FindModule(const CString& sModName, const CString& sUsername);
117
CModule* FindModule(const CString& sModName, CUser* pUser);
118
118
bool DeleteUser(const CString& sUsername);
119
119
bool AddUser(CUser* pUser, CString& sErrorRet);
120
120
const map<CString,CUser*> & GetUserMap() const { return(m_msUsers); }
123
CListener* FindListener(u_short uPort, const CString& BindHost, EAddrType eAddr);
124
bool AddListener(CListener*);
125
bool DelListener(CListener*);
122
127
// Message of the Day
123
128
void SetMotd(const CString& sMessage) { ClearMotd(); AddMotd(sMessage); }
124
129
void AddMotd(const CString& sMessage) { if (!sMessage.empty()) { m_vsMotd.push_back(sMessage); } }
136
141
void LeakConnectUser(CConnectUserTimer *pTimer);
144
CFile* InitPidFile();
139
145
bool DoRehash(CString& sError);
140
146
// Returns true if something was done
141
147
bool HandleUserDeletion();
144
time_t m_TimeStarted;
146
enum ConfigState m_eConfigState;
147
vector<CListener*> m_vpListeners;
148
map<CString,CUser*> m_msUsers;
149
map<CString,CUser*> m_msDelUsers;
150
CSockManager m_Manager;
156
CString m_sConfigFile;
157
CString m_sStatusPrefix;
158
CString m_sISpoofFile;
159
CString m_sOrigISpoof;
160
CString m_sISpoofFormat;
165
CFile* m_pISpoofLockFile;
166
unsigned int m_uiConnectDelay;
167
unsigned int m_uiAnonIPLimit;
169
CGlobalModules* m_pModules;
171
unsigned long long m_uBytesRead;
172
unsigned long long m_uBytesWritten;
173
CConnectUserTimer *m_pConnectUserTimer;
174
TCacheMap<CString> m_sConnectThrottle;
177
class CRealListener : public CZNCSock {
179
CRealListener() : CZNCSock() {}
180
virtual ~CRealListener() {}
182
virtual bool ConnectionFrom(const CString& sHost, unsigned short uPort) {
183
DEBUG(GetSockName() << " == ConnectionFrom(" << sHost << ", " << uPort << ")");
184
return CZNC::Get().IsHostAllowed(sHost);
187
virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort) {
188
CClient *pClient = new CClient(sHost, uPort);
189
if (CZNC::Get().AllowConnectionFrom(sHost)) {
191
CZNC::Get().GetModules().OnClientConnect(pClient, sHost, uPort);
194
pClient->RefuseLogin("Too many anonymous connections from your IP");
196
CZNC::Get().GetModules().OnFailedLogin("", sHost);
202
virtual void SockError(int iErrno) {
203
DEBUG(GetSockName() << " == SockError(" << strerror(iErrno) << ")");
204
if (iErrno == EMFILE) {
205
// We have too many open fds, let's close this listening port to be able to continue
206
// to work, next rehash will (try to) reopen it.
214
CListener(unsigned short uPort, const CString& sBindHost, bool bSSL, bool bIPV6) {
216
m_sBindHost = sBindHost;
224
CZNC::Get().GetManager().DelSockByAddr(m_pListener);
228
void SetSSL(bool b) { m_bSSL = b; }
229
void SetIPV6(bool b) { m_bIPV6 = b; }
230
void SetPort(unsigned short u) { m_uPort = u; }
231
void SetBindHost(const CString& s) { m_sBindHost = s; }
235
bool IsSSL() const { return m_bSSL; }
236
bool IsIPV6() const { return m_bIPV6; }
237
unsigned short GetPort() const { return m_uPort; }
238
const CString& GetBindHost() const { return m_sBindHost; }
239
CRealListener* GetRealListener() const { return m_pListener; }
243
if (!m_uPort || m_pListener) {
247
m_pListener = new CRealListener;
253
m_pListener->SetPemLocation(CZNC::Get().GetPemLocation());
257
return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN,
258
m_pListener, 0, m_bIPV6);
264
unsigned short m_uPort;
266
CRealListener* m_pListener;
150
time_t m_TimeStarted;
152
enum ConfigState m_eConfigState;
153
vector<CListener*> m_vpListeners;
154
map<CString,CUser*> m_msUsers;
155
map<CString,CUser*> m_msDelUsers;
156
CSockManager m_Manager;
162
CString m_sConfigFile;
164
CString m_sStatusPrefix;
165
CString m_sISpoofFile;
166
CString m_sOrigISpoof;
167
CString m_sISpoofFormat;
172
CFile* m_pISpoofLockFile;
173
unsigned int m_uiConnectDelay;
174
unsigned int m_uiAnonIPLimit;
175
CGlobalModules* m_pModules;
176
unsigned long long m_uBytesRead;
177
unsigned long long m_uBytesWritten;
178
CConnectUserTimer *m_pConnectUserTimer;
179
TCacheMap<CString> m_sConnectThrottle;
269
182
#endif // !_ZNC_H