2023-07-27 00:23:37 +00:00
|
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
2023-11-08 14:31:28 +00:00
|
|
|
|
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
2023-07-27 00:23:37 +00:00
|
|
|
|
|
|
|
|
|
part 'desec_dns_info.g.dart';
|
|
|
|
|
|
|
|
|
|
/// https://desec.readthedocs.io/en/latest/dns/domains.html#domain-management
|
|
|
|
|
@JsonSerializable()
|
|
|
|
|
class DesecDomain {
|
|
|
|
|
DesecDomain(
|
|
|
|
|
this.name,
|
|
|
|
|
this.minimumTtl,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/// Restrictions on what is a valid domain name apply on
|
|
|
|
|
/// a per-user basis.
|
|
|
|
|
///
|
|
|
|
|
/// The maximum length is 191.
|
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
|
|
/// Smallest TTL that can be used in an RRset.
|
|
|
|
|
/// The value is set automatically by DESEC
|
|
|
|
|
@JsonKey(name: 'minimum_ttl')
|
|
|
|
|
final int minimumTtl;
|
|
|
|
|
|
|
|
|
|
static DesecDomain fromJson(final Map<String, dynamic> json) =>
|
|
|
|
|
_$DesecDomainFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// https://desec.readthedocs.io/en/latest/dns/rrsets.html#retrieving-and-creating-dns-records
|
|
|
|
|
@JsonSerializable()
|
|
|
|
|
class DesecDnsRecord {
|
2023-11-08 14:31:28 +00:00
|
|
|
|
factory DesecDnsRecord.fromDnsRecord(final DnsRecord record) {
|
|
|
|
|
final String type = record.type;
|
|
|
|
|
String content = record.content ?? '';
|
|
|
|
|
String name = record.name ?? '';
|
|
|
|
|
if (type == 'MX') {
|
|
|
|
|
name = '';
|
|
|
|
|
content = '10 $content';
|
|
|
|
|
}
|
|
|
|
|
if (type == 'TXT' && content.isNotEmpty && !content.startsWith('"')) {
|
|
|
|
|
content = '"$content"';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DesecDnsRecord(
|
|
|
|
|
subname: name,
|
|
|
|
|
type: type,
|
|
|
|
|
ttl: record.ttl,
|
|
|
|
|
records: [content],
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-07-27 00:23:37 +00:00
|
|
|
|
DesecDnsRecord({
|
|
|
|
|
required this.subname,
|
|
|
|
|
required this.type,
|
|
|
|
|
required this.ttl,
|
|
|
|
|
required this.records,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/// Subdomain string which, together with domain, defines the RRset name.
|
|
|
|
|
/// Typical examples are www or _443._tcp.
|
|
|
|
|
final String subname;
|
|
|
|
|
|
|
|
|
|
/// RRset type (uppercase). A broad range of record types is supported,
|
|
|
|
|
/// with most DNSSEC-related types (and the SOA type) managed automagically
|
|
|
|
|
/// by the backend.
|
|
|
|
|
final String type;
|
|
|
|
|
|
|
|
|
|
/// Time-to-live value, which dictates for how long resolvers may
|
|
|
|
|
/// cache this RRset, measured in seconds.
|
|
|
|
|
///
|
|
|
|
|
/// The smallest acceptable value is given by the domain’s minimum TTL setting.
|
|
|
|
|
/// The maximum value is 86400 (one day).
|
|
|
|
|
final int ttl;
|
|
|
|
|
|
|
|
|
|
/// Array of record content strings.
|
|
|
|
|
///
|
|
|
|
|
/// The maximum number of array elements is 4091,
|
|
|
|
|
/// and the maximum length of the array is 64,000 (after JSON encoding).
|
|
|
|
|
final List<String> records;
|
|
|
|
|
|
|
|
|
|
static DesecDnsRecord fromJson(final Map<String, dynamic> json) =>
|
|
|
|
|
_$DesecDnsRecordFromJson(json);
|
|
|
|
|
Map<String, dynamic> toJson() => _$DesecDnsRecordToJson(this);
|
|
|
|
|
}
|