#!/usr/local/bin/expect --
set timeout 40
#sets the timeout value taken by an interactive input#
set send_slow {1 .2}
#force send -s to send string with .2 sec. in between each 1 character send.#
set send_human {.1 .3 1 .05 2}
set prompt "(%|#|\\$) $" ; # default propmt
catch {set prompt $env(EXPECT_PROMPT) }
puts "Content-type: text/html\n" ;# note extra newline
puts "
Passwd change at XYZ Web site.
Operation in progress.Please wait.......
"
proc cgi2ascii {buf} {
regsub -all {\+} $buf { } buf
regsub -all {([\\["$])} $buf {\\\1} buf
regsub -all -nocase "%0d%0a" $buf "\n" buf
regsub -all -nocase {%([a-f0-9][a-f0-9])} $buf {[format %c 0x\1]} buf
eval return \"$buf\"
}
foreach pair [split [read stdin $env(CONTENT_LENGTH)] &] {
regexp (.*)=(.*) $pair dummy varname val
set val [cgi2ascii $val]
set var($varname) $val
}
log_user 0
spawn telnet 192.1.1.30
expect "login:"
send "$var(name)\r"
expect "Password:"
send "$var(old)\r"
expect {
"Login incorrect" {
puts "Incorrect login credential supplied.
"
puts "Your IP address and user name is recorded.
"
puts "You can try again."
exit
} $prompt
}
send "exit\r"
spawn telnet 192.1.1.30
expect "login:"
send "root\r"
expect "Password:"
send "pass12one\r"
expect -re $prompt
send "passwd $var(name)\r"
expect "New password:"
send "$var(new1)\r"
expect "new password"
send "$var(new2)\r"
expect {
"successfully changed" {
puts "Password changed at XYZ Site"
puts "
Goto homepage"
exit
} "try again."
}
puts ""
exit