#!/bin/sh

. ../common/ajax_common


import_file()
{
	file_path="${1}"
	[ "${file_path}" = "" ] && file_path="${CGI_file}"
	[ "${file_path}" = "" ] && retjson 1 "NO_FILE"

	errmsg=`${FLOWEYE} pppoeacct load file=${file_path}`

	rm -rf "${file_path}"
}


csv_format()
{
	row=1

	file_path="/${TMPDIR}/csv_account.conf"
	
	mkdir -p "${TMPDIR}"
	[ -f "${file_path}" ] && rm -rf "${file_path}"
	touch ${file_path}

	awk -v file="${file_path}" -F"," \
	'{
		if(NR == 1) next;

		split($11, vlan, "/");

		result = sprintf("u g=%s n=%s p=%s b=%s e=%s s=%s maxonline=%s mac=%s ip=%s outvlan=%s outvlan1=%s",
			$1, $3, $4, $5, $6, $7, $8, $9, $10, vlan[1], vlan[2]);

		if($12 != "NULL")
			result = sprintf("%s outif=%s", result, $12);

		result = sprintf("%s m=0;%s", result, $13);

		print result >> file;
	}' ${CGI_file}

	cp ${file_path} /root/import.log

	import_file ${file_path}
}


haizhizhu()
{
	echo "a"
}


ros()
{
	echo "a"
}


wayos()
{
	echo "a"
}


bytevalue()
{
	echo "a"
}


ikuai()
{
	echo "a"
}


bithighway()
{
	echo "a"
}


natshell()
{
	echo "a"
}


lfradius()
{
	echo "a"
}


sxzros()
{
	echo "a"
}


action_check

case "${CGI_file_type}" in
	"local")
		import_file
		;;

	"csv")
		csv_format
		;;
	
	"haizhizhu")
		haizhizhu
		;;
	
	"ros")
		ros
		;;
		
	"wayos")
		;;
	
	"bytevalue")
		;;
	
	"ikuai")
		;;

	"bithighway")
		;;
	
	"natshell")
		;;
		
	"lfradius")
		;;

	"sxzros")
		;;

	*)
		retjson 1 "UNKNOW_ACTION"
		;;
esac

rm ${CGI_file}
retjson 0 "ɹ"
