Ejemplo n.º 1
0
    internal static bool TableExists(string tableName)
    {
        using var db = new AaruServerContext();

        DbConnection connection = db.Database.GetDbConnection();

        connection.Open();

        DbCommand command = connection.CreateCommand();

        command.CommandText =
            $"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=\"{tableName}\"";

        long result = (long)command.ExecuteScalar();

        return(result != 0);
    }
Ejemplo n.º 2
0
    public static void Seed(AaruServerContext ctx, IServiceProvider serviceProvider)
    {
        string email = "*****@*****.**";

        char[] randChars = new char[16];
        UserManager <IdentityUser> userManager = serviceProvider.GetRequiredService <UserManager <IdentityUser> >();
        var rnd = new Random();

        for (int i = 0; i < randChars.Length; i++)
        {
            randChars[i] = (char)rnd.Next(32, 126);
        }

        string password = new(randChars);

        if (userManager.FindByEmailAsync(email).Result != null)
        {
            return;
        }

        var user = new IdentityUser
        {
            Email              = email,
            NormalizedEmail    = email,
            EmailConfirmed     = true,
            UserName           = email,
            NormalizedUserName = email
        };

        IdentityResult result = userManager.CreateAsync(user, password).Result;

        if (result.Succeeded)
        {
            System.Console.WriteLine("Password is {0}, save it!", password);
        }
    }
 public CompactDiscOffsetsController(AaruServerContext context) => _context = context;
Ejemplo n.º 4
0
 public TestedMediasController(AaruServerContext context) => _context = context;
Ejemplo n.º 5
0
 public UploadReportController(IWebHostEnvironment environment, AaruServerContext ctx)
 {
     _environment = environment;
     _ctx         = ctx;
 }
