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 {
37 FILES_STORE_SETTINGS();
38 int ParseSettings(const STG::ModuleSettings & s);
39 const std::string & GetStrError() const;
41 std::string GetWorkDir() const { return workDir; }
42 std::string GetUsersDir() const { return usersDir; }
43 std::string GetAdminsDir() const { return adminsDir; }
44 std::string GetTariffsDir() const { return tariffsDir; }
45 std::string GetServicesDir() const { return servicesDir; }
47 mode_t GetStatMode() const { return statMode; }
48 mode_t GetStatModeDir() const;
49 uid_t GetStatUID() const { return statUID; }
50 gid_t GetStatGID() const { return statGID; }
52 mode_t GetConfMode() const { return confMode; }
53 mode_t GetConfModeDir() const;
54 uid_t GetConfUID() const { return confUID; }
55 gid_t GetConfGID() const { return confGID; }
57 mode_t GetLogMode() const { return userLogMode; }
58 uid_t GetLogUID() const { return userLogUID; }
59 gid_t GetLogGID() const { return userLogGID; }
61 bool GetRemoveBak() const { return removeBak; }
62 bool GetReadBak() const { return readBak; }
65 FILES_STORE_SETTINGS(const FILES_STORE_SETTINGS & rvalue);
66 FILES_STORE_SETTINGS & operator=(const FILES_STORE_SETTINGS & rvalue);
68 const STG::ModuleSettings * settings;
70 int User2UID(const char * user, uid_t * uid);
71 int Group2GID(const char * gr, gid_t * gid);
72 int Str2Mode(const char * str, mode_t * mode);
73 int ParseOwner(const std::vector<STG::ParamValue> & moduleParams, const std::string & owner, uid_t * uid);
74 int ParseGroup(const std::vector<STG::ParamValue> & moduleParams, const std::string & group, uid_t * uid);
75 int ParseMode(const std::vector<STG::ParamValue> & moduleParams, const std::string & modeStr, mode_t * mode);
76 int ParseYesNo(const std::string & value, bool * val);
82 std::string adminsDir;
83 std::string tariffsDir;
84 std::string servicesDir;
101 //-----------------------------------------------------------------------------
102 class FILES_STORE: public STG::Store {
105 const std::string & GetStrError() const override { return errorStr; }
108 int GetUsersList(std::vector<std::string> * usersList) const override;
109 int AddUser(const std::string & login) const override;
110 int DelUser(const std::string & login) const override;
111 int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
112 int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
114 int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
115 int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
117 int WriteUserChgLog(const std::string & login,
118 const std::string & admLogin,
120 const std::string & paramName,
121 const std::string & oldValue,
122 const std::string & newValue,
123 const std::string & message = "") const override;
124 int WriteUserConnect(const std::string & login, uint32_t ip) const override;
125 int WriteUserDisconnect(const std::string & login,
126 const STG::DirTraff & up,
127 const STG::DirTraff & down,
128 const STG::DirTraff & sessionUp,
129 const STG::DirTraff & sessionDown,
132 const std::string & reason) const override;
134 int WriteDetailedStat(const STG::TraffStat & statTree,
136 const std::string & login) const override;
138 int AddMessage(STG::Message * msg, const std::string & login) const override;
139 int EditMessage(const STG::Message & msg, const std::string & login) const override;
140 int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
141 int DelMessage(uint64_t id, const std::string & login) const override;
142 int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
144 int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
147 int GetAdminsList(std::vector<std::string> * adminsList) const override;
148 int AddAdmin(const std::string & login) const override;
149 int DelAdmin(const std::string & login) const override;
150 int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
151 int SaveAdmin(const STG::AdminConf & ac) const override;
154 int GetTariffsList(std::vector<std::string> * tariffsList) const override;
155 int AddTariff(const std::string & name) const override;
156 int DelTariff(const std::string & name) const override;
157 int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
158 int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
161 int GetCorpsList(std::vector<std::string> *) const override { return 0; }
162 int SaveCorp(const STG::CorpConf &) const override { return 0; }
163 int RestoreCorp(STG::CorpConf *, const std::string &) const override { return 0; }
164 int AddCorp(const std::string &) const override { return 0; }
165 int DelCorp(const std::string &) const override { return 0; }
168 int GetServicesList(std::vector<std::string> *) const override;
169 int SaveService(const STG::ServiceConf &) const override;
170 int RestoreService(STG::ServiceConf *, const std::string &) const override;
171 int AddService(const std::string &) const override;
172 int DelService(const std::string &) const override;
174 void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
175 int ParseSettings() override;
176 const std::string & GetVersion() const override { return version; }
179 FILES_STORE(const FILES_STORE & rvalue);
180 FILES_STORE & operator=(const FILES_STORE & rvalue);
182 int ReadMessage(const std::string & fileName,
183 STG::Message::Header * hdr,
184 std::string * text) const;
186 virtual int RestoreUserStat(STG::UserStat * stat, const std::string & login, const std::string & fileName) const;
187 virtual int RestoreUserConf(STG::UserConf * conf, const std::string & login, const std::string & fileName) const;
189 virtual int WriteLogString(const std::string & str, const std::string & login) const;
190 virtual int WriteLog2String(const std::string & str, const std::string & login) const;
191 int RemoveDir(const char * path) const;
192 int Touch(const std::string & path) const;
194 mutable std::string errorStr;
196 FILES_STORE_SETTINGS storeSettings;
197 STG::ModuleSettings settings;
198 mutable pthread_mutex_t mutex;
200 STG::PluginLogger logger;