ZServer serving CGI by itself
Hi folks, I'm evaluating Zope. We have existing CGI programs (such as mailman) that we'd like to run, but we don't want to hassle with running two web servers. So, my question is, how do you run CGI programs from ZServer itself? I know that I can run Apache (or a number of other web servers) to serve CGI programs. I don't want to do that. I want to run just one web server -- ZServer. I haven't seen any documentation on how to add CGI capability to Zope. Before I spend my time writing a product or external method that allows me to call CGI programs from inside Zope, has anyone else already done this? Thanks for the bandwidth, Fred P.S. If anyone has implementation ideas, I'd like to hear them. I assume I can just write a Python function to pass along standard in and the environment variables to the CGI program, execute it in a shell and collect standard out back. BTW, this will be running exclusively under Linux. P.P.S. What is the deal with mailman? Why isn't mailman integrated with Zope yet?
Hi Fred, // I haven't seen any documentation on how to add CGI capability to Zope. // // Before I spend my time writing a product or external method that allows // me to call CGI programs from inside Zope, has anyone else already done // this? I have a C++ program I run from Zope and then return the results to Zope. Just like you described, I farm the work out to an external method which runs the CGI, grabs the results and hands them back to Zope. Be sure to hard code the line that calls your CGI. Otherwise, the External Method could be used to call any (potentially damaging) code on your Linux box. The (simplified) DTML Method "displayResults": <dtml-var standard_html_header> <dtml-let ws=CWebCGI> <- This creates and initializes an object with the External Method <p>The initial gas heating usage: <dtml-var "ws.calc.results.gashtg"></p> <p>The simulation method is invoked: <dtml-call "ws.simulate()"></p> <- This invokes the Simulate method of the ws object, which is what calls the CGI <p>The gas heating usage after the simulation: <dtml-var "ws.calc.results.interestingValue"></p> <- this displays the results of the CGI call </dtml-let> <dtml-var standard_html_footer> The (simplified) External Method "CWebCGI": import sys, os, string class CResults: "Container for results" def __init__(self): self.interestingValue = 0.0 class CCalc: "Container for calculation data" def __init__(self): self.results = CResults() self.parameters = "enter your CGI's parameter(s) here (if any)" # Note this file is on the Linux Hard Drive, not the ZODB class CWebCGI: "Container for the simulation" def __init__(self): self.calc = CCalc() self.execPath = "/path/to/the/CGIprogram" # Note this file is on the Linux Hard Drive, not the ZODB. def simulate(self): f = os.popen(self.execPath + " " + self.calc.parameters) lines = f.readlines() # grab the output of the CGI here status = f.close() self.calc.results.interestingValue = string.split(lines[0], "=")[1] def wsFactory(): # <- This is the "Function Name" of the External Method return CWebCGI() // // Thanks for the bandwidth, // Fred Hope it helps, Eric.
Oops, replace "gashtg" with "interestingValue" below. Sorry I missed t. -E ... "ws.calc.results.gashtg"></p> should be ... "ws.calc.results.interestingValue"></p>
Eric, Thank you very much for the example code. That basically does what I want. However, I have a couple of added complexities. First, I have a lot of scripts, not just one. I'd like to have the equivalent of a ScriptAlias in Apache, where I can tell Zope to treat everything in a certain directory as a CGI script. Second, my scripts do funky things like set cookies for authentication. So I need to tell Zope to basically get out of the way after calling the CGI script. (Specifically, I don't want Zope sending the HTTP header.) Third, some of my scripts are long running processes and I'd like to be able to send results back to the client unbuffered. With Apache 1.3.x, I'm able to run Python scripts with the -u flag to the Python interpreter to force unbuffered output (i.e. you see the progress instead of having to wait for the script to finish). I'm thinking of writing a CGIScript product to handle this. My idea is that I could add a CGIScript object to any Zope folder, setting parameters as appropriate. Parameters could include: 1) name of CGI script to execute on host machine or name of directory containing CGI scripts 2) buffer output 3) script sends HTTP headers 4) environment variables 5) exception handling Has a general CGI product in Zope already been done? I've already written a few external methods in testing Zope, which is easy enough, but haven't yet tried to write a product. How hard is it? Anyone have any advice (aside from go with the flow and run Zope behind Apache)? Thanks, Fred P.S. Is standard_error_message broken in Zope 2.2.2? I couldn't figure out how to use error_value without the code in lib/python/ZPublisher/HTTPResponse.py throwing in extra <html> tags. I finally just edited that file and things seem to be working. Running with or without the -D flag didn't make any difference. Eric Walstad wrote:
I have a C++ program I run from Zope and then return the results to Zope. Just like you described, I farm the work out to an external method which runs the CGI, grabs the results and hands them back to Zope. Be sure to hard code the line that calls your CGI. Otherwise, the External Method could be used to call any (potentially damaging) code on your Linux box.
[snip]
Hi Fred, Wow, you've left me in the dust. I've not needed to try what you are attempting and I don't know how Zope would handle passing the RESPONSE buck to another application. I hope someone with more "Zen" can answer the particulars for you! Best of luck. Eric. // However, I have a couple of added complexities. // // First, I have a lot of scripts, not just one. I'd like to have the // equivalent of a ScriptAlias in Apache, where I can tell Zope to treat // everything in a certain directory as a CGI script. // // Second, my scripts do funky things like set cookies for authentication. // So I need to tell Zope to basically get out of the way after calling the // CGI script. (Specifically, I don't want Zope sending the HTTP header.) // // Third, some of my scripts are long running processes and I'd like to be // able to send results back to the client unbuffered. With Apache 1.3.x, // I'm able to run Python scripts with the -u flag to the Python // interpreter to force unbuffered output (i.e. you see the progress // instead of having to wait for the script to finish). // // I'm thinking of writing a CGIScript product to handle this. My idea is // that I could add a CGIScript object to any Zope folder, setting // parameters as appropriate. Parameters could include: // // 1) name of CGI script to execute on host machine or name of directory // containing CGI scripts // 2) buffer output // 3) script sends HTTP headers // 4) environment variables // 5) exception handling // // Has a general CGI product in Zope already been done? I've already // written a few external methods in testing Zope, which is easy enough, // but haven't yet tried to write a product. How hard is it? Anyone have // any advice (aside from go with the flow and run Zope behind Apache)? // // Thanks, // Fred // // P.S. Is standard_error_message broken in Zope 2.2.2? I couldn't figure // out how to use error_value without the code in // lib/python/ZPublisher/HTTPResponse.py throwing in extra <html> tags. I // finally just edited that file and things seem to be working. Running // with or without the -D flag didn't make any difference.
participants (2)
-
Eric Walstad -
Fred Wilson Horch