#!/bin/sh

. ../common/ajax_common


if [ "${PALANG}" = "en" ]; then
    LANG001="Error"		#ʧ
    LANG002="Success"	#ɹ
fi


load_config()
{
    ${FLOWEYE} phonewifi stat | awk -F"=" \
    'BEGIN{
        dot = "";
        printf "{";
    }{
        printf "%s\"%s\":\"%s\"", dot, $1, $2;
        if(dot == "") dot = ",";
    }END{
        printf "}";
    }'
}


load_set_env()
{
    . ../common/ajax_object_lib

    printf "{"
    printf "\"iptab\":`lib_iptable_list`"
    printf ",\"conf\":`load_config`"
    printf "}"
}


set_config()
{
    cmdargs=""
    cmdargs="${cmdargs} enable=${CGI_enable}"
    cmdargs="${cmdargs} whitelist=${CGI_whitelist}"
    cmdargs="${cmdargs} start=${CGI_start}"
    cmdargs="${cmdargs} end=${CGI_end}"

    newttl=`${FLOWEYE} phonewifi stat | grep "newttl=" | cut -d"=" -f2`
    if [ ${newttl} -le 2 -o ${CGI_newttl} = "1" ]; then
        cmdargs="${cmdargs} newttl=${CGI_newttl}"
    fi

    errmsg=`${FLOWEYE} phonewifi config ${cmdargs}`

    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
    else
        sync_floweye "phonewifi config ${cmdargs}"
        WEB_LOGGER "繲ģ" "${cmdargs}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}


load_gswifi_list()
{
    ${FLOWEYE} gswifi list | grep -i "${CGI_keyword}" | awk \
    'BEGIN{
        dot = "";
        printf "[";
    }{
        col = 1;
        printf "%s{", dot;
        printf "\"ip\":\"%s\"", $(col++);
        printf ",\"mac\":\"%s\"", $(col++);
        printf ",\"time\":\"%s\"", $(col++);
        printf ",\"phone\":\"%s\"", $(col++);
        printf ",\"pc\":\"%s\"", $(col++);
        printf ",\"trust\":%s", $(col++);
        printf ",\"account\":\"%s\"", $(col++);
        printf "}";
        if(dot == "") dot = ",";
    }END{
        printf "]";
    }'
}


export_gswifi_csv()
{
    mkdir -p ${WEB_DOWNLOAD}

    file_name="豸_`date "+%Y%m%d_%H%M%S"`.csv"
    download_path="${WEB_DOWNLOAD}/${file_name}"

    echo ",豸IP,豸MAC,ʱ,ƶն,PCն" > ${download_path}

    ${FLOWEYE} gswifi list | awk \
    '{
        time = strftime("%Y-%m-%d %H:%M:%S", $3);
        printf "%s,%s,%s,%s,%s,%s\n", NR, $1, $2, time, $4, $5;
    }' >> ${download_path}

    WEB_LOGGER "豸б"
    retjson 0 "OK" "\"${file_name}\""
}


load_gswifi_stat()
{
    ${FLOWEYE} gswifi stat | awk -F"=" \
    'BEGIN{
        dot = "";
        printf "{";
    }{
        printf "%s\"%s\":\"%s\"", dot, $1, $2;
        if(dot == "") dot = ",";
    }END{
        printf "}";
    }'
}


