#!/bin/sh
#This script is created by ssparser automatically. The parser first created by MaoShouyan
printf "Content-type: text/html; charset=GB2312
Cache-Control: no-cache

"
echo -n "";
RAMDISK="/usr/ramdisk"
if [ -f ${RAMDISK}/PG.conf ]; then
        . ${RAMDISK}/PG.conf
        PGPATH="${RAMDISK}"
else
        . /etc/PG.conf
fi
. ${PGPATH}/etc/panabit.inf
PGBIN=${PGPATH}/bin
FLOWEYE=${PGBIN}/floweye
EVENTFILE=${PGETC}/log/pending_events
if [ -f ${PGETC}/sysname.conf ]; then
        . ${PGETC}/sysname.conf
fi
AIDE_PPPOECLIENTACCT=${PGPATH}/admin/cgi-bin/common/aide_pppoe_clientacct
resources_file="/tmp/status/ipmport_resources_${CGI_s}"
status_file="/tmp/status/ipmport_status_${CGI_s}"
if [ "${CGI_s}" != "" -a "${CGI_n}" = "" ]; then
	#line=`ps axuw | grep ${resources_file} | grep -v grep`
	#if [ "${line}" = "" ]; then 
		[ "${CGI_o}" = "on" ] && override="-override"
		${AIDE_PPPOECLIENTACCT} -i ${override} -debug ${resources_file} > ${status_file}
	#fi
	exit 0
fi
res_all=0
count_all=0
lastnum=0
r_txt=""
if [ -f ${resources_file} ]; then 
	res_all=`grep "[^ ]" ${resources_file} | wc -l`
	res_all=$((${res_all}))
fi
if [ -f ${status_file} ]; then
	count_all=`grep "^[err|ok]" ${status_file} | wc -l`
	count_all=$((${count_all}))
	lastnum=$((${count_all} - ${CGI_n}))
	r_txt=`grep "^[err|ok]" ${status_file} | tail -n ${lastnum} | awk -F'ok ' '{
	if(substr($1,1,3) != "err")
	print "\""$2"\",";
}'`
fi
echo "{ res_all: ${res_all},
 count: ${count_all},
 ok: [ ${r_txt%,*} ], "
if [ -f ${status_file} ]; then
	r_txt=`grep "^[err|ok]" ${status_file} | tail -n ${lastnum} | awk -F'err ' '{
	if(substr($1,1,2) != "ok")
	print "\""$2"\",";
}'`
fi
echo "err: [ ${r_txt%,*} ]}"

echo -n "
";
