mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-28 19:56:50 +00:00
Refactor DNS checks
This commit is contained in:
parent
9afe61db42
commit
a0edbd636d
|
@ -6,11 +6,11 @@ import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/ssh.dart';
|
import 'package:selfprivacy/logic/get_it/ssh.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
||||||
|
|
||||||
import 'package:selfprivacy/logic/models/server_details.dart';
|
import 'package:selfprivacy/logic/models/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
|
|
||||||
import 'app_config_repository.dart';
|
import 'app_config_repository.dart';
|
||||||
|
|
||||||
export 'package:provider/provider.dart';
|
export 'package:provider/provider.dart';
|
||||||
|
|
||||||
part 'app_config_state.dart';
|
part 'app_config_state.dart';
|
||||||
|
@ -83,9 +83,10 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
var ip4 = state.hetznerServer!.ip4;
|
var ip4 = state.hetznerServer!.ip4;
|
||||||
var domainName = state.cloudFlareDomain!.domainName;
|
var domainName = state.cloudFlareDomain!.domainName;
|
||||||
|
|
||||||
var isMatch = await repository.isDnsAddressesMatch(domainName, ip4);
|
var matches = await repository.isDnsAddressesMatch(
|
||||||
|
domainName, ip4, state.dnsMatches);
|
||||||
|
|
||||||
if (isMatch) {
|
if (matches.values.every((value) => value)) {
|
||||||
var server = await repository.startServer(
|
var server = await repository.startServer(
|
||||||
state.hetznerServer!,
|
state.hetznerServer!,
|
||||||
);
|
);
|
||||||
|
@ -101,6 +102,12 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
);
|
);
|
||||||
resetServerIfServerIsOkay();
|
resetServerIfServerIsOkay();
|
||||||
} else {
|
} else {
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
dnsMatches: matches,
|
||||||
|
),
|
||||||
|
);
|
||||||
startServerIfDnsIsOkay();
|
startServerIfDnsIsOkay();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -108,7 +115,7 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
if (isImmediate) {
|
if (isImmediate) {
|
||||||
work();
|
work();
|
||||||
} else {
|
} else {
|
||||||
var pauseDuration = Duration(seconds: 60);
|
var pauseDuration = Duration(seconds: 30);
|
||||||
emit(TimerState(
|
emit(TimerState(
|
||||||
dataState: state,
|
dataState: state,
|
||||||
timerStart: DateTime.now(),
|
timerStart: DateTime.now(),
|
||||||
|
@ -289,6 +296,7 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
isServerResetedFirstTime: false,
|
isServerResetedFirstTime: false,
|
||||||
isServerResetedSecondTime: false,
|
isServerResetedSecondTime: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
dnsMatches: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
|
import 'package:basic_utils/basic_utils.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/config/hive_config.dart';
|
import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/message.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_details.dart';
|
import 'package:selfprivacy/logic/models/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/message.dart';
|
|
||||||
import 'package:basic_utils/basic_utils.dart';
|
|
||||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
||||||
|
|
||||||
import 'app_config_cubit.dart';
|
import 'app_config_cubit.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
|
||||||
|
|
||||||
class AppConfigRepository {
|
class AppConfigRepository {
|
||||||
Box box = Hive.box(BNames.appConfig);
|
Box box = Hive.box(BNames.appConfig);
|
||||||
|
@ -49,6 +50,7 @@ class AppConfigRepository {
|
||||||
isServerResetedSecondTime:
|
isServerResetedSecondTime:
|
||||||
box.get(BNames.isServerResetedSecondTime, defaultValue: false),
|
box.get(BNames.isServerResetedSecondTime, defaultValue: false),
|
||||||
isLoading: box.get(BNames.isLoading, defaultValue: false),
|
isLoading: box.get(BNames.isLoading, defaultValue: false),
|
||||||
|
dnsMatches: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +70,8 @@ class AppConfigRepository {
|
||||||
return serverDetails;
|
return serverDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isDnsAddressesMatch(String? domainName, String? ip4) async {
|
Future<Map<String, bool>> isDnsAddressesMatch(String? domainName, String? ip4,
|
||||||
|
Map<String, bool>? skippedMatches) async {
|
||||||
var addresses = <String>[
|
var addresses = <String>[
|
||||||
'$domainName',
|
'$domainName',
|
||||||
'api.$domainName',
|
'api.$domainName',
|
||||||
|
@ -77,7 +80,13 @@ class AppConfigRepository {
|
||||||
'password.$domainName'
|
'password.$domainName'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var matches = <String, bool>{};
|
||||||
|
|
||||||
for (var address in addresses) {
|
for (var address in addresses) {
|
||||||
|
if (skippedMatches != null && skippedMatches[address] == true) {
|
||||||
|
matches[address] = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var lookupRecordRes = await DnsUtils.lookupRecord(
|
var lookupRecordRes = await DnsUtils.lookupRecord(
|
||||||
address,
|
address,
|
||||||
RRecordType.A,
|
RRecordType.A,
|
||||||
|
@ -98,11 +107,13 @@ class AppConfigRepository {
|
||||||
if (lookupRecordRes == null ||
|
if (lookupRecordRes == null ||
|
||||||
lookupRecordRes.isEmpty ||
|
lookupRecordRes.isEmpty ||
|
||||||
lookupRecordRes[0].data != ip4) {
|
lookupRecordRes[0].data != ip4) {
|
||||||
return false;
|
matches[address] = false;
|
||||||
|
} else {
|
||||||
|
matches[address] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createServer(
|
Future<void> createServer(
|
||||||
|
|
|
@ -89,6 +89,7 @@ class TimerState extends AppConfigNotFinished {
|
||||||
isServerResetedFirstTime: dataState.isServerResetedFirstTime,
|
isServerResetedFirstTime: dataState.isServerResetedFirstTime,
|
||||||
isServerResetedSecondTime: dataState.isServerResetedSecondTime,
|
isServerResetedSecondTime: dataState.isServerResetedSecondTime,
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
|
dnsMatches: dataState.dnsMatches,
|
||||||
);
|
);
|
||||||
|
|
||||||
final AppConfigNotFinished dataState;
|
final AppConfigNotFinished dataState;
|
||||||
|
@ -105,6 +106,7 @@ class TimerState extends AppConfigNotFinished {
|
||||||
|
|
||||||
class AppConfigNotFinished extends AppConfigState {
|
class AppConfigNotFinished extends AppConfigState {
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
final Map<String, bool>? dnsMatches;
|
||||||
|
|
||||||
AppConfigNotFinished({
|
AppConfigNotFinished({
|
||||||
String? hetznerKey,
|
String? hetznerKey,
|
||||||
|
@ -117,6 +119,7 @@ class AppConfigNotFinished extends AppConfigState {
|
||||||
required bool isServerResetedFirstTime,
|
required bool isServerResetedFirstTime,
|
||||||
required bool isServerResetedSecondTime,
|
required bool isServerResetedSecondTime,
|
||||||
required this.isLoading,
|
required this.isLoading,
|
||||||
|
required this.dnsMatches,
|
||||||
}) : super(
|
}) : super(
|
||||||
hetznerKey: hetznerKey,
|
hetznerKey: hetznerKey,
|
||||||
cloudFlareKey: cloudFlareKey,
|
cloudFlareKey: cloudFlareKey,
|
||||||
|
@ -139,7 +142,8 @@ class AppConfigNotFinished extends AppConfigState {
|
||||||
hetznerServer,
|
hetznerServer,
|
||||||
isServerStarted,
|
isServerStarted,
|
||||||
isServerResetedFirstTime,
|
isServerResetedFirstTime,
|
||||||
isLoading
|
isLoading,
|
||||||
|
dnsMatches,
|
||||||
];
|
];
|
||||||
|
|
||||||
AppConfigNotFinished copyWith({
|
AppConfigNotFinished copyWith({
|
||||||
|
@ -153,6 +157,7 @@ class AppConfigNotFinished extends AppConfigState {
|
||||||
bool? isServerResetedFirstTime,
|
bool? isServerResetedFirstTime,
|
||||||
bool? isServerResetedSecondTime,
|
bool? isServerResetedSecondTime,
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
|
Map<String, bool>? dnsMatches,
|
||||||
}) =>
|
}) =>
|
||||||
AppConfigNotFinished(
|
AppConfigNotFinished(
|
||||||
hetznerKey: hetznerKey ?? this.hetznerKey,
|
hetznerKey: hetznerKey ?? this.hetznerKey,
|
||||||
|
@ -167,6 +172,7 @@ class AppConfigNotFinished extends AppConfigState {
|
||||||
isServerResetedSecondTime:
|
isServerResetedSecondTime:
|
||||||
isServerResetedSecondTime ?? this.isServerResetedSecondTime,
|
isServerResetedSecondTime ?? this.isServerResetedSecondTime,
|
||||||
isLoading: isLoading ?? this.isLoading,
|
isLoading: isLoading ?? this.isLoading,
|
||||||
|
dnsMatches: dnsMatches ?? this.dnsMatches,
|
||||||
);
|
);
|
||||||
|
|
||||||
AppConfigFinished finish() => AppConfigFinished(
|
AppConfigFinished finish() => AppConfigFinished(
|
||||||
|
@ -195,6 +201,7 @@ class AppConfigEmpty extends AppConfigNotFinished {
|
||||||
isServerResetedFirstTime: false,
|
isServerResetedFirstTime: false,
|
||||||
isServerResetedSecondTime: false,
|
isServerResetedSecondTime: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
dnsMatches: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:selfprivacy/config/brand_theme.dart';
|
import 'package:selfprivacy/config/brand_theme.dart';
|
||||||
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/initializing/backblaze_form_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/forms/initializing/backblaze_form_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/initializing/cloudflare_form_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/forms/initializing/cloudflare_form_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/initializing/domain_cloudflare.dart';
|
import 'package:selfprivacy/logic/cubit/forms/initializing/domain_cloudflare.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/initializing/hetzner_form_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/forms/initializing/hetzner_form_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/initializing/root_user_form_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/forms/initializing/root_user_form_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
|
||||||
import 'package:selfprivacy/logic/cubit/providers/providers_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/providers/providers_cubit.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||||
|
@ -19,7 +20,6 @@ import 'package:selfprivacy/ui/components/brand_timer/brand_timer.dart';
|
||||||
import 'package:selfprivacy/ui/components/progress_bar/progress_bar.dart';
|
import 'package:selfprivacy/ui/components/progress_bar/progress_bar.dart';
|
||||||
import 'package:selfprivacy/ui/pages/rootRoute.dart';
|
import 'package:selfprivacy/ui/pages/rootRoute.dart';
|
||||||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
|
||||||
|
|
||||||
class InitializingPage extends StatelessWidget {
|
class InitializingPage extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
|
@ -467,6 +467,22 @@ class InitializingPage extends StatelessWidget {
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
BrandText.body2(text),
|
BrandText.body2(text),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
|
if (doneCount == 0 && state.dnsMatches != null)
|
||||||
|
Column(
|
||||||
|
children: state.dnsMatches!.entries.map((entry) {
|
||||||
|
var domain = entry.key;
|
||||||
|
var isCorrect = entry.value;
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
if (isCorrect) Icon(Icons.check, color: Colors.green),
|
||||||
|
if (!isCorrect) Icon(Icons.schedule, color: Colors.amber),
|
||||||
|
SizedBox(width: 10),
|
||||||
|
Text(domain),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
SizedBox(height: 10),
|
||||||
if (!state.isLoading)
|
if (!state.isLoading)
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
|
|
Loading…
Reference in a new issue