diff --git a/server/AyaNova/ControllerHelpers/ApiServerState.cs b/server/AyaNova/ControllerHelpers/ApiServerState.cs index b2158817..c1063ba1 100644 --- a/server/AyaNova/ControllerHelpers/ApiServerState.cs +++ b/server/AyaNova/ControllerHelpers/ApiServerState.cs @@ -45,6 +45,12 @@ namespace AyaNova.Api.ControllerHelpers //Lock down the server for license related issue //Only SuperUser account (id=1) can login or do anything, treats as if server was set to closed even if they change it to open //only way to reset it is to fetch a valid license + // This is set to locked in TWO ways: + + // 1) By CoreJobSweeper *if* the user count is mismatched to the license likely due to Users messing directly with the DB + //trying to circumvent licensing + // 2) By License::InitializeAsync upon finding user count mismatch or expired license key + // and initializeasync is called on boot up or when a new key is downloaded and installed only // var msg = $"{reason}\r\nLogin as SuperUser to start evaluation / install license"; SetState(ServerState.OpsOnly, msg); @@ -185,7 +191,7 @@ namespace AyaNova.Api.ControllerHelpers { get { - return _currentState != ServerState.Closed && _currentState != ServerState.OpsOnly && !SYSTEM_LOCK ; + return _currentState != ServerState.Closed && _currentState != ServerState.OpsOnly && !SYSTEM_LOCK; } } diff --git a/server/AyaNova/generator/CoreJobLicense.cs b/server/AyaNova/generator/CoreJobLicense.cs index 0a3827ca..5b0a6a30 100644 --- a/server/AyaNova/generator/CoreJobLicense.cs +++ b/server/AyaNova/generator/CoreJobLicense.cs @@ -7,9 +7,10 @@ using AyaNova.Util; namespace AyaNova.Biz { + //NOTE: this is not where the license expiration is checked, that's done in corejobsweeper with the user count checks /// - /// called by Generator to check for new licenses automatically + /// called by Generator to check RockFish for new licenses automatically /// /// internal static class CoreJobLicense diff --git a/server/AyaNova/generator/CoreJobSweeper.cs b/server/AyaNova/generator/CoreJobSweeper.cs index 2de17d4c..cac62688 100644 --- a/server/AyaNova/generator/CoreJobSweeper.cs +++ b/server/AyaNova/generator/CoreJobSweeper.cs @@ -57,8 +57,9 @@ namespace AyaNova.Biz await SweepInternalJobsLogsAsync(ct, dtDeleteCutoff); - //In flight check of user count exceeded in case someone meddled in the DB Directly -#if (SUBSCRIPTION_BUILD) + //In flight check validate the db license related user data in case of attempted circumvention + + //User count - common check to both build types if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveInternalUsersCount) { var msg = $"{AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)"; @@ -67,6 +68,9 @@ namespace AyaNova.Biz return; } +#if (SUBSCRIPTION_BUILD) + + //Customer contact count - check only for subscription build if (await AyaNova.Biz.UserBiz.ActiveCustomerContactUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveCustomerContactUsersCount) { var msg = $"{AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (Customer Contact User count)"; @@ -74,22 +78,6 @@ namespace AyaNova.Biz log.LogCritical(msg); return; } - -#else - // if (await UserBiz.ActiveTechUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveTechsCount) - // { - // //Warning: magic string, do not change this, triggers special login procedures to fix license issue - // AyaNova.Util.ServiceProviderProvider.ServerState.SetSystemLock(AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR); - // log.LogCritical(AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR); - // return; - // } - if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveInternalUsersCount) - { - var msg = $"{AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)"; - AyaNova.Util.ServiceProviderProvider.ServerState.SetSystemLock(msg); - log.LogCritical(msg); - return; - } #endif } diff --git a/server/AyaNova/util/License.cs b/server/AyaNova/util/License.cs index 436c1ff4..8a8c5524 100644 --- a/server/AyaNova/util/License.cs +++ b/server/AyaNova/util/License.cs @@ -528,17 +528,17 @@ namespace AyaNova.Core var FetchRequest = new dtoFetchRequest() { DbId = LicenseDbId }; string LicenseUrlParameter = "rvf"; -// #if (DEBUG) -// if (devTestTrial) -// { -// #if (SUBSCRIPTION_BUILD) -// LicenseUrlParameter += "?dtt=true&pp=false";//signal to rockfish to provide a key immediately for dev testing -// #else -// LicenseUrlParameter += "?dtt=true&pp=true";//signal to rockfish to provide a key immediately for dev testing -// #endif + // #if (DEBUG) + // if (devTestTrial) + // { + // #if (SUBSCRIPTION_BUILD) + // LicenseUrlParameter += "?dtt=true&pp=false";//signal to rockfish to provide a key immediately for dev testing + // #else + // LicenseUrlParameter += "?dtt=true&pp=true";//signal to rockfish to provide a key immediately for dev testing + // #endif -// } -// #endif + // } + // #endif try { @@ -692,9 +692,9 @@ namespace AyaNova.Core } + //################## This is called on Boot up of server and when a new license key is fetched and installed ############### /// /// Initialize the license - /// /// internal static async Task InitializeAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log) { @@ -783,9 +783,9 @@ namespace AyaNova.Core } - //Has someone been trying funny business with the active techs in the db? -#if (SUBSCRIPTION_BUILD) + //Validate the db license related user data in case of attempted circumvention + //User count - common check to both build types if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > _ActiveLicense.ActiveInternalUsersCount) { var msg = $"{SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)"; @@ -793,8 +793,8 @@ namespace AyaNova.Core log.LogCritical(msg); return; } - - +#if (SUBSCRIPTION_BUILD) + //Customer contact count - check only for subscription build if (await AyaNova.Biz.UserBiz.ActiveCustomerContactUserCountAsync() > _ActiveLicense.ActiveCustomerContactUsersCount) { var msg = $"{SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (Customer Contact User count)"; @@ -802,26 +802,8 @@ namespace AyaNova.Core log.LogCritical(msg); return; } - - -#else - // if (await AyaNova.Biz.UserBiz.ActiveTechUserCountAsync() > _ActiveLicense.ActiveTechsCount) - // { - // apiServerState.SetSystemLock(SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR); - // log.LogCritical(SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR); - // return; - //} - if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > _ActiveLicense.ActiveInternalUsersCount) - { - var msg = $"{SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)"; - apiServerState.SetSystemLock(msg); - log.LogCritical(msg); - return; - } #endif - - //Key is ok, might not have been on first boot so check and clear if locked //This works for now because system lock only means license lock //if ever changed for other purposes then need to handle that see serverstate for ideas @@ -945,6 +927,7 @@ namespace AyaNova.Core #endregion #region PARSE and Validate key + //################## This is called on Boot up of server and when a new license key is fetched and installed ############### /// /// Parses and validates the integrity of a passed in textual license key ///