From: Maxim Mamontov <faust.madf@gmail.com> Date: Mon, 21 Mar 2011 12:40:53 +0000 (+0200) Subject: user_property.h moved to general include dir X-Git-Tag: 2.407-rc3~136 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/9596c437646f369c3924dc78b20872762f3a47b9?ds=inline;hp=38da2fa514bbfb11197fa17ecb1cde480bb9e2cc user_property.h moved to general include dir --- diff --git a/include/user_property.h b/include/user_property.h new file mode 100644 index 00000000..b269389a --- /dev/null +++ b/include/user_property.h @@ -0,0 +1,420 @@ +/* +$Revision: 1.44 $ +$Date: 2010/09/13 05:54:43 $ +$Author: faust $ +*/ + +#ifndef USER_PROPERTY_H +#define USER_PROPERTY_H + +#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" + +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); + USER_PROPERTY<varT> & operator-= (const varT & rvalue); + + const varT * operator&() const throw(); + const varT & ConstData() const throw(); + + 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(); + 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(); + const varT & Get() const; + const std::string & GetName() const; + 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: + 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> +USER_PROPERTY<varT>::USER_PROPERTY(varT & val) + : value(val) +{ +pthread_mutex_init(&mutex, NULL); +modificationTime = stgTime; +} +//----------------------------------------------------------------------------- +template <typename varT> +USER_PROPERTY<varT>::~USER_PROPERTY() +{ +} +//----------------------------------------------------------------------------- +template <typename varT> +void USER_PROPERTY<varT>::ModifyTime() throw() +{ +modificationTime = stgTime; +} +//----------------------------------------------------------------------------- +template <typename varT> +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> +USER_PROPERTY<varT> & USER_PROPERTY<varT>::operator= (const varT & newValue) +{ +Set(newValue); +return *this; +} +//----------------------------------------------------------------------------- +template <typename varT> +USER_PROPERTY<varT>& USER_PROPERTY<varT>::operator-= (const varT & delta) +{ +varT newValue = ConstData() - delta; +Set(newValue); +return *this; +} +//----------------------------------------------------------------------------- +template <typename varT> +const varT * USER_PROPERTY<varT>::operator&() const throw() +{ +return &value; +} +//----------------------------------------------------------------------------- +template <typename varT> +const varT & USER_PROPERTY<varT>::ConstData() const throw() +{ +return value; +} +//----------------------------------------------------------------------------- +template <typename varT> +void USER_PROPERTY<varT>::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); +beforeNotifiers.insert(n); +} +//----------------------------------------------------------------------------- +template <typename varT> +void USER_PROPERTY<varT>::DelBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); +beforeNotifiers.erase(n); +} +//----------------------------------------------------------------------------- +template <typename varT> +void USER_PROPERTY<varT>::AddAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); +afterNotifiers.insert(n); +} +//----------------------------------------------------------------------------- +template <typename varT> +void USER_PROPERTY<varT>::DelAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n) +{ +STG_LOCKER locker(&mutex, __FILE__, __LINE__); +afterNotifiers.erase(n); +} +//----------------------------------------------------------------------------- +template <typename varT> +time_t USER_PROPERTY<varT>::ModificationTime() const throw() +{ +return modificationTime; +} +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +template <typename varT> +USER_PROPERTY_LOGGED<varT>::USER_PROPERTY_LOGGED(varT & val, + 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> +USER_PROPERTY_LOGGED<varT>::~USER_PROPERTY_LOGGED() +{ +} +//----------------------------------------------------------------------------- +template <typename varT> +USER_PROPERTY_LOGGED<varT> * USER_PROPERTY_LOGGED<varT>::GetPointer() throw() +{ +return this; +} +//----------------------------------------------------------------------------- +template <typename varT> +const varT & USER_PROPERTY_LOGGED<varT>::Get() const +{ +return USER_PROPERTY<varT>::ConstData(); +}; +//------------------------------------------------------------------------- +template <typename varT> +const std::string & USER_PROPERTY_LOGGED<varT>::GetName() const +{ +return name; +}; +//------------------------------------------------------------------------- +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")) + { + stringstream oldVal; + 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> +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> +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> +ostream & operator<< (ostream & stream, const USER_PROPERTY<varT> & value) +{ +return stream << value.ConstData(); +} +//----------------------------------------------------------------------------- + +#endif // USER_PROPERTY_H diff --git a/projects/stargazer/plugins/authorization/ao/ao.cpp b/projects/stargazer/plugins/authorization/ao/ao.cpp index b59bd58c..811807de 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.cpp +++ b/projects/stargazer/plugins/authorization/ao/ao.cpp @@ -31,7 +31,7 @@ $Author: faust $ #include "ao.h" #include "user.h" #include "users.h" -#include "../../../user_property.h" +#include "user_property.h" #include "../../../eventloop.h" class AO_CREATOR diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index b3d8823e..4e60829d 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -41,8 +41,8 @@ #include "common.h" #include "stg_locker.h" #include "tariff.h" +#include "user_property.h" #include "../../../settings.h" -#include "../../../user_property.h" extern volatile const time_t stgTime; diff --git a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp index a557b677..30205c92 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp @@ -6,8 +6,7 @@ #include "user_ips.h" #include "utils.h" #include "common.h" - -#include "../../../user_property.h" +#include "user_property.h" //------------------------------------------------------------------------------ diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp index d16d883f..296a7c7b 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp @@ -5,13 +5,13 @@ #include "users.h" #include "admins.h" #include "tariffs.h" -#include "../../../user_property.h" #include "rpcconfig.h" #include "user_helper.h" #include "user_ips.h" #include "utils.h" #include "common.h" +#include "user_property.h" //------------------------------------------------------------------------------ diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index b90cb2b6..8a01f169 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -12,8 +12,8 @@ #include "parser.h" #include "version.h" #include "tariffs.h" +#include "user_property.h" #include "../../../settings.h" -#include "../../../user_property.h" #define UNAME_LEN (256) //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index 3067e87e..169ac61d 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -7,8 +7,8 @@ #include "ping.h" #include "user.h" #include "stg_locker.h" +#include "user_property.h" #include "../../../settings.h" -#include "../../../user_property.h" class PING_CREATOR { diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index c3fb7183..a4eea3a8 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -34,7 +34,7 @@ #include "store.h" #include "common.h" #include "user_conf.h" -#include "../../../user_property.h" +#include "user_property.h" extern volatile const time_t stgTime; diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 1cc7883b..a772e507 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -36,7 +36,7 @@ #include "ur_functor.h" #include "send_functor.h" #include "stg_locker.h" -#include "../../../user_property.h" +#include "user_property.h" extern volatile const time_t stgTime; diff --git a/projects/stargazer/user_property.h b/projects/stargazer/user_property.h deleted file mode 100644 index b269389a..00000000 --- a/projects/stargazer/user_property.h +++ /dev/null @@ -1,420 +0,0 @@ -/* -$Revision: 1.44 $ -$Date: 2010/09/13 05:54:43 $ -$Author: faust $ -*/ - -#ifndef USER_PROPERTY_H -#define USER_PROPERTY_H - -#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" - -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); - USER_PROPERTY<varT> & operator-= (const varT & rvalue); - - const varT * operator&() const throw(); - const varT & ConstData() const throw(); - - 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(); - 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(); - const varT & Get() const; - const std::string & GetName() const; - 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: - 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> -USER_PROPERTY<varT>::USER_PROPERTY(varT & val) - : value(val) -{ -pthread_mutex_init(&mutex, NULL); -modificationTime = stgTime; -} -//----------------------------------------------------------------------------- -template <typename varT> -USER_PROPERTY<varT>::~USER_PROPERTY() -{ -} -//----------------------------------------------------------------------------- -template <typename varT> -void USER_PROPERTY<varT>::ModifyTime() throw() -{ -modificationTime = stgTime; -} -//----------------------------------------------------------------------------- -template <typename varT> -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> -USER_PROPERTY<varT> & USER_PROPERTY<varT>::operator= (const varT & newValue) -{ -Set(newValue); -return *this; -} -//----------------------------------------------------------------------------- -template <typename varT> -USER_PROPERTY<varT>& USER_PROPERTY<varT>::operator-= (const varT & delta) -{ -varT newValue = ConstData() - delta; -Set(newValue); -return *this; -} -//----------------------------------------------------------------------------- -template <typename varT> -const varT * USER_PROPERTY<varT>::operator&() const throw() -{ -return &value; -} -//----------------------------------------------------------------------------- -template <typename varT> -const varT & USER_PROPERTY<varT>::ConstData() const throw() -{ -return value; -} -//----------------------------------------------------------------------------- -template <typename varT> -void USER_PROPERTY<varT>::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -beforeNotifiers.insert(n); -} -//----------------------------------------------------------------------------- -template <typename varT> -void USER_PROPERTY<varT>::DelBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -beforeNotifiers.erase(n); -} -//----------------------------------------------------------------------------- -template <typename varT> -void USER_PROPERTY<varT>::AddAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -afterNotifiers.insert(n); -} -//----------------------------------------------------------------------------- -template <typename varT> -void USER_PROPERTY<varT>::DelAfterNotifier(PROPERTY_NOTIFIER_BASE<varT> * n) -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -afterNotifiers.erase(n); -} -//----------------------------------------------------------------------------- -template <typename varT> -time_t USER_PROPERTY<varT>::ModificationTime() const throw() -{ -return modificationTime; -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -template <typename varT> -USER_PROPERTY_LOGGED<varT>::USER_PROPERTY_LOGGED(varT & val, - 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> -USER_PROPERTY_LOGGED<varT>::~USER_PROPERTY_LOGGED() -{ -} -//----------------------------------------------------------------------------- -template <typename varT> -USER_PROPERTY_LOGGED<varT> * USER_PROPERTY_LOGGED<varT>::GetPointer() throw() -{ -return this; -} -//----------------------------------------------------------------------------- -template <typename varT> -const varT & USER_PROPERTY_LOGGED<varT>::Get() const -{ -return USER_PROPERTY<varT>::ConstData(); -}; -//------------------------------------------------------------------------- -template <typename varT> -const std::string & USER_PROPERTY_LOGGED<varT>::GetName() const -{ -return name; -}; -//------------------------------------------------------------------------- -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")) - { - stringstream oldVal; - 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> -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> -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> -ostream & operator<< (ostream & stream, const USER_PROPERTY<varT> & value) -{ -return stream << value.ConstData(); -} -//----------------------------------------------------------------------------- - -#endif // USER_PROPERTY_H