예제 #1
0
def validate(data):
	x = jcfg.JcPassword()
	for pos in const.ALL_WANS:
		data[pos]["pppoe-mode"]["password"] = x.encrypt(data[pos]["pppoe-mode"]["password"]) 
	e = jcfg.validate_jcfg(HELPER, {TAG: data})
	if not e[0]:
		return e
	for pos in const.ALL_WANS:
		data[pos]["pppoe-mode"]["password"] = x.decrypt(data[pos]["pppoe-mode"]["password"]) 
		if data[pos]["enable"] != 1:
			continue
		if data[pos]["type"] == "static":
			if len(data[pos]["static-mode"]["ip"]) == 0:
				return (False, ["network", pos, "static-mode", "ip", "can't be empty"])
			if data[pos]["static-mode"]["mask"] == "":
				return (False, ["network", pos, "static-mode", "mask", "can't be empty"])
			if data[pos]["static-mode"]["gateway"] == "":
				return (False, ["network", pos, "static-mode", "gateway", "can't be empty"])
		elif data[pos]["type"] == "pppoe":
			if data[pos]["pppoe-mode"]["username"] == "":
				return (False, ["network", pos, "pppoe-mode", "username", "can't be empty"])
			if data[pos]["pppoe-mode"]["password"] == "":
				return (False, ["network", pos, "pppoe-mode", "password", "can't be empty"])
		elif data[pos]["type"] == "dhcp":
			pass
		else:
			return (False, ["network", pos, "type", data[pos]["type"], jcfg.SEMERR_INVAL_VAL])
	return (True, None)
def importing(imported_file, user):
	ret = True
	emsg = []
	f = open(imported_file, "r")
	lines = f.readlines()
	f.close()
	xt_func.sudo(["rm -rf",imported_file])
	e = jcfg.parse_syntax(lines)
	if not e[0]:
		return e
	data = e[1]
	if "xteralink" not in data:
		return (False, N_("invalid configuration"))
	data = data["xteralink"]
	for i in const.MOD_LIST:
		page = __import__(i)
		if page.TAG not in data:
			print "skip", page.TAG
			continue
		print "importing", page.TAG
		e = jcfg.validate_jcfg(page.HELPER, {page.TAG: data[page.TAG]})
		if not e[0]:
			ret = False
			emsg.append(e[1])
			continue
		e = page.set(e[1][page.TAG], user)
		if not e[0]:
			ret = False
			emsg.append(e[1])
			
	return (ret, emsg)
def validate(data):
	if "date" in data:
		del data["date"]
	return jcfg.validate_jcfg(HELPER, {TAG: data})
예제 #4
0
def validate(data):
	return jcfg.validate_jcfg(HELPER, {TAG: data})