Files
nokia-auto-vpn/run.exp
2025-08-26 18:10:53 +02:00

50 lines
1.0 KiB
Plaintext
Executable File

#!/usr/bin/expect -f
#
# Usage:
# vpn-auto.exp <connection-name> <vpn-user> <vpn-pass> <otp-secret>
#
# Example:
# ./vpn-auto.exp PEM_PASS VPN_USER VPN_PASS MS_AUTH_OTP
# ./vpn-auto.exp pass1234 zsolt.alfoldi@nokia.com 1234pass 987456
# never timeout
set timeout -1
# pull args off the command line
if { $argc != 4 } {
puts stderr "Usage: $argv0 <vpn-name> <user> <pass> <otp-secret>"
exit 1
}
lassign $argv vpn_pem_pass vpn_user vpn_pass otp
# start the connection
spawn nmcli connection up Nokia --ask
# watch for the prompts and supply answers
expect {
-re "Enter PEM pass phrase" {
send "$vpn_pem_pass\r"
exp_continue
}
-re "Username:" {
send "$vpn_user\r"
exp_continue
}
-re "PASSCODE:" {
send "$vpn_pass\r"
exp_continue
}
-re "Response:" {
send "$otp\r"
exp_continue
}
-re "Login failed." {
send_user "Detected: Login failed. Exiting.\n"
close
wait
exit 1
}
eof
}