mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add files to database.
This commit is contained in:
4472
Marechai.Database/Migrations/20200610215731_AddFiles.Designer.cs
generated
Normal file
4472
Marechai.Database/Migrations/20200610215731_AddFiles.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
88
Marechai.Database/Migrations/20200610215731_AddFiles.cs
Normal file
88
Marechai.Database/Migrations/20200610215731_AddFiles.cs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
// MARECHAI: Master repository of computing history artifacts information
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program 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 General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright © 2003-2020 Natalia Portillo
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace Marechai.Database.Migrations
|
||||||
|
{
|
||||||
|
public partial class AddFiles : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable("Files", table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<ulong>(nullable: false).
|
||||||
|
Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
CreatedOn = table.Column<DateTime>(nullable: false).
|
||||||
|
Annotation("MySql:ValueGenerationStrategy",
|
||||||
|
MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
UpdatedOn = table.Column<DateTime>(nullable: false).
|
||||||
|
Annotation("MySql:ValueGenerationStrategy",
|
||||||
|
MySqlValueGenerationStrategy.ComputedColumn),
|
||||||
|
Size = table.Column<ulong>(nullable: false), Md5 = table.Column<byte[]>("binary(16)", nullable: true),
|
||||||
|
Sha1 = table.Column<byte[]>("binary(20)", nullable: true),
|
||||||
|
Sha256 = table.Column<byte[]>("binary(32)", nullable: true),
|
||||||
|
Sha3 = table.Column<byte[]>("binary(64)", nullable: true),
|
||||||
|
Spamsum = table.Column<string>(nullable: true), Mime = table.Column<string>(nullable: true),
|
||||||
|
Magic = table.Column<string>(nullable: true), AccoustId = table.Column<string>(nullable: true),
|
||||||
|
Infected = table.Column<bool>(nullable: false), Malware = table.Column<string>(nullable: true),
|
||||||
|
Hack = table.Column<bool>(nullable: false), HackGroup = table.Column<string>(nullable: true)
|
||||||
|
}, constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Files", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_AccoustId", "Files", "AccoustId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Hack", "Files", "Hack");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_HackGroup", "Files", "HackGroup");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Infected", "Files", "Infected");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Magic", "Files", "Magic");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Malware", "Files", "Malware");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Md5", "Files", "Md5");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Mime", "Files", "Mime");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Sha1", "Files", "Sha1");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Sha256", "Files", "Sha256");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Sha3", "Files", "Sha3");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Size", "Files", "Size");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Files_Spamsum", "Files", "Spamsum");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable("Files");
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
55
Marechai.Database/Models/File.cs
Normal file
55
Marechai.Database/Models/File.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
// MARECHAI: Master repository of computing history artifacts information
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program 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 General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright © 2003-2020 Natalia Portillo
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace Marechai.Database.Models
|
||||||
|
{
|
||||||
|
public class DbFile : BaseModel<ulong>
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public ulong Size { get; set; }
|
||||||
|
[Column(TypeName = "binary(16)")]
|
||||||
|
public string Md5 { get; set; }
|
||||||
|
[Column(TypeName = "binary(20)")]
|
||||||
|
public string Sha1 { get; set; }
|
||||||
|
[Column(TypeName = "binary(32)")]
|
||||||
|
public string Sha256 { get; set; }
|
||||||
|
[Column(TypeName = "binary(64)")]
|
||||||
|
public string Sha3 { get; set; }
|
||||||
|
public string Spamsum { get; set; }
|
||||||
|
public string Mime { get; set; }
|
||||||
|
public string Magic { get; set; }
|
||||||
|
public string AccoustId { get; set; }
|
||||||
|
[DefaultValue(false)]
|
||||||
|
public bool Infected { get; set; }
|
||||||
|
public string Malware { get; set; }
|
||||||
|
[DefaultValue(false)]
|
||||||
|
public bool Hack { get; set; }
|
||||||
|
public string HackGroup { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,15 +25,21 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Marechai.Database.Schemas;
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Marechai.Database.Models
|
namespace Marechai.Database.Models
|
||||||
{
|
{
|
||||||
public class MarechaiContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
|
public class MarechaiContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
|
||||||
{
|
{
|
||||||
|
readonly ValueConverter<string, byte[]> hexToBytesConverter =
|
||||||
|
new ValueConverter<string, byte[]>(v => HexStringToBytesConverter.StringToHex(v),
|
||||||
|
v => HexStringToBytesConverter.HexToString(v));
|
||||||
|
|
||||||
public MarechaiContext() { }
|
public MarechaiContext() { }
|
||||||
|
|
||||||
public MarechaiContext(DbContextOptions<MarechaiContext> options) : base(options) { }
|
public MarechaiContext(DbContextOptions<MarechaiContext> options) : base(options) { }
|
||||||
@@ -100,6 +106,7 @@ namespace Marechai.Database.Models
|
|||||||
public virtual DbSet<CurrencyInflation> CurrenciesInflation { get; set; }
|
public virtual DbSet<CurrencyInflation> CurrenciesInflation { get; set; }
|
||||||
public virtual DbSet<CurrencyPegging> CurrenciesPegging { get; set; }
|
public virtual DbSet<CurrencyPegging> CurrenciesPegging { get; set; }
|
||||||
public virtual DbSet<DumpHardware> DumpHardwares { get; set; }
|
public virtual DbSet<DumpHardware> DumpHardwares { get; set; }
|
||||||
|
public virtual DbSet<DbFile> Files { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
@@ -1585,6 +1592,28 @@ namespace Marechai.Database.Models
|
|||||||
entity.HasIndex(e => e.SoftwareVersion);
|
entity.HasIndex(e => e.SoftwareVersion);
|
||||||
entity.HasIndex(e => e.SoftwareOperatingSystem);
|
entity.HasIndex(e => e.SoftwareOperatingSystem);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<DbFile>(entity =>
|
||||||
|
{
|
||||||
|
entity.Property(e => e.Md5).HasConversion(hexToBytesConverter);
|
||||||
|
entity.Property(e => e.Sha1).HasConversion(hexToBytesConverter);
|
||||||
|
entity.Property(e => e.Sha256).HasConversion(hexToBytesConverter);
|
||||||
|
entity.Property(e => e.Sha3).HasConversion(hexToBytesConverter);
|
||||||
|
|
||||||
|
entity.HasIndex(e => e.Size);
|
||||||
|
entity.HasIndex(e => e.Md5);
|
||||||
|
entity.HasIndex(e => e.Sha1);
|
||||||
|
entity.HasIndex(e => e.Sha256);
|
||||||
|
entity.HasIndex(e => e.Sha3);
|
||||||
|
entity.HasIndex(e => e.Spamsum);
|
||||||
|
entity.HasIndex(e => e.Mime);
|
||||||
|
entity.HasIndex(e => e.Magic);
|
||||||
|
entity.HasIndex(e => e.AccoustId);
|
||||||
|
entity.HasIndex(e => e.Infected);
|
||||||
|
entity.HasIndex(e => e.Malware);
|
||||||
|
entity.HasIndex(e => e.Hack);
|
||||||
|
entity.HasIndex(e => e.HackGroup);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
87
Marechai.Database/Schemas/HexStringToBytesConverter.cs
Normal file
87
Marechai.Database/Schemas/HexStringToBytesConverter.cs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
// MARECHAI: Master repository of computing history artifacts information
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program 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 General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright © 2003-2020 Natalia Portillo
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Marechai.Database.Schemas
|
||||||
|
{
|
||||||
|
public static class HexStringToBytesConverter
|
||||||
|
{
|
||||||
|
public static byte[] StringToHex(string v)
|
||||||
|
{
|
||||||
|
byte[] hex = new byte[v.Length / 2];
|
||||||
|
string str = v.ToLowerInvariant();
|
||||||
|
|
||||||
|
for(int i = 0; i < hex.Length; i++)
|
||||||
|
{
|
||||||
|
char c0 = str[i * 2];
|
||||||
|
char c1 = str[(i * 2) + 1];
|
||||||
|
|
||||||
|
if(c0 >= 0x30 &&
|
||||||
|
c0 <= 0x39)
|
||||||
|
hex[i] += (byte)((c0 - 0x30) * 16);
|
||||||
|
else if(c0 >= 0x61 &&
|
||||||
|
c0 <= 0x66)
|
||||||
|
hex[i] += (byte)((c0 - 0x57) * 16);
|
||||||
|
else
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
|
||||||
|
if(c1 >= 0x30 &&
|
||||||
|
c1 <= 0x39)
|
||||||
|
hex[i] += (byte)(c1 - 0x30);
|
||||||
|
else if(c1 >= 0x61 &&
|
||||||
|
c1 <= 0x66)
|
||||||
|
hex[i] += (byte)(c1 - 0x57);
|
||||||
|
else
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string HexToString(byte[] v)
|
||||||
|
{
|
||||||
|
char[] chars = new char[v.Length * 2];
|
||||||
|
|
||||||
|
for(int i = 0; i < v.Length; i++)
|
||||||
|
{
|
||||||
|
int c0 = v[i] / 0x10;
|
||||||
|
int c1 = v[i] & 0xF;
|
||||||
|
|
||||||
|
if(c0 >= 10)
|
||||||
|
chars[i * 2] = (char)(c0 + 0x57);
|
||||||
|
else
|
||||||
|
chars[i * 2] = (char)(c0 + 0x30);
|
||||||
|
|
||||||
|
if(c1 >= 10)
|
||||||
|
chars[(i * 2) + 1] = (char)(c1 + 0x57);
|
||||||
|
else
|
||||||
|
chars[(i * 2) + 1] = (char)(c1 + 0x30);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string(chars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<Version>4.0.0.1662</Version>
|
<Version>4.0.0.1669</Version>
|
||||||
<Company>Canary Islands Computer Museum</Company>
|
<Company>Canary Islands Computer Museum</Company>
|
||||||
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
||||||
<Product>Canary Islands Computer Museum Website</Product>
|
<Product>Canary Islands Computer Museum Website</Product>
|
||||||
|
|||||||
Reference in New Issue
Block a user