#!/bin/bash
#**********一键配置主机名,IP,agent序列号,安全加固-UTF-8版本******************
#******************************************************************
REDC='\E[1;31m'
GREENC='\E[1;32m'
YELLOWC='\E[1;33m'
BLUEC='\E[1;34m'
PINKC='\E[1;35m'
RES='\E[0m'
PURPLE='\033[35m'

TMPFILE="./tmp_file"
HOSTNAME="/etc/hostname"
INTERFACE="/etc/network/interfaces"
INTERFACE_BAK="/etc/network/interfaces-sys-use"
LINXSNFILE="/etc/linxsn/security_sn.conf"
COMPLETEFILE="/opt/security/complete_security_config.sh"
SIMPLEFILE="/opt/security/simple_security_config.sh"
BACK_SIMPLE="/opt/security/simple_backup/.simple"
BACK_COMPLETE="/opt/security/complete_backup/.complete"
LINXSN="/proc/linxsn_info"
SSHD_CONFIG="/etc/ssh/sshd_config"
PUB="PubkeyAuthentication yes"
AUTH="AuthorizedKeysFile .ssh/authorized_keys"
RESTART_SSH="/etc/init.d/ssh restart"
USBFS="usbfs"
USERGROUP="/etc/group"
FSTAB="/etc/fstab"
DNS_CONFIG="/etc/resolv.conf"
FAILED="\Z1失败!"
SUCCESS="\Z2成功!"
NO_INTERFACES="dialog --colors --msgbox ""\Z1"没有发现interfaces文件及其备份文件,无法进行IP配置!" 5 55"
YESNO="dialog  --clear --colors  --title "继续/返回" --yesno ""\Z1"注意!当前系统未配置凝思系统序列号,网络配置无法生效,是否继续?" 7 51"
AUTO_DESCRIPTION="dialog  --colors  --title "批量配置IP说明"  --msgbox ""\Z2"批量配置会将您手动输入的IP地址和子网掩码,按网段加一进行配置."\n"比如:输入IP子网掩码为:172.16.2.3/255.255.0.0"\n"则最终网口配置如下:"\n"eth0:172.16.2.3/255.255.0.0"\n"eth1:172.17.2.3/255.255.0.0"\n"eth2:172.18.2.3/255.255.0.0"\n"..." 13 55"
MANUAL_DESCRIPTION="dialog  --colors  --title "手动配置IP说明"  --msgbox ""\Z2"手动配置是针对特定网口进行配置."\n"会按照选择网口"-->"输入IP"-->"输入子网掩码的顺序进行配置网口." 7 55"

#变量里面附加了变量,不能直接标明.
env()
{
IP_INVALID="dialog --colors --msgbox ""\Z1"输入的IP地址无效!"\n""\n"您输入的IP地址如下:"\n""$ip_addr""\n""\n"请按照以下模型输入:"\n"172.20.0.41"\n"172.21.0.41"\n"100.100.101.21"\n"100.100.102.21"\n"xxx.xxx.xxx.xxx"\n"..." 17 25"

DNS_INVAILID="dialog --colors --msgbox ""\Z1"输入的DNS服务器IP地址无效!"\n""\n"您输入的IP地址如下:"\n""$dns_address""\n""\n"请按照以下模型输入:"\n"8.8.8.8"\n"114.114.114.114"\n"以及自定义的DNS服务器ip地址"\n"..." 17 25"

MASK_INVALID="dialog --colors --msgbox ""\Z1"输入的子网掩码无效!"\n""\n"您输入的子网掩码如下:"\n""$net_mask""\n"请按照以下模型输入:"\n"255.255.255.0"\n"255.255.0.0"\n"255.254.0.0"\n"255.252.0.0"\n"255.248.0.0"\n"255.240.0.0"\n"255.0.0.0"\n"..." 17 25"

MANUAL_IP=" ""\Z2"配置"$net"成功!"\n"ip:"$ip_addr""\n"netmask:"$net_mask"""
}
#***************************************************************************

[ -f /etc/init.d/functions ] && . /etc/init.d/functions

