Add page to remove private information from ATA IDENTIFY DEVICE responses.

This commit is contained in:
2019-11-10 02:41:18 +00:00
parent 0b85eb850e
commit d13e32bd2b
3 changed files with 342 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -344,5 +345,205 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
return View(model);
}
public IActionResult CheckPrivate()
{
List<CommonTypes.Metadata.Ata> havePrivacy = new List<CommonTypes.Metadata.Ata>();
byte[] tmp;
foreach(CommonTypes.Metadata.Ata ata in _context.Ata)
{
Identify.IdentifyDevice? id = ata.IdentifyDevice;
if(id is null)
continue;
if(!string.IsNullOrWhiteSpace(id.Value.SerialNumber) ||
id.Value.WWN != 0 ||
id.Value.WWNExtension != 0 ||
!string.IsNullOrWhiteSpace(id.Value.MediaSerial))
{
havePrivacy.Add(ata);
continue;
}
tmp = new byte[10];
Array.Copy(ata.Identify, 121 * 2, tmp, 0, 10);
if(tmp.All(b => b > 0x20) &&
tmp.All(b => b <= 0x5F))
{
havePrivacy.Add(ata);
continue;
}
tmp = new byte[62];
Array.Copy(ata.Identify, 129 * 2, tmp, 0, 62);
if(tmp.All(b => b > 0x20) &&
tmp.All(b => b <= 0x5F))
{
havePrivacy.Add(ata);
continue;
}
tmp = new byte[14];
Array.Copy(ata.Identify, 161 * 2, tmp, 0, 14);
if(tmp.All(b => b > 0x20) &&
tmp.All(b => b <= 0x5F))
{
havePrivacy.Add(ata);
continue;
}
tmp = new byte[12];
Array.Copy(ata.Identify, 224 * 2, tmp, 0, 12);
if(tmp.All(b => b > 0x20) &&
tmp.All(b => b <= 0x5F))
{
havePrivacy.Add(ata);
continue;
}
tmp = new byte[38];
Array.Copy(ata.Identify, 236 * 2, tmp, 0, 38);
if(tmp.All(b => b > 0x20) &&
tmp.All(b => b <= 0x5F))
{
havePrivacy.Add(ata);
}
}
return View(havePrivacy);
}
public IActionResult ClearPrivate(int id)
{
CommonTypes.Metadata.Ata ata = _context.Ata.FirstOrDefault(a => a.Id == id);
if(ata is null)
return RedirectToAction(nameof(CheckPrivate));
// Serial number
for(int i = 0; i < 20; i++)
ata.Identify[10 * 2 + i] = 0x20;
// Media serial number
for(int i = 0; i < 40; i++)
ata.Identify[176 * 2 + i] = 0x20;
// WWN and WWN Extension
for(int i = 0; i < 16; i++)
ata.Identify[108 * 2 + i] = 0;
// We need to tell EFCore the entity has changed
_context.Update(ata);
_context.SaveChanges();
return RedirectToAction(nameof(CheckPrivate));
}
public IActionResult ClearReserved(int id)
{
CommonTypes.Metadata.Ata ata = _context.Ata.FirstOrDefault(a => a.Id == id);
if(ata is null)
return RedirectToAction(nameof(CheckPrivate));
// ReservedWords121
for(int i = 0; i < 10; i++)
ata.Identify[121 * 2 + i] = 0;
// ReservedWords129
for(int i = 0; i < 40; i++)
ata.Identify[129 * 2 + i] = 0;
// ReservedCFA
for(int i = 0; i < 14; i++)
ata.Identify[161 * 2 + i] = 0;
// ReservedCEATA224
for(int i = 0; i < 12; i++)
ata.Identify[224 * 2 + i] = 0;
// ReservedWords
for(int i = 0; i < 14; i++)
ata.Identify[161 * 2 + i] = 0;
// We need to tell EFCore the entity has changed
_context.Update(ata);
_context.SaveChanges();
return RedirectToAction(nameof(CheckPrivate));
}
public IActionResult ClearPrivateAll()
{
foreach(CommonTypes.Metadata.Ata ata in _context.Ata)
{
if(ata is null)
return RedirectToAction(nameof(CheckPrivate));
// Serial number
for(int i = 0; i < 20; i++)
ata.Identify[10 * 2 + i] = 0x20;
// Media serial number
for(int i = 0; i < 40; i++)
ata.Identify[176 * 2 + i] = 0x20;
// WWN and WWN Extension
for(int i = 0; i < 16; i++)
ata.Identify[108 * 2 + i] = 0;
// We need to tell EFCore the entity has changed
_context.Update(ata);
}
_context.SaveChanges();
return RedirectToAction(nameof(CheckPrivate));
}
public IActionResult ClearReservedAll()
{
foreach(CommonTypes.Metadata.Ata ata in _context.Ata)
{
// ReservedWords121
for(int i = 0; i < 10; i++)
ata.Identify[121 * 2 + i] = 0;
// ReservedWords129
for(int i = 0; i < 40; i++)
ata.Identify[129 * 2 + i] = 0;
// ReservedCFA
for(int i = 0; i < 14; i++)
ata.Identify[161 * 2 + i] = 0;
// ReservedCEATA224
for(int i = 0; i < 12; i++)
ata.Identify[224 * 2 + i] = 0;
// ReservedWords
for(int i = 0; i < 14; i++)
ata.Identify[161 * 2 + i] = 0;
// We need to tell EFCore the entity has changed
_context.Update(ata);
}
_context.SaveChanges();
return RedirectToAction(nameof(CheckPrivate));
}
}
}

