From: Naffanya Date: Wed, 29 Jan 2014 21:04:05 +0000 (+0200) Subject: Search parameter in map case insensitive X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/b3139bf3f37b3b0244efea8b4b5e5a7d0bc90095?hp=-c Search parameter in map case insensitive --- b3139bf3f37b3b0244efea8b4b5e5a7d0bc90095 diff --combined include/stg/user.h index b7024859,a8f61105..8dc761e3 --- a/include/stg/user.h +++ b/include/stg/user.h @@@ -21,14 -21,16 +21,16 @@@ #ifndef USER_H #define USER_H - #include - #include - - #include "os_int.h" #include "notifer.h" #include "message.h" #include "tariff.h" #include "user_traff.h" + #include "os_int.h" + + #include + #include + + #include class USER_PROPERTIES; class AUTH; @@@ -71,12 -73,12 +73,12 @@@ public virtual bool GetConnected() const = 0; virtual time_t GetConnectedModificationTime() const = 0; + virtual const std::string & GetLastDisconnectReason() 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 time_t GetAuthorizedModificationTime() const = 0; + virtual bool IsAuthorizedBy(const AUTH * auth) const = 0; + virtual std::vector GetAuthorizers() const = 0; virtual int AddMessage(STG_MSG * msg) = 0; @@@ -96,7 -98,7 +98,7 @@@ virtual time_t GetLastWriteStatTime() const = 0; virtual bool IsInetable() = 0; - virtual std::string GetEnabledDirs() = 0; + virtual std::string GetEnabledDirs() const = 0; virtual void OnAdd() = 0; virtual void OnDelete() = 0; diff --combined include/stg/user_property.h index 7c0f4da1,1716296a..398c4579 --- a/include/stg/user_property.h +++ b/include/stg/user_property.h @@@ -12,13 -12,12 +12,14 @@@ $Author: faust #include #include #include +#include #include #include #include "stg/logger.h" #include "stg/locker.h" #include "stg/scriptexecuter.h" ++#include "stg/common.h" #include "store.h" #include "admin.h" @@@ -26,14 -25,10 +27,14 @@@ #include "noncopyable.h" extern volatile time_t stgTime; - +//----------------------------------------------------------------------------- +class USER_PROPERTY_BASE { +public: + virtual std::string ToString() const = 0; +}; //----------------------------------------------------------------------------- template -class USER_PROPERTY { +class USER_PROPERTY : public USER_PROPERTY_BASE { public: USER_PROPERTY(varT & val); virtual ~USER_PROPERTY(); @@@ -73,8 -68,7 +74,8 @@@ public bool isPassword, bool isStat, STG_LOGGER & logger, - const std::string & sd); + const std::string & sd, + std::map & properties); virtual ~USER_PROPERTY_LOGGED() {} USER_PROPERTY_LOGGED * GetPointer() throw() { return this; } @@@ -124,7 -118,6 +125,7 @@@ private USER_STAT stat; USER_CONF conf; + std::map properties; public: USER_PROPERTIES(const std::string & sd); @@@ -137,9 -130,6 +138,9 @@@ void SetProperties(const USER_PROPERTIES & p) { stat = p.stat; conf = p.conf; } + std::string GetPropertyValue(const std::string & name) const; + bool Exists(const std::string & name) const; + USER_PROPERTY_LOGGED cash; USER_PROPERTY_LOGGED up; USER_PROPERTY_LOGGED down; @@@ -278,8 -268,7 +279,8 @@@ USER_PROPERTY_LOGGED::USER_PROPER bool isPass, bool isSt, STG_LOGGER & logger, - const std::string & sd) + const std::string & sd, + std::map & properties) : USER_PROPERTY(val), stgLogger(logger), @@@ -288,7 -277,6 +289,7 @@@ name(n), scriptsDir(sd) { - properties.insert(std::make_pair(name, this)); ++properties.insert(std::make_pair(ToLower(name), this)); } //------------------------------------------------------------------------- template @@@ -388,23 -376,6 +389,23 @@@ els //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- +inline +std::string USER_PROPERTIES::GetPropertyValue(const std::string & name) const +{ +std::map::const_iterator it = properties.find(name); +if (it == properties.end()) + return ""; +return it->second->ToString(); +} +//----------------------------------------------------------------------------- +inline +bool USER_PROPERTIES::Exists(const std::string & name) const +{ +return properties.find(name) != properties.end(); +} +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- template inline std::ostream & operator<< (std::ostream & stream, const USER_PROPERTY & value) @@@ -413,10 -384,9 +414,10 @@@ return stream << value.ConstData() } //----------------------------------------------------------------------------- template +inline std::string USER_PROPERTY::ToString() const { -std::stringstream stream; +std::ostringstream stream; stream << value; return stream.str(); } diff --combined include/stg/users.h index 2ba23833,1a8d7a43..9f516aef --- a/include/stg/users.h +++ b/include/stg/users.h @@@ -32,6 -32,7 +32,7 @@@ class USERS public: virtual ~USERS() {} virtual int FindByName(const std::string & login, USER_PTR * user) = 0; + virtual int FindByName(const std::string & login, CONST_USER_PTR * user) const = 0; virtual bool TariffInUse(const std::string & tariffName) const = 0; @@@ -46,13 -47,16 +47,16 @@@ virtual bool Authorize(const std::string & login, uint32_t ip, uint32_t enabledDirs, const AUTH * auth) = 0; - virtual bool Unauthorize(const std::string & login, const AUTH * auth) = 0; + virtual bool Unauthorize(const std::string & login, + const AUTH * auth, + const std::string & reason = std::string()) = 0; virtual int ReadUsers() = 0; virtual size_t Count() const = 0; virtual int FindByIPIdx(uint32_t ip, USER_PTR * user) const = 0; virtual bool IsIPInIndex(uint32_t ip) const = 0; + virtual bool IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const = 0; virtual int OpenSearch() = 0; virtual int SearchNext(int handle, USER_PTR * u) = 0; @@@ -60,6 -64,7 +64,6 @@@ virtual int Start() = 0; virtual int Stop() = 0; - }; #endif diff --combined projects/stargazer/main.cpp index eb61e2d5,1e4c677e..200fd2a6 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@@ -106,7 -106,7 +106,7 @@@ els } } //----------------------------------------------------------------------------- - #ifdef LINUX + #if defined(LINUX) || defined(DARWIN) int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings) #else int StartScriptExecuter(char *, int msgKey, int * msgID, SETTINGS_IMPL * settings) @@@ -151,7 -151,7 +151,7 @@@ switch (executerPid case 0: delete settings; - #ifdef LINUX + #if defined(LINUX) || defined(DARWIN) Executer(*msgID, executerPid, procName); #else Executer(*msgID, executerPid); @@@ -160,7 -160,7 +160,7 @@@ default: if (executersPid.empty()) { - #ifdef LINUX + #if defined(LINUX) || defined(DARWIN) Executer(*msgID, executerPid, NULL); #else Executer(*msgID, executerPid); @@@ -271,7 -271,6 +271,7 @@@ if (settings->ReadSettings() WriteServLog("ReadSettings error. %s", settings->GetStrError().c_str()); exit(1); } + #ifndef NO_DAEMON std::string startFile(settings->GetConfDir() + START_FILE); #endif @@@ -464,7 -463,7 +464,7 @@@ while (true } break; default: - WriteServLog("Ignore signel %d", sig); + WriteServLog("Ignore signal %d", sig); break; } if (stop) diff --combined projects/stargazer/plugins/other/rscript/rscript.cpp index 5c94606b,3bc90792..725bc3f1 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@@ -324,6 -324,9 +324,9 @@@ std::for_each(authorizedUsers.begin() authorizedUsers.end(), UpdateRouter(*this)); + logger("%s reloaded successfully.", rsSettings.GetMapFileName().c_str()); + printfd(__FILE__, "REMOTE_SCRIPT::Reload() %s reloaded successfully.\n"); + return 0; } //----------------------------------------------------------------------------- @@@ -426,7 -429,7 +429,7 @@@ for(it = rsSettings.GetUserParams().beg it != rsSettings.GetUserParams().end(); ++it) { - std::string parameter(GetUserParam(rsu.user, *it)); + std::string parameter(rsu.user->GetParamValue(it->c_str())); if (params.length() + parameter.length() > RS_PARAMS_LEN - 1) break; params += parameter + " "; @@@ -515,6 -518,86 +518,6 @@@ for (size_t i = 0; i < netRouters.size( return std::vector(); } //----------------------------------------------------------------------------- -std::string REMOTE_SCRIPT::GetUserParam(USER_PTR u, const std::string & paramName) const -{ -std::string value = ""; -if (strcasecmp(paramName.c_str(), "cash") == 0) - strprintf(&value, "%f", u->GetProperty().cash.Get()); -else -if (strcasecmp(paramName.c_str(), "freeMb") == 0) - strprintf(&value, "%f", u->GetProperty().freeMb.Get()); -else -if (strcasecmp(paramName.c_str(), "passive") == 0) - strprintf(&value, "%d", u->GetProperty().passive.Get()); -else -if (strcasecmp(paramName.c_str(), "disabled") == 0) - strprintf(&value, "%d", u->GetProperty().disabled.Get()); -else -if (strcasecmp(paramName.c_str(), "alwaysOnline") == 0) - strprintf(&value, "%d", u->GetProperty().alwaysOnline.Get()); -else -if (strcasecmp(paramName.c_str(), "tariffName") == 0 || - strcasecmp(paramName.c_str(), "tariff") == 0) - value = "\"" + u->GetProperty().tariffName.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "nextTariff") == 0) - value = "\"" + u->GetProperty().nextTariff.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "address") == 0) - value = "\"" + u->GetProperty().address.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "note") == 0) - value = "\"" + u->GetProperty().note.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "group") == 0) - value = "\"" + u->GetProperty().group.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "email") == 0) - value = "\"" + u->GetProperty().email.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "realName") == 0) - value = "\"" + u->GetProperty().realName.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "credit") == 0) - strprintf(&value, "%f", u->GetProperty().credit.Get()); -else -if (strcasecmp(paramName.c_str(), "userdata0") == 0) - value = "\"" + u->GetProperty().userdata0.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata1") == 0) - value = "\"" + u->GetProperty().userdata1.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata2") == 0) - value = "\"" + u->GetProperty().userdata2.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata3") == 0) - value = "\"" + u->GetProperty().userdata3.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata4") == 0) - value = "\"" + u->GetProperty().userdata4.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata5") == 0) - value = "\"" + u->GetProperty().userdata5.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata6") == 0) - value = "\"" + u->GetProperty().userdata6.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata7") == 0) - value = "\"" + u->GetProperty().userdata7.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata8") == 0) - value = "\"" + u->GetProperty().userdata8.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "userdata9") == 0) - value = "\"" + u->GetProperty().userdata9.Get() + "\""; -else -if (strcasecmp(paramName.c_str(), "enabledDirs") == 0) - value = u->GetEnabledDirs(); -else - printfd(__FILE__, "Unknown value name: %s\n", paramName.c_str()); -return value; -} -//----------------------------------------------------------------------------- void REMOTE_SCRIPT::SetUserNotifiers(USER_PTR u) { ipNotifierList.push_front(RS::IP_NOTIFIER(*this, u)); @@@ -546,14 -629,25 +549,25 @@@ authorizedUsers.insert(std::make_pair(u void REMOTE_SCRIPT::DelRSU(USER_PTR user) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - const std::map::iterator it( + std::map::iterator it(authorizedUsers.begin()); + while (it != authorizedUsers.end()) + { + if (it->second.user == user) + { + Send(it->second, true); + authorizedUsers.erase(it); + return; + } + ++it; + } + /*const std::map::iterator it( authorizedUsers.find(user->GetCurrIP()) ); if (it != authorizedUsers.end()) { Send(it->second, true); authorizedUsers.erase(it); - } + }*/ } //----------------------------------------------------------------------------- void RS::IP_NOTIFIER::Notify(const uint32_t & /*oldValue*/, const uint32_t & newValue) diff --combined projects/stargazer/user_impl.cpp index fff3f58d,3b2489ad..7f6ff352 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@@ -32,12 -32,9 +32,9 @@@ #define _GNU_SOURCE #endif - #include - #include // access - - #include - #include - #include + #include "user_impl.h" + #include "settings_impl.h" + #include "stg_timer.h" #include "stg/users.h" #include "stg/common.h" @@@ -45,9 -42,16 +42,16 @@@ #include "stg/tariff.h" #include "stg/tariffs.h" #include "stg/admin.h" - #include "user_impl.h" - #include "settings_impl.h" - #include "stg_timer.h" + + #include + #include + + #include + #include + #include + + #include + #include // access #ifdef USE_ABSTRACT_SETTINGS USER_IMPL::USER_IMPL(const SETTINGS * s, @@@ -60,12 -64,9 +64,9 @@@ property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), lastScanMessages(0), - login(), id(0), __connected(0), connected(__connected), - enabledDirs(), - userIDGenerator(), __currIP(0), currIP(__currIP), lastIPForDisconnect(0), @@@ -74,11 -75,8 +75,8 @@@ store(st), tariffs(t), tariff(NULL), - traffStat(), - traffStatSaved(), settings(s), - authorizedBy(), - messages(), + authorizedModificationTime(0), deleted(false), lastWriteStat(0), lastWriteDetailedStat(0), @@@ -116,14 -114,10 +114,10 @@@ userdata7(property.userdata7), userdata8(property.userdata8), userdata9(property.userdata9), - sessionUpload(), - sessionDownload(), passiveNotifier(this), tariffNotifier(this), cashNotifier(this), - ipNotifier(this), - mutex(), - errorStr() + ipNotifier(this) { password = "*_EMPTY_PASSWORD_*"; tariffName = NO_TARIFF_NAME; @@@ -153,12 -147,9 +147,9 @@@ USER_IMPL::USER_IMPL(const SETTINGS_IMP property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), lastScanMessages(0), - login(), id(0), __connected(0), connected(__connected), - enabledDirs(), - userIDGenerator(), __currIP(0), currIP(__currIP), lastIPForDisconnect(0), @@@ -167,11 -158,8 +158,8 @@@ store(st), tariffs(t), tariff(NULL), - traffStat(), - traffStatSaved(), settings(s), - authorizedBy(), - messages(), + authorizedModificationTime(0), deleted(false), lastWriteStat(0), lastWriteDetailedStat(0), @@@ -209,15 -197,11 +197,11 @@@ userdata7(property.userdata7), userdata8(property.userdata8), userdata9(property.userdata9), - sessionUpload(), - sessionDownload(), passiveNotifier(this), disabledNotifier(this), tariffNotifier(this), cashNotifier(this), - ipNotifier(this), - mutex(), - errorStr() + ipNotifier(this) { password = "*_EMPTY_PASSWORD_*"; tariffName = NO_TARIFF_NAME; @@@ -248,7 -232,6 +232,6 @@@ USER_IMPL::USER_IMPL(const USER_IMPL & id(u.id), __connected(0), connected(__connected), - enabledDirs(), userIDGenerator(u.userIDGenerator), __currIP(u.__currIP), currIP(__currIP), @@@ -261,7 -244,7 +244,7 @@@ traffStat(u.traffStat), traffStatSaved(u.traffStatSaved), settings(u.settings), - authorizedBy(), + authorizedModificationTime(u.authorizedModificationTime), messages(u.messages), deleted(u.deleted), lastWriteStat(u.lastWriteStat), @@@ -306,9 -289,7 +289,7 @@@ disabledNotifier(this), tariffNotifier(this), cashNotifier(this), - ipNotifier(this), - mutex(), - errorStr() + ipNotifier(this) { if (&u == this) return; @@@ -535,6 -516,8 +516,8 @@@ els } } + if (authorizedBy.empty()) + authorizedModificationTime = stgTime; authorizedBy.insert(auth); ScanMessage(); @@@ -542,7 -525,7 +525,7 @@@ return 0; } //----------------------------------------------------------------------------- - void USER_IMPL::Unauthorize(const AUTH * auth) + void USER_IMPL::Unauthorize(const AUTH * auth, const std::string & reason) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); /* @@@ -553,6 -536,8 +536,8 @@@ if (!authorizedBy.erase(auth) if (authorizedBy.empty()) { + authorizedModificationTime = stgTime; + lastDisconnectReason = reason; lastIPForDisconnect = currIP; currIP = 0; // DelUser in traffcounter return; @@@ -566,6 -551,13 +551,13 @@@ STG_LOCKER lock(&mutex, __FILE__, __LIN return authorizedBy.find(auth) != authorizedBy.end(); } //----------------------------------------------------------------------------- + std::vector USER_IMPL::GetAuthorizers() const + { + std::vector list; + std::transform(authorizedBy.begin(), authorizedBy.end(), std::back_inserter(list), std::mem_fun(&AUTH::GetVersion)); + return list; + } + //----------------------------------------------------------------------------- void USER_IMPL::Connect(bool fakeConnect) { /* @@@ -641,6 -633,7 +633,7 @@@ if (!lastIPForDisconnect if (!fakeDisconnect) { + lastDisconnectReason = reason; std::string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect"; if (access(scriptOnDisonnect.c_str(), X_OK) == 0) @@@ -679,7 -672,12 +672,12 @@@ connected = false; } - if (store->WriteUserDisconnect(login, up, down, sessionUpload, sessionDownload, cash, freeMb, reason)) + std::string reasonMessage(reason); + if (!lastDisconnectReason.empty()) + reasonMessage += ": " + lastDisconnectReason; + + if (store->WriteUserDisconnect(login, up, down, sessionUpload, sessionDownload, + cash, freeMb, reasonMessage)) { WriteServLog("Cannot write disconnect for user %s.", login.c_str()); WriteServLog("%s", store->GetStrError().c_str()); @@@ -823,7 -821,7 +821,7 @@@ if (settings->GetShowFeeInCash() || tar return (cash - tariff->GetFee() >= -credit); } //----------------------------------------------------------------------------- -std::string USER_IMPL::GetEnabledDirs() +std::string USER_IMPL::GetEnabledDirs() const { //STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@@ -1255,6 -1253,9 +1253,9 @@@ STG_LOCKER lock(&mutex, __FILE__, __LIN if (passive.ConstData() || tariff == NULL) return; + if (tariff->GetPeriod() != TARIFF::MONTH) + return; + double fee = tariff->GetFee() / DaysInCurrentMonth(); if (std::fabs(fee) < 1.0e-3) @@@ -1289,6 -1290,9 +1290,9 @@@ STG_LOCKER lock(&mutex, __FILE__, __LIN if (tariff == NULL) return; + if (tariff->GetPeriod() != TARIFF::MONTH) + return; + double passiveTimePart = 1.0; if (!settings->GetFullFee()) { @@@ -1350,6 -1354,39 +1354,39 @@@ switch (settings->GetFeeChargeType() } } //----------------------------------------------------------------------------- + void USER_IMPL::ProcessDailyFee() + { + STG_LOCKER lock(&mutex, __FILE__, __LINE__); + + if (passive.ConstData() || tariff == NULL) + return; + + if (tariff->GetPeriod() != TARIFF::DAY) + return; + + double fee = tariff->GetFee(); + + if (fee == 0.0) + return; + + double c = cash; + switch (settings->GetFeeChargeType()) + { + case 0: + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + case 1: + if (c + credit >= 0) + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + case 2: + if (c + credit >= fee) + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + } + ResetPassiveTime(); + } + //----------------------------------------------------------------------------- void USER_IMPL::SetPrepaidTraff() { if (tariff != NULL) @@@ -1474,22 -1511,39 +1511,22 @@@ while (it != messages.end() //----------------------------------------------------------------------------- std::string USER_IMPL::GetParamValue(const std::string & name) const { -if (name == "freeMb") return property.freeMb.ToString(); -if (name == "passive") return property.passive.ToString(); -if (name == "disabled") return property.disabled.ToString(); -if (name == "alwaysOnline") return property.alwaysOnline.ToString(); -if (name == "tariffName") return property.tariffName; -if (name == "nextTariff") return property.nextTariff; -if (name == "address") return property.address; -if (name == "note") return property.note; -if (name == "group") return property.group; -if (name == "email") return property.email; -if (name == "phone") return property.phone; -if (name == "realName") return property.realName; -if (name == "credit") return property.credit.ToString(); -if (name == "userdata0") return property.userdata0; -if (name == "userdata1") return property.userdata1; -if (name == "userdata2") return property.userdata2; -if (name == "userdata3") return property.userdata3; -if (name == "userdata4") return property.userdata4; -if (name == "userdata5") return property.userdata5; -if (name == "userdata6") return property.userdata6; -if (name == "userdata7") return property.userdata7; -if (name == "userdata8") return property.userdata8; -if (name == "userdata9") return property.userdata9; -if (name == "cash") return property.cash.ToString(); -if (name == "id") - { - std::stringstream stream; - stream << id; - return stream.str();; - } -if (name == "login") return login; -if (name == "ip") return currIP.ToString(); -return ""; + if (name == "id") + { + std::ostringstream stream; + stream << id; + return stream.str(); + } + if (name == "login") return login; + if (name == "currIP") return currIP.ToString(); + if (name == "enabledDirs") return GetEnabledDirs(); + if (property.Exists(name)) + return property.GetPropertyValue(name); + else + { + WriteServLog("User’s parameter '%s' does not exist.", name.c_str()); + return ""; + } } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --combined projects/stargazer/user_impl.h index 38d3c013,150f2a8b..5b51fc5d --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@@ -27,14 -27,7 +27,7 @@@ #ifndef USER_IMPL_H #define USER_IMPL_H - #include - #include - #include - #include - #include "stg/user.h" - #include "stg/os_int.h" - #include "stg/const.h" #include "stg/user_stat.h" #include "stg/user_conf.h" #include "stg/user_ips.h" @@@ -42,6 -35,15 +35,15 @@@ #include "stg/auth.h" #include "stg/message.h" #include "stg/noncopyable.h" + #include "stg/os_int.h" + #include "stg/const.h" + + #include + #include + #include + #include + + #include //----------------------------------------------------------------------------- class TARIFF; @@@ -182,10 -184,14 +184,14 @@@ public bool GetConnected() const { return connected; } time_t GetConnectedModificationTime() const { return connected.ModificationTime(); } + const std::string & GetLastDisconnectReason() const { return lastDisconnectReason; } int GetAuthorized() const { return static_cast(authorizedBy.size()); } + time_t GetAuthorizedModificationTime() const { return authorizedModificationTime; } int Authorize(uint32_t ip, uint32_t enabledDirs, const AUTH * auth); - void Unauthorize(const AUTH * auth); + void Unauthorize(const AUTH * auth, + const std::string & reason = std::string()); bool IsAuthorizedBy(const AUTH * auth) const; + std::vector GetAuthorizers() const; int AddMessage(STG_MSG * msg); @@@ -209,9 -215,10 +215,10 @@@ void ProcessDayFee(); void ProcessDayFeeSpread(); void ProcessNewMonth(); + void ProcessDailyFee(); bool IsInetable(); - std::string GetEnabledDirs(); + std::string GetEnabledDirs() const; void OnAdd(); void OnDelete(); @@@ -249,6 -256,7 +256,7 @@@ private USER_PROPERTY currIP; uint32_t lastIPForDisconnect; // User's ip after unauth but before disconnect + std::string lastDisconnectReason; time_t pingTime; @@@ -268,6 -276,7 +276,7 @@@ #endif std::set authorizedBy; + time_t authorizedModificationTime; std::list messages; diff --combined projects/stargazer/user_property.cpp index a94b60a4,f5f5eeea..a0c974bc --- a/projects/stargazer/user_property.cpp +++ b/projects/stargazer/user_property.cpp @@@ -3,40 -3,40 +3,39 @@@ USER_PROPERTIES::USER_PROPERTIES(const std::string & sd) : stat(), conf(), - cash (stat.cash, "cash", false, true, GetStgLogger(), sd), - up (stat.monthUp, "upload", false, true, GetStgLogger(), sd), - down (stat.monthDown, "download", false, true, GetStgLogger(), sd), - lastCashAdd (stat.lastCashAdd, "lastCashAdd", false, true, GetStgLogger(), sd), - passiveTime (stat.passiveTime, "passiveTime", false, true, GetStgLogger(), sd), - lastCashAddTime (stat.lastCashAddTime, "lastCashAddTime", false, true, GetStgLogger(), sd), - freeMb (stat.freeMb, "freeMb", false, true, GetStgLogger(), sd), - lastActivityTime(stat.lastActivityTime, "lastActivityTime", false, true, GetStgLogger(), sd), + cash (stat.cash, "cash", false, true, GetStgLogger(), sd, properties), - up (stat.up, "upload", false, true, GetStgLogger(), sd, properties), - down (stat.down, "download", false, true, GetStgLogger(), sd, properties), ++ up (stat.monthUp, "upload", false, true, GetStgLogger(), sd, properties), ++ down (stat.monthDown, "download", false, true, GetStgLogger(), sd, properties), + lastCashAdd (stat.lastCashAdd, "lastCashAdd", false, true, GetStgLogger(), sd, properties), + passiveTime (stat.passiveTime, "passiveTime", false, true, GetStgLogger(), sd, properties), + lastCashAddTime (stat.lastCashAddTime, "lastCashAddTime", false, true, GetStgLogger(), sd, properties), + freeMb (stat.freeMb, "freeMb", false, true, GetStgLogger(), sd, properties), + lastActivityTime(stat.lastActivityTime, "lastActivityTime", false, true, GetStgLogger(), sd, properties), -- - password (conf.password, "password", true, false, GetStgLogger(), sd), - passive (conf.passive, "passive", false, false, GetStgLogger(), sd), - disabled (conf.disabled, "disabled", false, false, GetStgLogger(), sd), - disabledDetailStat(conf.disabledDetailStat, "DisabledDetailStat", false, false, GetStgLogger(), sd), - alwaysOnline(conf.alwaysOnline, "alwaysOnline", false, false, GetStgLogger(), sd), - tariffName (conf.tariffName, "tariff", false, false, GetStgLogger(), sd), - nextTariff (conf.nextTariff, "new tariff", false, false, GetStgLogger(), sd), - address (conf.address, "address", false, false, GetStgLogger(), sd), - note (conf.note, "note", false, false, GetStgLogger(), sd), - group (conf.group, "group", false, false, GetStgLogger(), sd), - email (conf.email, "email", false, false, GetStgLogger(), sd), - phone (conf.phone, "phone", false, false, GetStgLogger(), sd), - realName (conf.realName, "realName", false, false, GetStgLogger(), sd), - credit (conf.credit, "credit", false, false, GetStgLogger(), sd), - creditExpire(conf.creditExpire, "creditExpire", false, false, GetStgLogger(), sd), - ips (conf.ips, "IP", false, false, GetStgLogger(), sd), - userdata0 (conf.userdata[0], "userdata0", false, false, GetStgLogger(), sd), - userdata1 (conf.userdata[1], "userdata1", false, false, GetStgLogger(), sd), - userdata2 (conf.userdata[2], "userdata2", false, false, GetStgLogger(), sd), - userdata3 (conf.userdata[3], "userdata3", false, false, GetStgLogger(), sd), - userdata4 (conf.userdata[4], "userdata4", false, false, GetStgLogger(), sd), - userdata5 (conf.userdata[5], "userdata5", false, false, GetStgLogger(), sd), - userdata6 (conf.userdata[6], "userdata6", false, false, GetStgLogger(), sd), - userdata7 (conf.userdata[7], "userdata7", false, false, GetStgLogger(), sd), - userdata8 (conf.userdata[8], "userdata8", false, false, GetStgLogger(), sd), - userdata9 (conf.userdata[9], "userdata9", false, false, GetStgLogger(), sd) + password (conf.password, "password", true, false, GetStgLogger(), sd, properties), + passive (conf.passive, "passive", false, false, GetStgLogger(), sd, properties), + disabled (conf.disabled, "disabled", false, false, GetStgLogger(), sd, properties), + disabledDetailStat(conf.disabledDetailStat, "DisabledDetailStat", false, false, GetStgLogger(), sd, properties), + alwaysOnline(conf.alwaysOnline, "alwaysOnline", false, false, GetStgLogger(), sd, properties), + tariffName (conf.tariffName, "tariff", false, false, GetStgLogger(), sd, properties), + nextTariff (conf.nextTariff, "new tariff", false, false, GetStgLogger(), sd, properties), + address (conf.address, "address", false, false, GetStgLogger(), sd, properties), + note (conf.note, "note", false, false, GetStgLogger(), sd, properties), + group (conf.group, "group", false, false, GetStgLogger(), sd, properties), + email (conf.email, "email", false, false, GetStgLogger(), sd, properties), + phone (conf.phone, "phone", false, false, GetStgLogger(), sd, properties), + realName (conf.realName, "realName", false, false, GetStgLogger(), sd, properties), + credit (conf.credit, "credit", false, false, GetStgLogger(), sd, properties), + creditExpire(conf.creditExpire, "creditExpire", false, false, GetStgLogger(), sd, properties), + ips (conf.ips, "ips", false, false, GetStgLogger(), sd, properties), + userdata0 (conf.userdata[0], "userdata0", false, false, GetStgLogger(), sd, properties), + userdata1 (conf.userdata[1], "userdata1", false, false, GetStgLogger(), sd, properties), + userdata2 (conf.userdata[2], "userdata2", false, false, GetStgLogger(), sd, properties), + userdata3 (conf.userdata[3], "userdata3", false, false, GetStgLogger(), sd, properties), + userdata4 (conf.userdata[4], "userdata4", false, false, GetStgLogger(), sd, properties), + userdata5 (conf.userdata[5], "userdata5", false, false, GetStgLogger(), sd, properties), + userdata6 (conf.userdata[6], "userdata6", false, false, GetStgLogger(), sd, properties), + userdata7 (conf.userdata[7], "userdata7", false, false, GetStgLogger(), sd, properties), + userdata8 (conf.userdata[8], "userdata8", false, false, GetStgLogger(), sd, properties), + userdata9 (conf.userdata[9], "userdata9", false, false, GetStgLogger(), sd, properties) {}