From 2529ae443070ce292250061b8cd21519ea01ebc4 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 5 Aug 2013 19:56:57 +0300 Subject: [PATCH] Added last disconnect reason and last authorization time. --- include/stg/user.h | 7 +++--- projects/stargazer/user_impl.cpp | 39 ++++++++------------------------ projects/stargazer/user_impl.h | 4 ++++ 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/include/stg/user.h b/include/stg/user.h index 0adb342a..1fa49201 100644 --- a/include/stg/user.h +++ b/include/stg/user.h @@ -74,11 +74,10 @@ 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; diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 5bb0069f..f6bf0070 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -62,12 +62,9 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), lastScanMessages(0), - login(), id(0), __connected(0), connected(__connected), - enabledDirs(), - userIDGenerator(), __currIP(0), currIP(__currIP), lastIPForDisconnect(0), @@ -76,11 +73,8 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, store(st), tariffs(t), tariff(NULL), - traffStat(), - traffStatSaved(), settings(s), - authorizedBy(), - messages(), + authorizedModificationTime(0), deleted(false), lastWriteStat(0), lastWriteDetailedStat(0), @@ -118,14 +112,10 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, 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; @@ -155,12 +145,9 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), lastScanMessages(0), - login(), id(0), __connected(0), connected(__connected), - enabledDirs(), - userIDGenerator(), __currIP(0), currIP(__currIP), lastIPForDisconnect(0), @@ -169,11 +156,8 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, store(st), tariffs(t), tariff(NULL), - traffStat(), - traffStatSaved(), settings(s), - authorizedBy(), - messages(), + authorizedModificationTime(0), deleted(false), lastWriteStat(0), lastWriteDetailedStat(0), @@ -211,15 +195,11 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, 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; @@ -250,7 +230,6 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u) id(u.id), __connected(0), connected(__connected), - enabledDirs(), userIDGenerator(u.userIDGenerator), __currIP(u.__currIP), currIP(__currIP), @@ -263,7 +242,7 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u) traffStat(u.traffStat), traffStatSaved(u.traffStatSaved), settings(u.settings), - authorizedBy(), + authorizedModificationTime(u.authorizedModificationTime), messages(u.messages), deleted(u.deleted), lastWriteStat(u.lastWriteStat), @@ -308,9 +287,7 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u) disabledNotifier(this), tariffNotifier(this), cashNotifier(this), - ipNotifier(this), - mutex(), - errorStr() + ipNotifier(this) { if (&u == this) return; @@ -537,6 +514,8 @@ else } } +if (authorizedBy.empty()) + authorizedModificationTime = stgTime; authorizedBy.insert(auth); ScanMessage(); @@ -555,6 +534,7 @@ if (!authorizedBy.erase(auth)) if (authorizedBy.empty()) { + authorizedModificationTime = stgTime; lastIPForDisconnect = currIP; currIP = 0; // DelUser in traffcounter return; @@ -642,6 +622,7 @@ if (!lastIPForDisconnect) if (!fakeDisconnect) { + lastDisconnectReason = reason; std::string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect"; if (access(scriptOnDisonnect.c_str(), X_OK) == 0) diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index a581f2e5..412816c3 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -183,7 +183,9 @@ 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; @@ -240,6 +242,7 @@ private: int id; bool __connected; USER_PROPERTY connected; + std::string lastDisconnectReason; bool enabledDirs[DIR_NUM]; @@ -268,6 +271,7 @@ private: #endif std::set authorizedBy; + time_t authorizedModificationTime; std::list messages; -- 2.44.2