Procházet zdrojové kódy

Fix/4492 remove duplicate sftpc (#4493)

* Check if this potensially works

* Remove duplicated code

* Source backup.sh
Jaap Marcus před 1 rokem
rodič
revize
82f42ce646
1 změnil soubory, kde provedl 12 přidání a 117 odebrání
  1. 12 117
      bin/v-add-backup-host

+ 12 - 117
bin/v-add-backup-host

@@ -29,6 +29,8 @@ arch=$(arch)
 source /etc/hestiacp/hestia.conf
 # shellcheck source=/usr/local/hestia/func/main.sh
 source $HESTIA/func/main.sh
+# shellcheck source=/usr/local/hestia/func/backup.sh
+source $HESTIA/func/backup.sh
 # load config file
 source_conf "$HESTIA/conf/hestia.conf"
 # Fetch current verison B2 CLI tool
@@ -38,123 +40,6 @@ source_conf "$HESTIA/install/upgrade/upgrade.conf"
 b2cli="/usr/local/bin/b2"
 b2lnk="https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v$b2_v/b2-linux"
 
-# Defining ftp command function
-ftpc() {
-	ftp -p -n $host $port << EOF
-    quote USER $user
-    quote PASS $password
-    binary
-    $1
-    $2
-    $3
-    quit
-EOF
-}
-
-# Defining sftp command function
-sftpc() {
-	if [ "$privatekey" != "yes" ]; then
-		expect -f "-" "$@" << EOF
-        set count 0
-        spawn /usr/bin/sftp -o StrictHostKeyChecking=no -o Port=$port $user@$host
-        expect {
-            -nocase "password:" {
-                send "$password\r"
-                exp_continue
-            }
-
-            -re "Password for (.*)@(.*)" {
-                send "$password\r"
-                exp_continue
-            }
-
-            -re "Couldn't|(.*)disconnect|(.*)stalled|(.*)not found" {
-                set count \$argc
-                set output "Disconnected."
-                set rc $E_FTP
-                exp_continue
-            }
-
-            -re ".*denied.*(publickey|password)." {
-                set output "Permission denied, wrong publickey or password."
-                set rc $E_CONNECT
-            }
-
-            "sftp>" {
-                if {\$count < \$argc} {
-                    set arg [lindex \$argv \$count]
-                    send "\$arg\r"
-                    incr count
-                } else {
-                    send "exit\r"
-                    set output "Disconnected."
-                    if {[info exists rc] != 1} {
-                        set rc $OK
-                    }
-                }
-                exp_continue
-            }
-
-            timeout {
-                set output "Connection timeout."
-                set rc $E_CONNECT
-            }
-        }
-
-        if {[info exists output] == 1} {
-            puts "\$output"
-        }
-
-        exit \$rc
-EOF
-	else
-		expect -f "-" "$@" << EOF
-            set count 0
-            spawn /usr/bin/sftp -o StrictHostKeyChecking=no -o Port=$port -i $raw_password $user@$host
-            expect {
-
-                -re "Couldn't|(.*)disconnect|(.*)stalled|(.*)not found" {
-                    set count \$argc
-                    set output "Disconnected."
-                    set rc $E_FTP
-                    exp_continue
-                }
-
-                -re ".*denied.*(publickey|password)." {
-                    set output "Permission denied, wrong publickey or password."
-                    set rc $E_CONNECT
-                }
-
-                "sftp>" {
-                    if {\$count < \$argc} {
-                        set arg [lindex \$argv \$count]
-                        send "\$arg\r"
-                        incr count
-                    } else {
-                        send "exit\r"
-                        set output "Disconnected."
-                        if {[info exists rc] != 1} {
-                            set rc $OK
-                        }
-                    }
-                    exp_continue
-                }
-
-                timeout {
-                    set output "Connection timeout."
-                    set rc $E_CONNECT
-                }
-            }
-
-            if {[info exists output] == 1} {
-                puts "\$output"
-            }
-
-            exit \$rc
-EOF
-	fi
-}
-
 #----------------------------------------------------------#
 #                    Verifications                         #
 #----------------------------------------------------------#
@@ -201,6 +86,12 @@ if [ "$type" = 'ftp' ]; then
 	if [ -z $port ]; then
 		port=21
 	fi
+	PORT=$port
+	USERNAME=$user
+	PASSWORD=$password
+	HOST=$host
+	PRIVATEKEY=$privatekey
+
 	fconn=$(ftpc 2>&1)
 	ferror=$(echo $fconn \
 		| grep -i -e failed -e error -e "can't" -e "not conn" -e "incorrect")
@@ -231,6 +122,10 @@ if [ "$type" = 'sftp' ]; then
 	if [ -z $port ]; then
 		port=22
 	fi
+	PORT=$port
+	USERNAME=$user
+	PASSWORD=$password
+	HOST=$host
 	if [ -z $path ]; then
 		sftmpdir="vst.bK76A9SUkt"
 		sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1