diff --git a/lib/logic/api_maps/rest_maps/api_factory_creator.dart b/lib/logic/api_maps/rest_maps/api_factory_creator.dart index 25518f3c..c835b0cd 100644 --- a/lib/logic/api_maps/rest_maps/api_factory_creator.dart +++ b/lib/logic/api_maps/rest_maps/api_factory_creator.dart @@ -1,5 +1,6 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart'; import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/cloudflare/cloudflare_factory.dart'; +import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns_factory.dart'; import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart'; import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/digital_ocean/digital_ocean_factory.dart'; import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner_factory.dart'; @@ -32,6 +33,8 @@ class ApiFactoryCreator { switch (settings.provider) { case DnsProvider.cloudflare: return CloudflareApiFactory(); + case DnsProvider.digitalOcean: + return DigitalOceanDnsApiFactory(); case DnsProvider.unknown: throw UnknownApiProviderException('Unknown DNS provider'); } diff --git a/lib/logic/api_maps/rest_maps/dns_providers/cloudflare/cloudflare.dart b/lib/logic/api_maps/rest_maps/dns_providers/cloudflare/cloudflare.dart index 14cf5c96..04ff622b 100644 --- a/lib/logic/api_maps/rest_maps/dns_providers/cloudflare/cloudflare.dart +++ b/lib/logic/api_maps/rest_maps/dns_providers/cloudflare/cloudflare.dart @@ -27,7 +27,7 @@ class CloudflareApi extends DnsProviderApi { BaseOptions get options { final BaseOptions options = BaseOptions(baseUrl: rootAddress); if (isWithToken) { - final String? token = getIt().cloudFlareKey; + final String? token = getIt().dnsProviderKey; assert(token != null); options.headers = {'Authorization': 'Bearer $token'}; } diff --git a/lib/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns.dart b/lib/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns.dart new file mode 100644 index 00000000..a633fa65 --- /dev/null +++ b/lib/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns.dart @@ -0,0 +1,304 @@ +import 'dart:io'; + +import 'package:dio/dio.dart'; +import 'package:selfprivacy/config/get_it_config.dart'; +import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart'; +import 'package:selfprivacy/logic/models/hive/server_domain.dart'; +import 'package:selfprivacy/logic/models/json/dns_records.dart'; + +class DigitalOceanDnsApi extends DnsProviderApi { + DigitalOceanDnsApi({ + this.hasLogger = false, + this.isWithToken = true, + this.customToken, + }); + @override + final bool hasLogger; + @override + final bool isWithToken; + + final String? customToken; + + @override + RegExp getApiTokenValidation() => + RegExp(r'\s+|[!$%^&*()@+|~=`{}\[\]:<>?,.\/]'); + + @override + BaseOptions get options { + final BaseOptions options = BaseOptions(baseUrl: rootAddress); + if (isWithToken) { + final String? token = getIt().dnsProviderKey; + assert(token != null); + options.headers = {'Authorization': 'Bearer $token'}; + } + + if (customToken != null) { + options.headers = {'Authorization': 'Bearer $customToken'}; + } + + if (validateStatus != null) { + options.validateStatus = validateStatus!; + } + return options; + } + + @override + String rootAddress = 'https://api.digitalocean.com/v2'; + + @override + Future> isApiTokenValid(final String token) async { + bool isValid = false; + Response? response; + String message = ''; + final Dio client = await getClient(); + try { + response = await client.get( + '/account', + options: Options( + followRedirects: false, + validateStatus: (final status) => + status != null && (status >= 200 || status == 401), + headers: {'Authorization': 'Bearer $token'}, + ), + ); + } catch (e) { + print(e); + isValid = false; + message = e.toString(); + } finally { + close(client); + } + + if (response == null) { + return APIGenericResult( + data: isValid, + success: false, + message: message, + ); + } + + if (response.statusCode == HttpStatus.ok) { + isValid = true; + } else if (response.statusCode == HttpStatus.unauthorized) { + isValid = false; + } else { + throw Exception('code: ${response.statusCode}'); + } + + return APIGenericResult( + data: isValid, + success: true, + message: response.statusMessage, + ); + } + + @override + // TODO: Remove from DnsProviderInterface, stub for now + Future getZoneId(final String domain) async => domain; + + @override + Future> removeSimilarRecords({ + required final ServerDomain domain, + final String? ip4, + }) async { + final String domainName = domain.domainName; + final String domainZoneId = domain.zoneId; + + final String url = '/zones/$domainZoneId/dns_records'; + + final Dio client = await getClient(); + try { + final Response response = await client.get(url); + + final List records = response.data['result'] ?? []; + final List allDeleteFutures = []; + + for (final record in records) { + if (record['zone_name'] == domainName) { + allDeleteFutures.add( + client.delete('$url/${record["id"]}'), + ); + } + } + await Future.wait(allDeleteFutures); + } catch (e) { + print(e); + return APIGenericResult( + success: false, + data: null, + message: e.toString(), + ); + } finally { + close(client); + } + + return APIGenericResult(success: true, data: null); + } + + @override + Future> getDnsRecords({ + required final ServerDomain domain, + }) async { + Response response; + final String domainName = domain.domainName; + final String domainZoneId = domain.zoneId; + final List allRecords = []; + + final String url = '/zones/$domainZoneId/dns_records'; + + final Dio client = await getClient(); + try { + response = await client.get(url); + final List records = response.data['result'] ?? []; + + for (final record in records) { + if (record['zone_name'] == domainName) { + allRecords.add( + DnsRecord( + name: record['name'], + type: record['type'], + content: record['content'], + ttl: record['ttl'], + proxied: record['proxied'], + ), + ); + } + } + } catch (e) { + print(e); + } finally { + close(client); + } + + return allRecords; + } + + @override + Future> createMultipleDnsRecords({ + required final ServerDomain domain, + final String? ip4, + }) async { + final String domainName = domain.domainName; + final String domainZoneId = domain.zoneId; + final List listDnsRecords = projectDnsRecords(domainName, ip4); + final List allCreateFutures = []; + + final Dio client = await getClient(); + try { + for (final DnsRecord record in listDnsRecords) { + allCreateFutures.add( + client.post( + '/zones/$domainZoneId/dns_records', + data: record.toJson(), + ), + ); + } + await Future.wait(allCreateFutures); + } on DioError catch (e) { + print(e.message); + rethrow; + } catch (e) { + print(e); + return APIGenericResult( + success: false, + data: null, + message: e.toString(), + ); + } finally { + close(client); + } + + return APIGenericResult(success: true, data: null); + } + + List projectDnsRecords( + final String? domainName, + final String? ip4, + ) { + final DnsRecord domainA = + DnsRecord(type: 'A', name: domainName, content: ip4); + + final DnsRecord mx = DnsRecord(type: 'MX', name: '@', content: domainName); + final DnsRecord apiA = DnsRecord(type: 'A', name: 'api', content: ip4); + final DnsRecord cloudA = DnsRecord(type: 'A', name: 'cloud', content: ip4); + final DnsRecord gitA = DnsRecord(type: 'A', name: 'git', content: ip4); + final DnsRecord meetA = DnsRecord(type: 'A', name: 'meet', content: ip4); + final DnsRecord passwordA = + DnsRecord(type: 'A', name: 'password', content: ip4); + final DnsRecord socialA = + DnsRecord(type: 'A', name: 'social', content: ip4); + final DnsRecord vpn = DnsRecord(type: 'A', name: 'vpn', content: ip4); + + final DnsRecord txt1 = DnsRecord( + type: 'TXT', + name: '_dmarc', + content: 'v=DMARC1; p=none', + ttl: 18000, + ); + + final DnsRecord txt2 = DnsRecord( + type: 'TXT', + name: domainName, + content: 'v=spf1 a mx ip4:$ip4 -all', + ttl: 18000, + ); + + return [ + domainA, + apiA, + cloudA, + gitA, + meetA, + passwordA, + socialA, + mx, + txt1, + txt2, + vpn + ]; + } + + @override + Future setDnsRecord( + final DnsRecord record, + final ServerDomain domain, + ) async { + final String domainZoneId = domain.zoneId; + final String url = '$rootAddress/zones/$domainZoneId/dns_records'; + + final Dio client = await getClient(); + try { + await client.post( + url, + data: record.toJson(), + ); + } catch (e) { + print(e); + } finally { + close(client); + } + } + + @override + Future> domainList() async { + final String url = '$rootAddress/zones'; + List domains = []; + + final Dio client = await getClient(); + try { + final Response response = await client.get( + url, + queryParameters: {'per_page': 50}, + ); + domains = response.data['result'] + .map((final el) => el['name'] as String) + .toList(); + } catch (e) { + print(e); + } finally { + close(client); + } + + return domains; + } +} diff --git a/lib/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns_factory.dart b/lib/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns_factory.dart new file mode 100644 index 00000000..715a4178 --- /dev/null +++ b/lib/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns_factory.dart @@ -0,0 +1,16 @@ +import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns.dart'; +import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart'; +import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart'; +import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart'; + +class DigitalOceanDnsApiFactory extends DnsProviderApiFactory { + @override + DnsProviderApi getDnsProvider({ + final DnsProviderApiSettings settings = const DnsProviderApiSettings(), + }) => + DigitalOceanDnsApi( + hasLogger: settings.hasLogger, + isWithToken: settings.isWithToken, + customToken: settings.customToken, + ); +} diff --git a/lib/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart b/lib/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart index 553c3492..bfcaf0f9 100644 --- a/lib/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart +++ b/lib/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart @@ -20,7 +20,7 @@ class DnsProviderFormCubit extends FormCubit { @override FutureOr onSubmit() async { - initializingCubit.setCloudflareKey(apiKey.state.value); + initializingCubit.setDnsApiToken(apiKey.state.value); } final ServerInstallationCubit initializingCubit; diff --git a/lib/logic/cubit/server_installation/server_installation_cubit.dart b/lib/logic/cubit/server_installation/server_installation_cubit.dart index c63154c0..466d255c 100644 --- a/lib/logic/cubit/server_installation/server_installation_cubit.dart +++ b/lib/logic/cubit/server_installation/server_installation_cubit.dart @@ -214,16 +214,16 @@ class ServerInstallationCubit extends Cubit { ); } - void setCloudflareKey(final String cloudFlareKey) async { + void setDnsApiToken(final String dnsApiToken) async { if (state is ServerInstallationRecovery) { - setAndValidateCloudflareToken(cloudFlareKey); + setAndValidateCloudflareToken(dnsApiToken); return; } - await repository.saveCloudFlareKey(cloudFlareKey); + await repository.setDnsApiToken(dnsApiToken); emit( (state as ServerInstallationNotFinished) - .copyWith(cloudFlareKey: cloudFlareKey), + .copyWith(dnsApiToken: dnsApiToken), ); } @@ -284,7 +284,7 @@ class ServerInstallationCubit extends Cubit { await repository.createServer( state.rootUser!, state.serverDomain!.domainName, - state.cloudFlareKey!, + state.dnsApiToken!, state.backblazeCredential!, onCancel: onCancel, onSuccess: onSuccess, @@ -586,7 +586,7 @@ class ServerInstallationCubit extends Cubit { ), ); break; - case RecoveryStep.cloudflareToken: + case RecoveryStep.dnsProviderToken: repository.deleteServerDetails(); emit( dataState.copyWith( @@ -673,7 +673,7 @@ class ServerInstallationCubit extends Cubit { emit( dataState.copyWith( serverDetails: serverDetails, - currentStep: RecoveryStep.cloudflareToken, + currentStep: RecoveryStep.dnsProviderToken, ), ); } @@ -699,7 +699,7 @@ class ServerInstallationCubit extends Cubit { provider: DnsProvider.cloudflare, ), ); - await repository.saveCloudFlareKey(token); + await repository.setDnsApiToken(token); emit( dataState.copyWith( serverDomain: ServerDomain( @@ -707,7 +707,7 @@ class ServerInstallationCubit extends Cubit { zoneId: zoneId, provider: DnsProvider.cloudflare, ), - cloudFlareKey: token, + dnsApiToken: token, currentStep: RecoveryStep.backblazeToken, ), ); @@ -754,7 +754,7 @@ class ServerInstallationCubit extends Cubit { ServerInstallationNotFinished( providerApiToken: state.providerApiToken, serverDomain: state.serverDomain, - cloudFlareKey: state.cloudFlareKey, + dnsApiToken: state.dnsApiToken, backblazeCredential: state.backblazeCredential, rootUser: state.rootUser, serverDetails: null, diff --git a/lib/logic/cubit/server_installation/server_installation_repository.dart b/lib/logic/cubit/server_installation/server_installation_repository.dart index f1aeadf5..0cb476ea 100644 --- a/lib/logic/cubit/server_installation/server_installation_repository.dart +++ b/lib/logic/cubit/server_installation/server_installation_repository.dart @@ -45,7 +45,7 @@ class ServerInstallationRepository { Future load() async { final String? providerApiToken = getIt().serverProviderKey; final String? location = getIt().serverLocation; - final String? cloudflareToken = getIt().cloudFlareKey; + final String? cloudflareToken = getIt().dnsProviderKey; final String? serverTypeIdentificator = getIt().serverType; final ServerDomain? serverDomain = getIt().serverDomain; final ServerProvider? serverProvider = @@ -86,7 +86,7 @@ class ServerInstallationRepository { return ServerInstallationFinished( providerApiToken: providerApiToken!, serverTypeIdentificator: serverTypeIdentificator ?? '', - cloudFlareKey: cloudflareToken!, + dnsApiToken: cloudflareToken!, serverDomain: serverDomain!, backblazeCredential: backblazeCredential!, serverDetails: serverDetails!, @@ -103,7 +103,7 @@ class ServerInstallationRepository { serverDomain != null) { return ServerInstallationRecovery( providerApiToken: providerApiToken, - cloudFlareKey: cloudflareToken, + dnsApiToken: cloudflareToken, serverDomain: serverDomain, backblazeCredential: backblazeCredential, serverDetails: serverDetails, @@ -120,7 +120,7 @@ class ServerInstallationRepository { return ServerInstallationNotFinished( providerApiToken: providerApiToken, - cloudFlareKey: cloudflareToken, + dnsApiToken: cloudflareToken, serverDomain: serverDomain, backblazeCredential: backblazeCredential, serverDetails: serverDetails, @@ -147,7 +147,7 @@ class ServerInstallationRepository { if (serverDomain.provider != DnsProvider.unknown) { return RecoveryStep.backblazeToken; } - return RecoveryStep.cloudflareToken; + return RecoveryStep.dnsProviderToken; } return RecoveryStep.serverSelection; } @@ -717,8 +717,8 @@ class ServerInstallationRepository { getIt().init(); } - Future saveCloudFlareKey(final String key) async { - await getIt().storeCloudFlareKey(key); + Future setDnsApiToken(final String key) async { + await getIt().storeDnsProviderKey(key); } Future deleteCloudFlareKey() async { diff --git a/lib/logic/cubit/server_installation/server_installation_state.dart b/lib/logic/cubit/server_installation/server_installation_state.dart index 331c3e2a..5ceaafdd 100644 --- a/lib/logic/cubit/server_installation/server_installation_state.dart +++ b/lib/logic/cubit/server_installation/server_installation_state.dart @@ -4,7 +4,7 @@ abstract class ServerInstallationState extends Equatable { const ServerInstallationState({ required this.providerApiToken, required this.serverTypeIdentificator, - required this.cloudFlareKey, + required this.dnsApiToken, required this.backblazeCredential, required this.serverDomain, required this.rootUser, @@ -18,7 +18,7 @@ abstract class ServerInstallationState extends Equatable { List get props => [ providerApiToken, serverTypeIdentificator, - cloudFlareKey, + dnsApiToken, backblazeCredential, serverDomain, rootUser, @@ -28,7 +28,7 @@ abstract class ServerInstallationState extends Equatable { ]; final String? providerApiToken; - final String? cloudFlareKey; + final String? dnsApiToken; final String? serverTypeIdentificator; final BackblazeCredential? backblazeCredential; final ServerDomain? serverDomain; @@ -40,7 +40,7 @@ abstract class ServerInstallationState extends Equatable { bool get isServerProviderApiKeyFilled => providerApiToken != null; bool get isServerTypeFilled => serverTypeIdentificator != null; - bool get isDnsProviderFilled => cloudFlareKey != null; + bool get isDnsProviderFilled => dnsApiToken != null; bool get isBackupsProviderFilled => backblazeCredential != null; bool get isDomainSelected => serverDomain != null; bool get isPrimaryUserFilled => rootUser != null; @@ -87,7 +87,7 @@ class TimerState extends ServerInstallationNotFinished { }) : super( providerApiToken: dataState.providerApiToken, serverTypeIdentificator: dataState.serverTypeIdentificator, - cloudFlareKey: dataState.cloudFlareKey, + dnsApiToken: dataState.dnsApiToken, backblazeCredential: dataState.backblazeCredential, serverDomain: dataState.serverDomain, rootUser: dataState.rootUser, @@ -114,7 +114,7 @@ enum ServerSetupProgress { nothingYet, serverProviderFilled, servertTypeFilled, - cloudFlareFilled, + dnsProviderFilled, backblazeFilled, domainFilled, userFilled, @@ -133,7 +133,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { required this.dnsMatches, super.providerApiToken, super.serverTypeIdentificator, - super.cloudFlareKey, + super.dnsApiToken, super.backblazeCredential, super.serverDomain, super.rootUser, @@ -146,7 +146,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { List get props => [ providerApiToken, serverTypeIdentificator, - cloudFlareKey, + dnsApiToken, backblazeCredential, serverDomain, rootUser, @@ -160,7 +160,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { ServerInstallationNotFinished copyWith({ final String? providerApiToken, final String? serverTypeIdentificator, - final String? cloudFlareKey, + final String? dnsApiToken, final BackblazeCredential? backblazeCredential, final ServerDomain? serverDomain, final User? rootUser, @@ -175,7 +175,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { providerApiToken: providerApiToken ?? this.providerApiToken, serverTypeIdentificator: serverTypeIdentificator ?? this.serverTypeIdentificator, - cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey, + dnsApiToken: dnsApiToken ?? this.dnsApiToken, backblazeCredential: backblazeCredential ?? this.backblazeCredential, serverDomain: serverDomain ?? this.serverDomain, rootUser: rootUser ?? this.rootUser, @@ -192,7 +192,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { ServerInstallationFinished finish() => ServerInstallationFinished( providerApiToken: providerApiToken!, serverTypeIdentificator: serverTypeIdentificator ?? '', - cloudFlareKey: cloudFlareKey!, + dnsApiToken: dnsApiToken!, backblazeCredential: backblazeCredential!, serverDomain: serverDomain!, rootUser: rootUser!, @@ -208,7 +208,7 @@ class ServerInstallationEmpty extends ServerInstallationNotFinished { : super( providerApiToken: null, serverTypeIdentificator: null, - cloudFlareKey: null, + dnsApiToken: null, backblazeCredential: null, serverDomain: null, rootUser: null, @@ -225,7 +225,7 @@ class ServerInstallationFinished extends ServerInstallationState { const ServerInstallationFinished({ required String super.providerApiToken, required String super.serverTypeIdentificator, - required String super.cloudFlareKey, + required String super.dnsApiToken, required BackblazeCredential super.backblazeCredential, required ServerDomain super.serverDomain, required User super.rootUser, @@ -239,7 +239,7 @@ class ServerInstallationFinished extends ServerInstallationState { List get props => [ providerApiToken, serverTypeIdentificator, - cloudFlareKey, + dnsApiToken, backblazeCredential, serverDomain, rootUser, @@ -256,7 +256,7 @@ enum RecoveryStep { oldToken, serverProviderToken, serverSelection, - cloudflareToken, + dnsProviderToken, backblazeToken, } @@ -278,7 +278,7 @@ class ServerInstallationRecovery extends ServerInstallationState { required this.recoveryCapabilities, super.providerApiToken, super.serverTypeIdentificator, - super.cloudFlareKey, + super.dnsApiToken, super.backblazeCredential, super.serverDomain, super.rootUser, @@ -295,7 +295,7 @@ class ServerInstallationRecovery extends ServerInstallationState { List get props => [ providerApiToken, serverTypeIdentificator, - cloudFlareKey, + dnsApiToken, backblazeCredential, serverDomain, rootUser, @@ -308,7 +308,7 @@ class ServerInstallationRecovery extends ServerInstallationState { ServerInstallationRecovery copyWith({ final String? providerApiToken, final String? serverTypeIdentificator, - final String? cloudFlareKey, + final String? dnsApiToken, final BackblazeCredential? backblazeCredential, final ServerDomain? serverDomain, final User? rootUser, @@ -320,7 +320,7 @@ class ServerInstallationRecovery extends ServerInstallationState { providerApiToken: providerApiToken ?? this.providerApiToken, serverTypeIdentificator: serverTypeIdentificator ?? this.serverTypeIdentificator, - cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey, + dnsApiToken: dnsApiToken ?? this.dnsApiToken, backblazeCredential: backblazeCredential ?? this.backblazeCredential, serverDomain: serverDomain ?? this.serverDomain, rootUser: rootUser ?? this.rootUser, @@ -332,7 +332,7 @@ class ServerInstallationRecovery extends ServerInstallationState { ServerInstallationFinished finish() => ServerInstallationFinished( providerApiToken: providerApiToken!, serverTypeIdentificator: serverTypeIdentificator ?? '', - cloudFlareKey: cloudFlareKey!, + dnsApiToken: dnsApiToken!, backblazeCredential: backblazeCredential!, serverDomain: serverDomain!, rootUser: rootUser!, diff --git a/lib/logic/get_it/api_config.dart b/lib/logic/get_it/api_config.dart index 434c9b32..6697c2f8 100644 --- a/lib/logic/get_it/api_config.dart +++ b/lib/logic/get_it/api_config.dart @@ -12,7 +12,7 @@ class ApiConfigModel { String? get serverProviderKey => _serverProviderKey; String? get serverLocation => _serverLocation; String? get serverType => _serverType; - String? get cloudFlareKey => _cloudFlareKey; + String? get dnsProviderKey => _dnsProviderKey; ServerProvider? get serverProvider => _serverProvider; BackblazeCredential? get backblazeCredential => _backblazeCredential; ServerDomain? get serverDomain => _serverDomain; @@ -20,7 +20,7 @@ class ApiConfigModel { String? _serverProviderKey; String? _serverLocation; - String? _cloudFlareKey; + String? _dnsProviderKey; String? _serverType; ServerProvider? _serverProvider; ServerHostingDetails? _serverDetails; @@ -38,9 +38,9 @@ class ApiConfigModel { _serverProviderKey = value; } - Future storeCloudFlareKey(final String value) async { + Future storeDnsProviderKey(final String value) async { await _box.put(BNames.cloudFlareKey, value); - _cloudFlareKey = value; + _dnsProviderKey = value; } Future storeServerTypeIdentifier(final String typeIdentifier) async { @@ -76,7 +76,7 @@ class ApiConfigModel { void clear() { _serverProviderKey = null; _serverLocation = null; - _cloudFlareKey = null; + _dnsProviderKey = null; _backblazeCredential = null; _serverDomain = null; _serverDetails = null; @@ -88,7 +88,7 @@ class ApiConfigModel { void init() { _serverProviderKey = _box.get(BNames.hetznerKey); _serverLocation = _box.get(BNames.serverLocation); - _cloudFlareKey = _box.get(BNames.cloudFlareKey); + _dnsProviderKey = _box.get(BNames.cloudFlareKey); _backblazeCredential = _box.get(BNames.backblazeCredential); _serverDomain = _box.get(BNames.serverDomain); _serverDetails = _box.get(BNames.serverDetails); diff --git a/lib/logic/models/hive/server_domain.dart b/lib/logic/models/hive/server_domain.dart index 9b5d32c1..a58ff5a1 100644 --- a/lib/logic/models/hive/server_domain.dart +++ b/lib/logic/models/hive/server_domain.dart @@ -29,4 +29,6 @@ enum DnsProvider { unknown, @HiveField(1) cloudflare, + @HiveField(2) + digitalOcean, } diff --git a/lib/ui/pages/setup/recovering/recovery_routing.dart b/lib/ui/pages/setup/recovering/recovery_routing.dart index c2fb1d13..120cf11b 100644 --- a/lib/ui/pages/setup/recovering/recovery_routing.dart +++ b/lib/ui/pages/setup/recovering/recovery_routing.dart @@ -53,7 +53,7 @@ class RecoveryRouting extends StatelessWidget { case RecoveryStep.serverSelection: currentPage = const RecoveryConfirmServer(); break; - case RecoveryStep.cloudflareToken: + case RecoveryStep.dnsProviderToken: currentPage = const RecoveryConfirmCloudflare(); break; case RecoveryStep.backblazeToken: