Modifica x gestione checkIp tutto in blazor (NO JS)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GPW.CORE.Comp
|
||||
{
|
||||
public class IpUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Restituisce l'IP v4 locale dato uno degli ip machcina (anche IPV6)
|
||||
/// </summary>
|
||||
/// <param name="firstIp"></param>
|
||||
/// <returns></returns>
|
||||
public static string getLocalIpv4(string firstIp)
|
||||
{
|
||||
string devIp = firstIp;
|
||||
IPAddress clientIP = IPAddress.Parse(devIp);
|
||||
IPHostEntry GetIPHost = Dns.GetHostEntry(clientIP);
|
||||
if (GetIPHost != null)
|
||||
{
|
||||
// se trovo + di 1 ip cerco il primo NON IPV6...
|
||||
if (GetIPHost.AddressList.Count() > 1)
|
||||
{
|
||||
foreach (IPAddress item in GetIPHost.AddressList)
|
||||
{
|
||||
if (item.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
devIp = item.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return devIp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GPW.CORE.Comp;
|
||||
using GPW.CORE.Data.DbModels;
|
||||
using GPW.CORE.Data.DTO;
|
||||
using GPW.CORE.Smart.Data;
|
||||
@@ -40,17 +41,13 @@ namespace GPW.CORE.Smart.Components
|
||||
{
|
||||
// var accessorie / base
|
||||
TimbratureModel currRecord = new TimbratureModel();
|
||||
string remoteIp = "";
|
||||
string ipv4 = "::";
|
||||
if (httpContextAccessor.HttpContext != null)
|
||||
{
|
||||
remoteIp = $"{httpContextAccessor.HttpContext.Connection?.RemoteIpAddress}";
|
||||
var remoteIp = $"{httpContextAccessor.HttpContext.Connection?.RemoteIpAddress}";
|
||||
// provo a recuperare ipV4...
|
||||
ipv4 = IpUtils.getLocalIpv4(remoteIp);
|
||||
}
|
||||
#if false
|
||||
if (ListTimbRich == null)
|
||||
{
|
||||
ListTimbRich = new List<TimbratureModel>();
|
||||
}
|
||||
#endif
|
||||
|
||||
// verifico se si trattasse di timbratura uscita da attività del giorno precedente...
|
||||
if (IsUscita)
|
||||
@@ -79,12 +76,8 @@ namespace GPW.CORE.Smart.Components
|
||||
CodTipoTimb = "Web",
|
||||
DataOra = ieri.AddDays(1).AddSeconds(-1),
|
||||
IdxDipendente = MService.IdxDipendente,
|
||||
Ipv4 = $"{remoteIp}"
|
||||
Ipv4 = $"{ipv4}"
|
||||
};
|
||||
#if false
|
||||
ListTimb.Add(currRecord);
|
||||
ListTimbRich.Add(currRecord);
|
||||
#endif
|
||||
await CDataServ.TimbratureUpdate(currRecord);
|
||||
|
||||
// aggiungo apertura ad oggi
|
||||
@@ -95,12 +88,8 @@ namespace GPW.CORE.Smart.Components
|
||||
CodTipoTimb = "Web",
|
||||
DataOra = ieri.AddDays(1),
|
||||
IdxDipendente = MService.IdxDipendente,
|
||||
Ipv4 = $"{remoteIp}"
|
||||
Ipv4 = $"{ipv4}"
|
||||
};
|
||||
#if false
|
||||
ListTimb.Add(currRecord);
|
||||
ListTimbRich.Add(currRecord);
|
||||
#endif
|
||||
await CDataServ.TimbratureUpdate(currRecord);
|
||||
}
|
||||
}
|
||||
@@ -114,14 +103,9 @@ namespace GPW.CORE.Smart.Components
|
||||
CodTipoTimb = "Web",
|
||||
DataOra = DataRif,
|
||||
IdxDipendente = MService.IdxDipendente,
|
||||
Ipv4 = $"{remoteIp}"
|
||||
Ipv4 = $"{ipv4}"
|
||||
};
|
||||
|
||||
#if false
|
||||
// aggiungo alla lista...
|
||||
ListTimb.Add(currRecord);
|
||||
ListTimbRich.Add(currRecord);
|
||||
#endif
|
||||
// aggiorno
|
||||
await CDataServ.TimbratureUpdate(currRecord);
|
||||
await Task.Delay(1);
|
||||
|
||||
@@ -21,6 +21,7 @@ using GPW.CORE.Data.DbModels;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace GPW.CORE.Smart.Pages
|
||||
{
|
||||
@@ -52,6 +53,8 @@ namespace GPW.CORE.Smart.Pages
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
[Inject]
|
||||
private IHttpContextAccessor httpContextAccessor { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Prova login da dati URL
|
||||
@@ -81,9 +84,20 @@ namespace GPW.CORE.Smart.Pages
|
||||
string devAgent = await JSRuntime.InvokeAsync<string>("getUserAgent");
|
||||
var dimension = await JSRuntime.InvokeAsync<WindowDimension>("getWindowDimensions");
|
||||
string screenSize = $"{dimension.Width}x{dimension.Height}";
|
||||
string devIp = await JSRuntime.InvokeAsync<string>("getIpAddress");
|
||||
string devIp = ":";
|
||||
if (httpContextAccessor.HttpContext != null)
|
||||
{
|
||||
var remoteIp = $"{httpContextAccessor.HttpContext.Connection?.RemoteIpAddress}";
|
||||
// provo a recuperare ipV4...
|
||||
devIp = IpUtils.getLocalIpv4(remoteIp);
|
||||
}
|
||||
|
||||
#if false
|
||||
string devIp = await JSRuntime.InvokeAsync<string>("getIpAddress");
|
||||
#endif
|
||||
IPAddress clientIP = IPAddress.Parse(devIp);
|
||||
IPHostEntry GetIPHost = Dns.GetHostEntry(clientIP);
|
||||
#if false
|
||||
// se trovo + di 1 ip cerco il primo NON IPV6...
|
||||
if (GetIPHost.AddressList.Count() > 1)
|
||||
{
|
||||
@@ -95,7 +109,9 @@ namespace GPW.CORE.Smart.Pages
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
List<string> compName = GetIPHost.HostName.ToString().Split('.').ToList();
|
||||
string devName = compName != null && compName.Count > 0 ? compName[0] : "NA";
|
||||
string rndTxt01 = SteamCrypto.RandomString(16, true);
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 31 KiB |
Reference in New Issue
Block a user