This commit is contained in:
2023-02-17 16:40:15 +01:00
parent 88f7ffe1ed
commit e0a46601b7

View File

@@ -20,51 +20,57 @@ import requests
#import psutil #import psutil
stats = {} stats = {}
VERSION = "1.0.23" VERSION = "1.0.23"
curos = platform.system() curos = platform.system()
host = platform.node().lower() host = platform.node().lower()
print(host) print(host)
if curos == "Windows": if curos == "Windows":
import winreg import winreg
def uptime(): def uptime():
try: try:
f = open( "/proc/uptime" ) f = open( "/proc/uptime" )
contents = f.read().split() contents = f.read().split()
f.close() f.close()
except: except:
return "Cannot open uptime file: /proc/uptime" return "Cannot open uptime file: /proc/uptime"
total_seconds = float(contents[0]) total_seconds = float(contents[0])
# Helper vars: # Helper vars:
MINUTE = 60 MINUTE = 60
HOUR = MINUTE * 60 HOUR = MINUTE * 60
DAY = HOUR * 24 DAY = HOUR * 24
# Get the days, hours, etc: # Get the days, hours, etc:
days = int( total_seconds / DAY ) days = int( total_seconds / DAY )
hours = int( ( total_seconds % DAY ) / HOUR ) hours = int( ( total_seconds % DAY ) / HOUR )
minutes = int( ( total_seconds % HOUR ) / MINUTE ) minutes = int( ( total_seconds % HOUR ) / MINUTE )
seconds = int( total_seconds % MINUTE ) seconds = int( total_seconds % MINUTE )
# Build up the pretty string (like this: "N days, N hours, N minutes, N seconds") # Build up the pretty string (like this: "N days, N hours, N minutes, N seconds")
string = "" string = ""
# if days > 0: # if days > 0:
# string += str(days) + " " + (days == 1 and "d" or "d" ) + ", " # string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
# if len(string) > 0 or hours > 0: # if len(string) > 0 or hours > 0:
# string += str(hours) + " " + (hours == 1 and "h" or "h" ) + ", " # string += str(hours) + " " + (hours == 1 and "h" or "h" ) + ", "
# if len(string) > 0 or minutes > 0: # if len(string) > 0 or minutes > 0:
# string += str(minutes) + " " + (minutes == 1 and "m" or "m" ) + ", " # string += str(minutes) + " " + (minutes == 1 and "m" or "m" ) + ", "
if days > 0: if days > 0:
string += str(days) + " " + (days == 1 and "d" or "d" ) + ", " string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
if len(string) > 0 or hours > 0: if len(string) > 0 or hours > 0:
string += str(hours) + ":" if hours < 10:
if len(string) > 0 or minutes > 0: hours = "0{}".format(hours)
string += str(minutes) + ":" string += str(hours) + ":"
string += str(seconds) if len(string) > 0 or minutes > 0:
if minutes < 10:
return string; minutes = "0{}".format(minutes)
string += str(minutes) + ":"
if seconds < 10:
seconds = "0{}".format(seconds)
string += str(seconds)
return string;
def writeLog(msg, svr="INFO"): def writeLog(msg, svr="INFO"):
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if curos == "Windows": if curos == "Windows":
@@ -73,14 +79,14 @@ def writeLog(msg, svr="INFO"):
log_path = "/tmp/mqtt_srv.log" log_path = "/tmp/mqtt_srv.log"
f = open(log_path, "a") f = open(log_path, "a")
f.write(ts + " | " + svr + " | " + str(msg) + "\n") f.write(ts + " | " + svr + " | " + str(msg) + "\n")
f.close() f.close()
def check_router(): def check_router():
stats["uptime"] = uptime() stats["uptime"] = uptime()
stats["version"] = VERSION stats["version"] = VERSION
cmnd = "crontab -l" cmnd = "crontab -l"
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
if "#Skynet_banmalware#" in output: if "#Skynet_banmalware#" in output:
stats["skynet"] = "on" stats["skynet"] = "on"
else: else:
@@ -89,8 +95,8 @@ def check_router():
stats["diversion"] = "on" stats["diversion"] = "on"
else: else:
stats["diversion"] = "off" stats["diversion"] = "off"
cmnd = "nvram get vpn_client1_state" cmnd = "nvram get vpn_client1_state"
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
writeLog("Openvpn1 Status : " + str(output)) writeLog("Openvpn1 Status : " + str(output))
@@ -127,11 +133,11 @@ def check_router():
#stats["serv_dest"] = json.dumps(serv_d) #stats["serv_dest"] = json.dumps(serv_d)
#out = subprocess.Popen(cmnd.split()) #out = subprocess.Popen(cmnd.split())
#status, output = subprocess.getstatusoutput(cmnd) #status, output = subprocess.getstatusoutput(cmnd)
''' '''
print("Getting fw info") print("Getting fw info")
cmnd = "/root/router_cmd.sh -t firewall -n TOSHIBA-WIFI -m get" cmnd = "/root/router_cmd.sh -t firewall -n TOSHIBA-WIFI -m get"
#out = subprocess.Popen(cmnd.split()) #out = subprocess.Popen(cmnd.split())
@@ -154,10 +160,10 @@ def check_router():
#client.publish("sectorq/systems/router/stats", payload=json.dumps(stats), qos=0, retain=True) #client.publish("sectorq/systems/router/stats", payload=json.dumps(stats), qos=0, retain=True)
#else: #else:
# client.publish("sectorq/systems/router/macfilter", payload=0, qos=0, retain=True) # client.publish("sectorq/systems/router/macfilter", payload=0, qos=0, retain=True)
if host != "router" and host != "nas": if host != "router" and host != "nas":
import psutil import psutil
processes = list(p.name() for p in psutil.process_iter()) processes = list(p.name() for p in psutil.process_iter())
# print(processes) # print(processes)
count = processes.count("mqtt_srv.exe") count = processes.count("mqtt_srv.exe")
@@ -171,12 +177,12 @@ else:
if int(count) >= 2: if int(count) >= 2:
writeLog("script exist") writeLog("script exist")
sys.exit() sys.exit()
# Stops duplicate instance from running # Stops duplicate instance from running
writeLog(count) writeLog(count)
writeLog("Starting : " + str(VERSION)) writeLog("Starting : " + str(VERSION))
@@ -215,7 +221,7 @@ for o, a in opts:
_MESSAGE = a _MESSAGE = a
elif o in ("-t", "--publish"): elif o in ("-t", "--publish"):
_TOPIC = a _TOPIC = a
elif o in ("-S", "--setvar"): elif o in ("-S", "--setvar"):
_SETVAR = True _SETVAR = True
_THR_NAME = sys.argv[2] _THR_NAME = sys.argv[2]
_THR_VAL = sys.argv[3] _THR_VAL = sys.argv[3]
@@ -319,7 +325,7 @@ IP = get_ip()
print("OS : " + curos) print("OS : " + curos)
writeLog("OS : " + curos) writeLog("OS : " + curos)
if curos != "Windows": if curos != "Windows":
import autorandr import autorandr
else: else:
import winreg import winreg
@@ -358,14 +364,14 @@ def on_connect(client, userdata, flags, rc):
client.publish("sectorq/systems/" + host.lower() + "/stat", payload="on", qos=0, retain=True) client.publish("sectorq/systems/" + host.lower() + "/stat", payload="on", qos=0, retain=True)
if host.lower() == "router": if host.lower() == "router":
check_router() check_router()
if host.lower() == "nas": if host.lower() == "nas":
print("Getting VM info") print("Getting VM info")
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all" cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all"
print(cmnd) print(cmnd)
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
l = 1 l = 1
lines = output.splitlines() lines = output.splitlines()
VMS = {} VMS = {}
for i in lines: for i in lines:
@@ -375,11 +381,11 @@ def on_connect(client, userdata, flags, rc):
line = re.split(r" {2,}", i) line = re.split(r" {2,}", i)
print(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip())) print(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip()))
VMS[str(line[1].strip())] = str(line[2].strip()) VMS[str(line[1].strip())] = str(line[2].strip())
for m in VMS: for m in VMS:
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m
#out = subprocess.Popen(cmnd.split()) #out = subprocess.Popen(cmnd.split())
print(cmnd) print(cmnd)
@@ -389,7 +395,7 @@ def on_connect(client, userdata, flags, rc):
client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True) client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True)
else: else:
client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True) client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True)
client.subscribe(topic) client.subscribe(topic)
@@ -417,14 +423,14 @@ def on_message(client, userdata, msg):
except: except:
print("Action not set") print("Action not set")
writeLog("Action not set", "WARNING") writeLog("Action not set", "WARNING")
try: try:
print(myObj["cmd"]) print(myObj["cmd"])
writeLog(myObj["cmd"]) writeLog(myObj["cmd"])
except: except:
print("Cmd not set") print("Cmd not set")
writeLog("Cmd not set", "WARNING") writeLog("Cmd not set", "WARNING")
try: try:
print(myObj["target"]) print(myObj["target"])
writeLog(myObj["target"]) writeLog(myObj["target"])
@@ -444,7 +450,7 @@ def on_message(client, userdata, msg):
except: except:
print("Command Not Set") print("Command Not Set")
writeLog("Command Not Set") writeLog("Command Not Set")
try: try:
print(myObj["cmd_line"]) print(myObj["cmd_line"])
writeLog(myObj["cmd_line"]) writeLog(myObj["cmd_line"])
@@ -466,7 +472,7 @@ def on_message(client, userdata, msg):
ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 16) ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 16)
print("Executed " + myObj["cmd_line"]) print("Executed " + myObj["cmd_line"])
writeLog("Executed " + myObj["cmd_line"]) writeLog("Executed " + myObj["cmd_line"])
if myObj["cmd"] == "nas_cmd": if myObj["cmd"] == "nas_cmd":
print("Executing NAS") print("Executing NAS")
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + str(myObj["target"]) cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + str(myObj["target"])
@@ -483,8 +489,8 @@ def on_message(client, userdata, msg):
cmd_type = "start" cmd_type = "start"
if myObj["command"] == "suspend": if myObj["command"] == "suspend":
cmd_type = "shutdown" cmd_type = "shutdown"
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh " + cmd_type + " " + str(myObj["target"]) cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh " + cmd_type + " " + str(myObj["target"])
subprocess.Popen(cmnd.split()) subprocess.Popen(cmnd.split())
print(cmnd) print(cmnd)
@@ -502,14 +508,14 @@ def on_message(client, userdata, msg):
except: except:
print("failed to execute!") print("failed to execute!")
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False) client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False)
if myObj["cmd"] == "distrib": if myObj["cmd"] == "distrib":
print("distributin313g") print("distributin313g")
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
#sys.exit() #sys.exit()
subprocess.Popen(['/bin/systemctl', 'restart', 'mqtt']) subprocess.Popen(['/bin/systemctl', 'restart', 'mqtt'])
if myObj["cmd"] == "uci": if myObj["cmd"] == "uci":
print("uci1") print("uci1")
print("Executing " + myObj["cmd_line"]) print("Executing " + myObj["cmd_line"])
@@ -526,7 +532,7 @@ def on_message(client, userdata, msg):
except: except:
print("failed to execute!") print("failed to execute!")
client.publish("sectorq/systems/router/stats", payload="failed", qos=0, retain=False) client.publish("sectorq/systems/router/stats", payload="failed", qos=0, retain=False)
elif myObj["cmd_line"] == "wireless0": elif myObj["cmd_line"] == "wireless0":
cmnd = "/root/router_cmd.sh -t wireless -v 0 -m set" cmnd = "/root/router_cmd.sh -t wireless -v 0 -m set"
try: try:
@@ -566,10 +572,10 @@ def on_message(client, userdata, msg):
cmnd = "service {}".format(myObj["target"]) cmnd = "service {}".format(myObj["target"])
print(cmnd) print(cmnd)
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
elif myObj["cmd_line"] == "serv_dest": elif myObj["cmd_line"] == "serv_dest":
writeLog("Payload111111 : " + myObj["target"].lower()) writeLog("Payload111111 : " + myObj["target"].lower())
cmnd = "nvram get vts_rulelist" cmnd = "nvram get vts_rulelist"
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
rule_data = output.split("<") rule_data = output.split("<")
@@ -597,7 +603,7 @@ def on_message(client, userdata, msg):
serv_d[r]["dest_ip"] = myObj["target"] serv_d[r]["dest_ip"] = myObj["target"]
except: except:
serv_d[r] = rules[r] serv_d[r] = rules[r]
lala = [] lala = []
for sr in serv_d: for sr in serv_d:
lala.append("{}>{}>{}>{}>{}>".format(sr,serv_d[sr]["src_port"],serv_d[sr]["dest_ip"],serv_d[sr]["dest_port"],serv_d[sr]["prot"])) lala.append("{}>{}>{}>{}>{}>".format(sr,serv_d[sr]["src_port"],serv_d[sr]["dest_ip"],serv_d[sr]["dest_port"],serv_d[sr]["prot"]))
@@ -611,7 +617,7 @@ def on_message(client, userdata, msg):
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
cmnd = "service restart_firewall" cmnd = "service restart_firewall"
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
writeLog("Payload111114") writeLog("Payload111114")
writeLog(output) writeLog(output)
print(json.dumps(serv_d)) print(json.dumps(serv_d))
''' '''
@@ -619,29 +625,29 @@ def on_message(client, userdata, msg):
dest_ip = "192.168.77.246" dest_ip = "192.168.77.246"
elif myObj["target"].lower() == "192.168.77.106": elif myObj["target"].lower() == "192.168.77.106":
dest_ip = "192.168.77.106" dest_ip = "192.168.77.106"
RULES = ["EMAIL993", "EMAIL995", "EMAIL143", "EMAIL25", "EMAIL993", "EMAIL465", "HTTPS", "HTTP"] RULES = ["EMAIL993", "EMAIL995", "EMAIL143", "EMAIL25", "EMAIL993", "EMAIL465", "HTTPS", "HTTP"]
for i in RULES: for i in RULES:
cmnd = "uci set firewall.{}.dest_ip={}".format(i,dest_ip) cmnd = "uci set firewall.{}.dest_ip={}".format(i,dest_ip)
writeLog(cmnd) writeLog(cmnd)
subprocess.Popen(cmnd.split()) subprocess.Popen(cmnd.split())
#cmnd = "uci set dhcp.@dnsmasq[0].address=/mqtt_broker/" + dest_ip #cmnd = "uci set dhcp.@dnsmasq[0].address=/mqtt_broker/" + dest_ip
#writeLog(cmnd) #writeLog(cmnd)
#subprocess.Popen(cmnd.split()) #subprocess.Popen(cmnd.split())
time.sleep(1) time.sleep(1)
cmnd = "uci commit" cmnd = "uci commit"
subprocess.Popen(cmnd.split()) subprocess.Popen(cmnd.split())
writeLog("Starting " + myObj["target"].lower()) writeLog("Starting " + myObj["target"].lower())
if myObj["target"].lower() == "192.168.77.246": if myObj["target"].lower() == "192.168.77.246":
dest_ip = "192.168.77.246" dest_ip = "192.168.77.246"
cmnd = "ssh root@192.168.77.246 'docker start mailu_resolver_1 mailu_redis_1 mailu_front_1 mailu_antispam_1 mailu_imap_1 mailu_admin_1 mailu_smtp_1 mailu_webmail_1 watchtower_watchtower_1 nginx-proxy-manager_db_1 nginx-proxy-manager_app_1 HomeAssistant webhub_client_1 dockermon_docker_mon_1 mosquitto_mosquitto_1 node-red_node-red_1 nextcloud_db_1 nextcloud_app_1'" cmnd = "ssh root@192.168.77.246 'docker start mailu_resolver_1 mailu_redis_1 mailu_front_1 mailu_antispam_1 mailu_imap_1 mailu_admin_1 mailu_smtp_1 mailu_webmail_1 watchtower_watchtower_1 nginx-proxy-manager_db_1 nginx-proxy-manager_app_1 HomeAssistant webhub_client_1 dockermon_docker_mon_1 mosquitto_mosquitto_1 node-red_node-red_1 nextcloud_db_1 nextcloud_app_1'"
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
elif myObj["target"].lower() == "192.168.77.106": elif myObj["target"].lower() == "192.168.77.106":
@@ -657,7 +663,7 @@ def on_message(client, userdata, msg):
MQTT_BROKER = dest_ip MQTT_BROKER = dest_ip
MQTT_USER = "jaydee" MQTT_USER = "jaydee"
MQTT_PASS = "jaydee1" MQTT_PASS = "jaydee1"
cmnd = "nmap -sP 192.168.77.*|grep \"Nmap scan report\"|egrep -o \"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\"" cmnd = "nmap -sP 192.168.77.*|grep \"Nmap scan report\"|egrep -o \"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\""
#print(cmnd) #print(cmnd)
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
@@ -674,11 +680,11 @@ def on_message(client, userdata, msg):
if status == 0: if status == 0:
try: try:
# url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+5" # url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+5"
url = "http://" + sys_ip + "/cm?cmnd=Backlog%20MqttHost%20" + MQTT_BROKER + "%3BMqttUser%20" + MQTT_USER + "%3BMqttPassword%20" + MQTT_PASS url = "http://" + sys_ip + "/cm?cmnd=Backlog%20MqttHost%20" + MQTT_BROKER + "%3BMqttUser%20" + MQTT_USER + "%3BMqttPassword%20" + MQTT_PASS
print(url) print(url)
requests.get(url) requests.get(url)
except: except:
#print(sys_ip + " : Not a tasmota!") #print(sys_ip + " : Not a tasmota!")
pass pass
@@ -686,8 +692,8 @@ def on_message(client, userdata, msg):
#print(sys_ip + " : Not a listening") #print(sys_ip + " : Not a listening")
pass pass
time.sleep(1) time.sleep(1)
cmnd = "sed -i 's/^MQTT_HOST = .*/MQTT_HOST = \"" + dest_ip + "\"/' /root/mqtt_srv.py" cmnd = "sed -i 's/^MQTT_HOST = .*/MQTT_HOST = \"" + dest_ip + "\"/' /root/mqtt_srv.py"
writeLog(cmnd) writeLog(cmnd)
@@ -696,13 +702,13 @@ def on_message(client, userdata, msg):
else: else:
pass pass
#cmnd = "/root/router_cmd.sh -t wireless -v 0" #cmnd = "/root/router_cmd.sh -t wireless -v 0"
print("Executed " + cmnd) print("Executed " + cmnd)
writeLog("Executed " + cmnd) writeLog("Executed " + cmnd)
''' '''
if myObj["cmd"] == "banip": if myObj["cmd"] == "banip":
if myObj["status"] == "ban": if myObj["status"] == "ban":
cmnd = "echo " + str(myObj["target"]) + " >> /etc/banip/banip.blacklist; /etc/init.d/banip refresh" cmnd = "echo " + str(myObj["target"]) + " >> /etc/banip/banip.blacklist; /etc/init.d/banip refresh"
@@ -714,13 +720,13 @@ def on_message(client, userdata, msg):
stats["banip"] = "paused" stats["banip"] = "paused"
writeLog(cmnd) writeLog(cmnd)
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
client.publish("sectorq/systems/router/stats", payload=json.dumps(stats), qos=0, retain=True) client.publish("sectorq/systems/router/stats", payload=json.dumps(stats), qos=0, retain=True)
if myObj["cmd"] == "vnc": if myObj["cmd"] == "vnc":
print(myObj["target"]) print(myObj["target"])
writeLog(myObj["target"]) writeLog(myObj["target"])
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
#sys.exit() #sys.exit()
myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc' myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc'
@@ -737,7 +743,7 @@ def on_message(client, userdata, msg):
client.publish("sectorq/monitor/" + host.lower(), payload="{\"mb_temp\":0,\"mem_usage\":0,\"cpu_temp\":0,\"cpu_usage\":0,\"gpu_temp\":0,\"gpu_usage\":0}", qos=0, retain=False) client.publish("sectorq/monitor/" + host.lower(), payload="{\"mb_temp\":0,\"mem_usage\":0,\"cpu_temp\":0,\"cpu_usage\":0,\"gpu_temp\":0,\"gpu_usage\":0}", qos=0, retain=False)
print("lalaa2") print("lalaa2")
if myObj["cmd"] == "display": if myObj["cmd"] == "display":
if curos == "Windows1": if curos == "Windows1":
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
@@ -755,21 +761,21 @@ def on_message(client, userdata, msg):
myCmd = "" myCmd = ""
if myObj["target"] == "mid": if myObj["target"] == "mid":
myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --off --output HDMI-1 --off --output eDP-1 --off" myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --off --output HDMI-1 --off --output eDP-1 --off"
elif myObj["target"] == "all": elif myObj["target"] == "all":
myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --auto --above HDMI-2 --mode 1920x1080 --output HDMI-1 --auto --left-of HDMI-2 --mode 1920x1080 --output eDP-1 --auto --right-of HDMI-2 --mode 1920x1080" myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --auto --above HDMI-2 --mode 1920x1080 --output HDMI-1 --auto --left-of HDMI-2 --mode 1920x1080 --output eDP-1 --auto --right-of HDMI-2 --mode 1920x1080"
elif myObj["target"] == "midleft": elif myObj["target"] == "midleft":
myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --off --output HDMI-1 --auto --left-of HDMI-2 --mode 1920x1080 --output eDP-1 --off" myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --off --output HDMI-1 --auto --left-of HDMI-2 --mode 1920x1080 --output eDP-1 --off"
elif myObj["target"] == "midtop": elif myObj["target"] == "midtop":
myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --auto --above HDMI-2 --mode 1920x1080 --output HDMI-1 --off --output eDP-1 --off" myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --auto --above HDMI-2 --mode 1920x1080 --output HDMI-1 --off --output eDP-1 --off"
elif myObj["target"] == "midleftbuild": elif myObj["target"] == "midleftbuild":
myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --off --output HDMI-1 --auto --left-of HDMI-2 --mode 1920x1080 --output eDP-1 --auto --right-of HDMI-2 --mode 1920x1080" myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --off --output HDMI-1 --auto --left-of HDMI-2 --mode 1920x1080 --output eDP-1 --auto --right-of HDMI-2 --mode 1920x1080"
elif myObj["target"] == "midbuild": elif myObj["target"] == "midbuild":
myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --off --output HDMI-1 --off --output eDP-1 --auto --right-of HDMI-2 --mode 1920x1080" myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --off --output HDMI-1 --off --output eDP-1 --auto --right-of HDMI-2 --mode 1920x1080"
elif myObj["target"] == "midlefttop": elif myObj["target"] == "midlefttop":
myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --auto --above HDMI-2 --mode 1920x1080 --output HDMI-1 --auto --left-of HDMI-2 --mode 1920x1080 --output eDP-1 --off" myCmd = "xrandr --output HDMI-2 --primary --auto --mode 1920x1080 --output DVI-I-2-1 --auto --above HDMI-2 --mode 1920x1080 --output HDMI-1 --auto --left-of HDMI-2 --mode 1920x1080 --output eDP-1 --off"
else: else:
pass pass
if myCmd != "": if myCmd != "":
print(myCmd) print(myCmd)
subprocess.Popen(myCmd.split()) subprocess.Popen(myCmd.split())
@@ -791,29 +797,29 @@ def on_message(client, userdata, msg):
mon2 = "HDMI-2" mon2 = "HDMI-2"
mon3 = "DVI-I-2-1" mon3 = "DVI-I-2-1"
mon4 = "eDP-1" mon4 = "eDP-1"
if myObj["target"] == "mid": if myObj["target"] == "mid":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon1 + " --off --output " + mon4 + " --off" myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon1 + " --off --output " + mon4 + " --off"
elif myObj["target"] == "left": elif myObj["target"] == "left":
myCmd = "xrandr --output " + mon1 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon2 + " --off --output " + mon4 + " --off" myCmd = "xrandr --output " + mon1 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon2 + " --off --output " + mon4 + " --off"
elif myObj["target"] == "all": elif myObj["target"] == "all":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080" myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080"
elif myObj["target"] == "midleft": elif myObj["target"] == "midleft":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --off" myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --off"
elif myObj["target"] == "midtop": elif myObj["target"] == "midtop":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --off --output " + mon4 + " --off" myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --off --output " + mon4 + " --off"
elif myObj["target"] == "midleftbuild": elif myObj["target"] == "midleftbuild":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080" myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080"
elif myObj["target"] == "midbuild": elif myObj["target"] == "midbuild":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080" myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080"
elif myObj["target"] == "midlefttop": elif myObj["target"] == "midlefttop":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --off" myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --off"
elif myObj["target"] == "build": elif myObj["target"] == "build":
myCmd = "xrandr --output " + mon2 + " --off --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --mode 1920x1080" myCmd = "xrandr --output " + mon2 + " --off --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --mode 1920x1080"
else: else:
pass pass
writeLog(myCmd) writeLog(myCmd)
if myCmd != "": if myCmd != "":
print(myCmd) print(myCmd)
@@ -826,12 +832,12 @@ def on_message(client, userdata, msg):
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
#sys.exit() #sys.exit()
#print("reconfigure") #print("reconfigure")
subprocess.Popen(['MultiMonitorTool.exe', '/SaveConfig', 'c:\\Program Files\\jaydee\\switcher.cfg']) subprocess.Popen(['MultiMonitorTool.exe', '/SaveConfig', 'c:\\Program Files\\jaydee\\switcher.cfg'])
myCmd = "powershell switcher.ps1 " + str(myObj["target"]) + " " + str(myObj["status"]) myCmd = "powershell switcher.ps1 " + str(myObj["target"]) + " " + str(myObj["status"])
writeLog(myCmd) writeLog(myCmd)
subprocess.Popen(myCmd.split()) subprocess.Popen(myCmd.split())
time.sleep(1) time.sleep(1)
subprocess.Popen(['MultiMonitorTool.exe', '/LoadConfig', 'c:\\Program Files\\jaydee\\switcher.cfg']) subprocess.Popen(['MultiMonitorTool.exe', '/LoadConfig', 'c:\\Program Files\\jaydee\\switcher.cfg'])
client.publish("sectorq/feedback", payload='{"action":"resp", "source":"ASUS", "dev":{"display' + str(myObj["target"]) + '":'+ str(myObj["status"]) +'} }' , qos=0, retain=False) client.publish("sectorq/feedback", payload='{"action":"resp", "source":"ASUS", "dev":{"display' + str(myObj["target"]) + '":'+ str(myObj["status"]) +'} }' , qos=0, retain=False)
if myObj["cmd"] == "displ": if myObj["cmd"] == "displ":
print("Display") print("Display")
@@ -841,7 +847,7 @@ def on_message(client, userdata, msg):
if myObj["cmd"] == "xrandr": if myObj["cmd"] == "xrandr":
if curos == "Windows": if curos == "Windows":
subprocess.Popen(['MultiMonitorTool.exe', '/LoadConfig', 'c:\\Program Files\\jaydee\\all_on.cfg']) subprocess.Popen(['MultiMonitorTool.exe', '/LoadConfig', 'c:\\Program Files\\jaydee\\all_on.cfg'])
else: else:
print("Display") print("Display")
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
@@ -983,10 +989,10 @@ if curos == "Windows":
'TMOBO':'MB_TEMP' 'TMOBO':'MB_TEMP'
} }
#ks = ["TCPU", "TPCHDIO", "SMEMUTI", "SVIRTMEMUTI", "SCPUUTI", "FCPU", "TGPU1DIO", "SGPU1BIUTI"] #ks = ["TCPU", "TPCHDIO", "SMEMUTI", "SVIRTMEMUTI", "SCPUUTI", "FCPU", "TGPU1DIO", "SGPU1BIUTI"]
path = winreg.HKEY_CURRENT_USER path = winreg.HKEY_CURRENT_USER
try: try:
key = winreg.OpenKeyEx(path, r"SOFTWARE\\FinalWire\\AIDA64\\SensorValues") key = winreg.OpenKeyEx(path, r"SOFTWARE\\FinalWire\\AIDA64\\SensorValues")
@@ -1002,8 +1008,8 @@ if curos == "Windows":
except: except:
print("aida initializing...") print("aida initializing...")
results = {"status":"init"} results = {"status":"init"}
else: else:
print("CPU Cnt : {}".format(psutil.cpu_count())) print("CPU Cnt : {}".format(psutil.cpu_count()))
print(psutil.virtual_memory()) print(psutil.virtual_memory())
@@ -1015,7 +1021,7 @@ if curos == "Windows":
print(swap_data) print(swap_data)
print("MEM : {}".format(mem_data.percent)) print("MEM : {}".format(mem_data.percent))
print(psutil.getloadavg()) print(psutil.getloadavg())
try: try:
print(psutil.sensors_temperatures()) print(psutil.sensors_temperatures())
except: except:
pass pass
@@ -1060,7 +1066,7 @@ else:
#cpu_usage = psutil.cpu_percent(interval=1) #cpu_usage = psutil.cpu_percent(interval=1)
load1, load5, load15 = psutil.getloadavg() load1, load5, load15 = psutil.getloadavg()
cpu_usage = round((load1/os.cpu_count()) * 100, 1) cpu_usage = round((load1/os.cpu_count()) * 100, 1)
print(mem_data) print(mem_data)
print(mem_data.percent) print(mem_data.percent)
print(psutil.disk_usage('/')) print(psutil.disk_usage('/'))
@@ -1071,7 +1077,7 @@ else:
#print(output) #print(output)
#print(type(output)) #print(type(output))
#jn1 = json.loads(output) #jn1 = json.loads(output)
#print(str(jn1["coretemp-isa-0000"]["Package id 0"]["temp1_input"])) #print(str(jn1["coretemp-isa-0000"]["Package id 0"]["temp1_input"]))
#print(str(jn1["asus-isa-0000"]["cpu_fan"]["fan1_input"])) #print(str(jn1["asus-isa-0000"]["cpu_fan"]["fan1_input"]))
#client.publish("sectorq/monitor/" + host.lower(), payload="{\"mb_temp\":0,\"mem_usage\":0,\"cpu_temp\":0,\"cpu_usage\":0,\"gpu_temp\":0,\"gpu_usage\":0}", qos=0, retain=False) #client.publish("sectorq/monitor/" + host.lower(), payload="{\"mb_temp\":0,\"mem_usage\":0,\"cpu_temp\":0,\"cpu_usage\":0,\"gpu_temp\":0,\"gpu_usage\":0}", qos=0, retain=False)
@@ -1122,11 +1128,11 @@ else:
check_router() check_router()
elif host.lower() == "nas": elif host.lower() == "nas":
print("Getting VM info") print("Getting VM info")
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all" cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all"
writeLog(cmnd) writeLog(cmnd)
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
l = 1 l = 1
lines = output.splitlines() lines = output.splitlines()
VMS = {} VMS = {}
for i in lines: for i in lines:
@@ -1136,11 +1142,11 @@ else:
line = re.split(r" {2,}", i) line = re.split(r" {2,}", i)
print(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip())) print(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip()))
VMS[str(line[1].strip())] = str(line[2].strip()) VMS[str(line[1].strip())] = str(line[2].strip())
for m in VMS: for m in VMS:
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m
#out = subprocess.Popen(cmnd.split()) #out = subprocess.Popen(cmnd.split())
writeLog(cmnd) writeLog(cmnd)
@@ -1149,17 +1155,17 @@ else:
if output.strip() == "running": if output.strip() == "running":
client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True) client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True)
else: else:
client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True) client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True)
if FILE_TIMESTAMP != mtime: if FILE_TIMESTAMP != mtime:
writeLog("Script updated ! restarting...") writeLog("Script updated ! restarting...")
#os.execv(sys.executable, ['python'] + sys.argv) #os.execv(sys.executable, ['python'] + sys.argv)
#os.system("/share/ZFS530_DATA/.qpkg/QPython39/bin/python3 mqtt_srv.py") #os.system("/share/ZFS530_DATA/.qpkg/QPython39/bin/python3 mqtt_srv.py")
if host.lower() == "nas": if host.lower() == "nas":
sys.stdout.flush() sys.stdout.flush()
os.execv("/share/ZFS530_DATA/.qpkg/QPython39/bin/python3", sys.argv) os.execv("/share/ZFS530_DATA/.qpkg/QPython39/bin/python3", sys.argv)
if host.lower() == "router" or host.lower() == "omv": if host.lower() == "router" or host.lower() == "omv":
#sys.stdout.flush() #sys.stdout.flush()
#os.execv(sys.argv, "") #os.execv(sys.argv, "")