I have this Expect TCL script which is working but I need a small alteration.
#!/usr/bin/expect --
puts "Content-type: text/html\n" ;# note extra newline
puts "
<head>
<title>Password Change Result</title>
</head>
<h2>Password Change Result</h2>
"
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
proc errormsg {s} {puts "<h3>Password Not Changed: $s</h3>"}
proc successmsg {s} {puts "<h3>$s</h3>"}
spawn /bin/su $var(name) -c "/usr/bin/passwd $var(name)"
expect {
"/bin/su:" {
errormsg "check your username"
exit
} default {
errormsg "$expect_out(buffer)"
exit
} "Password:"
}
send "$var(old)\r"
expect {
"/bin/su:" {
errormsg "old password incorrect"
exit
} default {
errormsg "$expect_out(buffer)"
exit
} "password:"
}
send "$var(old)\r"
expect "password:"
send "$var(new1)\r"
expect "password:"
send "$var(new2)\r"
close
wait
if {[info exists error]} {
errormsg "$error"
} else {
successmsg "Password changed successfully</p>
Please login with your new details"
}
If the security requirements are not met on the new password the script still reports the password was changed. If the password is not changed passwd reports:
passwd: "the error"
I need the script to not say the password was changed or not. If "passwd:" was the last message then error else give the success message.
Thanks
Dean.[/code]