
#!/bin/sh
# File	: modify_fpolicy_ransomware-blocker.sh
# By	: Maarten.deBoer@Atos.net, 170704
# Subject	: SCript to modify fpolicy ransomware-blocker for OCW
PGM="`basename $0|cut -d\. -f1`"
VER="0.1"
SSH="/usr/bin/ssh -n"
FILERS="nlnaf83 nlnaf84"
CUST="ocw"
LOG="${HOME}/log/${PGM}_${CUST}.log"

REMOVEFILE="${HOME}/etc/${PGM}.remove"
ADDFILE="${HOME}/etc/${PGM}.add"

if [ ! -f ${REMOVEFILE} ] || [ ! -f ${ADDFILE} ]; then
  echo  "No ${REMOVEFILE} or ${ADDFILE} found. So exiting ..."
  exit 3
fi

echo "`date` ${PGM} c${VER} started."|tee -a ${LOG}

for FILER in ${FILERS}
do
  echo "${FILER} ..."
  ${SSH} ${FILER} "vfiler status"|grep running|grep "${CUST}"|awk '{print $1}'| while read VFILER REST
  do
    echo "${FILER}/${VFILER}:"|tee -a ${LOG}
    ${SSH} ${FILER} "vfiler run ${VFILER} fpolicy show ransomware-blocker"|tee -a ${LOG}
    echo "  Removing ..."
    cat ${REMOVEFILE}|grep -v ^# |awk '{print $1}'|while read EXT REST
    do
      echo "  Removing: ${EXT} ..."|tee -a ${LOG}
      ${SSH} ${FILER} "vfiler run ${VFILER} fpolicy extension include remove ransomware-blocker ${EXT}"|tee -a ${LOG}
    done
    echo "  Adding ..."
    cat ${ADDFILE}|grep -v ^# |awk '{print $1}'|while read EXT REST
    do
      echo "  Adding: ${EXT} ..."|tee -a ${LOG}
      ${SSH} ${FILER} "vfiler run ${VFILER} fpolicy extension include add ransomware-blocker ${EXT}"|tee -a ${LOG}
    done
    ${SSH} ${FILER} "vfiler run ${VFILER} fpolicy show ransomware-blocker"|tee -a ${LOG}
  done  # vfiler
done  # for

exit 0

