2 * Copyright (C) 2004-2011 See the AUTHORS file for details.
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.
12 #include "zncconfig.h"
22 class CConnectUserTimer
;
23 class CConfigWriteTimer
;
36 ECONFIG_NEED_VERBOSE_WRITE
,
42 bool WritePidFile(int iPid
);
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
);
50 CString
ExpandConfigPath(const CString
& sConfigFile
, bool bAllowMkDir
= true);
51 bool WriteNewConfig(const CString
& sConfigFile
);
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
; }
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
);
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
);
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
);
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
; }
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
; }
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
); }
133 CListener
* FindListener(u_short uPort
, const CString
& BindHost
, EAddrType eAddr
);
134 bool AddListener(CListener
*);
135 bool DelListener(CListener
*);
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
; }
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();
150 // Never call this unless you are CConnectUserTimer::~CConnectUserTimer()
151 void LeakConnectUser(CConnectUserTimer
*pTimer
);
153 void DisableConfigTimer();
155 static void DumpConfig(const CConfig
* Config
);
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
);
166 time_t m_TimeStarted
;
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
;
177 CString m_sConfigFile
;
179 CString m_sStatusPrefix
;
181 CString m_sSSLCertFile
;
182 VCString m_vsBindHosts
;
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
;