]> jfr.im git - irc/rizon/znc.git/blame - znc.h
Write forceserver and webircpassword to conf
[irc/rizon/znc.git] / znc.h
CommitLineData
a09a7e79 1/*
b9b0fd4c 2 * Copyright (C) 2004-2011 See the AUTHORS file for details.
a09a7e79 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 */
6dcacaa7 8
538d3ece 9#ifndef _ZNC_H
10#define _ZNC_H
11
3ecbf133 12#include "zncconfig.h"
f8bb245c 13#include "Client.h"
3dde793e 14#include "Modules.h"
65510446 15#include "Socket.h"
538d3ece 16#include <map>
e72c4456 17
538d3ece 18using std::map;
19
ca824705 20class CListener;
65510446 21class CUser;
a213258c 22class CConnectUserTimer;
672df0a8 23class CConfigWriteTimer;
70c77458 24class CConfig;
8e59f751 25class CFile;
a213258c 26
538d3ece 27class CZNC {
28public:
29 CZNC();
acd854eb 30 ~CZNC();
538d3ece 31
c1ee7248 32 enum ConfigState {
33 ECONFIG_NOTHING,
34 ECONFIG_NEED_REHASH,
672df0a8
A
35 ECONFIG_NEED_WRITE,
36 ECONFIG_NEED_VERBOSE_WRITE,
37 ECONFIG_WANT_WRITE
c1ee7248 38 };
39
538d3ece 40 void DeleteUsers();
e64b2549 41 void Loop();
538d3ece 42 bool WritePidFile(int iPid);
9a1c3874 43 bool DeletePidFile();
33ce80f4 44 bool WaitForChildLock();
86924339 45 bool IsHostAllowed(const CString& sHostMask) const;
b25e65db 46 // This returns false if there are too many anonymous connections from this ip
47 bool AllowConnectionFrom(const CString& sIP) const;
0a622749 48 void InitDirs(const CString& sArgvPath, const CString& sDataDir);
538d3ece 49 bool OnBoot();
f5c2528c 50 CString ExpandConfigPath(const CString& sConfigFile, bool bAllowMkDir = true);
de2f07ec 51 bool WriteNewConfig(const CString& sConfigFile);
1f090c4d 52 bool WriteConfig();
8e33a737 53 bool ParseConfig(const CString& sConfig);
54 bool RehashConfig(CString& sError);
d397cb8a 55 static CString GetVersion();
beb5b49b 56 static CString GetTag(bool bIncludeVersion = true);
86924339 57 CString GetUptime() const;
341263f9 58 void ClearBindHosts();
59 bool AddBindHost(const CString& sHost);
60 bool RemBindHost(const CString& sHost);
a773c13f 61 void Broadcast(const CString& sMessage, bool bAdminOnly = false,
62 CUser* pSkipUser = NULL, CClient* pSkipClient = NULL);
b772e266 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; }
85dce87d 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);
573c4be4 77
0bd4927d 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
573c4be4 83 // Setters
c1ee7248 84 void SetConfigState(enum ConfigState e) { m_eConfigState = e; }
ad92c58c 85 void SetSkinName(const CString& s) { m_sSkinName = s; }
7cb1d2f9 86 void SetStatusPrefix(const CString& s) { m_sStatusPrefix = (s.empty()) ? "*" : s; }
e62ca411 87 void SetMaxBufferSize(unsigned int i) { m_uiMaxBufferSize = i; }
0456e3f0 88 void SetAnonIPLimit(unsigned int i) { m_uiAnonIPLimit = i; }
89 void SetServerThrottle(unsigned int i) { m_sConnectThrottle.SetTTL(i*1000); }
a9ba4020 90 void SetProtectWebSessions(bool b) { m_bProtectWebSessions = b; }
0456e3f0 91 void SetConnectDelay(unsigned int i);
573c4be4 92 // !Setters
538d3ece 93
94 // Getters
c1ee7248 95 enum ConfigState GetConfigState() const { return m_eConfigState; }
0eaf9bdc 96 CSockManager& GetManager() { return m_Manager; }
b25e65db 97 const CSockManager& GetManager() const { return m_Manager; }
3dde793e 98 CGlobalModules& GetModules() { return *m_pModules; }
207478d3 99 size_t FilterUncommonModules(set<CModInfo>& ssModules);
ad92c58c 100 CString GetSkinName() const { return m_sSkinName; }
7cb1d2f9 101 const CString& GetStatusPrefix() const { return m_sStatusPrefix; }
8e59f751
US
102 const CString& GetCurPath() const;
103 const CString& GetHomePath() const;
104 const CString& GetZNCPath() const;
f5c2528c 105 CString GetConfPath(bool bAllowMkDir = true) const;
4b1fbab6 106 CString GetUserPath() const;
107 CString GetModPath() const;
8e59f751 108 CString GetPemLocation() const;
31a56a5c 109 const CString& GetConfigFile() const { return m_sConfigFile; }
b03f495b 110 bool WritePemFile();
341263f9 111 const VCString& GetBindHosts() const { return m_vsBindHosts; }
ca824705 112 const vector<CListener*>& GetListeners() const { return m_vpListeners; }
78f8cce2 113 time_t TimeStarted() const { return m_TimeStarted; }
e62ca411 114 unsigned int GetMaxBufferSize() const { return m_uiMaxBufferSize; }
0456e3f0 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; }
a9ba4020 118 bool GetProtectWebSessions() const { return m_bProtectWebSessions; }
a0cc3de4 119 CString GetWebircPassword() const { return m_webircPassword; }
6cabf380 120 CString GetForceServer() const { return m_forceServer; }
538d3ece 121 // !Getters
122
123 // Static allocator
2a32927d 124 static CZNC& Get();
c315a07d 125 CUser* FindUser(const CString& sUsername);
ad92c58c 126 CModule* FindModule(const CString& sModName, const CString& sUsername);
127 CModule* FindModule(const CString& sModName, CUser* pUser);
c315a07d 128 bool DeleteUser(const CString& sUsername);
e8d176ea 129 bool AddUser(CUser* pUser, CString& sErrorRet);
b0a1714b 130 const map<CString,CUser*> & GetUserMap() const { return(m_msUsers); }
a056702b 131
cac29752 132 // Listener yummy
133 CListener* FindListener(u_short uPort, const CString& BindHost, EAddrType eAddr);
134 bool AddListener(CListener*);
135 bool DelListener(CListener*);
136
d2e72850 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
a213258c 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();
a213258c 149
79212882 150 // Never call this unless you are CConnectUserTimer::~CConnectUserTimer()
151 void LeakConnectUser(CConnectUserTimer *pTimer);
152
672df0a8
A
153 void DisableConfigTimer();
154
70c77458
US
155 static void DumpConfig(const CConfig* Config);
156
538d3ece 157private:
e2b91a32 158 CFile* InitPidFile();
8e33a737 159 bool DoRehash(CString& sError);
45dae8a1 160 // Returns true if something was done
161 bool HandleUserDeletion();
2472ea7a 162 CString MakeConfigHeader();
70c77458 163 bool AddListener(const CString& sLine, CString& sError);
e326f6eb 164
538d3ece 165protected:
f2d7ae1a 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;
f2d7ae1a 175 CString m_sZNCPath;
176
177 CString m_sConfigFile;
178 CString m_sSkinName;
179 CString m_sStatusPrefix;
f2d7ae1a 180 CString m_sPidFile;
f82f3cf0 181 CString m_sSSLCertFile;
341263f9 182 VCString m_vsBindHosts;
f2d7ae1a 183 VCString m_vsMotd;
a4d388b5 184 CFile* m_pLockFile;
f2d7ae1a 185 unsigned int m_uiConnectDelay;
186 unsigned int m_uiAnonIPLimit;
e62ca411 187 unsigned int m_uiMaxBufferSize;
f2d7ae1a 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;
a9ba4020 193 bool m_bProtectWebSessions;
672df0a8 194 CConfigWriteTimer *m_pConfigTimer;
a0cc3de4 195 CString m_webircPassword;
6cabf380 196 CString m_forceServer;
538d3ece 197};
198
199#endif // !_ZNC_H