]> git.stg.codes - stg.git/commitdiff
Merge branch 'naffanya-dev'
authorMaxim Mamontov <faust@stg.dp.ua>
Fri, 23 Aug 2013 18:59:58 +0000 (21:59 +0300)
committerMaxim Mamontov <faust@stg.dp.ua>
Fri, 23 Aug 2013 18:59:58 +0000 (21:59 +0300)
1  2 
include/stg/user.h
include/stg/users.h
projects/stargazer/main.cpp
projects/stargazer/user_impl.cpp
projects/stargazer/user_impl.h

diff --combined include/stg/user.h
index 44d3e5b2293988020425518bcceaabd5ef84a7b2,365c71ef1f0c53567e251e95c1dfe5da707f9f28..a8f61105ec3adb3e04cf64be201615703d2d2189
  #ifndef USER_H
  #define USER_H
  
 -#include <ctime>
 -#include <string>
 -
 -#include "os_int.h"
  #include "notifer.h"
  #include "message.h"
  #include "tariff.h"
  #include "user_traff.h"
 +#include "os_int.h"
 +
 +#include <vector>
 +#include <string>
 +
 +#include <ctime>
  
  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<std::string> GetAuthorizers() const = 0;
  
      virtual int                 AddMessage(STG_MSG * msg) = 0;
  
  
      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 19a9d7b7446a8b01cc647b8ad7b63a496ddbd59e,ed9af90172639606c22a6a6566992fcdfd410862..a1d5d295ced2f91adaac53ac95589e5c5c1ad42f
@@@ -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
index 11fad552504730f7aa5b86b837fd4ca070c2b468,b7bb91f58b08c9382b79310b2f6431f76294c539..7cc8eccc6e54c32f7ead49ad48bd01357b7d88bf
@@@ -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);
  
      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
index 4f216b06e561674dc8f96c5d570e61ba7ef7f988,52731b7bd8581f4a593d87f5daadb60f1180fea2..13cf0b77dc87cd4c1337c6cefc530db7e728572a
  #define _GNU_SOURCE
  #endif
  
 -#include <pthread.h>
 -#include <unistd.h> // access
 -
 -#include <cassert>
 -#include <cstdlib>
 -#include <cmath>
 +#include "user_impl.h"
 +#include "settings_impl.h"
 +#include "stg_timer.h"
  
  #include "stg/users.h"
  #include "stg/common.h"
  #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 <algorithm>
 +#include <functional>
 +
 +#include <cassert>
 +#include <cstdlib>
 +#include <cmath>
 +
 +#include <pthread.h>
 +#include <unistd.h> // access
  
  #ifdef USE_ABSTRACT_SETTINGS
  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),
        store(st),
        tariffs(t),
        tariff(NULL),
 -      traffStat(),
 -      traffStatSaved(),
        settings(s),
 -      authorizedBy(),
 -      messages(),
 +      authorizedModificationTime(0),
        deleted(false),
        lastWriteStat(0),
        lastWriteDetailedStat(0),
        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),
        store(st),
        tariffs(t),
        tariff(NULL),
 -      traffStat(),
 -      traffStatSaved(),
        settings(s),
 -      authorizedBy(),
 -      messages(),
 +      authorizedModificationTime(0),
        deleted(false),
        lastWriteStat(0),
        lastWriteDetailedStat(0),
        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),
        traffStat(u.traffStat),
        traffStatSaved(u.traffStatSaved),
        settings(u.settings),
 -      authorizedBy(),
 +      authorizedModificationTime(u.authorizedModificationTime),
        messages(u.messages),
        deleted(u.deleted),
        lastWriteStat(u.lastWriteStat),
        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<std::string> USER_IMPL::GetAuthorizers() const
 +{
 +    std::vector<std::string> 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(),
                  id,
                  dirsStr);
  
+         std::vector<std::string>::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)
                  id,
                  dirsStr);
  
+         std::vector<std::string>::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)
index 96317f06f369181d7317f2341cfc14c7a3f7a580,d240f0c8c161ae85a42ddcd2d3fee522fe803181..26ff58fc2b8d902f093739e4cc867f1670a43794
  #ifndef USER_IMPL_H
  #define USER_IMPL_H
  
 -#include <ctime>
 -#include <list>
 -#include <string>
 -#include <set>
 -
  #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"
  #include "stg/auth.h"
  #include "stg/message.h"
  #include "stg/noncopyable.h"
 +#include "stg/os_int.h"
 +#include "stg/const.h"
 +
 +#include <list>
 +#include <vector>
 +#include <string>
 +#include <set>
 +
 +#include <ctime>
  
  //-----------------------------------------------------------------------------
  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<int>(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<std::string> GetAuthorizers() const;
  
      int             AddMessage(STG_MSG * msg);
  
      void            OnAdd();
      void            OnDelete();
  
+     virtual std::string GetParamValue(const std::string & name) const;
  private:
      USER_IMPL & operator=(const USER_IMPL & rvalue);
  
      int             id;
      bool            __connected;
      USER_PROPERTY<bool> connected;
 +    std::string     lastDisconnectReason;
  
      bool            enabledDirs[DIR_NUM];
  
  #endif
  
      std::set<const AUTH *> authorizedBy;
 +    time_t          authorizedModificationTime;
  
      std::list<STG_MSG> messages;