Przeglądaj źródła

pasv_address triggers for vsftpd

Serghey Rodin 13 lat temu
rodzic
commit
fa45276267
2 zmienionych plików z 72 dodań i 2 usunięć
  1. 24 2
      bin/v-change-sys-ip-nat
  2. 48 0
      bin/v-restart-ftp

+ 24 - 2
bin/v-change-sys-ip-nat

@@ -1,6 +1,6 @@
 #!/bin/bash
 # info: change ip nat address
-# options: IP NAT_IP
+# options: IP NAT_IP [RESTART]
 #
 # The function for changing nat ip associated with ip.
 
@@ -12,6 +12,7 @@
 # Argument defenition
 ip=$1
 nat_ip=$2
+restart=$3
 
 # Includes
 source $VESTA/conf/vesta.conf
@@ -23,7 +24,7 @@ source $VESTA/func/ip.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-check_args '2' "$#" 'IP NAT_IP'
+check_args '2' "$#" 'IP NAT_IP [RESTART]'
 validate_format 'ip'
 if [ ! -z "$nat_ip" ]; then
     validate_format 'nat_ip'
@@ -42,11 +43,32 @@ else
     update_ip_value '$NAT' "$nat_ip"
 fi
 
+# Change vsftpd config
+if [ "$FTP_SYSTEM" = 'vsftpd' ]; then
+    conf="/etc/vsftpd/vsftpd.conf"
+    if [ -z "$(grep pasv_address $conf)" ]; then
+        if [ ! -z "$nat_ip" ]; then
+            echo "pasv_address=$nat_ip" >> $conf
+        fi
+    else
+        if [ ! -z "$nat_ip" ]; then
+            sed -i "s/pasv_address=.*/pasv_address='$nat_ip'/g" $conf
+        else
+            sed -i "/pasv_address/d" $conf
+        fi
+    fi
+fi
+
 
 #----------------------------------------------------------#
 #                       Vesta                              #
 #----------------------------------------------------------#
 
+# Restart ftp server
+if [ "$restart" != 'no' ]; then
+    $BIN/v-restart-ftp "$EVENT"
+fi
+
 # Logging
 log_history "changed associated nat address on $ip to $nat_ip" '' 'admin'
 log_event "$OK" "$EVENT"

+ 48 - 0
bin/v-restart-ftp

@@ -0,0 +1,48 @@
+#!/bin/bash
+# info: restart ftp service
+# options: NONE
+#
+# The function tells ftp server to reread its configuration.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Includes
+source $VESTA/conf/vesta.conf
+source $VESTA/func/main.sh
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Vsftpd
+if [ "$FTP_SYSTEM" = 'vsftpd' ]; then
+    /etc/init.d/vsftpd reload >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+        /etc/init.d/vsftpd restart >/dev/null 2>&1
+        if [ $? -ne 0 ]; then
+            exit $E_RESTART
+        fi
+    fi
+fi
+
+# ProFTPD
+if [ "$FTP_SYSTEM" = 'proftpd' ]; then
+    /etc/init.d/proftpd reload >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+        /etc/init.d/proftpd restart >/dev/null 2>&1
+        if [ $? -ne 0 ]; then
+            exit $E_RESTART
+        fi
+    fi
+fi
+
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+exit