Пример #1
0
def get(fname=TAG+".txt", fdir=const.CFG_DIR):
	import xte_network
	version_j = xt_func.load_json(const.CFG_DIR+"version.json")[1]
	license_j = xt_func.load_json(const.CFG_DIR+"license.json")[1]
	traffic = _get_summary_traffic()
	detection = _get_summary_detection()
	txt = xt_func.sh(["cat", "/proc/uptime"])[1]
	up_secs = int(txt.split(".")[0]) #Tuncate to integer
	network_c = xte_network.get()[1]

	data = {
		"version": version_j["version"],
		"sn": license_j["sn"],
		"uptime": _calc_uptime(up_secs),
		"connections":xt_func.sudo(["cat", "/proc/sys/net/netfilter/nf_conntrack_count"])[1],
		"cpu":_get_cpu_usage(),
	}
	for pos in const.ALL_POS:
		data[pos] = _get_pos_summary(pos)
		data[pos]["ip"] = _get_wan_address(pos)
		data[pos]["detection"] = detection[pos]
		data[pos]["rx"] = traffic[pos]["rx"]
		data[pos]["tx"] = traffic[pos]["tx"]
		if pos == "lan" or pos == "dmz":
			data[pos]["label"] = "N/A"
		else:
			data[pos]["label"] = network_c[pos]["label"]
	return (True, data)	
Пример #2
0
def _get_summary_traffic():
	data = {}
	import time
	while True:
		e = xt_func.load_json(const.BM_RECORD)
		if e[0]: break
		time.sleep(1)
	
	for i in e[1]:
		data[i[0]] = {
			"rx": round((i[1] * 8.0)/const.KILO, 2),
			"tx": round((i[2] * 8.0)/const.KILO, 2)
		}

	return data
Пример #3
0
def _set(data):
	hw = xt_func.load_json(const.HW_INFO)[1]
	ret = True
	emsg = []
	xt_func.sudo(["killall bmstatd"])
	xt_func.sudo(["killall proxyarpd"])
	xt_func.sudo(["killall dy_monitor"])
	time.sleep(4) # dy_monitor needs 3 sec to end itself
	for (dev, pos, rtab, dum) in const.IFMAP:
		xt_func.sudo(["ip link set dev", pos, "down"])
		xt_func.sudo(["ip addr flush dev", pos])
		xt_func.sudo(["ip route flush table", rtab])
	xt_func.sudo(["ip route flush cache"])

	e = _set_hardware(data, hw)
	if not e[0]:
		ret = False
		emsg.append(e[1])

	e = _set_ifup_address_and_route(data)
	if not e[0]:
		ret = False
		emsg.append(e[1])

	e = _set_netpos(data) 
	if not e[0]: 
		ret = False
		emsg.append(e[1])

	e = _set_public_ip_passthrough(data)
	if not e[0]: 
		ret = False
		emsg.append(e[1])

	e = _set_bandwidth_limit(data) 
	if not e[0]: 
		ret = False
		emsg.append(e[1])

	e = do_arpenforce(data)
	if not e[0]: 
		ret = False
		emsg.append(e[1])

	return (ret, emsg)
def get(fname=USER_TABLE, fdir=const.CFG_DIR):
	return xt_func.load_json(fdir+fname)