Ejemplo n.º 6
0
    public static void Main(string[] args)
    {
        DateTime start, end;
        int      counter = 0;

        start = DateTime.UtcNow;
        System.Console.WriteLine("{0}: Connecting to database...", DateTime.UtcNow);
        var ctx = new AaruServerContext();

        end = DateTime.UtcNow;
        System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);

        System.Console.WriteLine("{0}: Migrating database to latest version...", DateTime.UtcNow);
        start = DateTime.UtcNow;
        ctx.Database.Migrate();
        end = DateTime.UtcNow;
        System.Console.WriteLine("{0}: Took {1:F2} seconds", DateTime.UtcNow, (end - start).TotalSeconds);

        WebClient client;

        try
        {
            System.Console.WriteLine("{0}: Retrieving USB IDs from Linux USB...", DateTime.UtcNow);
            start  = DateTime.UtcNow;
            client = new WebClient();
            var sr = new StringReader(client.DownloadString("http://www.linux-usb.org/usb.ids"));
            end = DateTime.UtcNow;
            System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);

            UsbVendor vendor           = null;
            int       newVendors       = 0;
            int       newProducts      = 0;
            int       modifiedVendors  = 0;
            int       modifiedProducts = 0;

            start = DateTime.UtcNow;
            System.Console.WriteLine("{0}: Adding and updating database entries...", DateTime.UtcNow);

            do
            {
                if (counter == 1000)
                {
                    DateTime start2 = DateTime.UtcNow;
                    System.Console.WriteLine("{0}: Saving changes", start2);
                    ctx.SaveChanges();
                    end = DateTime.UtcNow;
                    System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start2).TotalSeconds);
                    counter = 0;
                }

                string line = sr.ReadLine();

                if (line is null)
                {
                    break;
                }

                if (line.Length == 0 ||
                    line[0] == '#')
                {
                    continue;
                }

                ushort number;
                string name;

                if (line[0] == '\t')
                {
                    try
                    {
                        number = Convert.ToUInt16(line.Substring(1, 4), 16);
                    }
                    catch (FormatException)
                    {
                        continue;
                    }

                    if (number == 0)
                    {
                        continue;
                    }

                    name = line.Substring(7);

                    UsbProduct product =
                        ctx.UsbProducts.FirstOrDefault(p => p.ProductId == number && p.Vendor != null &&
                                                       p.Vendor.VendorId == vendor.VendorId);

                    if (product is null)
                    {
                        product = new UsbProduct(vendor, number, name);
                        ctx.UsbProducts.Add(product);

                        System.Console.WriteLine("{0}: Will add product {1} with ID {2:X4} and vendor {3} ({4:X4})",
                                                 DateTime.UtcNow, product.Product, product.ProductId,
                                                 product.Vendor?.Vendor ?? "null", product.Vendor?.VendorId ?? 0);

                        newProducts++;
                        counter++;
                    }
                    else if (name != product.Product)
                    {
                        System.Console.
                        WriteLine("{0}: Will modify product with ID {1:X4} and vendor {2} ({3:X4}) from \"{4}\" to \"{5}\"",
                                  DateTime.UtcNow, product.ProductId, product.Vendor?.Vendor ?? "null",
                                  product.Vendor?.VendorId ?? 0, product.Product, name);

                        product.Product      = name;
                        product.ModifiedWhen = DateTime.UtcNow;
                        modifiedProducts++;
                        counter++;
                    }

                    continue;
                }

                try
                {
                    number = Convert.ToUInt16(line.Substring(0, 4), 16);
                }
                catch (FormatException)
                {
                    continue;
                }

                if (number == 0)
                {
                    continue;
                }

                name = line.Substring(6);

                vendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == number);

                if (vendor is null)
                {
                    vendor = new UsbVendor(number, name);
                    ctx.UsbVendors.Add(vendor);

                    System.Console.WriteLine("{0}: Will add vendor {1} with ID {2:X4}", DateTime.UtcNow, vendor.Vendor,
                                             vendor.VendorId);

                    newVendors++;
                    counter++;
                }
                else if (name != vendor.Vendor)
                {
                    System.Console.WriteLine("{0}: Will modify vendor with ID {1:X4} from \"{2}\" to \"{3}\"",
                                             DateTime.UtcNow, vendor.VendorId, vendor.Vendor, name);

                    vendor.Vendor       = name;
                    vendor.ModifiedWhen = DateTime.UtcNow;
                    modifiedVendors++;
                    counter++;
                }
            } while(true);

            end = DateTime.UtcNow;
            System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);

            System.Console.WriteLine("{0}: Saving database changes...", DateTime.UtcNow);
            start = DateTime.UtcNow;
            ctx.SaveChanges();
            end = DateTime.UtcNow;
            System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);

            System.Console.WriteLine("{0}: {1} vendors added.", DateTime.UtcNow, newVendors);
            System.Console.WriteLine("{0}: {1} products added.", DateTime.UtcNow, newProducts);
            System.Console.WriteLine("{0}: {1} vendors modified.", DateTime.UtcNow, modifiedVendors);
            System.Console.WriteLine("{0}: {1} products modified.", DateTime.UtcNow, modifiedProducts);

            System.Console.WriteLine("{0}: Looking up a vendor", DateTime.UtcNow);
            start  = DateTime.UtcNow;
            vendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == 0x8086);

            if (vendor is null)
            {
                System.Console.WriteLine("{0}: Error, could not find vendor.", DateTime.UtcNow);
            }
            else
            {
                System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, vendor.Vendor);
            }

            end = DateTime.UtcNow;
            System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);

            System.Console.WriteLine("{0}: Looking up a product", DateTime.UtcNow);
            start = DateTime.UtcNow;

            UsbProduct prd = ctx.UsbProducts.FirstOrDefault(p => p.ProductId == 0x0001 && p.Vendor.VendorId == 0x8086);

            if (prd is null)
            {
                System.Console.WriteLine("{0}: Error, could not find product.", DateTime.UtcNow);
            }
            else
            {
                System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, prd.Product);
            }

            end = DateTime.UtcNow;
            System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);
        }
        catch (Exception ex)
        {
        #if DEBUG
            if (Debugger.IsAttached)
            {
                throw;
            }
        #endif
            System.Console.WriteLine("{0}: Exception {1} filling USB IDs...", DateTime.UtcNow, ex);
        }

        System.Console.WriteLine("{0}: Fixing all devices without modification time...", DateTime.UtcNow);
        start = DateTime.UtcNow;

        foreach (Device device in ctx.Devices.Where(d => d.ModifiedWhen == null))
        {
            device.ModifiedWhen = device.AddedWhen;
        }

        end = DateTime.UtcNow;
        System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);

        System.Console.WriteLine("{0}: Committing changes...", DateTime.UtcNow);
        start = DateTime.UtcNow;
        ctx.SaveChanges();
        end = DateTime.UtcNow;
        System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);

        try
        {
            System.Console.WriteLine("{0}: Retrieving CompactDisc read offsets from AccurateRip...", DateTime.UtcNow);

            start = DateTime.UtcNow;

            client = new WebClient();
            string html = client.DownloadString("http://www.accuraterip.com/driveoffsets.htm");
            end = DateTime.UtcNow;
            System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds);

            // The HTML is too malformed to process easily, so find start of table
            html = "<html><body><table><tr>" +
                   html.Substring(html.IndexOf("<td bgcolor=\"#000000\">", StringComparison.Ordinal));

            var doc = new HtmlDocument();
            doc.LoadHtml(html);
            HtmlNode firstTable = doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/table[1]");

            bool firstRow = true;

            int addedOffsets    = 0;
            int modifiedOffsets = 0;

            System.Console.WriteLine("{0}: Processing offsets...", DateTime.UtcNow);
            start = DateTime.UtcNow;

            foreach (HtmlNode row in firstTable.Descendants("tr"))
            {
                HtmlNode[] columns = row.Descendants("td").ToArray();

                if (columns.Length != 4)
                {
                    System.Console.WriteLine("{0}: Row does not have correct number of columns...", DateTime.UtcNow);

                    continue;
                }

                string column0 = columns[0].InnerText;
                string column1 = columns[1].InnerText;
                string column2 = columns[2].InnerText;
                string column3 = columns[3].InnerText;

                if (firstRow)
                {
                    if (column0.ToLowerInvariant() != "cd drive")
                    {
                        System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow,
                                                 columns[0].InnerText);

                        break;
                    }

                    if (column1.ToLowerInvariant() != "correction offset")
                    {
                        System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow,
                                                 columns[1].InnerText);

                        break;
                    }

                    if (column2.ToLowerInvariant() != "submitted by")
                    {
                        System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow,
                                                 columns[2].InnerText);

                        break;
                    }

                    if (column3.ToLowerInvariant() != "percentage agree")
                    {
                        System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow,
                                                 columns[3].InnerText);

                        break;
                    }

                    firstRow = false;

                    continue;
                }

                string manufacturer;
                string model;

                if (column0[0] == '-' &&
                    column0[1] == ' ')
                {
                    manufacturer = null;
                    model        = column0.Substring(2).Trim();
                }
                else
                {
                    int cutOffset = column0.IndexOf(" - ", StringComparison.Ordinal);

                    if (cutOffset == -1)
                    {
                        manufacturer = null;
                        model        = column0;
                    }
                    else
                    {
                        manufacturer = column0.Substring(0, cutOffset).Trim();
                        model        = column0.Substring(cutOffset + 3).Trim();
                    }
                }

                switch (manufacturer)
                {
                case "Lite-ON":
                    manufacturer = "JLMS";

                    break;

                case "LG Electronics":
                    manufacturer = "HL-DT-ST";

                    break;

                case "Panasonic":
                    manufacturer = "MATSHITA";

                    break;
                }

                CompactDiscOffset cdOffset =
                    ctx.CdOffsets.FirstOrDefault(o => o.Manufacturer == manufacturer && o.Model == model);

                if (column1.ToLowerInvariant() == "[purged]")
                {
                    if (cdOffset != null)
                    {
                        ctx.CdOffsets.Remove(cdOffset);
                    }

                    continue;
                }

                if (!short.TryParse(column1, out short offset))
                {
                    continue;
                }

                if (!int.TryParse(column2, out int submissions))
                {
                    continue;
                }

                if (column3[^ 1] != '%')
