From 39af1132f84ab725d1eb91e9c5263080efbe672b Mon Sep 17 00:00:00 2001 From: Sheppy Date: Wed, 25 Oct 2017 20:48:33 +0200 Subject: [PATCH] lalala --- herbstluftwm/autostart | 2 +- herbstluftwm/hl_constants.py | 1 + herbstluftwm/hl_panel_content.py | 10 ++++-- herbstluftwm/hl_status_deamon.py | 62 ++++++++++++++++++++++++-------- herbstluftwm/password.cip | 1 + 5 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 herbstluftwm/password.cip diff --git a/herbstluftwm/autostart b/herbstluftwm/autostart index ba28d3c..8ae0ecc 100755 --- a/herbstluftwm/autostart +++ b/herbstluftwm/autostart @@ -120,7 +120,7 @@ hc keybind $Mod-Control-Up resize up +$resizestep hc keybind $Mod-Control-Right resize right +$resizestep # tags -#hc rename default "1" || true +hc rename default "1" || true hc add "2" hc add "3" hc add "4" diff --git a/herbstluftwm/hl_constants.py b/herbstluftwm/hl_constants.py index ac81771..2490eaf 100644 --- a/herbstluftwm/hl_constants.py +++ b/herbstluftwm/hl_constants.py @@ -12,6 +12,7 @@ PRINT_LOG = "pracct.log" VPN_LOG = "vpn_status.log" BATTERY_LOG = "battery.log" IP_LOG = "ip.log" +LOGINS_LOG = "logins.log" BATTERY_CRITICAL = 2 # in % BAT_WARNING_STR = ">>>>>>>>>>>>>>>> ------------ WARNING BATTER FAILURE IMMINENT ------------ <<<<<<<<<<<<<" diff --git a/herbstluftwm/hl_panel_content.py b/herbstluftwm/hl_panel_content.py index 517a991..c531029 100755 --- a/herbstluftwm/hl_panel_content.py +++ b/herbstluftwm/hl_panel_content.py @@ -11,8 +11,8 @@ def guthaben(): with open(hl_utils.hlpath(PRINT_LOG)) as f: raw = f.read(); guthaben = "Druckerguthaben: " + raw + " Euro" - col = get_color(float(raw),0,COLOR_BORDER) - guthaben = color_panel(guthaben,col) + col = hl_utils.get_color(float(raw),0,COLOR_BORDER) + guthaben = hl_utils.color_panel(guthaben,col) return guthaben; def vpn(): @@ -46,5 +46,9 @@ def battery(): def date(): return hl_utils.shexec("date +' ^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d'") +def logins(): + with open(LOGINS_LOG,'r') as f: + return f.read() + if __name__ == "__main__": - print(ip(),vpn(),guthaben(),battery(),date(),sep='',end='') + print(logins(),ip(),vpn(),guthaben(),battery(),date(),sep='',end='') diff --git a/herbstluftwm/hl_status_deamon.py b/herbstluftwm/hl_status_deamon.py index 2a56252..8841810 100755 --- a/herbstluftwm/hl_status_deamon.py +++ b/herbstluftwm/hl_status_deamon.py @@ -7,7 +7,9 @@ import subprocess import re import hl_utils import signal +import socket from hl_constants import * +from datetime import datetime battery_average=[] bat_prev = -1 @@ -17,10 +19,34 @@ def sigusr1_handler(signum, frame): def cip_logins(): - l=hl_utils.shexec("wget -q -O- --user cip --password $(cat $HOME/.config/password.cip) 'https://atlantishq.de/cipactive/active_logins'") - if len(l) > 5: - return hl_utils.color_panel("CIP Logins: "+str(len(l)),RED) - color = hl_utils.get_color( + MAX_LOGINS=5 + pw="NOPE" + try: + with open(hl_utils.hlpath("password.cip")) as f: + pw=f.read().strip("\n") + except: + return "" + cmd="wget -q -O- --user cip --password "+pw+" 'https://atlantishq.de/cipactive/active_logins'" + try: + l=hl_utils.shexec(cmd).split("\n") + except: + return "" + + if len(l) > MAX_LOGINS: + ret = hl_utils.color_panel("CIP Logins: "+str(len(l)),RED) + elif len(l) <= 1: + ret = "" + else: + color = hl_utils.get_color(len(l),MAX_LOGINS,0) + ret = str(l) + for line in l: + if line =='': + continue + ret = ret + line + ", " + ret = ret[:-len(", ")] + ret = hl_utils.color_panel("CIP Logins: "+ret,color) + with open(hl_utils.hlpath(LOGINS_LOG),'w') as f: + f.write(ret) def battery(): try: @@ -98,8 +124,8 @@ def battery(): def pr_acct_status(): if hl_utils.is_cip(): - out = hl_utils.color_remove(hl_utils.shexec(PRINT_LOG).split("\n")[0]).split(' ')[-1] - with open(hl_utils.hlpath(PRINT_LOG),'w+') as f: + out = hl_utils.color_remove(hl_utils.shexec("pr_acct").split("\n")[0]).split(' ')[-1] + with open(hl_utils.hlpath(PRINT_LOG),'w') as f: f.write(out) def vpn_status(): @@ -127,13 +153,19 @@ def battery_status(): with open(hl_utils.hlpath(BATTERY_LOG),'w') as g: g.write(battery()) +last_ip="LOL" def ip_status(): + global last_ip + try: + ip="Public IP: "+ hl_utils.shexec("wget --timeout=3 -O- --quiet https://atlantishq.de/ipcheck") + if last_ip == ip: + return + else: + last_ip = ip + tmp = hl_utils.color_panel(ip,GREEN) + except: + tmp = hl_utils.color_panel("Offline",RED) with open(hl_utils.hlpath(IP_LOG),'w') as g: - p="Public IP: " - try: - tmp = hl_utils.color_panel(p+hl_utils.shexec("wget --timeout=3 -O- --quiet https://atlantishq.de/ipcheck"),GREEN) - except: - tmp = hl_utils.color_panel("Offline",RED) g.write(tmp) def save(): @@ -141,14 +173,16 @@ def save(): pr_acct_status() battery_status() ip_status() + cip_logins() + trace_login() def trace_login(): - if is_cip(): + if hl_utils.is_cip(): try: - tmp = shexec("wget --timeout=3 -O- --quiet 'https://atlantishq.de/ciplog/"+socket.gethostname()+"&active&"+str(datetime.now())+"'") + tmp = hl_utils.shexec("wget --timeout=3 -O- --quiet 'https://atlantishq.de/ciplog/"+socket.gethostname()+"&active&"+str(datetime.now())+"'") except: tmp = "Service Unreachable" - with open(hlpath("cip_logins.log"),'w') as f: + with open(hl_utils.hlpath("cip_logins.log"),'w') as f: f.write(tmp) if __name__ == '__main__': diff --git a/herbstluftwm/password.cip b/herbstluftwm/password.cip new file mode 100644 index 0000000..d479bfe --- /dev/null +++ b/herbstluftwm/password.cip @@ -0,0 +1 @@ +huehuehuemordekaiser