Hi,
I found the question asked but no solution. It looks like proc_open would work but we have php 4.2.2. The following code works by creating a script that is run by /usr/bin/expect:
This is the script:
spawn /usr/bin/pgp -esa /home/user/testfiles/pgp_man.txt DummyUserID
for {} 1 {} {
expect {
"Enter pass phrase:" {
sleep 1;
set send_human {.1 .3 1 .07 .1 .3 .1} ;
send -h "Unsecure Dummy PassPhrase!\r"
}
"Overwrite" {
send -h "y\r"
}
eof exit
}
}
This is the php code that creates and runs it:
$pid = getmypid ( );
$pass_phrase = '"Unsecure Dummy PassPhrase!\r"';
To sign a plaintext file with your secret key, and then encrypt it
with recipent's public key, producing a .pgp file:
pgp -es textfile her_userid [other userids] [-u your_userid]
$script_text = array
(
"\n",
"spawn /usr/bin/pgp -esa /home/user/testfiles/pgp_man.txt DummyUserID\n",
"for {} 1 {} {\n",
" expect {\n",
" \"Enter pass phrase:\" {\n",
" sleep 1;\n",
" set send_human {.1 .3 1 .07 .1 .3 .1} ;\n",
" send -h $pass_phrase" . "\n",
" }\n",
" \"Overwrite\" {\n",
' send -h "y\r"'. "\n",
" }\n",
" eof exit\n",
" }\n",
"}\n"
);
$script_name = "/tmp/run_pgp$pid";
print $script_name;
$script_file = fopen ($script_name, "w");
foreach ($script_text as $curr_line )
{
if ( !fwrite($script_file, $curr_line) )
{
$error_msg = "\nERROR - could not write $curr_line to script\n";
print $error_msg;
exit();
}
}
fclose ($script_file);
$script_cmd = "/usr/bin/expect $script_name";
$last_line = exec ( $script_cmd, $pgp_results, $pgp_status );
if ( $pgp_status != 0 )
{
print "\nERROR - bad status from pgp script ($pgp_status) \n";
}
else
{
print "\npgp script ran correctly \n";
}
sleep (2);
unlink ( $script_name );
exit ();
?>
Best Wishes,
Mitch