This commit is contained in:
2025-02-24 01:06:18 +01:00
parent cb2ee57784
commit 7c748b1dff
2 changed files with 203 additions and 166 deletions

View File

@@ -17,7 +17,7 @@ import ctypes
import getopt
import random
import requests
import shutil
if os.path.exists("/etc/mqtt_srv/mqtt_srv.cfg"):
with open("/etc/mqtt_srv/mqtt_srv.cfg") as json_file:
@@ -28,7 +28,7 @@ else:
#import psutil
stats = {}
VERSION = "1.0.36"
VERSION = "1.0.37"
curos = platform.system()
host = platform.node().lower().replace(".home.lan","")
@@ -74,14 +74,19 @@ def uptime():
string += str(seconds)
return string;
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
ts2 = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
if curos == "Windows":
log_path = "c:\\Program Files\\jaydee\\jaydee.log"
else:
log_path = "/tmp/mqtt_srv.log"
if os.path.exists(log_path):
shutil.move(log_path, log_path + "." + ts2)
def writeLog(msg, svr="INFO"):
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if curos == "Windows":
log_path = "c:\\Program Files\\jaydee\\jaydee.log"
else:
log_path = "/tmp/mqtt_srv.log"
ts2 = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
f = open(log_path, "a")
f.write(ts + " | " + svr + " | " + str(msg) + "\n")
f.close()
@@ -654,8 +659,8 @@ def on_message(client, userdata, msg):
# os.startfile(sys.argv[0])
#sys.exit()
myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc'
print(myCmd)
writeLog(myCmd)
subprocess.Popen(myCmd.split())
if myObj["cmd"] == "getstats":
print("lalaa1")
@@ -667,19 +672,43 @@ 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)
print("lalaa2")
if myObj["cmd"] == "openrgb":
myCmd = 'powershell.exe -windowstyle hidden -command Stop-ScheduledTask -TaskName "jaydee\OpenRGB"'
writeLog(myCmd)
subprocess.Popen(myCmd.split())
time.sleep(2)
myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\OpenRGB"'
writeLog(myCmd)
subprocess.Popen(myCmd.split())
if myObj["cmd"] == "hyperion":
myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\hyperion"'
writeLog(myCmd)
subprocess.Popen(myCmd.split())
if myObj["cmd"] == "hyperiond":
myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\hyperiond"'
writeLog(myCmd)
subprocess.Popen(myCmd.split())
if myObj["cmd"] == "assist":
if myObj['target'] == "start":
myCmd =f"powershell c:\\Users\\jd\Documents\\volume.ps1 10"
else:
myCmd =f"powershell c:\\Users\\jd\\Documents\\volume.ps1 100"
output = subprocess.Popen(myCmd, shell=True)
if myObj["cmd"] == "display":
if curos == "Windows1":
if curos == "Windows":
# os.startfile(sys.argv[0])
#sys.exit()
#print("reconfigure")
myCmd = 'MonitorSwitcher.exe -load:' + myObj["target"] + '.xml'
#myCmd = 'MonitorSwitcher.exe -load:' + myObj["target"] + '.xml'
myCmd =f"powershell -w h -command \" Import-Module DisplayConfig ; Import-Clixml $home\monitors\{myObj['target']}.xml | Use-DisplayConfig -UpdateAdapterIds \""
writeLog(myCmd)
#writeLog(os.path.realpath(__file__))
print("lalaa2")
#subprocess.Popen(r'"{}"'.format(myCmd), shell=True)
print("lalaa3")
subprocess.Popen(myCmd.split(), shell=True,cwd=r'c:\Progra~1\jaydee')
#myCmd = f"MultiMonitorTool.exe /LoadConfig \"c:\\Program Files\\jaydee\\Monitors\\{myObj["target"]}.cfg\""
#writeLog(myCmd)
#print(myCmd)
output = subprocess.Popen(myCmd, shell=True)
#output = subprocess.Popen(myCmd.split())
writeLog(output)
else:
'''
myCmd = ""
@@ -706,7 +735,7 @@ def on_message(client, userdata, msg):
'''
myCmd = ""
writeLog(myObj["target"])
if curos == "Windows":
if curos == "Windows1":
myCmd = "DisplayFusionCommand.exe -monitorloadprofile {}".format(myObj["target"])
@@ -813,8 +842,9 @@ def on_message(client, userdata, msg):
if myObj["cmd"] == "suspend":
writeLog("suspending")
if curos == "Windows":
if host == "amd" or host == "amd1":
os.system("shutdown /s /t 1")
if host == "amd" or host == "amd1" or host == "morefine":
#os.system("shutdown /s /t 1")
os.system("shutdown /h")
else:
os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
#cmnd = "psshutdown -d -t 1"
@@ -936,16 +966,13 @@ if curos == "Windows":
client.loop_start()
NEXT_CHECK = 0
while True:
print("Version: {}".format(VERSION))
time.sleep(5)
try:
mtime = os.path.getmtime(sys.argv[0])
except OSError:
mtime = 0
print(mtime)
if NEXT_CHECK < int(time.time()):
NEXT_CHECK = int(time.time()) + 10
writeLog("Blalala : Next : " + str(NEXT_CHECK))
if curos == "Windows":
if checkIfProcessRunning("aida64.exe"):
aide_refs = {
@@ -961,9 +988,7 @@ if curos == "Windows":
}
#ks = ["TCPU", "TPCHDIO", "SMEMUTI", "SVIRTMEMUTI", "SCPUUTI", "FCPU", "TGPU1DIO", "SGPU1BIUTI"]
path = winreg.HKEY_CURRENT_USER
try:
key = winreg.OpenKeyEx(path, r"SOFTWARE\\FinalWire\\AIDA64\\SensorValues")
@@ -1010,6 +1035,28 @@ if curos == "Windows":
client.publish("sectorq/systems/" + host.lower() + "/stat", payload="on", qos=0, retain=True)
#print(json.dumps(stats))
#writeLog(json.dumps(stats))
writeLog(FILE_TIMESTAMP)
writeLog(mtime)
writeLog(sys.argv[0])
if FILE_TIMESTAMP != mtime:
writeLog("Script updated ! restarting...")
#os.execv(sys.executable, ['python'] + sys.argv)
#os.system("/share/ZFS530_DATA/.qpkg/QPython39/bin/python3 mqtt_srv.py")
if host.lower() == "morefine":
mycmd = 'powershell -w h -command Start-ScheduledTask -TaskName "jaydee\\restart_mqtt_srv"'
writeLog(mycmd)
status,output = subprocess.Popen(mycmd.split(),shell=True)
if host.lower() == "router" or host.lower() == "omv":
#sys.stdout.flush()
#os.execv(sys.argv, "")
print("argv was",sys.argv)
print("sys.executable was", sys.executable)
print("restart now")
os.execv(sys.executable, ['python3'] + sys.argv)
#os.startfile(sys.argv[0])
sys.exit()
else:
print("Linux")
client.loop_start()
@@ -1020,15 +1067,16 @@ else:
time.sleep(5)
try:
mtime = os.path.getmtime(sys.argv[0])
writeLog(sys.argv[0])
except OSError:
mtime = 0
#print(mtime)
if NEXT_CHECK < int(time.time()):
NEXT_CHECK = int(time.time()) + 20
writeLog("Blalala : Next : " + str(NEXT_CHECK))
#writeLog("Blalala : Next : " + str(NEXT_CHECK))
if host.lower() == "asus" or host.lower() == "morefine" or host.lower() == "ryzen" or host.lower() == "amd" or host.lower() == "rack":
writeLog("Blalala : AAA")
#writeLog("Blalala : AAA")
print(psutil.sensors_temperatures())
#print(psutil.sensors_fans())
sences = psutil.sensors_temperatures()
@@ -1163,7 +1211,8 @@ else:
payload[m] = 0
client.publish( "home-assistant/" + host + "/hwstats", payload=json.dumps(payload), qos=0, retain=True)
writeLog(FILE_TIMESTAMP)
writeLog(mtime)
if FILE_TIMESTAMP != mtime:
writeLog("Script updated ! restarting...")
#os.execv(sys.executable, ['python'] + sys.argv)