sleep 10

svrmode='svrdata'
opermode='operdata'
statusmode1='false'
statusmode2='true'
usualmode='none'
tlmode=`./CLI_client pqprobe read | grep tlenable | awk -F[,:] '{print $2}'`
secdatamode=`./CLI_client sec_data read | grep enable | awk -F[,:] '{print $2}'`
wanmode=`./CLI_client wan_stats wanstats_read_stat | grep upload_mode | awk -F[.\"] '{print $4}'`
tupmode=`./CLI_client  tuple  | grep upload_mode | awk -F[.\"] '{print $4}'`
lanmode=`./CLI_client lanhost_stats lanhoststats_read_stat | grep upload_mode | awk -F[.\"] '{print $4}'`
httpsmdoe=`./CLI_client https read | grep upload_mode | awk -F[.\"] '{print $4}'`
httpsperiod=`./CLI_client https read | grep period | awk -F [,:] '{print $2}'`
uselon=`./CLI_client __oper_data read | grep uselconn | awk -F [,:] '{print $2}'`
period=5

openhttps(){
     if [ $httpsmdoe = $usualmode -a $httpsperiod = $period ]
     then
     ./CLI_client https write '{"upload_mode":"svrdata"}'
     fi
 }

closehttps(){
    ./CLI_client https write '{"period":0}'
}

openpq(){
    if  [ $statusmode1 = $tlmode]
    then 
   ./CLI_client pqprobe write '{"tlenable":true,"dnsenable":true}'
   fi
}

closepq(){
    ./CLI_client pqprobe write '{"tlenable":false,"dnsenable":false}'
}

opensecdata(){
    if [ $statusmode1 = $secdatamode]
    then
    ./CLI_client pqprobe write '{"enable":true}'
    else
    echo 'sec have opend'
    fi
}

closesecdata(){
    if [ $statusmode2 = $secdatamode]
    then
    ./CLI_client pqprobe write '{"enable":false}'
    else
    echo 'sec have closed'
    fi
}

opensecbutler(){
    if [ $wanmode = $svrmode ]
    then
    ./CLI_client wan_stats wanstats_set_period '{"period":120}'
    ./CLI_client wan_stats wanstats_set_upload_mode '{"upload_mode":"operdata"}'
    fi

    if [ $lanmode = $svrmode ] 
    then
    ./CLI_client lanhost_stats lanhoststats_set_period '{"period":120}'
    ./CLI_client lanhost_stats lanhoststats_set_upload_mode '{"upload_mode":"operdata"}'
    fi
    
    if [ $tupmode = $usualmode]
    then
    ./CLI_client  tuple  write  '{"upload_mode":"operdata"}'
    fi 

    if [ $uselon = $statusmode1 ]
    then
    ./CLI_client __oper_data write '{"rules":[{"addr":"mk-collect.189smarthome.com:7890","period":120,"filter":["all"]}]}'
    else
    ./CLI_client __oper_data write '{"rules":[{"addr":"mk-collect.189smarthome.com:7890","uselconn":false,"period":120,"filter":["all"]}]}'
    fi

}

openhttps


