[#60] Services: Encrypt zip files for backup and upload
Test / Run tests (push) Successful in 2m12s

This commit is contained in:
lorenz.stechauner committed 2026-11-25 14:08:57 +01:00
1 parent f388ddbe41
commit 4bb13dbb06
10 files changed
+116 -73

No files matched your search

+2 -2
View File
@@ -28,7 +28,7 @@ namespace Elwig.Services {
}
public static async Task BackupDatabase() {
await Database.ExportSql(Path.Combine(App.Config.BackupPath, $"{File.GetLastWriteTime(App.Config.DatabaseFile):yyyy-MM-dd_HH-mm-ss}.sql.zip"), true);
await Database.ExportSql(Path.Combine(App.Config.BackupPath, $"{File.GetLastWriteTime(App.Config.DatabaseFile):yyyy-MM-dd_HH-mm-ss}.sql.zip"), true, App.Config.BackupEncryptionKey);
}
public static void PruneBackups() {
@@ -122,7 +122,7 @@ namespace Elwig.Services {
if (!InteractionService.AskContinue("Datenbank wiederherstellen", "Soll die Datenbank wirklich unwiederruflich durch die wiederhergestellte Version ersetzt werden?"))
return;
Mouse.OverrideCursor = Cursors.Wait;
await App.ReplaceDatabase(d.FileName);
await App.ReplaceDatabase(d.FileName, App.Config.BackupDecryptionKeys);
}
} catch (Exception exc) {
InteractionService.ShowException(exc);
+13 -13
View File
@@ -18,7 +18,7 @@ namespace Elwig.Services {
public static readonly Expression<Func<AreaCmtContract, bool>> ChangedAreaCmtContracts = (c) => ((c.XTime == null && c.MTime > 1751328000) || c.MTime > c.XTime) && (c.ITime == null || c.MTime > c.ITime);
public static readonly Expression<Func<Delivery, bool>> ChangedDeliveries = (d) => ((d.XTime == null && d.MTime > 1751328000) || d.MTime > d.XTime) && (d.ITime == null || d.MTime > d.ITime);
public static async Task Upload(string url, string username, string password, IQueryable<Member> query, IEnumerable<string> filterNames) {
public static async Task Upload(string url, string username, ReadOnlyMemory<char> password, IQueryable<Member> query, IEnumerable<string> filterNames) {
try {
var filename = $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip";
var path = Path.Combine(App.TempPath, filename);
@@ -54,7 +54,7 @@ namespace Elwig.Services {
InteractionService.ShowError("Mitglieder hochladen", "Es wurden keine Mitglieder zum Hochladen ausgewählt!");
} else {
var exportedAt = DateTime.Now;
await ElwigData.Export(path, members, history, areaCmts, wbKgs, filterNames);
await ElwigData.Export(path, members, history, areaCmts, wbKgs, filterNames, App.Config.SyncEncryptionKey);
await Utils.UploadExportData(path, url, username, password);
await UpdateExportedAt(members, areaCmts, [], exportedAt);
InteractionService.ShowInformation("Mitglieder hochgeladen", $"Hochladen von {members.Count:N0} Mitgliedern erfolgreich!");
@@ -68,7 +68,7 @@ namespace Elwig.Services {
}
}
public static async Task Upload(string url, string username, string password, IQueryable<DeliveryPart> query, IEnumerable<string> filterNames) {
public static async Task Upload(string url, string username, ReadOnlyMemory<char> password, IQueryable<DeliveryPart> query, IEnumerable<string> filterNames) {
try {
var filename = $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip";
var path = Path.Combine(App.TempPath, filename);
@@ -88,7 +88,7 @@ namespace Elwig.Services {
InteractionService.ShowError("Lieferungen hochladen", "Es wurden keine Lieferungen zum Hochladen ausgewählt!");
} else {
var exportedAt = DateTime.Now;
await ElwigData.Export(path, list, wbKgs, filterNames);
await ElwigData.Export(path, list, wbKgs, filterNames, App.Config.SyncEncryptionKey);
await Utils.UploadExportData(path, url, username, password);
await UpdateExportedAt([], [], list, exportedAt);
InteractionService.ShowInformation("Lieferungen hochgeladen", $"Hochladen von {list.Count:N0} Lieferungen erfolgreich!");
@@ -102,7 +102,7 @@ namespace Elwig.Services {
}
}
public static async Task UploadModified(string url, string username, string password) {
public static async Task UploadModified(string url, string username, ReadOnlyMemory<char> password) {
try {
var path = Path.Combine(App.TempPath, $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip");
List<Member> members;
@@ -145,7 +145,7 @@ namespace Elwig.Services {
AreaCmts = (areaCmts, ["geändert seit letztem Export"]),
Deliveries = (deliveries, ["geändert seit letzem Export"]),
WbKgs = (wbKgs, ["von exportierten Mitgliedern, Flächenbindungen und Lieferungen"]),
}).Export(path);
}).Export(path, App.Config.SyncEncryptionKey);
await Utils.UploadExportData(path, url, username, password);
await UpdateExportedAt(members, areaCmts, deliveries, exportedAt);
InteractionService.ShowInformation("Mitglieder und Lieferungen hochladen", $"Hochladen von {members.Count:N0} Mitgliedern, {areaCmts.Count:N0} Flächenbindungsverträgen, und {deliveries.Count:N0} Lieferungen erfolgreich!");
@@ -159,7 +159,7 @@ namespace Elwig.Services {
}
}
public static async Task UploadBranchDeliveries(string url, string username, string password, int? year = null) {
public static async Task UploadBranchDeliveries(string url, string username, ReadOnlyMemory<char> password, int? year = null) {
try {
year ??= Utils.CurrentLastSeason;
var path = Path.Combine(App.TempPath, $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip");
@@ -179,7 +179,7 @@ namespace Elwig.Services {
InteractionService.ShowError("Lieferungen hochladen", "Es gibt keine Lieferungen, die hochgeladen werden können!");
} else {
var exportedAt = DateTime.Now;
await ElwigData.Export(path, deliveries, wbKgs, [$"{year}", $"Zweigstelle {App.BranchName}"]);
await ElwigData.Export(path, deliveries, wbKgs, [$"{year}", $"Zweigstelle {App.BranchName}"], App.Config.SyncEncryptionKey);
await Utils.UploadExportData(path, url, username, password);
await UpdateExportedAt([], [], deliveries, exportedAt);
InteractionService.ShowInformation("Lieferungen hochladen", $"Hochladen von {deliveries.Count:N0} Lieferungen erfolgreich!");
@@ -193,7 +193,7 @@ namespace Elwig.Services {
}
}
public static async Task<List<(string Name, string Url)>> GetFilesToImport(string url, string username, string password) {
public static async Task<List<(string Name, string Url)>> GetFilesToImport(string url, string username, ReadOnlyMemory<char> password) {
var data = await Utils.GetExportMetaData(url, username, password);
var files = data
.Select(f => new {
@@ -214,7 +214,7 @@ namespace Elwig.Services {
];
}
public static async Task Download(string url, string username, string password, bool confirmImports) {
public static async Task Download(string url, string username, ReadOnlyMemory<char> password, bool confirmImports) {
try {
var import = await GetFilesToImport(url, username, password);
var paths = new List<string>();
@@ -226,7 +226,7 @@ namespace Elwig.Services {
paths.Add(filename);
}
}
await ElwigData.Import(paths, confirmImports ? ElwigData.ImportMode.Interactively : ElwigData.ImportMode.FromBranches);
await ElwigData.Import(paths, confirmImports ? ElwigData.ImportMode.Interactively : ElwigData.ImportMode.FromBranches, App.Config.SyncDecryptionKeys);
} catch (HttpRequestException exc) {
InteractionService.ShowException("Daten herunterladen", "Eventuell Internetverbindung prüfen!", exc);
} catch (TaskCanceledException exc) {
@@ -257,7 +257,7 @@ namespace Elwig.Services {
App.HintContextChange();
}
public static async Task<bool> ChangesAvailable(AppDbContext ctx, string url, string username, string password) {
public static async Task<bool> ChangesAvailable(AppDbContext ctx, string url, string username, ReadOnlyMemory<char> password) {
try {
return await ctx.Members.Where(ChangedMembers).AnyAsync() || await ctx.AreaCommitmentContracts.Where(ChangedAreaCmtContracts).AnyAsync() || await ctx.Deliveries.Where(ChangedDeliveries).AnyAsync() || (Utils.HasInternetConnectivity() && (await GetFilesToImport(url, username, password)).Count > 0);
} catch {
@@ -265,7 +265,7 @@ namespace Elwig.Services {
}
}
public static async Task<bool> ChangesAvailable(AppDbContext ctx, string url, string username, string password, int? year = null) {
public static async Task<bool> ChangesAvailable(AppDbContext ctx, string url, string username, ReadOnlyMemory<char> password, int? year = null) {
try {
year ??= Utils.CurrentLastSeason;
return await ctx.Deliveries.Where(d => d.ZwstId == App.ZwstId && d.Year == year).Where(ChangedDeliveries).AnyAsync() || (Utils.HasInternetConnectivity() && (await GetFilesToImport(url, username, password)).Count > 0);