Skip to content

Commit f5382e9

Browse files
committed
v1.2.1: Fix and new endpoint logs/export support
1 parent f0d09bd commit f5382e9

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ DDNS(new API(__DIR__ . "/configurations", ".env-custom"), file_get_contents("/my
127127

128128
## Changes
129129

130+
### v1.2.1: Fixed and logs/export support
131+
132+
- Added support for `logs/export` allowing you to export a DNS application log file
133+
- Fixed incorrect endpoint URL for some "Log" endpoints
134+
130135
### v1.2: Adding support for export functions
131136

132137
- Added support for export functions within API classes. When using export functions note that downloading log files may take quite a while. You may also need to adjust the `memory_limit`.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ente/technitium-dnsserver-php-api",
33
"type": "library",
44
"license": "GPL-3.0-only",
5-
"version": "1.2",
5+
"version": "1.2.1",
66
"description": "API client to interact with the Technitium DNS Server",
77
"authors": [
88
{

src/API.dnsserver.ente.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function loader(): void{
107107
require_once __DIR__ . "/helper/Log.Helper.API.dnsserver.ente.php";
108108
}
109109

110-
public function downloadFile($endpoint, $bypass, $data): string {
110+
public function downloadFile($endpoint, $bypass, $data, $csv = false): string {
111111
$c = curl_init();
112112
$endpoint = $this->prepareEndpoint($endpoint, $bypass);
113113
$method = "POST";
@@ -141,6 +141,10 @@ public function downloadFile($endpoint, $bypass, $data): string {
141141
} else {
142142
$fileName = bin2hex(random_bytes(16)) . ".txt";
143143
}
144+
145+
if($csv){
146+
$fileName = $fileName . ".csv";
147+
}
144148

145149
$path = __DIR__ . "/helper/data/downloads/" . $fileName;
146150
if (file_put_contents($path, $body) === false) {

src/endpoints/admin/Logs.admin.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function list(): array|bool{
4040
* @return array Returns the result array or `false` if the group was not found.
4141
*/
4242
public function query($data): array{
43-
return $this->API->sendCall($data, "admin/logs/query");
43+
return $this->API->sendCall($data, "logs/query");
4444
}
4545

4646
/**
@@ -64,7 +64,7 @@ public function download(string $fileName, int $limit = 0): string|bool{
6464
* @return bool Returns `true` if the file was deleted or `false` if the file was not found.
6565
*/
6666
public function delete(string $log): bool{
67-
$response = $this->API->sendCall(["log" => $log], "admin/logs/delete");
67+
$response = $this->API->sendCall(["log" => $log], "logs/delete");
6868
return $response["status"] == "ok";
6969
}
7070

@@ -73,7 +73,27 @@ public function delete(string $log): bool{
7373
* @return bool Returns `true` if the files were deleted or `false` if the files were not found.
7474
*/
7575
public function deleteAll(): bool{
76-
$response = $this->API->sendCall([], "admin/logs/deleteAll");
76+
$response = $this->API->sendCall([], "logs/deleteAll");
7777
return $response["status"] == "ok";
7878
}
79+
80+
public function exportAppLog($data): string|bool{
81+
$response = $this->API->downloadFile("logs/export", 0, [
82+
"classPath" => $data["classPath"],
83+
"start" => $data["start"],
84+
"end" => $data["end"],
85+
"clientIpAddress" => $data["clientIpAddress"],
86+
"protocol" => $data["protocol"],
87+
"responseType" => $data["responseType"],
88+
"rcode" => $data["rcode"],
89+
"qname" => $data["qname"],
90+
"qtype" => $data["qtype"],
91+
"qclass" => $data["qclass"]
92+
]);
93+
if(!empty($response)){
94+
return $response;
95+
} else {
96+
return false;
97+
}
98+
}
7999
}

src/helper/endpoints.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,6 @@
140140
"logs/download",
141141
"logs/delete",
142142
"logs/deleteAll",
143-
"logs/query"
143+
"logs/query",
144+
"logs/export"
144145
]

0 commit comments

Comments
 (0)