#按ESC直接退出配置脚本
function esc_abort(){
  status=$1
  if [ $status == "255" ];then
	clear 
  	echo -e "$GREENC 退出程序!(ESC) $RES"
   	exit
  fi
}
#对话框输入函数
#param $1:标题名 $2:左上角提示 $3:默认值
function inputbox(){
	dialog --title "$1" --clear --inputbox "$2" 10 51 $3 2>tmp.file
}
#dialog打印函数
#param$1 $2
function dialog_display() { 
  if [ $3 == "1" ] ;then
	dialog --colors --title "$1" --no-collapse    --msgbox "$2" 7 50   
  else
	dialog --colors --title "$1" --no-collapse    --msgbox "$2" 5 46   
  fi
}
#echo打印函数
function echo_display(){
	echo -e "$GREENC $1 $RES"
} 
#*****************主机名Ip配置************************
#检测ip和子网掩码的合法性
#param $1 flag $2 输入ip或者子网掩码
function ip_netmask_check(){
  if [ $1 == "ip" ];then
    ip_addr=`cat tmp.file`
    env
    length_ip=`echo ${#ip_addr}`
    if [[ ! $length_ip -gt "15" && ! $length_ip -lt "8" ]];then
      for i in `echo  $ip_addr | awk -F. '{print $1,$2,$3,$4}'`
      do
          expr $i + 0 &>/dev/null
          isinteg=$?
          if [[ $isinteg != "0" && $isinteg != "1" ]];then
              $IP_INVALID
              return 1
          fi
          if [  $i -gt "254" ];then
              $IP_INVALID
              return 1
          fi
      done
    else
      $IP_INVALID
      return 1 
    fi
  elif [ $1 == "netmask" ];then
	net_mask=`cat tmp.file`
	env
	num=0
	for i in `echo  $net_mask | awk -F. '{print $1,$2,$3,$4}'`
 	do
  	   expr $i + 0 &>/dev/null
       isinteg=$?
       if [[ $isinteg != "0"  && $isinteg != "1" ]];then
           $MASK_INVALID #是否为整数
           return 1
       fi
       if [ ! $i -gt "255" ];then
           if [ $i == "255" ];then
               num=`expr $num + 8`
           elif [ $i == "254" ];then
               num=`expr $num + 7`
           elif [ $i == "252" ];then
               num=`expr $num + 6`
           elif [ $i == "248" ];then
               num=`expr $num + 5`
           elif [ $i == "240" ];then
               num=`expr $num + 4`
           elif [ $i == "224" ];then
               num=`expr $num + 3`
           elif [ $i == "192" ];then
               num=`expr $num + 2`
           elif [ $i == "128" ];then
               num=`expr $num + 1`
           elif [ $i == "0" ];then
               break #遇到第一个为0的字段则表示后面全是0,否则是输入错误的问题.
           else
               $MASK_INVALID
               return 1
           fi
       else
           $MASK_INVALID
           return 1
       fi
    done
 		 return $num
  else
	return 
  fi
}

#判断是否有eth*可用网口
#param $1:网口
function eth_exist(){
  netlist1=`ifconfig -a | grep eth | awk '{print $1}'`
  echo $netlist1 > $TMPFILE
  grep $1  $TMPFILE
  if [ $? != "0" ];then
 	rm $TMPFILE	
 	return 1
  fi  
 	rm $TMPFILE
 	return 0 
}

#配置主机名
function manual_config_host (){
  inputbox "主机名设置" "请输入主机名:"
  status=$?
  if [ $status == "1" ];then
  	return
  fi
  esc_abort $status
  host_name=`cat tmp.file`
  echo_display "正在配置主机名..."
  sleep 0.5
  hostname $host_name 
  echo "$host_name" > $HOSTNAME
  if [ $? != "0" ];then
  	dialog_display $FAILED  "\Z1配置主机名失败,请检查权限等问题!" "1" 
  else
  	dialog_display $SUCCESS "\Z2配置主机名成功!\n主机名:$host_name" "1" 
  fi
  rm tmp.file
}
#配置DNS服务
function manual_config_dns (){

inputbox "DNS设置" "请输入DNS服务器IP地址:"
  status=$?
  if [ $status == "1" ];then
    return
  fi  
  esc_abort $status
 dns_address=`cat tmp.file` 
 dns_nameserver="nameserver $dns_address"
 env 
 #检查dnsip的合法性
 length_dns=`echo ${#dns_address}`
 if [[ ! $length_dns -gt "15" && ! $length_dns -lt "7" ]];then

  for i in `echo  $dns_address | awk -F. '{print $1,$2,$3,$4}'`
  do  
     expr $i + 0 &>/dev/null
     isinteg=$?
     if [[ $isinteg != "0"  && $isinteg != "1" ]];then
        $DNS_INVAILID
        return
     fi  
     if [  $i -gt "254" ];then
        $DNS_INVAILID
        return
     fi  
 
  done  
 else
    $DNS_INVAILID
    return
 fi
echo_display "正在配置DNS服务..."
  sleep 0.5 

  if [ -f $DNS_CONFIG ];then
    rm -rf $DNS_CONFIG
  fi  
  touch $DNS_CONFIG
  echo "$dns_nameserver"  > $DNS_CONFIG

  if [ $? != "0" ];then
    dialog_display $FAILED  "\Z1配置DNS服务失败,请检查权限等问题!" "1" 
  else
    dialog_display $SUCCESS "\Z2配置DNS服务成功!\nDNS服务器IP:$dns_address" "1" 
  fi  
  rm tmp.file
#  nameserver=`grep "nameserver"  $DNS_CONFIG -R`
#  if [ -z "$nameserver" ];then
#       echo "$dns_nameserver" >> $DNS_CONFIG
#       echo_display "$nameserver"
#           sleep 1
#  else
#       sed -i "s/$nameserver/$dns_nameserver/g" $DNS_CONFIG
#  fi
}