Ejemplo n.º 7
0
 public UploadStatsController(AaruServerContext ctx) => _ctx = ctx;
Ejemplo n.º 8
0
 public PcmciasController(AaruServerContext context) => _context = context;
Ejemplo n.º 9
0
 public DeviceStatsController(AaruServerContext context) => _context = context;
Ejemplo n.º 10
0
    public static void Convert(Stats newStats)
    {
        var ctx = new AaruServerContext();

        if (newStats.Commands?.Analyze > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "fs-info");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Analyze,
                    Name  = "fs-info"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Analyze;
            }
        }

        if (newStats.Commands?.Benchmark > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "benchmark");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Benchmark,
                    Name  = "benchmark"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Benchmark;
            }
        }

        if (newStats.Commands?.Checksum > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "checksum");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Checksum,
                    Name  = "checksum"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Checksum;
            }
        }

        if (newStats.Commands?.Compare > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "compare");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Compare,
                    Name  = "compare"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Compare;
            }
        }

        if (newStats.Commands?.CreateSidecar > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "create-sidecar");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.CreateSidecar,
                    Name  = "create-sidecar"
                });
            }
            else
            {
                existing.Count += newStats.Commands.CreateSidecar;
            }
        }

        if (newStats.Commands?.Decode > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "decode");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Decode,
                    Name  = "decode"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Decode;
            }
        }

        if (newStats.Commands?.DeviceInfo > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-info");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.DeviceInfo,
                    Name  = "device-info"
                });
            }
            else
            {
                existing.Count += newStats.Commands.DeviceInfo;
            }
        }

        if (newStats.Commands?.DeviceReport > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-report");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.DeviceReport,
                    Name  = "device-report"
                });
            }
            else
            {
                existing.Count += newStats.Commands.DeviceReport;
            }
        }

        if (newStats.Commands?.DumpMedia > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "dump-media");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.DumpMedia,
                    Name  = "dump-media"
                });
            }
            else
            {
                existing.Count += newStats.Commands.DumpMedia;
            }
        }

        if (newStats.Commands?.Entropy > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "entropy");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Entropy,
                    Name  = "entropy"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Entropy;
            }
        }

        if (newStats.Commands?.Formats > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "formats");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Formats,
                    Name  = "formats"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Formats;
            }
        }

        if (newStats.Commands?.MediaInfo > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-info");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.MediaInfo,
                    Name  = "media-info"
                });
            }
            else
            {
                existing.Count += newStats.Commands.MediaInfo;
            }
        }

        if (newStats.Commands?.MediaScan > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-scan");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.MediaScan,
                    Name  = "media-scan"
                });
            }
            else
            {
                existing.Count += newStats.Commands.MediaScan;
            }
        }

        if (newStats.Commands?.PrintHex > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "printhex");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.PrintHex,
                    Name  = "printhex"
                });
            }
            else
            {
                existing.Count += newStats.Commands.PrintHex;
            }
        }

        if (newStats.Commands?.Verify > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "verify");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Verify,
                    Name  = "verify"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Verify;
            }
        }

        if (newStats.Commands?.Ls > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "ls");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.Ls,
                    Name  = "ls"
                });
            }
            else
            {
                existing.Count += newStats.Commands.Ls;
            }
        }

        if (newStats.Commands?.ExtractFiles > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "extract-files");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.ExtractFiles,
                    Name  = "extract-files"
                });
            }
            else
            {
                existing.Count += newStats.Commands.ExtractFiles;
            }
        }

        if (newStats.Commands?.ListDevices > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-devices");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.ListDevices,
                    Name  = "list-devices"
                });
            }
            else
            {
                existing.Count += newStats.Commands.ListDevices;
            }
        }

        if (newStats.Commands?.ListEncodings > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-encodings");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.ListEncodings,
                    Name  = "list-encodings"
                });
            }
            else
            {
                existing.Count += newStats.Commands.ListEncodings;
            }
        }

        if (newStats.Commands?.ConvertImage > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "convert-image");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.ConvertImage,
                    Name  = "convert-image"
                });
            }
            else
            {
                existing.Count += newStats.Commands.ConvertImage;
            }
        }

        if (newStats.Commands?.ImageInfo > 0)
        {
            Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "image-info");

            if (existing == null)
            {
                ctx.Commands.Add(new Command
                {
                    Count = newStats.Commands.ImageInfo,
                    Name  = "image-info"
                });
            }
            else
            {
                existing.Count += newStats.Commands.ImageInfo;
            }
        }

        if (newStats.OperatingSystems != null)
        {
            foreach (OsStats operatingSystem in newStats.OperatingSystems)
            {
                if (string.IsNullOrWhiteSpace(operatingSystem.name) ||
                    string.IsNullOrWhiteSpace(operatingSystem.version))
                {
                    continue;
                }

                OperatingSystem existing =
                    ctx.OperatingSystems.FirstOrDefault(c => c.Name == operatingSystem.name &&
                                                        c.Version == operatingSystem.version);

                if (existing == null)
                {
                    ctx.OperatingSystems.Add(new OperatingSystem
                    {
                        Count   = operatingSystem.Value,
                        Name    = operatingSystem.name,
                        Version = operatingSystem.version
                    });
                }
                else
                {
                    existing.Count += operatingSystem.Value;
                }
            }
        }
        else
        {
            OperatingSystem existing = ctx.OperatingSystems.FirstOrDefault(c => c.Name == "Linux" && c.Version == null);

            if (existing == null)
            {
                ctx.OperatingSystems.Add(new OperatingSystem
                {
                    Count = 1,
                    Name  = "Linux"
                });
            }
            else
            {
                existing.Count++;
            }
        }

        if (newStats.Versions != null)
        {
            foreach (NameValueStats nvs in newStats.Versions)
            {
                if (string.IsNullOrWhiteSpace(nvs.name))
                {
                    continue;
                }

                Version existing = ctx.Versions.FirstOrDefault(c => c.Name == nvs.name);

                if (existing == null)
                {
                    ctx.Versions.Add(new Version
                    {
                        Count = nvs.Value,
                        Name  = nvs.name
                    });
                }
                else
                {
                    existing.Count += nvs.Value;
                }
            }
        }
        else
        {
            Version existing = ctx.Versions.FirstOrDefault(c => c.Name == "previous");

            if (existing == null)
            {
                ctx.Versions.Add(new Version
                {
                    Count = 1,
                    Name  = "previous"
                });
            }
            else
            {
                existing.Count++;
            }
        }

        if (newStats.Filesystems != null)
        {
            foreach (NameValueStats nvs in newStats.Filesystems)
            {
                if (string.IsNullOrWhiteSpace(nvs.name))
                {
                    continue;
                }

                Filesystem existing = ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name);

                if (existing == null)
                {
                    ctx.Filesystems.Add(new Filesystem
                    {
                        Count = nvs.Value,
                        Name  = nvs.name
                    });
                }
                else
                {
                    existing.Count += nvs.Value;
                }
            }
        }

        if (newStats.Partitions != null)
        {
            foreach (NameValueStats nvs in newStats.Partitions)
            {
                if (string.IsNullOrWhiteSpace(nvs.name))
                {
                    continue;
                }

                Partition existing = ctx.Partitions.FirstOrDefault(c => c.Name == nvs.name);

                if (existing == null)
                {
                    ctx.Partitions.Add(new Partition
                    {
                        Count = nvs.Value,
                        Name  = nvs.name
                    });
                }
                else
                {
                    existing.Count += nvs.Value;
                }
            }
        }

        if (newStats.MediaImages != null)
        {
            foreach (NameValueStats nvs in newStats.MediaImages)
            {
                if (string.IsNullOrWhiteSpace(nvs.name))
                {
                    continue;
                }

                MediaFormat existing = ctx.MediaFormats.FirstOrDefault(c => c.Name == nvs.name);

                if (existing == null)
                {
                    ctx.MediaFormats.Add(new MediaFormat
                    {
                        Count = nvs.Value,
                        Name  = nvs.name
                    });
                }
                else
                {
                    existing.Count += nvs.Value;
                }
            }
        }

        if (newStats.Filters != null)
        {
            foreach (NameValueStats nvs in newStats.Filters)
            {
                if (string.IsNullOrWhiteSpace(nvs.name))
                {
                    continue;
                }

                Filter existing = ctx.Filters.FirstOrDefault(c => c.Name == nvs.name);

                if (existing == null)
                {
                    ctx.Filters.Add(new Filter
                    {
                        Count = nvs.Value,
                        Name  = nvs.name
                    });
                }
                else
                {
                    existing.Count += nvs.Value;
                }
            }
        }

        if (newStats.Devices != null)
        {
            foreach (DeviceStats device in newStats.Devices.Where(device => !string.IsNullOrWhiteSpace(device.Model)).
                     Where(device => !ctx.DeviceStats.Any(c => c.Bus == device.Bus &&
                                                          c.Manufacturer == device.Manufacturer &&
                                                          c.Model == device.Model &&
                                                          c.Revision == device.Revision)))
            {
                ctx.DeviceStats.Add(new DeviceStat
                {
                    Bus          = device.Bus,
                    Manufacturer = device.Manufacturer,
                    Model        = device.Model,
                    Revision     = device.Revision
                });
            }
        }

        if (newStats.Medias != null)
        {
            foreach (MediaStats media in newStats.Medias)
            {
                if (string.IsNullOrWhiteSpace(media.type))
                {
                    continue;
                }

                Media existing = ctx.Medias.FirstOrDefault(c => c.Type == media.type && c.Real == media.real);

                if (existing == null)
                {
                    ctx.Medias.Add(new Media
                    {
                        Count = media.Value,
                        Real  = media.real,
                        Type  = media.type
                    });
                }
                else
                {
                    existing.Count += media.Value;
                }
            }
        }

        ctx.SaveChanges();
    }
