adguard-home-manager/lib/models/logs.dart

216 lines
5.1 KiB
Dart
Raw Normal View History

2022-09-30 23:33:57 +02:00
import 'dart:convert';
class LogsList {
int loadStatus = 0;
LogsData? logsData;
LogsList({
required this.loadStatus,
this.logsData
});
}
LogsData logsFromJson(String str) => LogsData.fromJson(json.decode(str));
String logsToJson(LogsData data) => json.encode(data.toJson());
class LogsData {
List<Log> data;
2022-10-02 03:58:02 +02:00
final DateTime? oldest;
2022-09-30 23:33:57 +02:00
LogsData({
required this.data,
2022-10-02 03:58:02 +02:00
this.oldest,
2022-09-30 23:33:57 +02:00
});
factory LogsData.fromJson(Map<String, dynamic> json) => LogsData(
data: List<Log>.from(json["data"].map((x) => Log.fromJson(x))),
2022-10-02 03:58:02 +02:00
oldest: json["oldest"] != '' ? DateTime.parse(json["oldest"]) : null,
2022-09-30 23:33:57 +02:00
);
Map<String, dynamic> toJson() => {
"data": List<dynamic>.from(data.map((x) => x.toJson())),
2024-09-11 18:13:26 +02:00
"oldest": oldest?.toIso8601String(),
2022-09-30 23:33:57 +02:00
};
}
class Log {
2023-04-13 02:13:30 +02:00
final bool? answerDnssec;
2022-09-30 23:33:57 +02:00
final bool cached;
final String client;
2022-10-15 23:08:01 +02:00
final ClientInfo? clientInfo;
2023-05-17 20:48:43 +02:00
final String? clientProto;
2022-09-30 23:33:57 +02:00
final String elapsedMs;
final Question question;
final String reason;
final List<Rule> rules;
2023-04-13 02:13:30 +02:00
final String? status;
2022-09-30 23:33:57 +02:00
final DateTime time;
2023-06-15 14:27:08 +02:00
final String? upstream;
2022-10-22 02:39:29 +02:00
final List<Answer> answer;
2022-09-30 23:33:57 +02:00
final int? filterId;
final String? rule;
final List<Answer>? originalAnswer;
Log({
2023-04-13 02:13:30 +02:00
this.answerDnssec,
2022-09-30 23:33:57 +02:00
required this.cached,
required this.client,
2022-10-15 23:08:01 +02:00
this.clientInfo,
2022-09-30 23:33:57 +02:00
required this.clientProto,
required this.elapsedMs,
required this.question,
required this.reason,
required this.rules,
2023-04-13 02:13:30 +02:00
this.status,
2022-09-30 23:33:57 +02:00
required this.time,
required this.upstream,
2022-10-22 02:39:29 +02:00
required this.answer,
2022-09-30 23:33:57 +02:00
this.filterId,
this.rule,
this.originalAnswer,
});
factory Log.fromJson(Map<String, dynamic> json) => Log(
answerDnssec: json["answer_dnssec"],
2023-05-13 01:33:24 +02:00
cached: json["cached"] ?? false,
2022-09-30 23:33:57 +02:00
client: json["client"],
2022-10-15 23:08:01 +02:00
clientInfo: json["client_info"] != null ? ClientInfo.fromJson(json["client_info"]) : null,
2022-09-30 23:33:57 +02:00
clientProto: json["client_proto"],
elapsedMs: json["elapsedMs"],
question: Question.fromJson(json["question"]),
reason: json["reason"],
2023-06-13 12:53:10 +02:00
rules: json["rules"] != null ? List<Rule>.from(json["rules"].map((x) => Rule.fromJson(x))) : [],
2022-09-30 23:33:57 +02:00
status: json["status"],
time: DateTime.parse(json["time"]),
upstream: json["upstream"],
2022-10-22 02:39:29 +02:00
answer: json["answer"] != null ? List<Answer>.from(json["answer"].map((x) => Answer.fromJson(x))) : [],
2022-09-30 23:33:57 +02:00
filterId: json["filterId"],
rule: json["rule"],
originalAnswer: json["original_answer"] == null ? null : List<Answer>.from(json["original_answer"].map((x) => Answer.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"answer_dnssec": answerDnssec,
"cached": cached,
"client": client,
2022-10-15 23:08:01 +02:00
"client_info": clientInfo?.toJson(),
2022-09-30 23:33:57 +02:00
"client_proto": clientProto,
"elapsedMs": elapsedMs,
"question": question.toJson(),
"reason":reason,
"rules": List<dynamic>.from(rules.map((x) => x.toJson())),
"status": status,
"time": time.toIso8601String(),
"upstream": upstream,
2022-10-22 03:21:16 +02:00
"answer": List<dynamic>.from(answer.map((x) => x.toJson())),
2022-09-30 23:33:57 +02:00
"filterId": filterId,
"rule": rule,
"original_answer": originalAnswer == null ? null : List<dynamic>.from(originalAnswer!.map((x) => x.toJson())),
};
}
class Answer {
final String type;
final String value;
final int ttl;
Answer({
required this.type,
required this.value,
required this.ttl,
});
factory Answer.fromJson(Map<String, dynamic> json) => Answer(
type: json["type"],
value: json["value"],
ttl: json["ttl"],
);
Map<String, dynamic> toJson() => {
"type": type,
"value": value,
"ttl": ttl,
};
}
class ClientInfo {
final Whois whois;
final String name;
final String disallowedRule;
final bool disallowed;
ClientInfo({
required this.whois,
required this.name,
required this.disallowedRule,
required this.disallowed,
});
factory ClientInfo.fromJson(Map<String, dynamic> json) => ClientInfo(
2022-11-30 23:35:31 +01:00
whois: Whois.fromJson(Map<String, dynamic>.from(json["whois"])),
2022-09-30 23:33:57 +02:00
name: json["name"],
disallowedRule: json["disallowed_rule"],
disallowed: json["disallowed"],
);
Map<String, dynamic> toJson() => {
"whois": whois.toJson(),
"name": name,
"disallowed_rule": disallowedRule,
"disallowed": disallowed,
};
}
class Whois {
Whois();
factory Whois.fromJson(Map<String, dynamic> json) => Whois();
Map<String, dynamic> toJson() => {};
}
class Question {
final String questionClass;
2023-05-20 20:31:48 +02:00
final String? name;
2022-09-30 23:33:57 +02:00
final String type;
Question({
required this.questionClass,
required this.name,
required this.type,
});
factory Question.fromJson(Map<String, dynamic> json) => Question(
questionClass: json["class"],
name: json["name"],
type: json["type"],
);
Map<String, dynamic> toJson() => {
"class": questionClass,
"name": name,
"type": type,
};
}
class Rule {
final int filterListId;
final String text;
Rule({
required this.filterListId,
required this.text,
});
factory Rule.fromJson(Map<String, dynamic> json) => Rule(
filterListId: json["filter_list_id"],
text: json["text"],
);
Map<String, dynamic> toJson() => {
"filter_list_id": filterListId,
"text": text,
};
}