#手动配置IP,netmask
function manual_config_ip(){
  $MANUAL_DESCRIPTION
  #判断是否添加了凝思序列号
  if [ ! -f $LINXSN ];then
	$YESNO
	status=$?
	if [ $status == "1" ];then
		return
	fi
	esc_abort $status
  fi
  inputbox "IP设置" "请输入需要配置的网口(默认eth0):" "eth0"
  status=$?
  if [ $status == "1" ];then
  	return
  fi
  esc_abort $status
  net=`cat tmp.file`
  eth_exist $net
  if [ $? == "1" ];then
  	dialog_display $FAILED "\Z1当前输入网口(:$net)不可用,请重新输入!"
  	return
  fi 
  
  inputbox "IP设置" "请输入IP(格式:xxx.xxx.xxx.xxx):"
  status=$?
  #判断Ip合法性,做基本情况处理(1.是否整数2.长度3.ip范围.未覆盖全部)
  if [ $status == "1" ];then
  	return
  fi
  esc_abort $status

  ip_addr=`cat tmp.file`
  env
  ip_netmask_check "ip" $ip_addr 
  if [ $? == "1" ];then
 	return
  fi  

  inputbox "子网掩码设置" "请输入子网掩码(默认255.255.0.0):" "255.255.0.0"
  status=$?
  if [ $status == "1" ];then
  	return
  fi
  esc_abort $status
  net_mask=`cat tmp.file`
  env
  ip_netmask_check "netmask" $net_mask
  num=$?
  if [ $num == "1" ];then
 	return
  fi  
  echo_display "正在配置IP..."
  sleep 1
  #判断是否有Interfaces文件存在,不存在则拷贝interfaces-sys-use
  netlist=`ifconfig -a | grep eth | awk '{print $1}'` 
  if [ ! -f $INTERFACE ];then
	if [ -f $INTERFACE_BAK ];then
		cp $INTERFACE_BAK $INTERFACE
  		chown root:netadmin $INTERFACE
  		chmod 664 $INTERFACE
	else
		$NO_INTERFACES
		return
	fi
  fi
  num_auto=`grep -o "auto " $INTERFACE | wc -l`
  if [ $num_auto == "1" ];then 
  	echo -n "auto " >> $INTERFACE
  	for network in $netlist
      do  
      	echo -n "$network " >> $INTERFACE
  	done
  fi	
  grep "iface $net" $INTERFACE 
  
  if [ $? == "0" ];then
  	ifconfig $net $ip_addr/$num
  	sed -i '/iface '"$net"' /{n;d}' $INTERFACE
  	sed -i '/iface '"$net"' /{n;d}' $INTERFACE
  	sed -i '/iface '"$net"'/a\\ \tnetmask '"$net_mask"'' $INTERFACE
  	sed -i '/iface '"$net"'/a\\ \taddress '"$ip_addr"'' $INTERFACE
  	dialog_display $SUCCESS  $MANUAL_IP "1"
  else
  	ifconfig $net $ip_addr/$num	
  	echo -e "\niface $net inet static" >> $INTERFACE
  	echo -e "\taddress $ip_addr" >> $INTERFACE
  	echo -e "\tnetmask $net_mask" >> $INTERFACE	
  	dialog_display $SUCCESS  $MANUAL_IP "1"
  fi
  rm tmp.file
}

