+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
-#ifndef ADMIN_H
-#define ADMIN_H
-
-#include <string>
-
-#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
+++ /dev/null
- /*
- $Revision: 1.9 $
- $Date: 2010/09/10 05:02:08 $
- $Author: faust $
- */
-
-#ifndef ADMIN_CONF_H
-#define ADMIN_CONF_H
-
-#include <string>
-
-#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
-
-
+++ /dev/null
- /*
- $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
+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
-#ifndef ADMINS_H
-#define ADMINS_H
-
-#include <string>
-
-#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
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
- /*
- $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
+++ /dev/null
-#ifndef __BASE_DB_H__
-#define __BASE_DB_H__
-
-#include <string>
-#include <vector>
-#include <map>
-
-class BASE_DB {
-public:
-
- typedef std::map<std::string, std::string> TUPLE;
- typedef std::vector<TUPLE> TUPLES;
- typedef std::vector<std::string> 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
+++ /dev/null
-#ifndef CORP_CONF_H
-#define CORP_CONF_H
-
-struct CORP_CONF
-{
-string name;
-double cash;
-};
-
-#endif //CORP_CONF_H
+++ /dev/null
-#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
-
-
+++ /dev/null
-/*\r
- *****************************************************************************\r
- *\r
- * File: mimetype.h\r
- *\r
- * Description: TODO:\r
- *\r
- * $Id: mimetype.h,v 1.1.1.1 2005/10/09 11:00:45 nobunaga Exp $\r
- *\r
- *****************************************************************************\r
- */\r
-\r
-#ifndef _MIMETYPE_H\r
-#define _MIMETYPE_H_\r
-\r
-\r
-struct MIMETYPE\r
- {\r
- char *ext;\r
- char *type;\r
- };\r
-\r
-const MIMETYPE mTypes[]=\r
-{\r
- { ".jpg" , "image/jpeg" },\r
- { ".gif", "image/gif" },\r
- { ".jpeg", "image/jpeg" },\r
- { ".htm", "text/html" },\r
- { ".html", "text/html" },\r
- { ".txt", "text/plain" },\r
- { ".css", "text/css" }\r
-};\r
-\r
-#endif /* _MIMETYPE_H_ */\r
-\r
-/* EOF */\r
-\r
+++ /dev/null
- /*
- $Revision: 1.5 $
- $Date: 2010/03/04 11:49:52 $
- $Author: faust $
- */
-
-#ifndef MODULE_SETTINGS_H
-#define MODULE_SETTINGS_H
-
-#include <cstring> // strcasecmp
-#include <string>
-#include <vector>
-
-//-----------------------------------------------------------------------------
-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<std::string> 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<PARAM_VALUE> moduleParams;
-};
-//-----------------------------------------------------------------------------
-#endif
+++ /dev/null
-#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
+++ /dev/null
- /*
- $Revision: 1.6 $
- $Date: 2007/12/03 09:00:17 $
- $Author: nobunaga $
- */
-
-#ifndef PROPERTY_NOTIFER_H
-#define PROPERTY_NOTIFER_H
-
-//-----------------------------------------------------------------------------
-template <typename varParamType>
-class PROPERTY_NOTIFIER_BASE
-{
-public:
- virtual ~PROPERTY_NOTIFIER_BASE(){};
- virtual void Notify(const varParamType & oldValue, const varParamType & newValue) = 0;
-};
-//-----------------------------------------------------------------------------
-template <typename varParamType>
-class NOTIFIER_BASE
-{
-public:
- virtual ~NOTIFIER_BASE(){};
- virtual void Notify(const varParamType & value) = 0;
-};
-//-----------------------------------------------------------------------------
-#endif //PROPERTY_NOTIFER_H
-
-
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.4 $
- $Date: 2008/03/25 17:41:50 $
- */
-
-
-#ifndef OS_INT_H
-#define OS_INT_H
-
-#ifdef LINUX
-#include <stdint.h>
-#endif
-
-#ifdef FREE_BSD5
-#include <inttypes.h>
-#endif
-
-#ifdef FREE_BSD
-#include <sys/inttypes.h>
-#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
-
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.12 $
- $Date: 2010/03/04 11:53:14 $
- $Author: faust $
-*/
-
-
-#ifndef PLUGIN_H
-#define PLUGIN_H
-
-#include <string>
-
-#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
+++ /dev/null
-#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
+++ /dev/null
-#ifndef RAW_IP_PACKET_H
-#define RAW_IP_PACKET_H
-
-#if defined(FREE_BSD) || defined(FREE_BSD5)
-#include <netinet/in_systm.h> // n_long in netinet/ip.h
-#endif
-
-#include <netinet/in.h> // for htons
-#include <netinet/ip.h> // for struct ip
-
-#include <cstring>
-
-#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
+++ /dev/null
- /*
- $Revision: 1.9 $
- $Date: 2010/03/11 14:42:04 $
- $Author: faust $
- */
-
-/*
- * Copyright (c) 2001 by Peter Simons <simons@cryp.to>.
- * 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 <iostream>
-
-template <typename varT>
-class RESETABLE
-{
- template <typename varT1>
- friend std::ostream & operator<<(std::ostream & o, RESETABLE<varT1> v);
-public:
- typedef varT value_type;
-
- //-------------------------------------------------------------------------
- RESETABLE()
- : value(),
- is_set(false)
- {
- }
- //-------------------------------------------------------------------------
- RESETABLE<value_type>(const RESETABLE<value_type> & rvalue)
- : value(rvalue.value),
- is_set(rvalue.is_set)
- {
- }
- //-------------------------------------------------------------------------
- RESETABLE(const value_type& val)
- : value(val),
- is_set(true)
- {
- }
- //-------------------------------------------------------------------------
- RESETABLE<value_type> & operator=(const RESETABLE<value_type> & rvalue)
- {
- value = rvalue.value;
- is_set = rvalue.is_set;
- return *this;
- }
- //-------------------------------------------------------------------------
- RESETABLE<value_type> & 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 <typename varT>
-std::ostream & operator<<(std::ostream & o, RESETABLE<varT> v)
-{
- return o << v.value;
-}
-//-------------------------------------------------------------------------
-#endif // RESETABLE_VARIABLE_H
-
+++ /dev/null
-#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
+++ /dev/null
-#ifndef SERVICE_CONF_H
-#define SERVICE_CONF_H
-
-struct SERVICE_CONF
-{
-string name;
-string comment;
-double cost;
-int payDay;
-};
-
-#endif //SERVICE_CONF_H
-
+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
-#ifndef SETTINGS_H
-#define SETTINGS_H
-
-#include <string>
-
-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
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+#ifndef ADMIN_H
+#define ADMIN_H
+
+#include <string>
+
+#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
--- /dev/null
+ /*
+ $Revision: 1.9 $
+ $Date: 2010/09/10 05:02:08 $
+ $Author: faust $
+ */
+
+#ifndef ADMIN_CONF_H
+#define ADMIN_CONF_H
+
+#include <string>
+
+#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
+
+
--- /dev/null
+ /*
+ $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
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+#ifndef ADMINS_H
+#define ADMINS_H
+
+#include <string>
+
+#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
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $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
--- /dev/null
+#ifndef __BASE_DB_H__
+#define __BASE_DB_H__
+
+#include <string>
+#include <vector>
+#include <map>
+
+class BASE_DB {
+public:
+
+ typedef std::map<std::string, std::string> TUPLE;
+ typedef std::vector<TUPLE> TUPLES;
+ typedef std::vector<std::string> 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
--- /dev/null
+#ifndef CORP_CONF_H
+#define CORP_CONF_H
+
+struct CORP_CONF
+{
+string name;
+double cash;
+};
+
+#endif //CORP_CONF_H
--- /dev/null
+#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
+
+
--- /dev/null
+/*\r
+ *****************************************************************************\r
+ *\r
+ * File: mimetype.h\r
+ *\r
+ * Description: TODO:\r
+ *\r
+ * $Id: mimetype.h,v 1.1.1.1 2005/10/09 11:00:45 nobunaga Exp $\r
+ *\r
+ *****************************************************************************\r
+ */\r
+\r
+#ifndef _MIMETYPE_H\r
+#define _MIMETYPE_H_\r
+\r
+\r
+struct MIMETYPE\r
+ {\r
+ char *ext;\r
+ char *type;\r
+ };\r
+\r
+const MIMETYPE mTypes[]=\r
+{\r
+ { ".jpg" , "image/jpeg" },\r
+ { ".gif", "image/gif" },\r
+ { ".jpeg", "image/jpeg" },\r
+ { ".htm", "text/html" },\r
+ { ".html", "text/html" },\r
+ { ".txt", "text/plain" },\r
+ { ".css", "text/css" }\r
+};\r
+\r
+#endif /* _MIMETYPE_H_ */\r
+\r
+/* EOF */\r
+\r
--- /dev/null
+ /*
+ $Revision: 1.5 $
+ $Date: 2010/03/04 11:49:52 $
+ $Author: faust $
+ */
+
+#ifndef MODULE_SETTINGS_H
+#define MODULE_SETTINGS_H
+
+#include <cstring> // strcasecmp
+#include <string>
+#include <vector>
+
+//-----------------------------------------------------------------------------
+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<std::string> 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<PARAM_VALUE> moduleParams;
+};
+//-----------------------------------------------------------------------------
+#endif
--- /dev/null
+#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
--- /dev/null
+ /*
+ $Revision: 1.6 $
+ $Date: 2007/12/03 09:00:17 $
+ $Author: nobunaga $
+ */
+
+#ifndef PROPERTY_NOTIFER_H
+#define PROPERTY_NOTIFER_H
+
+//-----------------------------------------------------------------------------
+template <typename varParamType>
+class PROPERTY_NOTIFIER_BASE
+{
+public:
+ virtual ~PROPERTY_NOTIFIER_BASE(){};
+ virtual void Notify(const varParamType & oldValue, const varParamType & newValue) = 0;
+};
+//-----------------------------------------------------------------------------
+template <typename varParamType>
+class NOTIFIER_BASE
+{
+public:
+ virtual ~NOTIFIER_BASE(){};
+ virtual void Notify(const varParamType & value) = 0;
+};
+//-----------------------------------------------------------------------------
+#endif //PROPERTY_NOTIFER_H
+
+
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.4 $
+ $Date: 2008/03/25 17:41:50 $
+ */
+
+
+#ifndef OS_INT_H
+#define OS_INT_H
+
+#ifdef LINUX
+#include <stdint.h>
+#endif
+
+#ifdef FREE_BSD5
+#include <inttypes.h>
+#endif
+
+#ifdef FREE_BSD
+#include <sys/inttypes.h>
+#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
+
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+/*
+ $Revision: 1.12 $
+ $Date: 2010/03/04 11:53:14 $
+ $Author: faust $
+*/
+
+
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+#include <string>
+
+#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
--- /dev/null
+#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
--- /dev/null
+#ifndef RAW_IP_PACKET_H
+#define RAW_IP_PACKET_H
+
+#if defined(FREE_BSD) || defined(FREE_BSD5)
+#include <netinet/in_systm.h> // n_long in netinet/ip.h
+#endif
+
+#include <netinet/in.h> // for htons
+#include <netinet/ip.h> // for struct ip
+
+#include <cstring>
+
+#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
--- /dev/null
+ /*
+ $Revision: 1.9 $
+ $Date: 2010/03/11 14:42:04 $
+ $Author: faust $
+ */
+
+/*
+ * Copyright (c) 2001 by Peter Simons <simons@cryp.to>.
+ * 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 <iostream>
+
+template <typename varT>
+class RESETABLE
+{
+ template <typename varT1>
+ friend std::ostream & operator<<(std::ostream & o, RESETABLE<varT1> v);
+public:
+ typedef varT value_type;
+
+ //-------------------------------------------------------------------------
+ RESETABLE()
+ : value(),
+ is_set(false)
+ {
+ }
+ //-------------------------------------------------------------------------
+ RESETABLE<value_type>(const RESETABLE<value_type> & rvalue)
+ : value(rvalue.value),
+ is_set(rvalue.is_set)
+ {
+ }
+ //-------------------------------------------------------------------------
+ RESETABLE(const value_type& val)
+ : value(val),
+ is_set(true)
+ {
+ }
+ //-------------------------------------------------------------------------
+ RESETABLE<value_type> & operator=(const RESETABLE<value_type> & rvalue)
+ {
+ value = rvalue.value;
+ is_set = rvalue.is_set;
+ return *this;
+ }
+ //-------------------------------------------------------------------------
+ RESETABLE<value_type> & 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 <typename varT>
+std::ostream & operator<<(std::ostream & o, RESETABLE<varT> v)
+{
+ return o << v.value;
+}
+//-------------------------------------------------------------------------
+#endif // RESETABLE_VARIABLE_H
+
--- /dev/null
+#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
--- /dev/null
+#ifndef SERVICE_CONF_H
+#define SERVICE_CONF_H
+
+struct SERVICE_CONF
+{
+string name;
+string comment;
+double cost;
+int payDay;
+};
+
+#endif //SERVICE_CONF_H
+
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#include <string>
+
+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
--- /dev/null
+/*
+ * 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 <stg34@ua.fm>
+ */
+
+ /*
+ $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
--- /dev/null
+#ifndef STG_MESSAGES_H
+#define STG_MESSAGES_H
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.3 $
+ $Date: 2010/03/04 11:49:52 $
+ */
+
+#include <ctime>
+#include <string>
+
+#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
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.16 $
+ $Date: 2010/01/19 11:09:48 $
+ $Author: faust $
+ */
+
+#ifndef STORE_H
+#define STORE_H
+
+#include <string>
+#include <vector>
+#include <map>
+
+#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<std::string> * 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<STG_MSG_HDR> * 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<std::string> * 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<std::string> * 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<std::string> * 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<std::string> * 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
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+#ifndef TARIFF_H
+#define TARIFF_H
+
+#include <ctime>
+
+#include <string>
+
+#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
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.9 $
+ $Date: 2010/10/05 20:41:11 $
+ $Author: faust $
+ */
+
+#ifndef TARIFF_CONF_H
+#define TARIFF_CONF_H
+
+#include <string>
+#include <vector>
+
+#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<int> hDay;
+ RESETABLE<int> mDay;
+ RESETABLE<int> hNight;
+ RESETABLE<int> mNight;
+ RESETABLE<double> priceDayA;
+ RESETABLE<double> priceNightA;
+ RESETABLE<double> priceDayB;
+ RESETABLE<double> priceNightB;
+ RESETABLE<int> threshold;
+ RESETABLE<int> singlePrice;
+ RESETABLE<int> 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<double> fee;
+ RESETABLE<double> free;
+ RESETABLE<int> traffType;
+ RESETABLE<double> passiveCost;
+ RESETABLE<std::string> name;
+};
+//-----------------------------------------------------------------------------
+struct TARIFF_DATA
+{
+ TARIFF_CONF tariffConf;
+ std::vector<DIRPRICE_DATA> 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_DATA_RES> 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
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+#ifndef TARIFFS_H
+#define TARIFFS_H
+
+#include <string>
+#include <list>
+
+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<TARIFF_DATA> * tdl) = 0;
+
+ virtual const std::string & GetStrError() const = 0;
+};
+
+#endif
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+#ifndef TRAFFCOUNTER_H
+#define TRAFFCOUNTER_H
+
+#include "raw_ip_packet.h"
+
+class TRAFFCOUNTER {
+public:
+ virtual void Process(const RAW_PACKET & rawPacket) = 0;
+};
+
+#endif
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+#ifndef USER_H
+#define USER_H
+
+#include <ctime>
+#include <string>
+
+#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<uint32_t> * notifier) = 0;
+ virtual void DelCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE<uint32_t> * notifier) = 0;
+
+ virtual void AddCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE<uint32_t> * notifier) = 0;
+ virtual void DelCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE<uint32_t> * notifier) = 0;
+
+ virtual void AddConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE<bool> * notifier) = 0;
+ virtual void DelConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE<bool> * notifier) = 0;
+
+ virtual void AddConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE<bool> * notifier) = 0;
+ virtual void DelConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE<bool> * 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
--- /dev/null
+ /*
+ $Revision: 1.12 $
+ $Date: 2010/03/11 14:42:05 $
+ $Author: faust $
+ */
+
+#ifndef USER_CONF_H
+#define USER_CONF_H
+
+#include <string>
+#include <vector>
+#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<std::string> service;
+ std::string group;
+ double credit;
+ std::string nextTariff;
+ std::vector<std::string> 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<std::string>()),
+ 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<std::string> password;
+ RESETABLE<int> passive;
+ RESETABLE<int> disabled;
+ RESETABLE<int> disabledDetailStat;
+ RESETABLE<int> alwaysOnline;
+ RESETABLE<std::string> tariffName;
+ RESETABLE<std::string> address;
+ RESETABLE<std::string> phone;
+ RESETABLE<std::string> email;
+ RESETABLE<std::string> note;
+ RESETABLE<std::string> realName;
+ RESETABLE<std::string> group;
+ RESETABLE<double> credit;
+ RESETABLE<std::string> nextTariff;
+ std::vector<RESETABLE<std::string> > userdata;
+ RESETABLE<time_t> creditExpire;
+ RESETABLE<USER_IPS> ips;
+};
+//-----------------------------------------------------------------------------
+#endif
+
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.22 $
+ $Date: 2010/03/04 11:49:53 $
+ $Author: faust $
+ */
+
+#ifndef USER_IPS_H
+#define USER_IPS_H
+
+#ifdef FREE_BSD
+#include <sys/types.h>
+#endif
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <cstring>
+#include <vector>
+#include <string>
+#include <iostream>
+#include <sstream>
+
+#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<IP_MASK> 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<IP_MASK>::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<IP_MASK>::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<std::string> 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
--- /dev/null
+/*
+$Revision: 1.44 $
+$Date: 2010/09/13 05:54:43 $
+$Author: faust $
+*/
+
+#ifndef USER_PROPERTY_H
+#define USER_PROPERTY_H
+
+#include <unistd.h> // access
+
+#include <ctime>
+#include <string>
+#include <set>
+#include <sstream>
+#include <iostream>
+
+#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<typename varT>
+class USER_PROPERTY {
+public:
+ USER_PROPERTY(varT & val);
+ virtual ~USER_PROPERTY();
+
+ void Set(const varT & rvalue);
+
+ USER_PROPERTY<varT> & 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<varT> * n);
+ void DelBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n);
+
+ void AddAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n);
+ void DelAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n);
+
+ time_t ModificationTime() const throw() { return modificationTime; }
+ void ModifyTime() throw();
+
+private:
+ varT & value;
+ time_t modificationTime;
+ std::set<PROPERTY_NOTIFIER_BASE<varT> *> beforeNotifiers;
+ std::set<PROPERTY_NOTIFIER_BASE<varT> *> afterNotifiers;
+ pthread_mutex_t mutex;
+};
+//-----------------------------------------------------------------------------
+template<typename varT>
+class USER_PROPERTY_LOGGED: public USER_PROPERTY<varT> {
+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<varT> * GetPointer() throw() { return this; }
+ const varT & Get() const { return USER_PROPERTY<varT>::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<double> cash;
+ USER_PROPERTY_LOGGED<DIR_TRAFF> up;
+ USER_PROPERTY_LOGGED<DIR_TRAFF> down;
+ USER_PROPERTY_LOGGED<double> lastCashAdd;
+ USER_PROPERTY_LOGGED<time_t> passiveTime;
+ USER_PROPERTY_LOGGED<time_t> lastCashAddTime;
+ USER_PROPERTY_LOGGED<double> freeMb;
+ USER_PROPERTY_LOGGED<time_t> lastActivityTime;
+
+ USER_PROPERTY_LOGGED<std::string> password;
+ USER_PROPERTY_LOGGED<int> passive;
+ USER_PROPERTY_LOGGED<int> disabled;
+ USER_PROPERTY_LOGGED<int> disabledDetailStat;
+ USER_PROPERTY_LOGGED<int> alwaysOnline;
+ USER_PROPERTY_LOGGED<std::string> tariffName;
+ USER_PROPERTY_LOGGED<std::string> nextTariff;
+ USER_PROPERTY_LOGGED<std::string> address;
+ USER_PROPERTY_LOGGED<std::string> note;
+ USER_PROPERTY_LOGGED<std::string> group;
+ USER_PROPERTY_LOGGED<std::string> email;
+ USER_PROPERTY_LOGGED<std::string> phone;
+ USER_PROPERTY_LOGGED<std::string> realName;
+ USER_PROPERTY_LOGGED<double> credit;
+ USER_PROPERTY_LOGGED<time_t> creditExpire;
+ USER_PROPERTY_LOGGED<USER_IPS> ips;
+ USER_PROPERTY_LOGGED<std::string> userdata0;
+ USER_PROPERTY_LOGGED<std::string> userdata1;
+ USER_PROPERTY_LOGGED<std::string> userdata2;
+ USER_PROPERTY_LOGGED<std::string> userdata3;
+ USER_PROPERTY_LOGGED<std::string> userdata4;
+ USER_PROPERTY_LOGGED<std::string> userdata5;
+ USER_PROPERTY_LOGGED<std::string> userdata6;
+ USER_PROPERTY_LOGGED<std::string> userdata7;
+ USER_PROPERTY_LOGGED<std::string> userdata8;
+ USER_PROPERTY_LOGGED<std::string> userdata9;
+};
+//=============================================================================
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+USER_PROPERTY<varT>::USER_PROPERTY(varT & val)
+ : value(val),
+ modificationTime(stgTime)
+{
+pthread_mutex_init(&mutex, NULL);
+}
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+USER_PROPERTY<varT>::~USER_PROPERTY()
+{
+pthread_mutex_destroy(&mutex);
+}
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+void USER_PROPERTY<varT>::ModifyTime() throw()
+{
+modificationTime = stgTime;
+}
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+void USER_PROPERTY<varT>::Set(const varT & rvalue)
+{
+STG_LOCKER locker(&mutex, __FILE__, __LINE__);
+
+typename std::set<PROPERTY_NOTIFIER_BASE<varT> *>::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 <typename varT>
+inline
+USER_PROPERTY<varT> & USER_PROPERTY<varT>::operator= (const varT & newValue)
+{
+Set(newValue);
+return *this;
+}
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+void USER_PROPERTY<varT>::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
+{
+STG_LOCKER locker(&mutex, __FILE__, __LINE__);
+beforeNotifiers.insert(n);
+}
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+void USER_PROPERTY<varT>::DelBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
+{
+STG_LOCKER locker(&mutex, __FILE__, __LINE__);
+beforeNotifiers.erase(n);
+}
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+void USER_PROPERTY<varT>::AddAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
+{
+STG_LOCKER locker(&mutex, __FILE__, __LINE__);
+afterNotifiers.insert(n);
+}
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+void USER_PROPERTY<varT>::DelAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
+{
+STG_LOCKER locker(&mutex, __FILE__, __LINE__);
+afterNotifiers.erase(n);
+}
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename varT>
+inline
+USER_PROPERTY_LOGGED<varT>::USER_PROPERTY_LOGGED(varT & val,
+ const std::string & n,
+ bool isPass,
+ bool isSt,
+ STG_LOGGER & logger,
+ const std::string & sd)
+
+ : USER_PROPERTY<varT>(val),
+ stgLogger(logger),
+ isPassword(isPass),
+ isStat(isSt),
+ name(n),
+ scriptsDir(sd)
+{
+}
+//-------------------------------------------------------------------------
+template <typename varT>
+bool USER_PROPERTY_LOGGED<varT>::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<varT>::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<varT>::Set(val);
+ return true;
+ }
+else
+ {
+ WriteAccessDenied(login, admin, name);
+ return false;
+ }
+return true;
+}
+//-------------------------------------------------------------------------
+template <typename varT>
+inline
+void USER_PROPERTY_LOGGED<varT>::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 <typename varT>
+inline
+void USER_PROPERTY_LOGGED<varT>::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 <typename varT>
+void USER_PROPERTY_LOGGED<varT>::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<typename varT>
+inline
+ostream & operator<< (ostream & stream, const USER_PROPERTY<varT> & value)
+{
+return stream << value.ConstData();
+}
+//-----------------------------------------------------------------------------
+
+#endif // USER_PROPERTY_H
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.15 $
+ $Date: 2010/03/11 14:42:05 $
+ $Author: faust $
+ */
+
+#ifndef USER_STAT_H
+#define USER_STAT_H
+
+#include <ctime>
+#include <map>
+
+#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<IP_DIR_PAIR, STAT_NODE> 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<double> cash;
+ RESETABLE<double> freeMb;
+ RESETABLE<double> lastCashAdd;
+ RESETABLE<time_t> lastCashAddTime;
+ RESETABLE<time_t> passiveTime;
+ RESETABLE<time_t> lastActivityTime;
+ RESETABLE<DIR_TRAFF> up;
+ RESETABLE<DIR_TRAFF> down;
+};
+//-----------------------------------------------------------------------------
+#endif
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+/*
+ $Revision: 1.7 $
+ $Date: 2010/10/07 19:48:52 $
+ $Author: faust $
+ */
+
+#ifndef USER_TRAFF_H
+#define USER_TRAFF_H
+
+#include <iostream>
+#include <vector>
+
+#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<uint64_t> 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
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+#ifndef USERS_H
+#define USERS_H
+
+#include <string>
+
+#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<USER_PTR> * notifier) = 0;
+ virtual void DelNotifierUserAdd(NOTIFIER_BASE<USER_PTR> * notifier) = 0;
+
+ virtual void AddNotifierUserDel(NOTIFIER_BASE<USER_PTR> * notifier) = 0;
+ virtual void DelNotifierUserDel(NOTIFIER_BASE<USER_PTR> * 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
--- /dev/null
+#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 <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.6 $
+ $Date: 2009/08/05 11:40:30 $
+ $Author: faust $
+ */
+
+#include <sys/time.h>
+#include <time.h>
+
+#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
--- /dev/null
+/*
+ * 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 <faust@stargazer.dp.ua>
+ */
+
+ /*
+ $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
+++ /dev/null
-/*
- * 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 <stg34@ua.fm>
- */
-
- /*
- $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
+++ /dev/null
-#ifndef STG_MESSAGES_H
-#define STG_MESSAGES_H
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.3 $
- $Date: 2010/03/04 11:49:52 $
- */
-
-#include <ctime>
-#include <string>
-
-#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
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.16 $
- $Date: 2010/01/19 11:09:48 $
- $Author: faust $
- */
-
-#ifndef STORE_H
-#define STORE_H
-
-#include <string>
-#include <vector>
-#include <map>
-
-#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<std::string> * 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<STG_MSG_HDR> * 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<std::string> * 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<std::string> * 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<std::string> * 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<std::string> * 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
+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
-#ifndef TARIFF_H
-#define TARIFF_H
-
-#include <ctime>
-
-#include <string>
-
-#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
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.9 $
- $Date: 2010/10/05 20:41:11 $
- $Author: faust $
- */
-
-#ifndef TARIFF_CONF_H
-#define TARIFF_CONF_H
-
-#include <string>
-#include <vector>
-
-#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<int> hDay;
- RESETABLE<int> mDay;
- RESETABLE<int> hNight;
- RESETABLE<int> mNight;
- RESETABLE<double> priceDayA;
- RESETABLE<double> priceNightA;
- RESETABLE<double> priceDayB;
- RESETABLE<double> priceNightB;
- RESETABLE<int> threshold;
- RESETABLE<int> singlePrice;
- RESETABLE<int> 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<double> fee;
- RESETABLE<double> free;
- RESETABLE<int> traffType;
- RESETABLE<double> passiveCost;
- RESETABLE<std::string> name;
-};
-//-----------------------------------------------------------------------------
-struct TARIFF_DATA
-{
- TARIFF_CONF tariffConf;
- std::vector<DIRPRICE_DATA> 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_DATA_RES> 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
+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
-#ifndef TARIFFS_H
-#define TARIFFS_H
-
-#include <string>
-#include <list>
-
-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<TARIFF_DATA> * tdl) = 0;
-
- virtual const std::string & GetStrError() const = 0;
-};
-
-#endif
+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
-#ifndef TRAFFCOUNTER_H
-#define TRAFFCOUNTER_H
-
-#include "raw_ip_packet.h"
-
-class TRAFFCOUNTER {
-public:
- virtual void Process(const RAW_PACKET & rawPacket) = 0;
-};
-
-#endif
+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
-#ifndef USER_H
-#define USER_H
-
-#include <ctime>
-#include <string>
-
-#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<uint32_t> * notifier) = 0;
- virtual void DelCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE<uint32_t> * notifier) = 0;
-
- virtual void AddCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE<uint32_t> * notifier) = 0;
- virtual void DelCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE<uint32_t> * notifier) = 0;
-
- virtual void AddConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE<bool> * notifier) = 0;
- virtual void DelConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE<bool> * notifier) = 0;
-
- virtual void AddConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE<bool> * notifier) = 0;
- virtual void DelConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE<bool> * 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
+++ /dev/null
- /*
- $Revision: 1.12 $
- $Date: 2010/03/11 14:42:05 $
- $Author: faust $
- */
-
-#ifndef USER_CONF_H
-#define USER_CONF_H
-
-#include <string>
-#include <vector>
-#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<std::string> service;
- std::string group;
- double credit;
- std::string nextTariff;
- std::vector<std::string> 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<std::string>()),
- 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<std::string> password;
- RESETABLE<int> passive;
- RESETABLE<int> disabled;
- RESETABLE<int> disabledDetailStat;
- RESETABLE<int> alwaysOnline;
- RESETABLE<std::string> tariffName;
- RESETABLE<std::string> address;
- RESETABLE<std::string> phone;
- RESETABLE<std::string> email;
- RESETABLE<std::string> note;
- RESETABLE<std::string> realName;
- RESETABLE<std::string> group;
- RESETABLE<double> credit;
- RESETABLE<std::string> nextTariff;
- std::vector<RESETABLE<std::string> > userdata;
- RESETABLE<time_t> creditExpire;
- RESETABLE<USER_IPS> ips;
-};
-//-----------------------------------------------------------------------------
-#endif
-
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.22 $
- $Date: 2010/03/04 11:49:53 $
- $Author: faust $
- */
-
-#ifndef USER_IPS_H
-#define USER_IPS_H
-
-#ifdef FREE_BSD
-#include <sys/types.h>
-#endif
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <cstring>
-#include <vector>
-#include <string>
-#include <iostream>
-#include <sstream>
-
-#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<IP_MASK> 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<IP_MASK>::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<IP_MASK>::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<std::string> 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
+++ /dev/null
-/*
-$Revision: 1.44 $
-$Date: 2010/09/13 05:54:43 $
-$Author: faust $
-*/
-
-#ifndef USER_PROPERTY_H
-#define USER_PROPERTY_H
-
-#include <unistd.h> // access
-
-#include <ctime>
-#include <string>
-#include <set>
-#include <sstream>
-#include <iostream>
-
-#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<typename varT>
-class USER_PROPERTY {
-public:
- USER_PROPERTY(varT & val);
- virtual ~USER_PROPERTY();
-
- void Set(const varT & rvalue);
-
- USER_PROPERTY<varT> & 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<varT> * n);
- void DelBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n);
-
- void AddAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n);
- void DelAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n);
-
- time_t ModificationTime() const throw() { return modificationTime; }
- void ModifyTime() throw();
-
-private:
- varT & value;
- time_t modificationTime;
- std::set<PROPERTY_NOTIFIER_BASE<varT> *> beforeNotifiers;
- std::set<PROPERTY_NOTIFIER_BASE<varT> *> afterNotifiers;
- pthread_mutex_t mutex;
-};
-//-----------------------------------------------------------------------------
-template<typename varT>
-class USER_PROPERTY_LOGGED: public USER_PROPERTY<varT> {
-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<varT> * GetPointer() throw() { return this; }
- const varT & Get() const { return USER_PROPERTY<varT>::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<double> cash;
- USER_PROPERTY_LOGGED<DIR_TRAFF> up;
- USER_PROPERTY_LOGGED<DIR_TRAFF> down;
- USER_PROPERTY_LOGGED<double> lastCashAdd;
- USER_PROPERTY_LOGGED<time_t> passiveTime;
- USER_PROPERTY_LOGGED<time_t> lastCashAddTime;
- USER_PROPERTY_LOGGED<double> freeMb;
- USER_PROPERTY_LOGGED<time_t> lastActivityTime;
-
- USER_PROPERTY_LOGGED<std::string> password;
- USER_PROPERTY_LOGGED<int> passive;
- USER_PROPERTY_LOGGED<int> disabled;
- USER_PROPERTY_LOGGED<int> disabledDetailStat;
- USER_PROPERTY_LOGGED<int> alwaysOnline;
- USER_PROPERTY_LOGGED<std::string> tariffName;
- USER_PROPERTY_LOGGED<std::string> nextTariff;
- USER_PROPERTY_LOGGED<std::string> address;
- USER_PROPERTY_LOGGED<std::string> note;
- USER_PROPERTY_LOGGED<std::string> group;
- USER_PROPERTY_LOGGED<std::string> email;
- USER_PROPERTY_LOGGED<std::string> phone;
- USER_PROPERTY_LOGGED<std::string> realName;
- USER_PROPERTY_LOGGED<double> credit;
- USER_PROPERTY_LOGGED<time_t> creditExpire;
- USER_PROPERTY_LOGGED<USER_IPS> ips;
- USER_PROPERTY_LOGGED<std::string> userdata0;
- USER_PROPERTY_LOGGED<std::string> userdata1;
- USER_PROPERTY_LOGGED<std::string> userdata2;
- USER_PROPERTY_LOGGED<std::string> userdata3;
- USER_PROPERTY_LOGGED<std::string> userdata4;
- USER_PROPERTY_LOGGED<std::string> userdata5;
- USER_PROPERTY_LOGGED<std::string> userdata6;
- USER_PROPERTY_LOGGED<std::string> userdata7;
- USER_PROPERTY_LOGGED<std::string> userdata8;
- USER_PROPERTY_LOGGED<std::string> userdata9;
-};
-//=============================================================================
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-USER_PROPERTY<varT>::USER_PROPERTY(varT & val)
- : value(val),
- modificationTime(stgTime)
-{
-pthread_mutex_init(&mutex, NULL);
-}
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-USER_PROPERTY<varT>::~USER_PROPERTY()
-{
-pthread_mutex_destroy(&mutex);
-}
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-void USER_PROPERTY<varT>::ModifyTime() throw()
-{
-modificationTime = stgTime;
-}
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-void USER_PROPERTY<varT>::Set(const varT & rvalue)
-{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-
-typename std::set<PROPERTY_NOTIFIER_BASE<varT> *>::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 <typename varT>
-inline
-USER_PROPERTY<varT> & USER_PROPERTY<varT>::operator= (const varT & newValue)
-{
-Set(newValue);
-return *this;
-}
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-void USER_PROPERTY<varT>::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
-{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-beforeNotifiers.insert(n);
-}
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-void USER_PROPERTY<varT>::DelBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
-{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-beforeNotifiers.erase(n);
-}
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-void USER_PROPERTY<varT>::AddAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
-{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-afterNotifiers.insert(n);
-}
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-void USER_PROPERTY<varT>::DelAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
-{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-afterNotifiers.erase(n);
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-template <typename varT>
-inline
-USER_PROPERTY_LOGGED<varT>::USER_PROPERTY_LOGGED(varT & val,
- const std::string & n,
- bool isPass,
- bool isSt,
- STG_LOGGER & logger,
- const std::string & sd)
-
- : USER_PROPERTY<varT>(val),
- stgLogger(logger),
- isPassword(isPass),
- isStat(isSt),
- name(n),
- scriptsDir(sd)
-{
-}
-//-------------------------------------------------------------------------
-template <typename varT>
-bool USER_PROPERTY_LOGGED<varT>::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<varT>::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<varT>::Set(val);
- return true;
- }
-else
- {
- WriteAccessDenied(login, admin, name);
- return false;
- }
-return true;
-}
-//-------------------------------------------------------------------------
-template <typename varT>
-inline
-void USER_PROPERTY_LOGGED<varT>::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 <typename varT>
-inline
-void USER_PROPERTY_LOGGED<varT>::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 <typename varT>
-void USER_PROPERTY_LOGGED<varT>::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<typename varT>
-inline
-ostream & operator<< (ostream & stream, const USER_PROPERTY<varT> & value)
-{
-return stream << value.ConstData();
-}
-//-----------------------------------------------------------------------------
-
-#endif // USER_PROPERTY_H
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.15 $
- $Date: 2010/03/11 14:42:05 $
- $Author: faust $
- */
-
-#ifndef USER_STAT_H
-#define USER_STAT_H
-
-#include <ctime>
-#include <map>
-
-#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<IP_DIR_PAIR, STAT_NODE> 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<double> cash;
- RESETABLE<double> freeMb;
- RESETABLE<double> lastCashAdd;
- RESETABLE<time_t> lastCashAddTime;
- RESETABLE<time_t> passiveTime;
- RESETABLE<time_t> lastActivityTime;
- RESETABLE<DIR_TRAFF> up;
- RESETABLE<DIR_TRAFF> down;
-};
-//-----------------------------------------------------------------------------
-#endif
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.7 $
- $Date: 2010/10/07 19:48:52 $
- $Author: faust $
- */
-
-#ifndef USER_TRAFF_H
-#define USER_TRAFF_H
-
-#include <iostream>
-#include <vector>
-
-#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<uint64_t> 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
+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
-#ifndef USERS_H
-#define USERS_H
-
-#include <string>
-
-#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<USER_PTR> * notifier) = 0;
- virtual void DelNotifierUserAdd(NOTIFIER_BASE<USER_PTR> * notifier) = 0;
-
- virtual void AddNotifierUserDel(NOTIFIER_BASE<USER_PTR> * notifier) = 0;
- virtual void DelNotifierUserDel(NOTIFIER_BASE<USER_PTR> * 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
+++ /dev/null
-#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 <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.6 $
- $Date: 2009/08/05 11:40:30 $
- $Author: faust $
- */
-
-#include <sys/time.h>
-#include <time.h>
-
-#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
+++ /dev/null
-/*
- * 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 <faust@stargazer.dp.ua>
- */
-
- /*
- $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