v-change-sys-ip-nat 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. # info: change ip nat address
  3. # options: IP NAT_IP [RESTART]
  4. #
  5. # The function for changing nat ip associated with ip.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. ip=$1
  11. nat_ip=$2
  12. restart=$3
  13. # Includes
  14. source $VESTA/conf/vesta.conf
  15. source $VESTA/func/main.sh
  16. source $VESTA/func/ip.sh
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '2' "$#" 'IP NAT_IP [RESTART]'
  21. validate_format 'ip'
  22. if [ ! -z "$nat_ip" ]; then
  23. validate_format 'nat_ip'
  24. fi
  25. is_ip_valid
  26. #----------------------------------------------------------#
  27. # Action #
  28. #----------------------------------------------------------#
  29. # Changing nat ip
  30. if [ -z "$(grep NAT= $VESTA/data/ips/$ip)" ]; then
  31. sed -i "s/^TIME/NAT='$nat_ip'\nTIME/g" $VESTA/data/ips/$ip
  32. else
  33. update_ip_value '$NAT' "$nat_ip"
  34. fi
  35. # Change vsftpd config
  36. if [ "$FTP_SYSTEM" = 'vsftpd' ]; then
  37. conf="/etc/vsftpd/vsftpd.conf"
  38. if [ -z "$(grep pasv_address $conf)" ]; then
  39. if [ ! -z "$nat_ip" ]; then
  40. echo "pasv_address=$nat_ip" >> $conf
  41. fi
  42. else
  43. if [ ! -z "$nat_ip" ]; then
  44. sed -i "s/pasv_address=.*/pasv_address='$nat_ip'/g" $conf
  45. else
  46. sed -i "/pasv_address/d" $conf
  47. fi
  48. fi
  49. fi
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. # Restart ftp server
  54. if [ "$restart" != 'no' ]; then
  55. $BIN/v-restart-ftp "$EVENT"
  56. fi
  57. # Logging
  58. log_history "changed associated nat address on $ip to $nat_ip" '' 'admin'
  59. log_event "$OK" "$EVENT"
  60. exit