From c1708495806db98bf84706ed8d5b4e93656df56e Mon Sep 17 00:00:00 2001 From: PedroBuffon Date: Sat, 13 Jul 2024 09:34:12 -0300 Subject: [PATCH 1/3] Enhanced gotify (#756) * Enhancing Gotify App(Need Testing) * Enhancing Gotify tested and working * Remove whitespaces --- Gotify/Gotify.php | 76 +++++++++++++++++++++++++++++++++++++- Gotify/app.json | 2 +- Gotify/config.blade.php | 14 +++++++ Gotify/livestats.blade.php | 14 +++++++ 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 Gotify/config.blade.php create mode 100644 Gotify/livestats.blade.php diff --git a/Gotify/Gotify.php b/Gotify/Gotify.php index f89f1444dd..e07181b5c1 100644 --- a/Gotify/Gotify.php +++ b/Gotify/Gotify.php @@ -2,6 +2,80 @@ namespace App\SupportedApps\Gotify; -class Gotify extends \App\SupportedApps +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 + ], + ]; + } } diff --git a/Gotify/app.json b/Gotify/app.json index 3915b6f3fb..04c632383f 100644 --- a/Gotify/app.json +++ b/Gotify/app.json @@ -4,7 +4,7 @@ "website": "https://gotify.net", "license": "MIT License", "description": "A self-hosted push notification service.", - "enhanced": false, + "enhanced": true, "tile_background": "dark", "icon": "gotify.png" } diff --git a/Gotify/config.blade.php b/Gotify/config.blade.php new file mode 100644 index 0000000000..4a8082c945 --- /dev/null +++ b/Gotify/config.blade.php @@ -0,0 +1,14 @@ +

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

+
+
+ + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} +
+
+ + {!! Form::text('config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!} +
+
+ +
+
diff --git a/Gotify/livestats.blade.php b/Gotify/livestats.blade.php new file mode 100644 index 0000000000..77df438e86 --- /dev/null +++ b/Gotify/livestats.blade.php @@ -0,0 +1,14 @@ + From 666f8ab23232d5d70a70c5b3f527512f398cf689 Mon Sep 17 00:00:00 2001 From: PedroBuffon Date: Sat, 13 Jul 2024 19:10:43 -0300 Subject: [PATCH 2/3] Enhanced glances (#758) * Enhancing Gotify App(Need Testing) * Enhancing Gotify tested and working * Reset gotify on main branch * Enhanced Glaces * Added MemUsage to livestats * Fixed Class Name * Fixed whitespaces and added new line at the end --- Glances/Glances.php | 101 +++++++++++++++++++++++++++++++++++- Glances/app.json | 2 +- Glances/config.blade.php | 14 +++++ Glances/livestats.blade.php | 8 +++ 4 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 Glances/config.blade.php create mode 100644 Glances/livestats.blade.php diff --git a/Glances/Glances.php b/Glances/Glances.php index 3dd5c1b201..e963ba71ac 100644 --- a/Glances/Glances.php +++ b/Glances/Glances.php @@ -2,6 +2,105 @@ namespace App\SupportedApps\Glances; -class Glances extends \App\SupportedApps +class Glances extends \App\SupportedApps implements \App\EnhancedApps { + public $config; + + public function __construct() + { + } + + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $details = []; + + if (isset($this->config->availablestats) && is_array($this->config->availablestats)) { + $details = ["visiblestats" => []]; + foreach ($this->config->availablestats as $stat) { + $newstat = new \stdClass(); + $availableStats = self::getAvailableStats(); + + if (isset($availableStats[$stat])) { + $newstat->title = $availableStats[$stat]; + + // Fetch CpuTotal + if ($stat === "CpuTotal") { + $Response = parent::execute($this->url("cpu/total")); + $result = json_decode($Response->getBody()); + if (isset($result->total)) { + $newstat->value = $result->total; + } else { + $newstat->value = null; // or some default value + } + } + + // Fetch MemTotal + if ($stat === "MemTotal") { + $Response = parent::execute($this->url("mem/total")); + $result = json_decode($Response->getBody()); + if (isset($result->total)) { + $newstat->value = $this->convertBytesToGigabytes($result->total); + } else { + $newstat->value = null; // or some default value + } + } + + // Fetch MemAvail + if ($stat === "MemAvail") { + $Response = parent::execute($this->url("mem/available")); + $result = json_decode($Response->getBody()); + if (isset($result->available)) { + $newstat->value = $this->convertBytesToGigabytes($result->available); + } else { + $newstat->value = null; // or some default value + } + } + + // Fetch MemAvail + if ($stat === "MemUsage") { + $Response = parent::execute($this->url("mem/used")); + $result = json_decode($Response->getBody()); + if (isset($result->used)) { + $newstat->value = $this->convertBytesToGigabytes($result->used); + } else { + $newstat->value = null; // or some default value + } + } + + $details["visiblestats"][] = $newstat; + } + } + } + + return parent::getLiveStats($status, $details); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . "api/4/" . $endpoint; + return $api_url; + } + + public static function getAvailableStats() + { + return [ + "CpuTotal" => "CpuTotal", + "MemTotal" => "MemTotal", + "MemAvail" => "MemAvail", + "MemUsage" => "MemUsage", + ]; + } + + private function convertBytesToGigabytes($bytes) + { + $gigabytes = $bytes / (1024 ** 3); // Converts bytes to gigabytes + return round($gigabytes, 2) . ' GB'; // Rounds to 4 significant digits + } } diff --git a/Glances/app.json b/Glances/app.json index b5916532a1..ac87d08170 100644 --- a/Glances/app.json +++ b/Glances/app.json @@ -4,7 +4,7 @@ "website": "https://nicolargo.github.io/glances", "license": "GNU Lesser General Public License v3.0 only", "description": "Glances is a cross-platform monitoring tool which aims to present a large amount of monitoring information through a curses or Web based interface.", - "enhanced": false, + "enhanced": true, "tile_background": "dark", "icon": "glances.png" } diff --git a/Glances/config.blade.php b/Glances/config.blade.php new file mode 100644 index 0000000000..e6d527bf2e --- /dev/null +++ b/Glances/config.blade.php @@ -0,0 +1,14 @@ +

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

+
+
+ + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} +
+
+ + {!! Form::select('config[availablestats][]', App\SupportedApps\Glances\Glances::getAvailableStats(), isset($item) ? $item->getConfig()->availablestats ?? null : null, ['multiple' => 'multiple']) !!} +
+
+ +
+
diff --git a/Glances/livestats.blade.php b/Glances/livestats.blade.php new file mode 100644 index 0000000000..cb9431aef3 --- /dev/null +++ b/Glances/livestats.blade.php @@ -0,0 +1,8 @@ + From 95926bdc71dd46836cc77f3dba0d376fc5968377 Mon Sep 17 00:00:00 2001 From: PedroBuffon Date: Sat, 13 Jul 2024 19:11:13 -0300 Subject: [PATCH 3/3] 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 --- Gotify/Gotify.php | 74 --------------------------- Gotify/app.json | 4 +- Gotify/livestats.blade.php | 14 ----- Mailcow/Mailcow.php | 76 +++++++++++++++++++++++++++- Mailcow/app.json | 2 +- {Gotify => Mailcow}/config.blade.php | 0 Mailcow/livestats.blade.php | 14 +++++ 7 files changed, 92 insertions(+), 92 deletions(-) delete mode 100644 Gotify/livestats.blade.php rename {Gotify => Mailcow}/config.blade.php (100%) create mode 100644 Mailcow/livestats.blade.php diff --git a/Gotify/Gotify.php b/Gotify/Gotify.php index e07181b5c1..9ae316faa3 100644 --- a/Gotify/Gotify.php +++ b/Gotify/Gotify.php @@ -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 - ], - ]; - } } diff --git a/Gotify/app.json b/Gotify/app.json index 04c632383f..c135dd446f 100644 --- a/Gotify/app.json +++ b/Gotify/app.json @@ -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" -} +} \ No newline at end of file diff --git a/Gotify/livestats.blade.php b/Gotify/livestats.blade.php deleted file mode 100644 index 77df438e86..0000000000 --- a/Gotify/livestats.blade.php +++ /dev/null @@ -1,14 +0,0 @@ -
    -
  • - Apps - {!! $applications !!} -
  • -
  • - Clients - {!! $clients !!} -
  • -
  • - Messages - {!! $messages !!} -
  • -
diff --git a/Mailcow/Mailcow.php b/Mailcow/Mailcow.php index ad59477422..30138e146b 100644 --- a/Mailcow/Mailcow.php +++ b/Mailcow/Mailcow.php @@ -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 + ], + ]; + } } diff --git a/Mailcow/app.json b/Mailcow/app.json index 3d6ae8cfe9..68554d62f9 100644 --- a/Mailcow/app.json +++ b/Mailcow/app.json @@ -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" } diff --git a/Gotify/config.blade.php b/Mailcow/config.blade.php similarity index 100% rename from Gotify/config.blade.php rename to Mailcow/config.blade.php diff --git a/Mailcow/livestats.blade.php b/Mailcow/livestats.blade.php new file mode 100644 index 0000000000..6fe23a6ff3 --- /dev/null +++ b/Mailcow/livestats.blade.php @@ -0,0 +1,14 @@ +
    +
  • + Mailboxes + {!! $mailboxes !!} +
  • +
  • + Domains + {!! $domains !!} +
  • +
  • + Queue + {!! $queue !!} +
  • +