split up files, add release script
parent
45e1204397
commit
0cf55aef93
@ -0,0 +1,80 @@
|
|||||||
|
from util import find_data_file
|
||||||
|
from util import setup_child
|
||||||
|
from util import fprint
|
||||||
|
from util import run_ps
|
||||||
|
from util import win32
|
||||||
|
import util
|
||||||
|
import time
|
||||||
|
import csv
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def process(data):
|
||||||
|
setup_child()
|
||||||
|
fprint("netstat processing")
|
||||||
|
if win32:
|
||||||
|
#output = data.stdout
|
||||||
|
#print(output)
|
||||||
|
output = data.stdout.decode().split('\r\n') # split stdout into lines
|
||||||
|
#print(output)
|
||||||
|
if output[0].find("The requested operation requires elevation.") >= 0:
|
||||||
|
#print("test3")
|
||||||
|
raise PermissionError("Unable to acquire netstat data without admin!")
|
||||||
|
#print("test2")
|
||||||
|
output2 = list()
|
||||||
|
output2.append([util.sysid, util.userid, util.sysdom, util.time()]) # add metadata
|
||||||
|
#print(output2)
|
||||||
|
procname = ""
|
||||||
|
"""for x in range(4, len(output)):
|
||||||
|
tmp = output[x].split(" ")
|
||||||
|
print(tmp)
|
||||||
|
tmp = [i for i in output[x] if i]
|
||||||
|
print(tmp)
|
||||||
|
print(len(tmp))
|
||||||
|
if len(len(tmp) == 1):
|
||||||
|
procname = tmp[0]
|
||||||
|
print(x)
|
||||||
|
else:
|
||||||
|
print(x)
|
||||||
|
output2[x] = list()
|
||||||
|
output2[x].append(procname)
|
||||||
|
output2[x].append(output[x].split(" "))
|
||||||
|
output2[x] = [i for i in output2[x] if i]
|
||||||
|
output2 = [i for i in output2 if i]
|
||||||
|
print(output2)"""
|
||||||
|
x = len(output) - 1 # start at the end because filename comes after connection
|
||||||
|
procname = "Unknown" # if the very last connection happens to have no file (yes, it's possible), we can say unknown
|
||||||
|
while x > 3:
|
||||||
|
string = output[x]
|
||||||
|
#print("LINE: ", string)
|
||||||
|
string_split = string.split(" ")
|
||||||
|
string_split = [i for i in string_split if i]
|
||||||
|
if string.find("Can not obtain ownership information") >= 0: # Higher privilige than us, must be system
|
||||||
|
procname = "Windows System"
|
||||||
|
elif string.find("]") >= 0 and string.find("[") == 1: # generic [file.exe]
|
||||||
|
procname = string[2:-1]
|
||||||
|
elif len(string_split) == 5: # actual netstat line
|
||||||
|
tmp = [procname,] # add executable name first
|
||||||
|
tmp.extend(string.split(" "))
|
||||||
|
tmp = [i for i in tmp if i]
|
||||||
|
#print(tmp)
|
||||||
|
output2.append(tmp)
|
||||||
|
#else: # In case of an extra line above file, or an empty line, ignore it
|
||||||
|
#print("Garbage data", string)
|
||||||
|
x = x - 1
|
||||||
|
#output2 = output2[2:]
|
||||||
|
#print(output2)
|
||||||
|
with open(find_data_file(util.datafile), "w", newline="") as f:
|
||||||
|
writer = csv.writer(f)
|
||||||
|
writer.writerows(output2)
|
||||||
|
fprint("done creating csv")
|
||||||
|
|
||||||
|
def start():
|
||||||
|
fprint("netstat started")
|
||||||
|
setup_child()
|
||||||
|
|
||||||
|
if win32:
|
||||||
|
data = run_ps("netstat -n -o -b")
|
||||||
|
fprint("data acquired")
|
||||||
|
return data
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -xeuo pipefail
|
||||||
|
|
||||||
|
TOKEN=$(< token.txt)
|
||||||
|
git commit -a
|
||||||
|
|
||||||
|
COMMIT=$(git log | head -n 1 | cut -d' ' -f2)
|
||||||
|
echo $COMMIT
|
||||||
|
export PATH=$PATH:"C:\Program Files\7-Zip"
|
||||||
|
|
||||||
|
7z a -r release-$COMMIT.zip ./build/exe.win-amd64-3.10/*
|
||||||
|
|
||||||
|
DATA='{
|
||||||
|
"body": "Autogenerated release",
|
||||||
|
"draft": true,
|
||||||
|
"name": "Development release",
|
||||||
|
"prerelease": true,
|
||||||
|
"tag_name": "testing",
|
||||||
|
"target_commitish": "'$COMMIT'"
|
||||||
|
}'
|
||||||
|
OUT=$(curl -X 'POST' \
|
||||||
|
'https://git.deck.sh/api/v1/repos/Interfaz/ff/releases?token='$TOKEN'' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d "$DATA")
|
||||||
|
|
||||||
|
ID=$(echo $OUT | cut -d',' -f 1 | cut -d':' -f 2)
|
||||||
|
|
||||||
|
OUT=curl -X 'POST' \
|
||||||
|
'https://git.deck.sh/api/v1/repos/Interfaz/ff/releases/'$ID'/assets?token='$TOKEN'' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: multipart/form-data' \
|
||||||
|
-F 'attachment=@'release-$COMMIT.zip';type=application/x-zip-compressed'
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
from fabric import Connection
|
||||||
|
from util import find_data_file
|
||||||
|
from util import setup_child
|
||||||
|
from util import fprint
|
||||||
|
|
||||||
|
def sftp_send_data(res, config, filename):
|
||||||
|
setup_child()
|
||||||
|
fprint("Connecting over SSH to " + config['sftp']['host'])
|
||||||
|
c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),})
|
||||||
|
fprint("Sending data over SFTP: " + filename)
|
||||||
|
fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath']['send']))
|
||||||
|
fprint("Data sent over SFTP sucessfully")
|
||||||
|
#command = 'ls ' + config['sftp']['filepath']['send']
|
||||||
|
#fprint(c.run(command))
|
@ -0,0 +1,98 @@
|
|||||||
|
import inspect
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
from sys import platform
|
||||||
|
import time as t
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
win32 = platform == "win32"
|
||||||
|
linux = platform == "linux" or platform == "linux2"
|
||||||
|
macos = platform == "darwin"
|
||||||
|
datafile = ""
|
||||||
|
|
||||||
|
if win32:
|
||||||
|
sysid = hex(uuid.getnode())
|
||||||
|
datafile += sysid
|
||||||
|
datafile += "gendata.csv"
|
||||||
|
# Python is running as Administrator (so netstat can get filename, to block, etc),
|
||||||
|
# so we use this to see who is actually logged in
|
||||||
|
# it's very hacky
|
||||||
|
startupinfo = subprocess.STARTUPINFO()
|
||||||
|
#if not getattr(sys, "frozen", False):
|
||||||
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # hide powershell window
|
||||||
|
res = subprocess.check_output(["WMIC", "ComputerSystem", "GET", "UserName"], universal_newlines=True, startupinfo=startupinfo)
|
||||||
|
_, username = res.strip().rsplit("\n", 1)
|
||||||
|
userid, sysdom = username.rsplit("\\", 1)
|
||||||
|
|
||||||
|
def time():
|
||||||
|
return int(t.time())
|
||||||
|
|
||||||
|
def fprint(msg):
|
||||||
|
#if not getattr(sys, "frozen", False):
|
||||||
|
setup_child()
|
||||||
|
try:
|
||||||
|
frm = inspect.stack()[1]
|
||||||
|
|
||||||
|
mod = inspect.getmodule(frm[0])
|
||||||
|
print('[' + mod.__name__ + ":" + frm.function + ']:', msg)
|
||||||
|
except Exception as e:
|
||||||
|
try:
|
||||||
|
print('[????:' + frm.function + ']:', msg)
|
||||||
|
except:
|
||||||
|
print('[????]:', msg)
|
||||||
|
|
||||||
|
|
||||||
|
# else:
|
||||||
|
#print(msg)
|
||||||
|
|
||||||
|
def find_data_file(filename):
|
||||||
|
if getattr(sys, "frozen", False):
|
||||||
|
# The application is frozen
|
||||||
|
datadir = os.path.dirname(sys.executable)
|
||||||
|
else:
|
||||||
|
# The application is not frozen
|
||||||
|
# Change this bit to match where you store your data files:
|
||||||
|
datadir = os.path.dirname(__file__)
|
||||||
|
return os.path.join(datadir, filename)
|
||||||
|
|
||||||
|
def run_ps(cmd):
|
||||||
|
fprint("init PS")
|
||||||
|
if win32:
|
||||||
|
startupinfo = subprocess.STARTUPINFO()
|
||||||
|
#print("DICKS")
|
||||||
|
#if not getattr(sys, "frozen", False):
|
||||||
|
# print("test")
|
||||||
|
#
|
||||||
|
#completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
|
||||||
|
#else:
|
||||||
|
# print("alt")
|
||||||
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # , "-WindowStyle", "hidden"
|
||||||
|
fprint("running PS command: " + cmd)
|
||||||
|
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
|
||||||
|
fprint("ran PS command sucessfully")
|
||||||
|
#completed = subprocess.run(["powershell", "-WindowStyle", "hidden", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
|
||||||
|
|
||||||
|
return completed
|
||||||
|
|
||||||
|
def setup_child():
|
||||||
|
if not getattr(sys, "frozen", False):
|
||||||
|
sys.stdout = Logger(filename=find_data_file("output.log"))
|
||||||
|
sys.stderr = Logger(filename=find_data_file("output.log"))
|
||||||
|
|
||||||
|
class Logger(object):
|
||||||
|
def __init__(self, filename="output.log"):
|
||||||
|
self.log = open(filename, "a")
|
||||||
|
self.terminal = sys.stdout
|
||||||
|
|
||||||
|
def write(self, message):
|
||||||
|
self.log.write(message)
|
||||||
|
#close(filename)
|
||||||
|
#self.log = open(filename, "a")
|
||||||
|
try:
|
||||||
|
self.terminal.write(message)
|
||||||
|
except:
|
||||||
|
sleep(0)
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
print("")
|
Loading…
Reference in New Issue