Code backup
This commit is contained in:
2026-05-10 16:59:01 +02:00
commit 368d6fafea
796 changed files with 315310 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
@page
@model webapp_local.Pages.IT.UserListModel
@{
ViewData["Title"] = "Elenco Utenti";
}
@section ToolBar {
@(Html.DevExtreme().Toolbar()
.Items(items =>
{
items.Add()
.Widget(w => w
.Button()
.Icon("menu")
.OnClick("webapp_shared.onMenuButtonClick")
)
.Location(ToolbarItemLocation.Before);
items.Add()
.Template(
@<text>
<div class="toolbar-label">
<h4 id="helpText" style="display: block; margin: 0px;"><i class='@Model.NavigationItem.Icon'></i>&nbsp&nbsp @Model.NavigationItem.Text</h4>
</div>
</text>
)
.LocateInMenu(ToolbarItemLocateInMenuMode.Never)
.Location(ToolbarItemLocation.Center);
items.Add()
.Widget(w => w
.Button()
.ID("btnAutoRefresh")
.Icon("fas fa-recycle")
.Hint("Refresh dei dati")
.OnClick("reloadData")
)
.Location(ToolbarItemLocation.After);
})
)
}
<div id="mainDiv" class="justify-content-center">
@(Html.DevExtreme().DataGrid()
.ID("gridADUser")
.DataSource(d => d.RemoteController().LoadUrl(Url.Page("UserList", "ADUserData")).Key("id"))
.LoadPanel(loadPanel => loadPanel.Enabled(false))
.Scrolling(scrolling => scrolling.Mode(GridScrollingMode.Infinite))
.Sorting(sorting => sorting.Mode(GridSortingMode.None))
.Columns(c =>
{
c.Add().DataField("initials").Caption("Sigla").SortOrder(SortOrder.Asc);
c.Add().DataField("samAccountName").Caption("UserName");
c.Add().DataField("name").Caption("Nome");
})
.WordWrapEnabled(true)
.ShowBorders(true)
.FilterRow(f => f.Visible(true))
.FilterPanel(fp => fp.Visible(true))
.HeaderFilter(f => f.Visible(true))
.RemoteOperations(true)
.ColumnAutoWidth(true)
.AllowColumnResizing(true)
.CacheEnabled(true)
.RowAlternationEnabled(true)
.CustomizeColumns("customizeColumns")
)
</div>
@section scripts {
<script>
var gridADUser;
$(document).ready(function () {
gridADUser = $("#gridADUser").dxDataGrid("instance");
$(window).resize(function () {
if (gridADUser != null) {
var res = layoutdrawer.option('height') - 15;
if (res < 200)
res = 200;
gridADUser.option("height", res);
}
});
$(window).resize();
});
function reloadData() {
gridADUser.getDataSource().reload();
}
</Script>
}
+51
View File
@@ -0,0 +1,51 @@
using DevExtreme.AspNet.Data;
using DevExtreme.AspNet.Mvc;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Localization;
using System.Collections.Generic;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Threading.Tasks;
using webapp_local.Models;
using webapp_shared;
using webapp_shared.Code;
namespace webapp_local.Pages.IT
{
[UserPermissionsOneOfThesePolicies("CanViewUserList")]
[BindProperties]
public class UserListModel : _LayoutModel
{
public UserListModel(IStringLocalizer<_LayoutModel> _localizer, IConfiguration _config, UserManager<ApplicationUser> _userManager) : base(_localizer, _config, _userManager)
{
}
public async Task<JsonResult> OnGetADUserData(DataSourceLoadOptions options)
{
var ret = new List<ArrayADUser>();
int index = 0;
using (var context = new PrincipalContext(ContextType.Domain, "pal.local"))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
ret.Add(new ArrayADUser()
{
id = index++,
Initials = de.Properties.Contains("Initials") ? de.Properties["Initials"].Value.ToString() : "",
SamAccountName = de.Properties.Contains("SamAccountName") ? de.Properties["SamAccountName"].Value.ToString() : "",
Name = de.Properties.Contains("Name") ? de.Properties["Name"].Value.ToString() : "",
});
}
}
}
return new JsonResult(DataSourceLoader.Load(ret, options));
}
}
}
+87
View File
@@ -0,0 +1,87 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Moq;
using webapp_italsort.DataItalsortGestionale;
using webapp_italsort.Repositories.SharePoint;
namespace library_spo_utils.test
{
[TestClass]
public class NonComplianceSettingsRepositoryTest
{
private readonly NonComplianceSettingsRepository _sut;
private readonly Mock<IDbContextFactory<Db_ItalsortGestionaleContext>> _factoryMock = new Mock<IDbContextFactory<Db_ItalsortGestionaleContext>>();
private readonly Mock<IHttpContextAccessor> _accessorMock = new Mock<IHttpContextAccessor>();
private Db_ItalsortGestionaleContext _context;
public NonComplianceSettingsRepositoryTest()
{
_sut = new NonComplianceSettingsRepository(_factoryMock.Object);
}
[TestInitialize]
public void Setup()
{
var httpContext = new DefaultHttpContext();
var fakeTenantId = "abcd";
httpContext.Request.Headers["Tenant-ID"] = fakeTenantId;
_accessorMock.Setup(_ => _.HttpContext).Returns(httpContext);
var options = new DbContextOptionsBuilder<Db_ItalsortGestionaleContextDefault>()
.UseInMemoryDatabase("InMemoryTest")
.Options;
_context = new Db_ItalsortGestionaleContext(options, _accessorMock.Object);
_factoryMock.Setup(x => x.CreateDbContext()).Returns(_context);
}
[TestMethod]
[DataRow("codice-test")]
public async Task GetCode_ShouldReturn_Instance(string code)
{
var record = new InventNonConformanceTable()
{
Code = code
};
_context.InventNonConformanceTable.Add(record);
await _context.SaveChangesAsync();
var result = _sut.GetByCode(code);
Assert.IsNotNull(result);
Assert.AreEqual(code, result.Code);
}
[TestMethod]
[DataRow("codice", "NC23", "00012", "NC23-00012")]
public async Task DefaultNonComplianceProject_Should_Return_ProjId(string code, string projId, string subProj,string projConcat)
{
var record = new InventNonConformanceTable()
{
Code = code,
Proj = new ProjTable()
{
ProjId = projId,
Name = ""
},
SubProj = new SubProjTable()
{
SubProjId = subProj,
}
};
_context.InventNonConformanceTable.Add(record);
await _context.SaveChangesAsync();
var projIdResult = _sut.DefaultNonComplianceProject(code);
Assert.IsNotNull(projIdResult);
Assert.AreEqual(projConcat, projIdResult);
}
}
}
+1878
View File
File diff suppressed because it is too large Load Diff
+142
View File
@@ -0,0 +1,142 @@
using System;
using System.Net;
using System.Linq;
using System.Collections;
using System.Runtime.InteropServices;
namespace devlist
{
public class IPEnumeration: IEnumerable
{
private string startAddress;
private string endAddress;
internal static Int64 AddressToInt(IPAddress addr)
{
byte[] addressBits = addr.GetAddressBytes();
Int64 retval = 0;
for (int i = 0; i < addressBits.Length; i++)
{
retval = (retval << 8) + (int)addressBits[i];
}
return retval;
}
internal static Int64 AddressToInt(string addr)
{
return AddressToInt(IPAddress.Parse(addr));
}
internal static IPAddress IntToAddress(Int64 addr)
{
return IPAddress.Parse(addr.ToString());
}
public IPEnumeration(string startAddress, string endAddress)
{
this.startAddress = startAddress;
this.endAddress = endAddress;
}
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator) GetEnumerator();
}
public IPEnumerator GetEnumerator()
{
return new IPEnumerator(startAddress, endAddress);
}
}
public class IPEnumerator: IEnumerator
{
private string startAddress;
private string endAddress;
private Int64 currentIP;
private Int64 endIP;
public IPEnumerator(string startAddress, string endAddress)
{
this.startAddress = startAddress;
this.endAddress = endAddress;
currentIP = IPEnumeration.AddressToInt(startAddress);
endIP = IPEnumeration.AddressToInt(endAddress);
}
public bool MoveNext()
{
currentIP++;
return (currentIP <= endIP);
}
public void Reset()
{
currentIP = IPEnumeration.AddressToInt(startAddress);
}
object IEnumerator.Current
{
get
{
return Current;
}
}
public IPAddress Current
{
get
{
try
{
return IPEnumeration.IntToAddress(currentIP);
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}
public static class IPHelper
{
[DllImport("iphlpapi.dll", ExactSpelling=true)]
public static extern int SendARP( int DestIP, int SrcIP, byte[] pMacAddr, ref uint PhyAddrLen);
public static string getMAC(IPAddress address)
{
int intAddress = BitConverter.ToInt32(address.GetAddressBytes(), 0);
byte[] macAddr = new byte[6];
uint macAddrLen = (uint) macAddr.Length;
if (SendARP(intAddress, 0, macAddr, ref macAddrLen) != 0)
return "(NO ARP result)";
string[] str = new string[(int)macAddrLen];
for (int i = 0; i < macAddrLen; i++)
str[i] = macAddr[i].ToString("x2");
return string.Join(":", str);
}
}
class Program
{
public static void Main(string[] args)
{
foreach(IPAddress addr in new IPEnumeration("172.25.216.10","172.25.216.20"))
{
Console.WriteLine("{0}\t\t{1}",addr.ToString(), IPHelper.getMAC(addr));
}
Console.ReadKey(true);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
TextToBeWritten = "Pinging 172.16.94.95... \r\n";
Ping ping = new Ping();
PingReply pingReply = ping.Send("172.16.94.95");
if (pingReply.Status == IPStatus.Success)
{
//Machine is alive
TextToBeWritten += "Success!";
}
else
TextToBeWritten += "Error!";
+37
View File
@@ -0,0 +1,37 @@
TextToBeWritten = "<div>Pinging... </div>";
string ipBase = "172.16.94.";
for (int i = 1; i < 100; i++)
{
string ip = ipBase + i.ToString();
Ping p = new Ping();
var pingReply = p.Send(ip, 100);
if (pingReply.Status != IPStatus.Success)
TextToBeWritten += "<div><div class=\"host-offline\">Offline</div>" + ip + "</div>";
else
{
//Machine is alive
TextToBeWritten += "<div><div class=\"host-online\">Online</div>" + ip + "</div>";
IPAddress hostIPAddress = IPAddress.Parse(ip);
TextToBeWritten += "<div>";
try
{
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
IPAddress[] address = hostInfo.AddressList;
String[] alias = hostInfo.Aliases;
TextToBeWritten += "Host: " + hostInfo.HostName;
}
catch (Exception e)
{
TextToBeWritten += "DNS Resolution Error: " + e.Message;
}
TextToBeWritten += "</div>";
}
}
+116
View File
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Localization;
using webapp_shared;
namespace webapp_local.Pages.InfoTech
{
public class ServerLoginsModel : _LayoutModel
{
public string TextToBeWritten { get; set; }
public ServerLoginsModel(IStringLocalizer<_LayoutModel> _localizer, IConfiguration _config) : base(_localizer, _config)
{
}
public override void OnGet()
{
base.OnGet();
if (!Permissions.CanViewVisitorsRegister)
{
// Redirect a 404
Response.Redirect("/Error");
}
TextToBeWritten = "<div>Pinging... </div>";
//ip da teneresott'occhio 172.16.94.1-254
string ipBase = "172.16.91.";
for (int i = 1; i < 254; i++)
{
string ip = ipBase + i.ToString();
Ping p = new Ping();
var pingReply = p.Send(ip, 50);
if (pingReply.Status != IPStatus.Success)
TextToBeWritten += "<div>" + "<span class=\"host-offline\">● </span>Offline " + ip + "<br>Host: Disconnesso" + "<br></div>";
else
{
//Machine is alive
TextToBeWritten += "<div>" + "<span class=\"host-online\">● </span>Online " + ip + "</div>";
IPAddress hostIPAddress = IPAddress.Parse(ip);
TextToBeWritten += "<div>";
//DNS hostbyaddress
try
{
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
IPAddress[] address = hostInfo.AddressList;
String[] alias = hostInfo.Aliases;
TextToBeWritten += "Host: " + hostInfo.HostName + "<br>";
String CmdText = @"/c quser /server:" + ip;
Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = CmdText,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
String line = proc.StandardOutput.ReadToEnd();
line = line.Replace("\r\n", "<br>" + System.Environment.NewLine);
line = line.Replace("NOMEUTENTE", "UTENTE");
line = line.Replace("NOMESESSIONE", "SESSIONE");
line = line.Replace(" ", "&emsp;&emsp;&emsp;");
line = line.Replace(" ", "&emsp;&emsp;");
line = line.Replace(" ", "&emsp;");
line = line.Replace(" ", "&emsp;");
line = line.Replace(" ", "&emsp;");
line = line.Replace(" ", "&emsp;&emsp;");
line = line.Replace(" ", "&emsp;");
TextToBeWritten += "User Actualy Logged:<br>" + line;
}
catch (Exception e)
{
TextToBeWritten += "DNS Resolution Error: " + e.Message + "<br>";
}
TextToBeWritten += "<br></div>";
}
}
}
}
}
+117
View File
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Localization;
using webapp_shared;
namespace webapp_local.Pages.InfoTech
{
public class ServerLoginsModel : _LayoutModel
{
public string TextToBeWritten { get; set; }
public ServerLoginsModel(IStringLocalizer<_LayoutModel> _localizer, IConfiguration _config) : base(_localizer, _config)
{
}
public override void OnGet()
{
base.OnGet();
if (!Permissions.CanViewVisitorsRegister)
{
// Redirect a 404
Response.Redirect("/Error");
}
TextToBeWritten = "<div>Pinging... <br></div>";
//ip da teneresott'occhio 172.16.94.1-254
string ipBase = "172.16.94.";
for (int i = 30; i < 40; i++)
{
string ip = ipBase + i.ToString();
Ping p = new Ping();
var pingReply = p.Send(ip, 50);
if (pingReply.Status != IPStatus.Success)
TextToBeWritten += "<hr class=\"solid\">" + "<div>" + "<span class=\"host-offline\">● </span>Offline " + ip + "<br>Host: Disconnesso" + "<br><br></div>";
else
{
//Machine is alive
TextToBeWritten += "<hr class=\"solid\">" + "<div>" + "<span class=\"host-online\">● </span>Online " + ip + "</div>";
IPAddress hostIPAddress = IPAddress.Parse(ip);
TextToBeWritten += "<div>";
//DNS hostbyaddress
try
{
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
IPAddress[] address = hostInfo.AddressList;
String[] alias = hostInfo.Aliases;
TextToBeWritten += "Host: " + hostInfo.HostName + "<br>";
String CmdText = @"/c quser /server:" + ip;
Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = CmdText,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
String line = proc.StandardOutput.ReadToEnd();
line = line.Replace("\r\n", "<br>" + System.Environment.NewLine);
line = line.Replace("NOMEUTENTE", "UTENTE");
line = line.Replace("NOMESESSIONE", "SESSIONE");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
TextToBeWritten += "User Actualy Logged:<br>" + line;
}
catch (Exception e)
{
TextToBeWritten += "DNS Resolution Error: " + e.Message;
}
TextToBeWritten += "</div>";
}
}
}
}
}
+38
View File
@@ -0,0 +1,38 @@
string name = "Franco".ToUpper();
string surname = "Di Sorte".ToUpper().Replace(" ","");
List<string> rawAlias = new List<string>();
var range = string.Empty;
if (name.Length > surname.Length) { range = surname; } else { range = name; }
for (int i = 1;
i < 3;
i++)
{
if (i != 1)
{
rawAlias.Add($"{name[0..i]}{surname[0..i]}");
rawAlias.Add($"{name[0..i]}{surname[0]}");
rawAlias.Add($"{name[0]}{surname[0..i]}");
continue;
}
rawAlias.Add($"{name[0..i]}{surname[0..i]}");
}
rawAlias.Sort();
var alias = rawAlias.OrderBy(x => x.Length);
var existAlias = new List<string>()
{
{""}
};
foreach (var a in alias)
{
if(!existAlias.Contains(a))
Console.WriteLine(a);
}