added gluetun service status widget

This commit is contained in:
Jammo2k5 2022-07-20 22:08:30 +01:00
parent 55bde6c78a
commit 8d22d88471
3 changed files with 434 additions and 278 deletions

View File

@ -55,6 +55,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a
- [Nextcloud Stats](#nextcloud-stats)
- [Nextcloud PHP Opcache](#nextcloud-php-opcache-stats)
- [Sabnzbd](#sabnzbd)
- [Gluetun VPN Info](#gluetun-vpn-info)
- **[System Resource Monitoring](#system-resource-monitoring)**
- [CPU Usage Current](#current-cpu-usage)
- [CPU Usage Per Core](#cpu-usage-per-core)
@ -1827,6 +1828,39 @@ Shows queue information regarding your self hosted Sabnzbd server.
---
### Gluetun VPN Info
Display info from the Gluetun VPN container public IP API. This can show the IP and location data for the exit VPN node.
<p align="center"><img width="380" src="https://imgur.com/TOtYZ7k" /></p>
##### Options
**Field** | **Type** | **Required** | **Description**
--- | --- | --- | ---
**`visibleFields`** | `string` | Required | A comma separated list of the fields you want visible in the widget. You can have any number of the following : `public_ip`, `region`, `country`, `city`, `location`, `organisation`, `postal_code`, `timezone`
**`host`** | `string` | Required | The url to the gluetun HTTP control server. E.g. `http://gluetun:8000`
##### Example
```yaml
- type: gluetun-status
useProxy: true
options:
hostname: http://server-or-conatiner-hostname:8000
visibleFields: public_ip,region,country,city,location,organisation,postal_code,timezone
```
##### Info
- **CORS**: 🟠 Proxied
- **Auth**: 🟢 Required
- **Price**: 🟢 Free
- **Host**: Self-Hosted (see [Gluetun](https://github.com/qdm12/gluetun))
- **Privacy**: _See [Gluetun Wiki](https://github.com/qdm12/gluetun/wiki)_
---
## System Resource Monitoring
The easiest method for displaying system info and resource usage in Dashy is with [Glances](https://nicolargo.github.io/glances/).

View File

@ -0,0 +1,121 @@
<template>
<div class="vpn-ip-addr-wrapper">
<div class="ip-row public-ip" v-if="public_ipT">
<span class="lbl">VPN IP</span>
<span class="val">{{ public_ip }}</span>
</div>
<div class="ip-row" v-if="regionT">
<span class="lbl">Region</span>
<span class="val">{{ region }}</span>
</div>
<div class="ip-row" v-if="countryT">
<span class="lbl">Country</span>
<span class="val">{{ country }}</span>
</div>
<div class="ip-row" v-if="cityT">
<span class="lbl">City</span>
<span class="val">{{ city }}</span>
</div>
<div class="ip-row" v-if="postal_codeT">
<span class="lbl">Post Code</span>
<span class="val">{{ postal_code }}</span>
</div>
<div class="ip-row" v-if="locationT">
<span class="lbl">Location</span>
<span class="val">{{ location }}</span>
</div>
<div class="ip-row" v-if="timezoneT">
<span class="lbl">Timezone</span>
<span class="val">{{ timezone }}</span>
</div>
<div class="ip-row" v-if="organizationT">
<span class="lbl">Organization</span>
<span class="val">{{ organization }}</span>
</div>
</div>
</template>
<script>
import WidgetMixin from '@/mixins/WidgetMixin';
import { widgetApiEndpoints } from '@/utils/defaults';
import { getCountryFlag, getMapUrl } from '@/utils/MiscHelpers';
export default {
mixins: [WidgetMixin],
data() {
return {
public_ip: null,
region: null,
country: null,
city: null,
location: null,
organization: null,
postal_code: null,
timezone: null,
public_ipT: null,
regionT: null,
countryT: null,
cityT: null,
locationT: null,
organizationT: null,
postal_codeT: null,
timezoneT: null,
};
},
methods: {
/* Make GET request to Gluetun publicip API endpoint */
fetchData() {
this.processToggles(this.options.visibleFields);
this.makeRequest(this.options.hostname + "/v1/publicip/ip").then(this.processData);
},
/* Assign data variables to the returned data */
processData(ipInfo) {
this.public_ip = ipInfo.public_ip;
this.region = ipInfo.region;
this.country = ipInfo.country;
this.city = ipInfo.city;
this.location = ipInfo.location;
this.organization = ipInfo.organization;
this.postal_code = ipInfo.postal_code;
this.timezone = ipInfo.timezone;
},
processToggles(toggles) {
var fields = toggles.split(",");
this.public_ipT = fields.includes("public_ip");
this.regionT = fields.includes("region");
this.countryT = fields.includes("country");
this.cityT = fields.includes("city");
this.locationT = fields.includes("location");
this.organizationT = fields.includes("organization");
this.postal_codeT = fields.includes("postal_code");
this.timezoneT = fields.includes("timezone");
}
},
};
</script>
<style scoped lang="scss">
.vpn-ip-addr-wrapper {
.ip-row {
display: flex;
padding: 0.1rem 0.1rem 0.5rem 0.1rem;
align-items: center;
justify-content: space-between;
color: var(--widget-text-color);
max-width: 400px;
margin: 0.5rem auto;
span.lbl {
font-weight: bold;
}
span.val {
font-family: var(--font-monospace);
}
&:not(.public-ip) {
opacity: var(--dimming-factor);
}
&:not(:last-child) {
border-bottom: 1px dashed var(--widget-text-color);
}
}
}
</style>

557
src/components/Widgets/WidgetBase.vue Normal file → Executable file
View File

@ -1,278 +1,279 @@
<template>
<div :class="`widget-base ${ loading ? 'is-loading' : '' }`">
<!-- Update and Full-Page Action Buttons -->
<Button :click="update" class="action-btn update-btn" v-if="!hideControls && !loading">
<UpdateIcon />
</Button>
<Button :click="fullScreenWidget"
class="action-btn open-btn" v-if="!hideControls && !error && !loading">
<OpenIcon />
</Button>
<!-- Loading Spinner -->
<div v-if="loading" class="loading">
<LoadingAnimation v-if="loading" class="loader" />
</div>
<!-- Error Message Display -->
<div v-if="error" class="widget-error">
<p class="error-msg">An error occurred, see the logs for more info.</p>
<p class="error-output">{{ errorMsg }}</p>
<p class="retry-link" @click="update">Retry</p>
</div>
<!-- Widget Label -->
<div class="widget-label" v-if="widgetOptions.label">{{ widgetOptions.label }}</div>
<!-- Widget -->
<div :class="`widget-wrap ${ error ? 'has-error' : '' }`">
<component
v-bind:is="component"
:options="widgetOptions"
@loading="setLoaderState"
@error="handleError"
:ref="widgetRef"
/>
</div>
</div>
</template>
<script>
// Import form elements, icons and utils
import ErrorHandler from '@/utils/ErrorHandler';
import Button from '@/components/FormElements/Button';
import UpdateIcon from '@/assets/interface-icons/widget-update.svg';
import OpenIcon from '@/assets/interface-icons/open-new-tab.svg';
import LoadingAnimation from '@/assets/interface-icons/loader.svg';
const COMPAT = {
'adguard-dns-info': 'AdGuardDnsInfo',
'adguard-filter-status': 'AdGuardFilterStatus',
'adguard-stats': 'AdGuardStats',
'adguard-top-domains': 'AdGuardTopDomains',
anonaddy: 'AnonAddy',
apod: 'Apod',
'blacklist-check': 'BlacklistCheck',
clock: 'Clock',
'crypto-price-chart': 'CryptoPriceChart',
'crypto-watch-list': 'CryptoWatchList',
'cve-vulnerabilities': 'CveVulnerabilities',
'domain-monitor': 'DomainMonitor',
'code-stats': 'CodeStats',
'covid-stats': 'CovidStats',
embed: 'EmbedWidget',
'eth-gas-prices': 'EthGasPrices',
'exchange-rates': 'ExchangeRates',
'flight-data': 'Flights',
'github-profile-stats': 'GitHubProfile',
'github-trending-repos': 'GitHubTrending',
'gl-alerts': 'GlAlerts',
'gl-current-cores': 'GlCpuCores',
'gl-current-cpu': 'GlCpuGauge',
'gl-cpu-history': 'GlCpuHistory',
'gl-disk-io': 'GlDiskIo',
'gl-disk-space': 'GlDiskSpace',
'gl-ip-address': 'GlIpAddress',
'gl-load-history': 'GlLoadHistory',
'gl-current-mem': 'GlMemGauge',
'gl-mem-history': 'GlMemHistory',
'gl-network-interfaces': 'GlNetworkInterfaces',
'gl-network-traffic': 'GlNetworkTraffic',
'gl-system-load': 'GlSystemLoad',
'gl-cpu-temp': 'GlCpuTemp',
'health-checks': 'HealthChecks',
iframe: 'IframeWidget',
image: 'ImageWidget',
joke: 'Jokes',
'mullvad-status': 'MullvadStatus',
'nd-cpu-history': 'NdCpuHistory',
'nd-load-history': 'NdLoadHistory',
'nd-ram-history': 'NdRamHistory',
'news-headlines': 'NewsHeadlines',
'nextcloud-notifications': 'NextcloudNotifications',
'nextcloud-php-opcache': 'NextcloudPhpOpcache',
'nextcloud-stats': 'NextcloudStats',
'nextcloud-system': 'NextcloudSystem',
'nextcloud-user': 'NextcloudUser',
'nextcloud-user-status': 'NextcloudUserStatus',
'pi-hole-stats': 'PiHoleStats',
'pi-hole-top-queries': 'PiHoleTopQueries',
'pi-hole-traffic': 'PiHoleTraffic',
'public-holidays': 'PublicHolidays',
'public-ip': 'PublicIp',
'rss-feed': 'RssFeed',
sabnzbd: 'Sabnzbd',
'sports-scores': 'SportsScores',
'stat-ping': 'StatPing',
'stock-price-chart': 'StockPriceChart',
'synology-download': 'SynologyDownload',
'system-info': 'SystemInfo',
'tfl-status': 'TflStatus',
'wallet-balance': 'WalletBalance',
weather: 'Weather',
'weather-forecast': 'WeatherForecast',
'xkcd-comic': 'XkcdComic',
};
export default {
name: 'Widget',
components: {
// Register form elements
Button,
UpdateIcon,
OpenIcon,
LoadingAnimation,
},
props: {
widget: Object,
index: Number,
},
data: () => ({
loading: false,
error: false,
errorMsg: null,
}),
computed: {
appConfig() {
return this.$store.getters.appConfig;
},
/* Returns the widget type, shows error if not specified */
widgetType() {
if (!this.widget.type) {
ErrorHandler('Missing type attribute for widget');
return null;
}
return this.widget.type.toLowerCase();
},
/* Returns users specified widget options, or empty object */
widgetOptions() {
const options = this.widget.options || {};
const timeout = this.widget.timeout || null;
const ignoreErrors = this.widget.ignoreErrors || false;
const label = this.widget.label || null;
const useProxy = this.appConfig.widgetsAlwaysUseProxy || !!this.widget.useProxy;
const updateInterval = this.widget.updateInterval !== undefined
? this.widget.updateInterval : null;
return {
timeout, ignoreErrors, label, useProxy, updateInterval, ...options,
};
},
/* A unique string to reference the widget by */
widgetRef() {
return `widget-${this.widgetType}-${this.index}`;
},
hideControls() {
return this.widget.hideControls;
},
component() {
const type = COMPAT[this.widgetType] || this.widget.type;
if (!type) {
ErrorHandler('Widget type was not found');
return null;
}
// eslint-disable-next-line prefer-template
return () => import('@/components/Widgets/' + type + '.vue').catch(() => import('@/components/Widgets/Blank.vue'));
},
},
methods: {
/* Calls update data method on widget */
update() {
this.error = false;
this.$refs[this.widgetRef].update();
},
/* Shows message when error occurred */
handleError(msg) {
this.error = true;
this.errorMsg = msg;
},
/* Opens current widget in full-page */
fullScreenWidget() {
this.$emit('navigateToSection');
},
/* Toggles loading state */
setLoaderState(loading) {
this.loading = loading;
},
},
};
</script>
<style scoped lang="scss">
@import '@/styles/media-queries.scss';
.widget-base {
position: relative;
padding: 0.75rem 0.5rem 0.5rem 0.5rem;
background: var(--widget-base-background);
box-shadow: var(--widget-base-shadow, none);
// Refresh and full-page action buttons
button.action-btn {
height: 1rem;
min-width: auto;
width: 1.75rem;
margin: 0;
padding: 0.1rem 0;
position: absolute;
top: 0;
border: none;
opacity: var(--dimming-factor);
color: var(--widget-text-color);
&:hover {
opacity: 1;
color: var(--widget-background-color);
}
&.update-btn {
right: -0.25rem;
}
&.open-btn {
right: 1.75rem;
}
}
// Optional widget label
.widget-label {
color: var(--widget-text-color);
}
// Actual widget container
.widget-wrap {
&.has-error {
cursor: not-allowed;
opacity: 0.5;
border-radius: var(--curve-factor);
background: #ffff0040;
&:hover { background: none; }
}
}
// Error message output
.widget-error {
p.error-msg {
color: var(--warning);
font-weight: bold;
font-size: 1rem;
margin: 0 auto 0.5rem auto;
}
p.error-output {
font-family: var(--font-monospace);
color: var(--widget-text-color);
font-size: 0.85rem;
margin: 0.5rem auto;
}
p.retry-link {
cursor: pointer;
text-decoration: underline;
color: var(--widget-text-color);
font-size: 0.85rem;
margin: 0;
}
}
// Loading spinner
.loading {
margin: 0.2rem auto;
text-align: center;
svg.loader {
width: 100px;
}
}
// Hide widget contents while loading
&.is-loading {
.widget-wrap {
display: none;
}
}
}
</style>
<template>
<div :class="`widget-base ${ loading ? 'is-loading' : '' }`">
<!-- Update and Full-Page Action Buttons -->
<Button :click="update" class="action-btn update-btn" v-if="!hideControls && !loading">
<UpdateIcon />
</Button>
<Button :click="fullScreenWidget"
class="action-btn open-btn" v-if="!hideControls && !error && !loading">
<OpenIcon />
</Button>
<!-- Loading Spinner -->
<div v-if="loading" class="loading">
<LoadingAnimation v-if="loading" class="loader" />
</div>
<!-- Error Message Display -->
<div v-if="error" class="widget-error">
<p class="error-msg">An error occurred, see the logs for more info.</p>
<p class="error-output">{{ errorMsg }}</p>
<p class="retry-link" @click="update">Retry</p>
</div>
<!-- Widget Label -->
<div class="widget-label" v-if="widgetOptions.label">{{ widgetOptions.label }}</div>
<!-- Widget -->
<div :class="`widget-wrap ${ error ? 'has-error' : '' }`">
<component
v-bind:is="component"
:options="widgetOptions"
@loading="setLoaderState"
@error="handleError"
:ref="widgetRef"
/>
</div>
</div>
</template>
<script>
// Import form elements, icons and utils
import ErrorHandler from '@/utils/ErrorHandler';
import Button from '@/components/FormElements/Button';
import UpdateIcon from '@/assets/interface-icons/widget-update.svg';
import OpenIcon from '@/assets/interface-icons/open-new-tab.svg';
import LoadingAnimation from '@/assets/interface-icons/loader.svg';
const COMPAT = {
'adguard-dns-info': 'AdGuardDnsInfo',
'adguard-filter-status': 'AdGuardFilterStatus',
'adguard-stats': 'AdGuardStats',
'adguard-top-domains': 'AdGuardTopDomains',
anonaddy: 'AnonAddy',
apod: 'Apod',
'blacklist-check': 'BlacklistCheck',
clock: 'Clock',
'crypto-price-chart': 'CryptoPriceChart',
'crypto-watch-list': 'CryptoWatchList',
'cve-vulnerabilities': 'CveVulnerabilities',
'domain-monitor': 'DomainMonitor',
'code-stats': 'CodeStats',
'covid-stats': 'CovidStats',
embed: 'EmbedWidget',
'eth-gas-prices': 'EthGasPrices',
'exchange-rates': 'ExchangeRates',
'flight-data': 'Flights',
'github-profile-stats': 'GitHubProfile',
'github-trending-repos': 'GitHubTrending',
'gl-alerts': 'GlAlerts',
'gl-current-cores': 'GlCpuCores',
'gl-current-cpu': 'GlCpuGauge',
'gl-cpu-history': 'GlCpuHistory',
'gl-disk-io': 'GlDiskIo',
'gl-disk-space': 'GlDiskSpace',
'gl-ip-address': 'GlIpAddress',
'gl-load-history': 'GlLoadHistory',
'gl-current-mem': 'GlMemGauge',
'gl-mem-history': 'GlMemHistory',
'gl-network-interfaces': 'GlNetworkInterfaces',
'gl-network-traffic': 'GlNetworkTraffic',
'gl-system-load': 'GlSystemLoad',
'gl-cpu-temp': 'GlCpuTemp',
'health-checks': 'HealthChecks',
'gluetun-status': 'GluetunStatus',
iframe: 'IframeWidget',
image: 'ImageWidget',
joke: 'Jokes',
'mullvad-status': 'MullvadStatus',
'nd-cpu-history': 'NdCpuHistory',
'nd-load-history': 'NdLoadHistory',
'nd-ram-history': 'NdRamHistory',
'news-headlines': 'NewsHeadlines',
'nextcloud-notifications': 'NextcloudNotifications',
'nextcloud-php-opcache': 'NextcloudPhpOpcache',
'nextcloud-stats': 'NextcloudStats',
'nextcloud-system': 'NextcloudSystem',
'nextcloud-user': 'NextcloudUser',
'nextcloud-user-status': 'NextcloudUserStatus',
'pi-hole-stats': 'PiHoleStats',
'pi-hole-top-queries': 'PiHoleTopQueries',
'pi-hole-traffic': 'PiHoleTraffic',
'public-holidays': 'PublicHolidays',
'public-ip': 'PublicIp',
'rss-feed': 'RssFeed',
sabnzbd: 'Sabnzbd',
'sports-scores': 'SportsScores',
'stat-ping': 'StatPing',
'stock-price-chart': 'StockPriceChart',
'synology-download': 'SynologyDownload',
'system-info': 'SystemInfo',
'tfl-status': 'TflStatus',
'wallet-balance': 'WalletBalance',
weather: 'Weather',
'weather-forecast': 'WeatherForecast',
'xkcd-comic': 'XkcdComic',
};
export default {
name: 'Widget',
components: {
// Register form elements
Button,
UpdateIcon,
OpenIcon,
LoadingAnimation,
},
props: {
widget: Object,
index: Number,
},
data: () => ({
loading: false,
error: false,
errorMsg: null,
}),
computed: {
appConfig() {
return this.$store.getters.appConfig;
},
/* Returns the widget type, shows error if not specified */
widgetType() {
if (!this.widget.type) {
ErrorHandler('Missing type attribute for widget');
return null;
}
return this.widget.type.toLowerCase();
},
/* Returns users specified widget options, or empty object */
widgetOptions() {
const options = this.widget.options || {};
const timeout = this.widget.timeout || null;
const ignoreErrors = this.widget.ignoreErrors || false;
const label = this.widget.label || null;
const useProxy = this.appConfig.widgetsAlwaysUseProxy || !!this.widget.useProxy;
const updateInterval = this.widget.updateInterval !== undefined
? this.widget.updateInterval : null;
return {
timeout, ignoreErrors, label, useProxy, updateInterval, ...options,
};
},
/* A unique string to reference the widget by */
widgetRef() {
return `widget-${this.widgetType}-${this.index}`;
},
hideControls() {
return this.widget.hideControls;
},
component() {
const type = COMPAT[this.widgetType] || this.widget.type;
if (!type) {
ErrorHandler('Widget type was not found');
return null;
}
// eslint-disable-next-line prefer-template
return () => import('@/components/Widgets/' + type + '.vue').catch(() => import('@/components/Widgets/Blank.vue'));
},
},
methods: {
/* Calls update data method on widget */
update() {
this.error = false;
this.$refs[this.widgetRef].update();
},
/* Shows message when error occurred */
handleError(msg) {
this.error = true;
this.errorMsg = msg;
},
/* Opens current widget in full-page */
fullScreenWidget() {
this.$emit('navigateToSection');
},
/* Toggles loading state */
setLoaderState(loading) {
this.loading = loading;
},
},
};
</script>
<style scoped lang="scss">
@import '@/styles/media-queries.scss';
.widget-base {
position: relative;
padding: 0.75rem 0.5rem 0.5rem 0.5rem;
background: var(--widget-base-background);
box-shadow: var(--widget-base-shadow, none);
// Refresh and full-page action buttons
button.action-btn {
height: 1rem;
min-width: auto;
width: 1.75rem;
margin: 0;
padding: 0.1rem 0;
position: absolute;
top: 0;
border: none;
opacity: var(--dimming-factor);
color: var(--widget-text-color);
&:hover {
opacity: 1;
color: var(--widget-background-color);
}
&.update-btn {
right: -0.25rem;
}
&.open-btn {
right: 1.75rem;
}
}
// Optional widget label
.widget-label {
color: var(--widget-text-color);
}
// Actual widget container
.widget-wrap {
&.has-error {
cursor: not-allowed;
opacity: 0.5;
border-radius: var(--curve-factor);
background: #ffff0040;
&:hover { background: none; }
}
}
// Error message output
.widget-error {
p.error-msg {
color: var(--warning);
font-weight: bold;
font-size: 1rem;
margin: 0 auto 0.5rem auto;
}
p.error-output {
font-family: var(--font-monospace);
color: var(--widget-text-color);
font-size: 0.85rem;
margin: 0.5rem auto;
}
p.retry-link {
cursor: pointer;
text-decoration: underline;
color: var(--widget-text-color);
font-size: 0.85rem;
margin: 0;
}
}
// Loading spinner
.loading {
margin: 0.2rem auto;
text-align: center;
svg.loader {
width: 100px;
}
}
// Hide widget contents while loading
&.is-loading {
.widget-wrap {
display: none;
}
}
}
</style>