]> git.stg.codes - stg.git/commitdiff
Merge branch 'stg-2.409'
authorMaxim Mamontov <faust.madf@gmail.com>
Sat, 17 Sep 2016 13:03:04 +0000 (16:03 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Sat, 17 Sep 2016 13:03:04 +0000 (16:03 +0300)
1  2 
projects/stargazer/inst/freebsd/etc/stargazer/stargazer.conf
projects/stargazer/inst/linux/etc/stargazer/stargazer.conf
projects/stargazer/settings_impl.cpp
projects/stargazer/settings_impl.h
projects/stargazer/user_impl.cpp

index 84d14f608668895a2ad658fb07db7dd92bdbbe33,c1f4fe929bfcb2deae10b5eab7f4c763ea12d067..bb8ee7c47e4ec7f3ada0ec6fee5f9dff8a6db6e4
@@@ -41,12 -41,6 +41,12 @@@ StatWritePeriod = 1
  # Default: 1
  DayFee = 1
  
 +# When set to 'no' Stargazer will continue reading database after error and show all of them.
 +# Parameter: optional
 +# Values: yes, no
 +# Default: yes
 +# StopOnError = yes
 +
  # Fee charged at the last (yes) or first (no) day of tariffication period.
  # Defines how the fee will be charged in the transition to the new tariff.
  # User has tariff A with fee 100. Changing it to tariff B with fee 200
@@@ -177,6 -171,38 +177,38 @@@ ModulesPath = /usr/lib/st
  # Default: no
  # ReconnectOnTariffChange = no
  
+ # Definest set of parameters passed to OnConnect and OnDisconnect scripts
+ # This set is added to the end of the default param list, which are, respectively:
+ # login, ip, cash, id, dirs
+ # Valid parameter names: "cash", "upload", "download", "lastCashAdd", "passiveTime",
+ # "lastCashAddTime", "freeMb", "lastActivityTime", "password", "passive", "disabled",
+ # "disabledDetailStat", "alwaysOnline", "tariffName", "nextTariff", "address",
+ # "note", "group", "email", "phone", "realName", "credit", "creditExpire", "ips",
+ # "userdata0" ... "userdata9".
+ # Parameter: optional
+ # Values: parameter names, case insensitive
+ # Default:
+ # ScriptParams =
+ # Enable or disable writing session log
+ # Parameter: optional
+ # Values: yes, no
+ # Default: no (session log is enabled)
+ # DisableSessionLog = no
+ # Filter for logging parameter changes
+ # Defines which parameters will be logged to parameter log in database. Allows
+ # to specify multiuple parameter names or asterisk (*), which means "log all params".
+ # Valid parameter names: "cash", "upload", "download", "lastCashAdd", "passiveTime",
+ # "lastCashAddTime", "freeMb", "lastActivityTime", "password", "passive", "disabled",
+ # "disabledDetailStat", "alwaysOnline", "tariffName", "nextTariff", "address",
+ # "note", "group", "email", "phone", "realName", "credit", "creditExpire", "ips",
+ # "userdata0" ... "userdata9".
+ # Parameter: optional
+ # Values: parameter names, case insensitive, or "*"
+ # Default: *
+ # FilterParamsLog = *
  ################################################################################
  # Store module
  # Configure the module that works with the database server
index 84d14f608668895a2ad658fb07db7dd92bdbbe33,c1f4fe929bfcb2deae10b5eab7f4c763ea12d067..bb8ee7c47e4ec7f3ada0ec6fee5f9dff8a6db6e4
@@@ -41,12 -41,6 +41,12 @@@ StatWritePeriod = 1
  # Default: 1
  DayFee = 1
  
 +# When set to 'no' Stargazer will continue reading database after error and show all of them.
 +# Parameter: optional
 +# Values: yes, no
 +# Default: yes
 +# StopOnError = yes
 +
  # Fee charged at the last (yes) or first (no) day of tariffication period.
  # Defines how the fee will be charged in the transition to the new tariff.
  # User has tariff A with fee 100. Changing it to tariff B with fee 200
@@@ -177,6 -171,38 +177,38 @@@ ModulesPath = /usr/lib/st
  # Default: no
  # ReconnectOnTariffChange = no
  
+ # Definest set of parameters passed to OnConnect and OnDisconnect scripts
+ # This set is added to the end of the default param list, which are, respectively:
+ # login, ip, cash, id, dirs
+ # Valid parameter names: "cash", "upload", "download", "lastCashAdd", "passiveTime",
+ # "lastCashAddTime", "freeMb", "lastActivityTime", "password", "passive", "disabled",
+ # "disabledDetailStat", "alwaysOnline", "tariffName", "nextTariff", "address",
+ # "note", "group", "email", "phone", "realName", "credit", "creditExpire", "ips",
+ # "userdata0" ... "userdata9".
+ # Parameter: optional
+ # Values: parameter names, case insensitive
+ # Default:
+ # ScriptParams =
+ # Enable or disable writing session log
+ # Parameter: optional
+ # Values: yes, no
+ # Default: no (session log is enabled)
+ # DisableSessionLog = no
+ # Filter for logging parameter changes
+ # Defines which parameters will be logged to parameter log in database. Allows
+ # to specify multiuple parameter names or asterisk (*), which means "log all params".
+ # Valid parameter names: "cash", "upload", "download", "lastCashAdd", "passiveTime",
+ # "lastCashAddTime", "freeMb", "lastActivityTime", "password", "passive", "disabled",
+ # "disabledDetailStat", "alwaysOnline", "tariffName", "nextTariff", "address",
+ # "note", "group", "email", "phone", "realName", "credit", "creditExpire", "ips",
+ # "userdata0" ... "userdata9".
+ # Parameter: optional
+ # Values: parameter names, case insensitive, or "*"
+ # Default: *
+ # FilterParamsLog = *
  ################################################################################
  # Store module
  # Configure the module that works with the database server
index fa7402ede625a934ce1f181491fbb06e4a135192,0cf9501bced5db222ec6413721f9cf70f1b51a6d..212ed6343c95bd8e289c044501b3c9dbfd37e539
@@@ -57,18 -57,21 +57,20 @@@ SETTINGS_IMPL::SETTINGS_IMPL(const std:
        spreadFee(false),
        freeMbAllowInet(false),
        dayFeeIsLastDay(false),
 +      stopOnError(true),
        writeFreeMbTraffCost(false),
        showFeeInCash(true),
        messageTimeout(0),
        feeChargeType(0),
        reconnectOnTariffChange(false),
+       disableSessionLog(false),
        logger(GetStgLogger())
  {
+     filterParamsLog.push_back("*");
  }
  //-----------------------------------------------------------------------------
  SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval)
 -    : SETTINGS(),
 -      strError(),
 -      modulesPath(rval.modulesPath),
 +    : modulesPath(rval.modulesPath),
        dirName(rval.dirName),
        confDir(rval.confDir),
        scriptsDir(rval.scriptsDir),
        spreadFee(rval.spreadFee),
        freeMbAllowInet(rval.freeMbAllowInet),
        dayFeeIsLastDay(rval.dayFeeIsLastDay),
 +      stopOnError(rval.stopOnError),
        writeFreeMbTraffCost(rval.writeFreeMbTraffCost),
        showFeeInCash(rval.showFeeInCash),
        messageTimeout(rval.messageTimeout),
        feeChargeType(rval.feeChargeType),
        reconnectOnTariffChange(rval.reconnectOnTariffChange),
+       disableSessionLog(rval.disableSessionLog),
+       filterParamsLog(rval.filterParamsLog),
        modulesSettings(rval.modulesSettings),
        storeModuleSettings(rval.storeModuleSettings),
        logger(GetStgLogger())
@@@ -121,12 -125,13 +125,14 @@@ SETTINGS_IMPL & SETTINGS_IMPL::operator
      spreadFee = rhs.spreadFee;
      freeMbAllowInet = rhs.freeMbAllowInet;
      dayFeeIsLastDay = rhs.dayFeeIsLastDay;
 +    stopOnError = rhs.stopOnError;
      writeFreeMbTraffCost = rhs.writeFreeMbTraffCost;
      showFeeInCash = rhs.showFeeInCash;
      messageTimeout = rhs.messageTimeout;
      feeChargeType = rhs.feeChargeType;
      reconnectOnTariffChange = rhs.reconnectOnTariffChange;
+     disableSessionLog = rhs.disableSessionLog;
+     filterParamsLog = rhs.filterParamsLog;
  
      modulesSettings = rhs.modulesSettings;
      storeModuleSettings = rhs.storeModuleSettings;
@@@ -329,15 -334,6 +335,15 @@@ while (node
              }
          }
  
 +    if (strcasecmp(node->getName(), "StopOnError") == 0)
 +        {
 +        if (ParseYesNo(node->getValue(0), &stopOnError) != 0)
 +            {
 +            strError = "Incorrect StopOnError value: \'" + std::string(node->getValue(0)) + "\'";
 +            return -1;
 +            }
 +        }
 +
      if (strcasecmp(node->getName(), "WriteFreeMbTraffCost") == 0)
          {
          if (ParseYesNo(node->getValue(0), &writeFreeMbTraffCost) != 0)
              }
          }
  
