#!/bin/bash

#used for cli command "set system aaa tacacs-plus disable"
# input $1: "ture" :disable tacacs-plus
#           "false":enable tacacs-plus
#no output

if [ x"$1" == x"true" ]; then
    sed -i 's/\(.*\)account\(.*\)pam_radius_auth\(.*\)/#account\2pam_radius_auth\3/g' /etc/pam.d/common-account
    #sed -i 's/\(.*\)auth\(.*\)pam_radius_auth\(.*\)/#auth\2pam_radius_auth\3/g' /etc/pam.d/common-auth
    sed -i 's/\(#*\)\(.*\)pam_radius_auth\(.*\)/#\2pam_radius_auth\3/g' /etc/pam.d/common-auth
    sed -i 's/\(.*\)session\(.*\)pam_radius_auth\(.*\)/#session\2pam_radius_auth\3/g' /etc/pam.d/common-session

    if [ -f /var/run/sshd.pid ];then
        /etc/init.d/ssh restart > /dev/null
    fi
elif [ x"$1" == x"false" ]; then
    sed -i 's/\(^#*\)\(.*\)pam_radius_auth\(.*\)/\2pam_radius_auth\3/g' /etc/pam.d/common-account
    sed -i 's/\(^#*\)\(.*\)pam_radius_auth\(.*\)/\2pam_radius_auth\3/g' /etc/pam.d/common-auth
    sed -i 's/\(^#*\)\(.*\)pam_radius_auth\(.*\)/\2pam_radius_auth\3/g' /etc/pam.d/common-session
    
    if [ -f /var/run/sshd.pid ];then
      /etc/init.d/ssh restart > /dev/null
    fi
fi


exit 0
