v-change-sys-ip-nat 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/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. 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. # Check ftp system
  36. if [ "$FTP_SYSTEM" = 'vsftpd' ]; then
  37. # Find configuration
  38. if [ -e '/etc/vsftpd/vsftpd.conf' ]; then
  39. conf='/etc/vsftpd/vsftpd.conf'
  40. fi
  41. if [ -e '/etc/vsftpd.conf' ]; then
  42. conf='/etc/vsftpd.conf'
  43. fi
  44. # Update config
  45. if [ -z "$(grep pasv_address $conf)" ]; then
  46. if [ ! -z "$nat_ip" ]; then
  47. echo "pasv_address=$nat_ip" >> $conf
  48. fi
  49. else
  50. if [ ! -z "$nat_ip" ]; then
  51. sed -i "s/pasv_address=.*/pasv_address='$nat_ip'/g" $conf
  52. else
  53. sed -i "/pasv_address/d" $conf
  54. fi
  55. fi
  56. fi
  57. #----------------------------------------------------------#
  58. # Vesta #
  59. #----------------------------------------------------------#
  60. # Restart ftp server
  61. if [ "$restart" != 'no' ]; then
  62. $BIN/v-restart-ftp
  63. if [ $? -ne 0 ]; then
  64. exit E_RESTART
  65. fi
  66. fi
  67. # Logging
  68. log_history "changed associated nat address on $ip to $nat_ip" '' 'admin'
  69. log_event "$OK" "$EVENT"
  70. exit