diff --git a/Makefile b/Makefile index ed4c1fc..d41c66f 100755 --- a/Makefile +++ b/Makefile @@ -28,7 +28,8 @@ COM =\ components/user\ components/volume\ components/wifi\ - components/mullvad + components/mullvad\ + components/relay all: slstatus $(COM:=.o): config.mk $(REQ:=.h) slstatus.h diff --git a/components/mullvad.c b/components/mullvad.c index f8a091d..d92ed9e 100644 --- a/components/mullvad.c +++ b/components/mullvad.c @@ -12,7 +12,7 @@ static int mullvad_conn() { FILE *fp; - char buff[128]; + char buff[0x80]; int conn = 0; fp = popen(MULLVAD_STAT_CMD, "r"); diff --git a/components/relay.c b/components/relay.c new file mode 100644 index 0000000..35a91e6 --- /dev/null +++ b/components/relay.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include "../slstatus.h" +#include "../util.h" + +#define MULLVAD_STAT_CMD "mullvad status" + +static const char *get_relay() { + FILE *fp; + char buff[0x80]; + static char relay[0x80]; + + fp = popen("mullvad status", "r"); + if (fp == NULL) { + perror("popen"); + return NULL; + } + while (fgets(buff, sizeof(buff), fp) != NULL) { + if (strstr(buff, "Relay")) { + if (sscanf(buff, "Relay: %s", relay) == 1) { + fclose(fp); + return relay; + } + } + } + pclose(fp); + return NULL; +} + +const char *mullvad_relay(const char *stat) { + static char rtrelay[0x80]; + const char *relay = get_relay(); + + if (relay != NULL) { + snprintf(rtrelay, sizeof(rtrelay), "%s", relay); + } else { + snprintf(rtrelay, sizeof(rtrelay), "No Relay"); + } + + return rtrelay; +} + diff --git a/config.def.h b/config.def.h index 905a1ee..3807e56 100755 --- a/config.def.h +++ b/config.def.h @@ -11,13 +11,14 @@ static const struct arg args[] = { { netspeed_tx, " [ %sB/s]", IFACE }, { ipv4, " ^c#fb4934^[ %s]", IFACE }, { run_command, " ^c#fb4934^[%s]", "sh /opt/suckless/slstatus/components/wg.sh" }, - { mullvad_stat, " [VPN: %s]", NULL}, - + { mullvad_relay, " [%s]", NULL }, + { mullvad_stat, " [%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" }, - // { vol_perc, " ^c#8ec07c^[ %s]", NULL }, + //{ run_command, " ^c#8ec07c^[ %s]", "amixer sget Master | awk -F\"[][]\" '/%/ { print $2 }' | head -n1" }, + { vol_perc, " ^c#8ec07c^[ %s]", NULL }, { cpu_perc, " ^c#b8bb26^[%s%%]", NULL }, { ram_used, " ^c#d3869b^[ %s]", NULL }, { datetime, " ^c#ebdbb2^[ %s]", "%H:%M:%S" }, diff --git a/slstatus.h b/slstatus.h index fd275f0..981f9bd 100755 --- a/slstatus.h +++ b/slstatus.h @@ -86,3 +86,5 @@ const char *wifi_perc(const char *interface); /* mullvad */ const char *mullvad_stat(const char *stat); + +const char *mullvad_relay(const char *stat);