]> git.stg.codes - stg.git/blobdiff - projects/stargazer/user_impl.cpp
Merge branch 'stg-2.409' into stg-2.409-radius
[stg.git] / projects / stargazer / user_impl.cpp
index 55a0b197968756d7addf7eb6e8e2be0aad686ba0..d530108b95e7f225b42e32ce544662559aba6ac3 100644 (file)
@@ -134,6 +134,8 @@ USER_IMPL::USER_IMPL(const SETTINGS * s,
       userdata7(property.userdata7),
       userdata8(property.userdata8),
       userdata9(property.userdata9),
       userdata7(property.userdata7),
       userdata8(property.userdata8),
       userdata9(property.userdata9),
+      sessionUploadModTime(stgTime),
+      sessionDownloadModTime(stgTime),
       passiveNotifier(this),
       disabledNotifier(this),
       tariffNotifier(this),
       passiveNotifier(this),
       disabledNotifier(this),
       tariffNotifier(this),
@@ -204,6 +206,8 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s,
       userdata7(property.userdata7),
       userdata8(property.userdata8),
       userdata9(property.userdata9),
       userdata7(property.userdata7),
       userdata8(property.userdata8),
       userdata9(property.userdata9),
+      sessionUploadModTime(stgTime),
+      sessionDownloadModTime(stgTime),
       passiveNotifier(this),
       disabledNotifier(this),
       tariffNotifier(this),
       passiveNotifier(this),
       disabledNotifier(this),
       tariffNotifier(this),
@@ -218,6 +222,7 @@ void USER_IMPL::Init()
 {
 password = "*_EMPTY_PASSWORD_*";
 tariffName = NO_TARIFF_NAME;
 {
 password = "*_EMPTY_PASSWORD_*";
 tariffName = NO_TARIFF_NAME;
+tariff = tariffs->FindByName(tariffName);
 ips = StrToIPS("*");
 lastWriteStat = stgTime + random() % settings->GetStatWritePeriod();
 lastWriteDetailedStat = stgTime;
 ips = StrToIPS("*");
 lastWriteStat = stgTime + random() % settings->GetStatWritePeriod();
 lastWriteDetailedStat = stgTime;
@@ -298,6 +303,8 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u)
       userdata9(property.userdata9),
       sessionUpload(),
       sessionDownload(),
       userdata9(property.userdata9),
       sessionUpload(),
       sessionDownload(),
+      sessionUploadModTime(stgTime),
+      sessionDownloadModTime(stgTime),
       passiveNotifier(this),
       disabledNotifier(this),
       tariffNotifier(this),
       passiveNotifier(this),
       disabledNotifier(this),
       tariffNotifier(this),
@@ -1178,10 +1185,24 @@ if (nextTariff.ConstData() != "")
     {
     const TARIFF * nt = tariffs->FindByName(nextTariff);
     if (nt == NULL)
     {
     const TARIFF * nt = tariffs->FindByName(nextTariff);
     if (nt == NULL)
+        {
         WriteServLog("Cannot change tariff for user %s. Tariff %s not exist.",
                      login.c_str(), property.tariffName.Get().c_str());
         WriteServLog("Cannot change tariff for user %s. Tariff %s not exist.",
                      login.c_str(), property.tariffName.Get().c_str());
+        }
     else
     else
-        property.tariffName.Set(nextTariff, sysAdmin, login, store);
+        {
+        std::string message = tariff->TariffChangeIsAllowed(*nt, stgTime);
+        if (message.empty())
+            {
+            property.tariffName.Set(nextTariff, sysAdmin, login, store);
+            }
+        else
+            {
+            WriteServLog("Tariff change is prohibited for user %s. %s",
+                         login.c_str(),
+                         message.c_str());
+            }
+        }
     ResetNextTariff();
     WriteConf();
     }
     ResetNextTariff();
     WriteConf();
     }