#自动批量配置IP
function auto_config_ip (){
  $AUTO_DESCRIPTION
  #判断是否添加了凝思序列号
  if [ ! -f $LINXSN ];then
	$YESNO
	status=$?
	if [ $status == "1" ];then
		return
	fi
	esc_abort $status
  fi
  eth_exist "eth"
  if [ $? == "1" ];then
    dialog_display $FAILED "\Z1未发现可用网口!"
    return
  fi

  #ip配置
  inputbox "IP设置" "请输入IP(格式:xxx.xxx.xxx.xxx):" 
  status=$?
  #判断Ip合法性,做基本情况处理(1.是否整数2.长度3.ip范围.未覆盖全部)
  if [ $status == "1" ];then
    return
  fi
  esc_abort $status
  ip_addr=`cat tmp.file`
  env
  ip_netmask_check "ip" $ip_addr 
  if [ $? == "1" ];then
 	return
  fi  

  inputbox "子网掩码设置" "请输入子网掩码(默认255.255.0.0):" "255.255.0.0"
  status=$?
  if [ $status == "1" ];then
    return
  fi
  esc_abort $status
  net_mask=`cat tmp.file`
  env
  ip_netmask_check "netmask" $net_mask
  num=$?
  if [ $num == "1" ];then
 	return
  fi  
  echo_display "正在批量配置IP..."
  sleep 1

  if [ -f $INTERFACE ];then
     rm -f $INTERFACE
  fi
  if [ ! -f $INTERFACE_BAK ];then
     touch $INTERFACE $INTERFACE_BAK
     echo -e  "auto lo\n" >> $INTERFACE_BAK
     echo -e  "iface lo inet loopback\n" >> $INTERFACE_BAK
  fi
  cp $INTERFACE_BAK $INTERFACE
  chown root:netadmin $INTERFACE
  chmod 664 $INTERFACE
  
  if [ -f $INTERFACE ];then
 	 DefaultIp=$ip_addr
 	 netlist=`ifconfig -a | grep eth | awk '{print $1}'`
 	 echo -n "auto " >> $INTERFACE
 	 for network in $netlist
 	 do
   	 	echo -n "$network " >> $INTERFACE
 	 done
 
	 for network in $netlist
 	 do
  	 	ifconfig $network $DefaultIp/$num
   	 	echo -e "\niface $network inet static" >> $INTERFACE
   	 	echo -e "\taddress $DefaultIp" >> $INTERFACE
   	 	echo -e "\tnetmask $net_mask" >> $INTERFACE
   	 	DefaultIp=`echo $DefaultIp | awk ' BEGIN{FS=OFS="."}{$2+=1;print}'`
 	 done	
  else
     $NO_INTERFACES
  fi
  dialog_display $SUCCESS  "\Z2批量配置IP成功!"
}
 
#配置IP主机名主菜单
function config_ip_host (){
  while true;do
   exec 3>&1
   SELECT1=$(dialog --title "IP主机名配置" --clear --menu  "请选择:" 20 70 5 \
		"1" "自动批量配置网口IP" \
   		"2" "手动配置特定网口IP" \
   		"3" "DNS配置" \
   		"4" "配置主机名" \
   		"5" "返回上一级菜单" 2>&1 1>&3 )
	status=$?
  	esc_abort $status
  	case $SELECT1 in
		1)
  		auto_config_ip
  		;;	
  		2)
  		manual_config_ip
  		;;
  		3)
  		manual_config_dns
  		;;
  		4)
  		manual_config_host
  		;;
  		5)
  		clear
  		break	
  		;;	
  	esac		
  done
}
 #****************************************************
 #****************序列号菜单**************************
function add_serial_number(){
  inputbox "Agent序列号设置" "请输入序列号(16位字母数字组合):"
  status=$?
  if [ $status == "1" ];then
  	return
  fi
  esc_abort $status
  
  serial_number=`cat tmp.file`
  echo_display "正在配置agent序列号..."
  sleep 1
  #序列号输入检测(位数.字符)
  echo $serial_number | grep -q '^[a-zA-Z0-9]\+$'
  status=$?
  length_number=`echo ${#serial_number}`
  if [[ $length_number != "16" || $status != "0"  ]];then
  	dialog_display $FAILED "\Z1agent序列号输入格式或长度有误,请重新输入!"
	return
  fi
   
  if [ ! -f $LINXSNFILE ];then
  	touch $LINXSNFILE
  fi
  
  echo "linx_serial=$serial_number" > $LINXSNFILE
  
  if [ $? != "0" ];then
  	dialog_display $FAILED "\Z1配置agent序列号失败,请检查权限等问题!"  
  else
  	dialog_display $SUCCESS "\Z2配置agent序列号成功!"  
  fi
   rm tmp.file
}
 
