CSC151, Class 13: CGI Overview: * Intro to CGI * What you need to do to write CGI in Scheme * How do do it * Lab Notes: * Too few students at strategic planning meeting * Writeup 1 is due! Some problems. * Questions on strings and characters? * No reading for tomorrow * Look what I found in one of your assignments (I think DrScheme put it there) ---------------------------------------- . . . . . . . . . . . ... . . X.... . . .. oX...O+ .. .. .. .. .. .. .. .... . . .... .@.. ..#. @@$.......@%& .@ @*@%@.@%@%@*=. ... @&..@%.%@..$&$... .. @ @....@.@....$&& .. .. @ @....&.&....$&% .. . .@ @@..&@.@&..-&&$. . ...@@@.@&@;.%@=@*=$$... ... @.@@%..@.@..*=$.& ... .. .@@@.@..&.&..@*&$$. .., . .. @ @@%@%@.@%@*$=&* .. . . @@@..%@;.%@%..$&: . . @@..@.@.@.@..$* . . @@@@.@%.%@.@&&; . .. @@@@.@.@.@:&> .. @@@.@%.%@%$*% @@@.@.@%=&% @.@%.=&*; :@.$> ---------------------------------------- Questions and Answers? * Scheme does some funky stuff if you have special characters, such as quotation marks within strings. > (string-append "Scheme" (string #\newline) "is weird") "Scheme\nis weird" > (string-append "Sam says " (string #\") "Hi" (string #\")) "Sam says \"Hi\"" You can see nicer versions with display > (display (string-append "Scheme" (string #\newline) "is weird")) Scheme is weird > (display (string-append "Sam says " (string #\") "Hi" (string #\"))) Sam says "Hi" Some of you had trouble submitting your assignments. When you save them, use "Save Other" under the "File" and then select "Save Definitions as Text...". Can you separate display boxes? No ---------------------------------------- Basic Web Model +---------+ Please give me page XXX +--------+ | | -------------------------> | | | Browser | | Server | | | <------------------------- | | +---------+ Here it is +--------+ CGI Model Please generate page XXX +---------+ using the following info +--------+ | | -------------------------> | | | Browser | | Server | | | <------------------------- | | +---------+ Here it is +--------+ ^ | Page | | Run | v +-------------+ | | | CGI Program | | | +-------------+ Sam's Scheme/CGI Model +---------------+ Evaluate (page) +--------------+ | | ------------------> | | | CGI Interface | | Scheme Prog. | | | <------------------ | | +---------------+ String for page +--------------+ ---------------------------------------- What you need to know how to do ... * What does the Scheme file have to look like? * What aspects of the strings lab that we didn't have time to finish would help us on this assignment? Sam's questions: 1. How do I write an HTML page that says "Run this program using this input" rather than "Load this page"? DETOUR: SEND EMAIL To its-equipment-hotline@lyris.grinnell.edu SAY Most of the mice on the computers in the MathLAN are not working as well as I'd like, particularly the mouse Leibniz (south-east corner of Science 2417). Could you please replace them ASAP? And no, Sam Rebelsky did not tell me to send this email. 2. How do I write this CGI thingy that tells my Scheme program to run? 3. How do I write a Scheme program that generates an HTML string? 4. How do I get my Scheme program to read the input that the user entered way back in step 1? 5. How do I put it all together? ---------------------------------------- How to do it ... 1. Write HTML to run a program with particular input derived from the user.
^ Instructions to your browser to tell the server to run the program "at an appropraite time". ^ Create an input area on the screen whose associated name will be "username". ^ Create a button that, when the user clicks it, tells the browser to submit the input to the program specified way back in "action" 2. CGI thingy Create a file containing the two following lines: #!/bin/bash /home/rebelsky/bin/schemeweb MY-SCHEME-FILE.ss Save it as SOMETHING.cgi in your public_html area. Execute the following completely nonsensical commands: $ chmod a+r SOMETHING.cgi $ chmod a+x SOMETHING.cgi 3. Write a Scheme program that generates an HTML string. (define page (lambda () (string-append "" (string #\newline) "" (string #\newline) "Whatever" (string #\newline) "" (string #\newline) "" (string #\newline) "Generated by Scheme" (string #\newline) "" (string #\newline) "" (string #\newline)))) 4. Learn how to use the information provided back in step 1. At the top of your Scheme file (load "/home/rebelsky/Web/Scheme/webutils.ss") Whenever you need something that someone typed in the HTML form, say username, use (get-cgi-variable 'username "default-value") ---------------------------------------- Lab ---------------------------------------- REFLECTION Before executing the "chmod" commands, you may first need % cd public_html DON'T TYPE THE PERCENT SIGN