Ejemplo n.º 11
0
 public MmcFeaturesController(AaruServerContext context) => _context = context;
Ejemplo n.º 12
0
 public MmcController(AaruServerContext context) => _context = context;
Ejemplo n.º 13
0
 public PartitionsController(AaruServerContext context) => _context = context;
Ejemplo n.º 14
0
 public CommandsController(AaruServerContext context) => _context = context;
Ejemplo n.º 15
0
 public MediaFormatsController(AaruServerContext context) => _context = context;
Ejemplo n.º 16
0
 public BlockDescriptorsController(AaruServerContext context) => _context = context;
 public OperatingSystemsController(AaruServerContext context) => _context = context;
Ejemplo n.º 18
0
 public ReportController(AaruServerContext context) => _ctx = context;
Ejemplo n.º 19
0
 public FilesystemsController(AaruServerContext context) => _context = context;
Ejemplo n.º 20
0
 public FireWiresController(AaruServerContext context) => _context = context;
Ejemplo n.º 21
0
 public VersionsController(AaruServerContext context) => _context = context;
Ejemplo n.º 22
0
 public UpdateController(AaruServerContext ctx) => _ctx = ctx;
Ejemplo n.º 23
0
    public static void Main(string[] args)
    {
        DateTime start;
        DateTime end;

        System.Console.Clear();

        System.Console.Write(
            "\u001b[32m                             .                ,,\n" +
            "\u001b[32m                          ;,.                  '0d.\n" +
            "\u001b[32m                        oc                       oWd                      \u001b[31m" +
            @"__/\\\\\\\\\\\\_____/\\\\\\\\\\\________/\\\\\\\\\_        " + "\n\u001b[0m" +
            "\u001b[32m                      ;X.                         'WN'                    \u001b[31m" +
            @" _\/\\\////////\\\__\/////\\\///______/\\\////////__       " + "\n\u001b[0m" +
            "\u001b[32m                     oMo                           cMM:                   \u001b[31m" +
            @"  _\/\\\______\//\\\_____\/\\\_______/\\\/___________      " + "\n\u001b[0m" +
            "\u001b[32m                    ;MM.                           .MMM;                  \u001b[31m" +
            @"   _\/\\\_______\/\\\_____\/\\\______/\\\_____________     " + "\n\u001b[0m" +
            "\u001b[32m                    NMM                             WMMW                  \u001b[31m" +
            @"    _\/\\\_______\/\\\_____\/\\\_____\/\\\_____________    " + "\n\u001b[0m" +
            "\u001b[32m                   'MMM                             MMMM;                 \u001b[31m" +
            @"     _\/\\\_______\/\\\_____\/\\\_____\//\\\____________   " + "\n\u001b[0m" +
            "\u001b[32m                   ,MMM:                           dMMMM:                 \u001b[31m" +
            @"      _\/\\\_______/\\\______\/\\\______\///\\\__________  " + "\n\u001b[0m" +
            "\u001b[32m                   .MMMW.                         :MMMMM.                 \u001b[31m" +
            @"       _\/\\\\\\\\\\\\/____/\\\\\\\\\\\____\////\\\\\\\\\_ " + "\n\u001b[0m" +
            "\u001b[32m                    XMMMW:    .:xKNMMMMMMN0d,    lMMMMMd                  \u001b[31m" +
            @"        _\////////////_____\///////////________\/////////__" + "\n\u001b[0m" +
            "\u001b[32m                    :MMMMMK; cWMNkl:;;;:lxKMXc .0MMMMMO\u001b[0m\n" +
            "\u001b[32m                   ..KMMMMMMNo,.             ,OMMMMMMW:,.                 \u001b[37;1m          Aaru Website\u001b[0m\n" +
            "\u001b[32m            .;d0NMMMMMMMMMMMMMMW0d:'    .;lOWMMMMMMMMMMMMMXkl.            \u001b[37;1m          Version \u001b[0m\u001b[33m{0}\u001b[37;1m-\u001b[0m\u001b[31m{1}\u001b[0m\n" +
            "\u001b[32m          :KMMMMMMMMMMMMMMMMMMMMMMMMc  WMMMMMMMMMMMMMMMMMMMMMMWk'\u001b[0m\n" +
            "\u001b[32m        ;NMMMMWX0kkkkO0XMMMMMMMMMMM0'  dNMMMMMMMMMMW0xl:;,;:oOWMMX;       \u001b[37;1m          Running under \u001b[35;1m{2}\u001b[37;1m, \u001b[35m{3}-bit\u001b[37;1m in \u001b[35m{4}-bit\u001b[37;1m mode.\u001b[0m\n" +
            "\u001b[32m       xMMWk:.           .c0MMMMMW'      OMMMMMM0c'..          .oNMO      \u001b[37;1m          Using \u001b[33;1m{5}\u001b[37;1m version \u001b[31;1m{6}\u001b[0m\n" +
            "\u001b[32m      OMNc            .MNc   oWMMk       'WMMNl. .MMK             ;KX.\u001b[0m\n" +
            "\u001b[32m     xMO               WMN     ;  .,    ,  ':    ,MMx               lK\u001b[0m\n" +
            "\u001b[32m    ,Md                cMMl     .XMMMWWMMMO      XMW.                :\u001b[0m\n" +
            "\u001b[32m    Ok                  xMMl     XMMMMMMMMc     0MW,\u001b[0m\n" +
            "\u001b[32m    0                    oMM0'   lMMMMMMMM.   :NMN'\u001b[0m\n" +
            "\u001b[32m    .                     .0MMKl ;MMMMMMMM  oNMWd\u001b[0m\n" +
            "\u001b[32m                            .dNW cMMMMMMMM, XKl\u001b[0m\n" +
            "\u001b[32m                                 0MMMMMMMMK\u001b[0m\n" +
            "\u001b[32m                                ;MMMMMMMMMMO                              \u001b[37;1m          Proudly presented to you by:\u001b[0m\n" +
            "\u001b[32m                               'WMMMMKxMMMMM0                             \u001b[34;1m          Natalia Portillo\u001b[0m\n" +
            "\u001b[32m                              oMMMMNc  :WMMMMN:\u001b[0m\n" +
            "\u001b[32m                           .dWMMM0;      dWMMMMXl.                        \u001b[37;1m          Thanks to all contributors, collaborators, translators, donators and friends.\u001b[0m\n" +
            "\u001b[32m               .......,cd0WMMNk:           c0MMMMMWKkolc:clodc'\u001b[0m\n" +
            "\u001b[32m                 .';loddol:'.                 ':oxkkOkkxoc,.\u001b[0m\n" +
            "\u001b[0m\n", Version.GetVersion(),
                         #if DEBUG
            "DEBUG"
                         #else
            "RELEASE"
                         #endif
            , DetectOS.GetPlatformName(DetectOS.GetRealPlatformID()),
            Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32,
            DetectOS.IsMono ? "Mono" : ".NET Core",
            DetectOS.IsMono ? Version.GetMonoVersion() : Version.GetNetCoreVersion());

        System.Console.WriteLine("\u001b[31;1mBuilding web application...\u001b[0m");

        WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

        builder.Services.AddDbContext <AaruServerContext>(options => options.
                                                          UseMySql(builder.Configuration.GetConnectionString("DefaultConnection"),
                                                                   new
                                                                   MariaDbServerVersion(new System.
                                                                                        Version(10, 4, 0))).
                                                          UseLazyLoadingProxies());

        builder.Services.AddDefaultIdentity <IdentityUser>(options =>
        {
            options.SignIn.RequireConfirmedAccount = true;
            options.User.RequireUniqueEmail        = true;
        }).AddEntityFrameworkStores <AaruServerContext>();

        builder.Services.AddApplicationInsightsTelemetry();

        builder.Services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

        WebApplication app = builder.Build();

        app.UseForwardedHeaders(new ForwardedHeadersOptions
        {
            ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
        });

        app.UseHttpMetrics();

        if (builder.Environment.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");

            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseDefaultFiles();
        app.UseStaticFiles();

        // Add other security headers
        app.UseMiddleware <SecurityHeadersMiddleware>();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute("areas", "{area}/{controller=Home}/{action=Index}/{id?}");
            endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapRazorPages();
        });

        app.Map("/metrics", metricsApp =>
        {
            metricsApp.UseMiddleware <BasicAuthMiddleware>("Aaru");

            // We already specified URL prefix in .Map() above, no need to specify it again here.
            metricsApp.UseMetricServer("");
        });

        using (IServiceScope scope = app.Services.CreateScope())
        {
            IServiceProvider services = scope.ServiceProvider;

            try
            {
                start = DateTime.Now;
                System.Console.WriteLine("\u001b[31;1mUpdating database with Entity Framework...\u001b[0m");
                AaruServerContext context = services.GetRequiredService <AaruServerContext>();
                context.Database.Migrate();
                end = DateTime.Now;

                System.Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
                                         (end - start).TotalSeconds);

                start = DateTime.Now;
                System.Console.WriteLine("\u001b[31;1mSeeding Identity...\u001b[0m");
                Seeder.Seed(context, services);
                context.Database.Migrate();
                end = DateTime.Now;

                System.Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
                                         (end - start).TotalSeconds);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("\u001b[31;1mCould not open database...\u001b[0m");
            #if DEBUG
                System.Console.WriteLine("\u001b[31;1mException: {0}\u001b[0m", ex.Message);
            #endif
                return;
            }
        }

        System.Console.WriteLine("\u001b[31;1mStarting web server...\u001b[0m");

        app.Run();
    }
Ejemplo n.º 24
0
 public TestedSequentialMediasController(AaruServerContext context) => _context = context;
Ejemplo n.º 25
0
 public ReportsController(AaruServerContext context) => _context = context;
Ejemplo n.º 26
0
 public UsbsController(AaruServerContext context) => _context = context;
Ejemplo n.º 27
0
 public FiltersController(AaruServerContext context) => _context = context;
Ejemplo n.º 28
0
 public ScsisController(AaruServerContext context) => _context = context;
Ejemplo n.º 29
0
 public StatsController(IWebHostEnvironment environment, AaruServerContext context)
 {
     _env = environment;
     _ctx = context;
 }
Ejemplo n.º 30
0
 public SupportedDensitiesController(AaruServerContext context) => _context = context;