This commit is contained in:
@@ -188,14 +188,35 @@ namespace AyaNova.Api.Controllers
|
|||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "There is an active registered license. Only an unlicensed or trial license database can request a trial key."));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "There is an active registered license. Only an unlicensed or trial license database can request a trial key."));
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//Send the request to RockFish here (or at least start the job to do it in which case return Accepted instead of no content and update comment above)
|
||||||
|
var ret = await Core.License.RequestTrialAsync(trialRequest, log);
|
||||||
|
if (ret == "ok")
|
||||||
|
{
|
||||||
|
//Log
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct);
|
||||||
|
}
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Exception rootex = ex;
|
||||||
|
while (rootex.InnerException != null)
|
||||||
|
{
|
||||||
|
rootex = rootex.InnerException;
|
||||||
|
}
|
||||||
|
|
||||||
//Send the request to RockFish here (or at least start the job to do it in which case return Accepted instead of no content and update comment above)
|
if (rootex.Message.Contains("E1020"))
|
||||||
var ret = await Core.License.RequestTrialAsync(trialRequest, log);
|
{
|
||||||
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, "LICENSE_KEY", rootex.Message));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
//Log
|
}
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct);
|
|
||||||
|
|
||||||
return Ok(ApiOkResponse.Response(ret));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using Org.BouncyCastle.Security;
|
using Org.BouncyCastle.Security;
|
||||||
using Org.BouncyCastle.OpenSsl;
|
using Org.BouncyCastle.OpenSsl;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -456,7 +457,7 @@ namespace AyaNova.Core
|
|||||||
if (res.IsSuccessStatusCode)
|
if (res.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(responseText))
|
if (string.IsNullOrWhiteSpace(responseText))
|
||||||
return "Accepted";
|
return "ok";
|
||||||
else
|
else
|
||||||
return responseText;
|
return responseText;
|
||||||
}
|
}
|
||||||
@@ -491,10 +492,13 @@ namespace AyaNova.Core
|
|||||||
if (res.IsSuccessStatusCode)
|
if (res.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var responseText = await res.Content.ReadAsStringAsync();
|
var responseText = await res.Content.ReadAsStringAsync();
|
||||||
AyaNovaLicenseKey ParsedKey = Parse(responseText, log);
|
var responseJson=JObject.Parse(responseText);
|
||||||
|
var keyText=responseJson["data"]["key"].Value<string>();
|
||||||
|
|
||||||
|
AyaNovaLicenseKey ParsedKey = Parse(keyText, log);
|
||||||
if (ParsedKey != null)
|
if (ParsedKey != null)
|
||||||
{
|
{
|
||||||
await InstallAsync(responseText, ParsedKey, apiServerState, ct, log);
|
await InstallAsync(keyText, ParsedKey, apiServerState, ct, log);
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
return $"E1020 - Error fetching license key: No key was returned";
|
return $"E1020 - Error fetching license key: No key was returned";
|
||||||
@@ -670,7 +674,7 @@ namespace AyaNova.Core
|
|||||||
CurrentInDbKeyRecord.Key = RawTextNewKey;
|
CurrentInDbKeyRecord.Key = RawTextNewKey;
|
||||||
//LOOKAT: reason, resultcode etc
|
//LOOKAT: reason, resultcode etc
|
||||||
//There is similar block related to this in ayschema for db schema version 8
|
//There is similar block related to this in ayschema for db schema version 8
|
||||||
ct.SaveChanges();
|
await ct.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -718,6 +722,7 @@ namespace AyaNova.Core
|
|||||||
|
|
||||||
string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(k, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");
|
string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(k, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");
|
||||||
string keySig = StringUtil.Extract(k, "[SIGNATURE", "SIGNATURE]").Trim();
|
string keySig = StringUtil.Extract(k, "[SIGNATURE", "SIGNATURE]").Trim();
|
||||||
|
//bugbug second time around after installing key, keysig has cr/lf characters in it after this extract method runs, not sure wtf as it isnt there the first time
|
||||||
|
|
||||||
#region Check Signature
|
#region Check Signature
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user