+     if (strcasecmp(node->getName(), "DisableSessionLog") == 0)
+         {
+         if (ParseYesNo(node->getValue(0), &disableSessionLog) != 0)
+             {
+             strError = "Incorrect DisableSessionLog value: \'" + std::string(node->getValue(0)) + "\'";
+             return -1;
+             }
+         }
+     if (strcasecmp(node->getName(), "FilterParamsLog") == 0)
+         {
+         filterParamsLog.clear();
+         for (int i = 0; node->getValue(i) != NULL; ++i)
+             filterParamsLog.push_back(node->getValue(i));
+         }
      if (strcasecmp(node->getName(), "DirNames") == 0)
          {
          const DOTCONFDocumentNode * child = node->getChildNode();
      if (strcasecmp(node->getName(), "ScriptParams") == 0)
          {
          for (int i = 0; node->getValue(i) != NULL; ++i)
-             {
              scriptParams.push_back(node->getValue(i));
-             }
          }
      node = node->getNextNode();
      }
index 20d82869983fc78e1871814645eec496d874a169,cc35393b2d18fab8d21cc705f3d1687fa031f43c..de27b72884a8a46d5a3bceca78503f5bac3923f5
@@@ -84,7 -84,6 +84,7 @@@ public
      bool                GetSpreadFee() const { return spreadFee; }
      bool                GetFreeMbAllowInet() const { return freeMbAllowInet; }
      bool                GetDayFeeIsLastDay() const { return dayFeeIsLastDay; }
 +    bool                GetStopOnError() const { return stopOnError; }
      bool                GetWriteFreeMbTraffCost() const
          { return writeFreeMbTraffCost; }
      bool                GetShowFeeInCash() const { return showFeeInCash; }
