Skip to content

Commit 95926bd

Browse files
authored
Enhanced mailcow (#757)
* Enhancing Gotify App(Need Testing) * Enhancing Gotify tested and working * Enchance Mailcow * Reset gotify app for branch consistency * Remove whitespaces * reset Gotify App * Update Gotify.php Added last line on the code
1 parent 666f8ab commit 95926bd

7 files changed

+92
-92
lines changed

Gotify/Gotify.php

-74
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,4 @@
44

55
class Gotify extends \App\SupportedApps implements \App\EnhancedApps
66
{
7-
public $config;
8-
9-
public function __construct()
10-
{
11-
}
12-
13-
public function test()
14-
{
15-
$attrs = $this->getAttrs();
16-
$test = parent::appTest($this->url("health"), $attrs);
17-
echo $test->status;
18-
}
19-
20-
public function livestats()
21-
{
22-
$status = "inactive";
23-
$data = [];
24-
$attrs = $this->getAttrs();
25-
26-
// Fetch applications
27-
$applicationsResponse = parent::execute($this->url("application"), $attrs);
28-
$applications = json_decode($applicationsResponse->getBody());
29-
30-
// Count applications
31-
if ($applications) {
32-
$data["applications"] = count($applications);
33-
} else {
34-
$data["applications"] = 0;
35-
}
36-
37-
// Fetch clients
38-
$clientsResponse = parent::execute($this->url("client"), $attrs);
39-
$clients = json_decode($clientsResponse->getBody());
40-
41-
// Count clients
42-
if ($clients) {
43-
$data["clients"] = count($clients);
44-
} else {
45-
$data["clients"] = 0;
46-
}
47-
48-
// Fetch messages
49-
$messagesResponse = parent::execute($this->url("message"), $attrs);
50-
$messages = json_decode($messagesResponse->getBody());
51-
52-
// Count messages
53-
if ($messages && isset($messages->messages)) {
54-
$data["messages"] = count($messages->messages);
55-
} else {
56-
$data["messages"] = 0;
57-
}
58-
59-
// Determine status based on data
60-
if ($data["applications"] > 0 || $data["clients"] > 0 || $data["messages"] > 0) {
61-
$status = "active";
62-
}
63-
64-
return parent::getLiveStats($status, $data);
65-
}
66-
67-
public function url($endpoint)
68-
{
69-
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
70-
return $api_url;
71-
}
72-
private function getAttrs()
73-
{
74-
return [
75-
"headers" => [
76-
"Accept" => "application/json",
77-
"X-Gotify-Key" => $this->config->apikey
78-
],
79-
];
80-
}
817
}

Gotify/app.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"website": "https://gotify.net",
55
"license": "MIT License",
66
"description": "A self-hosted push notification service.",
7-
"enhanced": true,
7+
"enhanced": false,
88
"tile_background": "dark",
99
"icon": "gotify.png"
10-
}
10+
}

Gotify/livestats.blade.php

-14
This file was deleted.

Mailcow/Mailcow.php

+75-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,80 @@
22

33
namespace App\SupportedApps\Mailcow;
44

5-
class Mailcow extends \App\SupportedApps
5+
class Mailcow extends \App\SupportedApps implements \App\EnhancedApps
66
{
7+
public $config;
8+
9+
public function __construct()
10+
{
11+
}
12+
13+
public function test()
14+
{
15+
$attrs = $this->getAttrs();
16+
$test = parent::appTest($this->url("status/containers"), $attrs);
17+
echo $test->status;
18+
}
19+
20+
public function livestats()
21+
{
22+
$status = "inactive";
23+
$data = [];
24+
$attrs = $this->getAttrs();
25+
26+
// Fetch mailboxes
27+
$mailboxesResponse = parent::execute($this->url("mailbox/all"), $attrs);
28+
$mailboxes = json_decode($mailboxesResponse->getBody());
29+
30+
// Count mailboxes
31+
if ($mailboxes) {
32+
$data["mailboxes"] = count($mailboxes);
33+
} else {
34+
$data["mailboxes"] = 0;
35+
}
36+
37+
// Fetch clients
38+
$domainsResponse = parent::execute($this->url("domain/all"), $attrs);
39+
$domains = json_decode($domainsResponse->getBody());
40+
41+
// Count clients
42+
if ($domains) {
43+
$data["domains"] = count($domains);
44+
} else {
45+
$data["domains"] = 0;
46+
}
47+
48+
// Fetch messages
49+
$queueResponse = parent::execute($this->url("mailq/all"), $attrs);
50+
$queue = json_decode($queueResponse->getBody());
51+
52+
// Count messages
53+
if ($queue && isset($queue->messages)) {
54+
$data["queue"] = count($queue->messages);
55+
} else {
56+
$data["queue"] = 0;
57+
}
58+
59+
// Determine status based on data
60+
if ($data["mailboxes"] > 0 || $data["domains"] > 0 || $data["queue"] >= 0) {
61+
$status = "active";
62+
}
63+
64+
return parent::getLiveStats($status, $data);
65+
}
66+
67+
public function url($endpoint)
68+
{
69+
$api_url = parent::normaliseurl($this->config->url) . "api/v1/get/" . $endpoint;
70+
return $api_url;
71+
}
72+
private function getAttrs()
73+
{
74+
return [
75+
"headers" => [
76+
"Accept" => "application/json",
77+
"X-API-Key" => $this->config->apikey
78+
],
79+
];
80+
}
781
}

Mailcow/app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"website": "https://mailcow.email",
55
"license": "GNU General Public License v3.0 only",
66
"description": "Mailcow is a Docker based email server which provides an elegant web interface for managing domains, mailboxes and more.",
7-
"enhanced": false,
7+
"enhanced": true,
88
"tile_background": "dark",
99
"icon": "mailcow.svg"
1010
}
File renamed without changes.

Mailcow/livestats.blade.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<ul class="livestats">
2+
<li>
3+
<span class="title">Mailboxes</span>
4+
<strong>{!! $mailboxes !!}</strong>
5+
</li>
6+
<li>
7+
<span class="title">Domains</span>
8+
<strong>{!! $domains !!}</strong>
9+
</li>
10+
<li>
11+
<span class="title">Queue</span>
12+
<strong>{!! $queue !!}</strong>
13+
</li>
14+
</ul>

0 commit comments

Comments
 (0)