mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-07 00:24:18 +00:00
Merge 'master' into 'price-calculation'
This commit is contained in:
commit
8a5ee1d42e
|
@ -2,6 +2,8 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/models/backup.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backups_credential.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/generic_result.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/rest_api_map.dart';
|
||||
|
@ -179,6 +181,42 @@ class BackblazeApi extends RestApiMap {
|
|||
}
|
||||
}
|
||||
|
||||
Future<BackblazeBucket?> fetchBucket(
|
||||
final BackupsCredential credentials,
|
||||
final BackupConfiguration configuration,
|
||||
) async {
|
||||
BackblazeBucket? bucket;
|
||||
final BackblazeApiAuth auth = await getAuthorizationToken();
|
||||
final Dio client = await getClient();
|
||||
client.options.baseUrl = auth.apiUrl;
|
||||
final Response response = await client.get(
|
||||
'$apiPrefix/b2_list_buckets',
|
||||
queryParameters: {
|
||||
'accountId': getIt<ApiConfigModel>().backblazeCredential!.keyId,
|
||||
},
|
||||
options: Options(
|
||||
headers: {'Authorization': auth.authorizationToken},
|
||||
),
|
||||
);
|
||||
close(client);
|
||||
if (response.statusCode == HttpStatus.ok) {
|
||||
for (final rawBucket in response.data['buckets']) {
|
||||
if (rawBucket['bucketId'] == configuration.locationId) {
|
||||
bucket = BackblazeBucket(
|
||||
bucketId: rawBucket['bucketId'],
|
||||
bucketName: rawBucket['bucketName'],
|
||||
encryptionKey: configuration.encryptionKey,
|
||||
applicationKeyId: '',
|
||||
applicationKey: '',
|
||||
);
|
||||
}
|
||||
}
|
||||
return bucket;
|
||||
} else {
|
||||
throw Exception('code: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool hasLogger;
|
||||
|
||||
|
|
|
@ -109,17 +109,34 @@ class BackupsCubit extends ServerInstallationDependendCubit<BackupsState> {
|
|||
|
||||
Future<void> reuploadKey() async {
|
||||
emit(state.copyWith(preventActions: true));
|
||||
final BackblazeBucket? bucket = getIt<ApiConfigModel>().backblazeBucket;
|
||||
BackblazeBucket? bucket = getIt<ApiConfigModel>().backblazeBucket;
|
||||
if (bucket == null) {
|
||||
emit(state.copyWith(isInitialized: false));
|
||||
} else {
|
||||
String login = bucket.applicationKeyId;
|
||||
String password = bucket.applicationKey;
|
||||
if (login.isEmpty || password.isEmpty) {
|
||||
final BackblazeApplicationKey key =
|
||||
await backblaze.createKey(bucket.bucketId);
|
||||
login = key.applicationKeyId;
|
||||
password = key.applicationKey;
|
||||
bucket = BackblazeBucket(
|
||||
bucketId: bucket.bucketId,
|
||||
bucketName: bucket.bucketName,
|
||||
encryptionKey: bucket.encryptionKey,
|
||||
applicationKey: password,
|
||||
applicationKeyId: login,
|
||||
);
|
||||
await getIt<ApiConfigModel>().storeBackblazeBucket(bucket);
|
||||
emit(state.copyWith(backblazeBucket: bucket));
|
||||
}
|
||||
final GenericResult result = await api.initializeRepository(
|
||||
InitializeRepositoryInput(
|
||||
provider: BackupsProviderType.backblaze,
|
||||
locationId: bucket.bucketId,
|
||||
locationName: bucket.bucketName,
|
||||
login: bucket.applicationKeyId,
|
||||
password: bucket.applicationKey,
|
||||
login: login,
|
||||
password: password,
|
||||
),
|
||||
);
|
||||
if (result.success == false) {
|
||||
|
@ -129,7 +146,7 @@ class BackupsCubit extends ServerInstallationDependendCubit<BackupsState> {
|
|||
return;
|
||||
} else {
|
||||
emit(state.copyWith(preventActions: false));
|
||||
getIt<NavigationService>().showSnackBar('backup.reuploaded_key');
|
||||
getIt<NavigationService>().showSnackBar('backup.reuploaded_key'.tr());
|
||||
await updateBackups();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,10 @@ import 'package:easy_localization/easy_localization.dart';
|
|||
import 'package:equatable/equatable.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/backblaze.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/tls_options.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_size.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backups_credential.dart';
|
||||
import 'package:selfprivacy/logic/models/callback_dialogue_branching.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
|
@ -218,8 +220,23 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
applicationKey: applicationKey,
|
||||
provider: BackupsProviderType.backblaze,
|
||||
);
|
||||
final BackblazeBucket? bucket;
|
||||
await repository.saveBackblazeKey(backblazeCredential);
|
||||
if (state is ServerInstallationRecovery) {
|
||||
final configuration = await ServerApi(
|
||||
customToken:
|
||||
(state as ServerInstallationRecovery).serverDetails!.apiToken,
|
||||
isWithToken: true,
|
||||
).getBackupsConfiguration();
|
||||
if (configuration != null) {
|
||||
try {
|
||||
bucket = await BackblazeApi()
|
||||
.fetchBucket(backblazeCredential, configuration);
|
||||
await getIt<ApiConfigModel>().storeBackblazeBucket(bucket!);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
finishRecoveryProcess(backblazeCredential);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ class ServerInstallationRepository {
|
|||
|
||||
RecoveryStep _getCurrentRecoveryStep(
|
||||
final String? serverProviderToken,
|
||||
final String? cloudflareToken,
|
||||
final String? dnsProviderToken,
|
||||
final ServerDomain serverDomain,
|
||||
final ServerHostingDetails? serverDetails,
|
||||
) {
|
||||
|
@ -218,24 +218,28 @@ class ServerInstallationRepository {
|
|||
final Map<String, bool> skippedMatches,
|
||||
) async {
|
||||
final Map<String, bool> matches = <String, bool>{};
|
||||
await InternetAddress.lookup(domainName!).then(
|
||||
(final records) {
|
||||
for (final record in records) {
|
||||
if (skippedMatches[record.host] ?? false) {
|
||||
matches[record.host] = true;
|
||||
continue;
|
||||
try {
|
||||
await InternetAddress.lookup(domainName!).then(
|
||||
(final records) {
|
||||
for (final record in records) {
|
||||
if (skippedMatches[record.host] ?? false) {
|
||||
matches[record.host] = true;
|
||||
continue;
|
||||
}
|
||||
if (record.address == ip4!) {
|
||||
matches[record.host] = true;
|
||||
}
|
||||
}
|
||||
if (record.address == ip4!) {
|
||||
matches[record.host] = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
Future<void> createDkimRecord(final ServerDomain cloudFlareDomain) async {
|
||||
Future<void> createDkimRecord(final ServerDomain domain) async {
|
||||
final ServerApi api = ServerApi();
|
||||
|
||||
late DnsRecord record;
|
||||
|
@ -248,7 +252,7 @@ class ServerInstallationRepository {
|
|||
|
||||
await ProvidersController.currentDnsProvider!.setDnsRecord(
|
||||
record,
|
||||
cloudFlareDomain,
|
||||
domain,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ class InitializingPage extends StatelessWidget {
|
|||
steps: const [
|
||||
'Hosting',
|
||||
'Server Type',
|
||||
'CloudFlare',
|
||||
'DNS Provider',
|
||||
'Backblaze',
|
||||
'Domain',
|
||||
'User',
|
||||
|
|
Loading…
Reference in a new issue