LAND:
- fix warning compilazione - fix auth windows x login
This commit is contained in:
+10
-6
@@ -23,18 +23,20 @@ namespace Egw.Core
|
||||
public static string DecryptString(string Message, string Passphrase)
|
||||
{
|
||||
string answ = Message;
|
||||
byte[] Results = null;
|
||||
byte[] Results = new byte[8];
|
||||
UTF8Encoding UTF8 = new UTF8Encoding();
|
||||
|
||||
// Step 1. We hash the passphrase using MD5
|
||||
// We use the MD5 hash generator as the result is a 128 bit byte array
|
||||
// which is a valid length for the TripleDES encoder we use below
|
||||
|
||||
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
|
||||
var HashProvider = MD5.Create();
|
||||
//MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
|
||||
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
|
||||
|
||||
// Step 2. Create a new TripleDESCryptoServiceProvider object
|
||||
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
|
||||
var TDESAlgorithm = TripleDES.Create();
|
||||
//TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
|
||||
|
||||
// Step 3. Setup the decoder
|
||||
TDESAlgorithm.Key = TDESKey;
|
||||
@@ -42,7 +44,7 @@ namespace Egw.Core
|
||||
TDESAlgorithm.Padding = PaddingMode.PKCS7;
|
||||
|
||||
// Step 4. Convert the input string to a byte[]
|
||||
byte[] DataToDecrypt = null;
|
||||
byte[] DataToDecrypt = new byte[8];
|
||||
try
|
||||
{
|
||||
DataToDecrypt = Convert.FromBase64String(Message);
|
||||
@@ -84,11 +86,13 @@ namespace Egw.Core
|
||||
// We use the MD5 hash generator as the result is a 128 bit byte array
|
||||
// which is a valid length for the TripleDES encoder we use below
|
||||
|
||||
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
|
||||
var HashProvider = MD5.Create();
|
||||
//MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
|
||||
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
|
||||
|
||||
// Step 2. Create a new TripleDESCryptoServiceProvider object
|
||||
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
|
||||
var TDESAlgorithm = TripleDES.Create();
|
||||
//TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
|
||||
|
||||
// Step 3. Setup the encoder
|
||||
TDESAlgorithm.Key = TDESKey;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Egw.Core
|
||||
}
|
||||
answ = Convert.ToDateTime(datePart);
|
||||
}
|
||||
catch (Exception exc)
|
||||
catch //(Exception exc)
|
||||
{
|
||||
//logger.lg.scriviLog(string.Format("Errore decodifica auth key:{0}AuthKey: {1}{0}cliente:{2}{0}applicativo:{3}{0}errore:{4}", Environment.NewLine, authKey, cliente, applicativo, exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
@using MP.Land.Data
|
||||
|
||||
@inject MessageService AppMessages
|
||||
@*@inject AuthenticationStateProvider AuthenticationStateProvider*@
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
|
||||
<div class="form-row pt-3">
|
||||
<div class="col-7 col-md-6 col-lg-4 col-xl-3">
|
||||
@*<LoginDisplay></LoginDisplay>*@
|
||||
@*<i class="fas fa-user-alt"></i> <b>@userName</b>*@
|
||||
<i class="fas fa-user-alt"></i> <b>@userName</b>
|
||||
</div>
|
||||
<div class="col-12 col-lg-4 col-xl-6 d-none d-lg-block text-center h4 text-truncate">
|
||||
<span class="@PageIcon" aria-hidden="true"></span> @PageName
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -62,20 +63,16 @@ namespace MP.Land.Components
|
||||
private async Task forceReload()
|
||||
{
|
||||
userName = "N.A.";
|
||||
await Task.Delay(1);
|
||||
#if false
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
|
||||
if (user.Identity.IsAuthenticated)
|
||||
{
|
||||
userName = $"{user.Identity.Name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
userName = "N.A.";
|
||||
}
|
||||
#endif
|
||||
await Task.Delay(1); var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
if (user.Identity != null && user.Identity.IsAuthenticated)
|
||||
{
|
||||
userName = $"{user.Identity.Name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
userName = "N.A.";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
+263
-253
@@ -12,6 +12,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace MP.Land.Data
|
||||
{
|
||||
/// <summary>
|
||||
@@ -19,56 +21,6 @@ namespace MP.Land.Data
|
||||
/// </summary>
|
||||
public class LicenseService
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration? _configuration;
|
||||
private static ILogger<LicenseService>? _logger;
|
||||
|
||||
/// <summary>
|
||||
/// URL dell'API x chiamate gestione licenze
|
||||
/// </summary>
|
||||
private static string apiUrl = "https://liman.egalware.com/ELM.API/";
|
||||
//private static string apiUrl = "https://localhost:44351/";
|
||||
|
||||
/// <summary>
|
||||
/// Chiave redis x info della licenza
|
||||
/// </summary>
|
||||
private static string rkeyAppInfo = "LongCache:AppInfo";
|
||||
|
||||
private readonly IDistributedCache distributedCache;
|
||||
|
||||
/// <summary>
|
||||
/// Elenco obj in cache
|
||||
/// </summary>
|
||||
private List<string> cachedDataList = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Fattorte conversione cache sliding --> 1 h
|
||||
/// </summary>
|
||||
private int cacheFact = 12;
|
||||
|
||||
/// <summary>
|
||||
/// Durata assoluta massima della cache IN SECONDI
|
||||
/// </summary>
|
||||
private int chAbsExp = 60 * 5;
|
||||
|
||||
/// <summary>
|
||||
/// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire rimossa
|
||||
/// NON estende oltre il tempo massimo di validità della cache (chAbsExp)
|
||||
/// </summary>
|
||||
private int chSliExp = 60 * 1;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
/// <summary>
|
||||
/// Chiave redis x attivazioni della licenza
|
||||
/// </summary>
|
||||
protected const string rKeyAttByLic = "LongCache:AttByLic";
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
@@ -95,9 +47,7 @@ namespace MP.Land.Data
|
||||
#region Public Properties
|
||||
|
||||
public List<LiManObj.AttivazioneDTO> ActivList { get; set; } = new List<LiManObj.AttivazioneDTO>();
|
||||
|
||||
public List<AnagKeyValueModel> AKVList { get; set; } = new List<AnagKeyValueModel>();
|
||||
|
||||
public string Applicazione { get; set; } = "";
|
||||
|
||||
public bool HasActivData
|
||||
@@ -158,74 +108,212 @@ namespace MP.Land.Data
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Private Methods
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Opzioni cache con moltiplicatore durata risp durata base (1/5 minuti)
|
||||
/// </summary>
|
||||
/// <param name="multFact"></param>
|
||||
/// <returns></returns>
|
||||
private DistributedCacheEntryOptions cacheOpt(int multFact)
|
||||
public async Task<List<LiManObj.AttivazioneDTO>> ActivListCache()
|
||||
{
|
||||
var numSecAbsExp = chAbsExp * multFact;
|
||||
var numSecSliExp = chSliExp * multFact;
|
||||
return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco attivazioni attuali
|
||||
/// </summary>
|
||||
private async Task<List<LiManObj.AttivazioneDTO>?> OnlineActivationList()
|
||||
{
|
||||
List<LiManObj.AttivazioneDTO>? answ = new List<LiManObj.AttivazioneDTO>();
|
||||
// cerco online
|
||||
RestClient client = new RestClient(apiUrl);
|
||||
//client.Authenticator = new HttpBasicAuthenticator("username", "password");
|
||||
string MKeyEnc = HttpUtility.UrlEncode(MasterKey);
|
||||
var request = new RestRequest($"api/attivazioni/?chiave={MKeyEnc}", Method.Get);
|
||||
var response = await client.GetAsync(request);
|
||||
// controllo risposta
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
List<LiManObj.AttivazioneDTO> dbResult = new List<LiManObj.AttivazioneDTO>();
|
||||
string cacheKey = $"{rKeyAttByLic}:{MasterKey}";
|
||||
trackCache(cacheKey);
|
||||
string rawData = await getRSV(cacheKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
// salvo in redis contenuto serializzato
|
||||
string rawData = $"{response.Content}";
|
||||
answ = JsonConvert.DeserializeObject<List<LiManObj.AttivazioneDTO>?>(rawData);
|
||||
var cacheRes = JsonConvert.DeserializeObject<List<LiManObj.AttivazioneDTO>?>(rawData);
|
||||
if (cacheRes != null)
|
||||
{
|
||||
dbResult = cacheRes;
|
||||
}
|
||||
}
|
||||
return await Task.FromResult(answ);
|
||||
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera info licenza da remoto
|
||||
/// Verifica attivazione licenza
|
||||
/// </summary>
|
||||
private async Task<List<LiManObj.ApplicativoDTO>> OnlineAppInfo()
|
||||
/// <param name="authKey"></param>
|
||||
/// <returns></returns>
|
||||
public bool checkLicenseActive(string authKey)
|
||||
{
|
||||
List<LiManObj.ApplicativoDTO> answ = new List<LiManObj.ApplicativoDTO>();
|
||||
bool answ = false;
|
||||
//cerco anche nelle info AKV
|
||||
if (AKVList != null)
|
||||
{
|
||||
var recLic = AKVList.Where(x => x.ValString == authKey).FirstOrDefault();
|
||||
int numLic = 0;
|
||||
//cerco in record
|
||||
if (recLic != null && recLic.ValInt != null)
|
||||
{
|
||||
numLic = (int)recLic.ValInt;
|
||||
// verifico scadenza licenza!
|
||||
DateTime scadenza = licenseManGLS.expiryDateByAuthKey(Installazione, recLic.NomeVar, numLic, authKey);
|
||||
answ = scadenza > DateTime.Today;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"checkLicenseActive | Record non trovato per {authKey}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato server gestione licenze
|
||||
/// </summary>
|
||||
public async Task<string> checkLimanServer()
|
||||
{
|
||||
string answ = "ND";
|
||||
// cerco online
|
||||
RestClient client = new RestClient(apiUrl);
|
||||
string MKeyEnc = HttpUtility.UrlEncode(MasterKey);
|
||||
//string mKey = System.Net.WebUtility.UrlEncode(MasterKey);
|
||||
string reqUrl = $"api/licenza/{Installazione}?CodApp={Applicazione}&Chiave={MKeyEnc}";
|
||||
var request = new RestRequest(reqUrl, Method.Get);
|
||||
var request = new RestRequest($"api/health", Method.Get);
|
||||
var response = await client.GetAsync(request);
|
||||
// controllo risposta
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
// verifico risposta
|
||||
string rawData = $"{response.Content}";
|
||||
answ = JsonConvert.DeserializeObject<List<LiManObj.ApplicativoDTO>?>(rawData);
|
||||
if (response.Content != null)
|
||||
{
|
||||
answ = response.Content.Replace("\"", "");
|
||||
}
|
||||
}
|
||||
return await Task.FromResult(answ);
|
||||
}
|
||||
|
||||
private void ReportUpdated()
|
||||
/// <summary>
|
||||
/// Verifica scadenza licenza
|
||||
/// </summary>
|
||||
/// <param name="authKey"></param>
|
||||
/// <returns></returns>
|
||||
public DateTime getLicenseExpiry(string authKey)
|
||||
{
|
||||
DateTime answ = DateTime.Today.AddDays(-1);
|
||||
//cerco anche nelle info AKV
|
||||
if (AKVList != null)
|
||||
{
|
||||
var recLic = AKVList.Where(x => x.ValString == authKey).FirstOrDefault();
|
||||
int numLic = 0;
|
||||
//cerco in record
|
||||
if (recLic != null && recLic.ValInt != null)
|
||||
{
|
||||
numLic = (int)recLic.ValInt;
|
||||
// verifico scadenza licenza!
|
||||
DateTime scadenza = licenseManGLS.expiryDateByAuthKey(Installazione, recLic.NomeVar, numLic, authKey);
|
||||
answ = scadenza;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"getLicenseExpiry | Record non trovato per {authKey}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init della classe con variabili di base da Redis/DB
|
||||
/// </summary>
|
||||
public bool InitAkv()
|
||||
{
|
||||
bool fatto = false;
|
||||
Applicazione = "MAPO";
|
||||
Installazione = getAVKStr("Installazione");
|
||||
MasterKey = getAVKStr(Applicazione);
|
||||
NumLicDb = getAVKInt(Applicazione);
|
||||
fatto = !string.IsNullOrEmpty($"{Installazione}{MasterKey}");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<List<LiManObj.ApplicativoDTO>> LicAppCache()
|
||||
{
|
||||
List<LiManObj.ApplicativoDTO> dbResult = new List<LiManObj.ApplicativoDTO>();
|
||||
string cacheKey = $"{rkeyAppInfo}:{MasterKey}";
|
||||
trackCache(cacheKey);
|
||||
string rawData = await getRSV(cacheKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
var cacheRes = JsonConvert.DeserializeObject<List<LiManObj.ApplicativoDTO>?>(rawData);
|
||||
if (cacheRes != null)
|
||||
{
|
||||
dbResult = cacheRes;
|
||||
}
|
||||
}
|
||||
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init della classe con variabili di base da Redis/DB
|
||||
/// </summary>
|
||||
public async Task<bool> RefreshLicense()
|
||||
{
|
||||
bool fatto = false;
|
||||
// scadenza info a 15 gg...
|
||||
int numDays = 15;
|
||||
|
||||
// dati applicativo
|
||||
var appData = await OnlineAppInfo();
|
||||
if (appData != null)
|
||||
{
|
||||
if (appData.Count > 0)
|
||||
{
|
||||
fatto = await setAppInfo(appData, numDays);
|
||||
// salvo info licenza...
|
||||
NumLicRemote = appData[0].NumLicenze;
|
||||
}
|
||||
}
|
||||
|
||||
// dati attivazioni
|
||||
var onlineAct = await OnlineActivationList();
|
||||
if (onlineAct != null)
|
||||
{
|
||||
if (onlineAct.Count > 0)
|
||||
{
|
||||
infoExpiry = DateTime.Now.AddDays(numDays);
|
||||
ActivList = onlineAct;
|
||||
fatto = await setActivList(onlineAct, numDays);
|
||||
}
|
||||
}
|
||||
await Task.Delay(1);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<bool> setActivList(List<LiManObj.AttivazioneDTO> newActList, int numDays)
|
||||
{
|
||||
bool fatto = false;
|
||||
string cacheKey = $"{rKeyAttByLic}:{MasterKey}";
|
||||
var rawData = JsonConvert.SerializeObject(newActList);
|
||||
await setRSV(cacheKey, rawData, numDays * cacheFact * 24);
|
||||
fatto = true;
|
||||
if (EA_InfoUpdated != null)
|
||||
{
|
||||
EA_InfoUpdated?.Invoke();
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public async Task<bool> setAppInfo(List<LiManObj.ApplicativoDTO> newAppInfo, int numDays)
|
||||
{
|
||||
bool fatto = false;
|
||||
string cacheKey = $"{rkeyAppInfo}:{MasterKey}";
|
||||
var rawData = JsonConvert.SerializeObject(newAppInfo);
|
||||
await setRSV(cacheKey, rawData, numDays * cacheFact * 24);
|
||||
fatto = true;
|
||||
if (EA_InfoUpdated != null)
|
||||
{
|
||||
EA_InfoUpdated?.Invoke();
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
/// <summary>
|
||||
/// Chiave redis x attivazioni della licenza
|
||||
/// </summary>
|
||||
protected const string rKeyAttByLic = "LongCache:AttByLic";
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
@@ -329,198 +417,120 @@ namespace MP.Land.Data
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Public Methods
|
||||
#region Private Fields
|
||||
|
||||
public async Task<List<LiManObj.AttivazioneDTO>> ActivListCache()
|
||||
{
|
||||
List<LiManObj.AttivazioneDTO> dbResult = new List<LiManObj.AttivazioneDTO>();
|
||||
string cacheKey = $"{rKeyAttByLic}:{MasterKey}";
|
||||
trackCache(cacheKey);
|
||||
string rawData = await getRSV(cacheKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
var cacheRes = JsonConvert.DeserializeObject<List<LiManObj.AttivazioneDTO>?>(rawData);
|
||||
if (cacheRes != null)
|
||||
{
|
||||
dbResult = cacheRes;
|
||||
}
|
||||
}
|
||||
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
private static IConfiguration? _configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Verifica attivazione licenza
|
||||
/// URL dell'API x chiamate gestione licenze
|
||||
/// </summary>
|
||||
/// <param name="authKey"></param>
|
||||
private static string apiUrl = "https://liman.egalware.com/ELM.API/";
|
||||
|
||||
/// <summary>
|
||||
/// Chiave redis x info della licenza
|
||||
/// </summary>
|
||||
private static string rkeyAppInfo = "LongCache:AppInfo";
|
||||
|
||||
//private static string apiUrl = "https://localhost:44351/";
|
||||
private readonly IDistributedCache distributedCache;
|
||||
|
||||
/// <summary>
|
||||
/// Elenco obj in cache
|
||||
/// </summary>
|
||||
private List<string> cachedDataList = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Fattorte conversione cache sliding --> 1 h
|
||||
/// </summary>
|
||||
private int cacheFact = 12;
|
||||
|
||||
/// <summary>
|
||||
/// Durata assoluta massima della cache IN SECONDI
|
||||
/// </summary>
|
||||
private int chAbsExp = 60 * 5;
|
||||
|
||||
/// <summary>
|
||||
/// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire
|
||||
/// rimossa NON estende oltre il tempo massimo di validità della cache (chAbsExp)
|
||||
/// </summary>
|
||||
private int chSliExp = 60 * 1;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private static ILogger<LicenseService> _logger { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Opzioni cache con moltiplicatore durata risp durata base (1/5 minuti)
|
||||
/// </summary>
|
||||
/// <param name="multFact"></param>
|
||||
/// <returns></returns>
|
||||
public bool checkLicenseActive(string authKey)
|
||||
private DistributedCacheEntryOptions cacheOpt(int multFact)
|
||||
{
|
||||
bool answ = false;
|
||||
//cerco anche nelle info AKV
|
||||
if (AKVList != null)
|
||||
{
|
||||
var recLic = AKVList.Where(x => x.ValString == authKey).FirstOrDefault();
|
||||
int numLic = 0;
|
||||
//cerco in record
|
||||
if (recLic != null)
|
||||
{
|
||||
numLic = (int)recLic.ValInt;
|
||||
// verifico scadenza licenza!
|
||||
DateTime scadenza = licenseManGLS.expiryDateByAuthKey(Installazione, recLic.NomeVar, numLic, authKey);
|
||||
answ = scadenza > DateTime.Today;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"checkLicenseActive | Record non trovato per {authKey}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifica scadenza licenza
|
||||
/// </summary>
|
||||
/// <param name="authKey"></param>
|
||||
/// <returns></returns>
|
||||
public DateTime getLicenseExpiry(string authKey)
|
||||
{
|
||||
DateTime answ = DateTime.Today.AddDays(-1);
|
||||
//cerco anche nelle info AKV
|
||||
if (AKVList != null)
|
||||
{
|
||||
var recLic = AKVList.Where(x => x.ValString == authKey).FirstOrDefault();
|
||||
int numLic = 0;
|
||||
//cerco in record
|
||||
if (recLic != null)
|
||||
{
|
||||
numLic = (int)recLic.ValInt;
|
||||
// verifico scadenza licenza!
|
||||
DateTime scadenza = licenseManGLS.expiryDateByAuthKey(Installazione, recLic.NomeVar, numLic, authKey);
|
||||
answ = scadenza;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"getLicenseExpiry | Record non trovato per {authKey}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
var numSecAbsExp = chAbsExp * multFact;
|
||||
var numSecSliExp = chSliExp * multFact;
|
||||
return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato server gestione licenze
|
||||
/// Elenco attivazioni attuali
|
||||
/// </summary>
|
||||
public async Task<string> checkLimanServer()
|
||||
private async Task<List<LiManObj.AttivazioneDTO>?> OnlineActivationList()
|
||||
{
|
||||
string answ = "ND";
|
||||
List<LiManObj.AttivazioneDTO>? answ = new List<LiManObj.AttivazioneDTO>();
|
||||
// cerco online
|
||||
RestClient client = new RestClient(apiUrl);
|
||||
var request = new RestRequest($"api/health", Method.Get);
|
||||
//client.Authenticator = new HttpBasicAuthenticator("username", "password");
|
||||
string MKeyEnc = HttpUtility.UrlEncode(MasterKey);
|
||||
var request = new RestRequest($"api/attivazioni/?chiave={MKeyEnc}", Method.Get);
|
||||
var response = await client.GetAsync(request);
|
||||
// controllo risposta
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
// verifico risposta
|
||||
answ = response.Content.Replace("\"", "");
|
||||
// salvo in redis contenuto serializzato
|
||||
string rawData = $"{response.Content}";
|
||||
answ = JsonConvert.DeserializeObject<List<LiManObj.AttivazioneDTO>?>(rawData);
|
||||
}
|
||||
return await Task.FromResult(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init della classe con variabili di base da Redis/DB
|
||||
/// Recupera info licenza da remoto
|
||||
/// </summary>
|
||||
public bool InitAkv()
|
||||
private async Task<List<LiManObj.ApplicativoDTO>> OnlineAppInfo()
|
||||
{
|
||||
bool fatto = false;
|
||||
Applicazione = "MAPO";
|
||||
Installazione = getAVKStr("Installazione");
|
||||
MasterKey = getAVKStr(Applicazione);
|
||||
NumLicDb = getAVKInt(Applicazione);
|
||||
fatto = !string.IsNullOrEmpty($"{Installazione}{MasterKey}");
|
||||
return fatto;
|
||||
List<LiManObj.ApplicativoDTO>? answ = new List<LiManObj.ApplicativoDTO>();
|
||||
// cerco online
|
||||
RestClient client = new RestClient(apiUrl);
|
||||
string MKeyEnc = HttpUtility.UrlEncode(MasterKey);
|
||||
//string mKey = System.Net.WebUtility.UrlEncode(MasterKey);
|
||||
string reqUrl = $"api/licenza/{Installazione}?CodApp={Applicazione}&Chiave={MKeyEnc}";
|
||||
var request = new RestRequest(reqUrl, Method.Get);
|
||||
var response = await client.GetAsync(request);
|
||||
// controllo risposta
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
// verifico risposta
|
||||
string rawData = $"{response.Content}";
|
||||
answ = JsonConvert.DeserializeObject<List<LiManObj.ApplicativoDTO>?>(rawData);
|
||||
}
|
||||
// restituisce valori o insieme vuoto
|
||||
return await Task.FromResult(answ ?? new List<LiManObj.ApplicativoDTO>());
|
||||
}
|
||||
|
||||
public async Task<List<LiManObj.ApplicativoDTO>> LicAppCache()
|
||||
private void ReportUpdated()
|
||||
{
|
||||
List<LiManObj.ApplicativoDTO> dbResult = new List<LiManObj.ApplicativoDTO>();
|
||||
string cacheKey = $"{rkeyAppInfo}:{MasterKey}";
|
||||
trackCache(cacheKey);
|
||||
string rawData = await getRSV(cacheKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
var cacheRes = JsonConvert.DeserializeObject<List<LiManObj.ApplicativoDTO>?>(rawData);
|
||||
if (cacheRes != null)
|
||||
{
|
||||
dbResult = cacheRes;
|
||||
}
|
||||
}
|
||||
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init della classe con variabili di base da Redis/DB
|
||||
/// </summary>
|
||||
public async Task<bool> RefreshLicense()
|
||||
{
|
||||
bool fatto = false;
|
||||
// scadenza info a 15 gg...
|
||||
int numDays = 15;
|
||||
|
||||
// dati applicativo
|
||||
var appData = await OnlineAppInfo();
|
||||
if (appData != null)
|
||||
{
|
||||
if (appData.Count > 0)
|
||||
{
|
||||
fatto = await setAppInfo(appData, numDays);
|
||||
// salvo info licenza...
|
||||
NumLicRemote = appData[0].NumLicenze;
|
||||
}
|
||||
}
|
||||
|
||||
// dati attivazioni
|
||||
var onlineAct = await OnlineActivationList();
|
||||
if (onlineAct != null)
|
||||
{
|
||||
if (onlineAct.Count > 0)
|
||||
{
|
||||
infoExpiry = DateTime.Now.AddDays(numDays);
|
||||
ActivList = onlineAct;
|
||||
fatto = await setActivList(onlineAct, numDays);
|
||||
}
|
||||
}
|
||||
await Task.Delay(1);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<bool> setActivList(List<LiManObj.AttivazioneDTO> newActList, int numDays)
|
||||
{
|
||||
bool fatto = false;
|
||||
string cacheKey = $"{rKeyAttByLic}:{MasterKey}";
|
||||
var rawData = JsonConvert.SerializeObject(newActList);
|
||||
await setRSV(cacheKey, rawData, numDays * cacheFact * 24);
|
||||
fatto = true;
|
||||
if (EA_InfoUpdated != null)
|
||||
{
|
||||
EA_InfoUpdated?.Invoke();
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<bool> setAppInfo(List<LiManObj.ApplicativoDTO> newAppInfo, int numDays)
|
||||
{
|
||||
bool fatto = false;
|
||||
string cacheKey = $"{rkeyAppInfo}:{MasterKey}";
|
||||
var rawData = JsonConvert.SerializeObject(newAppInfo);
|
||||
await setRSV(cacheKey, rawData, numDays * cacheFact * 24);
|
||||
fatto = true;
|
||||
if (EA_InfoUpdated != null)
|
||||
{
|
||||
EA_InfoUpdated?.Invoke();
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>MP.Land</RootNamespace>
|
||||
<Version>6.16.2211.0416</Version>
|
||||
<Version>6.16.2211.1518</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -45,6 +45,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DiffMatchPatch" Version="1.0.3" />
|
||||
<PackageReference Include="Majorsoft.Blazor.Components.Debounce" Version="1.5.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="6.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"windowsAuthentication": true,
|
||||
"anonymousAuthentication": false,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:7314",
|
||||
"sslPort": 44311
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo gestione Programmi MAPO</i>
|
||||
<h4>Versione: 6.16.2211.0416</h4>
|
||||
<h4>Versione: 6.16.2211.1518</h4>
|
||||
<br />
|
||||
Note di rilascio:
|
||||
<ul>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2211.0416
|
||||
6.16.2211.1518
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2211.0416</version>
|
||||
<version>6.16.2211.1518</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
+14
-2
@@ -1,3 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authentication.Negotiate;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@@ -75,8 +76,8 @@ namespace MP.Land
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
//app.UseAuthentication();
|
||||
//app.UseAuthorization();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
@@ -103,6 +104,17 @@ namespace MP.Land
|
||||
o.SlidingExpiration = true;
|
||||
});
|
||||
|
||||
|
||||
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
|
||||
.AddNegotiate();
|
||||
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
// By default, all incoming requests will be authorized according to the default policy.
|
||||
options.FallbackPolicy = options.DefaultPolicy;
|
||||
});
|
||||
|
||||
|
||||
services.AddStackExchangeRedisCache(options =>
|
||||
{
|
||||
//options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 1, EndPoints = { { "localhost", 6379 } } };
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>MP.Stats</RootNamespace>
|
||||
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
|
||||
<Version>6.16.2210.2110</Version>
|
||||
<Version>6.16.2211.1517</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo statistiche MAPO</i>
|
||||
<h4>Versione: 6.16.2210.2110</h4>
|
||||
<h4>Versione: 6.16.2211.1517</h4>
|
||||
<br />
|
||||
Note di rilascio:
|
||||
<ul>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2210.2110
|
||||
6.16.2211.1517
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2210.2110</version>
|
||||
<version>6.16.2211.1517</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user