From 8f36a912c1411e304f5dd1a845f1fe30f1d5b557 Mon Sep 17 00:00:00 2001 From: memL0rz Date: Mon, 21 Oct 2024 22:08:00 +0200 Subject: [PATCH] add mullvad comp --- Makefile | 4 +-- components/mullvad.c | 48 +++++++++++++++++++++++++++++++++ config.def.h | 63 +++++--------------------------------------- slstatus.c | 1 + slstatus.h | 4 +++ 5 files changed, 61 insertions(+), 59 deletions(-) create mode 100644 components/mullvad.c diff --git a/Makefile b/Makefile index b734fae..ed4c1fc 100755 --- a/Makefile +++ b/Makefile @@ -27,8 +27,8 @@ COM =\ components/uptime\ components/user\ components/volume\ - components/wifi - + components/wifi\ + components/mullvad all: slstatus $(COM:=.o): config.mk $(REQ:=.h) slstatus.h diff --git a/components/mullvad.c b/components/mullvad.c new file mode 100644 index 0000000..f8a091d --- /dev/null +++ b/components/mullvad.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include "../slstatus.h" +#include "../util.h" + +#define MULLVAD_STAT_CMD "mullvad status" + +static int +mullvad_conn() +{ + FILE *fp; + char buff[128]; + int conn = 0; + + fp = popen(MULLVAD_STAT_CMD, "r"); + if (fp == NULL) + { + perror("popen"); + return -1; + } + + while (fgets(buff, sizeof(buff), fp) != NULL) + { + if (strstr(buff, "Connected") != NULL) + { + conn = 1; + } + } + pclose(fp); + return conn; +} + +const char *mullvad_stat(const char *stat) +{ + static char status[128]; + if (mullvad_conn()) + { + snprintf(status, sizeof(status), "CNTD"); + } else { + snprintf(status, sizeof(status), "NOT CNTD"); + } + return status; +} + +// this shit sucks more diff --git a/config.def.h b/config.def.h index c11f97b..7a32670 100755 --- a/config.def.h +++ b/config.def.h @@ -1,61 +1,7 @@ const unsigned int interval = 1000; static const char unknown_str[] = "?"; -#define MAXLEN 2048 -/* - * function description argument (example) - * - * battery_perc battery percentage battery name (BAT0) - * NULL on OpenBSD/FreeBSD - * battery_remaining battery remaining HH:MM battery name (BAT0) - * NULL on OpenBSD/FreeBSD - * battery_state battery charging state battery name (BAT0) - * NULL on OpenBSD/FreeBSD - * cat read arbitrary file path - * cpu_freq cpu frequency in MHz NULL - * cpu_perc cpu usage in percent NULL - * datetime date and time format string (%F %T) - * disk_free free disk space in GB mountpoint path (/) - * disk_perc disk usage in percent mountpoint path (/) - * disk_total total disk space in GB mountpoint path (/) - * disk_used used disk space in GB mountpoint path (/) - * entropy available entropy NULL - * gid GID of current user NULL - * hostname hostname NULL - * ipv4 IPv4 address interface name (eth0) - * ipv6 IPv6 address interface name (eth0) - * kernel_release `uname -r` NULL - * keyboard_indicators caps/num lock indicators format string (c?n?) - * see keyboard_indicators.c - * keymap layout (variant) of current NULL - * keymap - * load_avg load average NULL - * netspeed_rx receive network speed interface name (wlan0) - * netspeed_tx transfer network speed interface name (wlan0) - * num_files number of files in a directory path - * (/home/foo/Inbox/cur) - * ram_free free memory in GB NULL - * ram_perc memory usage in percent NULL - * ram_total total memory size in GB NULL - * ram_used used memory in GB NULL - * run_command custom shell command command (echo foo) - * swap_free free swap in GB NULL - * swap_perc swap usage in percent NULL - * swap_total total swap size in GB NULL - * swap_used used swap in GB NULL - * temp temperature in degree celsius sensor file - * (/sys/class/thermal/...) - * NULL on OpenBSD - * thermal zone on FreeBSD - * (tz0, tz1, etc.) - * uid UID of current user NULL - * uptime system uptime NULL - * username username of current user NULL - * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) - * NULL on OpenBSD/FreeBSD - * wifi_essid WiFi ESSID interface name (wlan0) - * wifi_perc WiFi signal in percent interface name (wlan0) - */ +#define MAXLEN 2048 #define IFACE "enp4s0" #define BAT "BAT1" @@ -64,9 +10,12 @@ static const struct arg args[] = { { netspeed_rx, " [ %sB/s]", IFACE }, { netspeed_tx, " [ %sB/s]", IFACE }, { ipv4, " ^c#fb4934^[ %s]", IFACE }, - //{ battery_perc, " ^c#fe9019^[ %s%%", BAT }, + { mullvad_stat, " [VPN: %s]", NULL}, + + //{ battery_perc, " ^c#fe9019^[ %s%%", BAT }, //{ battery_remaining," %s]", BAT }, - { run_command, " ^c#8ec07c^[ %s]", "amixer sget Master | awk -F\"[][]\" '/%/ { print $2 }' | head -n1" }, + + { run_command, " ^c#8ec07c^[ %s]", "amixer sget Master | awk -F\"[][]\" '/%/ { print $2 }' | head -n1" }, { cpu_perc, " ^c#b8bb26^[%s%%]", NULL }, { ram_used, " ^c#d3869b^[ %s]", NULL }, { disk_free, " ^c#fe8019^[ %s]", "/" }, diff --git a/slstatus.c b/slstatus.c index fd31313..40564e3 100755 --- a/slstatus.c +++ b/slstatus.c @@ -11,6 +11,7 @@ #include "slstatus.h" #include "util.h" + struct arg { const char *(*func)(const char *); const char *fmt; diff --git a/slstatus.h b/slstatus.h index 8ef5874..fd275f0 100755 --- a/slstatus.h +++ b/slstatus.h @@ -5,6 +5,7 @@ const char *battery_perc(const char *); const char *battery_remaining(const char *); const char *battery_state(const char *); + /* cat */ const char *cat(const char *path); @@ -82,3 +83,6 @@ const char *vol_perc(const char *card); /* wifi */ const char *wifi_essid(const char *interface); const char *wifi_perc(const char *interface); + +/* mullvad */ +const char *mullvad_stat(const char *stat);