View File

@@ -0,0 +1,137 @@
@using System.Text
@model IEnumerable<DiscImageChef.CommonTypes.Metadata.Ata>
@{
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
ViewBag.Title = "DiscImageChef";
}
@{
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Index.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : DiscImageChef Server.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
}
ATA IDENTIFY DEVICE responses with possible private data
@if (!Model.Any())
{
<div>
No private data found.
<a asp-action="Index" class="btn btn-primary">Back to list</a>
</div>
return;
}
<div>
<a asp-action="ClearPrivateAll" class="btn btn-primary">Clear private fields for all</a>
<a asp-action="ClearReservedAll" class="btn btn-danger">Clear reserved fields for all</a>
<a asp-action="Index" class="btn btn-secondary">Back to list</a>
</div>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.Model)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.SerialNumber)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.WWN)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.WWNExtension)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.MediaSerial)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedWords121)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedWords129)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedCFA)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedCEATA224)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedWords)
</th>
<th>
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.IdentifyDevice.Value.Model)
</td>
<td>
@Html.DisplayFor(modelItem => item.IdentifyDevice.Value.SerialNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.IdentifyDevice.Value.WWN)
</td>
<td>
@Html.DisplayFor(modelItem => item.IdentifyDevice.Value.WWNExtension)
</td>
<td>
@Html.DisplayFor(modelItem => item.IdentifyDevice.Value.MediaSerial)
</td>
<td>
@Html.Encode(Encoding.ASCII.GetString(item.Identify, 121 * 2, 10).Replace("\0", ""))
</td>
<td>
@Html.Encode(Encoding.ASCII.GetString(item.Identify, 129 * 2, 62).Replace("\0", ""))
</td>
<td>
@Html.Encode(Encoding.ASCII.GetString(item.Identify, 161 * 2, 14).Replace("\0", ""))
</td>
<td>
@Html.Encode(Encoding.ASCII.GetString(item.Identify, 224 * 2, 12).Replace("\0", ""))
</td>
<td>
@Html.Encode(Encoding.ASCII.GetString(item.Identify, 236 * 2, 38).Replace("\0", ""))
</td>
<td>
<a asp-action="ClearPrivate" asp-route-id="@item.Id" class="btn btn-primary">Clear private fields</a>
<a asp-action="ClearReserved" asp-route-id="@item.Id" class="btn btn-danger">Clear reserved fields</a>
</td>
</tr>
}
</tbody>
</table>

View File

@@ -34,6 +34,10 @@
// ****************************************************************************/
}
ATA IDENTIFY DEVICE responses
<div>
<a asp-action="CheckPrivate" class="btn btn-primary">Check private fields</a>
<a asp-action="Consolidate" class="btn btn-danger">Consolidate duplicates</a>
</div>
<table class="table">
<thead>
<tr>