add mullvad comp
This commit is contained in:
4
Makefile
4
Makefile
@ -27,8 +27,8 @@ COM =\
|
|||||||
components/uptime\
|
components/uptime\
|
||||||
components/user\
|
components/user\
|
||||||
components/volume\
|
components/volume\
|
||||||
components/wifi
|
components/wifi\
|
||||||
|
components/mullvad
|
||||||
all: slstatus
|
all: slstatus
|
||||||
|
|
||||||
$(COM:=.o): config.mk $(REQ:=.h) slstatus.h
|
$(COM:=.o): config.mk $(REQ:=.h) slstatus.h
|
||||||
|
48
components/mullvad.c
Normal file
48
components/mullvad.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#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
|
59
config.def.h
59
config.def.h
@ -1,61 +1,7 @@
|
|||||||
const unsigned int interval = 1000;
|
const unsigned int interval = 1000;
|
||||||
static const char unknown_str[] = "?";
|
static const char unknown_str[] = "?";
|
||||||
#define MAXLEN 2048
|
|
||||||
|
|
||||||
/*
|
#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 IFACE "enp4s0"
|
#define IFACE "enp4s0"
|
||||||
#define BAT "BAT1"
|
#define BAT "BAT1"
|
||||||
@ -64,8 +10,11 @@ static const struct arg args[] = {
|
|||||||
{ netspeed_rx, " [ %sB/s]", IFACE },
|
{ netspeed_rx, " [ %sB/s]", IFACE },
|
||||||
{ netspeed_tx, " [ %sB/s]", IFACE },
|
{ netspeed_tx, " [ %sB/s]", IFACE },
|
||||||
{ ipv4, " ^c#fb4934^[ %s]", IFACE },
|
{ ipv4, " ^c#fb4934^[ %s]", IFACE },
|
||||||
|
{ mullvad_stat, " [VPN: %s]", NULL},
|
||||||
|
|
||||||
//{ battery_perc, " ^c#fe9019^[ %s%%", BAT },
|
//{ battery_perc, " ^c#fe9019^[ %s%%", BAT },
|
||||||
//{ battery_remaining," %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 },
|
{ cpu_perc, " ^c#b8bb26^[%s%%]", NULL },
|
||||||
{ ram_used, " ^c#d3869b^[ %s]", NULL },
|
{ ram_used, " ^c#d3869b^[ %s]", NULL },
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "slstatus.h"
|
#include "slstatus.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
|
||||||
struct arg {
|
struct arg {
|
||||||
const char *(*func)(const char *);
|
const char *(*func)(const char *);
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
|
@ -5,6 +5,7 @@ const char *battery_perc(const char *);
|
|||||||
const char *battery_remaining(const char *);
|
const char *battery_remaining(const char *);
|
||||||
const char *battery_state(const char *);
|
const char *battery_state(const char *);
|
||||||
|
|
||||||
|
|
||||||
/* cat */
|
/* cat */
|
||||||
const char *cat(const char *path);
|
const char *cat(const char *path);
|
||||||
|
|
||||||
@ -82,3 +83,6 @@ const char *vol_perc(const char *card);
|
|||||||
/* wifi */
|
/* wifi */
|
||||||
const char *wifi_essid(const char *interface);
|
const char *wifi_essid(const char *interface);
|
||||||
const char *wifi_perc(const char *interface);
|
const char *wifi_perc(const char *interface);
|
||||||
|
|
||||||
|
/* mullvad */
|
||||||
|
const char *mullvad_stat(const char *stat);
|
||||||
|
Reference in New Issue
Block a user