set_gswifi_stat()
{
    cmdargs="enable=${CGI_enable} model=${CGI_model} devlimit=${CGI_devlimit} devttl=${CGI_devttl}"

    errmsg=`${FLOWEYE} gswifi config ${cmdargs}`

    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
    else
        WEB_LOGGER "޸Ĺ" "${cmdargs}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}


load_trust_list()
{
    total=0 dot=""
	[ "${CGI_page}" = "" ] && CGI_page=1
	[ "${CGI_limit}" = "" ] && CGI_limit=100
	end=$((${CGI_page} * ${CGI_limit}))
	start=$((${end} - ${CGI_limit}))
 
    result=""
    if [ "${CGI_type}" = "gswifi" ]; then
	    result=`${FLOWEYE} gstrustip list`
    elif [ "${CGI_type}" = "terminal" ]; then
        result=`${FLOWEYE} devsnif list trust=1`
    fi

	if [ "${result}" = "" ]; then
		echo "{\"total\":0,\"data\":[]}"
		return 0
	fi
    
	printf "{\"data\":["
	
    if [ "${CGI_type}" = "gswifi" ]; then
	    #while read object time count description
        while read object time description

        do
		total=$((${total}+1))
		[ ${total} -le ${start} -o ${total} -gt ${end} ] && continue

		description=`utf8togb2312 ${description}`

        printf "${dot}"
        printf "{"
        printf "\"object\":\"${object}\","
        #printf "\"count\":\"${count}\","
        printf "\"time\":\"${time}\","
        printf "\"description\":\"${description}\""
        printf "}"
		
		[ "${dot}" = "" ] && dot=","
		
	done << EOF
	${result}
EOF

	printf "],\"total\":%d}" ${total};

    elif [ "${CGI_type}" = "terminal" ]; then
        while read object time description

        do
		total=$((${total}+1))
		[ ${total} -le ${start} -o ${total} -gt ${end} ] && continue

		description=`utf8togb2312 ${description}`

        printf "${dot}"
        printf "{"
        printf "\"object\":\"${object}\","
        printf "\"time\":\"${time}\","
        printf "\"description\":\"${description}\""
        printf "}"
		
		[ "${dot}" = "" ] && dot=","
		
	done << EOF
	${result}
EOF

	printf "],\"total\":%d}" ${total};

    fi

}


add_trust_ip()
{
    cmdargs="ip=${CGI_wipchstr} desc=${CGI_desc}"

    errmsg=""
    if [ "${CGI_type}" = "gswifi" ]; then
        cmdargs="${cmdargs} limit=${CGI_limit}"
	    errmsg=`${FLOWEYE} gstrustip add ${cmdargs}`
    elif [ "${CGI_type}" = "terminal" ]; then
        errmsg=`${FLOWEYE} devsnif add ${cmdargs}`
    fi

    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
    else
        WEB_LOGGER "ζ" "${cmdargs}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}


remove_trust_ip()
{
    for obj in `echo "${CGI_wipchstr}" | tr "|" " "`
    do 
        cmdargs="ip=$obj"

        if [ "${CGI_type}" = "gswifi" ]; then
            errmsg=`${FLOWEYE} gstrustip remove ${cmdargs}`
        elif [ "${CGI_type}" = "terminal" ]; then
            errmsg=`${FLOWEYE} devsnif remove ${cmdargs}`
        fi

        [ $? -ne 0 ] && retjson 1 "${LANG001:=ʧ}:${errmsg}"
    done

    WEB_LOGGER "ɾζ" "${cmdargs}"
    retjson 0 "${LANG002:=ɹ}"
}


trend_discovery_chart()
{
	tag=""
    tag2=""
    MAX_SHARE_LEVEL="$(${FLOWEYE} gswifi stat | grep MAX_SHARE_LEVEL | cut -d '=' -f 2)"
	
	printf "{\"name\":{"

    local i=0
    while [ ${i} -lt ${MAX_SHARE_LEVEL} ]
    do
        i=$((${i} + 1))

        tag="gswifi_cnt_${i}"
        tag2="${tag2} tag=${tag} "

		printf "${dot}\"$tag\":{"
		printf "\"name\":\"$tag\","
		printf "\"color\":\" \""
		printf "}"
		[ "${dot}" = "" ] && dot=","
	done

	printf "},\"data\":"
    ${FLOWEYE} chart dump $tag2 json=1
	printf "}"
}


load_trend_discovery_list()
{
    total=0 dot=""
	[ "${CGI_page}" = "" ] && CGI_page=1
	[ "${CGI_limit}" = "" ] && CGI_limit=100
	end=$((${CGI_page} * ${CGI_limit}))
	start=$((${end} - ${CGI_limit}))

	result=`${FLOWEYE} gswifi list hlist=1 time="${CGI_time}" | grep -i "${CGI_keyword}"`

	if [ "${result}" = "" ]; then
		echo "{\"total\":0,\"data\":[]}"
		return 0
	fi
    
	printf "{\"data\":["
	
	while read ip mac time phone pc devinfo account
	do
		total=$((${total}+1))
		[ ${total} -le ${start} -o ${total} -gt ${end} ] && continue

        account=`utf8togb2312 ${account}`
        devinfo=`utf8togb2312 ${devinfo}`

        printf "${dot}"
        printf "{"
        printf "\"ip\":\"${ip}\","
        printf "\"mac\":\"${mac}\","
        printf "\"time\":\"${time}\","
        printf "\"phone\":\"${phone}\","
        printf "\"pc\":\"${pc}\","
        printf "\"devinfo\":\"${devinfo}\","
        printf "\"account\":\"${account}\""
        printf "}"
		
		[ "${dot}" = "" ] && dot=","
		
	done << EOF
	${result}
EOF

	printf "],\"total\":%d}" ${total};
}


export_trend_discovery_csv()
{
    
    mkdir -p ${WEB_DOWNLOAD}

    file_name="ʷ豸_`date "+%Y%m%d_%H%M%S"`.csv"
    download_path="${WEB_DOWNLOAD}/${file_name}"

    echo ",豸IP,豸MAC,ʱ,ƶն,PCն,,˺" > ${download_path}
    
    result=`${FLOWEYE} gswifi list hlist=1`
    counter=1

    while read ip mac time phone pc devinfo account
	do
        account=`utf8togb2312 ${account}`
        time_=$(date -d "@${time}" "+%Y-%m-%d %H:%M:%S")
        printf "%s,%s,%s,%s,%s,%s,%s\n" "${counter}","${ip}","${mac}","$time_","${phone}","${pc}","${devinfo}","${account}" >> ${download_path}
		counter=$((counter + 1))
	done << EOF
	${result}
EOF

    WEB_LOGGER "ʷ豸б"
    retjson 0 "OK" "\"${file_name}\""
}


set_gswifi_terminal_rec()
{

    cmdargs="clireco=${CGI_clireco}"

    errmsg=`${FLOWEYE} gswifi config ${cmdargs}`

    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
    else
        WEB_LOGGER "/رնʶ" "${cmdargs}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}

set_gswifi_traffic_drop()
{
    cmdargs="drop=${CGI_drop}"

    errmsg=`${FLOWEYE} gswifi config ${cmdargs}`

    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
    else
        WEB_LOGGER "/رIP" "${cmdargs}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}


control_gswifi()
{

    cmdargs="ip=${CGI_ip} trust=${CGI_trust}"

    errmsg=""
    if [ "${CGI_type}" = "gswifi" ]; then
	    errmsg=`${FLOWEYE} gswifi set ${cmdargs}`
    elif [ "${CGI_type}" = "terminal" ]; then
        errmsg=`${FLOWEYE} devsnif config ${cmdargs}`
    fi

    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
    else
        WEB_LOGGER "ⶳ򶳽IP" "${cmdargs}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}


load_terminal_list()
{
    total=0 dot=""
	[ "${CGI_page}" = "" ] && CGI_page=1
	[ "${CGI_limit}" = "" ] && CGI_limit=100
	end=$((${CGI_page} * ${CGI_limit}))
	start=$((${end} - ${CGI_limit}))

	result=`${FLOWEYE} devsnif list | grep -i "${CGI_keyword}"`

	if [ "${result}" = "" ]; then
		echo "{\"total\":0,\"data\":[]}"
		return 0
	fi
    
	printf "{\"data\":["
	
	while read ip mac time brand model type trust account
	do
		total=$((${total}+1))
		[ ${total} -le ${start} -o ${total} -gt ${end} ] && continue

		brand=`utf8togb2312 ${brand}`
        model=`utf8togb2312 ${model}`
        type=`utf8togb2312 ${type}`
        account=`utf8togb2312 ${account}`

        printf "${dot}"
        printf "{"
        printf "\"ip\":\"${ip}\","
        printf "\"mac\":\"${mac}\","
        printf "\"time\":\"${time}\","
        printf "\"brand\":\"${brand}\","
        printf "\"model\":\"${model}\","
        printf "\"type\":\"${type}\","
        printf "\"trust\":\"${trust}\","
        printf "\"account\":\"${account}\""
        printf "}"
		
		[ "${dot}" = "" ] && dot=","
		
	done << EOF
	${result}
EOF

	printf "],\"total\":%d}" ${total};

}


set_terminal_stat()
{
    cmdargs="enable=${CGI_enable} model=${CGI_model} devlimit=${CGI_devlimit} devttl=${CGI_devttl}"
    cmdargs_=""
    cmdargs_del=""
    
    brand_str=`utf8togb2312 ${CGI_brand_str}`
    brandstr=`utf8togb2312 ${CGI_brandstr}`
    os_str=`utf8togb2312 ${CGI_os_str}`
    osstr=`utf8togb2312 ${CGI_osstr}`

    if [ "${CGI_model}" = "1" ]; then
        cmdargs_del="block=0 brandstr=${brand_str}"
        cmdargs_="block=1 osstr=${osstr}"
    elif [ "${CGI_model}" = "2" ]; then
        cmdargs_del="block=0 osstr=${os_str}"
        cmdargs_="block=1 brandstr=${brandstr}"
    fi

    errmsg=`${FLOWEYE} devsnif config ${cmdargs}`
    errmsg_=`${FLOWEYE} devsnif config ${cmdargs_}`
    errmsg_del=`${FLOWEYE} devsnif config ${cmdargs_del}`
       
    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
        retjson 1 "${LANG001:=ʧ}:${cmdargs_del}"
        retjson 1 "${LANG001:=ʧ}:${errmsg_}"
    else
        WEB_LOGGER "޸ն" "${cmdargs}"
        WEB_LOGGER "޸ն" "${cmdargs_del}"
        WEB_LOGGER "޸ն" "${cmdargs_}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}


set_terminal_traffic_drop()
{

    cmdargs="drop_enable=${CGI_drop}"

    errmsg=`${FLOWEYE} devsnif config ${cmdargs}`

    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
    else
        WEB_LOGGER "/رIP" "${cmdargs}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}


set_terminal_traffic_overlook()
{

    cmdargs="overlook=${CGI_overlook}"

    errmsg=`${FLOWEYE} devsnif config ${cmdargs}`

    if [ $? -ne 0 ]; then
        retjson 1 "${LANG001:=ʧ}:${errmsg}"
    else
        WEB_LOGGER "/رպնͺ" "${cmdargs}"
        retjson 0 "${LANG002:=ɹ}"
    fi
}


load_terminal_stat()
{

    ${FLOWEYE} devsnif stat | awk -F"=" \
    'BEGIN{
        dot = "";
        printf "{";
    }{
        printf "%s\"%s\":\"%s\"", dot, $1, $2;
        if(dot == "") dot = ",";
    }END{
        printf "}";
    }'
}


export_terminal_csv()
{
    mkdir -p ${WEB_DOWNLOAD}

    file_name="ն˼_`date "+%Y%m%d_%H%M%S"`.csv"
    download_path="${WEB_DOWNLOAD}/${file_name}"

    echo ",豸IP,豸MAC,ʱ,նƷ,նͺ,ϵͳ,˺" > ${download_path}

    ${FLOWEYE} devsnif list | awk \
    '{
        time = strftime("%Y-%m-%d %H:%M:%S", $3);
        printf "%s,%s,%s,%s,%s,%s,%s,%s\n", NR, $1, $2, time, $4, $5, $6, $7;
    }' >> ${download_path}

    WEB_LOGGER "ն˼б"
    retjson 0 "OK" "\"${file_name}\""
}


terminal_trend_discovery_chart()
{
	tag=""
    tag2=""
	
	printf "{\"name\":{"

    if [ "${CGI_type}" = "terminal" ];then
        local i=0
        while [ ${i} -lt 18 ]
        do

            tag="devsnif_cnt_$((i))"
            tag2+="tag=${tag} "

            i=$((${i} + 1))

            printf "${dot}\"$tag\":{"
            printf "\"name\":\"$tag\","
            printf "\"color\":\" \""
            printf "}"
            [ "${dot}" = "" ] && dot=","
        done
    else
        local i=18
        while [ ${i} -lt 23 ]
        do

            tag="devsnif_cnt_$((i))"
            tag2+="tag=${tag} "

             i=$((${i} + 1))

            printf "${dot}\"$tag\":{"
            printf "\"name\":\"$tag\","
            printf "\"color\":\" \""
            printf "}"
            [ "${dot}" = "" ] && dot=","
	   done 
    fi

	printf "},\"data\":"
    ${FLOWEYE} chart dump $tag2 json=1
	printf "}"
}


pie_system_chart()
{

	${FLOWEYE} devsnif list oslist=1 | awk \
	'BEGIN{
		dot = "";
		printf "[";
	}{
		printf "%s", dot;
		printf "{";
		printf "\"appid\":\"%s\",", $1;
		printf "\"en_name\":\"%s\",", $2;
		printf "\"name\":\"%s\",", $3;
		printf "\"system\":%s", $4;
		printf "}";
		if(dot == "") dot = ",";
	}END{
		printf "]";
	}'
}

pie_terminal_chart()
{

	${FLOWEYE} devsnif list devlist=1 | awk \
	'BEGIN{
		dot = "";
		printf "[";
	}{
		printf "%s", dot;
		printf "{";
		printf "\"appid\":\"%s\",", $1;
		printf "\"name\":\"%s\",", $2;
		printf "\"en_name\":\"%s\",", $3;
		printf "\"terminal\":%s", $4;
		printf "}";
		if(dot == "") dot = ",";
	}END{
		printf "]";
	}'
}


load_terminal_log_list()
{
    total=0 dot=""
	[ "${CGI_page}" = "" ] && CGI_page=1
	[ "${CGI_limit}" = "" ] && CGI_limit=100
	end=$((${CGI_page} * ${CGI_limit}))
	start=$((${end} - ${CGI_limit}))

	result=`${FLOWEYE} devsnif list hlist=1 time="${CGI_time}" | grep -i "${CGI_keyword}"`

	if [ "${result}" = "" ]; then
		echo "{\"total\":0,\"data\":[]}"
		return 0
	fi
    
	printf "{\"data\":["
	
	while read ip mac time brand model type trust account
	do
		total=$((${total}+1))
		[ ${total} -le ${start} -o ${total} -gt ${end} ] && continue

		brand=`utf8togb2312 ${brand}`
        model=`utf8togb2312 ${model}`
        type=`utf8togb2312 ${type}`
        account=`utf8togb2312 ${account}`

        printf "${dot}"
        printf "{"
        printf "\"ip\":\"${ip}\","
        printf "\"mac\":\"${mac}\","
        printf "\"time\":\"${time}\","
        printf "\"brand\":\"${brand}\","
        printf "\"model\":\"${model}\","
        printf "\"type\":\"${type}\","
        printf "\"trust\":\"${trust}\","
        printf "\"account\":\"${account}\""
        printf "}"
		
		[ "${dot}" = "" ] && dot=","
		
	done << EOF
	${result}
EOF

	printf "],\"total\":%d}" ${total};

}


export_terminal_log_csv()
{
    
    mkdir -p ${WEB_DOWNLOAD}

    file_name="ն˼־_`date "+%Y%m%d_%H%M%S"`.csv"
    download_path="${WEB_DOWNLOAD}/${file_name}"

    echo ",豸IP,豸MAC,ʱ,նƷ,նͺ,ϵͳ,˺" > ${download_path}
    
    result=`${FLOWEYE} devsnif list hlist=1`
    counter=1

    while read ip mac time brand model type trust account
	do
        brand=`utf8togb2312 ${brand}`
        model=`utf8togb2312 ${model}`
        type=`utf8togb2312 ${type}`
        account=`utf8togb2312 ${account}`
        time_=$(date -d "@${time}" "+%Y-%m-%d %H:%M:%S")
        printf "%s,%s,%s,%s,%s,%s,%s\n" "${counter}","${ip}","${mac}","$time_","${brand}","${model}","${type}","${account}" >> ${download_path}
		counter=$((counter + 1))
	done << EOF
	${result}
EOF

    WEB_LOGGER "ն˼־б"
    retjson 0 "OK" "\"${file_name}\""
}

load_terminal_env(){
    enable="$(${FLOWEYE} devsnif stat | grep '^enable=' | cut -d '=' -f 2)"
    devttl="$(${FLOWEYE} devsnif stat | grep devttl | cut -d '=' -f 2)"
    drop_enable="$(${FLOWEYE} devsnif stat | grep drop_enable | cut -d '=' -f 2)"

    sys_num="$(${FLOWEYE} devsnif list oslist=1 | awk '{sum += $NF} END {print sum}')"
    ter_num="$(${FLOWEYE} devsnif list devlist=1 | awk '{sum += $NF} END {print sum}')"
    ter_type_num="$(${FLOWEYE} devsnif list devlist=1 | tail -n 1 | awk '{print $1 + 1}')"
    trust_list_num="$(${FLOWEYE} devsnif list trust=1 | wc -l)"

    printf "{"
    printf "\"enable\":\"${enable}\","
    printf "\"ter_num\":\"${ter_num}\","
    printf "\"sys_num\":\"${sys_num}\","
    printf "\"devttl\":\"${devttl}\","
    printf "\"trust_list_num\":\"${trust_list_num}\","
    printf "\"ter_type_num\":\"${ter_type_num}\","
    printf "\"drop_enable\":\"${drop_enable}\""
    printf "}"

     
    
}


case "${CGI_action}" in
    "load_config")
        retjson 0 "OK" "`load_config`"
        ;;

    "load_set_env")
        retjson 0 "OK" "`load_set_env`"
        ;;

    "set_config")
        action_check
        set_config
        ;;

    "load_gswifi_list")
        retjson 0 "OK" "`load_gswifi_list`"
        ;;

    "export_gswifi_csv")
        action_check
        export_gswifi_csv
        ;;

    "load_gswifi_stat")
        retjson 0 "OK" "`load_gswifi_stat`"
        ;;

    "set_gswifi_stat")
        action_check
        set_gswifi_stat
        set_gswifi_terminal_rec
        set_gswifi_traffic_drop
        ;;

    "load_trust_list")
        retjson 0 "OK" "`load_trust_list`"
        ;;

    "add_trust_ip")
        action_check
        add_trust_ip
        ;;

    "remove_trust_ip")
        action_check
        remove_trust_ip
        ;;

    "trend_discovery_chart")
        retjson 0 "OK" "`trend_discovery_chart`"
        ;;

    "load_trend_discovery_list")
        retjson 0 "OK" "`load_trend_discovery_list`"
        ;;

    "export_trend_discovery_csv")
        action_check
        export_trend_discovery_csv
        ;;

    "set_gswifi_terminal_rec")
        action_check
        set_gswifi_terminal_rec
        ;;

    "set_gswifi_traffic_drop")
        action_check
        set_gswifi_traffic_drop
        ;;

    "control_gswifi")
        action_check
        control_gswifi
        ;;

    "load_terminal_list")
        retjson 0 "OK" "`load_terminal_list`"
        ;;

    "set_terminal_stat")
        action_check
        set_terminal_stat
        set_terminal_traffic_drop
        set_terminal_traffic_overlook
        ;;

    "set_terminal_traffic_drop")
        action_check
        set_terminal_traffic_drop
        ;;

     "set_terminal_traffic_overlook")
        action_check
        set_terminal_traffic_overlook
        ;;

    "load_terminal_stat")
        retjson 0 "OK" "`load_terminal_stat`"
        ;;

    "export_terminal_csv")
        action_check
        export_terminal_csv
        ;;

    "terminal_trend_discovery_chart")
        retjson 0 "OK" "`terminal_trend_discovery_chart`"
        ;;

    "pie_terminal_chart")
        retjson 0 "OK" "`pie_terminal_chart`"
        ;;

    "pie_system_chart")
        retjson 0 "OK" "`pie_system_chart`"
        ;;

    "load_terminal_log_list")
        retjson 0 "OK" "`load_terminal_log_list`"
        ;;

    "export_terminal_log_csv")
        action_check
        export_terminal_log_csv
        ;;

    "load_terminal_env")
        retjson 0 "OK" "`load_terminal_env`"
        ;;

    *)
        retjson 1 "UNKNOW_ACTION"
        ;;

esac
