#!/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/\(.*\)pam_tacplus\(.*\)/#\1pam_tacplus\2/g' /etc/pam.d/common-account
    #sed -i 's/\(.*\)pam_tacplus\(.*\)/#\1pam_tacplus\2/g' /etc/pam.d/common-auth
    #sed -i 's/\(.*\)pam_tacplus\(.*\)/#\1pam_tacplus\2/g' /etc/pam.d/common-session

    sed -i 's/\(.*\)account\(.*\)pam_tacplus\(.*\)/#account\2pam_tacplus\3/g' /etc/pam.d/common-account

    sed -i 's/\(#*\)\(.*\)pam_tacplus\(.*\)/#\2pam_tacplus\3/g' /etc/pam.d/common-auth

    sed -i 's/\(.*\)session\(.*\)pam_tacplus\(.*\)/#session\2pam_tacplus\3/g' /etc/pam.d/common-session

    #sed -i "s/^UsePAM.*/UsePAM no/" /etc/sshd_config 
    #kill -HUP `ps | grep -v grep | grep '/usr/sbin/sshd' | awk '{print $1}'`
    #/etc/init.d/ssh restart
    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_tacplus\(.*\)/\2pam_tacplus\3/g' /etc/pam.d/common-account
    sed -i 's/\(^#*\)\(.*\)pam_tacplus\(.*\)/\2pam_tacplus\3/g' /etc/pam.d/common-auth
    sed -i 's/\(^#*\)\(.*\)pam_tacplus\(.*\)/\2pam_tacplus\3/g' /etc/pam.d/common-session
    
    #sed -i "s/^UsePAM.*/UsePAM yes/" /etc/sshd_config 
    #kill -HUP `ps | grep -v grep | grep '/usr/sbin/sshd' | awk '{print $1}'`
    #/etc/init.d/ssh restart
    if [ -f /var/run/sshd.pid ];then
      /etc/init.d/ssh restart > /dev/null
    fi
fi


exit 0
