mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-25 18:26:36 +00:00
change http client
This commit is contained in:
parent
20cca91e00
commit
bc6c55b528
|
@ -29,7 +29,7 @@
|
||||||
"configuration_wizard": "Мастер Подключения",
|
"configuration_wizard": "Мастер Подключения",
|
||||||
"about_project": "О проекте SelfPrivacy",
|
"about_project": "О проекте SelfPrivacy",
|
||||||
"about_app": "О приложении",
|
"about_app": "О приложении",
|
||||||
"onboarding": "Onboarding",
|
"onboarding": "Приветствие",
|
||||||
"console": "Console",
|
"console": "Console",
|
||||||
"about_app_page": {
|
"about_app_page": {
|
||||||
"text": "Тут любая служебная информация, v.{}"
|
"text": "Тут любая служебная информация, v.{}"
|
||||||
|
|
|
@ -4,10 +4,12 @@ import 'package:selfprivacy/logic/get_it/console.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/navigation.dart';
|
import 'package:selfprivacy/logic/get_it/navigation.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/timer.dart';
|
import 'package:selfprivacy/logic/get_it/timer.dart';
|
||||||
|
|
||||||
|
export 'package:selfprivacy/logic/get_it/api_config.dart';
|
||||||
export 'package:selfprivacy/logic/get_it/console.dart';
|
export 'package:selfprivacy/logic/get_it/console.dart';
|
||||||
export 'package:selfprivacy/logic/get_it/navigation.dart';
|
export 'package:selfprivacy/logic/get_it/navigation.dart';
|
||||||
export 'package:selfprivacy/logic/get_it/timer.dart';
|
export 'package:selfprivacy/logic/get_it/timer.dart';
|
||||||
|
|
||||||
|
|
||||||
final getIt = GetIt.instance;
|
final getIt = GetIt.instance;
|
||||||
|
|
||||||
Future<void> getItSetup() async {
|
Future<void> getItSetup() async {
|
||||||
|
|
|
@ -1,32 +1,58 @@
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dio/adapter.dart';
|
import 'package:dio/adapter.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/console.dart';
|
import 'package:selfprivacy/logic/get_it/console.dart';
|
||||||
import 'package:selfprivacy/logic/models/message.dart';
|
import 'package:selfprivacy/logic/models/message.dart';
|
||||||
|
|
||||||
abstract class ApiMapOld {
|
abstract class ApiMap {
|
||||||
ApiMapOld() {
|
|
||||||
var client = Dio()..interceptors.add(ConsoleInterceptor());
|
Future<Dio> getClient() async {
|
||||||
(client.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
var dio = Dio(await options);
|
||||||
|
if (hasLoger) {
|
||||||
|
dio.interceptors.add(PrettyDioLogger());
|
||||||
|
}
|
||||||
|
dio..interceptors.add(ConsoleInterceptor());
|
||||||
|
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||||
(HttpClient client) {
|
(HttpClient client) {
|
||||||
client.badCertificateCallback =
|
client.badCertificateCallback =
|
||||||
(X509Certificate cert, String host, int port) => true;
|
(X509Certificate cert, String host, int port) => true;
|
||||||
return client;
|
return client;
|
||||||
};
|
};
|
||||||
loggedClient = client;
|
return dio;
|
||||||
}
|
}
|
||||||
String? rootAddress;
|
|
||||||
|
|
||||||
late Dio loggedClient;
|
FutureOr<BaseOptions> get options;
|
||||||
|
|
||||||
void close() {
|
abstract final String rootAddress;
|
||||||
loggedClient.close();
|
abstract final bool hasLoger;
|
||||||
}
|
abstract final bool isWithToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// abstract class ApiMapOld {
|
||||||
|
// ApiMapOld() {
|
||||||
|
// var client = Dio()..interceptors.add(ConsoleInterceptor());
|
||||||
|
// (client.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||||
|
// (HttpClient client) {
|
||||||
|
// client.badCertificateCallback =
|
||||||
|
// (X509Certificate cert, String host, int port) => true;
|
||||||
|
// return client;
|
||||||
|
// };
|
||||||
|
// loggedClient = client;
|
||||||
|
// }
|
||||||
|
// String? rootAddress;
|
||||||
|
|
||||||
|
// late Dio loggedClient;
|
||||||
|
|
||||||
|
// void close() {
|
||||||
|
// loggedClient.close();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
class ConsoleInterceptor extends InterceptorsWrapper {
|
class ConsoleInterceptor extends InterceptorsWrapper {
|
||||||
void addMessage(Message message) {
|
void addMessage(Message message) {
|
||||||
getIt.get<ConsoleModel>().addMessage(message);
|
getIt.get<ConsoleModel>().addMessage(message);
|
||||||
|
|
|
@ -1,31 +1,38 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||||
|
|
||||||
class BackblazeApi extends ApiMapOld {
|
class BackblazeApi extends ApiMap {
|
||||||
BackblazeApi([String? token]) {
|
BackblazeApi({this.hasLoger = false, this.isWithToken = true});
|
||||||
if (token != null) {
|
|
||||||
loggedClient.options = BaseOptions(
|
BaseOptions get options {
|
||||||
headers: {'Authorization': 'Basic $token'},
|
var options = BaseOptions(baseUrl: rootAddress);
|
||||||
baseUrl: rootAddress!,
|
if (isWithToken) {
|
||||||
);
|
var backblazeCredential = getIt<ApiConfigModel>().backblazeCredential;
|
||||||
|
var token = backblazeCredential!.applicationKey;
|
||||||
|
assert(token != null);
|
||||||
|
options.headers = {'Authorization': 'Basic $token'};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (validateStatus != null) {
|
||||||
|
options.validateStatus = validateStatus!;
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValidateStatus? validateStatus;
|
||||||
@override
|
@override
|
||||||
String? rootAddress =
|
String rootAddress = 'https://api.backblazeb2.com/b2api/v2/';
|
||||||
'https://api.backblazeb2.com/b2api/v2/b2_authorize_account';
|
|
||||||
|
|
||||||
Future<bool> isValid(String token) async {
|
Future<bool> isValid(String encodedApiKey) async {
|
||||||
var options = Options(
|
var client = await getClient();
|
||||||
headers: {'Authorization': 'Basic $token'},
|
Response response = await client.get(
|
||||||
validateStatus: (status) {
|
'b2_authorize_account',
|
||||||
return status == HttpStatus.ok || status == HttpStatus.unauthorized;
|
options: Options(headers: {'Authorization': 'Basic $encodedApiKey'}),
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
client.close();
|
||||||
Response response = await loggedClient.get(rootAddress!, options: options);
|
|
||||||
|
|
||||||
if (response.statusCode == HttpStatus.ok) {
|
if (response.statusCode == HttpStatus.ok) {
|
||||||
return true;
|
return true;
|
||||||
} else if (response.statusCode == HttpStatus.unauthorized) {
|
} else if (response.statusCode == HttpStatus.unauthorized) {
|
||||||
|
@ -34,4 +41,10 @@ class BackblazeApi extends ApiMapOld {
|
||||||
throw Exception('code: ${response.statusCode}');
|
throw Exception('code: ${response.statusCode}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool hasLoger;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool isWithToken;
|
||||||
}
|
}
|
|
@ -1,30 +1,43 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||||
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/dns_records.dart';
|
import 'package:selfprivacy/logic/models/dns_records.dart';
|
||||||
|
|
||||||
class CloudflareApi extends ApiMapOld {
|
class CloudflareApi extends ApiMap {
|
||||||
CloudflareApi([String? token]) {
|
CloudflareApi({this.hasLoger = false, this.isWithToken = true});
|
||||||
if (token != null) {
|
|
||||||
loggedClient.options =
|
BaseOptions get options {
|
||||||
BaseOptions(headers: {'Authorization': 'Bearer $token'});
|
var options = BaseOptions(baseUrl: rootAddress);
|
||||||
|
if (isWithToken) {
|
||||||
|
var token = getIt<ApiConfigModel>().cloudFlareKey;
|
||||||
|
assert(token != null);
|
||||||
|
options.headers = {'Authorization': 'Bearer $token'};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (validateStatus != null) {
|
||||||
|
options.validateStatus = validateStatus!;
|
||||||
|
}
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValidateStatus? validateStatus;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String? rootAddress = 'https://api.cloudflare.com/client/v4';
|
String rootAddress = 'https://api.cloudflare.com/client/v4';
|
||||||
|
|
||||||
Future<bool> isValid(String token) async {
|
Future<bool> isValid(String token) async {
|
||||||
var url = '$rootAddress/user/tokens/verify';
|
validateStatus = (status) {
|
||||||
var options = Options(
|
return status == HttpStatus.ok || status == HttpStatus.unauthorized;
|
||||||
headers: {'Authorization': 'Bearer $token'},
|
};
|
||||||
validateStatus: (status) {
|
|
||||||
return status == HttpStatus.ok || status == HttpStatus.unauthorized;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
Response response = await loggedClient.get(url, options: options);
|
var client = await getClient();
|
||||||
|
Response response = await client.get('/user/tokens/verify',
|
||||||
|
options: Options(headers: {'Authorization': 'Bearer $token'}));
|
||||||
|
|
||||||
|
client.close();
|
||||||
|
validateStatus = null;
|
||||||
|
|
||||||
if (response.statusCode == HttpStatus.ok) {
|
if (response.statusCode == HttpStatus.ok) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -35,22 +48,19 @@ class CloudflareApi extends ApiMapOld {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getZoneId(String? token, String domain) async {
|
Future<String?> getZoneId(String domain) async {
|
||||||
var url = '$rootAddress/zones';
|
validateStatus = (status) {
|
||||||
|
return status == HttpStatus.ok || status == HttpStatus.forbidden;
|
||||||
var options = Options(
|
};
|
||||||
headers: {'Authorization': 'Bearer $token'},
|
var client = await getClient();
|
||||||
validateStatus: (status) {
|
Response response = await client.get(
|
||||||
return status == HttpStatus.ok || status == HttpStatus.forbidden;
|
'/zones',
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
Response response = await loggedClient.get(
|
|
||||||
url,
|
|
||||||
options: options,
|
|
||||||
queryParameters: {'name': domain},
|
queryParameters: {'name': domain},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
client.close();
|
||||||
|
validateStatus = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return response.data['result'][0]['id'];
|
return response.data['result'][0]['id'];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -65,20 +75,24 @@ class CloudflareApi extends ApiMapOld {
|
||||||
var domainName = cloudFlareDomain.domainName;
|
var domainName = cloudFlareDomain.domainName;
|
||||||
var domainZoneId = cloudFlareDomain.zoneId;
|
var domainZoneId = cloudFlareDomain.zoneId;
|
||||||
|
|
||||||
var url = '$rootAddress/zones/$domainZoneId/dns_records';
|
var url = '/zones/$domainZoneId/dns_records';
|
||||||
|
|
||||||
|
var client = await getClient();
|
||||||
|
Response response = await client.get(url);
|
||||||
|
|
||||||
var response = await loggedClient.get(url);
|
|
||||||
List records = response.data['result'] ?? [];
|
List records = response.data['result'] ?? [];
|
||||||
var allDeleteFutures = <Future>[];
|
var allDeleteFutures = <Future>[];
|
||||||
|
|
||||||
for (var record in records) {
|
for (var record in records) {
|
||||||
if (record['zone_name'] == domainName) {
|
if (record['zone_name'] == domainName) {
|
||||||
allDeleteFutures.add(
|
allDeleteFutures.add(
|
||||||
loggedClient.delete('$url/${record["id"]}'),
|
client.delete('$url/${record["id"]}'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Future.wait(allDeleteFutures);
|
await Future.wait(allDeleteFutures);
|
||||||
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createMultipleDnsRecords({
|
Future<void> createMultipleDnsRecords({
|
||||||
|
@ -92,10 +106,11 @@ class CloudflareApi extends ApiMapOld {
|
||||||
var url = '$rootAddress/zones/$domainZoneId/dns_records';
|
var url = '$rootAddress/zones/$domainZoneId/dns_records';
|
||||||
|
|
||||||
var allCreateFutures = <Future>[];
|
var allCreateFutures = <Future>[];
|
||||||
|
var client = await getClient();
|
||||||
|
|
||||||
for (var record in listDnsRecords) {
|
for (var record in listDnsRecords) {
|
||||||
allCreateFutures.add(
|
allCreateFutures.add(
|
||||||
loggedClient.post(
|
client.post(
|
||||||
url,
|
url,
|
||||||
data: record.toJson(),
|
data: record.toJson(),
|
||||||
),
|
),
|
||||||
|
@ -103,23 +118,9 @@ class CloudflareApi extends ApiMapOld {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Future.wait(allCreateFutures);
|
await Future.wait(allCreateFutures);
|
||||||
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// setDkim(String dkimRecordString, String domainZoneId) {
|
|
||||||
// var txt3 = DnsRecords(
|
|
||||||
// type: 'TXT',
|
|
||||||
// name: 'selector._domainkey',
|
|
||||||
// content: dkimRecordString,
|
|
||||||
// ttl: 18000,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// var url = '$rootAddress/zones/$domainZoneId/dns_records';
|
|
||||||
// loggedClient.post(
|
|
||||||
// url,
|
|
||||||
// data: txt3.toJson(),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
List<DnsRecords> projectDnsRecords(String? domainName, String? ip4) {
|
List<DnsRecords> projectDnsRecords(String? domainName, String? ip4) {
|
||||||
var domainA = DnsRecords(type: 'A', name: domainName, content: ip4);
|
var domainA = DnsRecords(type: 'A', name: domainName, content: ip4);
|
||||||
|
|
||||||
|
@ -163,13 +164,22 @@ class CloudflareApi extends ApiMapOld {
|
||||||
|
|
||||||
Future<List<String>> domainList() async {
|
Future<List<String>> domainList() async {
|
||||||
var url = '$rootAddress/zones?per_page=50';
|
var url = '$rootAddress/zones?per_page=50';
|
||||||
var response = await loggedClient.get(
|
var client = await getClient();
|
||||||
|
|
||||||
|
var response = await client.get(
|
||||||
url,
|
url,
|
||||||
queryParameters: {'per_page': 50},
|
queryParameters: {'per_page': 50},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
client.close();
|
||||||
return response.data['result']
|
return response.data['result']
|
||||||
.map<String>((el) => el['name'] as String)
|
.map<String>((el) => el['name'] as String)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final bool hasLoger;
|
||||||
|
|
||||||
|
@override
|
||||||
|
final bool isWithToken;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,33 +2,50 @@ import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
import 'package:selfprivacy/logic/api_maps/api_map.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/utils/password_generator2.dart';
|
import 'package:selfprivacy/utils/password_generator2.dart';
|
||||||
|
|
||||||
class HetznerApi extends ApiMapOld {
|
class HetznerApi extends ApiMap {
|
||||||
HetznerApi([String? token]) {
|
bool hasLoger;
|
||||||
if (token != null) {
|
bool isWithToken;
|
||||||
loggedClient.options = BaseOptions(
|
|
||||||
headers: {'Authorization': 'Bearer $token'},
|
HetznerApi({this.hasLoger = false, this.isWithToken = true});
|
||||||
baseUrl: rootAddress!,
|
|
||||||
);
|
BaseOptions get options {
|
||||||
|
var options = BaseOptions(baseUrl: rootAddress);
|
||||||
|
if (isWithToken) {
|
||||||
|
var token = getIt<ApiConfigModel>().hetznerKey;
|
||||||
|
assert(token != null);
|
||||||
|
options.headers = {'Authorization': 'Bearer $token'};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (validateStatus != null) {
|
||||||
|
options.validateStatus = validateStatus!;
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValidateStatus? validateStatus;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String? rootAddress = 'https://api.hetzner.cloud/v1/servers';
|
String rootAddress = 'https://api.hetzner.cloud/v1';
|
||||||
|
|
||||||
Future<bool> isValid(String token) async {
|
Future<bool> isValid(String token) async {
|
||||||
var options = Options(
|
validateStatus = (status) {
|
||||||
headers: {'Authorization': 'Bearer $token'},
|
return status == HttpStatus.ok || status == HttpStatus.unauthorized;
|
||||||
validateStatus: (status) {
|
};
|
||||||
return status == HttpStatus.ok || status == HttpStatus.unauthorized;
|
var client = await getClient();
|
||||||
},
|
Response response = await client.get(
|
||||||
|
'/servers',
|
||||||
|
options: Options(
|
||||||
|
headers: {'Authorization': 'Bearer $token'},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
client.close();
|
||||||
Response response = await loggedClient.get(rootAddress!, options: options);
|
|
||||||
|
|
||||||
if (response.statusCode == HttpStatus.ok) {
|
if (response.statusCode == HttpStatus.ok) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -40,9 +57,9 @@ class HetznerApi extends ApiMapOld {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<HetznerServerDetails> createServer({
|
Future<HetznerServerDetails> createServer({
|
||||||
required String? cloudFlareKey,
|
required String cloudFlareKey,
|
||||||
required User rootUser,
|
required User rootUser,
|
||||||
required String? domainName,
|
required String domainName,
|
||||||
}) async {
|
}) async {
|
||||||
var dbPassword = getRandomString(40);
|
var dbPassword = getRandomString(40);
|
||||||
|
|
||||||
|
@ -50,11 +67,12 @@ class HetznerApi extends ApiMapOld {
|
||||||
'''{"name":"selfprivacy-server","server_type":"cx11","start_after_create":false,"image":"ubuntu-20.04", "volumes":[],"networks":[],"user_data":"#cloud-config\\nruncmd:\\n- curl https://git.selfprivacy.org/ilchub/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-20.09 DOMAIN=$domainName LUSER=${rootUser.login} PASSWORD=${rootUser.password} HASHED_PASSWORD=${rootUser.hashPassword} CF_TOKEN=$cloudFlareKey DB_PASSWORD=$dbPassword bash 2>&1 | tee /tmp/infect.log","labels":{},"automount":false}''',
|
'''{"name":"selfprivacy-server","server_type":"cx11","start_after_create":false,"image":"ubuntu-20.04", "volumes":[],"networks":[],"user_data":"#cloud-config\\nruncmd:\\n- curl https://git.selfprivacy.org/ilchub/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-20.09 DOMAIN=$domainName LUSER=${rootUser.login} PASSWORD=${rootUser.password} HASHED_PASSWORD=${rootUser.hashPassword} CF_TOKEN=$cloudFlareKey DB_PASSWORD=$dbPassword bash 2>&1 | tee /tmp/infect.log","labels":{},"automount":false}''',
|
||||||
);
|
);
|
||||||
|
|
||||||
Response response = await loggedClient.post(
|
var client = await getClient();
|
||||||
rootAddress!,
|
Response response = await client.post(
|
||||||
|
'/servers',
|
||||||
data: data,
|
data: data,
|
||||||
);
|
);
|
||||||
|
client.close();
|
||||||
return HetznerServerDetails(
|
return HetznerServerDetails(
|
||||||
id: response.data['server']['id'],
|
id: response.data['server']['id'],
|
||||||
ip4: response.data['server']['public_net']['ipv4']['ip'],
|
ip4: response.data['server']['public_net']['ipv4']['ip'],
|
||||||
|
@ -62,20 +80,23 @@ class HetznerApi extends ApiMapOld {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteSelfprivacyServer({
|
Future<void> deleteSelfprivacyServer() async {
|
||||||
required String? cloudFlareKey,
|
var client = await getClient();
|
||||||
}) async {
|
Response response = await client.get('/servers');
|
||||||
Response response = await loggedClient.get(rootAddress!);
|
|
||||||
|
|
||||||
List list = response.data['servers'];
|
List list = response.data['servers'];
|
||||||
var server = list.firstWhere((el) => el['name'] == 'selfprivacy-server');
|
var server = list.firstWhere((el) => el['name'] == 'selfprivacy-server');
|
||||||
await loggedClient.delete('$rootAddress/${server['id']}');
|
await client.delete('/servers/${server['id']}');
|
||||||
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<HetznerServerDetails> startServer({
|
Future<HetznerServerDetails> startServer({
|
||||||
required HetznerServerDetails server,
|
required HetznerServerDetails server,
|
||||||
}) async {
|
}) async {
|
||||||
await loggedClient.post('/${server.id}/actions/poweron');
|
var client = await getClient();
|
||||||
|
|
||||||
|
await client.post('/servers/${server.id}/actions/poweron');
|
||||||
|
client.close();
|
||||||
|
|
||||||
return server.copyWith(
|
return server.copyWith(
|
||||||
startTime: DateTime.now(),
|
startTime: DateTime.now(),
|
||||||
|
@ -85,10 +106,25 @@ class HetznerApi extends ApiMapOld {
|
||||||
Future<HetznerServerDetails> restart({
|
Future<HetznerServerDetails> restart({
|
||||||
required HetznerServerDetails server,
|
required HetznerServerDetails server,
|
||||||
}) async {
|
}) async {
|
||||||
await loggedClient.post('/${server.id}/actions/poweron');
|
var client = await getClient();
|
||||||
|
await client.post('/servers/${server.id}/actions/poweron');
|
||||||
|
client.close();
|
||||||
return server.copyWith(
|
return server.copyWith(
|
||||||
startTime: DateTime.now(),
|
startTime: DateTime.now(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metrics() async {
|
||||||
|
var hetznerServer = getIt<ApiConfigModel>().hetznerServer;
|
||||||
|
var client = await getClient();
|
||||||
|
await client.post('/servers/${hetznerServer!.id}/metrics');
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
getInfo() async {
|
||||||
|
var hetznerServer = getIt<ApiConfigModel>().hetznerServer;
|
||||||
|
var client = await getClient();
|
||||||
|
await client.post('/servers/${hetznerServer!.id}');
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,46 @@
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
|
|
||||||
import 'api_map.dart';
|
import 'api_map.dart';
|
||||||
|
|
||||||
class ServerApi extends ApiMapOld {
|
class ServerApi extends ApiMap {
|
||||||
ServerApi(String? domainName) {
|
bool hasLoger;
|
||||||
loggedClient.options = BaseOptions(
|
bool isWithToken;
|
||||||
baseUrl: 'https://api.$domainName',
|
|
||||||
);
|
ServerApi({this.hasLoger = false, this.isWithToken = true});
|
||||||
|
|
||||||
|
BaseOptions get options {
|
||||||
|
var options = BaseOptions();
|
||||||
|
|
||||||
|
if (isWithToken) {
|
||||||
|
var cloudFlareDomain = getIt<ApiConfigModel>().cloudFlareDomain;
|
||||||
|
var domainName = cloudFlareDomain!.domainName;
|
||||||
|
assert(domainName != null);
|
||||||
|
|
||||||
|
options = BaseOptions(baseUrl: 'https://api.$domainName');
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isHttpServerWorking() async {
|
Future<bool> isHttpServerWorking() async {
|
||||||
bool res;
|
bool res;
|
||||||
Response response;
|
Response response;
|
||||||
|
|
||||||
|
var client = await getClient();
|
||||||
try {
|
try {
|
||||||
response = await loggedClient.get('/serviceStatus');
|
response = await client.get('/serviceStatus');
|
||||||
res = response.statusCode == HttpStatus.ok;
|
res = response.statusCode == HttpStatus.ok;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
client.close();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Future<String> getDkim(String domainName) async {
|
String get rootAddress =>
|
||||||
// var response = await loggedClient.get(
|
throw UnimplementedError('not used in with implementation');
|
||||||
// '/getDKIM',
|
|
||||||
// options: Options(responseType: ResponseType.plain),
|
|
||||||
// );
|
|
||||||
// return _decodeAndCutData(response.data, domainName);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String _decodeAndCutData(String text, String domainName) {
|
|
||||||
// var decodedTextString = text.substring(1, text.length - 1);
|
|
||||||
// var stringToBase64 = utf8.fuse(base64);
|
|
||||||
|
|
||||||
// return stringToBase64
|
|
||||||
// .decode(decodedTextString)
|
|
||||||
// .replaceAll("selector._domainkey IN TXT ( ", "")
|
|
||||||
// .replaceAll("\"\n \"", "")
|
|
||||||
// .replaceAll(' ) ; ----- DKIM key selector for $domainName\n', '');
|
|
||||||
// }
|
|
||||||
|
|
|
@ -74,7 +74,6 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
|
|
||||||
if (isMatch) {
|
if (isMatch) {
|
||||||
var server = await repository.startServer(
|
var server = await repository.startServer(
|
||||||
state.hetznerKey,
|
|
||||||
state.hetznerServer!,
|
state.hetznerServer!,
|
||||||
);
|
);
|
||||||
repository.saveServerDetails(server);
|
repository.saveServerDetails(server);
|
||||||
|
@ -111,33 +110,30 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
AppConfigState? state,
|
AppConfigState? state,
|
||||||
bool isImmediate = false,
|
bool isImmediate = false,
|
||||||
}) async {
|
}) async {
|
||||||
state = state ?? this.state;
|
var dataState = state ?? this.state;
|
||||||
|
|
||||||
var work = () async {
|
var work = () async {
|
||||||
emit(TimerState(dataState: state!, isLoading: true));
|
emit(TimerState(dataState: dataState, isLoading: true));
|
||||||
|
|
||||||
var isServerWorking = await repository.isHttpServerWorking(
|
var isServerWorking = await repository.isHttpServerWorking();
|
||||||
state.cloudFlareDomain!.domainName,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isServerWorking) {
|
if (isServerWorking) {
|
||||||
var pauseDuration = Duration(seconds: 30);
|
var pauseDuration = Duration(seconds: 30);
|
||||||
emit(TimerState(
|
emit(TimerState(
|
||||||
dataState: state,
|
dataState: dataState,
|
||||||
timerStart: DateTime.now(),
|
timerStart: DateTime.now(),
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
duration: pauseDuration,
|
duration: pauseDuration,
|
||||||
));
|
));
|
||||||
timer = Timer(pauseDuration, () async {
|
timer = Timer(pauseDuration, () async {
|
||||||
var hetznerServerDetails = await repository.restart(
|
var hetznerServerDetails = await repository.restart(
|
||||||
state!.hetznerKey,
|
dataState.hetznerServer!,
|
||||||
state.hetznerServer!,
|
|
||||||
);
|
);
|
||||||
repository.saveIsServerReseted(true);
|
repository.saveIsServerReseted(true);
|
||||||
repository.saveServerDetails(hetznerServerDetails);
|
repository.saveServerDetails(hetznerServerDetails);
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
dataState.copyWith(
|
||||||
isServerReseted: true,
|
isServerReseted: true,
|
||||||
hetznerServer: hetznerServerDetails,
|
hetznerServer: hetznerServerDetails,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
@ -155,7 +151,7 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
var pauseDuration = Duration(seconds: 60);
|
var pauseDuration = Duration(seconds: 60);
|
||||||
emit(
|
emit(
|
||||||
TimerState(
|
TimerState(
|
||||||
dataState: state,
|
dataState: dataState,
|
||||||
timerStart: DateTime.now(),
|
timerStart: DateTime.now(),
|
||||||
duration: pauseDuration,
|
duration: pauseDuration,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
@ -176,9 +172,7 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
var work = () async {
|
var work = () async {
|
||||||
emit(TimerState(dataState: state!, isLoading: true));
|
emit(TimerState(dataState: state!, isLoading: true));
|
||||||
|
|
||||||
var isServerWorking = await repository.isHttpServerWorking(
|
var isServerWorking = await repository.isHttpServerWorking();
|
||||||
state.cloudFlareDomain!.domainName,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isServerWorking) {
|
if (isServerWorking) {
|
||||||
repository.saveHasFinalChecked(true);
|
repository.saveHasFinalChecked(true);
|
||||||
|
@ -246,7 +240,6 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
AppConfigState _stateCopy = state;
|
AppConfigState _stateCopy = state;
|
||||||
var onSuccess = (serverDetails) async {
|
var onSuccess = (serverDetails) async {
|
||||||
await repository.createDnsRecords(
|
await repository.createDnsRecords(
|
||||||
state.cloudFlareKey,
|
|
||||||
serverDetails.ip4,
|
serverDetails.ip4,
|
||||||
state.cloudFlareDomain!,
|
state.cloudFlareDomain!,
|
||||||
);
|
);
|
||||||
|
@ -263,10 +256,9 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
try {
|
try {
|
||||||
emit(state.copyWith(isLoading: true));
|
emit(state.copyWith(isLoading: true));
|
||||||
await repository.createServer(
|
await repository.createServer(
|
||||||
state.hetznerKey,
|
|
||||||
state.rootUser!,
|
state.rootUser!,
|
||||||
state.cloudFlareDomain!.domainName,
|
state.cloudFlareDomain!.domainName!,
|
||||||
state.cloudFlareKey,
|
state.cloudFlareKey!,
|
||||||
onCancel: onCancel,
|
onCancel: onCancel,
|
||||||
onSuccess: onSuccess,
|
onSuccess: onSuccess,
|
||||||
);
|
);
|
||||||
|
|
|
@ -22,7 +22,7 @@ class AppConfigRepository {
|
||||||
Box box = Hive.box(BNames.appConfig);
|
Box box = Hive.box(BNames.appConfig);
|
||||||
|
|
||||||
AppConfigState load() {
|
AppConfigState load() {
|
||||||
return AppConfigState(
|
var res = AppConfigState(
|
||||||
hetznerKey: getIt<ApiConfigModel>().hetznerKey,
|
hetznerKey: getIt<ApiConfigModel>().hetznerKey,
|
||||||
cloudFlareKey: getIt<ApiConfigModel>().cloudFlareKey,
|
cloudFlareKey: getIt<ApiConfigModel>().cloudFlareKey,
|
||||||
cloudFlareDomain: getIt<ApiConfigModel>().cloudFlareDomain,
|
cloudFlareDomain: getIt<ApiConfigModel>().cloudFlareDomain,
|
||||||
|
@ -35,6 +35,8 @@ class AppConfigRepository {
|
||||||
error: null,
|
error: null,
|
||||||
isLoading: box.get(BNames.isLoading, defaultValue: false),
|
isLoading: box.get(BNames.isLoading, defaultValue: false),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearAppConfig() {
|
void clearAppConfig() {
|
||||||
|
@ -42,12 +44,10 @@ class AppConfigRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<HetznerServerDetails> startServer(
|
Future<HetznerServerDetails> startServer(
|
||||||
String? hetznerKey,
|
|
||||||
HetznerServerDetails hetznerServer,
|
HetznerServerDetails hetznerServer,
|
||||||
) async {
|
) async {
|
||||||
var hetznerApi = HetznerApi(hetznerKey);
|
var hetznerApi = HetznerApi();
|
||||||
var serverDetails = await hetznerApi.startServer(server: hetznerServer);
|
var serverDetails = await hetznerApi.startServer(server: hetznerServer);
|
||||||
hetznerApi.close();
|
|
||||||
|
|
||||||
return serverDetails;
|
return serverDetails;
|
||||||
}
|
}
|
||||||
|
@ -90,15 +90,14 @@ class AppConfigRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createServer(
|
Future<void> createServer(
|
||||||
String? hetznerKey,
|
|
||||||
User rootUser,
|
User rootUser,
|
||||||
String? domainName,
|
String domainName,
|
||||||
String? cloudFlareKey, {
|
String cloudFlareKey, {
|
||||||
void Function()? onCancel,
|
required void Function() onCancel,
|
||||||
required Future<void> Function(HetznerServerDetails serverDetails)
|
required Future<void> Function(HetznerServerDetails serverDetails)
|
||||||
onSuccess,
|
onSuccess,
|
||||||
}) async {
|
}) async {
|
||||||
var hetznerApi = HetznerApi(hetznerKey);
|
var hetznerApi = HetznerApi();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var serverDetails = await hetznerApi.createServer(
|
var serverDetails = await hetznerApi.createServer(
|
||||||
|
@ -106,7 +105,6 @@ class AppConfigRepository {
|
||||||
rootUser: rootUser,
|
rootUser: rootUser,
|
||||||
domainName: domainName,
|
domainName: domainName,
|
||||||
);
|
);
|
||||||
hetznerApi.close();
|
|
||||||
saveServerDetails(serverDetails);
|
saveServerDetails(serverDetails);
|
||||||
onSuccess(serverDetails);
|
onSuccess(serverDetails);
|
||||||
} on DioError catch (e) {
|
} on DioError catch (e) {
|
||||||
|
@ -121,16 +119,13 @@ class AppConfigRepository {
|
||||||
text: 'basis.delete'.tr(),
|
text: 'basis.delete'.tr(),
|
||||||
isRed: true,
|
isRed: true,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await hetznerApi.deleteSelfprivacyServer(
|
await hetznerApi.deleteSelfprivacyServer();
|
||||||
cloudFlareKey: cloudFlareKey,
|
|
||||||
);
|
|
||||||
|
|
||||||
var serverDetails = await hetznerApi.createServer(
|
var serverDetails = await hetznerApi.createServer(
|
||||||
cloudFlareKey: cloudFlareKey,
|
cloudFlareKey: cloudFlareKey,
|
||||||
rootUser: rootUser,
|
rootUser: rootUser,
|
||||||
domainName: domainName,
|
domainName: domainName,
|
||||||
);
|
);
|
||||||
hetznerApi.close();
|
|
||||||
|
|
||||||
await saveServerDetails(serverDetails);
|
await saveServerDetails(serverDetails);
|
||||||
onSuccess(serverDetails);
|
onSuccess(serverDetails);
|
||||||
|
@ -139,8 +134,7 @@ class AppConfigRepository {
|
||||||
ActionButton(
|
ActionButton(
|
||||||
text: 'basis.cancel'.tr(),
|
text: 'basis.cancel'.tr(),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
hetznerApi.close();
|
onCancel();
|
||||||
onCancel!();
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -151,11 +145,10 @@ class AppConfigRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createDnsRecords(
|
Future<void> createDnsRecords(
|
||||||
String? cloudFlareKey,
|
|
||||||
String? ip4,
|
String? ip4,
|
||||||
CloudFlareDomain cloudFlareDomain,
|
CloudFlareDomain cloudFlareDomain,
|
||||||
) async {
|
) async {
|
||||||
var cloudflareApi = CloudflareApi(cloudFlareKey);
|
var cloudflareApi = CloudflareApi();
|
||||||
|
|
||||||
await cloudflareApi.removeSimilarRecords(
|
await cloudflareApi.removeSimilarRecords(
|
||||||
ip4: ip4,
|
ip4: ip4,
|
||||||
|
@ -166,22 +159,18 @@ class AppConfigRepository {
|
||||||
ip4: ip4,
|
ip4: ip4,
|
||||||
cloudFlareDomain: cloudFlareDomain,
|
cloudFlareDomain: cloudFlareDomain,
|
||||||
);
|
);
|
||||||
|
|
||||||
cloudflareApi.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isHttpServerWorking(String? domainName) async {
|
Future<bool> isHttpServerWorking() async {
|
||||||
var api = ServerApi(domainName);
|
var api = ServerApi();
|
||||||
var isHttpServerWorking = await api.isHttpServerWorking();
|
var isHttpServerWorking = await api.isHttpServerWorking();
|
||||||
api.close();
|
|
||||||
return isHttpServerWorking;
|
return isHttpServerWorking;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<HetznerServerDetails> restart(
|
Future<HetznerServerDetails> restart(
|
||||||
String? hetznerKey,
|
|
||||||
HetznerServerDetails server,
|
HetznerServerDetails server,
|
||||||
) async {
|
) async {
|
||||||
var hetznerApi = HetznerApi(hetznerKey);
|
var hetznerApi = HetznerApi();
|
||||||
return await hetznerApi.restart(server: server);
|
return await hetznerApi.restart(server: server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
||||||
|
|
||||||
class BackblazeFormCubit extends FormCubit {
|
class BackblazeFormCubit extends FormCubit {
|
||||||
BackblazeApi apiClient = BackblazeApi();
|
|
||||||
|
|
||||||
BackblazeFormCubit(this.initializingCubit) {
|
BackblazeFormCubit(this.initializingCubit) {
|
||||||
//var regExp = RegExp(r"\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]");
|
//var regExp = RegExp(r"\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]");
|
||||||
keyId = FieldCubit(
|
keyId = FieldCubit(
|
||||||
|
@ -42,14 +40,14 @@ class BackblazeFormCubit extends FormCubit {
|
||||||
|
|
||||||
final AppConfigCubit initializingCubit;
|
final AppConfigCubit initializingCubit;
|
||||||
|
|
||||||
// ignore: close_sinks
|
|
||||||
late final FieldCubit<String> keyId;
|
late final FieldCubit<String> keyId;
|
||||||
// ignore: close_sinks
|
|
||||||
late final FieldCubit<String> applicationKey;
|
late final FieldCubit<String> applicationKey;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOr<bool> asyncValidation() async {
|
FutureOr<bool> asyncValidation() async {
|
||||||
late bool isKeyValid;
|
late bool isKeyValid;
|
||||||
|
BackblazeApi apiClient = BackblazeApi(isWithToken: false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String encodedApiKey = encodedBackblazeKey(
|
String encodedApiKey = encodedBackblazeKey(
|
||||||
keyId.state.value,
|
keyId.state.value,
|
||||||
|
@ -67,11 +65,4 @@ class BackblazeFormCubit extends FormCubit {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> close() async {
|
|
||||||
apiClient.close();
|
|
||||||
|
|
||||||
return super.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@ import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/validations/validations.dart';
|
import 'package:selfprivacy/logic/cubit/forms/validations/validations.dart';
|
||||||
|
|
||||||
class CloudFlareFormCubit extends FormCubit {
|
class CloudFlareFormCubit extends FormCubit {
|
||||||
CloudflareApi apiClient = CloudflareApi();
|
|
||||||
|
|
||||||
CloudFlareFormCubit(this.initializingCubit) {
|
CloudFlareFormCubit(this.initializingCubit) {
|
||||||
var regExp = RegExp(r"\s+|[!$%^&*()@+|~=`{}\[\]:<>?,.\/]");
|
var regExp = RegExp(r"\s+|[!$%^&*()@+|~=`{}\[\]:<>?,.\/]");
|
||||||
apiKey = FieldCubit(
|
apiKey = FieldCubit(
|
||||||
|
@ -35,6 +33,7 @@ class CloudFlareFormCubit extends FormCubit {
|
||||||
@override
|
@override
|
||||||
FutureOr<bool> asyncValidation() async {
|
FutureOr<bool> asyncValidation() async {
|
||||||
late bool isKeyValid;
|
late bool isKeyValid;
|
||||||
|
CloudflareApi apiClient = CloudflareApi(isWithToken: false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
isKeyValid = await apiClient.isValid(apiKey.state.value);
|
isKeyValid = await apiClient.isValid(apiKey.state.value);
|
||||||
|
@ -51,8 +50,6 @@ class CloudFlareFormCubit extends FormCubit {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() async {
|
Future<void> close() async {
|
||||||
apiClient.close();
|
|
||||||
|
|
||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,19 +4,14 @@ import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
||||||
|
|
||||||
class DomainSetupCubit extends Cubit<DomainSetupState> {
|
class DomainSetupCubit extends Cubit<DomainSetupState> {
|
||||||
DomainSetupCubit(this.initializingCubit) : super(Initial()) {
|
DomainSetupCubit(this.initializingCubit) : super(Initial());
|
||||||
var token = initializingCubit.state.cloudFlareKey;
|
|
||||||
|
|
||||||
assert(token != null, 'no cloudflare token');
|
final AppConfigCubit initializingCubit;
|
||||||
|
|
||||||
api = CloudflareApi(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
AppConfigCubit initializingCubit;
|
|
||||||
late CloudflareApi api;
|
|
||||||
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
emit(Loading(LoadingTypes.loadingDomain));
|
emit(Loading(LoadingTypes.loadingDomain));
|
||||||
|
var api = CloudflareApi();
|
||||||
|
|
||||||
var list = await api.domainList();
|
var list = await api.domainList();
|
||||||
if (list.isEmpty) {
|
if (list.isEmpty) {
|
||||||
emit(Empty());
|
emit(Empty());
|
||||||
|
@ -29,20 +24,17 @@ class DomainSetupCubit extends Cubit<DomainSetupState> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() {
|
Future<void> close() {
|
||||||
api.close();
|
|
||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveDomain() async {
|
Future<void> saveDomain() async {
|
||||||
assert(state is Loaded, 'wrong state');
|
assert(state is Loaded, 'wrong state');
|
||||||
var domainName = (state as Loaded).domain;
|
var domainName = (state as Loaded).domain;
|
||||||
|
var api = CloudflareApi();
|
||||||
|
|
||||||
emit(Loading(LoadingTypes.saving));
|
emit(Loading(LoadingTypes.saving));
|
||||||
|
|
||||||
var zoneId = await api.getZoneId(
|
var zoneId = await api.getZoneId(domainName);
|
||||||
initializingCubit.state.cloudFlareKey,
|
|
||||||
domainName,
|
|
||||||
);
|
|
||||||
|
|
||||||
var domain = CloudFlareDomain(
|
var domain = CloudFlareDomain(
|
||||||
domainName: domainName,
|
domainName: domainName,
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
// import 'dart:async';
|
|
||||||
|
|
||||||
// import 'package:cubit_form/cubit_form.dart';
|
|
||||||
// import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
|
||||||
// import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
|
||||||
// import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
|
||||||
|
|
||||||
// class DomainFormCubit extends FormCubit {
|
|
||||||
// CloudflareApi apiClient = CloudflareApi();
|
|
||||||
|
|
||||||
// DomainFormCubit(this.initializingCubit) {
|
|
||||||
// var regExp =
|
|
||||||
// RegExp(r"^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}");
|
|
||||||
// domainName = FieldCubit(
|
|
||||||
// initalValue: '',
|
|
||||||
// validations: [
|
|
||||||
// RequiredStringValidation('required'),
|
|
||||||
// ValidationModel<String>(
|
|
||||||
// (s) => !regExp.hasMatch(s),
|
|
||||||
// 'invalid domain format',
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// );
|
|
||||||
|
|
||||||
// super.setFields([domainName]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// FutureOr<void> onSubmit() async {
|
|
||||||
// var domain = CloudFlareDomain(
|
|
||||||
// domainName: domainName.state.value,
|
|
||||||
// zoneId: zoneId,
|
|
||||||
// );
|
|
||||||
// initializingCubit.setDomain(domain);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// final AppConfigCubit initializingCubit;
|
|
||||||
|
|
||||||
// FieldCubit<String> domainName;
|
|
||||||
// String zoneId;
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// FutureOr<bool> asyncValidation() async {
|
|
||||||
// var key = initializingCubit.state.cloudFlareKey;
|
|
||||||
|
|
||||||
// String zoneId;
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// zoneId = await apiClient.getZoneId(key, domainName.state.value);
|
|
||||||
// } catch (e) {
|
|
||||||
// addError(e);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (zoneId == null) {
|
|
||||||
// domainName.setError('Domain not in the list');
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// this.zoneId = zoneId;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// Future<void> close() async {
|
|
||||||
// apiClient.close();
|
|
||||||
|
|
||||||
// return super.close();
|
|
||||||
// }
|
|
||||||
// }
|
|
|
@ -6,8 +6,6 @@ import 'package:selfprivacy/logic/cubit/forms/validations/validations.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
|
|
||||||
class HetznerFormCubit extends FormCubit {
|
class HetznerFormCubit extends FormCubit {
|
||||||
HetznerApi apiClient = HetznerApi();
|
|
||||||
|
|
||||||
HetznerFormCubit(this.initializingCubit) {
|
HetznerFormCubit(this.initializingCubit) {
|
||||||
var regExp = RegExp(r"\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]");
|
var regExp = RegExp(r"\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]");
|
||||||
apiKey = FieldCubit(
|
apiKey = FieldCubit(
|
||||||
|
@ -30,12 +28,13 @@ class HetznerFormCubit extends FormCubit {
|
||||||
|
|
||||||
final AppConfigCubit initializingCubit;
|
final AppConfigCubit initializingCubit;
|
||||||
|
|
||||||
// ignore: close_sinks
|
|
||||||
late final FieldCubit<String> apiKey;
|
late final FieldCubit<String> apiKey;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOr<bool> asyncValidation() async {
|
FutureOr<bool> asyncValidation() async {
|
||||||
late bool isKeyValid;
|
late bool isKeyValid;
|
||||||
|
HetznerApi apiClient = HetznerApi(isWithToken: false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
isKeyValid = await apiClient.isValid(apiKey.state.value);
|
isKeyValid = await apiClient.isValid(apiKey.state.value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -48,11 +47,4 @@ class HetznerFormCubit extends FormCubit {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> close() async {
|
|
||||||
apiClient.close();
|
|
||||||
|
|
||||||
return super.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
|
|
||||||
class RootUserFormCubit extends FormCubit {
|
class RootUserFormCubit extends FormCubit {
|
||||||
HetznerApi apiClient = HetznerApi();
|
|
||||||
|
|
||||||
RootUserFormCubit(this.initializingCubit) {
|
RootUserFormCubit(this.initializingCubit) {
|
||||||
var userRegExp = RegExp(r"\W");
|
var userRegExp = RegExp(r"\W");
|
||||||
var passwordRegExp = RegExp(r"[\n\r\s]+");
|
var passwordRegExp = RegExp(r"[\n\r\s]+");
|
||||||
|
@ -46,17 +43,7 @@ class RootUserFormCubit extends FormCubit {
|
||||||
|
|
||||||
final AppConfigCubit initializingCubit;
|
final AppConfigCubit initializingCubit;
|
||||||
|
|
||||||
// ignore: close_sinks
|
|
||||||
late final FieldCubit<String> userName;
|
late final FieldCubit<String> userName;
|
||||||
// ignore: close_sinks
|
|
||||||
late final FieldCubit<String> password;
|
late final FieldCubit<String> password;
|
||||||
// ignore: close_sinks
|
|
||||||
late final FieldCubit<bool> isVisible;
|
late final FieldCubit<bool> isVisible;
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> close() async {
|
|
||||||
apiClient.close();
|
|
||||||
|
|
||||||
return super.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ class UserFormCubit extends FormCubit {
|
||||||
usersCubit.addUser(user);
|
usersCubit.addUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore: close_sinks
|
|
||||||
late FieldCubit<String> login;
|
late FieldCubit<String> login;
|
||||||
late FieldCubit<String> password;
|
late FieldCubit<String> password;
|
||||||
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
// import 'package:bloc/bloc.dart';
|
|
||||||
// import 'package:equatable/equatable.dart';
|
|
||||||
// import 'package:meta/meta.dart';
|
|
||||||
// import 'package:selfprivacy/logic/models/service.dart';
|
|
||||||
// import 'package:selfprivacy/logic/models/state_types.dart';
|
|
||||||
|
|
||||||
// export 'package:provider/provider.dart';
|
|
||||||
// export 'package:selfprivacy/logic/models/state_types.dart';
|
|
||||||
|
|
||||||
// part 'services_state.dart';
|
|
||||||
|
|
||||||
// class ServicesCubit extends Cubit<ServicesState> {
|
|
||||||
// ServicesCubit() : super(ServicesState(all));
|
|
||||||
|
|
||||||
// void connect(Service service) {
|
|
||||||
// var newState = state.updateElement(service, StateType.stable);
|
|
||||||
// emit(newState);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// final all = ServiceTypes.values
|
|
||||||
// .map(
|
|
||||||
// (type) => Service(
|
|
||||||
// state: StateType.uninitialized,
|
|
||||||
// type: type,
|
|
||||||
// ),
|
|
||||||
// )
|
|
||||||
// .toList();
|
|
|
@ -1,26 +0,0 @@
|
||||||
// part of 'services_cubit.dart';
|
|
||||||
|
|
||||||
// @immutable
|
|
||||||
// class ServicesState extends Equatable{
|
|
||||||
// ServicesState(this.all);
|
|
||||||
|
|
||||||
// final List<Service> all;
|
|
||||||
|
|
||||||
// ServicesState updateElement(Service service, StateType newState) {
|
|
||||||
// var newList = [...all];
|
|
||||||
// var index = newList.indexOf(service);
|
|
||||||
// newList[index] = service.updateState(newState);
|
|
||||||
// return ServicesState(newList);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// List<Service> get connected => all
|
|
||||||
// .where((service) => service.state != StateType.uninitialized)
|
|
||||||
// .toList();
|
|
||||||
|
|
||||||
// List<Service> get uninitialized => all
|
|
||||||
// .where((service) => service.state == StateType.uninitialized)
|
|
||||||
// .toList();
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// List<Object> get props => all;
|
|
||||||
// }
|
|
23
lib/logic/models/server_info.dart
Normal file
23
lib/logic/models/server_info.dart
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
@JsonSerializable(createFactory: false)
|
||||||
|
class ServerInfo {
|
||||||
|
final String id;
|
||||||
|
final String name;
|
||||||
|
final ServerStatus status;
|
||||||
|
final DateTime created;
|
||||||
|
|
||||||
|
ServerInfo(this.id, this.name, this.status, this.created);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ServerStatus {
|
||||||
|
running,
|
||||||
|
initializing,
|
||||||
|
starting,
|
||||||
|
stopping,
|
||||||
|
off,
|
||||||
|
deleting,
|
||||||
|
migrating,
|
||||||
|
rebuilding,
|
||||||
|
unknown,
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
// import 'package:equatable/equatable.dart';
|
|
||||||
// import 'package:selfprivacy/logic/models/state_types.dart';
|
|
||||||
|
|
||||||
// enum ServiceTypes {
|
|
||||||
// messanger,
|
|
||||||
// mail,
|
|
||||||
// passwordManager,
|
|
||||||
// github,
|
|
||||||
// cloud,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// class Service extends Equatable {
|
|
||||||
// const Service({required this.state, required this.type});
|
|
||||||
|
|
||||||
// final StateType state;
|
|
||||||
// final ServiceTypes type;
|
|
||||||
|
|
||||||
// Service updateState(StateType newState) => Service(
|
|
||||||
// state: newState,
|
|
||||||
// type: type,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// List<Object?> get props => [state, type];
|
|
||||||
// }
|
|
|
@ -37,6 +37,8 @@ class MyApp extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
AppSettingsState appSettings = context.watch<AppSettingsCubit>().state;
|
AppSettingsState appSettings = context.watch<AppSettingsCubit>().state;
|
||||||
|
|
||||||
|
var a = DateTime.parse('2021-03-23T20:00:06+00:00');
|
||||||
|
print(a);
|
||||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||||
value: SystemUiOverlayStyle.light, // Manually changnig appbar color
|
value: SystemUiOverlayStyle.light, // Manually changnig appbar color
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
|
|
|
@ -408,7 +408,7 @@ class InitializingPage extends StatelessWidget {
|
||||||
Spacer(),
|
Spacer(),
|
||||||
BrandButton.rised(
|
BrandButton.rised(
|
||||||
onPressed:
|
onPressed:
|
||||||
isLoading! ? null : appConfigCubit.createServerAndSetDnsRecords,
|
isLoading! ? null : () => appConfigCubit.createServerAndSetDnsRecords(),
|
||||||
title: isLoading ? 'basis.loading'.tr() : 'initializing.11'.tr(),
|
title: isLoading ? 'basis.loading'.tr() : 'initializing.11'.tr(),
|
||||||
),
|
),
|
||||||
Spacer(flex: 2),
|
Spacer(flex: 2),
|
||||||
|
|
|
@ -124,8 +124,10 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||||
BrandButton.rised(
|
BrandButton.rised(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.read<AppSettingsCubit>().turnOffOnboarding();
|
context.read<AppSettingsCubit>().turnOffOnboarding();
|
||||||
Navigator.of(context)
|
Navigator.of(context).pushAndRemoveUntil(
|
||||||
.pushReplacement(materialRoute(widget.nextPage));
|
materialRoute(widget.nextPage),
|
||||||
|
(route) => false,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
title: 'basis.got_it'.tr(),
|
title: 'basis.got_it'.tr(),
|
||||||
),
|
),
|
||||||
|
|
|
@ -366,6 +366,7 @@ class _ServiceDetails extends StatelessWidget {
|
||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
BrandText.h1(title),
|
BrandText.h1(title),
|
||||||
|
SizedBox(height: 10),
|
||||||
child,
|
child,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -574,6 +574,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.5.0"
|
version: "1.5.0"
|
||||||
|
pretty_dio_logger:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: pretty_dio_logger
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.0-beta-1"
|
||||||
process:
|
process:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -25,6 +25,7 @@ dependencies:
|
||||||
hive_flutter: ^1.0.0
|
hive_flutter: ^1.0.0
|
||||||
json_annotation: ^4.0.0
|
json_annotation: ^4.0.0
|
||||||
package_info: ^2.0.0
|
package_info: ^2.0.0
|
||||||
|
pretty_dio_logger: ^1.1.1
|
||||||
provider: ^5.0.0
|
provider: ^5.0.0
|
||||||
url_launcher: ^6.0.2
|
url_launcher: ^6.0.2
|
||||||
wakelock: ^0.5.0+2
|
wakelock: ^0.5.0+2
|
||||||
|
|
Loading…
Reference in a new issue