mirror of
https://gitlab.sectorq.eu/jaydee/python.git
synced 2025-12-14 10:44:52 +01:00
lll
This commit is contained in:
79
handle_imported_video.py
Normal file
79
handle_imported_video.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import os
|
||||||
|
from posixpath import ismount
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import subprocess
|
||||||
|
import datetime
|
||||||
|
import shutil
|
||||||
|
import json
|
||||||
|
import getopt
|
||||||
|
|
||||||
|
_SOURCE_DIR = "/media/nas/nas-photo/imported/"
|
||||||
|
_DEV = "gopro9_1"
|
||||||
|
_DAY_DIR = "2022-08-04 - Bukovec-Jano"
|
||||||
|
_FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR
|
||||||
|
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], "hbl:o:s:t:", ["command=", "help", "output=", "backup"])
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
# print help information and exit:
|
||||||
|
print(str(err)) # will print something like "option -a not recognized"
|
||||||
|
#usage()
|
||||||
|
sys.exit(2)
|
||||||
|
output = None
|
||||||
|
# QJ : getopts
|
||||||
|
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "-h":
|
||||||
|
_ACTION = True
|
||||||
|
elif o in ("-b", "--backup"):
|
||||||
|
_BACKUP = True
|
||||||
|
elif o in ("-l", "--level"):
|
||||||
|
_LOG_LEVEL = a.upper()
|
||||||
|
elif o in ("-o", "--output"):
|
||||||
|
OUTPUT_FILE = a
|
||||||
|
elif o in ("-s", "--schema"):
|
||||||
|
SCHEMA = a
|
||||||
|
elif o in ("-t", "--tables"):
|
||||||
|
TABLES = a
|
||||||
|
|
||||||
|
else:
|
||||||
|
_WIZZARD = True
|
||||||
|
|
||||||
|
|
||||||
|
video_seq = {}
|
||||||
|
if os.path.exists(_FULL_PATH):
|
||||||
|
for filename in os.listdir(_FULL_PATH):
|
||||||
|
if filename.endswith(".MP4"):
|
||||||
|
part = "GH" + filename[2:4]
|
||||||
|
seq = filename[4:8]
|
||||||
|
if not seq in video_seq:
|
||||||
|
video_seq[seq] = []
|
||||||
|
video_seq[seq].append(part + seq + ".MP4")
|
||||||
|
print(filename)
|
||||||
|
print(seq)
|
||||||
|
print(part)
|
||||||
|
print(json.dumps(video_seq,indent=2))
|
||||||
|
|
||||||
|
for vid in video_seq:
|
||||||
|
export_name = "joined_" + vid + ".MP4"
|
||||||
|
parts = video_seq[vid]
|
||||||
|
parts.sort()
|
||||||
|
if len(parts) > 1:
|
||||||
|
print("This need to be joined!")
|
||||||
|
# for p in parts:
|
||||||
|
# join_string =
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
print(parts)
|
||||||
|
|
||||||
|
join_s = "|".join(parts)
|
||||||
|
print(join_s)
|
||||||
|
# print(type(parts))
|
||||||
|
#ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4
|
||||||
|
|
||||||
|
os.chdir(_FULL_PATH)
|
||||||
|
|
||||||
|
myCmd = 'ffmpeg -i concat:"' + join_s + '" ' + export_name
|
||||||
|
status, output = subprocess.getstatusoutput(myCmd)
|
||||||
|
print(output)
|
||||||
287
mqtt_srv.py
287
mqtt_srv.py
@@ -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))
|
||||||
@@ -122,15 +128,16 @@ def check_router():
|
|||||||
serv_d[rul[0]] = {"src_port":rul[1],"dest_ip":rul[2],"dest_port":rul[3],"prot":rul[4]}
|
serv_d[rul[0]] = {"src_port":rul[1],"dest_ip":rul[2],"dest_port":rul[3],"prot":rul[4]}
|
||||||
stats["serv_dest"] = rul[2]
|
stats["serv_dest"] = rul[2]
|
||||||
break
|
break
|
||||||
|
stats["status"] = "on"
|
||||||
#stats["serv_dest"] = json.dumps(serv_d)
|
#stats["serv_dest"] = json.dumps(serv_d)
|
||||||
#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 +161,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,8 +178,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))
|
||||||
@@ -211,7 +222,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]
|
||||||
@@ -315,7 +326,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
|
||||||
|
|
||||||
@@ -354,14 +365,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:
|
||||||
@@ -371,11 +382,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)
|
||||||
@@ -385,7 +396,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)
|
||||||
|
|
||||||
@@ -413,14 +424,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"])
|
||||||
@@ -440,7 +451,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"])
|
||||||
@@ -462,7 +473,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"])
|
||||||
@@ -479,8 +490,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)
|
||||||
@@ -498,14 +509,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"])
|
||||||
@@ -522,7 +533,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:
|
||||||
@@ -562,10 +573,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("<")
|
||||||
@@ -593,7 +604,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"]))
|
||||||
@@ -607,7 +618,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))
|
||||||
'''
|
'''
|
||||||
@@ -615,29 +626,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":
|
||||||
@@ -653,7 +664,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)
|
||||||
@@ -670,11 +681,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
|
||||||
@@ -682,8 +693,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)
|
||||||
@@ -692,13 +703,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"
|
||||||
@@ -710,13 +721,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'
|
||||||
@@ -733,7 +744,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])
|
||||||
@@ -751,21 +762,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())
|
||||||
@@ -787,29 +798,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)
|
||||||
@@ -822,12 +833,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")
|
||||||
@@ -837,7 +848,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])
|
||||||
@@ -917,9 +928,15 @@ def on_message(client, userdata, msg):
|
|||||||
print("not a json!")
|
print("not a json!")
|
||||||
|
|
||||||
client = mqtt.Client()
|
client = mqtt.Client()
|
||||||
|
<<<<<<< HEAD
|
||||||
client.username_pw_set("jaydee", password="jaydee1")
|
client.username_pw_set("jaydee", password="jaydee1")
|
||||||
client.will_set("home-assistant/" + host + "/hwstats", payload='{"status":"off"}', qos=0, retain=True)
|
client.will_set("home-assistant/" + host + "/hwstats", payload='{"status":"off"}', qos=0, retain=True)
|
||||||
|
|
||||||
|
=======
|
||||||
|
payload = '{"status":"off"}'
|
||||||
|
client.username_pw_set("jaydee", password="jaydee1")
|
||||||
|
client.will_set("home-assistant/" + host.lower() + "/hwstats", payload=payload, qos=0, retain=True)
|
||||||
|
>>>>>>> f8ca3c609387acf650821dc35de80b826724ee5f
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
writeLog(MQTT_HOST)
|
writeLog(MQTT_HOST)
|
||||||
@@ -971,10 +988,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")
|
||||||
@@ -991,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())
|
||||||
@@ -1004,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
|
||||||
@@ -1052,7 +1069,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('/'))
|
||||||
@@ -1063,7 +1080,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 +1139,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 +1153,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 +1166,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, "")
|
||||||
|
|||||||
62
pg_backup.py
Normal file
62
pg_backup.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import datetime
|
||||||
|
import getopt
|
||||||
|
import requests
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], "hbl:o:s:t:", ["command=", "help", "output=", "backup"])
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
# print help information and exit:
|
||||||
|
print(str(err)) # will print something like "option -a not recognized"
|
||||||
|
#usage()
|
||||||
|
sys.exit(2)
|
||||||
|
output = None
|
||||||
|
# QJ : getopts
|
||||||
|
|
||||||
|
OUTPUT_FILE = "pg_backup.sql"
|
||||||
|
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "-h":
|
||||||
|
_ACTION = True
|
||||||
|
elif o in ("-b", "--backup"):
|
||||||
|
_BACKUP = True
|
||||||
|
elif o in ("-l", "--level"):
|
||||||
|
_LOG_LEVEL = a.upper()
|
||||||
|
elif o in ("-o", "--output"):
|
||||||
|
OUTPUT_FILE = a
|
||||||
|
elif o in ("-s", "--schema"):
|
||||||
|
SCHEMA = a
|
||||||
|
elif o in ("-t", "--tables"):
|
||||||
|
TABLES = a
|
||||||
|
|
||||||
|
else:
|
||||||
|
_WIZZARD = True
|
||||||
|
|
||||||
|
LOG_FILE = "/tmp/pg_backup.log"
|
||||||
|
|
||||||
|
if _LOG_LEVEL == "DEBUG":
|
||||||
|
logging.basicConfig(filename=LOG_FILE, level=logging.DEBUG, format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
|
||||||
|
logging.debug('using debug loging')
|
||||||
|
elif _LOG_LEVEL == "ERROR":
|
||||||
|
logging.basicConfig(filename=LOG_FILE, level=logging.ERROR, format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
|
||||||
|
logging.info('using error loging')
|
||||||
|
elif _LOG_LEVEL == "SCAN":
|
||||||
|
logging.basicConfig(filename=LOG_FILE, level=logging.DEBUG, format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
|
||||||
|
logging.info('using error loging')
|
||||||
|
else:
|
||||||
|
logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
|
||||||
|
|
||||||
|
|
||||||
|
cmnd = "sudo -u postgres pg_dump {} {} > {}".format(TABLES, SCHEMA, OUTPUT_FILE)
|
||||||
|
print(cmnd)
|
||||||
|
#status, output = subprocess.getstatusoutput(cmnd)
|
||||||
|
|
||||||
|
|
||||||
@@ -14,9 +14,9 @@ import ctypes
|
|||||||
import getopt
|
import getopt
|
||||||
import requests
|
import requests
|
||||||
CHECK_MARK = "\033[0;32m\xE2\x9C\x94\033[0m"
|
CHECK_MARK = "\033[0;32m\xE2\x9C\x94\033[0m"
|
||||||
_MQTT_SETUP = _BACKUP = _APPLY = _WIFI_SETUP = False
|
_MQTT_SETUP = _BACKUP = _APPLY = _WIFI_SETUP = _UPGRADE_FW = False
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "wh:bm", ["command=", "help", "output=", "backup"])
|
opts, args = getopt.getopt(sys.argv[1:], "wh:bmu", ["command=", "help", "output=", "backup"])
|
||||||
except getopt.GetoptError as err:
|
except getopt.GetoptError as err:
|
||||||
# print help information and exit:
|
# print help information and exit:
|
||||||
print(str(err)) # will print something like "option -a not recognized"
|
print(str(err)) # will print something like "option -a not recognized"
|
||||||
@@ -36,6 +36,8 @@ for o, a in opts:
|
|||||||
_WIFI_SETUP = True
|
_WIFI_SETUP = True
|
||||||
elif o in ("-a", "--apply"):
|
elif o in ("-a", "--apply"):
|
||||||
_APPLY = True
|
_APPLY = True
|
||||||
|
elif o in ("-u", "--upgrade_fw"):
|
||||||
|
_UPGRADE_FW = True
|
||||||
else:
|
else:
|
||||||
_WIZZARD = True
|
_WIZZARD = True
|
||||||
|
|
||||||
@@ -90,7 +92,41 @@ def create_backup():
|
|||||||
#print(sys_ip + " : Not a listening")
|
#print(sys_ip + " : Not a listening")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def upgrade_fw():
|
||||||
|
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)
|
||||||
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
|
|
||||||
|
# print(output)
|
||||||
|
|
||||||
|
ips = output.splitlines()
|
||||||
|
for sys_ip in ips:
|
||||||
|
print("Thsis is ip : " + sys_ip)
|
||||||
|
cmnd = "nmap " + sys_ip + " -p80|grep \"80/tcp open http\""
|
||||||
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
|
# print("status of 80 : " + str(status))
|
||||||
|
if status == 0:
|
||||||
|
try:
|
||||||
|
# url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+5"
|
||||||
|
|
||||||
|
url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+1"
|
||||||
|
#print(url)
|
||||||
|
resp = requests.get(url)
|
||||||
|
json_str = resp.content.decode('utf-8')
|
||||||
|
#print(json_str)
|
||||||
|
tasm_data = json.loads(json_str)
|
||||||
|
#print(tasm_data)
|
||||||
|
print(tasm_data["StatusPRM"]["OtaUrl"])
|
||||||
|
|
||||||
|
|
||||||
|
except:
|
||||||
|
#print(sys_ip + " : Not a tasmota!")
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
#print(sys_ip + " : Not a listening")
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def wifi_setup():
|
def wifi_setup():
|
||||||
SSID1 = input(">> SID1 ? (default=jaydee) : ") or "jaydee"
|
SSID1 = input(">> SID1 ? (default=jaydee) : ") or "jaydee"
|
||||||
PASS1 = input(">> PASS1 ? (default=) : ") or ""
|
PASS1 = input(">> PASS1 ? (default=) : ") or ""
|
||||||
@@ -169,4 +205,8 @@ if _MQTT_SETUP:
|
|||||||
mqtt_setup()
|
mqtt_setup()
|
||||||
|
|
||||||
if _WIFI_SETUP:
|
if _WIFI_SETUP:
|
||||||
wifi_setup()
|
wifi_setup()
|
||||||
|
|
||||||
|
|
||||||
|
if _UPGRADE_FW:
|
||||||
|
upgrade_fw()
|
||||||
Reference in New Issue
Block a user