#!/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}

	while read line
	do
		if [ "${row}" = "1" ];then
			row=2
			continue
		fi

		echo "${line}" | awk -v file=${file_path} -F "," \
		'{
			printf "u g=%s n=%s p=%s b=%s e=%s s=%s maxonline=%s mac=%s ip=%s m=%s\n",
			$1, $2, $3, $4, $5, $6, $7, $8, $9, $10 >> file;
		}'
	done <<EOF
`cat ${CGI_file}`
EOF

	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 "ɹ"
