From 305b61045d28d120e32854b891f1e2dc66625747 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 17 Jun 2020 18:58:37 +0000 Subject: [PATCH] --- Controllers/RvfController.cs | 40 +--------- Controllers/RvlController.cs | 138 +++++++++++++++++++---------------- Controllers/RvrController.cs | 7 +- Models/License.cs | 1 + util/RavenKeyFactory.cs | 62 ++++++++++++++-- util/RfSchema.cs | 3 +- 6 files changed, 140 insertions(+), 111 deletions(-) diff --git a/Controllers/RvfController.cs b/Controllers/RvfController.cs index 419171b..7c8d1f8 100644 --- a/Controllers/RvfController.cs +++ b/Controllers/RvfController.cs @@ -8,6 +8,7 @@ using rockfishCore.Util; namespace rockfishCore.Controllers { + //### CUSTOMER ROUTE CALLED FROM RAVEN NO AUTH #### [Produces("application/json")] [Route("rvf")] public class RvfController : Controller //RAVEN License fetch route @@ -20,6 +21,7 @@ namespace rockfishCore.Controllers } + //### CUSTOMER ROUTE CALLED FROM RAVEN #### [HttpGet("{dbid}")] public async Task Get([FromRoute] Guid dbid) { @@ -63,46 +65,8 @@ namespace rockfishCore.Controllers key = LicenseKey } }); - - } - // [HttpGet("hello/{dbid}")] - // public ActionResult Hello([FromRoute] Guid dbid) - // { - // //check to see if there is anything of note for this server like a new key or a message etc - // if (!ModelState.IsValid) - // { - // return BadRequest(ModelState); - // } - - // //return a json object with results if anything to report - - // //This is to simulate the scenarios where there is no license to return - // //either due to no current account / canceled or simply no license exists - // //Changes here must be reflected in RAVEN Util.License.Fetch block - // bool bTestStatusOtherThanOk = false; - // if (bTestStatusOtherThanOk) - // { - // return Json(new { Status = "NONE", Reason = "No license" }); - // //return Json(new {Status="Canceled", Reason="Non payment"}); - // } - // else - // { - // return Ok(RavenKeyFactory.GetRavenTestKey(dbid)); - // } - - // } - - - - - - - private bool LicenseExists(long id) - { - return ct.License.Any(e => e.Id == id); - } } } \ No newline at end of file diff --git a/Controllers/RvlController.cs b/Controllers/RvlController.cs index 2b79924..570bd35 100644 --- a/Controllers/RvlController.cs +++ b/Controllers/RvlController.cs @@ -12,9 +12,11 @@ using System.ComponentModel.DataAnnotations; namespace rockfishCore.Controllers { - [Produces("text/plain")] + //### OUR ROUTE CALLED FROM ROCKFISH CLIENT #### + [Produces("application/json")] [Route("rvl")] - public class RvlController : Controller //RAVEN license controller + [Authorize] + public class RvlController : Controller { private readonly rockfishContext ct; @@ -98,74 +100,84 @@ namespace rockfishCore.Controllers return BadRequest($"Customer {Customer.Name} is set to DO NOT CONTACT, unable to process and send key"); } - - var newLicense = new RavenKeyFactory.AyaNovaLicenseKey(); - - newLicense.RegisteredTo = l.RegisteredTo; - newLicense.DbId = l.DbId; - newLicense.LicenseExpiration = DateUtil.EpochToDate(l.LicenseExpiration); - newLicense.MaintenanceExpiration = DateUtil.EpochToDate(l.MaintenanceExpiration); - foreach (dtoLicenseFeature f in l.Features) + try { - newLicense.Features.Add(new RavenKeyFactory.LicenseFeature() { Feature = f.Feature, Count = f.Count }); - } + var newLicense = new RavenKeyFactory.AyaNovaLicenseKey(); - //Everything seems to be in order generate the license, save it and send it - - - - - var NewRequest = new TrialRequest(); - NewRequest.Email = r.Email; - NewRequest.DbId = r.DbId; - NewRequest.CompanyName = r.Company; - NewRequest.ContactName = r.Contact; - await ct.TrialRequest.AddAsync(NewRequest); - await ct.SaveChangesAsync(); - NewRequest.EmailConfirmCode = NewRequest.Id.ToString() + FetchKeyCode.generate(); - await ct.SaveChangesAsync(); - var verifyUrl = LICENSE_SERVER_URL + $"rvr/verify/{NewRequest.EmailConfirmCode}"; - var body = $"Please verify your email address by clicking the link below or copy and pasting into a browser\r\n{verifyUrl}\r\n(If you did not request this you can ignore this message)"; - //send confirmation email - RfMail.SendMessage("support@ayanova.com", NewRequest.Email, "AyaNova trial request email verification", body, false); - //return Ok(new { Accepted = true }); - return Accepted(); - - } - - [HttpGet("verify/{code}")] - public async Task GetVerify([FromRoute] string code) - { - //is there a valid trial request - var req = await ct.TrialRequest.Where(z => z.EmailConfirmCode == code && z.DtFetched == null && z.Status == TrialRequest.TrialRequestStatus.NotSet).FirstOrDefaultAsync(); - if (req == null) - { - return new ContentResult + newLicense.RegisteredTo = l.RegisteredTo; + newLicense.DbId = l.DbId; + newLicense.LicenseExpiration = DateUtil.EpochToDate(l.LicenseExpiration); + newLicense.MaintenanceExpiration = DateUtil.EpochToDate(l.MaintenanceExpiration); + foreach (dtoLicenseFeature f in l.Features) { - ContentType = "text/html", - StatusCode = 200, - Content = "

Request not found

There was no evaluation request associated with this verification code.

" - }; + newLicense.Features.Add(new RavenKeyFactory.LicenseFeature() { Feature = f.Feature, Count = f.Count }); + } + + //Everything seems to be in order generate the license, save it and send it + + var Key = RavenKeyFactory.GenerateRavenKey(newLicense); + + //save it to the database + var DBLicense = new License(); + DBLicense.CustomerId = CustomerId; + DBLicense.SiteId = l.SiteId; + DBLicense.Email = Customer.AdminEmail; + DBLicense.DbId = l.DbId; + DBLicense.Key = Key; + DBLicense.RegTo = l.RegisteredTo; + await ct.License.AddAsync(DBLicense); + await ct.SaveChangesAsync(); + + //Key generated, record saved successfully + //inform customer and return no content + var body = $"Thank you for your purchase!\nYour AyaNova license key is ready to be installed.\nAyaNova will fetch it automatically within 24 hours or you can force it to fetch immediately from the License page in AyaNova now.\n---\n{l}"; + //send license email + RfMail.SendMessage("support@ayanova.com", Customer.AdminEmail, "AyaNova license key", body, false); + return NoContent(); } - - req.EmailValidated = true; - await ct.SaveChangesAsync(); - - //notify *us* - //http://localhost:3001/default.htm#!/trials/[id] - var rfUrl = LICENSE_SERVER_URL + $"default.htm#!/trialEdit/{req.Id}"; - var body = $"Email address {req.Email} was just verified for {req.ContactName} at {req.CompanyName}.\r\nTrial key is ready to be processed now:\r\n{rfUrl}"; - //send confirmation email - RfMail.SendMessage("support@ayanova.com", SUPPORT_EMAIL, "AyaNova trial request requiring action", body, false); - - return new ContentResult + catch (Exception ex) { - ContentType = "text/html", - StatusCode = 200, - Content = "

Email validated!

Your request is being processed and you will receive an email with instructions for starting your AyaNova evaluation.

" - }; + return StatusCode(500, $"Exception processing request: {ex.Message}"); + } } + + + + // [HttpGet("verify/{code}")] + // public async Task GetVerify([FromRoute] string code) + // { + // //is there a valid trial request + // var req = await ct.TrialRequest.Where(z => z.EmailConfirmCode == code && z.DtFetched == null && z.Status == TrialRequest.TrialRequestStatus.NotSet).FirstOrDefaultAsync(); + // if (req == null) + // { + // return new ContentResult + // { + // ContentType = "text/html", + // StatusCode = 200, + // Content = "

Request not found

There was no evaluation request associated with this verification code.

" + // }; + // } + + // req.EmailValidated = true; + // await ct.SaveChangesAsync(); + + // //notify *us* + // //http://localhost:3001/default.htm#!/trials/[id] + // var rfUrl = LICENSE_SERVER_URL + $"default.htm#!/trialEdit/{req.Id}"; + // var body = $"Email address {req.Email} was just verified for {req.ContactName} at {req.CompanyName}.\r\nTrial key is ready to be processed now:\r\n{rfUrl}"; + // //send confirmation email + // RfMail.SendMessage("support@ayanova.com", SUPPORT_EMAIL, "AyaNova trial request requiring action", body, false); + + // return new ContentResult + // { + // ContentType = "text/html", + // StatusCode = 200, + // Content = "

Email validated!

Your request is being processed and you will receive an email with instructions for starting your AyaNova evaluation.

" + // }; + // } + + }//eoc }//eons \ No newline at end of file diff --git a/Controllers/RvrController.cs b/Controllers/RvrController.cs index 0af1787..a015e40 100644 --- a/Controllers/RvrController.cs +++ b/Controllers/RvrController.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; using Microsoft.EntityFrameworkCore; using rockfishCore.Models; using rockfishCore.Util; @@ -12,6 +9,7 @@ using System.ComponentModel.DataAnnotations; namespace rockfishCore.Controllers { + //### CUSTOMER ROUTES NO AUTH [Produces("text/plain")] [Route("rvr")] public class RvrController : Controller //RAVEN trial license request @@ -44,6 +42,7 @@ namespace rockfishCore.Controllers public const string SUPPORT_EMAIL="support@ayanova.com"; #endif + //### CUSTOMER ROUTE CALLED FROM RAVEN #### [HttpPost] public async Task Post([FromBody] dtoRequest r) { @@ -98,6 +97,7 @@ namespace rockfishCore.Controllers } + //### CUSTOMER ROUTE CALLED FROM CUSTOMER BROWSER / EMAIL #### [HttpGet("verify/{code}")] public async Task GetVerify([FromRoute] string code) { @@ -131,6 +131,5 @@ namespace rockfishCore.Controllers }; } - }//eoc }//eons \ No newline at end of file diff --git a/Models/License.cs b/Models/License.cs index a17f0ae..75a4b23 100644 --- a/Models/License.cs +++ b/Models/License.cs @@ -8,6 +8,7 @@ namespace rockfishCore.Models { public long Id { get; set; } public long CustomerId { get; set; } + public long SiteId { get; set; } public long DtCreated { get; set; } public string RegTo { get; set; } public string Key { get; set; } diff --git a/util/RavenKeyFactory.cs b/util/RavenKeyFactory.cs index b03041f..fd5d438 100644 --- a/util/RavenKeyFactory.cs +++ b/util/RavenKeyFactory.cs @@ -13,23 +13,21 @@ namespace rockfishCore.Util //Key generator controller public static class RavenKeyFactory { + public const int TRIAL_PERIOD_DAYS = 45; + //Unlicensed token private const string UNLICENSED_TOKEN = "UNLICENSED"; //REVOKED token private const string REVOKED_TOKEN = "REVOKED"; + //FEATURE NAMES //Scheduleable users private const string SERVICE_TECHS_FEATURE_NAME = "ServiceTechs"; - //Accounting add-on private const string ACCOUNTING_FEATURE_NAME = "Accounting"; - //This feature name means it's a trial key private const string TRIAL_FEATURE_NAME = "TrialMode"; - - public const int TRIAL_PERIOD_DAYS = 45; - //This feature name means it's a SAAS or rental mode key for month to month hosted service private const string RENTAL_FEATURE_NAME = "ServiceMode"; @@ -63,6 +61,60 @@ namespace rockfishCore.Util Id = $"00-{sId}"; } + public override string ToString() + { + /*LICENSE DETAILS +Registered to: Montacargas y Equipos Colombia +Fetch address: facordoba@jycexports.com +Fetch code: ZgVySojpHg +Scheduleable resources: Up to 15 +Support and updates until: Thursday, August 13, 2020 + + +Plugins: + WBI - Web browser interface support and updates until: Tuesday, June 15, 2021 + ExportToXls support and updates until: Tuesday, June 15, 2021 + ImportExportCSVDuplicate support and updates until: Friday, July 17, 2020 + RI - Responsive Interface support and updates until: Tuesday, June 15, 2021 */ + System.Text.StringBuilder sb = new StringBuilder(); + sb.AppendLine("LICENSE DETAILS"); + sb.AppendLine($"Registered to: {RegisteredTo}"); + sb.AppendLine($"Database id: {DbId}"); + if (WillExpire) + sb.AppendLine($"License valid until: {LicenseExpiration.ToLongDateString()}"); + sb.AppendLine($"Support and updates until: {MaintenanceExpiration.ToLongDateString()}"); + foreach (LicenseFeature f in Features) + { + if (f.Feature == TRIAL_FEATURE_NAME) + { + sb.AppendLine("Temporary license for evaluation"); + continue; + } + if (f.Feature == RENTAL_FEATURE_NAME) + { + sb.AppendLine("Service / Rental license"); + continue; + } + if (f.Feature == ACCOUNTING_FEATURE_NAME) + { + sb.AppendLine("Accounting option"); + continue; + } + if (f.Feature == SERVICE_TECHS_FEATURE_NAME) + { + sb.AppendLine($"Scheduleable resources: {f.Count}"); + continue; + } + //default for items added later not tokenized + if (f.Count > 0) + sb.AppendLine($"{f.Feature}: {f.Count}"); + else + sb.AppendLine($"{f.Feature}"); + } + return sb.ToString(); + } + + public bool IsEmpty { get diff --git a/util/RfSchema.cs b/util/RfSchema.cs index dffb733..54497e5 100644 --- a/util/RfSchema.cs +++ b/util/RfSchema.cs @@ -363,7 +363,7 @@ namespace rockfishCore.Util ////////////////////////////////////////////////// //schema 16 RAVEN stuff if (currentSchema < 16) - { + { exec("CREATE TABLE trialrequest (" + "id INTEGER PRIMARY KEY, dbid text not null, companyname text not null, contactname text not null, notes text, email text not null, " + "emailconfirmcode text not null, emailvalidated boolean default 0 NOT NULL CHECK (emailvalidated IN (0,1)), dtrequested integer, " + @@ -373,6 +373,7 @@ namespace rockfishCore.Util exec("alter table site add dbid text default 'v7_no_dbid' NOT NULL"); exec("update site set legacyv7 = 1"); exec("alter table license add dbid text default 'v7_no_dbid' NOT NULL"); + exec("alter table license add siteid integer"); exec("alter table purchase add quantity integer default 1 not null"); exec("insert into product (name, productCode, price, renewPrice) values ('TEST RAVEN schedulable resource 1 year subscription license','testfeatscheduser',15900, 5565);"); exec("insert into product (name, productCode, price, renewPrice) values ('TEST RAVEN Accounting 1 year subscription license','testfeatacct',15000, 5250);");