From d13e32bd2bddb281e7464cd53f70a817ed842c92 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 10 Nov 2019 02:41:18 +0000 Subject: [PATCH] Add page to remove private information from ATA IDENTIFY DEVICE responses. --- .../Areas/Admin/Controllers/AtasController.cs | 201 ++++++++++++++++++ .../Admin/Views/Atas/CheckPrivate.cshtml | 137 ++++++++++++ .../Areas/Admin/Views/Atas/Index.cshtml | 4 + 3 files changed, 342 insertions(+) create mode 100644 DiscImageChef.Server/Areas/Admin/Views/Atas/CheckPrivate.cshtml diff --git a/DiscImageChef.Server/Areas/Admin/Controllers/AtasController.cs b/DiscImageChef.Server/Areas/Admin/Controllers/AtasController.cs index b701486e..11d1962f 100644 --- a/DiscImageChef.Server/Areas/Admin/Controllers/AtasController.cs +++ b/DiscImageChef.Server/Areas/Admin/Controllers/AtasController.cs @@ -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 havePrivacy = new List(); + 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)); + } } } \ No newline at end of file diff --git a/DiscImageChef.Server/Areas/Admin/Views/Atas/CheckPrivate.cshtml b/DiscImageChef.Server/Areas/Admin/Views/Atas/CheckPrivate.cshtml new file mode 100644 index 00000000..7646004c --- /dev/null +++ b/DiscImageChef.Server/Areas/Admin/Views/Atas/CheckPrivate.cshtml @@ -0,0 +1,137 @@ +@using System.Text +@model IEnumerable + +@{ + Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml"; + ViewBag.Title = "DiscImageChef"; +} +@{ + // /*************************************************************************** + // The Disc Image Chef + // ---------------------------------------------------------------------------- + // + // Filename : Index.cshtml + // Author(s) : Natalia Portillo + // + // 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 . + // + // ---------------------------------------------------------------------------- + // Copyright © 2011-2019 Natalia Portillo + // ****************************************************************************/ +} +ATA IDENTIFY DEVICE responses with possible private data + +@if (!Model.Any()) +{ +
+ No private data found. + Back to list +
+ + return; +} + + + + + + + + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Id) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.Model) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.SerialNumber) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.WWN) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.WWNExtension) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.MediaSerial) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedWords121) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedWords129) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedCFA) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedCEATA224) + + @Html.DisplayNameFor(model => model.IdentifyDevice.Value.ReservedWords) + +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.IdentifyDevice.Value.Model) + + @Html.DisplayFor(modelItem => item.IdentifyDevice.Value.SerialNumber) + + @Html.DisplayFor(modelItem => item.IdentifyDevice.Value.WWN) + + @Html.DisplayFor(modelItem => item.IdentifyDevice.Value.WWNExtension) + + @Html.DisplayFor(modelItem => item.IdentifyDevice.Value.MediaSerial) + + @Html.Encode(Encoding.ASCII.GetString(item.Identify, 121 * 2, 10).Replace("\0", "")) + + @Html.Encode(Encoding.ASCII.GetString(item.Identify, 129 * 2, 62).Replace("\0", "")) + + @Html.Encode(Encoding.ASCII.GetString(item.Identify, 161 * 2, 14).Replace("\0", "")) + + @Html.Encode(Encoding.ASCII.GetString(item.Identify, 224 * 2, 12).Replace("\0", "")) + + @Html.Encode(Encoding.ASCII.GetString(item.Identify, 236 * 2, 38).Replace("\0", "")) + + Clear private fields + Clear reserved fields +
\ No newline at end of file diff --git a/DiscImageChef.Server/Areas/Admin/Views/Atas/Index.cshtml b/DiscImageChef.Server/Areas/Admin/Views/Atas/Index.cshtml index f7e9db4e..a41d35c8 100644 --- a/DiscImageChef.Server/Areas/Admin/Views/Atas/Index.cshtml +++ b/DiscImageChef.Server/Areas/Admin/Views/Atas/Index.cshtml @@ -34,6 +34,10 @@ // ****************************************************************************/ } ATA IDENTIFY DEVICE responses +