mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
Merge pull request 'Fix installation Timer errors' (#105) from installation-timer into develop
Reviewed-on: https://git.selfprivacy.org/kherel/selfprivacy.org.app/pulls/105
This commit is contained in:
commit
dcf120bdbc
|
@ -284,7 +284,7 @@
|
||||||
"22": "Create master account",
|
"22": "Create master account",
|
||||||
"23": "Enter a nickname and strong password",
|
"23": "Enter a nickname and strong password",
|
||||||
"finish": "Everything is initialized",
|
"finish": "Everything is initialized",
|
||||||
"checks": "Checks have been completed \n{} ouf of {}"
|
"checks": "Checks have been completed \n{} out of {}"
|
||||||
},
|
},
|
||||||
"recovering": {
|
"recovering": {
|
||||||
"recovery_main_header": "Connect to an existing server",
|
"recovery_main_header": "Connect to an existing server",
|
||||||
|
|
|
@ -46,7 +46,10 @@ class ServerApi extends ApiMap {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
BaseOptions get options {
|
BaseOptions get options {
|
||||||
BaseOptions options = BaseOptions();
|
BaseOptions options = BaseOptions(
|
||||||
|
connectTimeout: 10000,
|
||||||
|
receiveTimeout: 10000,
|
||||||
|
);
|
||||||
|
|
||||||
if (isWithToken) {
|
if (isWithToken) {
|
||||||
final ServerDomain? cloudFlareDomain =
|
final ServerDomain? cloudFlareDomain =
|
||||||
|
@ -56,6 +59,8 @@ class ServerApi extends ApiMap {
|
||||||
|
|
||||||
options = BaseOptions(
|
options = BaseOptions(
|
||||||
baseUrl: 'https://api.$domainName',
|
baseUrl: 'https://api.$domainName',
|
||||||
|
connectTimeout: 10000,
|
||||||
|
receiveTimeout: 10000,
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer $apiToken',
|
'Authorization': 'Bearer $apiToken',
|
||||||
},
|
},
|
||||||
|
@ -65,6 +70,8 @@ class ServerApi extends ApiMap {
|
||||||
if (overrideDomain != null) {
|
if (overrideDomain != null) {
|
||||||
options = BaseOptions(
|
options = BaseOptions(
|
||||||
baseUrl: 'https://api.$overrideDomain',
|
baseUrl: 'https://api.$overrideDomain',
|
||||||
|
connectTimeout: 10000,
|
||||||
|
receiveTimeout: 10000,
|
||||||
headers: customToken != null
|
headers: customToken != null
|
||||||
? {'Authorization': 'Bearer $customToken'}
|
? {'Authorization': 'Bearer $customToken'}
|
||||||
: null,
|
: null,
|
||||||
|
@ -619,7 +626,7 @@ class ServerApi extends ApiMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getDkim() async {
|
Future<String> getDkim() async {
|
||||||
Response response;
|
Response response;
|
||||||
|
|
||||||
final Dio client = await getClient();
|
final Dio client = await getClient();
|
||||||
|
@ -627,13 +634,13 @@ class ServerApi extends ApiMap {
|
||||||
response = await client.get('/services/mailserver/dkim');
|
response = await client.get('/services/mailserver/dkim');
|
||||||
} on DioError catch (e) {
|
} on DioError catch (e) {
|
||||||
print(e.message);
|
print(e.message);
|
||||||
return null;
|
throw Exception('No DKIM key found');
|
||||||
} finally {
|
} finally {
|
||||||
close(client);
|
close(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.statusCode == null) {
|
if (response.statusCode == null) {
|
||||||
return null;
|
throw Exception('No DKIM key found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.statusCode == HttpStatus.notFound || response.data == null) {
|
if (response.statusCode == HttpStatus.notFound || response.data == null) {
|
||||||
|
@ -641,7 +648,7 @@ class ServerApi extends ApiMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.statusCode != HttpStatus.ok) {
|
if (response.statusCode != HttpStatus.ok) {
|
||||||
return '';
|
throw Exception('No DKIM key found');
|
||||||
}
|
}
|
||||||
|
|
||||||
final Codec<String, String> base64toString = utf8.fuse(base64);
|
final Codec<String, String> base64toString = utf8.fuse(base64);
|
||||||
|
|
|
@ -271,10 +271,6 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
dataBase: newVolume,
|
dataBase: newVolume,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (details == null) {
|
|
||||||
deleteVolume(newVolume.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,6 +316,8 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
print('Decoded data: $data');
|
print('Decoded data: $data');
|
||||||
|
|
||||||
ServerHostingDetails? serverDetails;
|
ServerHostingDetails? serverDetails;
|
||||||
|
DioError? hetznerError;
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Response serverCreateResponse = await client.post(
|
final Response serverCreateResponse = await client.post(
|
||||||
|
@ -335,16 +333,25 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
apiToken: apiToken,
|
apiToken: apiToken,
|
||||||
provider: ServerProvider.hetzner,
|
provider: ServerProvider.hetzner,
|
||||||
);
|
);
|
||||||
|
success = true;
|
||||||
} on DioError catch (e) {
|
} on DioError catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
deleteVolume(dataBase.id);
|
hetznerError = e;
|
||||||
rethrow;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
} finally {
|
} finally {
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
await Future.delayed(const Duration(seconds: 10));
|
||||||
|
await deleteVolume(dbId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hetznerError != null) {
|
||||||
|
throw hetznerError;
|
||||||
|
}
|
||||||
|
|
||||||
return serverDetails;
|
return serverDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,8 @@ class SshFormCubit extends FormCubit {
|
||||||
@override
|
@override
|
||||||
FutureOr<void> onSubmit() {
|
FutureOr<void> onSubmit() {
|
||||||
print(key.state.isValid);
|
print(key.state.isValid);
|
||||||
jobsCubit.addJob(CreateSSHKeyJob(user: user, publicKey: key.state.value));
|
jobsCubit
|
||||||
|
.addJob(CreateSSHKeyJob(user: user, publicKey: key.state.value.trim()));
|
||||||
}
|
}
|
||||||
|
|
||||||
late FieldCubit<String> key;
|
late FieldCubit<String> key;
|
||||||
|
|
|
@ -195,24 +195,10 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (matches.values.every((final bool value) => value)) {
|
if (matches.values.every((final bool value) => value)) {
|
||||||
final ServerHostingDetails? server = await repository.startServer(
|
final ServerHostingDetails server = await repository.startServer(
|
||||||
dataState.serverDetails!,
|
dataState.serverDetails!,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (server == null) {
|
|
||||||
final ServerInstallationNotFinished newState = dataState.copyWith(
|
|
||||||
isLoading: false,
|
|
||||||
dnsMatches: matches,
|
|
||||||
);
|
|
||||||
emit(newState);
|
|
||||||
runDelayed(
|
|
||||||
startServerIfDnsIsOkay,
|
|
||||||
const Duration(seconds: 30),
|
|
||||||
newState,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await repository.saveServerDetails(server);
|
await repository.saveServerDetails(server);
|
||||||
await repository.saveIsServerStarted(true);
|
await repository.saveIsServerStarted(true);
|
||||||
|
|
||||||
|
@ -338,10 +324,22 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
final bool isServerWorking = await repository.isHttpServerWorking();
|
final bool isServerWorking = await repository.isHttpServerWorking();
|
||||||
|
|
||||||
if (isServerWorking) {
|
if (isServerWorking) {
|
||||||
await repository.createDkimRecord(dataState.serverDomain!);
|
bool dkimCreated = true;
|
||||||
await repository.saveHasFinalChecked(true);
|
try {
|
||||||
|
await repository.createDkimRecord(dataState.serverDomain!);
|
||||||
emit(dataState.finish());
|
} catch (e) {
|
||||||
|
dkimCreated = false;
|
||||||
|
}
|
||||||
|
if (dkimCreated) {
|
||||||
|
await repository.saveHasFinalChecked(true);
|
||||||
|
emit(dataState.finish());
|
||||||
|
} else {
|
||||||
|
runDelayed(
|
||||||
|
finishCheckIfServerIsOkay,
|
||||||
|
const Duration(seconds: 60),
|
||||||
|
dataState,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
runDelayed(
|
runDelayed(
|
||||||
finishCheckIfServerIsOkay,
|
finishCheckIfServerIsOkay,
|
||||||
|
|
|
@ -151,10 +151,10 @@ class ServerInstallationRepository {
|
||||||
usersBox.clear();
|
usersBox.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServerHostingDetails?> startServer(
|
Future<ServerHostingDetails> startServer(
|
||||||
final ServerHostingDetails hetznerServer,
|
final ServerHostingDetails hetznerServer,
|
||||||
) async {
|
) async {
|
||||||
ServerHostingDetails? serverDetails;
|
ServerHostingDetails serverDetails;
|
||||||
|
|
||||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||||
serverDetails = await api.powerOn();
|
serverDetails = await api.powerOn();
|
||||||
|
@ -359,20 +359,20 @@ class ServerInstallationRepository {
|
||||||
dnsProviderApiFactory!.getDnsProvider();
|
dnsProviderApiFactory!.getDnsProvider();
|
||||||
final ServerApi api = ServerApi();
|
final ServerApi api = ServerApi();
|
||||||
|
|
||||||
final String? dkimRecordString = await api.getDkim();
|
String dkimRecordString = '';
|
||||||
|
try {
|
||||||
|
dkimRecordString = await api.getDkim();
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
|
||||||
await dnsProviderApi.setDkim(dkimRecordString ?? '', cloudFlareDomain);
|
await dnsProviderApi.setDkim(dkimRecordString, cloudFlareDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isHttpServerWorking() async {
|
Future<bool> isHttpServerWorking() async {
|
||||||
final ServerApi api = ServerApi();
|
final ServerApi api = ServerApi();
|
||||||
final bool isHttpServerWorking = await api.isHttpServerWorking();
|
return api.isHttpServerWorking();
|
||||||
try {
|
|
||||||
await api.getDkim();
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return isHttpServerWorking;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServerHostingDetails> restart() async {
|
Future<ServerHostingDetails> restart() async {
|
||||||
|
|
|
@ -35,11 +35,11 @@ abstract class ServerInstallationState extends Equatable {
|
||||||
final bool isServerResetedFirstTime;
|
final bool isServerResetedFirstTime;
|
||||||
final bool isServerResetedSecondTime;
|
final bool isServerResetedSecondTime;
|
||||||
|
|
||||||
bool get isProviderFilled => providerApiToken != null;
|
bool get isServerProviderFilled => providerApiToken != null;
|
||||||
bool get isCloudFlareFilled => cloudFlareKey != null;
|
bool get isDnsProviderFilled => cloudFlareKey != null;
|
||||||
bool get isBackblazeFilled => backblazeCredential != null;
|
bool get isBackupsProviderFilled => backblazeCredential != null;
|
||||||
bool get isDomainFilled => serverDomain != null;
|
bool get isDomainSelected => serverDomain != null;
|
||||||
bool get isUserFilled => rootUser != null;
|
bool get isPrimaryUserFilled => rootUser != null;
|
||||||
bool get isServerCreated => serverDetails != null;
|
bool get isServerCreated => serverDetails != null;
|
||||||
|
|
||||||
bool get isFullyInitilized => _fulfilementList.every((final el) => el!);
|
bool get isFullyInitilized => _fulfilementList.every((final el) => el!);
|
||||||
|
@ -58,11 +58,11 @@ abstract class ServerInstallationState extends Equatable {
|
||||||
|
|
||||||
List<bool?> get _fulfilementList {
|
List<bool?> get _fulfilementList {
|
||||||
final List<bool> res = [
|
final List<bool> res = [
|
||||||
isProviderFilled,
|
isServerProviderFilled,
|
||||||
isCloudFlareFilled,
|
isDnsProviderFilled,
|
||||||
isBackblazeFilled,
|
isBackupsProviderFilled,
|
||||||
isDomainFilled,
|
isDomainSelected,
|
||||||
isUserFilled,
|
isPrimaryUserFilled,
|
||||||
isServerCreated,
|
isServerCreated,
|
||||||
isServerStarted,
|
isServerStarted,
|
||||||
isServerResetedFirstTime,
|
isServerResetedFirstTime,
|
||||||
|
|
|
@ -104,7 +104,7 @@ class _Card extends StatelessWidget {
|
||||||
context.watch<ServerInstallationCubit>().state;
|
context.watch<ServerInstallationCubit>().state;
|
||||||
|
|
||||||
final String domainName =
|
final String domainName =
|
||||||
appConfig.isDomainFilled ? appConfig.serverDomain!.domainName : '';
|
appConfig.isDomainSelected ? appConfig.serverDomain!.domainName : '';
|
||||||
|
|
||||||
switch (provider.type) {
|
switch (provider.type) {
|
||||||
case ProviderType.server:
|
case ProviderType.server:
|
||||||
|
|
|
@ -42,7 +42,7 @@ class InitializingPage extends StatelessWidget {
|
||||||
() => _stepCheck(cubit),
|
() => _stepCheck(cubit),
|
||||||
() => _stepCheck(cubit),
|
() => _stepCheck(cubit),
|
||||||
() => _stepCheck(cubit),
|
() => _stepCheck(cubit),
|
||||||
() => Center(child: Text('initializing.finish'.tr()))
|
() => _stepCheck(cubit)
|
||||||
][cubit.state.progress.index]();
|
][cubit.state.progress.index]();
|
||||||
|
|
||||||
return BlocListener<ServerInstallationCubit, ServerInstallationState>(
|
return BlocListener<ServerInstallationCubit, ServerInstallationState>(
|
||||||
|
@ -60,7 +60,7 @@ class InitializingPage extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: paddingH15V0.copyWith(top: 10, bottom: 10),
|
padding: paddingH15V0.copyWith(top: 10, bottom: 10),
|
||||||
child: cubit.state.isFullyInitilized
|
child: cubit.state is ServerInstallationFinished
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
height: 80,
|
height: 80,
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,5 +4,5 @@ import 'package:selfprivacy/logic/cubit/server_installation/server_installation_
|
||||||
|
|
||||||
class UiHelpers {
|
class UiHelpers {
|
||||||
static String getDomainName(final ServerInstallationState config) =>
|
static String getDomainName(final ServerInstallationState config) =>
|
||||||
config.isDomainFilled ? config.serverDomain!.domainName : 'example.com';
|
config.isDomainSelected ? config.serverDomain!.domainName : 'example.com';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue