From f198d554f6991caebd5b338439bd7430f6a8e247 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Sun, 8 Jan 2023 01:00:48 +0000 Subject: [PATCH] --- server/biz/GlobalBizSettingsBiz.cs | 12 +- server/biz/LicenseBiz.cs | 366 ++++++++++++++++++++++++++++- server/models/License.cs | 14 +- server/util/AySchema.cs | 4 +- 4 files changed, 391 insertions(+), 5 deletions(-) diff --git a/server/biz/GlobalBizSettingsBiz.cs b/server/biz/GlobalBizSettingsBiz.cs index d69c02f..f60343c 100644 --- a/server/biz/GlobalBizSettingsBiz.cs +++ b/server/biz/GlobalBizSettingsBiz.cs @@ -541,7 +541,13 @@ namespace Sockeye.Biz */ string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(KeyText, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); var jKey = JObject.Parse(keyNoWS); + + //In v7 the license expires is an optional property set called "LockDate" l.LicenseExpire = null; + if (jKey["AyaNovaLicenseKey"]["LockDate"] != null) + l.LicenseExpire = jKey["AyaNovaLicenseKey"]["LockDate"].Value().ToUniversalTime(); + + l.MaintenanceExpire = jKey["AyaNovaLicenseKey"]["Expires"].Value().ToUniversalTime(); l.PGroup = ProductGroup.AyaNova7; l.FetchCode = jLicense["code"].Value(); @@ -559,7 +565,11 @@ namespace Sockeye.Biz */ string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(KeyText, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); var jKey = JObject.Parse(keyNoWS); + //In v7 the license expires is an optional property set called "LockDate" l.LicenseExpire = null; + if (jKey["AyaNovaLicenseKey"]["LockDate"] != null) + l.LicenseExpire = jKey["AyaNovaLicenseKey"]["LockDate"].Value().ToUniversalTime(); + l.MaintenanceExpire = jKey["AyaNovaLiteLicenseKey"]["Expires"].Value().ToUniversalTime(); l.PGroup = ProductGroup.AyaNova7; l.FetchCode = jLicense["code"].Value(); @@ -606,7 +616,7 @@ namespace Sockeye.Biz l.FetchEmail = jLicense["email"].Value(); l.Key = jLicense["key"].Value(); - l.Active=true;//active here means it's been fully prepared and is viable for use, all prior licenses fit this description so all are active + l.Active = true;//active here means it's been fully prepared and is viable for use, all prior licenses fit this description so all are active LicenseBiz biz = LicenseBiz.GetBiz(ct); await biz.CreateAsync(l); diff --git a/server/biz/LicenseBiz.cs b/server/biz/LicenseBiz.cs index e3b294c..2272095 100644 --- a/server/biz/LicenseBiz.cs +++ b/server/biz/LicenseBiz.cs @@ -69,7 +69,371 @@ namespace Sockeye.Biz var ret = await ct.License.AsNoTracking().SingleOrDefaultAsync(z => z.Id == id); if (logTheGetEvent && ret != null) await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, SockEvent.Retrieved), ct); - return ret; + + return ParseKeySetDTOFields(ret); + } + + //Read the license key text, parse it and set the dto fields accordingly + internal License ParseKeySetDTOFields(License l) + { + + if (l == null || string.IsNullOrWhiteSpace(l.Key)) + return l; + + + if (l.Key.Contains("AyaNovaLicenseKey")) + { + //v7 key + /* + [KEY + { + "AyaNovaLicenseKey": { + "SchemaVersion": "7", + "Id": "1517418112", + "Created": "2018-01-31T09:01:52.1878494-08:00", + "Sub": "true", + "RegisteredTo": "Direct Telecom Services", + "EmailAddress": "chrisw@dts.solutions", + "FetchCode": "AgYuDnjDyQ", + "Source": "5246494432", + "InstallableUntil": "2019-01-31T09:01:52.089767-08:00", + "TotalScheduleableUsers": "15", + "Expires": "2019-01-31T00:00:00", + "RequestedTrial": "False", + "Plugins": { + "Plugin": [ + { + "Item": "MBI - Minimal browser interface", + "SubscriptionExpires": "2018-06-13T00:00:00" + }, + { + "Item": "WBI - Web browser interface", + "SubscriptionExpires": "2018-06-13T00:00:00" + }, + { + "Item": "OutlookSchedule", + "SubscriptionExpires": "2018-06-13T00:00:00" + }, + { + "Item": "AyaNovaOLI", + "SubscriptionExpires": "2018-06-13T00:00:00" + }, + { + "Item": "RI - Responsive Interface", + "SubscriptionExpires": "2018-06-13T00:00:00" + } + ] + } + } + } + KEY] + [SIGNATURE + uBjnooIDd6MOiqT/z4tDQfeafkQiWDBtxDHXOxhZ7av1oWS72yPoe8BrAnDZiYbxE4+cHR3C0sPCgEVva5miV1foyi7P6YKkxkKQMxTUR5IssgWVHM59KnO1lR2ndCHWaqH3gHgSsb/sdvYfuHg8luTl1RgjNDZRdQqbPl4NLMcGGW86LoXjpLjsRRxImckBEJFnntd+aXCRmQjXEZWmfxDVW84qa6h+ZCOwL3KYJHuPQDcCmhcpp3MIR3OHoeYhmNG7TWuELsJ4hrsROcqSbEC/CdZD8hoZwtrysu/ZvNZOKchwFsiBaN47+DxK0K/fL/X8CDcG+w3iqgH/x5ipIw== + SIGNATURE] + "Plugin": [ + { + "Item": "MBI - Minimal browser interface", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "WBI - Web browser interface", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "QBI - QuickBooks interface", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "QBOI - QuickBooks Online interface", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "PTI - US Sage 50/Peachtree interface", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "QuickNotification", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "ExportToXls", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "OutlookSchedule", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "AyaNovaOLI", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "ImportExportCSVDuplicate", + "SubscriptionExpires": "2024-01-08T00:00:00" + }, + { + "Item": "RI - Responsive Interface", + "SubscriptionExpires": "2024-01-08T00:00:00" + } + */ + string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(l.Key, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); + var jKey = JObject.Parse(keyNoWS); + l.Users = jKey["AyaNovaLicenseKey"]["TotalScheduleableUsers"].Value(); + //plugins + //var jaPlugins = jKey["AyaNovaLicenseKey"]["TotalScheduleableUsers"].Value(); + var jaPlugins = (JArray)jKey.SelectToken("AyaNovaLicenseKey.Plugins.Plugin"); + for (int x = 0; x < jaPlugins.Count; x++) + { + var jPlugin = (JObject)jaPlugins[x]; + var plugItem = jPlugin["Item"].Value(); + var plugExpires = jPlugin["SubscriptionExpires"].Value().ToUniversalTime(); + + switch (plugItem) + { + case "MBI - Minimal browser interface": + { + l.MBI = true; + l.MBIExpires = plugExpires; + } + break; + case "WBI - Web browser interface": + { + l.WBI = true; + l.WBIExpires = plugExpires; + } + break; + case "QBI - QuickBooks interface": + { + l.QBI = true; + l.QBIExpires = plugExpires; + } + break; + case "QBOI - QuickBooks Online interface": + { + l.QBOI = true; + l.QBOIExpires = plugExpires; + } + break; + case "PTI - US Sage 50/Peachtree interface": + { + l.PTI = true; + l.PTIExpires = plugExpires; + } + break; + case "QuickNotification": + { + l.QuickNotification = true; + l.QuickNotificationExpires = plugExpires; + } + break; + case "ExportToXls": + { + l.ExportToXLS = true; + l.ExportToXLSExpires = plugExpires; + } + break; + case "OutlookSchedule": + { + l.OutlookSchedule = true; + l.OutlookScheduleExpires = plugExpires; + } + break; + case "AyaNovaOLI": + { + l.OLI = true; + l.OLIExpires = plugExpires; + } + break; + case "ImportExportCSVDuplicate": + { + l.ImportExportCSVDuplicate = true; + l.ImportExportCSVDuplicateExpires = plugExpires; + } + break; + case "RI - Responsive Interface": + { + l.RI = true; + l.RIExpires = plugExpires; + } + break; + + } + // dr["Plugin"] = (string)p[x].SelectToken("Item"); + // dr["SubscriptionExpires"] = (DateTime)p[x].SelectToken("SubscriptionExpires"); + // dtPlugins.Rows.Add(dr); + } + + } + else if (l.Key.Contains("AyaNovaLiteLicenseKey")) + { + //v7 LITE key + /* + "[KEY\n{\n \"AyaNovaLiteLicenseKey\": {\n \"SchemaVersion\": \"7\",\n \"Id\": \"1648506791\",\n \"Created\": \"2022-03-28T15:33:11.6010225-07:00\",\n + \"Sub\": \"true\",\n \"RegisteredTo\": \"Duncan Electric\",\n \"EmailAddress\": \"sandrajod@att.net\",\n + \"FetchCode\": \"hGAmScqYcU\",\n \"Source\": \"5246494431\",\n \"InstallableUntil\": \"2023-03-28T15:33:11.6009851-07:00\",\n + \"TotalScheduleableUsers\": \"1\",\n \"Expires\": \"2023-03-29T00:00:00\",\n \"RequestedTrial\": \"False\",\n \"Plugins\": {\n + \"Plugin\": []\n }\n }\n}\nKEY]\n + [SIGNATURE\nKuOF/SpBL1d8AFebvm2lipmKeGdbR6WzbhN68fun+ffVGRjXNX1jWI3rbf9P/shs2/M8gHqW/B7T0vVovGqosmNsGtvaYo30TKlZj9Eicr2+zDf7ojwZiBCeEnFzXr9+7aZrsZSvN20Pqof0xf/J4BVp1T66ecuZywMzH0NGsXXZtXhWYhGvLAZAR1X5/j5gqysSdysmV9j8Euz91zs/BRyfdU0uwwrdQzrJzI4V1MFl+/mIkhMUNcJ5bzjisWS2xeyNYCYnGpMF5oaGPaIcEtmTAdf5fPNNvw3sNhPaZgwlzN8FjfK6T0VgS19PcHCMOA1bTAiLLFNk6wkcjGp2Cw==\nSIGNATURE]\n" + */ + string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(l.Key, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); + var jKey = JObject.Parse(keyNoWS); + l.Users = 1; + var jaPlugins = (JArray)jKey.SelectToken("AyaNovaLicenseKey.Plugins.Plugin"); + for (int x = 0; x < jaPlugins.Count; x++) + { + var jPlugin = (JObject)jaPlugins[x]; + var plugItem = jPlugin["Item"].Value(); + var plugExpires = jPlugin["SubscriptionExpires"].Value().ToUniversalTime(); + + switch (plugItem) + { + case "MBI - Minimal browser interface": + { + l.MBI = true; + l.MBIExpires = plugExpires; + } + break; + case "WBI - Web browser interface": + { + l.WBI = true; + l.WBIExpires = plugExpires; + } + break; + case "QBI - QuickBooks interface": + { + l.QBI = true; + l.QBIExpires = plugExpires; + } + break; + case "QBOI - QuickBooks Online interface": + { + l.QBOI = true; + l.QBOIExpires = plugExpires; + } + break; + case "PTI - US Sage 50/Peachtree interface": + { + l.PTI = true; + l.PTIExpires = plugExpires; + } + break; + case "QuickNotification": + { + l.QuickNotification = true; + l.QuickNotificationExpires = plugExpires; + } + break; + case "ExportToXls": + { + l.ExportToXLS = true; + l.ExportToXLSExpires = plugExpires; + } + break; + case "OutlookSchedule": + { + l.OutlookSchedule = true; + l.OutlookScheduleExpires = plugExpires; + } + break; + case "AyaNovaOLI": + { + l.OLI = true; + l.OLIExpires = plugExpires; + } + break; + case "ImportExportCSVDuplicate": + { + l.ImportExportCSVDuplicate = true; + l.ImportExportCSVDuplicateExpires = plugExpires; + } + break; + case "RI - Responsive Interface": + { + l.RI = true; + l.RIExpires = plugExpires; + } + break; + + } + } + + } + else + { + //V8 RAVEN key + /* + {{ + "Key": { + "LicenseFormat": "8", + "Id": "1672261044", + "RegisteredTo": "PDI Technologies", + "DBID": "R6U37uNUN2hSQideG6Gg+MqoQY8vuUeyHFI6Kv7VDsE=", + "Perpetual": true, + "LicenseExpiration": "5555-01-01T00:00:00", + "MaintenanceExpiration": "2023-12-28T00:00:00", + "Features": [ + { + "Name": "ActiveInternalUsers", + "Count": 5 + } + ] + } +}} + +"Features": [ + { + "Name": "TrialMode" + }, + { + "Name": "ActiveInternalUsers", + "Count": 5000 + }, + { + "Name": "ActiveCustomerUsers", + "Count": 20000 + }, + { + "Name": "MaximumDataGB", + "Count": 20 + } + ] + */ + string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(l.Key, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); + var jKey = JObject.Parse(keyNoWS); + + + + var jaFeatures = (JArray)jKey.SelectToken("Key.Features"); + for (int x = 0; x < jaFeatures.Count; x++) + { + var jFeature = (JObject)jaFeatures[x]; + var feature = jFeature["Name"].Value(); + int count=0; + if(feature!="TrialMode") + count = jFeature["Count"].Value(); + } + + + + + l.Users = jKey["AyaNovaLicenseKey"]["TotalScheduleableUsers"].Value(); + + + + + + + l.DbId = jKey["Key"]["DBID"].Value(); + l.LicenseExpire = jKey["Key"]["LicenseExpiration"].Value().ToUniversalTime(); + //if (jKey["Key"]["Perpetual"].Value()) + if ((bool?)jKey["Key"]["Perpetual"] ?? true) + l.PGroup = ProductGroup.RavenPerpetual; + else + l.PGroup = ProductGroup.RavenSubscription; + l.MaintenanceExpire = jKey["Key"]["MaintenanceExpiration"].Value().ToUniversalTime(); + } + return l; + } //////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/server/models/License.cs b/server/models/License.cs index ce67cf1..a2bc77c 100644 --- a/server/models/License.cs +++ b/server/models/License.cs @@ -28,9 +28,21 @@ namespace Sockeye.Models public string FetchEmail { get; set; }//v7 uses public DateTime? FetchedOn { get; set; } public string DbId { get; set; }//v8 uses + public DateTime? LicenseExpire { get; set; } public DateTime MaintenanceExpire { get; set; } + //v8 dto props + [NotMapped] + public int CustomerUsers { get; set; }//v8 + [NotMapped] + public int MaxDataGB { get; set; }//v8 + [NotMapped] + public bool TrialMode { get; set; }//v8 + //shared dto props + [NotMapped] + public int Users { get; set; }//v7 scheduled users, v8 internal users + //V7 props for dto //not stored in db, hydrated if v7 license and //used to do the generation from selections at client @@ -78,7 +90,7 @@ namespace Sockeye.Models public bool ImportExportCSVDuplicate { get; set; } [NotMapped] public DateTime? ImportExportCSVDuplicateExpires { get; set; } - + public string Wiki { get; set; } public List Tags { get; set; } diff --git a/server/util/AySchema.cs b/server/util/AySchema.cs index 3634361..ad3b150 100644 --- a/server/util/AySchema.cs +++ b/server/util/AySchema.cs @@ -24,7 +24,7 @@ namespace Sockeye.Util internal const long EXPECTED_COLUMN_COUNT = 504; internal const long EXPECTED_INDEX_COUNT = 74; - internal const long EXPECTED_CHECK_CONSTRAINTS = 241; + internal const long EXPECTED_CHECK_CONSTRAINTS = 240; internal const long EXPECTED_FOREIGN_KEY_CONSTRAINTS = 32; internal const long EXPECTED_VIEWS = 0; internal const long EXPECTED_ROUTINES = 2; @@ -874,7 +874,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); LogUpdateMessage(log); await ExecQueryAsync("CREATE TABLE alicense (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created TIMESTAMPTZ NOT NULL, active BOOL NOT NULL DEFAULT false, " - + "customerid BIGINT REFERENCES acustomer(id), pgroup INTEGER NOT NULL DEFAULT 0, regto TEXT NOT NULL, key TEXT NOT NULL, fetchcode TEXT, fetchemail TEXT, " + + "customerid BIGINT REFERENCES acustomer(id), pgroup INTEGER NOT NULL DEFAULT 0, regto TEXT NOT NULL, key TEXT, fetchcode TEXT, fetchemail TEXT, " + "fetchedon TIMESTAMPTZ, dbid TEXT, licenseexpire TIMESTAMPTZ, maintenanceexpire TIMESTAMPTZ NOT NULL, " + "wiki TEXT, tags VARCHAR(255) ARRAY )");