Python, CGI and PGP
Phil Edwards
phil.edwards at mistral.co.uk
Tue Mar 26 12:09:01 EST 2002
Jim Dennis wrote:
>
> How are you feeding "sometext.txt" into the process in your CGI
> script? Why now show us the actual fragment of code that you're
> attempting to use?
>
> When it comes to environmental issues (in programming) it's generally
> pretty easy to replace a target program with a wrapper script like
> so:
>
> mv $ORIGINAL_BINARY $ORGINAL_BINARY.wrapped
> cat > $ORIGINAL_BINARY <<WRAPPER_SCRIPT
> #!/bin/sh
> printenv > /tmp/$(basename $0).$$
> . /some/where/$(basename $0).env
> exec $0.wrapped "$@"
> WRAPPER_SCRIPT
> chmod +x $ORIGINAL_BINARY
>
> ... this shell code is relatively terse (as well as concise) so
> I'll highlight some of it's finer points in english.
>
Thanks, Jim, this is definitely one for the "little black book". When I see
things like this, I'm reminded just why I love UNIX so much...
>
> If you are reasonably persistent and a little clever you should be able
Oh, that leaves me out, then :-)
Managed to figure it all out with the help of the wrapper stuff above. It
turns out that both 'os.system' and 'commands.getoutput' (which I had
tried) trash so much of the execution environment that there's hardly
anything left for the binary to wprk with.
I'm left with the following code in my CGI app:
cmd = 'export PGPPATH=/var/www/.pgp; /usr/local/bin/pgp -z windsurf -sta
-f - '
print 'content-type: text/html\n\n'
pw,pr = os.popen2(cmd)
pw.write(tdata)
pw.close()
junk = pr.read()
print string.replace(junk, '\n', '<br>\n')
Thanks for your help! It's a shame there isn't a scheme for sending
beer/pizza vouchers over the 'net...
--
Regards
Phil Edwards
UNIX Systems Administrator
==========================================================================
Mistral Internet http://www.mistral.co.uk
Tel: +44 (0)1273 747432 Fax +44 (0)1273 747452
Running Mandrake Linux release 8.1 (Vitamin) for i586 Kernel 2.4.8-34.1mdk
System uptime : 8 days, 8 min, 2 users, load average: 1.66, 1.36, 1.24
==========================================================================
More information about the Python-list
mailing list