#!/usr/bin/expect --
#!/bin/sh
set port [lrange $argv 0 0]
set username [lrange $argv 1 1]
set remoteHost [lrange $argv 2 2]
set password [lrange $argv 3 3]

spawn /usr/bin/ssh -f -NR "*:$port:localhost:22" $username@$remoteHost
match_max 100000;
set timeout 60;
expect {
    "?sh: Error*"
        { puts "CONNECTION_ERROR"; exit; }
    "*yes/no*"
        { send "yes\r"; exp_continue; }
    "*?assword:*" {
         send "$password\r"; set timeout 4;
         expect "*?assword:*" { puts "WRONG_PASSWORD"; exit; }
    }
}