Compare commits
12 Commits
dc645dfd19
...
master
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ae12d05779 | ||
4ab6081307 | |||
![]() |
142f761930 | ||
![]() |
413d66e719 | ||
![]() |
00fcc34e5e | ||
![]() |
9fdbb5e4a5 | ||
![]() |
f3898822a3 | ||
![]() |
f1db607cac | ||
![]() |
45e187f8fa | ||
![]() |
8f36a912c1 | ||
![]() |
ca89d5ae14 | ||
![]() |
03d8d4e38f |
5
Makefile
5
Makefile
@ -27,8 +27,9 @@ COM =\
|
|||||||
components/uptime\
|
components/uptime\
|
||||||
components/user\
|
components/user\
|
||||||
components/volume\
|
components/volume\
|
||||||
components/wifi
|
components/wifi\
|
||||||
|
components/mullvad\
|
||||||
|
components/relay
|
||||||
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[0x80];
|
||||||
|
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
|
45
components/relay.c
Normal file
45
components/relay.c
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#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 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;
|
||||||
|
}
|
||||||
|
|
1
components/sh/ip.sh
Normal file
1
components/sh/ip.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
curl -s icanhazip.com
|
9
components/sh/wg.sh
Normal file
9
components/sh/wg.sh
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
response=$(curl -s https://am.i.mullvad.net/json)
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
server=$(echo "$response" | jq -r '.mullvad_exit_ip_hostname')
|
||||||
|
if [ "$server" != "null" ]; then
|
||||||
|
echo "$server"
|
||||||
|
fi
|
||||||
|
|
83
config.def.h
83
config.def.h
@ -1,75 +1,28 @@
|
|||||||
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
|
||||||
|
|
||||||
/*
|
#define IFACE "enp6s0"
|
||||||
* function description argument (example)
|
#define BAT "BAT0"
|
||||||
*
|
|
||||||
* 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 "wifibox0"
|
|
||||||
#define BAT "BAT1"
|
|
||||||
|
|
||||||
static const struct arg args[] = {
|
static const struct arg args[] = {
|
||||||
{ netspeed_rx, " [ %sB/s]", IFACE },
|
{ netspeed_rx, " [ %sB/s]", IFACE },
|
||||||
{ ipv4, " ^c#fb4934^[ %s]", IFACE },
|
{ netspeed_tx, " [ %sB/s]", IFACE },
|
||||||
{ battery_perc, " ^c#fe9019^[ %s%%", BAT },
|
{ ipv4, " ^c#fb4934^[ %s]", IFACE },
|
||||||
{ battery_remaining," %s]", BAT },
|
{ run_command, " ^c#7ec07c^[%s]", "sh /opt/suckless/slstatus/components/sh/ip.sh" },
|
||||||
{ run_command, " ^c#8ec07c^[ %s]", "amixer sget Master | awk -F\"[][]\" '/%/ { print $2 }' | head -n1" },
|
{ run_command, " ^c#fb4934^[%s]", "sh /opt/suckless/slstatus/components/sh/wg.sh" },
|
||||||
|
//{ 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 | grep -oP '\\d+(?=%)' | head -n 1" },
|
||||||
|
//{ vol_perc, " ^c#8ec07c^[ %s]", NULL },
|
||||||
{ cpu_perc, " ^c#b8bb26^[%s%%]", NULL },
|
{ cpu_perc, " ^c#b8bb26^[%s%%]", NULL },
|
||||||
{ ram_used, " ^c#d3869b^[ %s]", NULL },
|
{ ram_used, " ^c#d3869b^[ %s]", NULL },
|
||||||
{ disk_free, " ^c#fe8019^[ %s]", "/" },
|
|
||||||
{ datetime, " ^c#ebdbb2^[ %s]", "%H:%M:%S" },
|
{ datetime, " ^c#ebdbb2^[ %s]", "%H:%M:%S" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ VERSION = 1.0
|
|||||||
# customize below to fit your system
|
# customize below to fit your system
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr
|
||||||
MANPREFIX = $(PREFIX)/share/man
|
MANPREFIX = $(PREFIX)/share/man
|
||||||
|
|
||||||
X11INC = ${PREFIX}/include
|
X11INC = ${PREFIX}/include
|
||||||
@ -16,7 +16,7 @@ CFLAGS = -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter -Os
|
|||||||
LDFLAGS = -L$(X11LIB) -s
|
LDFLAGS = -L$(X11LIB) -s
|
||||||
# OpenBSD: add -lsndio
|
# OpenBSD: add -lsndio
|
||||||
# FreeBSD: add -lkvm -lsndio
|
# FreeBSD: add -lkvm -lsndio
|
||||||
LDLIBS = -lX11 -lkvm -lsndio
|
LDLIBS = -lX11
|
||||||
|
|
||||||
# compiler and linker
|
# compiler and linker
|
||||||
CC = cc
|
CC = cc
|
||||||
|
@ -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,8 @@ 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);
|
||||||
|
|
||||||
|
const char *mullvad_relay(const char *stat);
|
||||||
|
Reference in New Issue
Block a user