2023-12-28 04:27:25 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
p = os.path.join
|
|
|
|
pUp = os.path.dirname
|
|
|
|
s = False
|
|
|
|
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
|
|
|
s = os.path.realpath(sys.executable)
|
|
|
|
else:
|
|
|
|
s = os.path.realpath(__file__)
|
|
|
|
sp = pUp(s)
|
|
|
|
|
|
|
|
# script start
|
|
|
|
import toml
|
|
|
|
import subprocess
|
|
|
|
|
2024-02-02 03:21:04 +00:00
|
|
|
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
|
|
|
|
|
2023-12-28 04:27:25 +00:00
|
|
|
def addressStr(addr):
|
|
|
|
return addr[0] + ":" + str(addr[1])
|
|
|
|
|
|
|
|
def addressSslStr(addr):
|
|
|
|
return addr[0] + ":" + str(addr[1] + 1)
|
|
|
|
|
|
|
|
def perr(rtn,cmd = None,op = None):
|
|
|
|
if rtn == 0: return
|
|
|
|
if cmd == None: cmd = []
|
|
|
|
exc = subprocess.CalledProcessError(rtn,cmd,op)
|
|
|
|
raise exc
|
|
|
|
|
|
|
|
def pcallStr(*args,**kwargs):
|
|
|
|
proc = subprocess.Popen(*args,**kwargs, stdout=subprocess.PIPE)
|
|
|
|
response = proc.stdout.read().decode("utf-8").strip("\n")
|
|
|
|
rtn = proc.wait()
|
|
|
|
perr(rtn,args[0])
|
|
|
|
return response
|
|
|
|
|
|
|
|
def main():
|
|
|
|
print("* Parsing config ...")
|
|
|
|
configFiles = ["broadcast.toml"]
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
configFiles = sys.argv[1:]
|
|
|
|
|
|
|
|
length = len(configFiles)
|
|
|
|
index = 0
|
|
|
|
while index < length:
|
|
|
|
configFiles[index] = p(sp,"config",configFiles[index])
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
config = toml.load(configFiles)
|
|
|
|
for key in config["args"]:
|
|
|
|
os.environ["fstream_arg_" + key] = str(config["args"][key])
|
2024-01-23 23:10:06 +00:00
|
|
|
if not "values" in config: config["values"] = {}
|
|
|
|
if not "python" in config["values"]: config["values"]["python"] = sys.executable
|
2023-12-28 04:27:25 +00:00
|
|
|
|
2024-01-23 22:59:04 +00:00
|
|
|
for encoder in config["encoder"]:
|
|
|
|
for i in range(len(encoder)):
|
2024-01-23 23:10:06 +00:00
|
|
|
for key in config["values"]:
|
|
|
|
encoder[i] = encoder[i].replace("$val:" +key+ "$",str(config["values"][key]))
|
2024-01-23 22:59:04 +00:00
|
|
|
|
|
|
|
for key in os.environ:
|
|
|
|
encoder[i] = encoder[i].replace("$env:" +key+ "$",os.environ[key])
|
2023-12-28 04:27:25 +00:00
|
|
|
|
|
|
|
ssl = False
|
|
|
|
if "ssl" in config and "enabled" in config["ssl"] and config["ssl"]["enabled"] != False:
|
|
|
|
if "ignoreCert" in config["ssl"] and config["ssl"]["ignoreCert"] == True:
|
|
|
|
os.environ["fstream_ssl_ignoreCert"] = "1"
|
|
|
|
ssl = True
|
|
|
|
|
|
|
|
aes = False
|
|
|
|
if "aespass" in config:
|
|
|
|
if not "bufsize" in config["args"]:
|
|
|
|
print("aespass is set, but args.bufsize is not.")
|
|
|
|
sys.exit(1)
|
|
|
|
os.environ["fstream_aespass"] = config["aespass"]
|
|
|
|
os.environ["fstream_aesbuffer"] = str(config["args"]["bufsize"] - 16)
|
|
|
|
aes = True
|
|
|
|
|
|
|
|
address = config["address"].rsplit(":",1)
|
|
|
|
address[1] = int(address[1])
|
|
|
|
|
|
|
|
if ssl == True:
|
|
|
|
print("* Getting login-token ...")
|
|
|
|
os.environ["fstream_ssl"] = "1"
|
|
|
|
os.environ["fstream_arg_token"] = pcallStr([
|
|
|
|
sys.executable,
|
|
|
|
p(sp,"fstream.py"),
|
|
|
|
addressSslStr(address),
|
|
|
|
"token"
|
|
|
|
])
|
|
|
|
del os.environ["fstream_arg_user_password"]
|
|
|
|
del os.environ["fstream_ssl"]
|
|
|
|
|
2024-01-23 22:59:04 +00:00
|
|
|
cmds = []
|
|
|
|
for encoder in config["encoder"]: cmds.append(encoder)
|
2024-01-23 23:09:23 +00:00
|
|
|
if aes == True: cmds.append([sys.executable,p(sp,"util","fstream-util-pipe_to_aes.py")])
|
2024-01-23 22:59:04 +00:00
|
|
|
cmds.append([sys.executable,p(sp,"fstream.py"),addressStr(address),"broadcast"])
|
2023-12-28 04:27:25 +00:00
|
|
|
|
2024-01-23 22:59:04 +00:00
|
|
|
procs = []
|
|
|
|
procs.append(subprocess.Popen(cmds[0],stdout=subprocess.PIPE))
|
|
|
|
for i in range(1,len(cmds) - 1):
|
|
|
|
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
|
|
|
|
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
|
2023-12-28 04:27:25 +00:00
|
|
|
|
2024-02-02 03:21:04 +00:00
|
|
|
# Pwetty pwease add thew funcshun owo uwu xoxoxox
|
|
|
|
import time
|
|
|
|
running = True
|
|
|
|
while running:
|
|
|
|
for proc in procs:
|
|
|
|
if proc.poll() is not None:
|
|
|
|
eprint("Process died: " + str(proc.args))
|
|
|
|
running = False
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
eprint("Terminating process chain (" + str(len(procs)) + ")...")
|
|
|
|
|
|
|
|
for proc in procs:
|
|
|
|
eprint("Closing: " + str(proc.args))
|
|
|
|
try:
|
|
|
|
proc.terminate()
|
|
|
|
proc.wait()
|
|
|
|
except Exception as ex:
|
|
|
|
eprint("Error waiting for process!!! " + str(ex))
|
|
|
|
|
2023-12-28 04:27:25 +00:00
|
|
|
main()
|