From: Maxim Mamontov Date: Sat, 17 Sep 2016 13:03:04 +0000 (+0300) Subject: Merge branch 'stg-2.409' X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/d1c864e3feaf4295d366e2ef497495738ce15337?ds=sidebyside;hp=-c Merge branch 'stg-2.409' --- d1c864e3feaf4295d366e2ef497495738ce15337 diff --combined projects/stargazer/inst/freebsd/etc/stargazer/stargazer.conf index 84d14f60,c1f4fe92..bb8ee7c4 --- a/projects/stargazer/inst/freebsd/etc/stargazer/stargazer.conf +++ b/projects/stargazer/inst/freebsd/etc/stargazer/stargazer.conf @@@ -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 diff --combined projects/stargazer/inst/linux/etc/stargazer/stargazer.conf index 84d14f60,c1f4fe92..bb8ee7c4 --- a/projects/stargazer/inst/linux/etc/stargazer/stargazer.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/stargazer.conf @@@ -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 diff --combined projects/stargazer/settings_impl.cpp index fa7402ed,0cf9501b..212ed634 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@@ -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), @@@ -87,12 -90,13 +89,14 @@@ 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) @@@ -395,6 -391,22 +401,22 @@@ } } + 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(); @@@ -464,9 -476,7 +486,7 @@@ if (strcasecmp(node->getName(), "ScriptParams") == 0) { for (int i = 0; node->getValue(i) != NULL; ++i) - { scriptParams.push_back(node->getValue(i)); - } } node = node->getNextNode(); } diff --combined projects/stargazer/settings_impl.h index 20d82869,cc35393b..de27b728 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@@ -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 & 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 filterParamsLog; std::vector modulesSettings; MODULE_SETTINGS storeModuleSettings; diff --combined projects/stargazer/user_impl.cpp index fe197cc5,55a0b197..c160db75 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@@ -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)