|
|
|
@ -67,10 +67,14 @@ def process_done(res):
|
|
|
|
|
if settings["running"] == True:
|
|
|
|
|
fprint("uploading to sftp...")
|
|
|
|
|
#ssh.sftp_send_data(res, config, datafile)
|
|
|
|
|
|
|
|
|
|
procdata_res = pool.apply_async(ssh.sftp_send_data, (config, datafile, 'send'), callback=upload_done)
|
|
|
|
|
|
|
|
|
|
def upload_done(res):
|
|
|
|
|
settings["block"] = True
|
|
|
|
|
tmpstat = settings["stats"]
|
|
|
|
|
tmpstat[2] += 1
|
|
|
|
|
settings["stats"] = tmpstat
|
|
|
|
|
|
|
|
|
|
def login_done(res):
|
|
|
|
|
if not res:
|
|
|
|
@ -87,7 +91,16 @@ def blockdata_done(res):
|
|
|
|
|
tmpkill = settings["kill"]
|
|
|
|
|
settings["kill"] = False
|
|
|
|
|
#block_res = pool.apply_async(block.block_conn, (config, datafile, res, settings))
|
|
|
|
|
block_pids, block_ips, block_data = block.block_conn(config, datafile, res)
|
|
|
|
|
block_pids, block_ips, block_data, goodct = block.block_conn(config, datafile, res)
|
|
|
|
|
tmpstat = settings["stats"]
|
|
|
|
|
tmpstat[1] += goodct
|
|
|
|
|
if tmpstat[0] > 0 and goodct > 0:
|
|
|
|
|
tmpstat[4] = 1.0 / (goodct * 100.0 / tmpstat[0])
|
|
|
|
|
else:
|
|
|
|
|
tmpstat[4] = 0.0
|
|
|
|
|
tmpstat[3] += 1
|
|
|
|
|
settings["stats"] = tmpstat
|
|
|
|
|
|
|
|
|
|
tmplist = settings["badapps"]
|
|
|
|
|
|
|
|
|
|
for x in block_pids:
|
|
|
|
@ -117,6 +130,11 @@ def blockdata_done(res):
|
|
|
|
|
|
|
|
|
|
settings["newdata"] = True
|
|
|
|
|
|
|
|
|
|
def readstat_done(res):
|
|
|
|
|
settings["stats"] = res
|
|
|
|
|
fprint("Read stats!" + str(settings["stats"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def killall():
|
|
|
|
|
kids = active_children()
|
|
|
|
|
for kid in kids:
|
|
|
|
@ -143,6 +161,8 @@ def mainloop(pool):
|
|
|
|
|
#print(res.get(timeout=1))
|
|
|
|
|
if counter == 0: # runs every INTERVAL
|
|
|
|
|
#fprint("start loop")
|
|
|
|
|
if settings["stats"][1] > 0:
|
|
|
|
|
util.write_stats(settings["stats"])
|
|
|
|
|
if netdata_res is None or netdata_res.ready():
|
|
|
|
|
#rawdata = netdata_res.get()
|
|
|
|
|
#procdata_res = pool.apply_async(process_netstat, (rawdata))
|
|
|
|
@ -200,6 +220,9 @@ def mainloop(pool):
|
|
|
|
|
|
|
|
|
|
if settings["fwll"] == True:
|
|
|
|
|
tmplist = settings["badlines"]
|
|
|
|
|
tmpstat = settings["stats"]
|
|
|
|
|
tmpstat[0] += len(tmplist)
|
|
|
|
|
settings["stats"] = tmpstat
|
|
|
|
|
settings["badlines"] = list()
|
|
|
|
|
for line in tmplist:
|
|
|
|
|
badproto = line[1]
|
|
|
|
@ -263,6 +286,7 @@ if __name__ == '__main__':
|
|
|
|
|
interval = config['core']['interval']
|
|
|
|
|
displaydata = manager.list(range(2)) # data to be printed
|
|
|
|
|
settings = manager.dict() # configuration
|
|
|
|
|
# setup shared data variables
|
|
|
|
|
settings["login"] = False
|
|
|
|
|
settings["loggedin"] = False
|
|
|
|
|
settings["showui"] = False
|
|
|
|
@ -273,16 +297,20 @@ if __name__ == '__main__':
|
|
|
|
|
settings["badlines"] = list()
|
|
|
|
|
settings["block"] = False
|
|
|
|
|
settings["kill"] = False
|
|
|
|
|
settings["config"] = config
|
|
|
|
|
settings["config"] = config
|
|
|
|
|
settings["applyconfig"] = False
|
|
|
|
|
settings["fwll"] = 0
|
|
|
|
|
settings["running"] = config["core"]["autostart"]
|
|
|
|
|
settings["newdata"] = False
|
|
|
|
|
# connections blocked, total connections allowed, count of data sent, data recieved, ratio blocked-unblocked
|
|
|
|
|
settings["stats"] = [0, 0, 0, 0, 0.0]
|
|
|
|
|
|
|
|
|
|
killme = manager.Value('d', 0)
|
|
|
|
|
#killme = False
|
|
|
|
|
# launch background UI app as process
|
|
|
|
|
util.clear_fwll()
|
|
|
|
|
p = Process(target=taskbartool.background, args=(displaydata,settings,killme))
|
|
|
|
|
|
|
|
|
|
p.start()
|
|
|
|
|
#p.join() # not a foreground job, so let's not join it
|
|
|
|
|
keeprunning = True
|
|
|
|
@ -290,12 +318,13 @@ if __name__ == '__main__':
|
|
|
|
|
# initial setup
|
|
|
|
|
#netdata_res = pool.apply_async(netstat, callback=netstat_done)
|
|
|
|
|
if linux:
|
|
|
|
|
# clear existing nftables entries, create new table
|
|
|
|
|
run_cmd("nft delete table ip ippigeon")
|
|
|
|
|
run_cmd("nft create table ip ippigeon")
|
|
|
|
|
run_cmd("nft add chain ip ippigeon output { type filter hook output priority 0 \; policy accept\; }")
|
|
|
|
|
#run_cmd("nft add chain ippigeon filter")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool.apply_async(util.read_stats, callback=readstat_done)
|
|
|
|
|
# launch loop - non-blocking!
|
|
|
|
|
counter = 0
|
|
|
|
|
while(keeprunning):
|
|
|
|
|