This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

CGI Expect TCL Script Help

Old posts that have not been replied to for several years.
Locked
p
pug306d

CGI Expect TCL Script Help

Post by pug306d »

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]
p
pug306d

Post by pug306d »

if anyone can help me get this working or write something that will work then please contact me with a offer on dean_dodd at yahoo.com

I'm hoping to get a script working on my host that will work with the Horde project "passwd" www.horde.org

It can written in either PHP, Perl or Expect TCL, if you can do it get in touch with a offer.

Thanks
Locked