function config_serial_number(){
  while true;do
  	exec 3>&1
    SELECT2=$(dialog --title "agent序列号设置" --clear --menu  "请选择:" 16 40 2 \
                    "1" "添加序列号" \
                    "2" "返回上一级菜单" 2>&1 1>&3 ) 
  	status=$?
  	esc_abort $status
  	case $SELECT2 in 
      	1)
  	    add_serial_number
      	;;
  	    2)
  		clear
  	    break
  	    ;;
  	esac
  done
}
 #****************************************************
 #***************安全加固菜单**************************
function add_no_passwd(){
  #num=`grep "PubkeyAuthentication" $SSHD_CONFIG  -R | wc -l`
  pub=`grep "PubkeyAuthentication" $SSHD_CONFIG  -R`
  auth=`grep "AuthorizedKeysFile" $SSHD_CONFIG  -R`
  if [[ -z "$pub" && -z "$auth" ]];then
  	echo "$PUB" >> $SSHD_CONFIG
  	echo "$AUTH" >> $SSHD_CONFIG
  else
  	sed -i "s/$pub/$PUB/g" $SSHD_CONFIG
  	sed -i '/AuthorizedKeysFile/d' $SSHD_CONFIG
	sed -i '/PubkeyAuthentication/a\'"$AUTH"'' $SSHD_CONFIG
  fi
  $RESTART_SSH
}

function security(){
  if [[ -f $COMPLETEFILE && -f $SIMPLEFILE ]];then
  
  	if [ $1 == "complete-install" ];then
    	if [ -f $BACK_SIMPLE  ];then
  			dialog_display $FAILED	"\Z1系统已经进行了简单加固!"		
        elif [ ! -f $BACK_COMPLETE ];then
  			echo_display "正在执行完整安全加固..."
            sleep 1
            echo "config" > tmpfile
            $COMPLETEFILE  < tmpfile

			#安全加固依然能够免密登录
			add_no_passwd
  			dialog_display $SUCCESS	"\Z2完整加固完成!"		
        else
  			dialog_display $FAILED	"\Z1系统已经进行了完整加固!"		
        fi
  
  	elif [ $1 == "simple-install" ];then
          if [  -f $BACK_COMPLETE  ];then
  			   dialog_display $FAILED	"\Z1系统已经进行了完整加固!"		
          elif [ ! -f $BACK_SIMPLE ];then
  		       echo_display "正在执行简单安全加固..."
               sleep 1 
               echo "config" > tmpfile
               $SIMPLEFILE <  tmpfile
		       #安全加固依然能够免密登录
	     	   add_no_passwd
  		       dialog_display $SUCCESS	"\Z2简单加固完成!"		
          else
  		       dialog_display $FAILED	"\Z1系统已经进行了简单加固!"		
          fi
  
    elif [ $1 == "complete-delete" ];then
          if [  -f $BACK_COMPLETE ];then
  		      echo_display "正在卸载完整安全加固..."
              sleep 1 
              echo "recover" > tmpfile
              $COMPLETEFILE < tmpfile
  			  dialog_display $SUCCESS	"\Z2完整安全加固卸载完成!"		
          elif [  -f $BACK_SIMPLE ];then
  			  dialog_display $FAILED "\Z1系统已经进行了简单安全加固,请卸载简单加固!"
          else
  			  dialog_display $FAILED  "\Z1系统未进行或者已经卸载了完整加固,请确认!"
          fi
  
     elif [ $1 == "simple-delete" ];then
          if [  -f $BACK_SIMPLE ];then
  	     	  echo_display "正在卸载简单安全加固..."
              sleep 1
              echo "recover" > tmpfile
              $SIMPLEFILE < tmpfile
  			  dialog_display $SUCCESS	"\Z2简单安全加固卸载完成!"		
          elif [  -f $BACK_COMPLETE ];then
  			  dialog_display $FAILED  "\Z1系统已经进行了完整安全加固,请卸载完整加固!"
          else
  			  dialog_display $FAILED "\Z1系统未进行或者已经卸载了简单加固,请确认!"
          fi
      else
  		  dialog_display $FAILED "没有该选项!"
      fi
  else
  	  dialog_display $FAILED "\Z1安全加固脚本不存在,请确认!"
  fi
 }
 
