-
Notifications
You must be signed in to change notification settings - Fork 1
/
znc.h
195 lines (172 loc) · 7 KB
/
znc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Copyright (C) 2004-2011 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#ifndef _ZNC_H
#define _ZNC_H
#include "zncconfig.h"
#include "Client.h"
#include "Modules.h"
#include "Socket.h"
#include "Listener.h"
#include <map>
using std::map;
class CListener;
class CUser;
class CIRCNetwork;
class CConnectUserTimer;
class CConfig;
class CFile;
class CZNC {
public:
CZNC();
~CZNC();
enum ConfigState {
ECONFIG_NOTHING,
ECONFIG_NEED_REHASH,
ECONFIG_NEED_WRITE
};
void DeleteUsers();
void Loop();
bool WritePidFile(int iPid);
bool DeletePidFile();
bool WaitForChildLock();
bool IsHostAllowed(const CString& sHostMask) const;
// This returns false if there are too many anonymous connections from this ip
bool AllowConnectionFrom(const CString& sIP) const;
void InitDirs(const CString& sArgvPath, const CString& sDataDir);
bool OnBoot();
CString ExpandConfigPath(const CString& sConfigFile, bool bAllowMkDir = true);
bool WriteNewConfig(const CString& sConfigFile);
bool WriteConfig();
bool ParseConfig(const CString& sConfig);
bool RehashConfig(CString& sError);
void BackupConfigOnce(const CString& sSuffix);
static CString GetVersion();
static CString GetTag(bool bIncludeVersion = true);
CString GetUptime() const;
void ClearBindHosts();
bool AddBindHost(const CString& sHost);
bool RemBindHost(const CString& sHost);
void Broadcast(const CString& sMessage, bool bAdminOnly = false,
CUser* pSkipUser = NULL, CClient* pSkipClient = NULL);
void AddBytesRead(unsigned long long u) { m_uBytesRead += u; }
void AddBytesWritten(unsigned long long u) { m_uBytesWritten += u; }
unsigned long long BytesRead() const { return m_uBytesRead; }
unsigned long long BytesWritten() const { return m_uBytesWritten; }
// Traffic fun
typedef std::pair<unsigned long long, unsigned long long> TrafficStatsPair;
typedef std::map<CString, TrafficStatsPair> TrafficStatsMap;
// Returns a map which maps user names to <traffic in, traffic out>
// while also providing the traffic of all users together, traffic which
// couldn't be accounted to any particular user and the total traffic
// generated through ZNC.
TrafficStatsMap GetTrafficStats(TrafficStatsPair &Users,
TrafficStatsPair &ZNC, TrafficStatsPair &Total);
// Authenticate a user.
// The result is passed back via callbacks to CAuthBase.
// CSmartPtr handles freeing this pointer!
void AuthUser(CSmartPtr<CAuthBase> AuthClass);
// Setters
void SetConfigState(enum ConfigState e) { m_eConfigState = e; }
void SetSkinName(const CString& s) { m_sSkinName = s; }
void SetStatusPrefix(const CString& s) { m_sStatusPrefix = (s.empty()) ? "*" : s; }
void SetMaxBufferSize(unsigned int i) { m_uiMaxBufferSize = i; }
void SetAnonIPLimit(unsigned int i) { m_uiAnonIPLimit = i; }
void SetServerThrottle(unsigned int i) { m_sConnectThrottle.SetTTL(i*1000); }
void SetProtectWebSessions(bool b) { m_bProtectWebSessions = b; }
void SetConnectDelay(unsigned int i);
// !Setters
// Getters
enum ConfigState GetConfigState() const { return m_eConfigState; }
CSockManager& GetManager() { return m_Manager; }
const CSockManager& GetManager() const { return m_Manager; }
CModules& GetModules() { return *m_pModules; }
size_t FilterUncommonModules(set<CModInfo>& ssModules);
CString GetSkinName() const { return m_sSkinName; }
const CString& GetStatusPrefix() const { return m_sStatusPrefix; }
const CString& GetCurPath() const;
const CString& GetHomePath() const;
const CString& GetZNCPath() const;
CString GetConfPath(bool bAllowMkDir = true) const;
CString GetUserPath() const;
CString GetModPath() const;
CString GetPemLocation() const;
const CString& GetConfigFile() const { return m_sConfigFile; }
bool WritePemFile();
const VCString& GetBindHosts() const { return m_vsBindHosts; }
const vector<CListener*>& GetListeners() const { return m_vpListeners; }
time_t TimeStarted() const { return m_TimeStarted; }
unsigned int GetMaxBufferSize() const { return m_uiMaxBufferSize; }
unsigned int GetAnonIPLimit() const { return m_uiAnonIPLimit; }
unsigned int GetServerThrottle() const { return m_sConnectThrottle.GetTTL() / 1000; }
unsigned int GetConnectDelay() const { return m_uiConnectDelay; }
bool GetProtectWebSessions() const { return m_bProtectWebSessions; }
// !Getters
// Static allocator
static CZNC& Get();
CUser* FindUser(const CString& sUsername);
CModule* FindModule(const CString& sModName, const CString& sUsername);
CModule* FindModule(const CString& sModName, CUser* pUser);
bool DeleteUser(const CString& sUsername);
bool AddUser(CUser* pUser, CString& sErrorRet);
const map<CString,CUser*> & GetUserMap() const { return(m_msUsers); }
// Listener yummy
CListener* FindListener(u_short uPort, const CString& BindHost, EAddrType eAddr);
bool AddListener(CListener*);
bool DelListener(CListener*);
// Message of the Day
void SetMotd(const CString& sMessage) { ClearMotd(); AddMotd(sMessage); }
void AddMotd(const CString& sMessage) { if (!sMessage.empty()) { m_vsMotd.push_back(sMessage); } }
void ClearMotd() { m_vsMotd.clear(); }
const VCString& GetMotd() const { return m_vsMotd; }
// !MOTD
// Create a CIRCSocket. Return false if user cant connect
bool ConnectNetwork(CIRCNetwork *pNetwork);
// This creates a CConnectUserTimer if we haven't got one yet
void EnableConnectUser();
void DisableConnectUser();
// Never call this unless you are CConnectUserTimer::~CConnectUserTimer()
void LeakConnectUser(CConnectUserTimer *pTimer);
static void DumpConfig(const CConfig* Config);
private:
CFile* InitPidFile();
bool DoRehash(CString& sError);
// Returns true if something was done
bool HandleUserDeletion();
CString MakeConfigHeader();
bool AddListener(const CString& sLine, CString& sError);
bool AddListener(CConfig* pConfig, CString& sError);
bool AddListener(unsigned int uPort, const CString& sBindHost, bool bSSL,
EAddrType eAddr, CListener::EAcceptType eAccept, CString& sError);
protected:
time_t m_TimeStarted;
enum ConfigState m_eConfigState;
vector<CListener*> m_vpListeners;
map<CString,CUser*> m_msUsers;
map<CString,CUser*> m_msDelUsers;
CSockManager m_Manager;
CString m_sCurPath;
CString m_sZNCPath;
CString m_sConfigFile;
CString m_sSkinName;
CString m_sStatusPrefix;
CString m_sPidFile;
CString m_sSSLCertFile;
VCString m_vsBindHosts;
VCString m_vsMotd;
CFile* m_pLockFile;
unsigned int m_uiConnectDelay;
unsigned int m_uiAnonIPLimit;
unsigned int m_uiMaxBufferSize;
CModules* m_pModules;
unsigned long long m_uBytesRead;
unsigned long long m_uBytesWritten;
CConnectUserTimer *m_pConnectUserTimer;
TCacheMap<CString> m_sConnectThrottle;
bool m_bProtectWebSessions;
};
#endif // !_ZNC_H