Skip to content

Enhanced mailcow #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions Gotify/Gotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,4 @@

class Gotify extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;

public function __construct()
{
}

public function test()
{
$attrs = $this->getAttrs();
$test = parent::appTest($this->url("health"), $attrs);
echo $test->status;
}

public function livestats()
{
$status = "inactive";
$data = [];
$attrs = $this->getAttrs();

// Fetch applications
$applicationsResponse = parent::execute($this->url("application"), $attrs);
$applications = json_decode($applicationsResponse->getBody());

// Count applications
if ($applications) {
$data["applications"] = count($applications);
} else {
$data["applications"] = 0;
}

// Fetch clients
$clientsResponse = parent::execute($this->url("client"), $attrs);
$clients = json_decode($clientsResponse->getBody());

// Count clients
if ($clients) {
$data["clients"] = count($clients);
} else {
$data["clients"] = 0;
}

// Fetch messages
$messagesResponse = parent::execute($this->url("message"), $attrs);
$messages = json_decode($messagesResponse->getBody());

// Count messages
if ($messages && isset($messages->messages)) {
$data["messages"] = count($messages->messages);
} else {
$data["messages"] = 0;
}

// Determine status based on data
if ($data["applications"] > 0 || $data["clients"] > 0 || $data["messages"] > 0) {
$status = "active";
}

return parent::getLiveStats($status, $data);
}

public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
return $api_url;
}
private function getAttrs()
{
return [
"headers" => [
"Accept" => "application/json",
"X-Gotify-Key" => $this->config->apikey
],
];
}
}
4 changes: 2 additions & 2 deletions Gotify/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"website": "https://gotify.net",
"license": "MIT License",
"description": "A self-hosted push notification service.",
"enhanced": true,
"enhanced": false,
"tile_background": "dark",
"icon": "gotify.png"
}
}
14 changes: 0 additions & 14 deletions Gotify/livestats.blade.php

This file was deleted.

76 changes: 75 additions & 1 deletion Mailcow/Mailcow.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,80 @@

namespace App\SupportedApps\Mailcow;

class Mailcow extends \App\SupportedApps
class Mailcow extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;

public function __construct()
{
}

public function test()
{
$attrs = $this->getAttrs();
$test = parent::appTest($this->url("status/containers"), $attrs);
echo $test->status;
}

public function livestats()
{
$status = "inactive";
$data = [];
$attrs = $this->getAttrs();

// Fetch mailboxes
$mailboxesResponse = parent::execute($this->url("mailbox/all"), $attrs);
$mailboxes = json_decode($mailboxesResponse->getBody());

// Count mailboxes
if ($mailboxes) {
$data["mailboxes"] = count($mailboxes);
} else {
$data["mailboxes"] = 0;
}

// Fetch clients
$domainsResponse = parent::execute($this->url("domain/all"), $attrs);
$domains = json_decode($domainsResponse->getBody());

// Count clients
if ($domains) {
$data["domains"] = count($domains);
} else {
$data["domains"] = 0;
}

// Fetch messages
$queueResponse = parent::execute($this->url("mailq/all"), $attrs);
$queue = json_decode($queueResponse->getBody());

// Count messages
if ($queue && isset($queue->messages)) {
$data["queue"] = count($queue->messages);
} else {
$data["queue"] = 0;
}

// Determine status based on data
if ($data["mailboxes"] > 0 || $data["domains"] > 0 || $data["queue"] >= 0) {
$status = "active";
}

return parent::getLiveStats($status, $data);
}

public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url) . "api/v1/get/" . $endpoint;
return $api_url;
}
private function getAttrs()
{
return [
"headers" => [
"Accept" => "application/json",
"X-API-Key" => $this->config->apikey
],
];
}
}
2 changes: 1 addition & 1 deletion Mailcow/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"website": "https://mailcow.email",
"license": "GNU General Public License v3.0 only",
"description": "Mailcow is a Docker based email server which provides an elegant web interface for managing domains, mailboxes and more.",
"enhanced": false,
"enhanced": true,
"tile_background": "dark",
"icon": "mailcow.svg"
}
File renamed without changes.
14 changes: 14 additions & 0 deletions Mailcow/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ul class="livestats">
<li>
<span class="title">Mailboxes</span>
<strong>{!! $mailboxes !!}</strong>
</li>
<li>
<span class="title">Domains</span>
<strong>{!! $domains !!}</strong>
</li>
<li>
<span class="title">Queue</span>
<strong>{!! $queue !!}</strong>
</li>
</ul>