@@@ -93,6 -92,8 +93,8 @@@
      unsigned            GetMessageTimeout() const { return messageTimeout * 3600 * 24; }
      unsigned            GetFeeChargeType() const { return feeChargeType; }
      bool                GetReconnectOnTariffChange() const { return reconnectOnTariffChange; }
+     bool                GetDisableSessionLog() const { return disableSessionLog; }
+     const std::vector<std::string> & GetFilterParamsLog() const { return filterParamsLog; }
  
      const std::string & GetModulesPath() const { return modulesPath; }
      const MODULE_SETTINGS & GetStoreModuleSettings() const
@@@ -131,12 -132,13 +133,14 @@@ private
      bool        spreadFee;
      bool        freeMbAllowInet;
      bool        dayFeeIsLastDay;
 +    bool        stopOnError;
      bool        writeFreeMbTraffCost;
      bool        showFeeInCash;
      unsigned    messageTimeout;
      unsigned    feeChargeType;
      bool        reconnectOnTariffChange;
+     bool        disableSessionLog;
+     std::vector<std::string> filterParamsLog;
  
      std::vector<MODULE_SETTINGS> modulesSettings;
      MODULE_SETTINGS storeModuleSettings;
index fe197cc5f9bec5c29d4d175ba21f08856b51e7d8,55a0b197968756d7addf7eb6e8e2be0aad686ba0..c160db75cb8a39ec8fd402a076fefe41d504780c
@@@ -80,7 -80,7 +80,7 @@@ USER_IMPL::USER_IMPL(const SETTINGS * s
             const USERS * u,
             const SERVICES & svcs)
      : users(u),
