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 $Date: 2010/01/19 11:06:53 $
31 #include <sys/types.h>
36 #include "stg/module_settings.h"
37 #include "stg/store.h"
38 #include "stg/conffiles.h"
39 #include "stg/user_traff.h"
40 #include "stg/logger.h"
42 //-----------------------------------------------------------------------------
43 extern "C" STORE * GetStore();
44 //-----------------------------------------------------------------------------
45 class FILES_STORE_SETTINGS {
47 FILES_STORE_SETTINGS();
48 int ParseSettings(const MODULE_SETTINGS & s);
49 const std::string & GetStrError() const;
51 std::string GetWorkDir() const { return workDir; }
52 std::string GetUsersDir() const { return usersDir; }
53 std::string GetAdminsDir() const { return adminsDir; }
54 std::string GetTariffsDir() const { return tariffsDir; }
56 mode_t GetStatMode() const { return statMode; }
57 mode_t GetStatModeDir() const;
58 uid_t GetStatUID() const { return statUID; }
59 gid_t GetStatGID() const { return statGID; }
61 mode_t GetConfMode() const { return confMode; }
62 mode_t GetConfModeDir() const;
63 uid_t GetConfUID() const { return confUID; }
64 gid_t GetConfGID() const { return confGID; }
66 mode_t GetLogMode() const { return userLogMode; }
67 uid_t GetLogUID() const { return userLogUID; }
68 gid_t GetLogGID() const { return userLogGID; }
70 bool GetRemoveBak() const { return removeBak; }
71 bool GetReadBak() const { return readBak; }
74 FILES_STORE_SETTINGS(const FILES_STORE_SETTINGS & rvalue);
75 FILES_STORE_SETTINGS & operator=(const FILES_STORE_SETTINGS & rvalue);
77 const MODULE_SETTINGS * settings;
79 int User2UID(const char * user, uid_t * uid);
80 int Group2GID(const char * gr, gid_t * gid);
81 int Str2Mode(const char * str, mode_t * mode);
82 int ParseOwner(const std::vector<PARAM_VALUE> & moduleParams, const std::string & owner, uid_t * uid);
83 int ParseGroup(const std::vector<PARAM_VALUE> & moduleParams, const std::string & group, uid_t * uid);
84 int ParseMode(const std::vector<PARAM_VALUE> & moduleParams, const std::string & modeStr, mode_t * mode);
85 int ParseYesNo(const std::string & value, bool * val);
91 std::string adminsDir;
92 std::string tariffsDir;
109 //-----------------------------------------------------------------------------
110 class FILES_STORE: public STORE {
113 virtual ~FILES_STORE() {}
114 virtual const std::string & GetStrError() const { return errorStr; }
117 virtual int GetUsersList(std::vector<std::string> * usersList) const;
118 virtual int AddUser(const std::string & login) const;
119 virtual int DelUser(const std::string & login) const;
120 virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const;
121 virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const;
123 virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const;
124 virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const;
126 virtual int WriteUserChgLog(const std::string & login,
127 const std::string & admLogin,
129 const std::string & paramName,
130 const std::string & oldValue,
131 const std::string & newValue,
132 const std::string & message = "") const;
133 virtual int WriteUserConnect(const std::string & login, uint32_t ip) const;
134 virtual int WriteUserDisconnect(const std::string & login,
135 const DIR_TRAFF & up,
136 const DIR_TRAFF & down,
137 const DIR_TRAFF & sessionUp,
138 const DIR_TRAFF & sessionDown,
141 const std::string & reason) const;
143 virtual int WriteDetailedStat(const TRAFF_STAT & statTree,
145 const std::string & login) const;
147 virtual int AddMessage(STG_MSG * msg, const std::string & login) const;
148 virtual int EditMessage(const STG_MSG & msg, const std::string & login) const;
149 virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const;
150 virtual int DelMessage(uint64_t id, const std::string & login) const;
151 virtual int GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const;
152 virtual int ReadMessage(const std::string & fileName,
154 std::string * text) const;
156 virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const;
159 virtual int GetAdminsList(std::vector<std::string> * adminsList) const;
160 virtual int AddAdmin(const std::string & login) const;
161 virtual int DelAdmin(const std::string & login) const;
162 virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const;
163 virtual int SaveAdmin(const ADMIN_CONF & ac) const;
166 virtual int GetTariffsList(std::vector<std::string> * tariffsList) const;
167 virtual int AddTariff(const std::string & name) const;
168 virtual int DelTariff(const std::string & name) const;
169 virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const;
170 virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const;
173 virtual int GetCorpsList(std::vector<std::string> *) const { return 0; }
174 virtual int SaveCorp(const CORP_CONF &) const { return 0; }
175 virtual int RestoreCorp(CORP_CONF *, const std::string &) const { return 0; }
176 virtual int AddCorp(const std::string &) const { return 0; }
177 virtual int DelCorp(const std::string &) const { return 0; }
180 virtual int GetServicesList(std::vector<std::string> *) const { return 0; }
181 virtual int SaveService(const SERVICE_CONF &) const { return 0; }
182 virtual int RestoreService(SERVICE_CONF *, const std::string &) const { return 0; }
183 virtual int AddService(const std::string &) const { return 0; }
184 virtual int DelService(const std::string &) const { return 0; }
186 virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
187 virtual int ParseSettings();
188 virtual const std::string & GetVersion() const { return version; }
191 FILES_STORE(const FILES_STORE & rvalue);
192 FILES_STORE & operator=(const FILES_STORE & rvalue);
194 virtual int RestoreUserStat(USER_STAT * stat, const std::string & login, const std::string & fileName) const;
195 virtual int RestoreUserConf(USER_CONF * conf, const std::string & login, const std::string & fileName) const;
197 virtual int WriteLogString(const std::string & str, const std::string & login) const;
198 virtual int WriteLog2String(const std::string & str, const std::string & login) const;
199 int RemoveDir(const char * path) const;
200 int Touch(const std::string & path) const;
202 mutable string errorStr;
204 FILES_STORE_SETTINGS storeSettings;
205 MODULE_SETTINGS settings;
206 mutable pthread_mutex_t mutex;
208 PLUGIN_LOGGER logger;
210 //-----------------------------------------------------------------------------