From: Maxim Mamontov Date: Fri, 23 Aug 2013 18:59:58 +0000 (+0300) Subject: Merge branch 'naffanya-dev' X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/e9cb0683c0b33d8458c1d9b2558bbeb5d101e680?ds=inline;hp=-c Merge branch 'naffanya-dev' --- e9cb0683c0b33d8458c1d9b2558bbeb5d101e680 diff --combined include/stg/user.h index 44d3e5b2,365c71ef..a8f61105 --- a/include/stg/user.h +++ b/include/stg/user.h @@@ -21,16 -21,14 +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; @@@ -73,12 -71,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; @@@ -102,6 -100,8 +102,8 @@@ virtual void OnAdd() = 0; virtual void OnDelete() = 0; + + virtual std::string GetParamValue(const std::string & name) const = 0; }; typedef USER * USER_PTR; diff --combined include/stg/users.h index 19a9d7b7,ed9af901..a1d5d295 --- a/include/stg/users.h +++ b/include/stg/users.h @@@ -32,7 -32,6 +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; @@@ -54,7 -53,6 +54,7 @@@ 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; @@@ -62,6 -60,7 +62,7 @@@ virtual int Start() = 0; virtual int Stop() = 0; + }; #endif diff --combined projects/stargazer/main.cpp index 11fad552,b7bb91f5..7cc8eccc --- 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,6 @@@ 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 --combined projects/stargazer/user_impl.cpp index 4f216b06,52731b7b..13cf0b77 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@@ -32,9 -32,12 +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" @@@ -42,16 -45,9 +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, @@@ -64,9 -60,12 +64,9 @@@ property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), lastScanMessages(0), - login(), id(0), __connected(0), connected(__connected), - enabledDirs(), - userIDGenerator(), __currIP(0), currIP(__currIP), lastIPForDisconnect(0), @@@ -75,8 -74,11 +75,8 @@@ store(st), tariffs(t), tariff(NULL), - traffStat(), - traffStatSaved(), settings(s), - authorizedBy(), - messages(), + authorizedModificationTime(0), deleted(false), lastWriteStat(0), lastWriteDetailedStat(0), @@@ -114,10 -116,14 +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; @@@ -147,9 -153,12 +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), @@@ -158,8 -167,11 +158,8 @@@ store(st), tariffs(t), tariff(NULL), - traffStat(), - traffStatSaved(), settings(s), - authorizedBy(), - messages(), + authorizedModificationTime(0), deleted(false), lastWriteStat(0), lastWriteDetailedStat(0), @@@ -197,11 -209,15 +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; @@@ -232,6 -248,7 +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), @@@ -244,7 -261,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), @@@ -289,7 -306,9 +289,7 @@@ disabledNotifier(this), tariffNotifier(this), cashNotifier(this), - ipNotifier(this), - mutex(), - errorStr() + ipNotifier(this) { if (&u == this) return; @@@ -516,8 -535,6 +516,8 @@@ els } } +if (authorizedBy.empty()) + authorizedModificationTime = stgTime; authorizedBy.insert(auth); ScanMessage(); @@@ -536,7 -553,6 +536,7 @@@ if (!authorizedBy.erase(auth) if (authorizedBy.empty()) { + authorizedModificationTime = stgTime; lastIPForDisconnect = currIP; currIP = 0; // DelUser in traffcounter return; @@@ -550,13 -566,6 +550,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) { /* @@@ -579,6 -588,7 +579,7 @@@ if (!fakeConnect } std::string scriptOnConnectParams; + strprintf(&scriptOnConnectParams, "%s \"%s\" \"%s\" \"%f\" \"%d\" \"%s\"", scriptOnConnect.c_str(), @@@ -588,6 -598,13 +589,13 @@@ id, dirsStr); + std::vector::const_iterator it(settings->GetScriptParams().begin()); + while (it != settings->GetScriptParams().end()) + { + scriptOnConnectParams += " \"" + GetParamValue(it->c_str()) + "\""; + ++it; + } + ScriptExec(scriptOnConnectParams.c_str()); } else @@@ -624,7 -641,6 +632,7 @@@ if (!lastIPForDisconnect if (!fakeDisconnect) { + lastDisconnectReason = reason; std::string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect"; if (access(scriptOnDisonnect.c_str(), X_OK) == 0) @@@ -646,6 -662,13 +654,13 @@@ id, dirsStr); + std::vector::const_iterator it(settings->GetScriptParams().begin()); + while (it != settings->GetScriptParams().end()) + { + scriptOnDisonnectParams += " \"" + GetParamValue(it->c_str()) + "\""; + ++it; + } + ScriptExec(scriptOnDisonnectParams.c_str()); } else @@@ -1449,6 -1472,43 +1464,43 @@@ 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 ""; + } + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CHG_PASSIVE_NOTIFIER::Notify(const int & oldPassive, const int & newPassive) diff --combined projects/stargazer/user_impl.h index 96317f06,d240f0c8..26ff58fc --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@@ -27,7 -27,14 +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" @@@ -35,15 -42,6 +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; @@@ -184,13 -182,10 +184,13 @@@ 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); bool IsAuthorizedBy(const AUTH * auth) const; + std::vector GetAuthorizers() const; int AddMessage(STG_MSG * msg); @@@ -221,6 -216,8 +221,8 @@@ void OnAdd(); void OnDelete(); + virtual std::string GetParamValue(const std::string & name) const; + private: USER_IMPL & operator=(const USER_IMPL & rvalue); @@@ -243,7 -240,6 +245,7 @@@ int id; bool __connected; USER_PROPERTY connected; + std::string lastDisconnectReason; bool enabledDirs[DIR_NUM]; @@@ -272,7 -268,6 +274,7 @@@ #endif std::set authorizedBy; + time_t authorizedModificationTime; std::list messages;