-       property(s->GetScriptsDir()),
+       property(*s),
        WriteServLog(GetStgLogger()),
        lastScanMessages(0),
        id(0),
@@@ -150,7 -150,7 +150,7 @@@ USER_IMPL::USER_IMPL(const SETTINGS_IMP
                       const USERS * u,
                       const SERVICES & svcs)
      : users(u),
-       property(s->GetScriptsDir()),
+       property(*s),
        WriteServLog(GetStgLogger()),
        lastScanMessages(0),
        id(0),
@@@ -237,7 -237,7 +237,7 @@@ pthread_mutex_init(&mutex, &attr)
  USER_IMPL::USER_IMPL(const USER_IMPL & u)
      : USER(),
        users(u.users),
-       property(u.settings->GetScriptsDir()),
+       property(*u.settings),
        WriteServLog(GetStgLogger()),
        lastScanMessages(0),
        login(u.login),
@@@ -621,7 -621,7 +621,7 @@@ if (!fakeConnect
      connected = true;
      }
  
- if (store->WriteUserConnect(login, currIP))
+ if (!settings->GetDisableSessionLog() && store->WriteUserConnect(login, currIP))
      {
      WriteServLog("Cannot write connect for user %s.", login.c_str());
      WriteServLog("%s", store->GetStrError().c_str());
@@@ -685,8 -685,8 +685,8 @@@ std::string reasonMessage(reason)
  if (!lastDisconnectReason.empty())
      reasonMessage += ": " + lastDisconnectReason;
  
- if (store->WriteUserDisconnect(login, up, down, sessionUpload, sessionDownload,
-                                cash, freeMb, reasonMessage))
+ if (!settings->GetDisableSessionLog() && 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());
@@@ -1328,75 -1328,6 +1328,75 @@@ switch (settings->GetFeeChargeType()
  ResetPassiveTime();
  }
  //-----------------------------------------------------------------------------
 +void USER_IMPL::ProcessServices()
 +{
 +struct tm tms;
 +time_t t = stgTime;
 +localtime_r(&t, &tms);
 +
 +double passiveTimePart = 1.0;
 +if (!settings->GetFullFee())
 +    {
 +    passiveTimePart = GetPassiveTimePart();
 +    }
 +else
 +    {
 +    if (passive.ConstData())
 +        {
 +        printfd(__FILE__, "Don't charge fee `cause we are passive\n");
 +        return;
 +        }
 +    }
 +
 +for (size_t i = 0; i < property.Conf().services.size(); ++i)
 +    {
 +    SERVICE_CONF conf;
 +    if (m_services.Find(property.Conf().services[i], &conf))
 +        continue;
 +    if (conf.payDay == tms.tm_mday ||
 +        (conf.payDay == 0 && tms.tm_mday == DaysInCurrentMonth()))
 +        {
 +        double c = cash;
 +        double fee = conf.cost * passiveTimePart;
 +        printfd(__FILE__, "Service fee. login: %8s Cash=%f Credit=%f  Fee=%f PassiveTimePart=%f fee=%f\n",
 +                login.c_str(),
 +                cash.ConstData(),
 +                credit.ConstData(),
 +                tariff->GetFee(),
 +                passiveTimePart,
 +                fee);
 +        switch (settings->GetFeeChargeType())
 +            {
 +            case 0:
 +                property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
 +                SetPrepaidTraff();
 +                break;
 +            case 1:
 +                if (c + credit >= 0)
 +                    {
 +                    property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
 +                    SetPrepaidTraff();
 +                    }
 +                break;
 +            case 2:
 +                if (c + credit >= fee)
 +                    {
 +                    property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
 +                    SetPrepaidTraff();
 +                    }
 +                break;
 +            case 3:
 +                if (c >= 0)
 +                    {
 +                    property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
 +                    SetPrepaidTraff();
 +                    }
 +                break;
 +            }
 +        }
 +    }
 +}
 +//-----------------------------------------------------------------------------
  void USER_IMPL::SetPrepaidTraff()
  {
  if (tariff != NULL)