diff --git a/handle_imported_video.py b/handle_imported_video.py new file mode 100644 index 0000000..dc78bb2 --- /dev/null +++ b/handle_imported_video.py @@ -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) \ No newline at end of file diff --git a/mqtt_srv.py b/mqtt_srv.py index 5f95a9c..602f5aa 100644 --- a/mqtt_srv.py +++ b/mqtt_srv.py @@ -20,51 +20,57 @@ import requests #import psutil stats = {} VERSION = "1.0.23" -curos = platform.system() +curos = platform.system() host = platform.node().lower() print(host) if curos == "Windows": import winreg def uptime(): - - try: - f = open( "/proc/uptime" ) - contents = f.read().split() - f.close() - except: + + try: + f = open( "/proc/uptime" ) + contents = f.read().split() + f.close() + except: return "Cannot open uptime file: /proc/uptime" - - total_seconds = float(contents[0]) - - # Helper vars: - MINUTE = 60 - HOUR = MINUTE * 60 - DAY = HOUR * 24 - - # Get the days, hours, etc: - days = int( total_seconds / DAY ) - hours = int( ( total_seconds % DAY ) / HOUR ) - minutes = int( ( total_seconds % HOUR ) / MINUTE ) - seconds = int( total_seconds % MINUTE ) - + + total_seconds = float(contents[0]) + + # Helper vars: + MINUTE = 60 + HOUR = MINUTE * 60 + DAY = HOUR * 24 + + # Get the days, hours, etc: + days = int( total_seconds / DAY ) + hours = int( ( total_seconds % DAY ) / HOUR ) + minutes = int( ( total_seconds % HOUR ) / MINUTE ) + seconds = int( total_seconds % MINUTE ) + # Build up the pretty string (like this: "N days, N hours, N minutes, N seconds") - string = "" + string = "" # if days > 0: # string += str(days) + " " + (days == 1 and "d" or "d" ) + ", " # if len(string) > 0 or hours > 0: # string += str(hours) + " " + (hours == 1 and "h" or "h" ) + ", " # if len(string) > 0 or minutes > 0: # string += str(minutes) + " " + (minutes == 1 and "m" or "m" ) + ", " - if days > 0: - string += str(days) + " " + (days == 1 and "d" or "d" ) + ", " - if len(string) > 0 or hours > 0: - string += str(hours) + ":" - if len(string) > 0 or minutes > 0: - string += str(minutes) + ":" - string += str(seconds) - - return string; - + if days > 0: + string += str(days) + " " + (days == 1 and "d" or "d" ) + ", " + if len(string) > 0 or hours > 0: + if hours < 10: + hours = "0{}".format(hours) + string += str(hours) + ":" + if len(string) > 0 or minutes > 0: + if minutes < 10: + minutes = "0{}".format(minutes) + string += str(minutes) + ":" + + if seconds < 10: + seconds = "0{}".format(seconds) + string += str(seconds) + return string; + def writeLog(msg, svr="INFO"): ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") if curos == "Windows": @@ -73,14 +79,14 @@ def writeLog(msg, svr="INFO"): log_path = "/tmp/mqtt_srv.log" f = open(log_path, "a") f.write(ts + " | " + svr + " | " + str(msg) + "\n") - f.close() + f.close() def check_router(): stats["uptime"] = uptime() stats["version"] = VERSION cmnd = "crontab -l" status, output = subprocess.getstatusoutput(cmnd) - + if "#Skynet_banmalware#" in output: stats["skynet"] = "on" else: @@ -89,8 +95,8 @@ def check_router(): stats["diversion"] = "on" else: stats["diversion"] = "off" - - + + cmnd = "nvram get vpn_client1_state" status, output = subprocess.getstatusoutput(cmnd) 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]} stats["serv_dest"] = rul[2] break + stats["status"] = "on" #stats["serv_dest"] = json.dumps(serv_d) #stats["serv_dest"] = json.dumps(serv_d) #out = subprocess.Popen(cmnd.split()) #status, output = subprocess.getstatusoutput(cmnd) - - + + ''' - - + + print("Getting fw info") cmnd = "/root/router_cmd.sh -t firewall -n TOSHIBA-WIFI -m get" #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) #else: # client.publish("sectorq/systems/router/macfilter", payload=0, qos=0, retain=True) - + if host != "router" and host != "nas": import psutil - + processes = list(p.name() for p in psutil.process_iter()) # print(processes) count = processes.count("mqtt_srv.exe") @@ -171,8 +178,12 @@ else: if int(count) >= 2: writeLog("script exist") sys.exit() + + + + # Stops duplicate instance from running - + writeLog(count) writeLog("Starting : " + str(VERSION)) @@ -211,7 +222,7 @@ for o, a in opts: _MESSAGE = a elif o in ("-t", "--publish"): _TOPIC = a - elif o in ("-S", "--setvar"): + elif o in ("-S", "--setvar"): _SETVAR = True _THR_NAME = sys.argv[2] _THR_VAL = sys.argv[3] @@ -315,7 +326,7 @@ IP = get_ip() print("OS : " + curos) writeLog("OS : " + curos) if curos != "Windows": - import autorandr + import autorandr else: 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) if host.lower() == "router": check_router() - + if host.lower() == "nas": print("Getting VM info") - + cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all" print(cmnd) status, output = subprocess.getstatusoutput(cmnd) - l = 1 + l = 1 lines = output.splitlines() VMS = {} for i in lines: @@ -371,11 +382,11 @@ def on_connect(client, userdata, flags, rc): line = re.split(r" {2,}", i) print(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip())) VMS[str(line[1].strip())] = str(line[2].strip()) - - - + + + for m in VMS: - + cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m #out = subprocess.Popen(cmnd.split()) 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) else: client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True) - + client.subscribe(topic) @@ -413,14 +424,14 @@ def on_message(client, userdata, msg): except: print("Action not set") writeLog("Action not set", "WARNING") - + try: print(myObj["cmd"]) writeLog(myObj["cmd"]) except: print("Cmd not set") writeLog("Cmd not set", "WARNING") - + try: print(myObj["target"]) writeLog(myObj["target"]) @@ -440,7 +451,7 @@ def on_message(client, userdata, msg): except: print("Command Not Set") writeLog("Command Not Set") - + try: print(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) print("Executed " + myObj["cmd_line"]) writeLog("Executed " + myObj["cmd_line"]) - + if myObj["cmd"] == "nas_cmd": print("Executing NAS") 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" if myObj["command"] == "suspend": cmd_type = "shutdown" - - + + cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh " + cmd_type + " " + str(myObj["target"]) subprocess.Popen(cmnd.split()) print(cmnd) @@ -498,14 +509,14 @@ def on_message(client, userdata, msg): except: print("failed to execute!") client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False) - - + + if myObj["cmd"] == "distrib": print("distributin313g") # os.startfile(sys.argv[0]) #sys.exit() subprocess.Popen(['/bin/systemctl', 'restart', 'mqtt']) - + if myObj["cmd"] == "uci": print("uci1") print("Executing " + myObj["cmd_line"]) @@ -522,7 +533,7 @@ def on_message(client, userdata, msg): except: print("failed to execute!") client.publish("sectorq/systems/router/stats", payload="failed", qos=0, retain=False) - + elif myObj["cmd_line"] == "wireless0": cmnd = "/root/router_cmd.sh -t wireless -v 0 -m set" try: @@ -562,10 +573,10 @@ def on_message(client, userdata, msg): cmnd = "service {}".format(myObj["target"]) print(cmnd) status, output = subprocess.getstatusoutput(cmnd) - + elif myObj["cmd_line"] == "serv_dest": writeLog("Payload111111 : " + myObj["target"].lower()) - + cmnd = "nvram get vts_rulelist" status, output = subprocess.getstatusoutput(cmnd) rule_data = output.split("<") @@ -593,7 +604,7 @@ def on_message(client, userdata, msg): serv_d[r]["dest_ip"] = myObj["target"] except: serv_d[r] = rules[r] - + lala = [] 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"])) @@ -607,7 +618,7 @@ def on_message(client, userdata, msg): status, output = subprocess.getstatusoutput(cmnd) cmnd = "service restart_firewall" status, output = subprocess.getstatusoutput(cmnd) - writeLog("Payload111114") + writeLog("Payload111114") writeLog(output) print(json.dumps(serv_d)) ''' @@ -615,29 +626,29 @@ def on_message(client, userdata, msg): dest_ip = "192.168.77.246" elif myObj["target"].lower() == "192.168.77.106": dest_ip = "192.168.77.106" - - - - + + + + RULES = ["EMAIL993", "EMAIL995", "EMAIL143", "EMAIL25", "EMAIL993", "EMAIL465", "HTTPS", "HTTP"] for i in RULES: cmnd = "uci set firewall.{}.dest_ip={}".format(i,dest_ip) writeLog(cmnd) subprocess.Popen(cmnd.split()) - + #cmnd = "uci set dhcp.@dnsmasq[0].address=/mqtt_broker/" + dest_ip #writeLog(cmnd) #subprocess.Popen(cmnd.split()) time.sleep(1) cmnd = "uci commit" - + subprocess.Popen(cmnd.split()) - + writeLog("Starting " + myObj["target"].lower()) if myObj["target"].lower() == "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'" status, output = subprocess.getstatusoutput(cmnd) elif myObj["target"].lower() == "192.168.77.106": @@ -653,7 +664,7 @@ def on_message(client, userdata, msg): MQTT_BROKER = dest_ip MQTT_USER = "jaydee" 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}\"" #print(cmnd) status, output = subprocess.getstatusoutput(cmnd) @@ -670,11 +681,11 @@ def on_message(client, userdata, msg): if status == 0: try: # 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 print(url) requests.get(url) - + except: #print(sys_ip + " : Not a tasmota!") pass @@ -682,8 +693,8 @@ def on_message(client, userdata, msg): #print(sys_ip + " : Not a listening") pass - - + + time.sleep(1) cmnd = "sed -i 's/^MQTT_HOST = .*/MQTT_HOST = \"" + dest_ip + "\"/' /root/mqtt_srv.py" writeLog(cmnd) @@ -692,13 +703,13 @@ def on_message(client, userdata, msg): else: pass #cmnd = "/root/router_cmd.sh -t wireless -v 0" - - + + print("Executed " + cmnd) writeLog("Executed " + cmnd) ''' - - + + if myObj["cmd"] == "banip": if myObj["status"] == "ban": 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" writeLog(cmnd) status, output = subprocess.getstatusoutput(cmnd) - + client.publish("sectorq/systems/router/stats", payload=json.dumps(stats), qos=0, retain=True) - + if myObj["cmd"] == "vnc": print(myObj["target"]) writeLog(myObj["target"]) - + # os.startfile(sys.argv[0]) #sys.exit() 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) print("lalaa2") - + if myObj["cmd"] == "display": if curos == "Windows1": # os.startfile(sys.argv[0]) @@ -751,21 +762,21 @@ def on_message(client, userdata, msg): myCmd = "" 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" - 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" - 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" - 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" - 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" - elif myObj["target"] == "midbuild": + 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" + 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" - 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" else: - pass - + pass + if myCmd != "": print(myCmd) subprocess.Popen(myCmd.split()) @@ -787,29 +798,29 @@ def on_message(client, userdata, msg): mon2 = "HDMI-2" mon3 = "DVI-I-2-1" mon4 = "eDP-1" - + if myObj["target"] == "mid": myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon1 + " --off --output " + mon4 + " --off" - elif myObj["target"] == "left": - myCmd = "xrandr --output " + mon1 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon2 + " --off --output " + mon4 + " --off" - - elif myObj["target"] == "all": + elif myObj["target"] == "left": + myCmd = "xrandr --output " + mon1 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon2 + " --off --output " + mon4 + " --off" + + 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" - 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" - 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" - 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" - elif myObj["target"] == "midbuild": + 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" + 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" - 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" - elif myObj["target"] == "build": + elif myObj["target"] == "build": myCmd = "xrandr --output " + mon2 + " --off --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --mode 1920x1080" else: - pass - + pass + writeLog(myCmd) if myCmd != "": print(myCmd) @@ -822,12 +833,12 @@ def on_message(client, userdata, msg): # os.startfile(sys.argv[0]) #sys.exit() #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"]) writeLog(myCmd) subprocess.Popen(myCmd.split()) 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) if myObj["cmd"] == "displ": print("Display") @@ -837,7 +848,7 @@ def on_message(client, userdata, msg): if myObj["cmd"] == "xrandr": 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: print("Display") # os.startfile(sys.argv[0]) @@ -917,9 +928,15 @@ def on_message(client, userdata, msg): print("not a json!") client = mqtt.Client() +<<<<<<< HEAD client.username_pw_set("jaydee", password="jaydee1") 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_message = on_message writeLog(MQTT_HOST) @@ -971,10 +988,10 @@ if curos == "Windows": 'TMOBO':'MB_TEMP' } #ks = ["TCPU", "TPCHDIO", "SMEMUTI", "SVIRTMEMUTI", "SCPUUTI", "FCPU", "TGPU1DIO", "SGPU1BIUTI"] - - - - + + + + path = winreg.HKEY_CURRENT_USER try: key = winreg.OpenKeyEx(path, r"SOFTWARE\\FinalWire\\AIDA64\\SensorValues") @@ -991,8 +1008,8 @@ if curos == "Windows": except: print("aida initializing...") results = {"status":"init"} - - + + else: print("CPU Cnt : {}".format(psutil.cpu_count())) print(psutil.virtual_memory()) @@ -1004,7 +1021,7 @@ if curos == "Windows": print(swap_data) print("MEM : {}".format(mem_data.percent)) print(psutil.getloadavg()) - try: + try: print(psutil.sensors_temperatures()) except: pass @@ -1052,7 +1069,7 @@ else: #cpu_usage = psutil.cpu_percent(interval=1) load1, load5, load15 = psutil.getloadavg() cpu_usage = round((load1/os.cpu_count()) * 100, 1) - + print(mem_data) print(mem_data.percent) print(psutil.disk_usage('/')) @@ -1063,7 +1080,7 @@ else: #print(output) #print(type(output)) #jn1 = json.loads(output) - + #print(str(jn1["coretemp-isa-0000"]["Package id 0"]["temp1_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) @@ -1122,11 +1139,11 @@ else: check_router() elif host.lower() == "nas": print("Getting VM info") - + cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all" writeLog(cmnd) status, output = subprocess.getstatusoutput(cmnd) - l = 1 + l = 1 lines = output.splitlines() VMS = {} for i in lines: @@ -1136,11 +1153,11 @@ else: line = re.split(r" {2,}", i) print(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip())) VMS[str(line[1].strip())] = str(line[2].strip()) - - - + + + for m in VMS: - + cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m #out = subprocess.Popen(cmnd.split()) writeLog(cmnd) @@ -1149,17 +1166,17 @@ else: if output.strip() == "running": client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True) 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: 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() == "nas": 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": #sys.stdout.flush() #os.execv(sys.argv, "") diff --git a/pg_backup.py b/pg_backup.py new file mode 100644 index 0000000..ed2e6f0 --- /dev/null +++ b/pg_backup.py @@ -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) + + diff --git a/scan_tasmotas.py b/scan_tasmotas.py index 50e024f..8a230dd 100644 --- a/scan_tasmotas.py +++ b/scan_tasmotas.py @@ -14,9 +14,9 @@ import ctypes import getopt import requests 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: - 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: # print help information and exit: print(str(err)) # will print something like "option -a not recognized" @@ -36,6 +36,8 @@ for o, a in opts: _WIFI_SETUP = True elif o in ("-a", "--apply"): _APPLY = True + elif o in ("-u", "--upgrade_fw"): + _UPGRADE_FW = True else: _WIZZARD = True @@ -90,7 +92,41 @@ def create_backup(): #print(sys_ip + " : Not a listening") 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(): SSID1 = input(">> SID1 ? (default=jaydee) : ") or "jaydee" PASS1 = input(">> PASS1 ? (default=) : ") or "" @@ -169,4 +205,8 @@ if _MQTT_SETUP: mqtt_setup() if _WIFI_SETUP: - wifi_setup() \ No newline at end of file + wifi_setup() + + +if _UPGRADE_FW: + upgrade_fw() \ No newline at end of file