diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 28d7a489..35dea986 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,11 +24,6 @@ variables: dotnet nuget add source https://nexus.steamware.net/repository/nuget-proxy-v3/index.json -n nexus-proxy-v3 -u nugetUser -p viaDante16 --store-password-in-clear-text echo "Has Source: $hasSource" -.fixVers: &fixVers - - | - $VersScript = $env:APP_NAME + "\bin\publish\post-build.ps1 -ProjectDir $CI_PROJECT_DIR\$env:APP_NAME -ProjectPath $CI_PROJECT_DIR\$env:APP_NAME\$env:APP_NAME.csproj" - echo "Script called: $VersScript" - # helper creazione hash files x IIS .hashBuild: &hashBuild - | @@ -265,7 +260,8 @@ LAND:IIS01:deploy: - develop needs: ["LAND:test"] script: - - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj PROG:IIS01:deploy: stage: deploy @@ -281,7 +277,8 @@ PROG:IIS01:deploy: - develop needs: ["PROG:test"] script: - - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj STAT:IIS01:deploy: stage: deploy @@ -297,7 +294,8 @@ STAT:IIS01:deploy: - develop needs: ["STAT:test"] script: - - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj MON:IIS01:deploy: stage: deploy @@ -313,24 +311,8 @@ MON:IIS01:deploy: - develop needs: ["MON:test"] script: - - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj - -# WAMON:IIS01:deploy: -# stage: deploy -# tags: -# - win -# variables: -# PROJ_PATH: MP.WASM.Mon\Server -# APP_NAME: MP.WASM.Mon.Server -# SOL_NAME: MP-WAMON -# before_script: -# - *nuget-fix -# - dotnet restore "$env:SOL_NAME.sln" -# only: -# - develop -# needs: ["WAMON:test"] -# script: -# - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:PROJ_PATH/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj SPEC:IIS01:deploy: stage: deploy @@ -346,7 +328,8 @@ SPEC:IIS01:deploy: - develop needs: ["SPEC:test"] script: - - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS01.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj LAND:IIS02:deploy: stage: deploy @@ -362,8 +345,9 @@ LAND:IIS02:deploy: - master needs: ["LAND:build"] script: - - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj - - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj PROG:IIS02:deploy: stage: deploy @@ -379,8 +363,9 @@ PROG:IIS02:deploy: - master needs: ["PROG:build"] script: - - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj - - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj STAT:IIS02:deploy: stage: deploy @@ -396,8 +381,9 @@ STAT:IIS02:deploy: - master needs: ["STAT:build"] script: - - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj - - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj MON:IIS02:deploy: stage: deploy @@ -413,26 +399,9 @@ MON:IIS02:deploy: - master needs: ["MON:build"] script: - - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj - - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj - -# WAMON:IIS02:deploy: -# stage: deploy -# tags: -# - win -# variables: -# PROJ_PATH: MP.WASM.Mon\Server -# APP_NAME: MP.WASM.Mon.Server -# SOL_NAME: MP-WAMON -# before_script: -# - *nuget-fix -# - dotnet restore "$env:SOL_NAME.sln" -# only: -# - master -# needs: ["WAMON:build"] -# script: -# - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:PROJ_PATH/$env:APP_NAME.csproj -# - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:PROJ_PATH/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj SPEC:IIS02:deploy: stage: deploy @@ -448,8 +417,9 @@ SPEC:IIS02:deploy: - master needs: ["SPEC:build"] script: - - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj - - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS02.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IIS03.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release -p:username=jenkins -p:Password=viadante16 -p:AllowUntrustedCertificate=true -p:verbosity=quiet $env:APP_NAME/$env:APP_NAME.csproj LAND:installer: stage: installer @@ -467,9 +437,9 @@ LAND:installer: - master needs: ["LAND:build"] script: - - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish -p:verbosity=quiet # qui il deploy su nexus... - - *fixVers - *hashBuild - *nexusUpload @@ -489,9 +459,9 @@ PROG:installer: - master needs: ["PROG:build"] script: - - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish -p:verbosity=quiet # qui il deploy su nexus... - - *fixVers - *hashBuild - *nexusUpload @@ -511,9 +481,9 @@ STAT:installer: - master needs: ["STAT:build"] script: - - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish -p:verbosity=quiet # qui il deploy su nexus... - - *fixVers - *hashBuild - *nexusUpload @@ -533,34 +503,12 @@ MON:installer: - master needs: ["MON:build"] script: - - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish -p:verbosity=quiet # qui il deploy su nexus... - - *fixVers - *hashBuild - *nexusUpload -# WAMON:installer: -# stage: installer -# tags: -# - win -# variables: -# PROJ_PATH: MP.WASM.Mon\Server -# APP_NAME: MP.WASM.Mon.Server -# SOL_NAME: MP-WAMON -# NEXUS_PATH: MP-WAMON -# before_script: -# - *nuget-fix -# - dotnet restore "$env:SOL_NAME.sln" -# only: -# - develop -# - master -# needs: ["WAMON:build"] -# script: -# - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:PROJ_PATH/$env:APP_NAME.csproj -o:publish -# # qui il deploy su nexus... -# - *hashBuild -# - *nexusUpload - SPEC:installer: stage: installer tags: @@ -577,9 +525,9 @@ SPEC:installer: - master needs: ["SPEC:build"] script: - - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release $env:APP_NAME/$env:APP_NAME.csproj -o:publish -p:verbosity=quiet # qui il deploy su nexus... - - *fixVers - *hashBuild - *nexusUpload @@ -605,7 +553,8 @@ LAND:release: paths: - publish/ script: - - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj -p:verbosity=quiet PROG:release: stage: release @@ -629,7 +578,8 @@ PROG:release: paths: - publish/ script: - - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj -p:verbosity=quiet STAT:release: stage: release @@ -653,7 +603,8 @@ STAT:release: paths: - publish/ script: - - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj -p:verbosity=quiet MON:release: stage: release @@ -675,30 +626,8 @@ MON:release: paths: - publish/ script: - - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj - -# WAMON:release: -# stage: release -# tags: -# - win -# variables: -# PROJ_PATH: MP.WASM.Mon\Server -# APP_NAME: MP.WASM.Mon.Server -# SOL_NAME: MP-WAMON -# NEXUS_PATH: MP-WAMON -# before_script: -# - *nuget-fix -# - dotnet restore "$env:SOL_NAME.sln" -# only: -# - tags -# except: -# - branches -# needs: ["WAMON:build"] -# artifacts: -# paths: -# - publish/ -# script: -# - dotnet publish -c Release -o ./publish $env:PROJ_PATH/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj -p:verbosity=quiet SPEC:release: stage: release @@ -720,5 +649,6 @@ SPEC:release: paths: - publish/ script: - - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + - dotnet publish -c Release -o ./publish $env:APP_NAME/$env:APP_NAME.csproj -p:verbosity=quiet diff --git a/Egw.Core/SteamCrypto.cs b/Egw.Core/SteamCrypto.cs index 1f021d25..2373a2fc 100644 --- a/Egw.Core/SteamCrypto.cs +++ b/Egw.Core/SteamCrypto.cs @@ -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; diff --git a/Egw.Core/licenseManGLS.cs b/Egw.Core/licenseManGLS.cs index fccea72c..c7108110 100644 --- a/Egw.Core/licenseManGLS.cs +++ b/Egw.Core/licenseManGLS.cs @@ -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); } diff --git a/MP.INVE/Components/CmpTop.razor.cs b/MP.INVE/Components/CmpTop.razor.cs index 58555dde..4886214a 100644 --- a/MP.INVE/Components/CmpTop.razor.cs +++ b/MP.INVE/Components/CmpTop.razor.cs @@ -1,13 +1,14 @@ using Blazored.SessionStorage; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.Extensions.Configuration; using Microsoft.JSInterop; using MP.Data.DTO; using MP.INVE.Data; namespace MP.INVE.Components { - public partial class CmpTop + public partial class CmpTop:IDisposable { #region Public Methods @@ -42,6 +43,8 @@ namespace MP.INVE.Components protected override async Task OnInitializedAsync() { + LServ.EA_LogIn += LServ_EA_LogIn; + LServ.EA_LogOut += LServ_EA_LogOut; await forceReload(); } protected async Task getId() @@ -58,11 +61,20 @@ namespace MP.INVE.Components } } + private void LServ_EA_LogOut() + { + NavManager.NavigateTo("OperatoreLogin", true); + } + + private void LServ_EA_LogIn() + { + NavManager.NavigateTo("Starter", true); + } + #endregion Protected Methods #region Private Fields - private string userName = ""; #endregion Private Fields @@ -79,7 +91,32 @@ namespace MP.INVE.Components private async Task forceReload() { +<<<<<<< HEAD + await Task.Delay(1); + // controllo per login + if (LServ.matrOpr <= 0 && !NavManager.Uri.Contains("OperatoreLogin")) + { + NavManager.NavigateTo("OperatoreLogin", true); + } + } + + private async Task logOut() + { + await Task.Delay(1); + LServ.LogOut(); + } + + private string userName + { + get + { + string answ = "ND"; + answ = $"{LServ.Cognome} {LServ.Cognome} ({LServ.matrOpr})"; + return answ; + } +======= await getId(); +>>>>>>> develop } private async void MService_EA_ShowSearch() diff --git a/MP.INVE/Data/LoginService.cs b/MP.INVE/Data/LoginService.cs new file mode 100644 index 00000000..dd08f946 --- /dev/null +++ b/MP.INVE/Data/LoginService.cs @@ -0,0 +1,255 @@ +using MP.Data.DTO; +using Newtonsoft.Json; +using NLog; +using StackExchange.Redis; +using System.Diagnostics; + +namespace MP.INVE.Data +{ + public class LoginService : IDisposable + { + #region Public Constructors + + public LoginService(IConfiguration configuration, ILogger logger, HttpClient httpClient, + IHttpContextAccessor httpContextAccessor) + { + this.HttpClient = httpClient; + HttpContextAccessor = httpContextAccessor; + + _logger = logger; + _logger.LogInformation("Starting LoginService INIT"); + _configuration = configuration; + + // setup compoenti REDIS + redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis")); + redisConnAdmin = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("RedisAdmin")); + redisDb = redisConn.GetDatabase(); + + // leggo cache lungo periodo + int.TryParse(_configuration.GetValue("ServerConf:redisLongTimeCache"), out redisLongTimeCache); + + _logger.LogInformation("Redis LoginService INIT"); + } + + #endregion Public Constructors + + #region Public Events + + public event Action EA_LogIn = null!; + + public event Action EA_LogOut = null!; + + #endregion Public Events + + #region Public Properties + + public string Cognome + { + get + { + string answ = "NA"; + if (matrOpr > 0 && !string.IsNullOrEmpty(authKey)) + { + var currUser = UserDTO(matrOpr, authKey); + if (currUser != null) + { + answ = currUser.Cognome; + } + } + return answ; + } + } + + public int matrOpr + { + get + { + int answ = 0; + if (HttpContextAccessor.HttpContext != null) + { +#if false + var token = HttpContextAccessor.HttpContext.Request.Cookies["userId_token"]; + if (token != null) + { + int.TryParse(token, out answ); + } +#endif + var currUser = UserDTO(matrOpr, authKey); + if (currUser != null) + { + answ = currUser.MatrOpr; + } + } + return answ; + } + set + { + CookieOptions options = new CookieOptions(); + options.Expires = DateTime.Now.AddDays(1); + if (HttpContextAccessor.HttpContext != null) + { + HttpContextAccessor.HttpContext.Response.Cookies.Append("userId_token", $"{value}", options); + } + } + } + + public string Nome + { + get + { + string answ = "NA"; + if (matrOpr > 0 && !string.IsNullOrEmpty(authKey)) + { + var currUser = UserDTO(matrOpr, authKey); + if (currUser != null) + { + answ = currUser.Nome; + } + } + return answ; + } + } + + #endregion Public Properties + + #region Public Methods + + public void Dispose() + { + } + + public void LogOut() + { + OperatoreDTO resetData = new OperatoreDTO(); + UserDTOSave(resetData); + } + + /// + /// Ricerca su REDIS dell'utente loggato + /// NB: da rifare con unico JWT che contenga tutto + /// + /// + /// + /// + public OperatoreDTO? UserDTO(int matrOpr, string authKey) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + OperatoreDTO? result = null; + string source = "REDIS"; + // cerco in redis... + RedisValue rawData = redisDb.StringGet($"{redisUserSession}:{matrOpr}"); + if (!string.IsNullOrEmpty($"{rawData}")) + { + try + { + result = JsonConvert.DeserializeObject($"{rawData}"); + } + catch + { } + } +#if false + else + { + result = await Task.FromResult(dbController.AnagStatiComm()); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(redisUserSession, rawData, getRandTOut(redisLongTimeCache)); + source = "DB"; + } +#endif + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"LoggedUser Read from {source}: {ts.TotalMilliseconds}ms"); + // restituisco + return result; + } + + /// + /// Salva su REDIS dati dell'utente loggato + /// + /// + public bool UserDTOSave(OperatoreDTO userData) + { + bool fatto = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + + string source = "REDIS"; + // cerco in redis... + string rawData = JsonConvert.SerializeObject(userData); + fatto = redisDb.StringSet($"{redisUserSession}:{userData.MatrOpr}", rawData, TimeSpan.FromMinutes(60)); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"UserDTO write to {source}: {ts.TotalMilliseconds}ms"); + // restituisco + return fatto; + } + + #endregion Public Methods + + #region Protected Properties + + protected string authKey + { + get + { + string answ = ""; + if (HttpContextAccessor.HttpContext != null) + { + var token = HttpContextAccessor.HttpContext.Request.Cookies["authKey_token"]; + if (token != null) + { + answ = token; + } + } + return answ; + } + set + { + CookieOptions options = new CookieOptions(); + options.Expires = DateTime.Now.AddDays(1); + + if (HttpContextAccessor.HttpContext != null) + { + HttpContextAccessor.HttpContext.Response.Cookies.Append("authKey_token", value, options); + } + } + } + + protected HttpClient HttpClient { get; set; } + protected IHttpContextAccessor HttpContextAccessor { get; set; } + + #endregion Protected Properties + + #region Private Fields + + private const string redisBaseAddr = "MP:INVE"; + + private const string redisUserSession = redisBaseAddr + ":User:"; + private static IConfiguration _configuration = null!; + + private static ILogger _logger = null!; + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + /// + /// Oggetto per connessione a REDIS + /// + private ConnectionMultiplexer redisConn = null!; + + /// + /// Oggetto per connessione a REDIS modalità admin (ex flux dati) + /// + private ConnectionMultiplexer redisConnAdmin = null!; + + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + private IDatabase redisDb = null!; + + private int redisLongTimeCache = 5; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/MP.INVE/Data/MessageService.cs b/MP.INVE/Data/MessageService.cs index 99dc18df..985557d0 100644 --- a/MP.INVE/Data/MessageService.cs +++ b/MP.INVE/Data/MessageService.cs @@ -53,7 +53,7 @@ get => searchVal; set { - //if (searchVal != value) + //if (_nome != value) //{ searchVal = value; diff --git a/MP.INVE/Data/MpDataService.cs b/MP.INVE/Data/MpDataService.cs index 13c3ee36..e44df918 100644 --- a/MP.INVE/Data/MpDataService.cs +++ b/MP.INVE/Data/MpDataService.cs @@ -1090,37 +1090,37 @@ namespace MP.INVE.Data #region Private Fields - private const string redisArtByDossier = redisBaseAddr + "SPEC:Cache:ArtByDossier"; + private const string redisArtByDossier = redisBaseAddr + ":Cache:ArtByDossier"; - private const string redisArtList = redisBaseAddr + "SPEC:Cache:ArtList"; + private const string redisArtList = redisBaseAddr + ":Cache:ArtList"; - private const string redisBaseAddr = "MP:"; + private const string redisBaseAddr = "MP:SPEC"; - private const string redisConfKey = redisBaseAddr + "SPEC:Cache:Config"; + private const string redisConfKey = redisBaseAddr + ":Cache:Config"; - private const string redisDossByMac = redisBaseAddr + "SPEC:Cache:DossByMac"; + private const string redisDossByMac = redisBaseAddr + ":Cache:DossByMac"; - private const string redisFluxByMac = redisBaseAddr + "SPEC:Cache:FluxByMac"; + private const string redisFluxByMac = redisBaseAddr + ":Cache:FluxByMac"; - private const string redisFluxLogFilt = redisBaseAddr + "SPEC:Cache:FluxLogFilt"; + private const string redisFluxLogFilt = redisBaseAddr + ":Cache:FluxLogFilt"; - private const string redisMacByFlux = redisBaseAddr + "SPEC:Cache:MacByFlux"; + private const string redisMacByFlux = redisBaseAddr + ":Cache:MacByFlux"; - private const string redisMacList = redisBaseAddr + "SPEC:Cache:MacList"; + private const string redisMacList = redisBaseAddr + ":Cache:MacList"; - private const string redisOdlCurrByMac = redisBaseAddr + "SPEC:Cache:OdlByMac"; + private const string redisOdlCurrByMac = redisBaseAddr + ":Cache:OdlByMac"; - private const string redisPOdlList = redisBaseAddr + "SPEC:Cache:POdlList"; + private const string redisPOdlList = redisBaseAddr + ":Cache:POdlList"; - private const string redisPOdlByPOdl = redisBaseAddr + "SPEC:Cache:POdlByPOdl"; + private const string redisPOdlByPOdl = redisBaseAddr + ":Cache:POdlByPOdl"; - private const string redisPOdlByOdl = redisBaseAddr + "SPEC:Cache:POdlByOdl"; + private const string redisPOdlByOdl = redisBaseAddr + ":Cache:POdlByOdl"; - private const string redisStatoCom = redisBaseAddr + "SPEC:Cache:StatoCom"; + private const string redisStatoCom = redisBaseAddr + ":Cache:StatoCom"; - private const string redisTipoArt = redisBaseAddr + "SPEC:Cache:TipoArt"; + private const string redisTipoArt = redisBaseAddr + ":Cache:TipoArt"; - private const string redisVocabolario = redisBaseAddr + "SPEC:Cache:Vocabolario"; + private const string redisVocabolario = redisBaseAddr + ":Cache:Vocabolario"; private static IConfiguration _configuration = null!; diff --git a/MP.INVE/Program.cs b/MP.INVE/Program.cs index 8b050128..1fc24ee7 100644 --- a/MP.INVE/Program.cs +++ b/MP.INVE/Program.cs @@ -36,6 +36,7 @@ builder.Services.AddAuthorization(options => builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); +builder.Services.AddHttpContextAccessor(); builder.Services.AddSingleton(redisMultiplexer); builder.Services.AddSingleton(); builder.Services.AddScoped(); diff --git a/MP.INVE/README.md b/MP.INVE/README.md index 788e177f..1b2c06b3 100644 --- a/MP.INVE/README.md +++ b/MP.INVE/README.md @@ -185,8 +185,8 @@ Invio aggregato dei dati di # Revisione Documento -| Date | Edit | Version | Note | -|------------|----------------|:-------:|-----------------:| -| 2022.11.10 | S.E. Locatelli | 0.1 | Initial draft | -| 2022.11.10 | Gian / Zac | 0.2 | Second draft | -| 2022.11.16 | Zac | 0.3 | Aggiunta condizione modifica previo controllo esistenza | +| Date | Edit | Version | Note | +| ---------- | -------------- | :-----: | ------------------------------------------------------: | +| 2022.11.10 | S.E. Locatelli | 0.1 | Initial draft | +| 2022.11.10 | Gian / Zac | 0.2 | Second draft | +| 2022.11.16 | Zac | 0.3 | Aggiunta condizione modifica previo controllo esistenza | diff --git a/MP.INVE/README.pdf b/MP.INVE/README.pdf index be7a8d21..cc873d27 100644 Binary files a/MP.INVE/README.pdf and b/MP.INVE/README.pdf differ diff --git a/MP.Land/Components/CmpTop.razor b/MP.Land/Components/CmpTop.razor index 534995a0..cb7100a0 100644 --- a/MP.Land/Components/CmpTop.razor +++ b/MP.Land/Components/CmpTop.razor @@ -4,12 +4,12 @@ @using MP.Land.Data @inject MessageService AppMessages -@*@inject AuthenticationStateProvider AuthenticationStateProvider*@ +@inject AuthenticationStateProvider AuthenticationStateProvider
@**@ - @* @userName*@ + @userName
@PageName diff --git a/MP.Land/Components/CmpTop.razor.cs b/MP.Land/Components/CmpTop.razor.cs index 1706938e..7b3b7d14 100644 --- a/MP.Land/Components/CmpTop.razor.cs +++ b/MP.Land/Components/CmpTop.razor.cs @@ -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 diff --git a/MP.Land/Data/LicenseService.cs b/MP.Land/Data/LicenseService.cs index baeb055c..ede92400 100644 --- a/MP.Land/Data/LicenseService.cs +++ b/MP.Land/Data/LicenseService.cs @@ -12,6 +12,8 @@ using System.Text; using System.Threading.Tasks; using System.Web; +#nullable enable + namespace MP.Land.Data { /// @@ -19,56 +21,6 @@ namespace MP.Land.Data /// public class LicenseService { - #region Private Fields - - private static IConfiguration? _configuration; - private static ILogger? _logger; - - /// - /// URL dell'API x chiamate gestione licenze - /// - private static string apiUrl = "https://liman.egalware.com/ELM.API/"; - //private static string apiUrl = "https://localhost:44351/"; - - /// - /// Chiave redis x info della licenza - /// - private static string rkeyAppInfo = "LongCache:AppInfo"; - - private readonly IDistributedCache distributedCache; - - /// - /// Elenco obj in cache - /// - private List cachedDataList = new List(); - - /// - /// Fattorte conversione cache sliding --> 1 h - /// - private int cacheFact = 12; - - /// - /// Durata assoluta massima della cache IN SECONDI - /// - private int chAbsExp = 60 * 5; - - /// - /// 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) - /// - private int chSliExp = 60 * 1; - - #endregion Private Fields - - #region Protected Fields - - /// - /// Chiave redis x attivazioni della licenza - /// - protected const string rKeyAttByLic = "LongCache:AttByLic"; - - #endregion Protected Fields - #region Public Constructors /// @@ -95,9 +47,7 @@ namespace MP.Land.Data #region Public Properties public List ActivList { get; set; } = new List(); - public List AKVList { get; set; } = new List(); - 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 - /// - /// Opzioni cache con moltiplicatore durata risp durata base (1/5 minuti) - /// - /// - /// - private DistributedCacheEntryOptions cacheOpt(int multFact) + public async Task> ActivListCache() { - var numSecAbsExp = chAbsExp * multFact; - var numSecSliExp = chSliExp * multFact; - return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); - } - - /// - /// Elenco attivazioni attuali - /// - private async Task?> OnlineActivationList() - { - List? answ = new List(); - // 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 dbResult = new List(); + 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?>(rawData); + var cacheRes = JsonConvert.DeserializeObject?>(rawData); + if (cacheRes != null) + { + dbResult = cacheRes; + } } - return await Task.FromResult(answ); + + return await Task.FromResult(dbResult); } /// - /// Recupera info licenza da remoto + /// Verifica attivazione licenza /// - private async Task> OnlineAppInfo() + /// + /// + public bool checkLicenseActive(string authKey) { - List answ = new List(); + 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; + } + + /// + /// Stato server gestione licenze + /// + public async Task 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?>(rawData); + if (response.Content != null) + { + answ = response.Content.Replace("\"", ""); + } } return await Task.FromResult(answ); } - private void ReportUpdated() + /// + /// Verifica scadenza licenza + /// + /// + /// + 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; + } + + /// + /// Init della classe con variabili di base da Redis/DB + /// + 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> LicAppCache() + { + List dbResult = new List(); + string cacheKey = $"{rkeyAppInfo}:{MasterKey}"; + trackCache(cacheKey); + string rawData = await getRSV(cacheKey); + if (!string.IsNullOrEmpty(rawData)) + { + var cacheRes = JsonConvert.DeserializeObject?>(rawData); + if (cacheRes != null) + { + dbResult = cacheRes; + } + } + + return await Task.FromResult(dbResult); + } + + /// + /// Init della classe con variabili di base da Redis/DB + /// + public async Task 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 setActivList(List 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 setAppInfo(List 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 + + /// + /// Chiave redis x attivazioni della licenza + /// + 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> ActivListCache() - { - List dbResult = new List(); - string cacheKey = $"{rKeyAttByLic}:{MasterKey}"; - trackCache(cacheKey); - string rawData = await getRSV(cacheKey); - if (!string.IsNullOrEmpty(rawData)) - { - var cacheRes = JsonConvert.DeserializeObject?>(rawData); - if (cacheRes != null) - { - dbResult = cacheRes; - } - } - - return await Task.FromResult(dbResult); - } + private static IConfiguration? _configuration; /// - /// Verifica attivazione licenza + /// URL dell'API x chiamate gestione licenze /// - /// + private static string apiUrl = "https://liman.egalware.com/ELM.API/"; + + /// + /// Chiave redis x info della licenza + /// + private static string rkeyAppInfo = "LongCache:AppInfo"; + + //private static string apiUrl = "https://localhost:44351/"; + private readonly IDistributedCache distributedCache; + + /// + /// Elenco obj in cache + /// + private List cachedDataList = new List(); + + /// + /// Fattorte conversione cache sliding --> 1 h + /// + private int cacheFact = 12; + + /// + /// Durata assoluta massima della cache IN SECONDI + /// + private int chAbsExp = 60 * 5; + + /// + /// 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) + /// + private int chSliExp = 60 * 1; + + #endregion Private Fields + + #region Private Properties + + private static ILogger _logger { get; set; } = null!; + + #endregion Private Properties + + #region Private Methods + + /// + /// Opzioni cache con moltiplicatore durata risp durata base (1/5 minuti) + /// + /// /// - 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; - } - /// - /// Verifica scadenza licenza - /// - /// - /// - 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)); } /// - /// Stato server gestione licenze + /// Elenco attivazioni attuali /// - public async Task checkLimanServer() + private async Task?> OnlineActivationList() { - string answ = "ND"; + List? answ = new List(); // 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?>(rawData); } return await Task.FromResult(answ); } /// - /// Init della classe con variabili di base da Redis/DB + /// Recupera info licenza da remoto /// - public bool InitAkv() + private async Task> OnlineAppInfo() { - bool fatto = false; - Applicazione = "MAPO"; - Installazione = getAVKStr("Installazione"); - MasterKey = getAVKStr(Applicazione); - NumLicDb = getAVKInt(Applicazione); - fatto = !string.IsNullOrEmpty($"{Installazione}{MasterKey}"); - return fatto; + List? answ = new List(); + // 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?>(rawData); + } + // restituisce valori o insieme vuoto + return await Task.FromResult(answ ?? new List()); } - public async Task> LicAppCache() + private void ReportUpdated() { - List dbResult = new List(); - string cacheKey = $"{rkeyAppInfo}:{MasterKey}"; - trackCache(cacheKey); - string rawData = await getRSV(cacheKey); - if (!string.IsNullOrEmpty(rawData)) - { - var cacheRes = JsonConvert.DeserializeObject?>(rawData); - if (cacheRes != null) - { - dbResult = cacheRes; - } - } - - return await Task.FromResult(dbResult); - } - - /// - /// Init della classe con variabili di base da Redis/DB - /// - public async Task 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 setActivList(List 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 setAppInfo(List 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 } } \ No newline at end of file diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index e5d244a5..f9e55a89 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net6.0 MP.Land - 6.16.2211.0416 + 6.16.2211.1518 @@ -45,6 +45,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MP.Land/Properties/launchSettings.json b/MP.Land/Properties/launchSettings.json index aeaf5b5b..7f84d546 100644 --- a/MP.Land/Properties/launchSettings.json +++ b/MP.Land/Properties/launchSettings.json @@ -1,7 +1,7 @@ { "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, + "windowsAuthentication": true, + "anonymousAuthentication": false, "iisExpress": { "applicationUrl": "http://localhost:7314", "sslPort": 44311 diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index 9fbcacb8..d340f879 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo gestione Programmi MAPO -

Versione: 6.16.2211.0416

+

Versione: 6.16.2211.1518


Note di rilascio:
    diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index 3af0d134..b3babe51 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2211.0416 +6.16.2211.1518 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index 2f81485a..3baa45d2 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2211.0416 + 6.16.2211.1518 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false diff --git a/MP.Land/Startup.cs b/MP.Land/Startup.cs index c599a8b6..e8f91d80 100644 --- a/MP.Land/Startup.cs +++ b/MP.Land/Startup.cs @@ -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 } } }; diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 8683fb68..39ac2560 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net6.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 6.16.2210.2110 + 6.16.2211.1517 diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index c3a834ed..5e47116b 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

    Versione: 6.16.2210.2110

    +

    Versione: 6.16.2211.1517


    Note di rilascio:
      diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index 148d3a17..b5d4a429 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2210.2110 +6.16.2211.1517 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index b9e7e7bc..920440d2 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2210.2110 + 6.16.2211.1517 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false