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