Current File : //root/scripts/makeaisa/csf_port_enable_tcpin.sh
#!/usr/bin/env bash
port=$1
csfconf="/etc/csf/csf.conf";
nulldata=/dev/null;
csf_st=0;

if  [ -f "$csfconf" ]
then
        if [ -f "$csfconf" ]
        then
                echo "" > $nulldata;
        else
                $csf_st=1;
        fi


        if [ $csf_st  == 0 ]
        then
                r="_back";
                n_csf_detail=$csfconf$r;
                csf_detail=$(grep -no "TCP_IN.*\""  $csfconf);
                yes | cp -avr  $csfconf $n_csf_detail  > $nulldata;
                line3=$(echo $csf_detail | awk '{print $1}' FS=":");

                if [[ $line3 = *[[:digit:]]* ]]; then
                        csf_data=$(echo $csf_detail | awk '{print $2}' FS="=" | sed -e 's/ //g' | sed 's/\"//g' | sed -e "s/\'//g" );
                        n_csf_data=$(echo $csf_data | sed -e 's/\,/ /g');
                        port_exist_status=0
                        for n_port in $n_csf_data
                        do
                                if [ $port == $n_port ]
                                then
                                        port_exist_status=1
                                fi
                        done
                        if [ $port_exist_status == 1 ]
                        then
                                echo  "PORT_EXIST_TCPIN";
                        else
                                tcp_data="TCP_IN = \"$csf_data,$port\" ";
                                sed -i "${line3}a  $tcp_data " $csfconf
                                sed -i "${line3}d"   $csfconf;
                                echo "PORT_EXIST_TCPIN";
                        fi

                else
                        echo "TCP_IN = \"$port\" " >>$csfconf;
                        echo "PORT_EXIST_TCPIN";
                fi
                        csf -r >$nulldata;

        else
                echo "CSF_FILE_NOT_EXIST";
        fi

else
        echo "CSF_FILE_NOT_EXIST";
fi