v-change-sys-ip-nat 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 definition
  10. ip=$1
  11. nat_ip=$2
  12. restart=$3
  13. # Includes
  14. source $VESTA/func/main.sh
  15. source $VESTA/func/ip.sh
  16. source $VESTA/conf/vesta.conf
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '2' "$#" 'IP NAT_IP [RESTART]'
  21. is_format_valid 'ip'
  22. is_format_valid 'nat_ip'
  23. is_ip_valid "$ip"
  24. #----------------------------------------------------------#
  25. # Action #
  26. #----------------------------------------------------------#
  27. # Changing nat ip
  28. if [ -z "$(grep NAT= $VESTA/data/ips/$ip)" ]; then
  29. sed -i "s/^TIME/NAT='$nat_ip'\nTIME/g" $VESTA/data/ips/$ip
  30. else
  31. update_ip_value '$NAT' "$nat_ip"
  32. fi
  33. # Check ftp system
  34. if [ "$FTP_SYSTEM" = 'vsftpd' ]; then
  35. # Find configuration
  36. if [ -e '/etc/vsftpd/vsftpd.conf' ]; then
  37. conf='/etc/vsftpd/vsftpd.conf'
  38. fi
  39. if [ -e '/etc/vsftpd.conf' ]; then
  40. conf='/etc/vsftpd.conf'
  41. fi
  42. # Update config
  43. if [ -z "$(grep pasv_address $conf)" ]; then
  44. if [ ! -z "$nat_ip" ]; then
  45. echo "pasv_address=$nat_ip" >> $conf
  46. fi
  47. else
  48. if [ ! -z "$nat_ip" ]; then
  49. sed -i "s/pasv_address=.*/pasv_address='$nat_ip'/g" $conf
  50. else
  51. sed -i "/pasv_address/d" $conf
  52. fi
  53. fi
  54. fi
  55. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Restart ftp server
  59. if [ "$restart" != 'no' ]; then
  60. $BIN/v-restart-ftp
  61. check_result $? "FTP restart failed" >/dev/null
  62. fi
  63. # Logging
  64. log_history "changed associated nat address on $ip to $nat_ip" '' 'admin'
  65. log_event "$OK" "$ARGUMENTS"
  66. exit