From: Maxim Mamontov Date: Thu, 7 Apr 2011 15:31:39 +0000 (+0300) Subject: Headers moved to subdir stg X-Git-Tag: 2.407-rc3~53 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/9701b7ab4dc4cd709ad4dcaa750fc0021f15e231 Headers moved to subdir stg --- diff --git a/include/admin.h b/include/admin.h deleted file mode 100644 index 7095bb62..00000000 --- a/include/admin.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#ifndef ADMIN_H -#define ADMIN_H - -#include - -#include "admin_conf.h" -#include "os_int.h" - -class ADMIN { -public: - virtual ADMIN & operator=(const ADMIN &) = 0; - virtual ADMIN & operator=(const ADMIN_CONF &) = 0; - virtual bool operator==(const ADMIN & rhs) const = 0; - virtual bool operator!=(const ADMIN & rhs) const = 0; - virtual bool operator<(const ADMIN & rhs) const = 0; - virtual bool operator<=(const ADMIN & rhs) const = 0; - - virtual const std::string & GetPassword() const = 0; - virtual const std::string & GetLogin() const = 0; - virtual PRIV const * GetPriv() const = 0; - virtual uint16_t GetPrivAsInt() const = 0; - virtual const ADMIN_CONF & GetConf() const = 0; - virtual uint32_t GetIP() const = 0; - virtual std::string GetIPStr() const = 0; - virtual void SetIP(uint32_t ip) = 0; - virtual const std::string GetLogStr() const = 0; -}; - -#endif diff --git a/include/admin_conf.h b/include/admin_conf.h deleted file mode 100644 index 32012f34..00000000 --- a/include/admin_conf.h +++ /dev/null @@ -1,77 +0,0 @@ - /* - $Revision: 1.9 $ - $Date: 2010/09/10 05:02:08 $ - $Author: faust $ - */ - -#ifndef ADMIN_CONF_H -#define ADMIN_CONF_H - -#include - -#include "os_int.h" - -#define ADM_LOGIN_LEN (32) -#define ADM_PASSWD_LEN (32) -//----------------------------------------------------------------------------- -struct PRIV -{ - PRIV() - : userStat(0), - userConf(0), - userCash(0), - userPasswd(0), - userAddDel(0), - adminChg(0), - tariffChg(0) - {}; - PRIV(uint16_t p) - : userStat((p & 0x0003) >> 0x00), - userConf((p & 0x000C) >> 0x02), - userCash((p & 0x0030) >> 0x04), - userPasswd((p & 0x00C0) >> 0x06), - userAddDel((p & 0x0300) >> 0x08), - adminChg((p & 0x0C00) >> 0x0A), - tariffChg((p & 0x3000) >> 0x0C) - {} - - uint16_t ToInt() const; - void FromInt(uint16_t p); - - uint16_t userStat; - uint16_t userConf; - uint16_t userCash; - uint16_t userPasswd; - uint16_t userAddDel; - uint16_t adminChg; - uint16_t tariffChg; -}; -//----------------------------------------------------------------------------- -struct ADMIN_CONF -{ - ADMIN_CONF() - : priv(), - login(), - password("* NO PASSWORD *") - {} - ADMIN_CONF(const ADMIN_CONF & rvalue) - : priv(rvalue.priv), - login(rvalue.login), - password(rvalue.password) - {} - ADMIN_CONF(const PRIV & pr, const std::string & l, const std::string & p) - : priv(pr), - login(l), - password(p) - {} - PRIV priv; - std::string login; - std::string password; -}; -//----------------------------------------------------------------------------- - -#include "admin_conf.inc.h" - -#endif - - diff --git a/include/admin_conf.inc.h b/include/admin_conf.inc.h deleted file mode 100644 index 44897a08..00000000 --- a/include/admin_conf.inc.h +++ /dev/null @@ -1,35 +0,0 @@ - /* - $Revision: 1.1 $ - $Date: 2010/09/10 01:45:24 $ - $Author: faust $ - */ - -#ifndef ADMIN_CONF_INC_H -#define ADMIN_CONF_INC_H - -inline -uint16_t PRIV::ToInt() const -{ -uint16_t p = (userStat << 0) | - (userConf << 2) | - (userCash << 4) | - (userPasswd << 6) | - (userAddDel << 8) | - (adminChg << 10) | - (tariffChg << 12); -return p; -} - -inline -void PRIV::FromInt(uint16_t p) -{ -userStat = (p & 0x0003) >> 0x00; // 1+2 -userConf = (p & 0x000C) >> 0x02; // 4+8 -userCash = (p & 0x0030) >> 0x04; // 10+20 -userPasswd = (p & 0x00C0) >> 0x06; // 40+80 -userAddDel = (p & 0x0300) >> 0x08; // 100+200 -adminChg = (p & 0x0C00) >> 0x0A; // 400+800 -tariffChg = (p & 0x3000) >> 0x0C; // 1000+2000 -} - -#endif diff --git a/include/admins.h b/include/admins.h deleted file mode 100644 index 169f1a26..00000000 --- a/include/admins.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#ifndef ADMINS_H -#define ADMINS_H - -#include - -#include "admin.h" -#include "admin_conf.h" - -class ADMINS { -public: - virtual int Add(const std::string & login, const ADMIN * admin) = 0; - virtual int Del(const std::string & login, const ADMIN * admin) = 0; - virtual int Change(const ADMIN_CONF & ac, const ADMIN * admin) = 0; - virtual const ADMIN * GetSysAdmin() const = 0; - virtual const ADMIN * GetNoAdmin() const = 0; - virtual bool FindAdmin(const std::string & l, ADMIN ** admin) = 0; - virtual bool AdminExists(const std::string & login) const = 0; - virtual bool AdminCorrect(const std::string & login, - const std::string & password, - ADMIN ** admin) = 0; - virtual const std::string & GetStrError() const = 0; - - virtual int OpenSearch() const = 0; - virtual int SearchNext(int, ADMIN_CONF * ac) const = 0; - virtual int CloseSearch(int) const = 0; -}; - -#endif diff --git a/include/auth.h b/include/auth.h deleted file mode 100644 index 8cdc3f2d..00000000 --- a/include/auth.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.6 $ - $Date: 2009/03/18 17:24:57 $ - */ - -#ifndef AUTH_H -#define AUTH_H - -#include "plugin.h" -#include "stg_message.h" -#include "noncopyable.h" - -class AUTH : public PLUGIN { -public: - virtual int SendMessage(const STG_MSG & msg, uint32_t ip) const = 0; -}; - -#endif diff --git a/include/base_db.h b/include/base_db.h deleted file mode 100644 index 8aa05508..00000000 --- a/include/base_db.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef __BASE_DB_H__ -#define __BASE_DB_H__ - -#include -#include -#include - -class BASE_DB { -public: - - typedef std::map TUPLE; - typedef std::vector TUPLES; - typedef std::vector COLUMNS; - - BASE_DB() {}; - BASE_DB(std::string & dbHost, - std::string & dbDatabase, - std::string & dbUser, - std::string & dbPassword) - : host(dbHost), - database(dbDatabase), - user(dbUser), - password(dbPassword) - {}; - virtual ~BASE_DB() {}; - - void SetHost(const std::string & h) { host = h; }; - void SetDatabase(const std::string & db) { database = db; }; - void SetUser(const std::string & u) { user = u; }; - void SetPassword(const std::string & p) { password = p; }; - - const std::string & GetHost() const { return host; }; - const std::string & GetDatabase() const { return database; }; - const std::string & GetUser() const { return user; }; - const std::string & GetPassword() const { return password; }; - - const std::string & GetErrorMsg() const { return errorMsg; }; - - virtual bool Connect() { return true; }; - virtual bool Disconnect() { return true; }; - virtual bool Query(const std::string & q) { return true; }; - virtual bool Start() { return true; }; - virtual bool Commit() { return true; }; - virtual bool Rollback() { return true; }; - - int GetTuples() const { return tuples; }; - int GetColumns() const { return columns; }; - int GetAffectedRows() const { return affected; }; - - virtual TUPLES GetResult() const { return TUPLES(); }; - virtual TUPLE GetTuple(int n = 0) const { return TUPLE(); }; - const COLUMNS & GetColumnsNames() const { return cols; }; - -protected: - std::string host; - std::string database; - std::string user; - std::string password; - - std::string errorMsg; - - COLUMNS cols; - - int columns; - int tuples; - int affected; -}; - -extern "C" BASE_DB * CreateDriver(); -extern "C" void DestroyDriver(BASE_DB *); - -typedef BASE_DB * (* CreateDriverFn)(); -typedef void (* DestroyDriverFn)(BASE_DB *); - -#endif diff --git a/include/corp_conf.h b/include/corp_conf.h deleted file mode 100644 index 88a84f18..00000000 --- a/include/corp_conf.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CORP_CONF_H -#define CORP_CONF_H - -struct CORP_CONF -{ -string name; -double cash; -}; - -#endif //CORP_CONF_H diff --git a/include/ia_packets.h b/include/ia_packets.h deleted file mode 100644 index bd8be538..00000000 --- a/include/ia_packets.h +++ /dev/null @@ -1,307 +0,0 @@ -#ifndef PACKETH -#define PACKETH - -#include "os_int.h" - -#define CONN_SYN_N 0 -#define CONN_SYN_ACK_N 1 -#define CONN_ACK_N 2 -#define ALIVE_SYN_N 3 -#define ALIVE_ACK_N 4 -#define DISCONN_SYN_N 5 -#define DISCONN_SYN_ACK_N 6 -#define DISCONN_ACK_N 7 -#define FIN_N 8 -#define ERROR_N 9 -#define INFO_N 10 -#define INFO_7_N 11 -#define INFO_8_N 12 -#define UPDATE_N 13 - -#define DIR_NUM (10) - -#define IA_FREEMB_LEN (16) -#define IA_LOGIN_LEN (32) -#define IA_PASSWD_LEN (32) -#define IA_MAX_TYPE_LEN (16) -#define IA_MAX_MSG_LEN (235) -#define IA_MAX_MSG_LEN_8 (1030) -#define IA_DIR_NAME_LEN (16) -#define IA_MAGIC_LEN (6) -#define IA_PROTO_VER_LEN (2) - -#define ST_NOT_INETABLE (0) -#define ST_INETABLE (1) - -#define IA_ID "00100" - -typedef int8_t string16[IA_DIR_NAME_LEN]; -//----------------------------------------------------------------------------- -struct HDR_8 -{ -int8_t magic[IA_MAGIC_LEN]; -int8_t protoVer[IA_PROTO_VER_LEN]; -//uint32_t ip; -//int8_t padding[4]; -}; -//----------------------------------------------------------------------------- -struct CONN_SYN_6 -{ -int8_t magic[IA_MAGIC_LEN]; -int8_t protoVer[IA_PROTO_VER_LEN]; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t login[IA_LOGIN_LEN]; -int8_t padding[2]; -}; -//----------------------------------------------------------------------------- -struct CONN_SYN_8 -{ -HDR_8 hdr; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t login[IA_LOGIN_LEN]; -uint32_t dirs; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct CONN_SYN_ACK_6 -{ -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -int32_t userTimeOut; // Byte-order dependent -int32_t aliveDelay; // Byte-order dependent -string16 dirName[DIR_NUM]; -}; -//----------------------------------------------------------------------------- -struct CONN_SYN_ACK_8 -{ -HDR_8 hdr; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -int32_t userTimeOut; // Byte-order dependent -int32_t aliveDelay; // Byte-order dependent -string16 dirName[DIR_NUM]; -}; -//----------------------------------------------------------------------------- -struct CONN_ACK_6 -{ -int8_t magic[IA_MAGIC_LEN]; -int8_t protoVer[IA_PROTO_VER_LEN]; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct CONN_ACK_8 -{ -HDR_8 hdr; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct ALIVE_SYN_6 -{ -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent - -int64_t mu[DIR_NUM]; // Byte-order dependent -int64_t md[DIR_NUM]; // Byte-order dependent - -int64_t su[DIR_NUM]; // Byte-order dependent -int64_t sd[DIR_NUM]; // Byte-order dependent - -int64_t cash; // Byte-order dependent - -int8_t freeMb[IA_FREEMB_LEN]; -}; -//----------------------------------------------------------------------------- -struct ALIVE_SYN_8 -{ -HDR_8 hdr; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent - -int64_t mu[DIR_NUM]; // Byte-order dependent -int64_t md[DIR_NUM]; // Byte-order dependent - -int64_t su[DIR_NUM]; // Byte-order dependent -int64_t sd[DIR_NUM]; // Byte-order dependent - -int64_t cash; // Äåíüãè óìíîæåííûå íà 1000 - Byte-order dependent -int8_t freeMb[IA_FREEMB_LEN]; - -uint32_t status; // Byte-order dependent -int8_t padding[4]; -}; -//----------------------------------------------------------------------------- -struct ALIVE_ACK_6 -{ -int8_t magic[IA_MAGIC_LEN]; -int8_t protoVer[IA_PROTO_VER_LEN]; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct ALIVE_ACK_8 -{ -HDR_8 hdr; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct DISCONN_SYN_6 -{ -int8_t magic[IA_MAGIC_LEN]; -int8_t protoVer[IA_PROTO_VER_LEN]; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t login[IA_LOGIN_LEN]; -int8_t padding[2]; -}; -//----------------------------------------------------------------------------- -struct DISCONN_SYN_8 -{ -HDR_8 hdr; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t login[IA_LOGIN_LEN]; -int8_t padding[4]; -}; -//----------------------------------------------------------------------------- -struct DISCONN_SYN_ACK_6 -{ -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct DISCONN_SYN_ACK_8 -{ -HDR_8 hdr; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct DISCONN_ACK_6 -{ -int8_t magic[IA_MAGIC_LEN]; -int8_t protoVer[IA_PROTO_VER_LEN]; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct DISCONN_ACK_8 -{ -HDR_8 hdr; -int8_t loginS[IA_LOGIN_LEN]; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -uint32_t rnd; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -struct FIN_6 -{ -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t ok[3]; -int8_t padding[1]; -}; -//----------------------------------------------------------------------------- -struct FIN_8 -{ -HDR_8 hdr; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t ok[3]; -int8_t padding[1]; -}; -//----------------------------------------------------------------------------- -struct ERR -{ -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t text[236]; -}; -//----------------------------------------------------------------------------- -struct ERR_8 -{ -HDR_8 hdr; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t text[236]; -}; -//----------------------------------------------------------------------------- -struct INFO_6 -{ -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t infoType; -int8_t text[IA_MAX_MSG_LEN]; -}; -//----------------------------------------------------------------------------- -struct INFO_7 -{ -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t infoType; -uint32_t sendTime; // Byte-order dependent -int8_t showTime; -int8_t text[IA_MAX_MSG_LEN]; -int8_t padding[5]; -}; -//----------------------------------------------------------------------------- -struct INFO_8 -{ -HDR_8 hdr; -int32_t len; // Byte-order dependent -int8_t type[IA_MAX_TYPE_LEN]; -int8_t infoType; -uint32_t sendTime; // Byte-order dependent -int8_t showTime; -int8_t text[IA_MAX_MSG_LEN_8]; -}; -//----------------------------------------------------------------------------- -struct LOADSTAT -{ -int64_t mu[DIR_NUM]; // Byte-order dependent -int64_t md[DIR_NUM]; // Byte-order dependent - -int64_t su[DIR_NUM]; // Byte-order dependent -int64_t sd[DIR_NUM]; // Byte-order dependent - -int64_t cash; // Äåíüãè óìíîæåííûå íà 1000 - Byte-order dependent -int8_t freeMb[IA_FREEMB_LEN]; -int32_t status; // Byte-order dependent -}; -//----------------------------------------------------------------------------- -#define CONN_SYN_7 CONN_SYN_6 -#define CONN_SYN_ACK_7 CONN_SYN_ACK_6 -#define CONN_ACK_7 CONN_ACK_6 -#define ALIVE_SYN_7 ALIVE_SYN_6 -#define ALIVE_ACK_7 ALIVE_ACK_6 -#define DISCONN_SYN_7 DISCONN_SYN_6 -#define DISCONN_SYN_ACK_7 DISCONN_SYN_ACK_6 -#define DISCONN_ACK_7 DISCONN_ACK_6 -#define FIN_7 FIN_6 - -#endif - - diff --git a/include/mimetype.h b/include/mimetype.h deleted file mode 100644 index a5f8487a..00000000 --- a/include/mimetype.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - ***************************************************************************** - * - * File: mimetype.h - * - * Description: TODO: - * - * $Id: mimetype.h,v 1.1.1.1 2005/10/09 11:00:45 nobunaga Exp $ - * - ***************************************************************************** - */ - -#ifndef _MIMETYPE_H -#define _MIMETYPE_H_ - - -struct MIMETYPE - { - char *ext; - char *type; - }; - -const MIMETYPE mTypes[]= -{ - { ".jpg" , "image/jpeg" }, - { ".gif", "image/gif" }, - { ".jpeg", "image/jpeg" }, - { ".htm", "text/html" }, - { ".html", "text/html" }, - { ".txt", "text/plain" }, - { ".css", "text/css" } -}; - -#endif /* _MIMETYPE_H_ */ - -/* EOF */ - diff --git a/include/module_settings.h b/include/module_settings.h deleted file mode 100644 index a1baf33c..00000000 --- a/include/module_settings.h +++ /dev/null @@ -1,51 +0,0 @@ - /* - $Revision: 1.5 $ - $Date: 2010/03/04 11:49:52 $ - $Author: faust $ - */ - -#ifndef MODULE_SETTINGS_H -#define MODULE_SETTINGS_H - -#include // strcasecmp -#include -#include - -//----------------------------------------------------------------------------- -struct PARAM_VALUE -{ - PARAM_VALUE() - : param(), - value() - {} - bool operator==(const PARAM_VALUE & rhs) const - { return !strcasecmp(param.c_str(), rhs.param.c_str()); } - - bool operator<(const PARAM_VALUE & rhs) const - { return strcasecmp(param.c_str(), rhs.param.c_str()) < 0; } - - std::string param; - std::vector value; -}; -//----------------------------------------------------------------------------- -struct MODULE_SETTINGS -{ - MODULE_SETTINGS() - : moduleName(), - moduleParams() - {} - MODULE_SETTINGS(const MODULE_SETTINGS & rvalue) - : moduleName(rvalue.moduleName), - moduleParams(rvalue.moduleParams) - {} - bool operator==(const MODULE_SETTINGS & rhs) const - { return !strcasecmp(moduleName.c_str(), rhs.moduleName.c_str()); } - - bool operator<(const MODULE_SETTINGS & rhs) const - { return strcasecmp(moduleName.c_str(), rhs.moduleName.c_str()) < 0; } - - std::string moduleName; - std::vector moduleParams; -}; -//----------------------------------------------------------------------------- -#endif diff --git a/include/noncopyable.h b/include/noncopyable.h deleted file mode 100644 index 3d4c53b3..00000000 --- a/include/noncopyable.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __NONCOPYABLE_H__ -#define __NONCOPYABLE_H__ - -class NONCOPYABLE -{ -protected: - NONCOPYABLE() {} - virtual ~NONCOPYABLE() {} -private: // emphasize the following members are private - NONCOPYABLE(const NONCOPYABLE &); - const NONCOPYABLE & operator=(const NONCOPYABLE &); -}; - -#endif diff --git a/include/notifer.h b/include/notifer.h deleted file mode 100644 index 57f9928e..00000000 --- a/include/notifer.h +++ /dev/null @@ -1,29 +0,0 @@ - /* - $Revision: 1.6 $ - $Date: 2007/12/03 09:00:17 $ - $Author: nobunaga $ - */ - -#ifndef PROPERTY_NOTIFER_H -#define PROPERTY_NOTIFER_H - -//----------------------------------------------------------------------------- -template -class PROPERTY_NOTIFIER_BASE -{ -public: - virtual ~PROPERTY_NOTIFIER_BASE(){}; - virtual void Notify(const varParamType & oldValue, const varParamType & newValue) = 0; -}; -//----------------------------------------------------------------------------- -template -class NOTIFIER_BASE -{ -public: - virtual ~NOTIFIER_BASE(){}; - virtual void Notify(const varParamType & value) = 0; -}; -//----------------------------------------------------------------------------- -#endif //PROPERTY_NOTIFER_H - - diff --git a/include/os_int.h b/include/os_int.h deleted file mode 100644 index cc017b84..00000000 --- a/include/os_int.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.4 $ - $Date: 2008/03/25 17:41:50 $ - */ - - -#ifndef OS_INT_H -#define OS_INT_H - -#ifdef LINUX -#include -#endif - -#ifdef FREE_BSD5 -#include -#endif - -#ifdef FREE_BSD -#include -#endif - -#ifdef WIN32 - -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; - -typedef int int32_t; -typedef unsigned int uint32_t; - -typedef short int int16_t; -typedef short unsigned int uint16_t; - -typedef char int8_t; -typedef unsigned char uint8_t; - - -#endif - - -#endif - diff --git a/include/plugin.h b/include/plugin.h deleted file mode 100644 index d196b353..00000000 --- a/include/plugin.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - -/* - $Revision: 1.12 $ - $Date: 2010/03/04 11:53:14 $ - $Author: faust $ -*/ - - -#ifndef PLUGIN_H -#define PLUGIN_H - -#include - -#include "noncopyable.h" -#include "os_int.h" -#include "admins.h" -#include "users.h" -#include "tariffs.h" - -class TRAFFCOUNTER; -class SETTINGS; -class STORE; -class MODULE_SETTINGS; - -class PLUGIN : private NONCOPYABLE { -public: - virtual void SetUsers(USERS * u) = 0; - virtual void SetTariffs(TARIFFS * t) = 0; - virtual void SetAdmins(ADMINS * a) = 0; - virtual void SetTraffcounter(TRAFFCOUNTER * tc) = 0; - virtual void SetStore(STORE * st) = 0; - virtual void SetStgSettings(const SETTINGS * s) = 0; - virtual void SetSettings(const MODULE_SETTINGS & s) = 0; - virtual int ParseSettings() = 0; - - virtual int Start() = 0; - virtual int Stop() = 0; - virtual int Reload() = 0; - virtual bool IsRunning() = 0; - virtual const std::string & GetStrError() const = 0; - virtual const std::string GetVersion() const = 0; - virtual uint16_t GetStartPosition() const = 0; - virtual uint16_t GetStopPosition() const = 0; -}; - -#endif diff --git a/include/rad_packets.h b/include/rad_packets.h deleted file mode 100644 index 96cddc4b..00000000 --- a/include/rad_packets.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef RAD_PACKETSH -#define RAD_PACKETSH - -#define RAD_MAGIC_LEN (5) -#define RAD_PROTO_VER_LEN (2) -#define RAD_MAX_PACKET_LEN (1024) -#define RAD_LOGIN_LEN (32) -#define RAD_SERVICE_LEN (16) -#define RAD_PASSWORD_LEN (32) -#define RAD_SESSID_LEN (32) - -// Request -#define RAD_AUTZ_PACKET (0) -#define RAD_AUTH_PACKET (1) -#define RAD_POST_AUTH_PACKET (2) -#define RAD_ACCT_START_PACKET (3) -#define RAD_ACCT_STOP_PACKET (4) -#define RAD_ACCT_UPDATE_PACKET (5) -#define RAD_ACCT_OTHER_PACKET (6) -// Responce -#define RAD_ACCEPT_PACKET (7) -#define RAD_REJECT_PACKET (8) - -#define RAD_ID "00100" - -#include "os_int.h" - -struct RAD_PACKET -{ -uint8_t magic[RAD_MAGIC_LEN]; -uint8_t protoVer[RAD_PROTO_VER_LEN]; -uint8_t packetType; -uint8_t login[RAD_LOGIN_LEN]; -uint32_t ip; -uint8_t service[RAD_SERVICE_LEN]; -uint8_t password[RAD_PASSWORD_LEN]; -uint8_t sessid[RAD_SESSID_LEN]; -uint8_t padding[4]; -}; - -#endif diff --git a/include/raw_ip_packet.h b/include/raw_ip_packet.h deleted file mode 100644 index a1bdda71..00000000 --- a/include/raw_ip_packet.h +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef RAW_IP_PACKET_H -#define RAW_IP_PACKET_H - -#if defined(FREE_BSD) || defined(FREE_BSD5) -#include // n_long in netinet/ip.h -#endif - -#include // for htons -#include // for struct ip - -#include - -#include "stg_const.h" -#include "common.h" - -#define IPv4 (2) - -enum { pcktSize = 68 }; //60(max) ip + 8 udp or tcp (part of tcp or udp header to ports) -//----------------------------------------------------------------------------- -struct RAW_PACKET -{ - RAW_PACKET() - : dataLen(-1) - { - memset(pckt, 0, pcktSize); - } - - RAW_PACKET(const RAW_PACKET & rp) - : dataLen(rp.dataLen) - { - memcpy(pckt, rp.pckt, pcktSize); - } - -uint16_t GetIPVersion() const; -uint8_t GetHeaderLen() const; -uint8_t GetProto() const; -uint32_t GetLen() const; -uint32_t GetSrcIP() const; -uint32_t GetDstIP() const; -uint16_t GetSrcPort() const; -uint16_t GetDstPort() const; - -bool operator==(const RAW_PACKET & rvalue) const; -bool operator!=(const RAW_PACKET & rvalue) const { return !(*this == rvalue); }; -bool operator<(const RAW_PACKET & rvalue) const; - -union - { - uint8_t pckt[pcktSize]; // Packet header as a raw data - struct - { - struct ip ipHeader; - // Only for packets without options field - uint16_t sPort; - uint16_t dPort; - } header __attribute__ ((packed)); - }; -int32_t dataLen; // IP packet length. Set to -1 to use length field from the header -}; -//----------------------------------------------------------------------------- -inline uint16_t RAW_PACKET::GetIPVersion() const -{ -return header.ipHeader.ip_v; -} -//----------------------------------------------------------------------------- -inline uint8_t RAW_PACKET::GetHeaderLen() const -{ -return header.ipHeader.ip_hl * 4; -} -//----------------------------------------------------------------------------- -inline uint8_t RAW_PACKET::GetProto() const -{ -return header.ipHeader.ip_p; -} -//----------------------------------------------------------------------------- -inline uint32_t RAW_PACKET::GetLen() const -{ -if (dataLen != -1) - return dataLen; -return ntohs(header.ipHeader.ip_len); -} -//----------------------------------------------------------------------------- -inline uint32_t RAW_PACKET::GetSrcIP() const -{ -return header.ipHeader.ip_src.s_addr; -} -//----------------------------------------------------------------------------- -inline uint32_t RAW_PACKET::GetDstIP() const -{ -return header.ipHeader.ip_dst.s_addr; -} -//----------------------------------------------------------------------------- -inline uint16_t RAW_PACKET::GetSrcPort() const -{ -if (header.ipHeader.ip_p == 1) // for icmp proto return port 0 - return 0; -return ntohs(*((uint16_t*)(pckt + header.ipHeader.ip_hl * 4))); -} -//----------------------------------------------------------------------------- -inline uint16_t RAW_PACKET::GetDstPort() const -{ -if (header.ipHeader.ip_p == 1) // for icmp proto return port 0 - return 0; -return ntohs(*((uint16_t*)(pckt + header.ipHeader.ip_hl * 4 + 2))); -} -//----------------------------------------------------------------------------- -inline bool RAW_PACKET::operator==(const RAW_PACKET & rvalue) const -{ -if (header.ipHeader.ip_src.s_addr != rvalue.header.ipHeader.ip_src.s_addr) - return false; - -if (header.ipHeader.ip_dst.s_addr != rvalue.header.ipHeader.ip_dst.s_addr) - return false; - -if (header.ipHeader.ip_p != 1 && rvalue.header.ipHeader.ip_p != 1) - { - if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4)) != - *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4))) - return false; - - if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4 + 2)) != - *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4 + 2))) - return false; - } - -if (header.ipHeader.ip_p != rvalue.header.ipHeader.ip_p) - return false; - -return true; -} -//----------------------------------------------------------------------------- -inline bool RAW_PACKET::operator<(const RAW_PACKET & rvalue) const -{ -if (header.ipHeader.ip_src.s_addr < rvalue.header.ipHeader.ip_src.s_addr) - return true; -if (header.ipHeader.ip_src.s_addr > rvalue.header.ipHeader.ip_src.s_addr) - return false; - -if (header.ipHeader.ip_dst.s_addr < rvalue.header.ipHeader.ip_dst.s_addr) - return true; -if (header.ipHeader.ip_dst.s_addr > rvalue.header.ipHeader.ip_dst.s_addr) - return false; - -if (header.ipHeader.ip_p != 1 && rvalue.header.ipHeader.ip_p != 1) - { - if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4)) < - *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4))) - return true; - if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4)) > - *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4))) - return false; - - if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4 + 2)) < - *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4 + 2))) - return true; - if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4 + 2)) > - *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4 + 2))) - return false; - } - -if (header.ipHeader.ip_p < rvalue.header.ipHeader.ip_p) - return true; - -return false; -} -//----------------------------------------------------------------------------- - -#endif diff --git a/include/resetable.h b/include/resetable.h deleted file mode 100644 index d31bffda..00000000 --- a/include/resetable.h +++ /dev/null @@ -1,98 +0,0 @@ - /* - $Revision: 1.9 $ - $Date: 2010/03/11 14:42:04 $ - $Author: faust $ - */ - -/* - * Copyright (c) 2001 by Peter Simons . - * All rights reserved. - */ - -#ifndef RESETABLE_VARIABLE_H -#define RESETABLE_VARIABLE_H - -// This is a wrapper class about variables where you want to keep -// track of whether it has been assigened yet or not. - -#include - -template -class RESETABLE -{ - template - friend std::ostream & operator<<(std::ostream & o, RESETABLE v); -public: - typedef varT value_type; - - //------------------------------------------------------------------------- - RESETABLE() - : value(), - is_set(false) - { - } - //------------------------------------------------------------------------- - RESETABLE(const RESETABLE & rvalue) - : value(rvalue.value), - is_set(rvalue.is_set) - { - } - //------------------------------------------------------------------------- - RESETABLE(const value_type& val) - : value(val), - is_set(true) - { - } - //------------------------------------------------------------------------- - RESETABLE & operator=(const RESETABLE & rvalue) - { - value = rvalue.value; - is_set = rvalue.is_set; - return *this; - } - //------------------------------------------------------------------------- - RESETABLE & operator= (const value_type& rhs) - { - value = rhs; - is_set = true; - return *this; - } - //------------------------------------------------------------------------- - const value_type& const_data() const throw() - { - return value; - } - //------------------------------------------------------------------------- - value_type& data() throw() - { - return value; - } - //------------------------------------------------------------------------- - operator const value_type&() const throw() - { - return value; - } - //------------------------------------------------------------------------- - bool res_empty() const throw() - { - return !is_set; - } - //------------------------------------------------------------------------- - void reset() throw() - { - is_set = false; - } - //------------------------------------------------------------------------- -protected: - value_type value; - bool is_set; -}; -//----------------------------------------------------------------------------- -template -std::ostream & operator<<(std::ostream & o, RESETABLE v) -{ - return o << v.value; -} -//------------------------------------------------------------------------- -#endif // RESETABLE_VARIABLE_H - diff --git a/include/rs_packets.h b/include/rs_packets.h deleted file mode 100644 index 1a038be7..00000000 --- a/include/rs_packets.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef RS_PACKETSH -#define RS_PACKETSH - -#define RS_MAGIC_LEN (6) -#define RS_PROTO_VER_LEN (2) -#define RS_MAX_PACKET_LEN (1048) -#define RS_LOGIN_LEN (32) -#define RS_PARAMS_LEN (979) - -#define RS_ALIVE_PACKET (0) -#define RS_CONNECT_PACKET (1) -#define RS_DISCONNECT_PACKET (2) - -#define RS_ID "RSP00" - -#include "os_int.h" - -struct RS_PACKET_HEADER -{ -int8_t magic[RS_MAGIC_LEN]; -int8_t protoVer[RS_PROTO_VER_LEN]; -int8_t packetType; -uint32_t ip; -uint32_t id; -int8_t login[RS_LOGIN_LEN]; -int8_t padding[7]; -} __attribute__((__packed__)); // 48 bytes, 6 blocks - -struct RS_PACKET_TAIL -{ -int8_t magic[RS_MAGIC_LEN]; -int8_t params[RS_PARAMS_LEN]; -int8_t padding[7]; -} __attribute__((__packed__)); // 992 bytes, 124 blocks - -#endif diff --git a/include/service_conf.h b/include/service_conf.h deleted file mode 100644 index 6c958c41..00000000 --- a/include/service_conf.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef SERVICE_CONF_H -#define SERVICE_CONF_H - -struct SERVICE_CONF -{ -string name; -string comment; -double cost; -int payDay; -}; - -#endif //SERVICE_CONF_H - diff --git a/include/settings.h b/include/settings.h deleted file mode 100644 index e97f3e2a..00000000 --- a/include/settings.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#ifndef SETTINGS_H -#define SETTINGS_H - -#include - -class SETTINGS { -public: - virtual const std::string & GetDirName(size_t num) const = 0; - virtual unsigned GetDetailStatWritePeriod() const = 0; - virtual unsigned GetStatWritePeriod() const = 0; - virtual unsigned GetDayFee() const = 0; - virtual bool GetFullFee() const = 0; - virtual unsigned GetDayResetTraff() const = 0; - virtual bool GetSpreadFee() const = 0; - virtual bool GetFreeMbAllowInet() const = 0; - virtual bool GetDayFeeIsLastDay() const = 0; - virtual bool GetWriteFreeMbTraffCost() const = 0; - virtual bool GetShowFeeInCash() const = 0; - virtual unsigned GetMessageTimeout() const = 0; - virtual const std::string & GetMonitorDir() const = 0; - virtual bool GetMonitoring() const = 0; -}; -//----------------------------------------------------------------------------- - -#endif diff --git a/include/stg/admin.h b/include/stg/admin.h new file mode 100644 index 00000000..7095bb62 --- /dev/null +++ b/include/stg/admin.h @@ -0,0 +1,49 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef ADMIN_H +#define ADMIN_H + +#include + +#include "admin_conf.h" +#include "os_int.h" + +class ADMIN { +public: + virtual ADMIN & operator=(const ADMIN &) = 0; + virtual ADMIN & operator=(const ADMIN_CONF &) = 0; + virtual bool operator==(const ADMIN & rhs) const = 0; + virtual bool operator!=(const ADMIN & rhs) const = 0; + virtual bool operator<(const ADMIN & rhs) const = 0; + virtual bool operator<=(const ADMIN & rhs) const = 0; + + virtual const std::string & GetPassword() const = 0; + virtual const std::string & GetLogin() const = 0; + virtual PRIV const * GetPriv() const = 0; + virtual uint16_t GetPrivAsInt() const = 0; + virtual const ADMIN_CONF & GetConf() const = 0; + virtual uint32_t GetIP() const = 0; + virtual std::string GetIPStr() const = 0; + virtual void SetIP(uint32_t ip) = 0; + virtual const std::string GetLogStr() const = 0; +}; + +#endif diff --git a/include/stg/admin_conf.h b/include/stg/admin_conf.h new file mode 100644 index 00000000..32012f34 --- /dev/null +++ b/include/stg/admin_conf.h @@ -0,0 +1,77 @@ + /* + $Revision: 1.9 $ + $Date: 2010/09/10 05:02:08 $ + $Author: faust $ + */ + +#ifndef ADMIN_CONF_H +#define ADMIN_CONF_H + +#include + +#include "os_int.h" + +#define ADM_LOGIN_LEN (32) +#define ADM_PASSWD_LEN (32) +//----------------------------------------------------------------------------- +struct PRIV +{ + PRIV() + : userStat(0), + userConf(0), + userCash(0), + userPasswd(0), + userAddDel(0), + adminChg(0), + tariffChg(0) + {}; + PRIV(uint16_t p) + : userStat((p & 0x0003) >> 0x00), + userConf((p & 0x000C) >> 0x02), + userCash((p & 0x0030) >> 0x04), + userPasswd((p & 0x00C0) >> 0x06), + userAddDel((p & 0x0300) >> 0x08), + adminChg((p & 0x0C00) >> 0x0A), + tariffChg((p & 0x3000) >> 0x0C) + {} + + uint16_t ToInt() const; + void FromInt(uint16_t p); + + uint16_t userStat; + uint16_t userConf; + uint16_t userCash; + uint16_t userPasswd; + uint16_t userAddDel; + uint16_t adminChg; + uint16_t tariffChg; +}; +//----------------------------------------------------------------------------- +struct ADMIN_CONF +{ + ADMIN_CONF() + : priv(), + login(), + password("* NO PASSWORD *") + {} + ADMIN_CONF(const ADMIN_CONF & rvalue) + : priv(rvalue.priv), + login(rvalue.login), + password(rvalue.password) + {} + ADMIN_CONF(const PRIV & pr, const std::string & l, const std::string & p) + : priv(pr), + login(l), + password(p) + {} + PRIV priv; + std::string login; + std::string password; +}; +//----------------------------------------------------------------------------- + +#include "admin_conf.inc.h" + +#endif + + diff --git a/include/stg/admin_conf.inc.h b/include/stg/admin_conf.inc.h new file mode 100644 index 00000000..44897a08 --- /dev/null +++ b/include/stg/admin_conf.inc.h @@ -0,0 +1,35 @@ + /* + $Revision: 1.1 $ + $Date: 2010/09/10 01:45:24 $ + $Author: faust $ + */ + +#ifndef ADMIN_CONF_INC_H +#define ADMIN_CONF_INC_H + +inline +uint16_t PRIV::ToInt() const +{ +uint16_t p = (userStat << 0) | + (userConf << 2) | + (userCash << 4) | + (userPasswd << 6) | + (userAddDel << 8) | + (adminChg << 10) | + (tariffChg << 12); +return p; +} + +inline +void PRIV::FromInt(uint16_t p) +{ +userStat = (p & 0x0003) >> 0x00; // 1+2 +userConf = (p & 0x000C) >> 0x02; // 4+8 +userCash = (p & 0x0030) >> 0x04; // 10+20 +userPasswd = (p & 0x00C0) >> 0x06; // 40+80 +userAddDel = (p & 0x0300) >> 0x08; // 100+200 +adminChg = (p & 0x0C00) >> 0x0A; // 400+800 +tariffChg = (p & 0x3000) >> 0x0C; // 1000+2000 +} + +#endif diff --git a/include/stg/admins.h b/include/stg/admins.h new file mode 100644 index 00000000..169f1a26 --- /dev/null +++ b/include/stg/admins.h @@ -0,0 +1,48 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef ADMINS_H +#define ADMINS_H + +#include + +#include "admin.h" +#include "admin_conf.h" + +class ADMINS { +public: + virtual int Add(const std::string & login, const ADMIN * admin) = 0; + virtual int Del(const std::string & login, const ADMIN * admin) = 0; + virtual int Change(const ADMIN_CONF & ac, const ADMIN * admin) = 0; + virtual const ADMIN * GetSysAdmin() const = 0; + virtual const ADMIN * GetNoAdmin() const = 0; + virtual bool FindAdmin(const std::string & l, ADMIN ** admin) = 0; + virtual bool AdminExists(const std::string & login) const = 0; + virtual bool AdminCorrect(const std::string & login, + const std::string & password, + ADMIN ** admin) = 0; + virtual const std::string & GetStrError() const = 0; + + virtual int OpenSearch() const = 0; + virtual int SearchNext(int, ADMIN_CONF * ac) const = 0; + virtual int CloseSearch(int) const = 0; +}; + +#endif diff --git a/include/stg/auth.h b/include/stg/auth.h new file mode 100644 index 00000000..8cdc3f2d --- /dev/null +++ b/include/stg/auth.h @@ -0,0 +1,38 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.6 $ + $Date: 2009/03/18 17:24:57 $ + */ + +#ifndef AUTH_H +#define AUTH_H + +#include "plugin.h" +#include "stg_message.h" +#include "noncopyable.h" + +class AUTH : public PLUGIN { +public: + virtual int SendMessage(const STG_MSG & msg, uint32_t ip) const = 0; +}; + +#endif diff --git a/include/stg/base_db.h b/include/stg/base_db.h new file mode 100644 index 00000000..8aa05508 --- /dev/null +++ b/include/stg/base_db.h @@ -0,0 +1,75 @@ +#ifndef __BASE_DB_H__ +#define __BASE_DB_H__ + +#include +#include +#include + +class BASE_DB { +public: + + typedef std::map TUPLE; + typedef std::vector TUPLES; + typedef std::vector COLUMNS; + + BASE_DB() {}; + BASE_DB(std::string & dbHost, + std::string & dbDatabase, + std::string & dbUser, + std::string & dbPassword) + : host(dbHost), + database(dbDatabase), + user(dbUser), + password(dbPassword) + {}; + virtual ~BASE_DB() {}; + + void SetHost(const std::string & h) { host = h; }; + void SetDatabase(const std::string & db) { database = db; }; + void SetUser(const std::string & u) { user = u; }; + void SetPassword(const std::string & p) { password = p; }; + + const std::string & GetHost() const { return host; }; + const std::string & GetDatabase() const { return database; }; + const std::string & GetUser() const { return user; }; + const std::string & GetPassword() const { return password; }; + + const std::string & GetErrorMsg() const { return errorMsg; }; + + virtual bool Connect() { return true; }; + virtual bool Disconnect() { return true; }; + virtual bool Query(const std::string & q) { return true; }; + virtual bool Start() { return true; }; + virtual bool Commit() { return true; }; + virtual bool Rollback() { return true; }; + + int GetTuples() const { return tuples; }; + int GetColumns() const { return columns; }; + int GetAffectedRows() const { return affected; }; + + virtual TUPLES GetResult() const { return TUPLES(); }; + virtual TUPLE GetTuple(int n = 0) const { return TUPLE(); }; + const COLUMNS & GetColumnsNames() const { return cols; }; + +protected: + std::string host; + std::string database; + std::string user; + std::string password; + + std::string errorMsg; + + COLUMNS cols; + + int columns; + int tuples; + int affected; +}; + +extern "C" BASE_DB * CreateDriver(); +extern "C" void DestroyDriver(BASE_DB *); + +typedef BASE_DB * (* CreateDriverFn)(); +typedef void (* DestroyDriverFn)(BASE_DB *); + +#endif diff --git a/include/stg/corp_conf.h b/include/stg/corp_conf.h new file mode 100644 index 00000000..88a84f18 --- /dev/null +++ b/include/stg/corp_conf.h @@ -0,0 +1,10 @@ +#ifndef CORP_CONF_H +#define CORP_CONF_H + +struct CORP_CONF +{ +string name; +double cash; +}; + +#endif //CORP_CONF_H diff --git a/include/stg/ia_packets.h b/include/stg/ia_packets.h new file mode 100644 index 00000000..bd8be538 --- /dev/null +++ b/include/stg/ia_packets.h @@ -0,0 +1,307 @@ +#ifndef PACKETH +#define PACKETH + +#include "os_int.h" + +#define CONN_SYN_N 0 +#define CONN_SYN_ACK_N 1 +#define CONN_ACK_N 2 +#define ALIVE_SYN_N 3 +#define ALIVE_ACK_N 4 +#define DISCONN_SYN_N 5 +#define DISCONN_SYN_ACK_N 6 +#define DISCONN_ACK_N 7 +#define FIN_N 8 +#define ERROR_N 9 +#define INFO_N 10 +#define INFO_7_N 11 +#define INFO_8_N 12 +#define UPDATE_N 13 + +#define DIR_NUM (10) + +#define IA_FREEMB_LEN (16) +#define IA_LOGIN_LEN (32) +#define IA_PASSWD_LEN (32) +#define IA_MAX_TYPE_LEN (16) +#define IA_MAX_MSG_LEN (235) +#define IA_MAX_MSG_LEN_8 (1030) +#define IA_DIR_NAME_LEN (16) +#define IA_MAGIC_LEN (6) +#define IA_PROTO_VER_LEN (2) + +#define ST_NOT_INETABLE (0) +#define ST_INETABLE (1) + +#define IA_ID "00100" + +typedef int8_t string16[IA_DIR_NAME_LEN]; +//----------------------------------------------------------------------------- +struct HDR_8 +{ +int8_t magic[IA_MAGIC_LEN]; +int8_t protoVer[IA_PROTO_VER_LEN]; +//uint32_t ip; +//int8_t padding[4]; +}; +//----------------------------------------------------------------------------- +struct CONN_SYN_6 +{ +int8_t magic[IA_MAGIC_LEN]; +int8_t protoVer[IA_PROTO_VER_LEN]; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t login[IA_LOGIN_LEN]; +int8_t padding[2]; +}; +//----------------------------------------------------------------------------- +struct CONN_SYN_8 +{ +HDR_8 hdr; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t login[IA_LOGIN_LEN]; +uint32_t dirs; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct CONN_SYN_ACK_6 +{ +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +int32_t userTimeOut; // Byte-order dependent +int32_t aliveDelay; // Byte-order dependent +string16 dirName[DIR_NUM]; +}; +//----------------------------------------------------------------------------- +struct CONN_SYN_ACK_8 +{ +HDR_8 hdr; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +int32_t userTimeOut; // Byte-order dependent +int32_t aliveDelay; // Byte-order dependent +string16 dirName[DIR_NUM]; +}; +//----------------------------------------------------------------------------- +struct CONN_ACK_6 +{ +int8_t magic[IA_MAGIC_LEN]; +int8_t protoVer[IA_PROTO_VER_LEN]; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct CONN_ACK_8 +{ +HDR_8 hdr; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct ALIVE_SYN_6 +{ +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent + +int64_t mu[DIR_NUM]; // Byte-order dependent +int64_t md[DIR_NUM]; // Byte-order dependent + +int64_t su[DIR_NUM]; // Byte-order dependent +int64_t sd[DIR_NUM]; // Byte-order dependent + +int64_t cash; // Byte-order dependent + +int8_t freeMb[IA_FREEMB_LEN]; +}; +//----------------------------------------------------------------------------- +struct ALIVE_SYN_8 +{ +HDR_8 hdr; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent + +int64_t mu[DIR_NUM]; // Byte-order dependent +int64_t md[DIR_NUM]; // Byte-order dependent + +int64_t su[DIR_NUM]; // Byte-order dependent +int64_t sd[DIR_NUM]; // Byte-order dependent + +int64_t cash; // Äåíüãè óìíîæåííûå íà 1000 - Byte-order dependent +int8_t freeMb[IA_FREEMB_LEN]; + +uint32_t status; // Byte-order dependent +int8_t padding[4]; +}; +//----------------------------------------------------------------------------- +struct ALIVE_ACK_6 +{ +int8_t magic[IA_MAGIC_LEN]; +int8_t protoVer[IA_PROTO_VER_LEN]; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct ALIVE_ACK_8 +{ +HDR_8 hdr; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct DISCONN_SYN_6 +{ +int8_t magic[IA_MAGIC_LEN]; +int8_t protoVer[IA_PROTO_VER_LEN]; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t login[IA_LOGIN_LEN]; +int8_t padding[2]; +}; +//----------------------------------------------------------------------------- +struct DISCONN_SYN_8 +{ +HDR_8 hdr; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t login[IA_LOGIN_LEN]; +int8_t padding[4]; +}; +//----------------------------------------------------------------------------- +struct DISCONN_SYN_ACK_6 +{ +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct DISCONN_SYN_ACK_8 +{ +HDR_8 hdr; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct DISCONN_ACK_6 +{ +int8_t magic[IA_MAGIC_LEN]; +int8_t protoVer[IA_PROTO_VER_LEN]; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct DISCONN_ACK_8 +{ +HDR_8 hdr; +int8_t loginS[IA_LOGIN_LEN]; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +uint32_t rnd; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +struct FIN_6 +{ +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t ok[3]; +int8_t padding[1]; +}; +//----------------------------------------------------------------------------- +struct FIN_8 +{ +HDR_8 hdr; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t ok[3]; +int8_t padding[1]; +}; +//----------------------------------------------------------------------------- +struct ERR +{ +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t text[236]; +}; +//----------------------------------------------------------------------------- +struct ERR_8 +{ +HDR_8 hdr; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t text[236]; +}; +//----------------------------------------------------------------------------- +struct INFO_6 +{ +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t infoType; +int8_t text[IA_MAX_MSG_LEN]; +}; +//----------------------------------------------------------------------------- +struct INFO_7 +{ +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t infoType; +uint32_t sendTime; // Byte-order dependent +int8_t showTime; +int8_t text[IA_MAX_MSG_LEN]; +int8_t padding[5]; +}; +//----------------------------------------------------------------------------- +struct INFO_8 +{ +HDR_8 hdr; +int32_t len; // Byte-order dependent +int8_t type[IA_MAX_TYPE_LEN]; +int8_t infoType; +uint32_t sendTime; // Byte-order dependent +int8_t showTime; +int8_t text[IA_MAX_MSG_LEN_8]; +}; +//----------------------------------------------------------------------------- +struct LOADSTAT +{ +int64_t mu[DIR_NUM]; // Byte-order dependent +int64_t md[DIR_NUM]; // Byte-order dependent + +int64_t su[DIR_NUM]; // Byte-order dependent +int64_t sd[DIR_NUM]; // Byte-order dependent + +int64_t cash; // Äåíüãè óìíîæåííûå íà 1000 - Byte-order dependent +int8_t freeMb[IA_FREEMB_LEN]; +int32_t status; // Byte-order dependent +}; +//----------------------------------------------------------------------------- +#define CONN_SYN_7 CONN_SYN_6 +#define CONN_SYN_ACK_7 CONN_SYN_ACK_6 +#define CONN_ACK_7 CONN_ACK_6 +#define ALIVE_SYN_7 ALIVE_SYN_6 +#define ALIVE_ACK_7 ALIVE_ACK_6 +#define DISCONN_SYN_7 DISCONN_SYN_6 +#define DISCONN_SYN_ACK_7 DISCONN_SYN_ACK_6 +#define DISCONN_ACK_7 DISCONN_ACK_6 +#define FIN_7 FIN_6 + +#endif + + diff --git a/include/stg/mimetype.h b/include/stg/mimetype.h new file mode 100644 index 00000000..a5f8487a --- /dev/null +++ b/include/stg/mimetype.h @@ -0,0 +1,37 @@ +/* + ***************************************************************************** + * + * File: mimetype.h + * + * Description: TODO: + * + * $Id: mimetype.h,v 1.1.1.1 2005/10/09 11:00:45 nobunaga Exp $ + * + ***************************************************************************** + */ + +#ifndef _MIMETYPE_H +#define _MIMETYPE_H_ + + +struct MIMETYPE + { + char *ext; + char *type; + }; + +const MIMETYPE mTypes[]= +{ + { ".jpg" , "image/jpeg" }, + { ".gif", "image/gif" }, + { ".jpeg", "image/jpeg" }, + { ".htm", "text/html" }, + { ".html", "text/html" }, + { ".txt", "text/plain" }, + { ".css", "text/css" } +}; + +#endif /* _MIMETYPE_H_ */ + +/* EOF */ + diff --git a/include/stg/module_settings.h b/include/stg/module_settings.h new file mode 100644 index 00000000..a1baf33c --- /dev/null +++ b/include/stg/module_settings.h @@ -0,0 +1,51 @@ + /* + $Revision: 1.5 $ + $Date: 2010/03/04 11:49:52 $ + $Author: faust $ + */ + +#ifndef MODULE_SETTINGS_H +#define MODULE_SETTINGS_H + +#include // strcasecmp +#include +#include + +//----------------------------------------------------------------------------- +struct PARAM_VALUE +{ + PARAM_VALUE() + : param(), + value() + {} + bool operator==(const PARAM_VALUE & rhs) const + { return !strcasecmp(param.c_str(), rhs.param.c_str()); } + + bool operator<(const PARAM_VALUE & rhs) const + { return strcasecmp(param.c_str(), rhs.param.c_str()) < 0; } + + std::string param; + std::vector value; +}; +//----------------------------------------------------------------------------- +struct MODULE_SETTINGS +{ + MODULE_SETTINGS() + : moduleName(), + moduleParams() + {} + MODULE_SETTINGS(const MODULE_SETTINGS & rvalue) + : moduleName(rvalue.moduleName), + moduleParams(rvalue.moduleParams) + {} + bool operator==(const MODULE_SETTINGS & rhs) const + { return !strcasecmp(moduleName.c_str(), rhs.moduleName.c_str()); } + + bool operator<(const MODULE_SETTINGS & rhs) const + { return strcasecmp(moduleName.c_str(), rhs.moduleName.c_str()) < 0; } + + std::string moduleName; + std::vector moduleParams; +}; +//----------------------------------------------------------------------------- +#endif diff --git a/include/stg/noncopyable.h b/include/stg/noncopyable.h new file mode 100644 index 00000000..3d4c53b3 --- /dev/null +++ b/include/stg/noncopyable.h @@ -0,0 +1,14 @@ +#ifndef __NONCOPYABLE_H__ +#define __NONCOPYABLE_H__ + +class NONCOPYABLE +{ +protected: + NONCOPYABLE() {} + virtual ~NONCOPYABLE() {} +private: // emphasize the following members are private + NONCOPYABLE(const NONCOPYABLE &); + const NONCOPYABLE & operator=(const NONCOPYABLE &); +}; + +#endif diff --git a/include/stg/notifer.h b/include/stg/notifer.h new file mode 100644 index 00000000..57f9928e --- /dev/null +++ b/include/stg/notifer.h @@ -0,0 +1,29 @@ + /* + $Revision: 1.6 $ + $Date: 2007/12/03 09:00:17 $ + $Author: nobunaga $ + */ + +#ifndef PROPERTY_NOTIFER_H +#define PROPERTY_NOTIFER_H + +//----------------------------------------------------------------------------- +template +class PROPERTY_NOTIFIER_BASE +{ +public: + virtual ~PROPERTY_NOTIFIER_BASE(){}; + virtual void Notify(const varParamType & oldValue, const varParamType & newValue) = 0; +}; +//----------------------------------------------------------------------------- +template +class NOTIFIER_BASE +{ +public: + virtual ~NOTIFIER_BASE(){}; + virtual void Notify(const varParamType & value) = 0; +}; +//----------------------------------------------------------------------------- +#endif //PROPERTY_NOTIFER_H + + diff --git a/include/stg/os_int.h b/include/stg/os_int.h new file mode 100644 index 00000000..cc017b84 --- /dev/null +++ b/include/stg/os_int.h @@ -0,0 +1,61 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.4 $ + $Date: 2008/03/25 17:41:50 $ + */ + + +#ifndef OS_INT_H +#define OS_INT_H + +#ifdef LINUX +#include +#endif + +#ifdef FREE_BSD5 +#include +#endif + +#ifdef FREE_BSD +#include +#endif + +#ifdef WIN32 + +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; + +typedef int int32_t; +typedef unsigned int uint32_t; + +typedef short int int16_t; +typedef short unsigned int uint16_t; + +typedef char int8_t; +typedef unsigned char uint8_t; + + +#endif + + +#endif + diff --git a/include/stg/plugin.h b/include/stg/plugin.h new file mode 100644 index 00000000..d196b353 --- /dev/null +++ b/include/stg/plugin.h @@ -0,0 +1,65 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + +/* + $Revision: 1.12 $ + $Date: 2010/03/04 11:53:14 $ + $Author: faust $ +*/ + + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include + +#include "noncopyable.h" +#include "os_int.h" +#include "admins.h" +#include "users.h" +#include "tariffs.h" + +class TRAFFCOUNTER; +class SETTINGS; +class STORE; +class MODULE_SETTINGS; + +class PLUGIN : private NONCOPYABLE { +public: + virtual void SetUsers(USERS * u) = 0; + virtual void SetTariffs(TARIFFS * t) = 0; + virtual void SetAdmins(ADMINS * a) = 0; + virtual void SetTraffcounter(TRAFFCOUNTER * tc) = 0; + virtual void SetStore(STORE * st) = 0; + virtual void SetStgSettings(const SETTINGS * s) = 0; + virtual void SetSettings(const MODULE_SETTINGS & s) = 0; + virtual int ParseSettings() = 0; + + virtual int Start() = 0; + virtual int Stop() = 0; + virtual int Reload() = 0; + virtual bool IsRunning() = 0; + virtual const std::string & GetStrError() const = 0; + virtual const std::string GetVersion() const = 0; + virtual uint16_t GetStartPosition() const = 0; + virtual uint16_t GetStopPosition() const = 0; +}; + +#endif diff --git a/include/stg/rad_packets.h b/include/stg/rad_packets.h new file mode 100644 index 00000000..96cddc4b --- /dev/null +++ b/include/stg/rad_packets.h @@ -0,0 +1,41 @@ +#ifndef RAD_PACKETSH +#define RAD_PACKETSH + +#define RAD_MAGIC_LEN (5) +#define RAD_PROTO_VER_LEN (2) +#define RAD_MAX_PACKET_LEN (1024) +#define RAD_LOGIN_LEN (32) +#define RAD_SERVICE_LEN (16) +#define RAD_PASSWORD_LEN (32) +#define RAD_SESSID_LEN (32) + +// Request +#define RAD_AUTZ_PACKET (0) +#define RAD_AUTH_PACKET (1) +#define RAD_POST_AUTH_PACKET (2) +#define RAD_ACCT_START_PACKET (3) +#define RAD_ACCT_STOP_PACKET (4) +#define RAD_ACCT_UPDATE_PACKET (5) +#define RAD_ACCT_OTHER_PACKET (6) +// Responce +#define RAD_ACCEPT_PACKET (7) +#define RAD_REJECT_PACKET (8) + +#define RAD_ID "00100" + +#include "os_int.h" + +struct RAD_PACKET +{ +uint8_t magic[RAD_MAGIC_LEN]; +uint8_t protoVer[RAD_PROTO_VER_LEN]; +uint8_t packetType; +uint8_t login[RAD_LOGIN_LEN]; +uint32_t ip; +uint8_t service[RAD_SERVICE_LEN]; +uint8_t password[RAD_PASSWORD_LEN]; +uint8_t sessid[RAD_SESSID_LEN]; +uint8_t padding[4]; +}; + +#endif diff --git a/include/stg/raw_ip_packet.h b/include/stg/raw_ip_packet.h new file mode 100644 index 00000000..a1bdda71 --- /dev/null +++ b/include/stg/raw_ip_packet.h @@ -0,0 +1,168 @@ +#ifndef RAW_IP_PACKET_H +#define RAW_IP_PACKET_H + +#if defined(FREE_BSD) || defined(FREE_BSD5) +#include // n_long in netinet/ip.h +#endif + +#include // for htons +#include // for struct ip + +#include + +#include "stg_const.h" +#include "common.h" + +#define IPv4 (2) + +enum { pcktSize = 68 }; //60(max) ip + 8 udp or tcp (part of tcp or udp header to ports) +//----------------------------------------------------------------------------- +struct RAW_PACKET +{ + RAW_PACKET() + : dataLen(-1) + { + memset(pckt, 0, pcktSize); + } + + RAW_PACKET(const RAW_PACKET & rp) + : dataLen(rp.dataLen) + { + memcpy(pckt, rp.pckt, pcktSize); + } + +uint16_t GetIPVersion() const; +uint8_t GetHeaderLen() const; +uint8_t GetProto() const; +uint32_t GetLen() const; +uint32_t GetSrcIP() const; +uint32_t GetDstIP() const; +uint16_t GetSrcPort() const; +uint16_t GetDstPort() const; + +bool operator==(const RAW_PACKET & rvalue) const; +bool operator!=(const RAW_PACKET & rvalue) const { return !(*this == rvalue); }; +bool operator<(const RAW_PACKET & rvalue) const; + +union + { + uint8_t pckt[pcktSize]; // Packet header as a raw data + struct + { + struct ip ipHeader; + // Only for packets without options field + uint16_t sPort; + uint16_t dPort; + } header __attribute__ ((packed)); + }; +int32_t dataLen; // IP packet length. Set to -1 to use length field from the header +}; +//----------------------------------------------------------------------------- +inline uint16_t RAW_PACKET::GetIPVersion() const +{ +return header.ipHeader.ip_v; +} +//----------------------------------------------------------------------------- +inline uint8_t RAW_PACKET::GetHeaderLen() const +{ +return header.ipHeader.ip_hl * 4; +} +//----------------------------------------------------------------------------- +inline uint8_t RAW_PACKET::GetProto() const +{ +return header.ipHeader.ip_p; +} +//----------------------------------------------------------------------------- +inline uint32_t RAW_PACKET::GetLen() const +{ +if (dataLen != -1) + return dataLen; +return ntohs(header.ipHeader.ip_len); +} +//----------------------------------------------------------------------------- +inline uint32_t RAW_PACKET::GetSrcIP() const +{ +return header.ipHeader.ip_src.s_addr; +} +//----------------------------------------------------------------------------- +inline uint32_t RAW_PACKET::GetDstIP() const +{ +return header.ipHeader.ip_dst.s_addr; +} +//----------------------------------------------------------------------------- +inline uint16_t RAW_PACKET::GetSrcPort() const +{ +if (header.ipHeader.ip_p == 1) // for icmp proto return port 0 + return 0; +return ntohs(*((uint16_t*)(pckt + header.ipHeader.ip_hl * 4))); +} +//----------------------------------------------------------------------------- +inline uint16_t RAW_PACKET::GetDstPort() const +{ +if (header.ipHeader.ip_p == 1) // for icmp proto return port 0 + return 0; +return ntohs(*((uint16_t*)(pckt + header.ipHeader.ip_hl * 4 + 2))); +} +//----------------------------------------------------------------------------- +inline bool RAW_PACKET::operator==(const RAW_PACKET & rvalue) const +{ +if (header.ipHeader.ip_src.s_addr != rvalue.header.ipHeader.ip_src.s_addr) + return false; + +if (header.ipHeader.ip_dst.s_addr != rvalue.header.ipHeader.ip_dst.s_addr) + return false; + +if (header.ipHeader.ip_p != 1 && rvalue.header.ipHeader.ip_p != 1) + { + if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4)) != + *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4))) + return false; + + if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4 + 2)) != + *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4 + 2))) + return false; + } + +if (header.ipHeader.ip_p != rvalue.header.ipHeader.ip_p) + return false; + +return true; +} +//----------------------------------------------------------------------------- +inline bool RAW_PACKET::operator<(const RAW_PACKET & rvalue) const +{ +if (header.ipHeader.ip_src.s_addr < rvalue.header.ipHeader.ip_src.s_addr) + return true; +if (header.ipHeader.ip_src.s_addr > rvalue.header.ipHeader.ip_src.s_addr) + return false; + +if (header.ipHeader.ip_dst.s_addr < rvalue.header.ipHeader.ip_dst.s_addr) + return true; +if (header.ipHeader.ip_dst.s_addr > rvalue.header.ipHeader.ip_dst.s_addr) + return false; + +if (header.ipHeader.ip_p != 1 && rvalue.header.ipHeader.ip_p != 1) + { + if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4)) < + *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4))) + return true; + if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4)) > + *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4))) + return false; + + if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4 + 2)) < + *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4 + 2))) + return true; + if (*((uint16_t *)(pckt + header.ipHeader.ip_hl * 4 + 2)) > + *((uint16_t *)(rvalue.pckt + rvalue.header.ipHeader.ip_hl * 4 + 2))) + return false; + } + +if (header.ipHeader.ip_p < rvalue.header.ipHeader.ip_p) + return true; + +return false; +} +//----------------------------------------------------------------------------- + +#endif diff --git a/include/stg/resetable.h b/include/stg/resetable.h new file mode 100644 index 00000000..d31bffda --- /dev/null +++ b/include/stg/resetable.h @@ -0,0 +1,98 @@ + /* + $Revision: 1.9 $ + $Date: 2010/03/11 14:42:04 $ + $Author: faust $ + */ + +/* + * Copyright (c) 2001 by Peter Simons . + * All rights reserved. + */ + +#ifndef RESETABLE_VARIABLE_H +#define RESETABLE_VARIABLE_H + +// This is a wrapper class about variables where you want to keep +// track of whether it has been assigened yet or not. + +#include + +template +class RESETABLE +{ + template + friend std::ostream & operator<<(std::ostream & o, RESETABLE v); +public: + typedef varT value_type; + + //------------------------------------------------------------------------- + RESETABLE() + : value(), + is_set(false) + { + } + //------------------------------------------------------------------------- + RESETABLE(const RESETABLE & rvalue) + : value(rvalue.value), + is_set(rvalue.is_set) + { + } + //------------------------------------------------------------------------- + RESETABLE(const value_type& val) + : value(val), + is_set(true) + { + } + //------------------------------------------------------------------------- + RESETABLE & operator=(const RESETABLE & rvalue) + { + value = rvalue.value; + is_set = rvalue.is_set; + return *this; + } + //------------------------------------------------------------------------- + RESETABLE & operator= (const value_type& rhs) + { + value = rhs; + is_set = true; + return *this; + } + //------------------------------------------------------------------------- + const value_type& const_data() const throw() + { + return value; + } + //------------------------------------------------------------------------- + value_type& data() throw() + { + return value; + } + //------------------------------------------------------------------------- + operator const value_type&() const throw() + { + return value; + } + //------------------------------------------------------------------------- + bool res_empty() const throw() + { + return !is_set; + } + //------------------------------------------------------------------------- + void reset() throw() + { + is_set = false; + } + //------------------------------------------------------------------------- +protected: + value_type value; + bool is_set; +}; +//----------------------------------------------------------------------------- +template +std::ostream & operator<<(std::ostream & o, RESETABLE v) +{ + return o << v.value; +} +//------------------------------------------------------------------------- +#endif // RESETABLE_VARIABLE_H + diff --git a/include/stg/rs_packets.h b/include/stg/rs_packets.h new file mode 100644 index 00000000..1a038be7 --- /dev/null +++ b/include/stg/rs_packets.h @@ -0,0 +1,36 @@ +#ifndef RS_PACKETSH +#define RS_PACKETSH + +#define RS_MAGIC_LEN (6) +#define RS_PROTO_VER_LEN (2) +#define RS_MAX_PACKET_LEN (1048) +#define RS_LOGIN_LEN (32) +#define RS_PARAMS_LEN (979) + +#define RS_ALIVE_PACKET (0) +#define RS_CONNECT_PACKET (1) +#define RS_DISCONNECT_PACKET (2) + +#define RS_ID "RSP00" + +#include "os_int.h" + +struct RS_PACKET_HEADER +{ +int8_t magic[RS_MAGIC_LEN]; +int8_t protoVer[RS_PROTO_VER_LEN]; +int8_t packetType; +uint32_t ip; +uint32_t id; +int8_t login[RS_LOGIN_LEN]; +int8_t padding[7]; +} __attribute__((__packed__)); // 48 bytes, 6 blocks + +struct RS_PACKET_TAIL +{ +int8_t magic[RS_MAGIC_LEN]; +int8_t params[RS_PARAMS_LEN]; +int8_t padding[7]; +} __attribute__((__packed__)); // 992 bytes, 124 blocks + +#endif diff --git a/include/stg/service_conf.h b/include/stg/service_conf.h new file mode 100644 index 00000000..6c958c41 --- /dev/null +++ b/include/stg/service_conf.h @@ -0,0 +1,13 @@ +#ifndef SERVICE_CONF_H +#define SERVICE_CONF_H + +struct SERVICE_CONF +{ +string name; +string comment; +double cost; +int payDay; +}; + +#endif //SERVICE_CONF_H + diff --git a/include/stg/settings.h b/include/stg/settings.h new file mode 100644 index 00000000..e97f3e2a --- /dev/null +++ b/include/stg/settings.h @@ -0,0 +1,45 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include + +class SETTINGS { +public: + virtual const std::string & GetDirName(size_t num) const = 0; + virtual unsigned GetDetailStatWritePeriod() const = 0; + virtual unsigned GetStatWritePeriod() const = 0; + virtual unsigned GetDayFee() const = 0; + virtual bool GetFullFee() const = 0; + virtual unsigned GetDayResetTraff() const = 0; + virtual bool GetSpreadFee() const = 0; + virtual bool GetFreeMbAllowInet() const = 0; + virtual bool GetDayFeeIsLastDay() const = 0; + virtual bool GetWriteFreeMbTraffCost() const = 0; + virtual bool GetShowFeeInCash() const = 0; + virtual unsigned GetMessageTimeout() const = 0; + virtual const std::string & GetMonitorDir() const = 0; + virtual bool GetMonitoring() const = 0; +}; +//----------------------------------------------------------------------------- + +#endif diff --git a/include/stg/stg_const.h b/include/stg/stg_const.h new file mode 100644 index 00000000..e882200d --- /dev/null +++ b/include/stg/stg_const.h @@ -0,0 +1,87 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + + /* + $Author: nobunaga $ + $Revision: 1.10 $ + $Date: 2008/01/11 17:33:50 $ + */ + + +#ifndef STG_CONST_H +#define STG_CONST_H + +#define DIR_NUM (10) +#define SYS_IFACE_LEN (9) +#define IFACE_LEN (255) +#define MAX_IP (5) +#define USERDATA_NUM (10) + +#define LOGIN_LEN (32) +#define PASSWD_LEN (32) +#define ADDR_LEN (255) +#define NOTE_LEN (255) +#define REALNM_LEN (255) +#define GROUP_LEN (255) +#define PHONE_LEN (255) +#define EMAIL_LEN (255) +#define USR_IFACE_LEN (255) +#define USER_DATA_LEN (255) +#define IP_STRING_LEN (255) + +#define ADM_LOGIN_LEN (32) +#define ADM_PASSWD_LEN (32) +#define TARIFF_NAME_LEN (32) +#define SERVER_NAME_LEN (255) + +#define DIR_NAME_LEN (16) + +#define MAX_MSG_LEN (235) +#define MAX_MSG_LEN_8 (1030) + +#define LOGCASH (1) +#define NOLOGCASH (0) + +#define USERNOCASH (0) +#define USERDISCONNECT (1) + +#define LOGEVENT_CONNECT (0) +#define LOGEVENT_DISCONNECT (1) +#define LOGEVENT_NEW_MONTH (2) +#define LOGEVENT_NO_CASH (3) +#define LOGEVENT_CONNECT_NO_CASH (4) +#define LOGEVENT_USER_DOWN (5) +#define LOGEVENT_DELETED (6) + +#define SET_TARIFF_NOW (0) +#define SET_TARIFF_DELAYED (1) +#define SET_TARIFF_RECALC (2) + +#define CASH_SET (0) +#define CASH_ADD (1) + +#define NO_TARIFF_NAME "*_NO_TARIFF_*" +#define NO_CORP_NAME "*_NO_CORP_*" + +#define mega (1024 * 1024) + +#define MONITOR_TIME_DELAY_SEC (60) + +#endif diff --git a/include/stg/stg_message.h b/include/stg/stg_message.h new file mode 100644 index 00000000..16fe566f --- /dev/null +++ b/include/stg/stg_message.h @@ -0,0 +1,56 @@ +#ifndef STG_MESSAGES_H +#define STG_MESSAGES_H + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.3 $ + $Date: 2010/03/04 11:49:52 $ + */ + +#include +#include + +#include "os_int.h" + +//----------------------------------------------------------------------------- +struct STG_MSG_HDR +{ +STG_MSG_HDR() + : id(0), + ver(0), + type(0), + lastSendTime(0), + creationTime(0), + showTime(0), + repeat(0), + repeatPeriod(0) +{}; + +uint64_t id; +unsigned ver; +unsigned type; +unsigned lastSendTime; +unsigned creationTime; +unsigned showTime; +int repeat; +unsigned repeatPeriod; +}; +//----------------------------------------------------------------------------- +struct STG_MSG +{ +STG_MSG() {}; + +time_t GetNextSendTime() const +{ +return header.lastSendTime + header.repeat * 60; +}; + +STG_MSG_HDR header; +std::string text; +}; +//----------------------------------------------------------------------------- + +#endif diff --git a/include/stg/store.h b/include/stg/store.h new file mode 100644 index 00000000..f33a0653 --- /dev/null +++ b/include/stg/store.h @@ -0,0 +1,116 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.16 $ + $Date: 2010/01/19 11:09:48 $ + $Author: faust $ + */ + +#ifndef STORE_H +#define STORE_H + +#include +#include +#include + +#include "user_stat.h" +#include "user_conf.h" +#include "corp_conf.h" +#include "service_conf.h" +#include "admin_conf.h" +#include "tariff_conf.h" +#include "module_settings.h" +#include "stg_message.h" + +//----------------------------------------------------------------------------- +class STORE { +public: + virtual int GetUsersList(std::vector * usersList) const = 0; + virtual int AddUser(const std::string & login) const = 0; + virtual int DelUser(const std::string & login) const = 0; + virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const = 0; + virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const = 0; + virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const = 0; + virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const = 0; + + virtual int WriteUserChgLog(const std::string & login, + const std::string & admLogin, + uint32_t admIP, + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message = "") const = 0; + + virtual int WriteUserConnect(const std::string & login, uint32_t ip) const = 0; + + virtual int WriteUserDisconnect(const std::string & login, + const DIR_TRAFF & up, + const DIR_TRAFF & down, + const DIR_TRAFF & sessionUp, + const DIR_TRAFF & sessionDown, + double cash, + double freeMb, + const std::string & reason) const = 0; + + virtual int WriteDetailedStat(const TRAFF_STAT & statTree, + time_t lastStat, + const std::string & login) const = 0; + + virtual int AddMessage(STG_MSG * msg, const std::string & login) const = 0; + virtual int EditMessage(const STG_MSG & msg, const std::string & login) const = 0; + virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const = 0; + virtual int DelMessage(uint64_t id, const std::string & login) const = 0; + virtual int GetMessageHdrs(vector * hdrsList, const std::string & login) const = 0; + + virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const = 0; + + virtual int GetAdminsList(std::vector * adminsList) const = 0; + virtual int SaveAdmin(const ADMIN_CONF & ac) const = 0; + virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const = 0; + virtual int AddAdmin(const std::string & login) const = 0; + virtual int DelAdmin(const std::string & login) const = 0; + + virtual int GetTariffsList(std::vector * tariffsList) const = 0; + virtual int AddTariff(const std::string & name) const = 0; + virtual int DelTariff(const std::string & name) const = 0; + virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const = 0; + virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const = 0; + + virtual int GetCorpsList(std::vector * corpsList) const = 0; + virtual int SaveCorp(const CORP_CONF & cc) const = 0; + virtual int RestoreCorp(CORP_CONF * cc, const std::string & name) const = 0; + virtual int AddCorp(const std::string & name) const = 0; + virtual int DelCorp(const std::string & name) const = 0; + + virtual int GetServicesList(std::vector * corpsList) const = 0; + virtual int SaveService(const SERVICE_CONF & sc) const = 0; + virtual int RestoreService(SERVICE_CONF * sc, const std::string & name) const = 0; + virtual int AddService(const std::string & name) const = 0; + virtual int DelService(const std::string & name) const = 0; + + virtual void SetSettings(const MODULE_SETTINGS & s) = 0; + virtual int ParseSettings() = 0; + virtual const std::string & GetStrError() const = 0; + virtual const std::string & GetVersion() const = 0; +}; +//----------------------------------------------------------------------------- + +#endif diff --git a/include/stg/tariff.h b/include/stg/tariff.h new file mode 100644 index 00000000..b19ec476 --- /dev/null +++ b/include/stg/tariff.h @@ -0,0 +1,56 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef TARIFF_H +#define TARIFF_H + +#include + +#include + +#include "os_int.h" +#include "tariff_conf.h" + +class TARIFF { +public: + virtual double GetPriceWithTraffType(uint64_t up, + uint64_t down, + int dir, + time_t t) const = 0; + virtual double GetFreeMb() const = 0; + virtual double GetPassiveCost() const = 0; + virtual double GetFee() const = 0; + virtual double GetFree() const = 0; + + virtual const std::string & GetName() const = 0; + virtual void SetName(const std::string & name) = 0; + + virtual int GetTraffType() const = 0; + virtual int64_t GetTraffByType(uint64_t up, uint64_t down) const = 0; + virtual int GetThreshold(int dir) const = 0; + virtual const TARIFF_DATA & GetTariffData() const = 0; + + virtual TARIFF & operator=(const TARIFF_DATA & td) = 0; + virtual TARIFF & operator=(const TARIFF & t) = 0; + virtual bool operator==(const TARIFF & rhs) const = 0; + virtual bool operator!=(const TARIFF & rhs) const = 0; +}; + +#endif diff --git a/include/stg/tariff_conf.h b/include/stg/tariff_conf.h new file mode 100644 index 00000000..30f19815 --- /dev/null +++ b/include/stg/tariff_conf.h @@ -0,0 +1,225 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.9 $ + $Date: 2010/10/05 20:41:11 $ + $Author: faust $ + */ + +#ifndef TARIFF_CONF_H +#define TARIFF_CONF_H + +#include +#include + +#include "resetable.h" +#include "stg_const.h" + +//----------------------------------------------------------------------------- +enum +{ + TRAFF_UP = 0, + TRAFF_DOWN, + TRAFF_UP_DOWN, + TRAFF_MAX +}; +//----------------------------------------------------------------------------- +struct DIRPRICE_DATA +{ + DIRPRICE_DATA() + : hDay(0), + mDay(0), + hNight(0), + mNight(0), + priceDayA(0), + priceNightA(0), + priceDayB(0), + priceNightB(0), + threshold(0), + singlePrice(0), + noDiscount(0) + {} + int hDay; + int mDay; + int hNight; + int mNight; + double priceDayA; + double priceNightA; + double priceDayB; + double priceNightB; + int threshold; + int singlePrice; // Do not use day/night division + int noDiscount; // Do not use threshold +}; +//----------------------------------------------------------------------------- +struct DIRPRICE_DATA_RES +{ + DIRPRICE_DATA_RES & operator= (const DIRPRICE_DATA & dpd) + { + hDay = dpd.hDay; + mDay = dpd.mDay; + hNight = dpd.hNight; + mNight = dpd.mNight; + priceDayA = dpd.priceDayA; + priceNightA = dpd.priceNightA; + priceDayB = dpd.priceDayB; + priceNightB = dpd.priceNightB; + threshold = dpd.threshold; + singlePrice = dpd.singlePrice; + noDiscount = dpd.noDiscount; + return *this; + }; + + DIRPRICE_DATA GetData() + { + DIRPRICE_DATA dd; + dd.hDay = hDay; + dd.hNight = hNight; + dd.mDay = mDay; + dd.mNight = mNight; + dd.noDiscount = noDiscount; + dd.priceDayA = priceDayA; + dd.priceDayB = priceDayB; + + dd.priceNightA = priceNightA; + dd.priceNightB = priceNightB; + dd.singlePrice = singlePrice; + dd.threshold = threshold; + return dd; + } + + RESETABLE hDay; + RESETABLE mDay; + RESETABLE hNight; + RESETABLE mNight; + RESETABLE priceDayA; + RESETABLE priceNightA; + RESETABLE priceDayB; + RESETABLE priceNightB; + RESETABLE threshold; + RESETABLE singlePrice; + RESETABLE noDiscount; +}; +//----------------------------------------------------------------------------- +struct TARIFF_CONF +{ + double fee; // ÷ÅÌÉÞÉÎÁ ÁÂÏÎÐÌÁÔÙ + double free; // îÁ ËÁËÕÀ ÓÕÍÍÕ ÄÅÎÅÇ ÀÚÅÒ ËÁÞÁÅÔ ÂÅÓÐÌÁÔÎÏ + int traffType; // UP, DOWN, UP+DOWN, MAX + double passiveCost; // óÔÏÉÍÏÓÔØ ÚÁÍÏÒÏÚËÉ + std::string name; + + TARIFF_CONF() + : fee(0), + free(0), + traffType(TRAFF_UP_DOWN), // UP-DOWN + passiveCost(0), + name() + {}; + + TARIFF_CONF(const std::string & n) + : fee(0), + free(0), + traffType(TRAFF_UP_DOWN), // UP-DOWN + passiveCost(0), + name(n) + {}; +}; +//----------------------------------------------------------------------------- +struct TARIFF_CONF_RES +{ + TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc) + { + fee = tc.fee; + free = tc.free; + traffType = tc.traffType; + passiveCost = tc.passiveCost; + name = tc.name; + return *this; + }; + + TARIFF_CONF GetData() + { + TARIFF_CONF tc; + tc.fee = fee; + tc.free = free; + tc.name = name; + tc.passiveCost = passiveCost; + tc.traffType = traffType; + return tc; + } + + RESETABLE fee; + RESETABLE free; + RESETABLE traffType; + RESETABLE passiveCost; + RESETABLE name; +}; +//----------------------------------------------------------------------------- +struct TARIFF_DATA +{ + TARIFF_CONF tariffConf; + std::vector dirPrice; + + TARIFF_DATA() + : tariffConf(), + dirPrice(DIR_NUM) + {} + + TARIFF_DATA(const std::string & name) + : tariffConf(name), + dirPrice(DIR_NUM) + {} + + TARIFF_DATA(const TARIFF_DATA & td) + : tariffConf(td.tariffConf), + dirPrice(td.dirPrice) + {} + + TARIFF_DATA & operator=(const TARIFF_DATA & td) + { + tariffConf = td.tariffConf; + dirPrice = td.dirPrice; + return *this; + }; +}; +//----------------------------------------------------------------------------- +struct TARIFF_DATA_RES +{ + TARIFF_CONF_RES tariffConf; + std::vector dirPrice; + + TARIFF_DATA_RES() + : tariffConf(), + dirPrice(DIR_NUM) + {} + + TARIFF_DATA GetData() + { + TARIFF_DATA td; + td.tariffConf = tariffConf.GetData(); + for (int i = 0; i < DIR_NUM; i++) + td.dirPrice[i] = dirPrice[i].GetData(); + return td; + } +}; +//----------------------------------------------------------------------------- +#endif diff --git a/include/stg/tariffs.h b/include/stg/tariffs.h new file mode 100644 index 00000000..1f91948f --- /dev/null +++ b/include/stg/tariffs.h @@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef TARIFFS_H +#define TARIFFS_H + +#include +#include + +class ADMIN; +class TARIFF; +class TARIFF_DATA; + +class TARIFFS { +public: + virtual int ReadTariffs () = 0; + virtual const TARIFF * FindByName(const std::string & name) const = 0; + virtual const TARIFF * GetNoTariff() const = 0; + virtual int GetTariffsNum() const = 0; + virtual int Del(const std::string & name, const ADMIN * admin) = 0; + virtual int Add(const std::string & name, const ADMIN * admin) = 0; + virtual int Chg(const TARIFF_DATA & td, const ADMIN * admin) = 0; + + virtual void GetTariffsData(std::list * tdl) = 0; + + virtual const std::string & GetStrError() const = 0; +}; + +#endif diff --git a/include/stg/traffcounter.h b/include/stg/traffcounter.h new file mode 100644 index 00000000..1962ee7a --- /dev/null +++ b/include/stg/traffcounter.h @@ -0,0 +1,31 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : maxim Mamontov + */ + +#ifndef TRAFFCOUNTER_H +#define TRAFFCOUNTER_H + +#include "raw_ip_packet.h" + +class TRAFFCOUNTER { +public: + virtual void Process(const RAW_PACKET & rawPacket) = 0; +}; + +#endif diff --git a/include/stg/user.h b/include/stg/user.h new file mode 100644 index 00000000..adf140de --- /dev/null +++ b/include/stg/user.h @@ -0,0 +1,111 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef USER_H +#define USER_H + +#include +#include + +#include "os_int.h" +#include "notifer.h" +#include "stg_message.h" +#include "tariff.h" +#include "user_traff.h" + +class USER_PROPERTIES; +class AUTH; + +class USER { +public: + virtual int WriteConf() = 0; + virtual int WriteStat() = 0; + + virtual const std::string & GetLogin() const = 0; + + virtual uint32_t GetCurrIP() const = 0; + virtual time_t GetCurrIPModificationTime() const = 0; + + virtual void AddCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + virtual void DelCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + + virtual void AddCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + virtual void DelCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + + virtual void AddConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + virtual void DelConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + + virtual void AddConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + virtual void DelConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + + virtual int GetID() const = 0; + + virtual double GetPassiveTimePart() const = 0; + + virtual const TARIFF * GetTariff() const = 0; + virtual void ResetNextTariff() = 0; + + #ifdef TRAFF_STAT_WITH_PORTS + virtual void AddTraffStatU(int dir, uint32_t ip, uint16_t port, uint32_t len) = 0; + virtual void AddTraffStatD(int dir, uint32_t ip, uint16_t port, uint32_t len) = 0; + #else + virtual void AddTraffStatU(int dir, uint32_t ip, uint32_t len) = 0; + virtual void AddTraffStatD(int dir, uint32_t ip, uint32_t len) = 0; + #endif + + virtual const DIR_TRAFF & GetSessionUpload() const = 0; + virtual const DIR_TRAFF & GetSessionDownload() const = 0; + + virtual bool GetConnected() const = 0; + virtual time_t GetConnectedModificationTime() const = 0; + virtual int GetAuthorized() const = 0; + virtual int Authorize(uint32_t ip, + uint32_t enabledDirs, + const AUTH * auth) = 0; + virtual void Unauthorize(const AUTH * auth) = 0; + virtual bool IsAuthorizedBy(const AUTH * auth) const = 0; + + virtual int AddMessage(STG_MSG * msg) = 0; + + virtual void UpdatePingTime(time_t t = 0) = 0; + virtual time_t GetPingTime() const = 0; + + virtual void Run() = 0; + + virtual const std::string & GetStrError() const = 0; + + virtual USER_PROPERTIES & GetProperty() = 0; + virtual const USER_PROPERTIES & GetProperty() const = 0; + + virtual bool GetDeleted() const = 0; + virtual void SetDeleted() = 0; + + virtual time_t GetLastWriteStatTime() const = 0; + + virtual bool IsInetable() = 0; + virtual std::string GetEnabledDirs() = 0; + + virtual void OnAdd() = 0; + virtual void OnDelete() = 0; +}; + +typedef USER * USER_PTR; + +#endif diff --git a/include/stg/user_conf.h b/include/stg/user_conf.h new file mode 100644 index 00000000..9a6efb23 --- /dev/null +++ b/include/stg/user_conf.h @@ -0,0 +1,158 @@ + /* + $Revision: 1.12 $ + $Date: 2010/03/11 14:42:05 $ + $Author: faust $ + */ + +#ifndef USER_CONF_H +#define USER_CONF_H + +#include +#include +#include "stg_const.h" +#include "user_ips.h" +#include "resetable.h" +#include "os_int.h" + +//----------------------------------------------------------------------------- +struct USER_CONF +{ + USER_CONF() + : password(), + passive(0), + disabled(0), + disabledDetailStat(0), + alwaysOnline(0), + tariffName(), + address(), + phone(), + email(), + note(), + realName(), + corp(), + service(), + group(), + credit(0), + nextTariff(), + userdata(USERDATA_NUM), + creditExpire(0), + ips() + {}; + + std::string password; + int passive; + int disabled; + int disabledDetailStat; + int alwaysOnline; + std::string tariffName; + std::string address; + std::string phone; + std::string email; + std::string note; + std::string realName; + std::string corp; + std::vector service; + std::string group; + double credit; + std::string nextTariff; + std::vector userdata; + time_t creditExpire; + USER_IPS ips; +}; +//----------------------------------------------------------------------------- +struct USER_CONF_RES +{ + USER_CONF_RES() + : password(), + passive(), + disabled(), + disabledDetailStat(), + alwaysOnline(), + tariffName(), + address(), + phone(), + email(), + note(), + realName(), + group(), + credit(), + nextTariff(), + userdata(USERDATA_NUM, RESETABLE()), + creditExpire(), + ips() + { + }; + + USER_CONF_RES & operator=(const USER_CONF & uc) + { + userdata.resize(USERDATA_NUM); + password = uc.password; + passive = uc.passive; + disabled = uc.disabled; + disabledDetailStat = uc.disabledDetailStat; + alwaysOnline = uc.alwaysOnline; + tariffName = uc.tariffName; + address = uc.address; + phone = uc.phone; + email = uc.email; + note = uc.note; + realName = uc.realName; + group = uc.group; + credit = uc.credit; + nextTariff = uc.nextTariff; + for (int i = 0; i < USERDATA_NUM; i++) + { + userdata[i] = uc.userdata[i]; + } + creditExpire = uc.creditExpire; + ips = uc.ips; + return *this; + }; + operator USER_CONF() const + { + USER_CONF uc; + uc.password = password; + uc.passive = passive; + uc.disabled = disabled; + uc.disabledDetailStat = disabledDetailStat; + uc.alwaysOnline = alwaysOnline; + uc.tariffName = tariffName; + uc.address = address; + uc.phone = phone; + uc.email = email; + uc.note = note; + uc.realName = realName; + uc.group = group; + uc.credit = credit; + uc.nextTariff = nextTariff; + for (int i = 0; i < USERDATA_NUM; i++) + { + uc.userdata[i] = userdata[i]; + } + uc.creditExpire = creditExpire; + uc.ips = ips; + return uc; + } + //------------------------------------------------------------------------- + + RESETABLE password; + RESETABLE passive; + RESETABLE disabled; + RESETABLE disabledDetailStat; + RESETABLE alwaysOnline; + RESETABLE tariffName; + RESETABLE address; + RESETABLE phone; + RESETABLE email; + RESETABLE note; + RESETABLE realName; + RESETABLE group; + RESETABLE credit; + RESETABLE nextTariff; + std::vector > userdata; + RESETABLE creditExpire; + RESETABLE ips; +}; +//----------------------------------------------------------------------------- +#endif + diff --git a/include/stg/user_ips.h b/include/stg/user_ips.h new file mode 100644 index 00000000..250520b2 --- /dev/null +++ b/include/stg/user_ips.h @@ -0,0 +1,280 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.22 $ + $Date: 2010/03/04 11:49:53 $ + $Author: faust $ + */ + +#ifndef USER_IPS_H +#define USER_IPS_H + +#ifdef FREE_BSD +#include +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "common.h" +#include "os_int.h" + +using namespace std; + +//------------------------------------------------------------------------- +struct IP_MASK +{ +IP_MASK() : ip(0), mask(0) {} +IP_MASK(const IP_MASK & ipm) : ip(ipm.ip), mask(ipm.mask) {} +uint32_t ip; +uint32_t mask; +}; +//------------------------------------------------------------------------- +class USER_IPS +{ + friend std::ostream & operator<< (ostream & o, const USER_IPS & i); + //friend stringstream & operator<< (stringstream & s, const USER_IPS & i); + friend const USER_IPS StrToIPS(const string & ipsStr) throw(string); + +public: + USER_IPS(); + USER_IPS(const USER_IPS &); + USER_IPS & operator=(const USER_IPS &); + const IP_MASK & operator[](int idx) const; + std::string GetIpStr() const; + bool IsIPInIPS(uint32_t ip) const; + bool OnlyOneIP() const; + int Count() const; + void Add(const IP_MASK &im); + void Erase(); + +private: + uint32_t CalcMask(unsigned int msk) const; + std::vector ips; +}; +//------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +inline +USER_IPS::USER_IPS() + : ips() +{} +//----------------------------------------------------------------------------- +inline +USER_IPS::USER_IPS(const USER_IPS & i) + : ips(i.ips) +{} +//----------------------------------------------------------------------------- +inline +USER_IPS & USER_IPS::operator=(const USER_IPS & i) +{ +ips = i.ips; +return *this; +} +//----------------------------------------------------------------------------- +inline +const IP_MASK & USER_IPS::operator[](int idx) const +{ +return ips[idx]; +} +//----------------------------------------------------------------------------- +inline +std::string USER_IPS::GetIpStr() const +{ +if (ips.empty()) + { + return ""; + } + +if (ips[0].ip == 0) + { + return "*"; + } + +std::vector::const_iterator it(ips.begin()); +std::stringstream s; +s << inet_ntostring(it->ip); +++it; +for (; it != ips.end(); ++it) + { + s << "," << inet_ntostring(it->ip); + } +return s.str(); +} +//----------------------------------------------------------------------------- +inline +int USER_IPS::Count() const +{ +return ips.size(); +} +//----------------------------------------------------------------------------- +inline +bool USER_IPS::IsIPInIPS(uint32_t ip) const +{ +if (ips.empty()) + { + return false; + } + +if (ips.front().ip == 0) + return true; + +for (std::vector::const_iterator it(ips.begin()); it != ips.end(); ++it) + { + uint32_t mask(CalcMask(it->mask)); + if ((ip & mask) == (it->ip & mask)) + return true; + } +return false; +} +//----------------------------------------------------------------------------- +inline +bool USER_IPS::OnlyOneIP() const +{ +if (ips.size() == 1 && ips.front().mask == 32) + return true; + +return false; +} +//----------------------------------------------------------------------------- +inline +uint32_t USER_IPS::CalcMask(unsigned int msk) const +{ +if (msk > 32) + return 0; +return htonl(0xFFffFFff << (32 - msk)); +} +//----------------------------------------------------------------------------- +inline +void USER_IPS::Add(const IP_MASK &im) +{ +ips.push_back(im); +} +//----------------------------------------------------------------------------- +inline +void USER_IPS::Erase() +{ +ips.erase(ips.begin(), ips.end()); +} +//----------------------------------------------------------------------------- +inline +std::ostream & operator<<(std::ostream & o, const USER_IPS & i) +{ +return o << i.GetIpStr(); +} +//----------------------------------------------------------------------------- +/*inline +stringstream & operator<<(std::stringstream & s, const USER_IPS & i) +{ +s << i.GetIpStr(); +return s; +}*/ +//----------------------------------------------------------------------------- +inline +const USER_IPS StrToIPS(const std::string & ipsStr) throw(std::string) +{ +USER_IPS ips; +char * paddr; +IP_MASK im; +std::vector ipMask; +std::string err; +if (ipsStr.empty()) + { + return ips; + } + +if (ipsStr[0] == '*' && ipsStr.size() == 1) + { + im.ip = 0; + im.mask = 0; + ips.ips.push_back(im); + return ips; + } + +char * str = new char[ipsStr.size() + 1]; +strcpy(str, ipsStr.c_str()); +char * pstr = str; +while ((paddr = strtok(pstr, ","))) + { + pstr = NULL; + ipMask.push_back(paddr); + } + +delete[] str; + +for (unsigned int i = 0; i < ipMask.size(); i++) + { + char str[128]; + char * strIp; + char * strMask; + strcpy(str, ipMask[i].c_str()); + strIp = strtok(str, "/"); + if (strIp == NULL) + { + err = "Incorrect IP address " + ipsStr; + return ips; + } + strMask = strtok(NULL, "/"); + + im.ip = inet_addr(strIp); + if (im.ip == INADDR_NONE) + { + err = "Incorrect IP address: " + std::string(strIp); + return ips; + } + + im.mask = 32; + if (strMask != NULL) + { + int m = 0; + if (str2x(strMask, m) != 0) + { + err = "Incorrect mask: " + std::string(strMask); + return ips; + } + im.mask = m; + + if (im.mask > 32) + { + err = "Incorrect mask: " + std::string(strMask); + return ips; + } + + if ((im.ip & ips.CalcMask(im.mask)) != im.ip) + { + err = "Address does'n match mask: " + std::string(strIp) + "/" + std::string(strMask); + return ips; + } + } + ips.ips.push_back(im); + } + +return ips; +} +//------------------------------------------------------------------------- +#endif //USER_IPS_H diff --git a/include/stg/user_property.h b/include/stg/user_property.h new file mode 100644 index 00000000..78e5675a --- /dev/null +++ b/include/stg/user_property.h @@ -0,0 +1,384 @@ +/* +$Revision: 1.44 $ +$Date: 2010/09/13 05:54:43 $ +$Author: faust $ +*/ + +#ifndef USER_PROPERTY_H +#define USER_PROPERTY_H + +#include // access + +#include +#include +#include +#include +#include + +#include "store.h" +#include "admin.h" +#include "notifer.h" +#include "stg_logger.h" +#include "stg_locker.h" +#include "script_executer.h" +#include "noncopyable.h" + +extern const volatile time_t stgTime; + +//----------------------------------------------------------------------------- +template +class USER_PROPERTY { +public: + USER_PROPERTY(varT & val); + virtual ~USER_PROPERTY(); + + void Set(const varT & rvalue); + + USER_PROPERTY & operator= (const varT & rvalue); + + const varT * operator&() const throw() { return &value; } + const varT & ConstData() const throw() { return value; } + + operator const varT&() const throw() { return value; } + + void AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); + void DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); + + void AddAfterNotifier(PROPERTY_NOTIFIER_BASE * n); + void DelAfterNotifier(PROPERTY_NOTIFIER_BASE * n); + + time_t ModificationTime() const throw() { return modificationTime; } + void ModifyTime() throw(); + +private: + varT & value; + time_t modificationTime; + std::set *> beforeNotifiers; + std::set *> afterNotifiers; + pthread_mutex_t mutex; +}; +//----------------------------------------------------------------------------- +template +class USER_PROPERTY_LOGGED: public USER_PROPERTY { +public: + USER_PROPERTY_LOGGED(varT & val, + const std::string & n, + bool isPassword, + bool isStat, + STG_LOGGER & logger, + const std::string & sd); + virtual ~USER_PROPERTY_LOGGED() {} + + USER_PROPERTY_LOGGED * GetPointer() throw() { return this; } + const varT & Get() const { return USER_PROPERTY::ConstData(); } + const std::string & GetName() const { return name; } + bool Set(const varT & val, + const ADMIN * admin, + const std::string & login, + const STORE * store, + const std::string & msg = ""); +private: + void WriteAccessDenied(const std::string & login, + const ADMIN * admin, + const std::string & parameter); + + void WriteSuccessChange(const std::string & login, + const ADMIN * admin, + const std::string & parameter, + const std::string & oldValue, + const std::string & newValue, + const std::string & msg, + const STORE * store); + + void OnChange(const std::string & login, + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const ADMIN * admin); + + STG_LOGGER & stgLogger; + bool isPassword; + bool isStat; + std::string name; + const std::string scriptsDir; +}; +//----------------------------------------------------------------------------- +class USER_PROPERTIES : private NONCOPYABLE { +/* + В этом месте важен порядок следования приватной и открытой частей. + Это связано с тем, что часть которая находится в публичной секции + по сути является завуалированной ссылкой на закрытую часть. Т.о. нам нужно + чтобы конструкторы из закрытой части вызвались раньше открытой. Поэтомому в + начале идет закрытая секция + * */ + +private: + USER_STAT stat; + USER_CONF conf; + +public: + USER_PROPERTIES(const std::string & sd); + + USER_STAT & Stat() { return stat; } + USER_CONF & Conf() { return conf; } + const USER_STAT & GetStat() const { return stat; } + const USER_CONF & GetConf() const { return conf; } + void SetStat(const USER_STAT & s) { stat = s; } + void SetConf(const USER_CONF & c) { conf = c; } + + void SetProperties(const USER_PROPERTIES & p) { stat = p.stat; conf = p.conf; } + + USER_PROPERTY_LOGGED cash; + USER_PROPERTY_LOGGED up; + USER_PROPERTY_LOGGED down; + USER_PROPERTY_LOGGED lastCashAdd; + USER_PROPERTY_LOGGED passiveTime; + USER_PROPERTY_LOGGED lastCashAddTime; + USER_PROPERTY_LOGGED freeMb; + USER_PROPERTY_LOGGED lastActivityTime; + + USER_PROPERTY_LOGGED password; + USER_PROPERTY_LOGGED passive; + USER_PROPERTY_LOGGED disabled; + USER_PROPERTY_LOGGED disabledDetailStat; + USER_PROPERTY_LOGGED alwaysOnline; + USER_PROPERTY_LOGGED tariffName; + USER_PROPERTY_LOGGED nextTariff; + USER_PROPERTY_LOGGED address; + USER_PROPERTY_LOGGED note; + USER_PROPERTY_LOGGED group; + USER_PROPERTY_LOGGED email; + USER_PROPERTY_LOGGED phone; + USER_PROPERTY_LOGGED realName; + USER_PROPERTY_LOGGED credit; + USER_PROPERTY_LOGGED creditExpire; + USER_PROPERTY_LOGGED ips; + USER_PROPERTY_LOGGED userdata0; + USER_PROPERTY_LOGGED userdata1; + USER_PROPERTY_LOGGED userdata2; + USER_PROPERTY_LOGGED userdata3; + USER_PROPERTY_LOGGED userdata4; + USER_PROPERTY_LOGGED userdata5; + USER_PROPERTY_LOGGED userdata6; + USER_PROPERTY_LOGGED userdata7; + USER_PROPERTY_LOGGED userdata8; + USER_PROPERTY_LOGGED userdata9; +}; +//============================================================================= + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +template +inline +USER_PROPERTY::USER_PROPERTY(varT & val) + : value(val), + modificationTime(stgTime) +{ +pthread_mutex_init(&mutex, NULL); +} +//----------------------------------------------------------------------------- +template +inline +USER_PROPERTY::~USER_PROPERTY() +{ +pthread_mutex_destroy(&mutex); +} +//----------------------------------------------------------------------------- +template +inline +void USER_PROPERTY::ModifyTime() throw() +{ +modificationTime = stgTime; +} +//----------------------------------------------------------------------------- +template +inline +void USER_PROPERTY::Set(const varT & rvalue) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); + +typename std::set *>::iterator ni; + +varT oldVal = value; + +ni = beforeNotifiers.begin(); +while (ni != beforeNotifiers.end()) + (*ni++)->Notify(oldVal, rvalue); + +value = rvalue; +modificationTime = stgTime; + +ni = afterNotifiers.begin(); +while (ni != afterNotifiers.end()) + (*ni++)->Notify(oldVal, rvalue); +} +//----------------------------------------------------------------------------- +template +inline +USER_PROPERTY & USER_PROPERTY::operator= (const varT & newValue) +{ +Set(newValue); +return *this; +} +//----------------------------------------------------------------------------- +template +inline +void USER_PROPERTY::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); +beforeNotifiers.insert(n); +} +//----------------------------------------------------------------------------- +template +inline +void USER_PROPERTY::DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); +beforeNotifiers.erase(n); +} +//----------------------------------------------------------------------------- +template +inline +void USER_PROPERTY::AddAfterNotifier(PROPERTY_NOTIFIER_BASE * n) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); +afterNotifiers.insert(n); +} +//----------------------------------------------------------------------------- +template +inline +void USER_PROPERTY::DelAfterNotifier(PROPERTY_NOTIFIER_BASE * n) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); +afterNotifiers.erase(n); +} +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +template +inline +USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, + const std::string & n, + bool isPass, + bool isSt, + STG_LOGGER & logger, + const std::string & sd) + + : USER_PROPERTY(val), + stgLogger(logger), + isPassword(isPass), + isStat(isSt), + name(n), + scriptsDir(sd) +{ +} +//------------------------------------------------------------------------- +template +bool USER_PROPERTY_LOGGED::Set(const varT & val, + const ADMIN * admin, + const std::string & login, + const STORE * store, + const std::string & msg) +{ +const PRIV * priv = admin->GetPriv(); +std::string adm_login = admin->GetLogin(); +std::string adm_ip = admin->GetIPStr(); + +if ((priv->userConf && !isStat) || + (priv->userStat && isStat) || + (priv->userPasswd && isPassword) || + (priv->userCash && name == "cash")) + { + std::stringstream oldVal; + std::stringstream newVal; + + oldVal.flags(oldVal.flags() | ios::fixed); + newVal.flags(newVal.flags() | ios::fixed); + + oldVal << USER_PROPERTY::ConstData(); + newVal << val; + + OnChange(login, name, oldVal.str(), newVal.str(), admin); + + if (isPassword) + { + WriteSuccessChange(login, admin, name, "******", "******", msg, store); + } + else + { + WriteSuccessChange(login, admin, name, oldVal.str(), newVal.str(), msg, store); + } + USER_PROPERTY::Set(val); + return true; + } +else + { + WriteAccessDenied(login, admin, name); + return false; + } +return true; +} +//------------------------------------------------------------------------- +template +inline +void USER_PROPERTY_LOGGED::WriteAccessDenied(const std::string & login, + const ADMIN * admin, + const std::string & parameter) +{ +stgLogger("%s Change user \'%s.\' Parameter \'%s\'. Access denied.", + admin->GetLogStr().c_str(), login.c_str(), parameter.c_str()); +} +//------------------------------------------------------------------------- +template +inline +void USER_PROPERTY_LOGGED::WriteSuccessChange(const std::string & login, + const ADMIN * admin, + const std::string & parameter, + const std::string & oldValue, + const std::string & newValue, + const std::string & msg, + const STORE * store) +{ +stgLogger("%s User \'%s\': \'%s\' parameter changed from \'%s\' to \'%s\'. %s", + admin->GetLogStr().c_str(), + login.c_str(), + parameter.c_str(), + oldValue.c_str(), + newValue.c_str(), + msg.c_str()); + +store->WriteUserChgLog(login, admin->GetLogin(), admin->GetIP(), parameter, oldValue, newValue, msg); +} +//------------------------------------------------------------------------- +template +void USER_PROPERTY_LOGGED::OnChange(const std::string & login, + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const ADMIN * admin) +{ +std::string filePath = scriptsDir + "/OnChange"; + +if (access(filePath.c_str(), X_OK) == 0) + { + std::string execString("\"" + filePath + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin->GetLogin() + "\" \"" + admin->GetIPStr() + "\""); + ScriptExec(execString); + } +else + { + stgLogger("Script OnChange cannot be executed. File %s not found.", filePath.c_str()); + } +} +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- +template +inline +ostream & operator<< (ostream & stream, const USER_PROPERTY & value) +{ +return stream << value.ConstData(); +} +//----------------------------------------------------------------------------- + +#endif // USER_PROPERTY_H diff --git a/include/stg/user_stat.h b/include/stg/user_stat.h new file mode 100644 index 00000000..42d436fd --- /dev/null +++ b/include/stg/user_stat.h @@ -0,0 +1,189 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.15 $ + $Date: 2010/03/11 14:42:05 $ + $Author: faust $ + */ + +#ifndef USER_STAT_H +#define USER_STAT_H + +#include +#include + +#include "os_int.h" +#include "resetable.h" +#include "user_traff.h" +//----------------------------------------------------------------------------- +struct IP_DIR_PAIR +{ + #ifdef TRAFF_STAT_WITH_PORTS + IP_DIR_PAIR(uint32_t _ip, + int _dir, + uint16_t _port) + : ip(_ip), + dir(_dir), + port(_port) + {} + #else + IP_DIR_PAIR(uint32_t _ip, + int _dir) + : ip(_ip), + dir(_dir) + {} + #endif + //------------------------ + bool operator<(const IP_DIR_PAIR & idp) const + { + if (ip < idp.ip) + return true; + + if (ip > idp.ip) + return false; + + #ifdef TRAFF_STAT_WITH_PORTS + if (port < idp.port) + return true; + + if (port > idp.port) + return false; + #endif + + if (dir < idp.dir) + return true; + + return false; + } + //------------------------ + bool operator!=(const IP_DIR_PAIR & rvalue) const + { + if (ip != rvalue.ip) + return true; + + #ifdef TRAFF_STAT_WITH_PORTS + if (port != rvalue.port) + return true; + #endif + + if (dir != rvalue.dir) + return true; + + return false; + } + //------------------------ + uint32_t ip; + int dir; + #ifdef TRAFF_STAT_WITH_PORTS + uint16_t port; + #endif +}; +//----------------------------------------------------------------------------- +struct STAT_NODE +{ + STAT_NODE(uint64_t _up, + uint64_t _down, + double _cash) + : up(_up), + down(_down), + cash(_cash) + {} + uint64_t up; + uint64_t down; + double cash; +}; +//----------------------------------------------------------------------------- +struct USER_STAT +{ + //USER_STAT & operator= (const USER_STAT_RES & usr); + USER_STAT() + : up(), + down(), + cash(0), + freeMb(0), + lastCashAdd(0), + lastCashAddTime(0), + passiveTime(0), + lastActivityTime(0) + {}; + + DIR_TRAFF up; + DIR_TRAFF down; + double cash; + double freeMb; + double lastCashAdd; + time_t lastCashAddTime; + time_t passiveTime; + time_t lastActivityTime; +}; +//----------------------------------------------------------------------------- +typedef std::map TRAFF_STAT; +//----------------------------------------------------------------------------- +struct USER_STAT_RES +{ + USER_STAT_RES() + : cash(), + freeMb(), + lastCashAdd(), + lastCashAddTime(), + passiveTime(), + lastActivityTime(), + up(), + down() + {} + + USER_STAT_RES & operator= (const USER_STAT & us) + { + cash = us.cash; + freeMb = us.freeMb; + lastCashAdd = us.lastCashAdd; + lastCashAddTime = us.lastCashAddTime; + passiveTime = us.passiveTime; + lastActivityTime = us.lastActivityTime; + up = us.up; + down = us.down; + return * this; + }; + operator USER_STAT() const + { + USER_STAT us; + us.cash = cash; + us.freeMb = freeMb; + us.lastCashAdd = lastCashAdd; + us.lastCashAddTime = lastCashAddTime; + us.passiveTime = passiveTime; + us.lastActivityTime = lastActivityTime; + us.up = up; + us.down = down; + return us; + }; + + RESETABLE cash; + RESETABLE freeMb; + RESETABLE lastCashAdd; + RESETABLE lastCashAddTime; + RESETABLE passiveTime; + RESETABLE lastActivityTime; + RESETABLE up; + RESETABLE down; +}; +//----------------------------------------------------------------------------- +#endif diff --git a/include/stg/user_traff.h b/include/stg/user_traff.h new file mode 100644 index 00000000..fdefee0f --- /dev/null +++ b/include/stg/user_traff.h @@ -0,0 +1,111 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + */ + +/* + $Revision: 1.7 $ + $Date: 2010/10/07 19:48:52 $ + $Author: faust $ + */ + +#ifndef USER_TRAFF_H +#define USER_TRAFF_H + +#include +#include + +#include "stg_const.h" +#include "os_int.h" + +enum TRAFF_DIRECTION {TRAFF_UPLOAD, TRAFF_DOWNLOAD}; + +class DIR_TRAFF +{ + friend std::ostream & operator<< (std::ostream & o, const DIR_TRAFF & traff); + +public: + //------------------------------------------------------------------------- + DIR_TRAFF(); + DIR_TRAFF(const DIR_TRAFF & ts); + DIR_TRAFF & operator=(const DIR_TRAFF & ts); + ~DIR_TRAFF(); + uint64_t operator[](int idx) const; + uint64_t & operator[](int idx); + DIR_TRAFF operator+(const DIR_TRAFF & ts); + +private: + std::vector traff; +}; +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +inline DIR_TRAFF::DIR_TRAFF() + : traff(DIR_NUM, 0) +{ +} +//----------------------------------------------------------------------------- +inline DIR_TRAFF::DIR_TRAFF(const DIR_TRAFF & ts) + : traff(ts.traff) +{ +} +//----------------------------------------------------------------------------- +inline DIR_TRAFF::~DIR_TRAFF() +{ +} +//----------------------------------------------------------------------------- +inline DIR_TRAFF & DIR_TRAFF::operator=(const DIR_TRAFF & ts) +{ +traff = ts.traff; +return *this; +}; +//----------------------------------------------------------------------------- +inline uint64_t & DIR_TRAFF::operator[](int idx) +{ +return traff[idx]; +}; +//----------------------------------------------------------------------------- +inline uint64_t DIR_TRAFF::operator[](int idx) const +{ +return traff[idx]; +}; +//----------------------------------------------------------------------------- +inline DIR_TRAFF DIR_TRAFF::operator+(const DIR_TRAFF & ts) +{ +for (int i = 0; i < DIR_NUM; i++) + { + traff[i] = traff[i] + ts.traff[i]; + } +return *this; +}; +//----------------------------------------------------------------------------- +inline std::ostream & operator<<(std::ostream & o, const DIR_TRAFF & traff) +{ +bool first = true; +for (size_t i = 0; i < DIR_NUM; ++i) + { + if (first) + first = false; + else + o << ","; + o << traff[i]; + } +return o; +} +//----------------------------------------------------------------------------- +#endif diff --git a/include/stg/users.h b/include/stg/users.h new file mode 100644 index 00000000..50f5ffe2 --- /dev/null +++ b/include/stg/users.h @@ -0,0 +1,60 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef USERS_H +#define USERS_H + +#include + +#include "notifer.h" +#include "user.h" + +class ADMIN; + +class USERS { +public: + virtual int FindByName(const std::string & login, USER_PTR * user) = 0; + + virtual bool TariffInUse(const std::string & tariffName) const = 0; + + virtual void AddNotifierUserAdd(NOTIFIER_BASE * notifier) = 0; + virtual void DelNotifierUserAdd(NOTIFIER_BASE * notifier) = 0; + + virtual void AddNotifierUserDel(NOTIFIER_BASE * notifier) = 0; + virtual void DelNotifierUserDel(NOTIFIER_BASE * notifier) = 0; + + virtual int Add(const std::string & login, const ADMIN * admin) = 0; + virtual void Del(const std::string & login, const ADMIN * admin) = 0; + + virtual int ReadUsers() = 0; + virtual int GetUserNum() const = 0; + + virtual int FindByIPIdx(uint32_t ip, USER_PTR * user) const = 0; + virtual bool IsIPInIndex(uint32_t ip) const = 0; + + virtual int OpenSearch() = 0; + virtual int SearchNext(int handle, USER_PTR * u) = 0; + virtual int CloseSearch(int handle) = 0; + + virtual int Start() = 0; + virtual int Stop() = 0; +}; + +#endif diff --git a/include/stg/utime.h b/include/stg/utime.h new file mode 100644 index 00000000..20da4e43 --- /dev/null +++ b/include/stg/utime.h @@ -0,0 +1,170 @@ +#ifndef UTIME_H +#define UTIME_H + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Date: 22.12.2007 + */ + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.6 $ + $Date: 2009/08/05 11:40:30 $ + $Author: faust $ + */ + +#include +#include + +#ifdef FREE_BSD +typedef long suseconds_t; +#endif + +struct UTIME: public timeval +{ + UTIME() + { + tv_sec = 0; + tv_usec = 0; + } + + UTIME(time_t t) + { + tv_sec = t; + tv_usec = 0; + } + + UTIME(long long a, long long b) + { + tv_sec = a; + tv_usec = b; + } + + bool operator<(const UTIME & rhs) const + { + if (tv_sec < rhs.tv_sec) + return true; + else if (tv_sec > rhs.tv_sec) + return false; + else if (tv_usec < rhs.tv_usec) + return true; + return false; + } + + bool operator<=(const UTIME & rhs) const + { + if (tv_sec < rhs.tv_sec) + return true; + else if (tv_sec > rhs.tv_sec) + return false; + else if (tv_usec < rhs.tv_usec) + return true; + else if (tv_usec > rhs.tv_usec) + return false; + return true; + } + + bool operator>(const UTIME & rhs) const + { + if (tv_sec > rhs.tv_sec) + return true; + else if (tv_sec < rhs.tv_sec) + return false; + else if (tv_usec > rhs.tv_usec) + return true; + return false; + } + + bool operator>=(const UTIME & rhs) const + { + if (tv_sec > rhs.tv_sec) + return true; + else if (tv_sec < rhs.tv_sec) + return false; + else if (tv_usec > rhs.tv_usec) + return true; + else if (tv_usec < rhs.tv_usec) + return false; + return true; + } + + bool operator==(const UTIME & rhs) const + { + return (tv_sec == rhs.tv_sec) && (tv_usec == rhs.tv_usec); + } + + UTIME operator+(const UTIME & rhs) + { + // TODO optimize + long long a, b; + a = tv_sec + rhs.tv_sec; + b = tv_usec + rhs.tv_usec; + if (b > 1000000) + { + ++a; + b -= 1000000; + } + return UTIME(a, b); + } + + UTIME operator-(const UTIME & rhs) + { + // TODO optimize + long long a, b; + a = tv_sec - rhs.tv_sec; + b = tv_usec - rhs.tv_usec; + if (a >= 0) + { + if (b >= 0) + { + return UTIME(a, b); + } + else + { + return UTIME(--a, b + 1000000); + } + } + else + { + if (b >= 0) + { + return UTIME(++a, 1000000 - b); + } + else + { + return UTIME(a, b); + } + } + } + + time_t GetSec() const + { + return tv_sec; + } + + suseconds_t GetUSec() const + { + return tv_usec; + } +}; + + +#endif //UTIME_H diff --git a/include/stg/version.h b/include/stg/version.h new file mode 100644 index 00000000..47cc941c --- /dev/null +++ b/include/stg/version.h @@ -0,0 +1,32 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontiv + */ + + /* + $Revision: 1.6 $ + $Date: 2010/11/08 10:13:18 $ + */ + +#ifndef __VERSION_H__ +#define __VERSION_H__ + +// Stargazer version +#define SERVER_VERSION "2.407-rc2" + +#endif diff --git a/include/stg_const.h b/include/stg_const.h deleted file mode 100644 index e882200d..00000000 --- a/include/stg_const.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Author: nobunaga $ - $Revision: 1.10 $ - $Date: 2008/01/11 17:33:50 $ - */ - - -#ifndef STG_CONST_H -#define STG_CONST_H - -#define DIR_NUM (10) -#define SYS_IFACE_LEN (9) -#define IFACE_LEN (255) -#define MAX_IP (5) -#define USERDATA_NUM (10) - -#define LOGIN_LEN (32) -#define PASSWD_LEN (32) -#define ADDR_LEN (255) -#define NOTE_LEN (255) -#define REALNM_LEN (255) -#define GROUP_LEN (255) -#define PHONE_LEN (255) -#define EMAIL_LEN (255) -#define USR_IFACE_LEN (255) -#define USER_DATA_LEN (255) -#define IP_STRING_LEN (255) - -#define ADM_LOGIN_LEN (32) -#define ADM_PASSWD_LEN (32) -#define TARIFF_NAME_LEN (32) -#define SERVER_NAME_LEN (255) - -#define DIR_NAME_LEN (16) - -#define MAX_MSG_LEN (235) -#define MAX_MSG_LEN_8 (1030) - -#define LOGCASH (1) -#define NOLOGCASH (0) - -#define USERNOCASH (0) -#define USERDISCONNECT (1) - -#define LOGEVENT_CONNECT (0) -#define LOGEVENT_DISCONNECT (1) -#define LOGEVENT_NEW_MONTH (2) -#define LOGEVENT_NO_CASH (3) -#define LOGEVENT_CONNECT_NO_CASH (4) -#define LOGEVENT_USER_DOWN (5) -#define LOGEVENT_DELETED (6) - -#define SET_TARIFF_NOW (0) -#define SET_TARIFF_DELAYED (1) -#define SET_TARIFF_RECALC (2) - -#define CASH_SET (0) -#define CASH_ADD (1) - -#define NO_TARIFF_NAME "*_NO_TARIFF_*" -#define NO_CORP_NAME "*_NO_CORP_*" - -#define mega (1024 * 1024) - -#define MONITOR_TIME_DELAY_SEC (60) - -#endif diff --git a/include/stg_message.h b/include/stg_message.h deleted file mode 100644 index 16fe566f..00000000 --- a/include/stg_message.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef STG_MESSAGES_H -#define STG_MESSAGES_H - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.3 $ - $Date: 2010/03/04 11:49:52 $ - */ - -#include -#include - -#include "os_int.h" - -//----------------------------------------------------------------------------- -struct STG_MSG_HDR -{ -STG_MSG_HDR() - : id(0), - ver(0), - type(0), - lastSendTime(0), - creationTime(0), - showTime(0), - repeat(0), - repeatPeriod(0) -{}; - -uint64_t id; -unsigned ver; -unsigned type; -unsigned lastSendTime; -unsigned creationTime; -unsigned showTime; -int repeat; -unsigned repeatPeriod; -}; -//----------------------------------------------------------------------------- -struct STG_MSG -{ -STG_MSG() {}; - -time_t GetNextSendTime() const -{ -return header.lastSendTime + header.repeat * 60; -}; - -STG_MSG_HDR header; -std::string text; -}; -//----------------------------------------------------------------------------- - -#endif diff --git a/include/store.h b/include/store.h deleted file mode 100644 index f33a0653..00000000 --- a/include/store.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.16 $ - $Date: 2010/01/19 11:09:48 $ - $Author: faust $ - */ - -#ifndef STORE_H -#define STORE_H - -#include -#include -#include - -#include "user_stat.h" -#include "user_conf.h" -#include "corp_conf.h" -#include "service_conf.h" -#include "admin_conf.h" -#include "tariff_conf.h" -#include "module_settings.h" -#include "stg_message.h" - -//----------------------------------------------------------------------------- -class STORE { -public: - virtual int GetUsersList(std::vector * usersList) const = 0; - virtual int AddUser(const std::string & login) const = 0; - virtual int DelUser(const std::string & login) const = 0; - virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const = 0; - virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const = 0; - virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const = 0; - virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const = 0; - - virtual int WriteUserChgLog(const std::string & login, - const std::string & admLogin, - uint32_t admIP, - const std::string & paramName, - const std::string & oldValue, - const std::string & newValue, - const std::string & message = "") const = 0; - - virtual int WriteUserConnect(const std::string & login, uint32_t ip) const = 0; - - virtual int WriteUserDisconnect(const std::string & login, - const DIR_TRAFF & up, - const DIR_TRAFF & down, - const DIR_TRAFF & sessionUp, - const DIR_TRAFF & sessionDown, - double cash, - double freeMb, - const std::string & reason) const = 0; - - virtual int WriteDetailedStat(const TRAFF_STAT & statTree, - time_t lastStat, - const std::string & login) const = 0; - - virtual int AddMessage(STG_MSG * msg, const std::string & login) const = 0; - virtual int EditMessage(const STG_MSG & msg, const std::string & login) const = 0; - virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const = 0; - virtual int DelMessage(uint64_t id, const std::string & login) const = 0; - virtual int GetMessageHdrs(vector * hdrsList, const std::string & login) const = 0; - - virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const = 0; - - virtual int GetAdminsList(std::vector * adminsList) const = 0; - virtual int SaveAdmin(const ADMIN_CONF & ac) const = 0; - virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const = 0; - virtual int AddAdmin(const std::string & login) const = 0; - virtual int DelAdmin(const std::string & login) const = 0; - - virtual int GetTariffsList(std::vector * tariffsList) const = 0; - virtual int AddTariff(const std::string & name) const = 0; - virtual int DelTariff(const std::string & name) const = 0; - virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const = 0; - virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const = 0; - - virtual int GetCorpsList(std::vector * corpsList) const = 0; - virtual int SaveCorp(const CORP_CONF & cc) const = 0; - virtual int RestoreCorp(CORP_CONF * cc, const std::string & name) const = 0; - virtual int AddCorp(const std::string & name) const = 0; - virtual int DelCorp(const std::string & name) const = 0; - - virtual int GetServicesList(std::vector * corpsList) const = 0; - virtual int SaveService(const SERVICE_CONF & sc) const = 0; - virtual int RestoreService(SERVICE_CONF * sc, const std::string & name) const = 0; - virtual int AddService(const std::string & name) const = 0; - virtual int DelService(const std::string & name) const = 0; - - virtual void SetSettings(const MODULE_SETTINGS & s) = 0; - virtual int ParseSettings() = 0; - virtual const std::string & GetStrError() const = 0; - virtual const std::string & GetVersion() const = 0; -}; -//----------------------------------------------------------------------------- - -#endif diff --git a/include/tariff.h b/include/tariff.h deleted file mode 100644 index b19ec476..00000000 --- a/include/tariff.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#ifndef TARIFF_H -#define TARIFF_H - -#include - -#include - -#include "os_int.h" -#include "tariff_conf.h" - -class TARIFF { -public: - virtual double GetPriceWithTraffType(uint64_t up, - uint64_t down, - int dir, - time_t t) const = 0; - virtual double GetFreeMb() const = 0; - virtual double GetPassiveCost() const = 0; - virtual double GetFee() const = 0; - virtual double GetFree() const = 0; - - virtual const std::string & GetName() const = 0; - virtual void SetName(const std::string & name) = 0; - - virtual int GetTraffType() const = 0; - virtual int64_t GetTraffByType(uint64_t up, uint64_t down) const = 0; - virtual int GetThreshold(int dir) const = 0; - virtual const TARIFF_DATA & GetTariffData() const = 0; - - virtual TARIFF & operator=(const TARIFF_DATA & td) = 0; - virtual TARIFF & operator=(const TARIFF & t) = 0; - virtual bool operator==(const TARIFF & rhs) const = 0; - virtual bool operator!=(const TARIFF & rhs) const = 0; -}; - -#endif diff --git a/include/tariff_conf.h b/include/tariff_conf.h deleted file mode 100644 index 30f19815..00000000 --- a/include/tariff_conf.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.9 $ - $Date: 2010/10/05 20:41:11 $ - $Author: faust $ - */ - -#ifndef TARIFF_CONF_H -#define TARIFF_CONF_H - -#include -#include - -#include "resetable.h" -#include "stg_const.h" - -//----------------------------------------------------------------------------- -enum -{ - TRAFF_UP = 0, - TRAFF_DOWN, - TRAFF_UP_DOWN, - TRAFF_MAX -}; -//----------------------------------------------------------------------------- -struct DIRPRICE_DATA -{ - DIRPRICE_DATA() - : hDay(0), - mDay(0), - hNight(0), - mNight(0), - priceDayA(0), - priceNightA(0), - priceDayB(0), - priceNightB(0), - threshold(0), - singlePrice(0), - noDiscount(0) - {} - int hDay; - int mDay; - int hNight; - int mNight; - double priceDayA; - double priceNightA; - double priceDayB; - double priceNightB; - int threshold; - int singlePrice; // Do not use day/night division - int noDiscount; // Do not use threshold -}; -//----------------------------------------------------------------------------- -struct DIRPRICE_DATA_RES -{ - DIRPRICE_DATA_RES & operator= (const DIRPRICE_DATA & dpd) - { - hDay = dpd.hDay; - mDay = dpd.mDay; - hNight = dpd.hNight; - mNight = dpd.mNight; - priceDayA = dpd.priceDayA; - priceNightA = dpd.priceNightA; - priceDayB = dpd.priceDayB; - priceNightB = dpd.priceNightB; - threshold = dpd.threshold; - singlePrice = dpd.singlePrice; - noDiscount = dpd.noDiscount; - return *this; - }; - - DIRPRICE_DATA GetData() - { - DIRPRICE_DATA dd; - dd.hDay = hDay; - dd.hNight = hNight; - dd.mDay = mDay; - dd.mNight = mNight; - dd.noDiscount = noDiscount; - dd.priceDayA = priceDayA; - dd.priceDayB = priceDayB; - - dd.priceNightA = priceNightA; - dd.priceNightB = priceNightB; - dd.singlePrice = singlePrice; - dd.threshold = threshold; - return dd; - } - - RESETABLE hDay; - RESETABLE mDay; - RESETABLE hNight; - RESETABLE mNight; - RESETABLE priceDayA; - RESETABLE priceNightA; - RESETABLE priceDayB; - RESETABLE priceNightB; - RESETABLE threshold; - RESETABLE singlePrice; - RESETABLE noDiscount; -}; -//----------------------------------------------------------------------------- -struct TARIFF_CONF -{ - double fee; // ÷ÅÌÉÞÉÎÁ ÁÂÏÎÐÌÁÔÙ - double free; // îÁ ËÁËÕÀ ÓÕÍÍÕ ÄÅÎÅÇ ÀÚÅÒ ËÁÞÁÅÔ ÂÅÓÐÌÁÔÎÏ - int traffType; // UP, DOWN, UP+DOWN, MAX - double passiveCost; // óÔÏÉÍÏÓÔØ ÚÁÍÏÒÏÚËÉ - std::string name; - - TARIFF_CONF() - : fee(0), - free(0), - traffType(TRAFF_UP_DOWN), // UP-DOWN - passiveCost(0), - name() - {}; - - TARIFF_CONF(const std::string & n) - : fee(0), - free(0), - traffType(TRAFF_UP_DOWN), // UP-DOWN - passiveCost(0), - name(n) - {}; -}; -//----------------------------------------------------------------------------- -struct TARIFF_CONF_RES -{ - TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc) - { - fee = tc.fee; - free = tc.free; - traffType = tc.traffType; - passiveCost = tc.passiveCost; - name = tc.name; - return *this; - }; - - TARIFF_CONF GetData() - { - TARIFF_CONF tc; - tc.fee = fee; - tc.free = free; - tc.name = name; - tc.passiveCost = passiveCost; - tc.traffType = traffType; - return tc; - } - - RESETABLE fee; - RESETABLE free; - RESETABLE traffType; - RESETABLE passiveCost; - RESETABLE name; -}; -//----------------------------------------------------------------------------- -struct TARIFF_DATA -{ - TARIFF_CONF tariffConf; - std::vector dirPrice; - - TARIFF_DATA() - : tariffConf(), - dirPrice(DIR_NUM) - {} - - TARIFF_DATA(const std::string & name) - : tariffConf(name), - dirPrice(DIR_NUM) - {} - - TARIFF_DATA(const TARIFF_DATA & td) - : tariffConf(td.tariffConf), - dirPrice(td.dirPrice) - {} - - TARIFF_DATA & operator=(const TARIFF_DATA & td) - { - tariffConf = td.tariffConf; - dirPrice = td.dirPrice; - return *this; - }; -}; -//----------------------------------------------------------------------------- -struct TARIFF_DATA_RES -{ - TARIFF_CONF_RES tariffConf; - std::vector dirPrice; - - TARIFF_DATA_RES() - : tariffConf(), - dirPrice(DIR_NUM) - {} - - TARIFF_DATA GetData() - { - TARIFF_DATA td; - td.tariffConf = tariffConf.GetData(); - for (int i = 0; i < DIR_NUM; i++) - td.dirPrice[i] = dirPrice[i].GetData(); - return td; - } -}; -//----------------------------------------------------------------------------- -#endif diff --git a/include/tariffs.h b/include/tariffs.h deleted file mode 100644 index 1f91948f..00000000 --- a/include/tariffs.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#ifndef TARIFFS_H -#define TARIFFS_H - -#include -#include - -class ADMIN; -class TARIFF; -class TARIFF_DATA; - -class TARIFFS { -public: - virtual int ReadTariffs () = 0; - virtual const TARIFF * FindByName(const std::string & name) const = 0; - virtual const TARIFF * GetNoTariff() const = 0; - virtual int GetTariffsNum() const = 0; - virtual int Del(const std::string & name, const ADMIN * admin) = 0; - virtual int Add(const std::string & name, const ADMIN * admin) = 0; - virtual int Chg(const TARIFF_DATA & td, const ADMIN * admin) = 0; - - virtual void GetTariffsData(std::list * tdl) = 0; - - virtual const std::string & GetStrError() const = 0; -}; - -#endif diff --git a/include/traffcounter.h b/include/traffcounter.h deleted file mode 100644 index 1962ee7a..00000000 --- a/include/traffcounter.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : maxim Mamontov - */ - -#ifndef TRAFFCOUNTER_H -#define TRAFFCOUNTER_H - -#include "raw_ip_packet.h" - -class TRAFFCOUNTER { -public: - virtual void Process(const RAW_PACKET & rawPacket) = 0; -}; - -#endif diff --git a/include/user.h b/include/user.h deleted file mode 100644 index adf140de..00000000 --- a/include/user.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#ifndef USER_H -#define USER_H - -#include -#include - -#include "os_int.h" -#include "notifer.h" -#include "stg_message.h" -#include "tariff.h" -#include "user_traff.h" - -class USER_PROPERTIES; -class AUTH; - -class USER { -public: - virtual int WriteConf() = 0; - virtual int WriteStat() = 0; - - virtual const std::string & GetLogin() const = 0; - - virtual uint32_t GetCurrIP() const = 0; - virtual time_t GetCurrIPModificationTime() const = 0; - - virtual void AddCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - virtual void DelCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - - virtual void AddCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - virtual void DelCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - - virtual void AddConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - virtual void DelConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - - virtual void AddConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - virtual void DelConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - - virtual int GetID() const = 0; - - virtual double GetPassiveTimePart() const = 0; - - virtual const TARIFF * GetTariff() const = 0; - virtual void ResetNextTariff() = 0; - - #ifdef TRAFF_STAT_WITH_PORTS - virtual void AddTraffStatU(int dir, uint32_t ip, uint16_t port, uint32_t len) = 0; - virtual void AddTraffStatD(int dir, uint32_t ip, uint16_t port, uint32_t len) = 0; - #else - virtual void AddTraffStatU(int dir, uint32_t ip, uint32_t len) = 0; - virtual void AddTraffStatD(int dir, uint32_t ip, uint32_t len) = 0; - #endif - - virtual const DIR_TRAFF & GetSessionUpload() const = 0; - virtual const DIR_TRAFF & GetSessionDownload() const = 0; - - virtual bool GetConnected() const = 0; - virtual time_t GetConnectedModificationTime() const = 0; - virtual int GetAuthorized() const = 0; - virtual int Authorize(uint32_t ip, - uint32_t enabledDirs, - const AUTH * auth) = 0; - virtual void Unauthorize(const AUTH * auth) = 0; - virtual bool IsAuthorizedBy(const AUTH * auth) const = 0; - - virtual int AddMessage(STG_MSG * msg) = 0; - - virtual void UpdatePingTime(time_t t = 0) = 0; - virtual time_t GetPingTime() const = 0; - - virtual void Run() = 0; - - virtual const std::string & GetStrError() const = 0; - - virtual USER_PROPERTIES & GetProperty() = 0; - virtual const USER_PROPERTIES & GetProperty() const = 0; - - virtual bool GetDeleted() const = 0; - virtual void SetDeleted() = 0; - - virtual time_t GetLastWriteStatTime() const = 0; - - virtual bool IsInetable() = 0; - virtual std::string GetEnabledDirs() = 0; - - virtual void OnAdd() = 0; - virtual void OnDelete() = 0; -}; - -typedef USER * USER_PTR; - -#endif diff --git a/include/user_conf.h b/include/user_conf.h deleted file mode 100644 index 9a6efb23..00000000 --- a/include/user_conf.h +++ /dev/null @@ -1,158 +0,0 @@ - /* - $Revision: 1.12 $ - $Date: 2010/03/11 14:42:05 $ - $Author: faust $ - */ - -#ifndef USER_CONF_H -#define USER_CONF_H - -#include -#include -#include "stg_const.h" -#include "user_ips.h" -#include "resetable.h" -#include "os_int.h" - -//----------------------------------------------------------------------------- -struct USER_CONF -{ - USER_CONF() - : password(), - passive(0), - disabled(0), - disabledDetailStat(0), - alwaysOnline(0), - tariffName(), - address(), - phone(), - email(), - note(), - realName(), - corp(), - service(), - group(), - credit(0), - nextTariff(), - userdata(USERDATA_NUM), - creditExpire(0), - ips() - {}; - - std::string password; - int passive; - int disabled; - int disabledDetailStat; - int alwaysOnline; - std::string tariffName; - std::string address; - std::string phone; - std::string email; - std::string note; - std::string realName; - std::string corp; - std::vector service; - std::string group; - double credit; - std::string nextTariff; - std::vector userdata; - time_t creditExpire; - USER_IPS ips; -}; -//----------------------------------------------------------------------------- -struct USER_CONF_RES -{ - USER_CONF_RES() - : password(), - passive(), - disabled(), - disabledDetailStat(), - alwaysOnline(), - tariffName(), - address(), - phone(), - email(), - note(), - realName(), - group(), - credit(), - nextTariff(), - userdata(USERDATA_NUM, RESETABLE()), - creditExpire(), - ips() - { - }; - - USER_CONF_RES & operator=(const USER_CONF & uc) - { - userdata.resize(USERDATA_NUM); - password = uc.password; - passive = uc.passive; - disabled = uc.disabled; - disabledDetailStat = uc.disabledDetailStat; - alwaysOnline = uc.alwaysOnline; - tariffName = uc.tariffName; - address = uc.address; - phone = uc.phone; - email = uc.email; - note = uc.note; - realName = uc.realName; - group = uc.group; - credit = uc.credit; - nextTariff = uc.nextTariff; - for (int i = 0; i < USERDATA_NUM; i++) - { - userdata[i] = uc.userdata[i]; - } - creditExpire = uc.creditExpire; - ips = uc.ips; - return *this; - }; - operator USER_CONF() const - { - USER_CONF uc; - uc.password = password; - uc.passive = passive; - uc.disabled = disabled; - uc.disabledDetailStat = disabledDetailStat; - uc.alwaysOnline = alwaysOnline; - uc.tariffName = tariffName; - uc.address = address; - uc.phone = phone; - uc.email = email; - uc.note = note; - uc.realName = realName; - uc.group = group; - uc.credit = credit; - uc.nextTariff = nextTariff; - for (int i = 0; i < USERDATA_NUM; i++) - { - uc.userdata[i] = userdata[i]; - } - uc.creditExpire = creditExpire; - uc.ips = ips; - return uc; - } - //------------------------------------------------------------------------- - - RESETABLE password; - RESETABLE passive; - RESETABLE disabled; - RESETABLE disabledDetailStat; - RESETABLE alwaysOnline; - RESETABLE tariffName; - RESETABLE address; - RESETABLE phone; - RESETABLE email; - RESETABLE note; - RESETABLE realName; - RESETABLE group; - RESETABLE credit; - RESETABLE nextTariff; - std::vector > userdata; - RESETABLE creditExpire; - RESETABLE ips; -}; -//----------------------------------------------------------------------------- -#endif - diff --git a/include/user_ips.h b/include/user_ips.h deleted file mode 100644 index 250520b2..00000000 --- a/include/user_ips.h +++ /dev/null @@ -1,280 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.22 $ - $Date: 2010/03/04 11:49:53 $ - $Author: faust $ - */ - -#ifndef USER_IPS_H -#define USER_IPS_H - -#ifdef FREE_BSD -#include -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "common.h" -#include "os_int.h" - -using namespace std; - -//------------------------------------------------------------------------- -struct IP_MASK -{ -IP_MASK() : ip(0), mask(0) {} -IP_MASK(const IP_MASK & ipm) : ip(ipm.ip), mask(ipm.mask) {} -uint32_t ip; -uint32_t mask; -}; -//------------------------------------------------------------------------- -class USER_IPS -{ - friend std::ostream & operator<< (ostream & o, const USER_IPS & i); - //friend stringstream & operator<< (stringstream & s, const USER_IPS & i); - friend const USER_IPS StrToIPS(const string & ipsStr) throw(string); - -public: - USER_IPS(); - USER_IPS(const USER_IPS &); - USER_IPS & operator=(const USER_IPS &); - const IP_MASK & operator[](int idx) const; - std::string GetIpStr() const; - bool IsIPInIPS(uint32_t ip) const; - bool OnlyOneIP() const; - int Count() const; - void Add(const IP_MASK &im); - void Erase(); - -private: - uint32_t CalcMask(unsigned int msk) const; - std::vector ips; -}; -//------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -inline -USER_IPS::USER_IPS() - : ips() -{} -//----------------------------------------------------------------------------- -inline -USER_IPS::USER_IPS(const USER_IPS & i) - : ips(i.ips) -{} -//----------------------------------------------------------------------------- -inline -USER_IPS & USER_IPS::operator=(const USER_IPS & i) -{ -ips = i.ips; -return *this; -} -//----------------------------------------------------------------------------- -inline -const IP_MASK & USER_IPS::operator[](int idx) const -{ -return ips[idx]; -} -//----------------------------------------------------------------------------- -inline -std::string USER_IPS::GetIpStr() const -{ -if (ips.empty()) - { - return ""; - } - -if (ips[0].ip == 0) - { - return "*"; - } - -std::vector::const_iterator it(ips.begin()); -std::stringstream s; -s << inet_ntostring(it->ip); -++it; -for (; it != ips.end(); ++it) - { - s << "," << inet_ntostring(it->ip); - } -return s.str(); -} -//----------------------------------------------------------------------------- -inline -int USER_IPS::Count() const -{ -return ips.size(); -} -//----------------------------------------------------------------------------- -inline -bool USER_IPS::IsIPInIPS(uint32_t ip) const -{ -if (ips.empty()) - { - return false; - } - -if (ips.front().ip == 0) - return true; - -for (std::vector::const_iterator it(ips.begin()); it != ips.end(); ++it) - { - uint32_t mask(CalcMask(it->mask)); - if ((ip & mask) == (it->ip & mask)) - return true; - } -return false; -} -//----------------------------------------------------------------------------- -inline -bool USER_IPS::OnlyOneIP() const -{ -if (ips.size() == 1 && ips.front().mask == 32) - return true; - -return false; -} -//----------------------------------------------------------------------------- -inline -uint32_t USER_IPS::CalcMask(unsigned int msk) const -{ -if (msk > 32) - return 0; -return htonl(0xFFffFFff << (32 - msk)); -} -//----------------------------------------------------------------------------- -inline -void USER_IPS::Add(const IP_MASK &im) -{ -ips.push_back(im); -} -//----------------------------------------------------------------------------- -inline -void USER_IPS::Erase() -{ -ips.erase(ips.begin(), ips.end()); -} -//----------------------------------------------------------------------------- -inline -std::ostream & operator<<(std::ostream & o, const USER_IPS & i) -{ -return o << i.GetIpStr(); -} -//----------------------------------------------------------------------------- -/*inline -stringstream & operator<<(std::stringstream & s, const USER_IPS & i) -{ -s << i.GetIpStr(); -return s; -}*/ -//----------------------------------------------------------------------------- -inline -const USER_IPS StrToIPS(const std::string & ipsStr) throw(std::string) -{ -USER_IPS ips; -char * paddr; -IP_MASK im; -std::vector ipMask; -std::string err; -if (ipsStr.empty()) - { - return ips; - } - -if (ipsStr[0] == '*' && ipsStr.size() == 1) - { - im.ip = 0; - im.mask = 0; - ips.ips.push_back(im); - return ips; - } - -char * str = new char[ipsStr.size() + 1]; -strcpy(str, ipsStr.c_str()); -char * pstr = str; -while ((paddr = strtok(pstr, ","))) - { - pstr = NULL; - ipMask.push_back(paddr); - } - -delete[] str; - -for (unsigned int i = 0; i < ipMask.size(); i++) - { - char str[128]; - char * strIp; - char * strMask; - strcpy(str, ipMask[i].c_str()); - strIp = strtok(str, "/"); - if (strIp == NULL) - { - err = "Incorrect IP address " + ipsStr; - return ips; - } - strMask = strtok(NULL, "/"); - - im.ip = inet_addr(strIp); - if (im.ip == INADDR_NONE) - { - err = "Incorrect IP address: " + std::string(strIp); - return ips; - } - - im.mask = 32; - if (strMask != NULL) - { - int m = 0; - if (str2x(strMask, m) != 0) - { - err = "Incorrect mask: " + std::string(strMask); - return ips; - } - im.mask = m; - - if (im.mask > 32) - { - err = "Incorrect mask: " + std::string(strMask); - return ips; - } - - if ((im.ip & ips.CalcMask(im.mask)) != im.ip) - { - err = "Address does'n match mask: " + std::string(strIp) + "/" + std::string(strMask); - return ips; - } - } - ips.ips.push_back(im); - } - -return ips; -} -//------------------------------------------------------------------------- -#endif //USER_IPS_H diff --git a/include/user_property.h b/include/user_property.h deleted file mode 100644 index 78e5675a..00000000 --- a/include/user_property.h +++ /dev/null @@ -1,384 +0,0 @@ -/* -$Revision: 1.44 $ -$Date: 2010/09/13 05:54:43 $ -$Author: faust $ -*/ - -#ifndef USER_PROPERTY_H -#define USER_PROPERTY_H - -#include // access - -#include -#include -#include -#include -#include - -#include "store.h" -#include "admin.h" -#include "notifer.h" -#include "stg_logger.h" -#include "stg_locker.h" -#include "script_executer.h" -#include "noncopyable.h" - -extern const volatile time_t stgTime; - -//----------------------------------------------------------------------------- -template -class USER_PROPERTY { -public: - USER_PROPERTY(varT & val); - virtual ~USER_PROPERTY(); - - void Set(const varT & rvalue); - - USER_PROPERTY & operator= (const varT & rvalue); - - const varT * operator&() const throw() { return &value; } - const varT & ConstData() const throw() { return value; } - - operator const varT&() const throw() { return value; } - - void AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); - void DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); - - void AddAfterNotifier(PROPERTY_NOTIFIER_BASE * n); - void DelAfterNotifier(PROPERTY_NOTIFIER_BASE * n); - - time_t ModificationTime() const throw() { return modificationTime; } - void ModifyTime() throw(); - -private: - varT & value; - time_t modificationTime; - std::set *> beforeNotifiers; - std::set *> afterNotifiers; - pthread_mutex_t mutex; -}; -//----------------------------------------------------------------------------- -template -class USER_PROPERTY_LOGGED: public USER_PROPERTY { -public: - USER_PROPERTY_LOGGED(varT & val, - const std::string & n, - bool isPassword, - bool isStat, - STG_LOGGER & logger, - const std::string & sd); - virtual ~USER_PROPERTY_LOGGED() {} - - USER_PROPERTY_LOGGED * GetPointer() throw() { return this; } - const varT & Get() const { return USER_PROPERTY::ConstData(); } - const std::string & GetName() const { return name; } - bool Set(const varT & val, - const ADMIN * admin, - const std::string & login, - const STORE * store, - const std::string & msg = ""); -private: - void WriteAccessDenied(const std::string & login, - const ADMIN * admin, - const std::string & parameter); - - void WriteSuccessChange(const std::string & login, - const ADMIN * admin, - const std::string & parameter, - const std::string & oldValue, - const std::string & newValue, - const std::string & msg, - const STORE * store); - - void OnChange(const std::string & login, - const std::string & paramName, - const std::string & oldValue, - const std::string & newValue, - const ADMIN * admin); - - STG_LOGGER & stgLogger; - bool isPassword; - bool isStat; - std::string name; - const std::string scriptsDir; -}; -//----------------------------------------------------------------------------- -class USER_PROPERTIES : private NONCOPYABLE { -/* - В этом месте важен порядок следования приватной и открытой частей. - Это связано с тем, что часть которая находится в публичной секции - по сути является завуалированной ссылкой на закрытую часть. Т.о. нам нужно - чтобы конструкторы из закрытой части вызвались раньше открытой. Поэтомому в - начале идет закрытая секция - * */ - -private: - USER_STAT stat; - USER_CONF conf; - -public: - USER_PROPERTIES(const std::string & sd); - - USER_STAT & Stat() { return stat; } - USER_CONF & Conf() { return conf; } - const USER_STAT & GetStat() const { return stat; } - const USER_CONF & GetConf() const { return conf; } - void SetStat(const USER_STAT & s) { stat = s; } - void SetConf(const USER_CONF & c) { conf = c; } - - void SetProperties(const USER_PROPERTIES & p) { stat = p.stat; conf = p.conf; } - - USER_PROPERTY_LOGGED cash; - USER_PROPERTY_LOGGED up; - USER_PROPERTY_LOGGED down; - USER_PROPERTY_LOGGED lastCashAdd; - USER_PROPERTY_LOGGED passiveTime; - USER_PROPERTY_LOGGED lastCashAddTime; - USER_PROPERTY_LOGGED freeMb; - USER_PROPERTY_LOGGED lastActivityTime; - - USER_PROPERTY_LOGGED password; - USER_PROPERTY_LOGGED passive; - USER_PROPERTY_LOGGED disabled; - USER_PROPERTY_LOGGED disabledDetailStat; - USER_PROPERTY_LOGGED alwaysOnline; - USER_PROPERTY_LOGGED tariffName; - USER_PROPERTY_LOGGED nextTariff; - USER_PROPERTY_LOGGED address; - USER_PROPERTY_LOGGED note; - USER_PROPERTY_LOGGED group; - USER_PROPERTY_LOGGED email; - USER_PROPERTY_LOGGED phone; - USER_PROPERTY_LOGGED realName; - USER_PROPERTY_LOGGED credit; - USER_PROPERTY_LOGGED creditExpire; - USER_PROPERTY_LOGGED ips; - USER_PROPERTY_LOGGED userdata0; - USER_PROPERTY_LOGGED userdata1; - USER_PROPERTY_LOGGED userdata2; - USER_PROPERTY_LOGGED userdata3; - USER_PROPERTY_LOGGED userdata4; - USER_PROPERTY_LOGGED userdata5; - USER_PROPERTY_LOGGED userdata6; - USER_PROPERTY_LOGGED userdata7; - USER_PROPERTY_LOGGED userdata8; - USER_PROPERTY_LOGGED userdata9; -}; -//============================================================================= - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -template -inline -USER_PROPERTY::USER_PROPERTY(varT & val) - : value(val), - modificationTime(stgTime) -{ -pthread_mutex_init(&mutex, NULL); -} -//----------------------------------------------------------------------------- -template -inline -USER_PROPERTY::~USER_PROPERTY() -{ -pthread_mutex_destroy(&mutex); -} -//----------------------------------------------------------------------------- -template -inline -void USER_PROPERTY::ModifyTime() throw() -{ -modificationTime = stgTime; -} -//----------------------------------------------------------------------------- -template -inline -void USER_PROPERTY::Set(const varT & rvalue) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); - -typename std::set *>::iterator ni; - -varT oldVal = value; - -ni = beforeNotifiers.begin(); -while (ni != beforeNotifiers.end()) - (*ni++)->Notify(oldVal, rvalue); - -value = rvalue; -modificationTime = stgTime; - -ni = afterNotifiers.begin(); -while (ni != afterNotifiers.end()) - (*ni++)->Notify(oldVal, rvalue); -} -//----------------------------------------------------------------------------- -template -inline -USER_PROPERTY & USER_PROPERTY::operator= (const varT & newValue) -{ -Set(newValue); -return *this; -} -//----------------------------------------------------------------------------- -template -inline -void USER_PROPERTY::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -beforeNotifiers.insert(n); -} -//----------------------------------------------------------------------------- -template -inline -void USER_PROPERTY::DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -beforeNotifiers.erase(n); -} -//----------------------------------------------------------------------------- -template -inline -void USER_PROPERTY::AddAfterNotifier(PROPERTY_NOTIFIER_BASE * n) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -afterNotifiers.insert(n); -} -//----------------------------------------------------------------------------- -template -inline -void USER_PROPERTY::DelAfterNotifier(PROPERTY_NOTIFIER_BASE * n) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -afterNotifiers.erase(n); -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -template -inline -USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, - const std::string & n, - bool isPass, - bool isSt, - STG_LOGGER & logger, - const std::string & sd) - - : USER_PROPERTY(val), - stgLogger(logger), - isPassword(isPass), - isStat(isSt), - name(n), - scriptsDir(sd) -{ -} -//------------------------------------------------------------------------- -template -bool USER_PROPERTY_LOGGED::Set(const varT & val, - const ADMIN * admin, - const std::string & login, - const STORE * store, - const std::string & msg) -{ -const PRIV * priv = admin->GetPriv(); -std::string adm_login = admin->GetLogin(); -std::string adm_ip = admin->GetIPStr(); - -if ((priv->userConf && !isStat) || - (priv->userStat && isStat) || - (priv->userPasswd && isPassword) || - (priv->userCash && name == "cash")) - { - std::stringstream oldVal; - std::stringstream newVal; - - oldVal.flags(oldVal.flags() | ios::fixed); - newVal.flags(newVal.flags() | ios::fixed); - - oldVal << USER_PROPERTY::ConstData(); - newVal << val; - - OnChange(login, name, oldVal.str(), newVal.str(), admin); - - if (isPassword) - { - WriteSuccessChange(login, admin, name, "******", "******", msg, store); - } - else - { - WriteSuccessChange(login, admin, name, oldVal.str(), newVal.str(), msg, store); - } - USER_PROPERTY::Set(val); - return true; - } -else - { - WriteAccessDenied(login, admin, name); - return false; - } -return true; -} -//------------------------------------------------------------------------- -template -inline -void USER_PROPERTY_LOGGED::WriteAccessDenied(const std::string & login, - const ADMIN * admin, - const std::string & parameter) -{ -stgLogger("%s Change user \'%s.\' Parameter \'%s\'. Access denied.", - admin->GetLogStr().c_str(), login.c_str(), parameter.c_str()); -} -//------------------------------------------------------------------------- -template -inline -void USER_PROPERTY_LOGGED::WriteSuccessChange(const std::string & login, - const ADMIN * admin, - const std::string & parameter, - const std::string & oldValue, - const std::string & newValue, - const std::string & msg, - const STORE * store) -{ -stgLogger("%s User \'%s\': \'%s\' parameter changed from \'%s\' to \'%s\'. %s", - admin->GetLogStr().c_str(), - login.c_str(), - parameter.c_str(), - oldValue.c_str(), - newValue.c_str(), - msg.c_str()); - -store->WriteUserChgLog(login, admin->GetLogin(), admin->GetIP(), parameter, oldValue, newValue, msg); -} -//------------------------------------------------------------------------- -template -void USER_PROPERTY_LOGGED::OnChange(const std::string & login, - const std::string & paramName, - const std::string & oldValue, - const std::string & newValue, - const ADMIN * admin) -{ -std::string filePath = scriptsDir + "/OnChange"; - -if (access(filePath.c_str(), X_OK) == 0) - { - std::string execString("\"" + filePath + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin->GetLogin() + "\" \"" + admin->GetIPStr() + "\""); - ScriptExec(execString); - } -else - { - stgLogger("Script OnChange cannot be executed. File %s not found.", filePath.c_str()); - } -} -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- -template -inline -ostream & operator<< (ostream & stream, const USER_PROPERTY & value) -{ -return stream << value.ConstData(); -} -//----------------------------------------------------------------------------- - -#endif // USER_PROPERTY_H diff --git a/include/user_stat.h b/include/user_stat.h deleted file mode 100644 index 42d436fd..00000000 --- a/include/user_stat.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.15 $ - $Date: 2010/03/11 14:42:05 $ - $Author: faust $ - */ - -#ifndef USER_STAT_H -#define USER_STAT_H - -#include -#include - -#include "os_int.h" -#include "resetable.h" -#include "user_traff.h" -//----------------------------------------------------------------------------- -struct IP_DIR_PAIR -{ - #ifdef TRAFF_STAT_WITH_PORTS - IP_DIR_PAIR(uint32_t _ip, - int _dir, - uint16_t _port) - : ip(_ip), - dir(_dir), - port(_port) - {} - #else - IP_DIR_PAIR(uint32_t _ip, - int _dir) - : ip(_ip), - dir(_dir) - {} - #endif - //------------------------ - bool operator<(const IP_DIR_PAIR & idp) const - { - if (ip < idp.ip) - return true; - - if (ip > idp.ip) - return false; - - #ifdef TRAFF_STAT_WITH_PORTS - if (port < idp.port) - return true; - - if (port > idp.port) - return false; - #endif - - if (dir < idp.dir) - return true; - - return false; - } - //------------------------ - bool operator!=(const IP_DIR_PAIR & rvalue) const - { - if (ip != rvalue.ip) - return true; - - #ifdef TRAFF_STAT_WITH_PORTS - if (port != rvalue.port) - return true; - #endif - - if (dir != rvalue.dir) - return true; - - return false; - } - //------------------------ - uint32_t ip; - int dir; - #ifdef TRAFF_STAT_WITH_PORTS - uint16_t port; - #endif -}; -//----------------------------------------------------------------------------- -struct STAT_NODE -{ - STAT_NODE(uint64_t _up, - uint64_t _down, - double _cash) - : up(_up), - down(_down), - cash(_cash) - {} - uint64_t up; - uint64_t down; - double cash; -}; -//----------------------------------------------------------------------------- -struct USER_STAT -{ - //USER_STAT & operator= (const USER_STAT_RES & usr); - USER_STAT() - : up(), - down(), - cash(0), - freeMb(0), - lastCashAdd(0), - lastCashAddTime(0), - passiveTime(0), - lastActivityTime(0) - {}; - - DIR_TRAFF up; - DIR_TRAFF down; - double cash; - double freeMb; - double lastCashAdd; - time_t lastCashAddTime; - time_t passiveTime; - time_t lastActivityTime; -}; -//----------------------------------------------------------------------------- -typedef std::map TRAFF_STAT; -//----------------------------------------------------------------------------- -struct USER_STAT_RES -{ - USER_STAT_RES() - : cash(), - freeMb(), - lastCashAdd(), - lastCashAddTime(), - passiveTime(), - lastActivityTime(), - up(), - down() - {} - - USER_STAT_RES & operator= (const USER_STAT & us) - { - cash = us.cash; - freeMb = us.freeMb; - lastCashAdd = us.lastCashAdd; - lastCashAddTime = us.lastCashAddTime; - passiveTime = us.passiveTime; - lastActivityTime = us.lastActivityTime; - up = us.up; - down = us.down; - return * this; - }; - operator USER_STAT() const - { - USER_STAT us; - us.cash = cash; - us.freeMb = freeMb; - us.lastCashAdd = lastCashAdd; - us.lastCashAddTime = lastCashAddTime; - us.passiveTime = passiveTime; - us.lastActivityTime = lastActivityTime; - us.up = up; - us.down = down; - return us; - }; - - RESETABLE cash; - RESETABLE freeMb; - RESETABLE lastCashAdd; - RESETABLE lastCashAddTime; - RESETABLE passiveTime; - RESETABLE lastActivityTime; - RESETABLE up; - RESETABLE down; -}; -//----------------------------------------------------------------------------- -#endif diff --git a/include/user_traff.h b/include/user_traff.h deleted file mode 100644 index fdefee0f..00000000 --- a/include/user_traff.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - -/* - $Revision: 1.7 $ - $Date: 2010/10/07 19:48:52 $ - $Author: faust $ - */ - -#ifndef USER_TRAFF_H -#define USER_TRAFF_H - -#include -#include - -#include "stg_const.h" -#include "os_int.h" - -enum TRAFF_DIRECTION {TRAFF_UPLOAD, TRAFF_DOWNLOAD}; - -class DIR_TRAFF -{ - friend std::ostream & operator<< (std::ostream & o, const DIR_TRAFF & traff); - -public: - //------------------------------------------------------------------------- - DIR_TRAFF(); - DIR_TRAFF(const DIR_TRAFF & ts); - DIR_TRAFF & operator=(const DIR_TRAFF & ts); - ~DIR_TRAFF(); - uint64_t operator[](int idx) const; - uint64_t & operator[](int idx); - DIR_TRAFF operator+(const DIR_TRAFF & ts); - -private: - std::vector traff; -}; -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -inline DIR_TRAFF::DIR_TRAFF() - : traff(DIR_NUM, 0) -{ -} -//----------------------------------------------------------------------------- -inline DIR_TRAFF::DIR_TRAFF(const DIR_TRAFF & ts) - : traff(ts.traff) -{ -} -//----------------------------------------------------------------------------- -inline DIR_TRAFF::~DIR_TRAFF() -{ -} -//----------------------------------------------------------------------------- -inline DIR_TRAFF & DIR_TRAFF::operator=(const DIR_TRAFF & ts) -{ -traff = ts.traff; -return *this; -}; -//----------------------------------------------------------------------------- -inline uint64_t & DIR_TRAFF::operator[](int idx) -{ -return traff[idx]; -}; -//----------------------------------------------------------------------------- -inline uint64_t DIR_TRAFF::operator[](int idx) const -{ -return traff[idx]; -}; -//----------------------------------------------------------------------------- -inline DIR_TRAFF DIR_TRAFF::operator+(const DIR_TRAFF & ts) -{ -for (int i = 0; i < DIR_NUM; i++) - { - traff[i] = traff[i] + ts.traff[i]; - } -return *this; -}; -//----------------------------------------------------------------------------- -inline std::ostream & operator<<(std::ostream & o, const DIR_TRAFF & traff) -{ -bool first = true; -for (size_t i = 0; i < DIR_NUM; ++i) - { - if (first) - first = false; - else - o << ","; - o << traff[i]; - } -return o; -} -//----------------------------------------------------------------------------- -#endif diff --git a/include/users.h b/include/users.h deleted file mode 100644 index 50f5ffe2..00000000 --- a/include/users.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#ifndef USERS_H -#define USERS_H - -#include - -#include "notifer.h" -#include "user.h" - -class ADMIN; - -class USERS { -public: - virtual int FindByName(const std::string & login, USER_PTR * user) = 0; - - virtual bool TariffInUse(const std::string & tariffName) const = 0; - - virtual void AddNotifierUserAdd(NOTIFIER_BASE * notifier) = 0; - virtual void DelNotifierUserAdd(NOTIFIER_BASE * notifier) = 0; - - virtual void AddNotifierUserDel(NOTIFIER_BASE * notifier) = 0; - virtual void DelNotifierUserDel(NOTIFIER_BASE * notifier) = 0; - - virtual int Add(const std::string & login, const ADMIN * admin) = 0; - virtual void Del(const std::string & login, const ADMIN * admin) = 0; - - virtual int ReadUsers() = 0; - virtual int GetUserNum() const = 0; - - virtual int FindByIPIdx(uint32_t ip, USER_PTR * user) const = 0; - virtual bool IsIPInIndex(uint32_t ip) const = 0; - - virtual int OpenSearch() = 0; - virtual int SearchNext(int handle, USER_PTR * u) = 0; - virtual int CloseSearch(int handle) = 0; - - virtual int Start() = 0; - virtual int Stop() = 0; -}; - -#endif diff --git a/include/utime.h b/include/utime.h deleted file mode 100644 index 20da4e43..00000000 --- a/include/utime.h +++ /dev/null @@ -1,170 +0,0 @@ -#ifndef UTIME_H -#define UTIME_H - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Date: 22.12.2007 - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.6 $ - $Date: 2009/08/05 11:40:30 $ - $Author: faust $ - */ - -#include -#include - -#ifdef FREE_BSD -typedef long suseconds_t; -#endif - -struct UTIME: public timeval -{ - UTIME() - { - tv_sec = 0; - tv_usec = 0; - } - - UTIME(time_t t) - { - tv_sec = t; - tv_usec = 0; - } - - UTIME(long long a, long long b) - { - tv_sec = a; - tv_usec = b; - } - - bool operator<(const UTIME & rhs) const - { - if (tv_sec < rhs.tv_sec) - return true; - else if (tv_sec > rhs.tv_sec) - return false; - else if (tv_usec < rhs.tv_usec) - return true; - return false; - } - - bool operator<=(const UTIME & rhs) const - { - if (tv_sec < rhs.tv_sec) - return true; - else if (tv_sec > rhs.tv_sec) - return false; - else if (tv_usec < rhs.tv_usec) - return true; - else if (tv_usec > rhs.tv_usec) - return false; - return true; - } - - bool operator>(const UTIME & rhs) const - { - if (tv_sec > rhs.tv_sec) - return true; - else if (tv_sec < rhs.tv_sec) - return false; - else if (tv_usec > rhs.tv_usec) - return true; - return false; - } - - bool operator>=(const UTIME & rhs) const - { - if (tv_sec > rhs.tv_sec) - return true; - else if (tv_sec < rhs.tv_sec) - return false; - else if (tv_usec > rhs.tv_usec) - return true; - else if (tv_usec < rhs.tv_usec) - return false; - return true; - } - - bool operator==(const UTIME & rhs) const - { - return (tv_sec == rhs.tv_sec) && (tv_usec == rhs.tv_usec); - } - - UTIME operator+(const UTIME & rhs) - { - // TODO optimize - long long a, b; - a = tv_sec + rhs.tv_sec; - b = tv_usec + rhs.tv_usec; - if (b > 1000000) - { - ++a; - b -= 1000000; - } - return UTIME(a, b); - } - - UTIME operator-(const UTIME & rhs) - { - // TODO optimize - long long a, b; - a = tv_sec - rhs.tv_sec; - b = tv_usec - rhs.tv_usec; - if (a >= 0) - { - if (b >= 0) - { - return UTIME(a, b); - } - else - { - return UTIME(--a, b + 1000000); - } - } - else - { - if (b >= 0) - { - return UTIME(++a, 1000000 - b); - } - else - { - return UTIME(a, b); - } - } - } - - time_t GetSec() const - { - return tv_sec; - } - - suseconds_t GetUSec() const - { - return tv_usec; - } -}; - - -#endif //UTIME_H diff --git a/include/version.h b/include/version.h deleted file mode 100644 index 47cc941c..00000000 --- a/include/version.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontiv - */ - - /* - $Revision: 1.6 $ - $Date: 2010/11/08 10:13:18 $ - */ - -#ifndef __VERSION_H__ -#define __VERSION_H__ - -// Stargazer version -#define SERVER_VERSION "2.407-rc2" - -#endif