|
This is a legacy page and remains here for historical reference.
Writing Applescript CGIs
CGI stands for Common Gateway Interface.
CGI in a nutshell - click the submit button on a web page with a form, and the browser passes the form data to the server, which in turn passes the form data to a program called a CGI. The CGI processes the data and returns a complete HTTP response (HTTP headers + HTML) to the server, which passes this response to the browser, which displays the HTML just as if it was a static page.
The following discussion assumes you have some familiarity with HTML and Applescript. If you have never created a web page using raw HTML, and have never written an Applescript, you may be confused. Learn those other skills first. Also, some experience with Web serving is very helpful, even if it is just Apple's Personal Web Sharing (MacOS 8/9).
CGIs do not work correctly with Applescript 1.6. Use Applescript 1.8.3 instead (available thru your SoftWare Update Control Panel).
|
Applescript CGIs do not work with Apache/MacOS X. James Sentman is working to provide a fix http://www.sentman.com/acgi/; please encourage and support him in his efforts.
WebSTAR V has Apple Event CGI support; however, it appears to be deficient. The applet must be running OR the OSX machine running W*V must be logged in as user "webstar". I consider these to be wrong behaviors, but I have not tested the latest W*V. |
- Create a plain text file with the following content. Save it in the Web Pages folder (in the Documents folder if using Mac OS 9.1) with the name [spitback2.html].
Handle CGI Example
Handle CGI Example
|
- Create an Applescript with the following code. Save it in the Web Pages folder with the name [spitback2.acgi]. Choose the "Stay Open" and "Never Show Startup Screen" options and save it as a Classic Applet.
-- change the [option-return]s to the character produced by typing return
-- while holding down the option key
property crlf : (ASCII character 13) & (ASCII character 10)
property http_10_header : "HTTP/1.0 200 OK" & crlf & "Server: PWS" & crlf & [option-return]
"MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf
property br : " "
property br2 : "
"
property brr : " " & return
property br2r : "
" & return
property rtn : return
property rtn2 : return & return
property pageTitle : "Unprocessed Results of handle CGI request"
-- the following construction prevents email readers from parsing the html (I hope)
property hht : ""
property thb : "" & rtn & "" & rtn
on handle CGI request URL_path [option-return]
searching for searching_for [option-return]
with posted data posted_data [option-return]
of content type content_type [option-return]
using access method access_method [option-return]
from address client_address [option-return]
from user userName [option-return]
using password password [option-return]
with user info user_info [option-return]
from server server_name [option-return]
via port server_port [option-return]
executing by script_name [option-return]
referred by referred_by [option-return]
from browser browser_name [option-return]
using action action_used [option-return]
of action type action_type [option-return]
from client IP address client_IP_address [option-return]
with full request full_request [option-return]
with connection ID connection_ID
set newhtml to http_10_header & hht & pageTitle & thb
set newhtml to newhtml & "" & pageTitle & "" & rtn
set newhtml to newhtml & "handle CGI request " & URL_path & brr
set newhtml to newhtml & "searching for " & searching_for & br2r
set newhtml to newhtml & "with posted data " & posted_data & "" & br2r
set newhtml to newhtml & "of content type " & content_type & brr
set newhtml to newhtml & "using access method " & access_method & brr
set newhtml to newhtml & "from address " & client_address & brr
set newhtml to newhtml & "from user " & userName & brr
set newhtml to newhtml & "using password " & password & brr
set newhtml to newhtml & "with user info " & user_info & brr
set newhtml to newhtml & "from server " & server_name & brr
set newhtml to newhtml & "via port " & server_port & brr
set newhtml to newhtml & "executing by " & script_name & brr
set newhtml to newhtml & "referred by " & referred_by & brr
set newhtml to newhtml & "from browser " & browser_name & brr
set newhtml to newhtml & "using action " & action_used & brr
set newhtml to newhtml & "of action type " & action_type & brr
set newhtml to newhtml & "from client IP address " & client_IP_address & br2r
set newhtml to newhtml & "with full request " & full_request & "" & br2r
set newhtml to newhtml & "with connection ID " & connection_ID & brr
set newhtml to newhtml & " Results generated on " & (current date) & rtn
set newhtml to newhtml & " |
|