function delete_security(){
  while true ;do
  	exec 3>&1
 	SELECT5=$(dialog --title "卸载安全加固" --clear --menu  "请选择:" 16 40 4 \
                  "1" "卸载完整加固" \
                  "2" "卸载简单加固" \
  			      "3" "返回上一级菜单" \
				  "4" "返回主菜单"    2>&1 1>&3 )
  	status=$?
  	esc_abort $status
  	case $SELECT5 in
  	  1)
  	   security "complete-delete"
  	   ;;
  	  2)
  	   security "simple-delete"
  	   ;;
  	  3)
  	   clear
  	   break
  	   ;;
  	  4)
  	   clear
  	   flag=1
  	   break
  	   ;;
  	esac
  done
}
 
function add_security(){
  while true ;do
  	exec 3>&1
    SELECT4=$(dialog --title "执行安全加固" --clear --menu  "请选择:" 16 40 4 \
                  "1" "完整安全加固" \
                  "2" "简单安全加固" \
    			  "3" "返回上一级菜单" \
				  "4" "返回主菜单"    2>&1 1>&3 )    
  	status=$?
  	esc_abort $status
  	case $SELECT4 in
  	  1)
  	   security "complete-install"
  	   ;;
  	  2)
  	   security "simple-install"
  	   ;;
  	  3)
  	   clear
  	   break
  	   ;;
  	  4)
  	   clear
  	   flag=1
  	   break
  	   ;;
  	esac
  done
}
 
function config_security(){
  while true;do
	if [ $flag == "1" ];then
 		flag=0
  	    break
 	fi
 	exec 3>&1
    SELECT3=$(dialog --title "安全加固内容配置" --clear --menu  "请选择:" 16 40 3 \
                  "1" "执行安全加固" \
                  "2" "卸载安全加固" \
				  "3" "返回上一级菜单" 2>&1 1>&3  )
  	status=$?
  	esc_abort $status
    case $SELECT3 in
        1)
        add_security 
        ;;
        2)
        delete_security 
        ;;
        3)
        clear
        break
        ;;
    esac
  done
 }
 #****************************************************

function config_usb_fingerprint(){
  inputbox "USB指纹仪支持配置" "请输入您需要使用指纹仪的普通用户:"
  status=$?
  if [ $status == "1" ];then
    return
  fi  
  esc_abort $status
  user=`cat tmp.file`
  echo_display "正在进行USB指纹仪支持配置..."
  sleep 1
  #adduser $user
  egrep "^$USBFS" $USERGROUP >& /dev/null
  if [ $? -ne 0 ]
  then
  	groupadd $USBFS
  fi

  useradd $user -g $USBFS -m
  gid=`cat $USERGROUP | grep $USBFS | tr -cd "[0-9]"`

  egrep "none /proc/bus/usb usbfs devgid=$gid" $FSTAB >& /dev/null
  if [ $? -ne 0 ]
  then
	echo "# $gid is the USB group ID" >> $FSTAB
  	echo "none /proc/bus/usb usbfs devgid=$gid,devmode=664 0 0" >> $FSTAB
  fi
  
  	dialog_display $SUCCESS  "\Z2USB指纹仪的支持配置成功!\n已经将$user用户加入到$USBFS用户组中去.\n更改$user密码,使用'passwd $user'命令." "1"

} 
 #****************主菜单*******************************
if [ `whoami` != "root"  ];then
	echo -e "$REDC请在root用户下执行! $RES"
	exit
fi

 while true;do
 	exec 3>&1
	SELECT=$(dialog --title "请选择你需要的配置"  --clear --menu "请选择:" 16 40 5 \
				  "1" "IP主机名配置" \
 				  "2" "Agent序列号配置" \
 				  "3" "安全加固配置" \
 				  "4" "USB指纹仪支持配置" \
 				  "5" "退出"  2>&1 1>&3 )
 	status=$?
 	esc_abort $status
 	case $SELECT in 
 		1)
 		config_ip_host
 		;;
 		2)
 		config_serial_number 	
 		;;
 		3)
 		config_security
 		;;
 		4)
 		config_usb_fingerprint
 		;;
 		5)
 		clear
 		exit
 		;;
 	esac
 done
