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