From: Maxim Mamontov Date: Sun, 8 Jun 2014 19:06:32 +0000 (+0300) Subject: Merge branch 'naffanya-dev' X-Git-Tag: 2.409~312 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/258b7ce79dba0c01b378e73bd6b8ee9fb1ae695d Merge branch 'naffanya-dev' --- diff --git a/include/stg/user.h b/include/stg/user.h index a8f61105..8dc761e3 100644 --- a/include/stg/user.h +++ b/include/stg/user.h @@ -98,7 +98,7 @@ public: 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 --git a/include/stg/user_property.h b/include/stg/user_property.h index 1716296a..97c1af51 100644 --- a/include/stg/user_property.h +++ b/include/stg/user_property.h @@ -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" @@ -25,10 +27,16 @@ $Author: faust $ #include "noncopyable.h" extern volatile time_t stgTime; - +//----------------------------------------------------------------------------- +class USER_PROPERTY_BASE { +public: + virtual std::string ToString() const = 0; +}; +//----------------------------------------------------------------------------- +typedef std::map REGISTRY; //----------------------------------------------------------------------------- template -class USER_PROPERTY { +class USER_PROPERTY : public USER_PROPERTY_BASE { public: USER_PROPERTY(varT & val); virtual ~USER_PROPERTY(); @@ -68,7 +76,8 @@ public: bool isPassword, bool isStat, STG_LOGGER & logger, - const std::string & sd); + const std::string & sd, + REGISTRY & properties); virtual ~USER_PROPERTY_LOGGED() {} USER_PROPERTY_LOGGED * GetPointer() throw() { return this; } @@ -118,6 +127,7 @@ private: USER_STAT stat; USER_CONF conf; + REGISTRY properties; public: USER_PROPERTIES(const std::string & sd); @@ -130,6 +140,9 @@ public: 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; @@ -268,7 +281,8 @@ USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, bool isPass, bool isSt, STG_LOGGER & logger, - const std::string & sd) + const std::string & sd, + REGISTRY & properties) : USER_PROPERTY(val), stgLogger(logger), @@ -277,6 +291,7 @@ USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, name(n), scriptsDir(sd) { +properties.insert(std::make_pair(ToLower(name), this)); } //------------------------------------------------------------------------- template @@ -376,6 +391,23 @@ else //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- +inline +std::string USER_PROPERTIES::GetPropertyValue(const std::string & name) const +{ +REGISTRY::const_iterator it = properties.find(ToLower(name)); +if (it == properties.end()) + return ""; +return it->second->ToString(); +} +//----------------------------------------------------------------------------- +inline +bool USER_PROPERTIES::Exists(const std::string & name) const +{ +return properties.find(ToLower(name)) != properties.end(); +} +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- template inline std::ostream & operator<< (std::ostream & stream, const USER_PROPERTY & value) @@ -384,9 +416,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 --git a/include/stg/users.h b/include/stg/users.h index 1a8d7a43..9f516aef 100644 --- a/include/stg/users.h +++ b/include/stg/users.h @@ -64,7 +64,6 @@ public: virtual int Start() = 0; virtual int Stop() = 0; - }; #endif diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 1e4c677e..200fd2a6 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -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 diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 3bc90792..e781a8cb 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -429,9 +429,12 @@ for(it = rsSettings.GetUserParams().begin(); 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) + { + logger("Script params string length %d exceeds the limit of %d symbols.", params.length() + parameter.length(), RS_PARAMS_LEN); break; + } params += parameter + " "; } strncpy((char *)packetTail.params, params.c_str(), RS_PARAMS_LEN); @@ -518,86 +521,6 @@ for (size_t i = 0; i < netRouters.size(); ++i) 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)); diff --git a/projects/stargazer/plugins/other/rscript/rscript.h b/projects/stargazer/plugins/other/rscript/rscript.h index 8d22b458..bc6aa92f 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.h +++ b/projects/stargazer/plugins/other/rscript/rscript.h @@ -213,7 +213,6 @@ private: std::vector IP2Routers(uint32_t ip); bool GetUsers(); - std::string GetUserParam(USER_PTR u, const std::string & paramName) const; void SetUserNotifiers(USER_PTR u); void UnSetUserNotifiers(USER_PTR u); diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 3b2489ad..47f35228 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -821,7 +821,7 @@ if (settings->GetShowFeeInCash() || tariff == NULL) return (cash - tariff->GetFee() >= -credit); } //----------------------------------------------------------------------------- -std::string USER_IMPL::GetEnabledDirs() +std::string USER_IMPL::GetEnabledDirs() const { //STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -1511,39 +1511,24 @@ 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 ""; + std::string lowerName = ToLower(name); + if (lowerName == "id") + { + std::ostringstream stream; + stream << id; + return stream.str(); + } + if (lowerName == "login") return login; + if (lowerName == "currip") return currIP.ToString(); + if (lowerName == "enableddirs") return GetEnabledDirs(); + if (lowerName == "tariff") return property.tariffName; + if (property.Exists(lowerName)) + return property.GetPropertyValue(lowerName); + else + { + WriteServLog("User’s parameter '%s' does not exist.", name.c_str()); + return ""; + } } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index 150f2a8b..5b51fc5d 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -218,7 +218,7 @@ public: void ProcessDailyFee(); bool IsInetable(); - std::string GetEnabledDirs(); + std::string GetEnabledDirs() const; void OnAdd(); void OnDelete(); diff --git a/projects/stargazer/user_property.cpp b/projects/stargazer/user_property.cpp index f5f5eeea..c8b58917 100644 --- a/projects/stargazer/user_property.cpp +++ b/projects/stargazer/user_property.cpp @@ -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.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, "tariffName", false, false, GetStgLogger(), sd, properties), + nextTariff (conf.nextTariff, "nextTariff", 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) {}