2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23 #include "stg/module_settings.h"
24 #include "stg/store.h"
25 #include "stg/conffiles.h"
26 #include "stg/user_traff.h"
27 #include "stg/logger.h"
31 #include <sys/types.h>
34 //-----------------------------------------------------------------------------
35 class FILES_STORE_SETTINGS
38 FILES_STORE_SETTINGS();
40 FILES_STORE_SETTINGS(const FILES_STORE_SETTINGS&) = default;
41 FILES_STORE_SETTINGS& operator=(const FILES_STORE_SETTINGS&) = default;
42 FILES_STORE_SETTINGS(FILES_STORE_SETTINGS&&) = default;
43 FILES_STORE_SETTINGS& operator=(FILES_STORE_SETTINGS&&) = default;
45 int ParseSettings(const STG::ModuleSettings & s);
46 const std::string & GetStrError() const;
48 std::string GetWorkDir() const { return m_workDir; }
49 std::string GetUsersDir() const { return m_usersDir; }
50 std::string GetAdminsDir() const { return m_adminsDir; }
51 std::string GetTariffsDir() const { return m_tariffsDir; }
52 std::string GetServicesDir() const { return m_servicesDir; }
54 mode_t GetStatMode() const { return m_statMode; }
55 mode_t GetStatModeDir() const;
56 uid_t GetStatUID() const { return m_statUID; }
57 gid_t GetStatGID() const { return m_statGID; }
59 mode_t GetConfMode() const { return m_confMode; }
60 mode_t GetConfModeDir() const;
61 uid_t GetConfUID() const { return m_confUID; }
62 gid_t GetConfGID() const { return m_confGID; }
64 mode_t GetLogMode() const { return m_userLogMode; }
65 uid_t GetLogUID() const { return m_userLogUID; }
66 gid_t GetLogGID() const { return m_userLogGID; }
68 bool GetRemoveBak() const { return m_removeBak; }
69 bool GetReadBak() const { return m_readBak; }
73 int User2UID(const char * user, uid_t * uid);
74 int Group2GID(const char * gr, gid_t * gid);
75 int Str2Mode(const char * str, mode_t * mode);
76 int ParseOwner(const std::vector<STG::ParamValue> & moduleParams, const std::string & owner, uid_t * uid);
77 int ParseGroup(const std::vector<STG::ParamValue> & moduleParams, const std::string & group, uid_t * uid);
78 int ParseMode(const std::vector<STG::ParamValue> & moduleParams, const std::string & modeStr, mode_t * mode);
79 int ParseYesNo(const std::string & value, bool * val);
81 std::string m_errorStr;
83 std::string m_workDir;
84 std::string m_usersDir;
85 std::string m_adminsDir;
86 std::string m_tariffsDir;
87 std::string m_servicesDir;
104 //-----------------------------------------------------------------------------
105 class FILES_STORE: public STG::Store
110 FILES_STORE(const FILES_STORE&) = delete;
111 FILES_STORE & operator=(const FILES_STORE&) = delete;
113 const std::string & GetStrError() const override { return m_errorStr; }
116 int GetUsersList(std::vector<std::string> * usersList) const override;
117 int AddUser(const std::string & login) const override;
118 int DelUser(const std::string & login) const override;
119 int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
120 int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
122 int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
123 int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
125 int WriteUserChgLog(const std::string & login,
126 const std::string & admLogin,
128 const std::string & paramName,
129 const std::string & oldValue,
130 const std::string & newValue,
131 const std::string & message = "") const override;
132 int WriteUserConnect(const std::string & login, uint32_t ip) const override;
133 int WriteUserDisconnect(const std::string & login,
134 const STG::DirTraff & up,
135 const STG::DirTraff & down,
136 const STG::DirTraff & sessionUp,
137 const STG::DirTraff & sessionDown,
140 const std::string & reason) const override;
142 int WriteDetailedStat(const STG::TraffStat & statTree,
144 const std::string & login) const override;
146 int AddMessage(STG::Message * msg, const std::string & login) const override;
147 int EditMessage(const STG::Message & msg, const std::string & login) const override;
148 int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
149 int DelMessage(uint64_t id, const std::string & login) const override;
150 int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
152 int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
155 int GetAdminsList(std::vector<std::string> * adminsList) const override;
156 int AddAdmin(const std::string & login) const override;
157 int DelAdmin(const std::string & login) const override;
158 int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
159 int SaveAdmin(const STG::AdminConf & ac) const override;
162 int GetTariffsList(std::vector<std::string> * tariffsList) const override;
163 int AddTariff(const std::string & name) const override;
164 int DelTariff(const std::string & name) const override;
165 int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
166 int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
169 int GetCorpsList(std::vector<std::string> *) const override { return 0; }
170 int SaveCorp(const STG::CorpConf &) const override { return 0; }
171 int RestoreCorp(STG::CorpConf *, const std::string &) const override { return 0; }
172 int AddCorp(const std::string &) const override { return 0; }
173 int DelCorp(const std::string &) const override { return 0; }
176 int GetServicesList(std::vector<std::string> *) const override;
177 int SaveService(const STG::ServiceConf &) const override;
178 int RestoreService(STG::ServiceConf *, const std::string &) const override;
179 int AddService(const std::string &) const override;
180 int DelService(const std::string &) const override;
182 void SetSettings(const STG::ModuleSettings & s) override { m_settings = s; }
183 int ParseSettings() override;
184 const std::string & GetVersion() const override { return m_version; }
187 int ReadMessage(const std::string & fileName,
188 STG::Message::Header * hdr,
189 std::string * text) const;
191 int RemoveDir(const char * path) const;
192 int Touch(const std::string & path) const;
194 int RestoreUserStat(STG::UserStat * stat, const std::string & login, const std::string & fileName) const;
195 int RestoreUserConf(STG::UserConf * conf, const std::string & login, const std::string & fileName) const;
197 int WriteLogString(const std::string & str, const std::string & login) const;
198 int WriteLog2String(const std::string & str, const std::string & login) const;
200 mutable std::string m_errorStr;
201 std::string m_version;
202 FILES_STORE_SETTINGS m_storeSettings;
203 STG::ModuleSettings m_settings;
204 mutable pthread_mutex_t m_mutex;
206 STG::PluginLogger m_logger;