Creating Web Applications With REBOL CGI One of the great things about REBOL is that you can accomplish a huge variety of computing work with it. It's a great tool for building custom GUI applications to manage data on Windows, Mac, Linux, and other operating systems. And if you already know some basics about programming with REBOL, you can easily learn how to use it to create WEB based data management apps, without having to learn any other language, database system, IDE, or any other development tools. To create and run web applications using REBOL CGI, you need a web server. Linux shared web hosting plans are available from Lunarpages.com, Hostgator.com, and others for less than $10 per month, and are capable of handling significant amounts of web traffic (many tens of thousands of visits a day). If you learn a little about web servers, you can also use free "AMP" software such as http://www.uniformserver.com to run a light web server from your home computer, using your existing broadband Internet connection. This author has used Lunarpages for many years to run mission critical REBOL CGI programs, and they are a reliable choice. The process of setting up REBOL CGI applications is basically the same for all other hosts, but before paying for any commercial hosting service make sure they allow REBOL CGI programs to run on their servers (DO NOT assume this is the case). To do any work with your web server, you'll need to know your account's FTP username, password, URL, and publicly viewable root folder. Be sure to have that info on hand before continuing with this tutorial. To begin building a web application with REBOL, you'll need to upload the REBOL interpreter to your web server. You only need to do this once for each web server (not for each program). Open your local REBOL interpreter to the console and type the following code - REPLACE the username, password, URL, and publicly viewable folder with your own account info. This will download a REBOL interpreter from the web, and upload it to your own server: file: ftp://user:pass@site.com/public_html/rebol ; EDIT with your info write/binary file (read/binary http://re-bol.com/rebol276) The file transfer process above should take just a few seconds if you're on a broadband connection. Once it's done, you need to set execute "permissions" for the REBOL interpreter in your hosting account. You can use the following REBOL script to do that. Just paste this code into your local REBOL interpreter and enter your web server URL, username, password, folder, etc., when prompted: REBOL [title: "FTP CHMOD"] website: request-text/title/default "Web Site:" "site.com" username: request-text/title/default "User Name:" "user" password: request-text/title/default "Password:" "pass" folder: request-text/title/default "Folder:" "public_html" file: request-text/title/default "File:" "rebol" permission: request-text/title/default "Permission:" "755" write %ftpargs.txt trim rejoin [{ open } website { user } username { } password { cd } folder { literal chmod } permission { } file { quit }] call/show "ftp -n -s:ftpargs.txt" If you have any problems using the above program on your operating system, you can simply run your OS's command line FTP program using the code below, and manually enter your web host account information as described: call/show {ftp} ; run this line in the REBOL interpreter console ; Type the following command at the FTP prompt (replace your web url): open yourdomain.com ; enter your username and password when prompted ; Type the following commands (replace your folder and file names): cd public_html/ literal chmod 755 rebol quit All the steps above only need to be completed the very first time you set up your web hosting account. Once you've got REBOL uploaded to your server, you can begin to create your first CGI program. To start editing a new web site script, type the following into your local REBOL interpreter console (again, be sure to edit the user name, password, URL, and public folder information to match your web server account settings): editor ftp://user:pass@site.com/public_html/example.cgi ; EDIT account Type the following code into the REBOL text editor and save it (clicking "Save" in the REBOL text editor ACTUALLY SAVES/UPLOADS THE CHANGES TO YOUR WEB SERVER): #!./rebol -cs REBOL [] print {content-type: text/html^/} Run the "FTP CHMOD" program above one more time to set the permissions for this new "example.cgi" to 755 (you'll need to set permissions to 755 for every .cgi script you create and upload to your server, so keep the above script handy). To be clear, in the ftp script above, change "rebol" to "example.cgi". Now browse to http://yourdomain.com/example.cgi , and you will see a blank page (replace "yourdomain.com" in the URL to the domain of your actual web server). If you get any errors, see the highlighted instructions below about error logs in cPanel. To make some text appear on your web page, use the "print" function. Edit your example.cgi file as follows, save it to your server, then refresh http://yourdomain.com/example.cgi to see the changes in your program appear live on your web site: #!./rebol -cs REBOL [] print {content-type: text/html^/} print {Hello world!} You can put any HTML code on your web page using the "print" function. Here is a demonstration of the most useful and necessary HTML tags needed to lay out web pages. In the REBOL editor enter and save the following code (editor ftp://user:pass@site.com/public_html/example.cgi) then refresh http://yourdomain.com/example.cgi in your browser to see the changes: #!./rebol -cs REBOL [] print {content-type: text/html^/} print {

This is some header text

This header text is smaller

In HTML, all spaces, tabs, newlines and other white spaces are compressed (i.e., this text is all printed on the same line, and wrapped to the length of the screen, and these spaces are all compressed to one space. If you want to explicitly display a certain number of spaces, use these characters:     For newlines (carriage returns), use the "br" tag:

You can also use "p" tags to create separate lines.

To adjust text size and color, use the "font" tag:

Little blue text
Big red text

To display a link to a web site, use the "a" tag:

yahoo.com

To display images, use the "img" tag:



To make an image link to a URL, use "img" and "a":

click the image:


This text is bolded.

            The "pre" tag displays preformatted text.
            Spaces, tabs, newlines, etc. are kept intact.
        
You can add a horizontal separator line with the "hr" tag:



Center anything on a page with the "center" tag:

Centered Text

Tables are used to display rows and columns of data. They can also be used to align portions of an HTML page in certain areas of the screen (i.e., to layout menu bar areas, headers, main content areas, and footers):

"tr" tags are rows
"td" tags are columns
You can set "td"s to span as many columns as needed, using the "colspan" setting, and you can use the "valign" property to set where in the cell text is placed. "bgcolor" sets the cell's background color. You can set size properties of all different parts of the table, using either percentage or pixel values.
Try resizing the page to see how centering, text wrapping and table layouts work. } Here are several examples of useful basic HTML page templates which use tables to layout sections of the page. You can adjust them as a basic outlines for your own page layouts: #!./rebol -cs REBOL [title: "Generic HTML Page With Tables"] print {content-type: text/html^/} print { Generic HTML Page With Tables
YOUR PAGE CONTENT GOES HERE.

Copyright © 2009 Yoursite.com. All rights reserved.

} Here is another useful generic HTML page layout using tables. Notice where it says "YOUR PAGE CONTENT GOES HERE": Table Based Page Layout, No Menu

HEADER IMAGE

Home : Contact
YOUR PAGE CONTENT GOES HERE

Copyright © 2010 This Web Site. All rights reserved.

Here is a variation of the generic HTML page layout above, with a menu bar on the left side: Table Based Layout Template, With Menu

Home

HEADER IMAGE

Menu


Page1
Page2


Home
YOUR CONTENT GOES HERE

Copyright © 2010 This Web Site. All rights reserved.

The pages above are just static HTML - they can only display a single, unchanging display. The real benefit of CGI is that you can use the entire power of the REBOL language to process data, and print dynamically changable output for visitors to see, respond to user input, and interact with visitors. Here's a simple CGI program that downloads a time stamped backup of the given URL, and displays the current backup to the user: #!./rebol -cs REBOL [title: "Backup Remote Page"] print {content-type: text/html^/} filename: to-file rejoin [now/date ".html"] write filename read http://www.guitarz.org/AboutNick.html print rejoin [ {The page at http://www.guitarz.org/AboutNick.html was just downloaded to this server. The current version of this backup, at } now/time {, looks like this:


} read filename } Here's an example that displays all the images in a folder on your web server: #! ./rebol -cs REBOL [title: "Photo Viewer"] print {content-type: text/html^/} print {Photos
} folder: read %. count: 0 foreach file folder [ if find [%.jpg %.gif %.png %.bmp] (suffix? file) [ print rejoin [{
}] count: count + 1 ] ] print rejoin [{
Total Images: } count {
}] The following program can be used to copy all the files in a folder from one web server, directly to another web server. It displays transferred file names to the user as it progresses. To use this script, just save, upload, and set permissions for it (be sure to edit the username, password, and URL info), then in your browser go to the URL at which it's located: #! ./rebol -cs REBOL [title: "Copy All Files to New Web Server"] print "content-type: text/html^/" print ["File Transfer"] foreach file (read ftp://user:pass@site.com/public_html/path/) [ print join file {
} write/binary (to-file file) (read/binary (to-url join http://site.com/path/ file)) ] print [] quit User input in CGI applications can be accomplished using HTML "forms". Form fields, textareas, check boxes, dropdown selectors, submit buttons, etc., take the place of familiar GUI widgets in desktop applications, to get data from users. To understand how forms work, edit example.cgi to contain the following code: #!./rebol -cs REBOL [] print {content-type: text/html^/} submitted: decode-cgi system/options/cgi/query-string probe submitted Now go to http://yourdomain.com/example.cgi?name=bob&id=1234567 . Notice that this URL is just the URL of your CGI program, followed by a question mark, followed by "name=bob" and "id=1234567", with those two pieces of data separated by an "&" symbol. Try going to http://yourdomain.com/example.cgi?name=john&id=7654321 , and see the CGI program print out John's name and ID. You can use that format to input ANY data you want to the CGI program. Forms simply provide a way to send data input by the user, to a script at a given URL, using the format above. Try this: create a new text file named form_example.html (be sure to edit your username, password, site, and folder): editor ftp://user:pass@site.com/public_html/form_example.html Copy the following HTML into form_example.html, and save it to your server. Notice that the "action" link in the code below is pointing to the URL of the example.cgi script that we've already created):
Name: ID:
Now go to http://yourdomain.com/form_example.cgi , fill out and submit the form, and pay attention to the link to which you are transferred, as well as the data printed by the script. It works exactly the same as the links that we hand coded above (i.e., the above form transfers you to http://yourdomain.com/example.cgi?name=john&id=7654321). The form just provides a useful interface that your web site visitors can use to enter their name and ID (instead of having to type in an archaic URL). Notice that there are FOUR pieces of data in each of the link examples shown earlier: 1) the label "name" 2) the data value "john" 3) the label "id" 4) the data value "7654321". In order to get DATA values submitted by the user (as opposed to their label names), we need to use the EVEN numbered pieces of data submitted by the form (in this case, the data values 2 and 4). Try changing the example.cgi file as follows: #!./rebol -cs REBOL [] print {content-type: text/html^/} submitted: decode-cgi system/options/cgi/query-string write/append %visitors.txt mold submitted/2 ; 2nd item = Name write/append %visitors.txt mold submitted/4 ; 4th item = ID previous-visitors: load %visitors.txt print {The following visitors have logged into this page:

} foreach [name id] previous-visitors [ print rejoin [ "Name: " name "ID: " id "
" ] ] The script now saves the name and ID of every visitor who submits the form, to the file %visitors.txt on your web server, and then prints out a neatly formatted list of every previous visitor. This should start to give you some idea of how CGI can become useful - you can write ANY submitted data to your web server, retrieve it, manipulate it, and display it to your visitors. As it stands, our example program is made up of 2 separate files on the web server: the file containing the HTML form, and the file containing the REBOL code. We can combine the 2 files into a single script by simply having the program print the HTML form, with an "action" URL in the form which points directly back to the script. The script can then check whether or not the user has entered some data (i.e., if submitted values 2 and 4 are not empty (""), some data has been entered by the user). If so, it will perform the actions currently in the example.cgi script above. Edit and save your example.cgi file as follows, and then refresh http://yourdomain/example.cgi to see it run: #!./rebol -cs REBOL [] print {content-type: text/html^/} submitted: decode-cgi system/options/cgi/query-string ; Do the following if no data has been submitted: if ((submitted/2 = "") and (submitted/4 = "") [ print {
Name: ID:
} quit ] ; Otherwise, do the following with the data submitted by the user: write/append %visitors.txt submitted/2 write/append %visitors.txt submitted/4 previous-visitors: read %visitors.txt print {The following visitors have logged into this page:

} foreach [name id] previous-visitors [ print rejoin [ "Name: " name "ID: " id "
" ] ] Notice the "quit" function after the printed HTML form. If the user is just coming to the page (i.e., has not yet submitted any data), we want them to see the input form, and nothing else, so we print the form and then quit the script. When the user fills out the form and clicks the submit button, the action points directly back to this same script, so the script runs again, this time with some submitted data, and only the second half of the program gets executed. Study that logic until it makes sense. All your CGI programs with follow this simple pattern. In larger programs you'll likely just have more input options to decipher (more forms to print, more "if" evaluations, etc.) and perhaps some more complex data manipulations to perform. Here's an example that allows the user to choose between options from a dropdown box in an HTML form, and then responds to that input appropriately. Notice that the dropdown code is dynamically created, instead of being typed in explicitly. This code allows you to more easily create drop down boxes containing many items (lists of times, colors, dates, etc.), just by putting them in a block: #! ./rebol -cs REBOL [title: "CGI Logic"] print {content-type: text/html^/} submitted: decode-cgi system/options/cgi/query-string ; Do different things, depending on the option submitted by the user: if submitted/2 = "option1" [ print "Now Doing Code For Option 1" quit ] if submitted/2 = "option2" [ print "Now Doing Code For Option 2" quit ] if submitted/2 = "option3" [ print "Now Doing Code For Option 3" quit ] ; If none of the above cases is true (i.e., the user is just visiting ; the page and hasn't yet selected an option), print the following ; HTML form by default: options: ["option1" "option2" "option3"] ; 3 options given to visitor print {
} quit The method that you've seen so far for transferring data from HTML forms to CGI scripts is called "GET". It uses the "?" and "&" symbols to transfer data to a URL using the format http://yourdomain.com/example.cgi?label1=data1&label2=data2&label3=data3. The submitted data is visible in the user's browser address bar and is saved in their browsing history, so it's not secure in any way. There is also a limit to how much data can be sent using the GET method (that varies between browsers and web servers, but it's typically limited to a small number of pages of text). If you want to send large amounts of data, or if you don't want visitors to easily see data which is being transferred by your web application, you must use the "POST" method. Post data is NOT visible in the address bar of the user's browser. To use the POST method of data submission simply add the following text to your HTML forms: method="POST" . Save the example below and upload it as example2.html (editor ftp://user:pass@site.com/public_html/example2.html):
Name:


Email:


Message:


As you've seen in previous examples, user submitted data was decoded by CGI scripts using the following line of code, which converts the submitted data to a variable labeled "submitted" (i.e., submitted/2, submitted/4, etc.): submitted: decode-cgi system/options/cgi/query-string The line above only handles GET data. To process both GET and POST data, you'll need to add the following stock code to your CGI scripts: switch system/options/cgi/request-method [ "POST" [ cgi-data: copy "" cgi-buffer: copy "" while [positive? read-io system/ports/input cgi-buffer 16380][ append cgi-data cgi-buffer clear cgi-buffer ] ] "GET" [cgi-data: system/options/cgi/query-string] ] submitted: decode-cgi cgi-data Save and upload the following file as example2.cgi, set its permissions to 755 and then go to the form at http://yourdomain.com/example2.html to see it work. Notice that none of the data appears in the browser's address bar, and you can paste very large amounts of text into the HTML text area (editor ftp://user:pass@site.com/public_html/example2.cgi): #!./rebol -cs REBOL [] print {content-type: text/html^/} switch system/options/cgi/request-method [ "POST" [ cgi-data: copy "" cgi-buffer: copy "" while [positive? read-io system/ports/input cgi-buffer 16380][ append cgi-data cgi-buffer clear cgi-buffer ] ] "GET" [cgi-data: system/options/cgi/query-string] ] submitted: decode-cgi cgi-data print {The following data was submitted:

} probe submitted Try running the following example to see how POST data may be combined into a single script that prints the HTML form and processes submitted data (editor ftp://user:pass@site.com/public_html/example3.cgi and then visit http://yourdomain.com/example3.cgi): #!./rebol -cs REBOL [] print {content-type: text/html^/} switch system/options/cgi/request-method [ "POST" [ cgi-data: copy "" cgi-buffer: copy "" while [positive? read-io system/ports/input cgi-buffer 16380][ append cgi-data cgi-buffer clear cgi-buffer ] ] "GET" [cgi-data: system/options/cgi/query-string] ] submitted: decode-cgi cgi-data if ((submitted/2 = "") and (submitted/4 = "") and (submitted/6 = "") [ print {
Name:


Email:


Message:


} quit ] print saved-text: rejoin [ {The following data was entered } now {: } {

Name: } submitted/2 {
Email: } submitted/4 {
Message:

} submitted/6 ] write/append %temp.txt saved-text The following complete example is a very versatile CGI program that can handle submissions from forms that contain any number of data fields, text areas, etc., using either GET or POST methods, so it can handle virtually any amount of user submitted data. This script saves the data to a file and confirms to the user the data which has been submitted. You can use it to process HTML forms of all types. If you save this file as form-handler.cgi, for example, then forms that you want processed by it should have http://yourdomain.com/form-handler.cgi in the ACTION url: #! ./rebol -cs REBOL [title: "Generic GET and POST Form Handler"] print {content-type: text/html^/} switch system/options/cgi/request-method [ "POST" [ cgi-data: copy "" cgi-buffer: copy "" while [positive? read-io system/ports/input cgi-buffer 16380][ append cgi-data cgi-buffer clear cgi-buffer ] ] "GET" [cgi-data: system/options/cgi/query-string] ] submitted: decode-cgi cgi-data entry: rejoin [{[^/ "Time Stamp:" "} form (now + 3:00) {"^/}] foreach [title value] submitted [ entry: rejoin [entry { "} mold title {" } mold value {^/}] ] append entry {]^/} write/append %submitted_forms.txt entry print { Your Form Has Been Submitted
] ] print rejoin [ { Thank You! The following information has been submitted:

Time Stamp: } now + 3:00 {

} html: copy "" foreach [title value] submitted [ repend html [
mold title mold value
} html {

} { You'll hear from us shortly!

Copyright © 2009 This Web Site. All rights reserved.
} ] quit You could use programs such as those below, on your desktop PC, to view and process data which has been submitted via your web site, by the script above. These few lines of code provide a full template and generic working example of how to accept, store, and process data from visitors on your web site: REBOL [title: "Generic Form Submission Editor"] submissions: load http://yoursite.com/submitted_forms.txt do create-list: [ data: copy [] foreach block submissions [ append/only data (extract/index block 2 4) ] datastring: copy {} foreach block data [ datastring: join datastring "[^/" foreach item block [ datastring: rejoin [datastring item newline] ] datastring: join datastring "]^/^/" ] editor datastring ] REBOL [title: "Generic CGI Form Submission Viewer"] sort-column: 4 ; even # cols contain data (2nd col is time stamp) signups: load http://yoursite.com/submitted_forms.txt do create-list: [ name-list: copy [] foreach item signups [append name-list (pick item sort-column)] ] view center-face layout [ the-list: text-list 600x150 data name-list [ foreach item signups [ if (pick item sort-column) = value [ dt: copy "" foreach [label data] item [ dt: rejoin [ dt newline label " " data ] ] a/text: dt show a ] ] ] a: area 600x300 across btn "Sort by..." [ sort-column: to-integer request-text/title/default { Data column to list:} "4" do create-list the-list/data: name-list show the-list ] tab text join (form length? signups) " entries." ] ************************************************************************** NOTE: In this text, you were shown how to use the REBOL text editor to edit CGI scripts directly on your web site, using FTP links that contain your web server account username, password, URL, and folder/file settings. That is NOT the only way to edit CGI programs on your web site. You can create CGI programs simply as new text files in your favorite text editor (Windows Notepad or any other editor will work). Just save the file and upload it to your web server account. To upload files into a Lunarpages account, go to http://yourdomain.com/cpanel in your browser, log in with your username and password, click the "File Manager" icon, click the "public_html" folder icon, click the "Upload file(s)" link, and select the file you want to upload from your hard drive. To change permissions for CGI scripts, just select any uploaded file in your cPanel file manager, click "Change Permissions", and set the permissions to "755". You can also use your cPanel file manager to create and edit files directly in your browser. If you use cPanel to edit your CGI scripts, you don't need any other programs to create online applications. Bookmark your cPanel page. It's a great way to access everything in your web site, from any computer with a web browser. There are many other ways to manage the edit/upload/permissions process. It's good to become familiar with all of them. You can use any third party FTP program (Filezilla, Cute_FTP, etc.) to upload files into your account and set permissions. Just set your username, password, ftp URL, etc., and follow the instructions in your chosen FTP program. One other thing to note is that your CGI scripts and HTML forms do not necessarily need to be saved in your public_html folder. You can, for example, use REBOL's make-dir function to create a new subfolder on your web server, and put separate programs in separate directories: make-dir ftp://user:pass@site.com/public_html/folder2/ editor ftp://user:pass@site.com/public_html/folder2/newexample.cgi Some web hosts require that all executable CGI applications go into a folder named "cgi-bin", but you can still put your HTML forms into any folder on your web site. Just be sure that your form ACTIONs point to the URL of your intended CGI script (i.e., ACTION="../cgi-bin/example.cgi"). If you get any errors in your CGI programs, make sure that the proper REBOL/core interpreter and example.cgi are both uploaded to your public_html folder, and make sure that permissions for both files have been saved as 755. If needed, you can find more useful error/debugging information by clicking the "Error log" icon in your cPanel. If you're using a host other than Lunarpages, you may need to upload a different version of the REBOL interpreter (i.e., if your server is running on Windows OS, then you'll need a Windows version of REBOL/core). You can download a version of REBOL that's appropriate for your host's operating system from: http://www.rebol.com/download-core.html . Be aware that some web hosts require that you put CGI programs into a specific folder such as "cgi-bin". Check with your web host for help with any such technical restrictions. ************************************************************************** Here are a few more useful CGI examples. Be sure to note the file name in the ACTION of any HTML forms, and save each CGI program with that file name (i.e., this first script should be saved as "bb.cgi"): #! ./rebol -cs REBOL [title: "CGI Bulletin Board" filename: %bb.cgi] print {content-type: text/html^/} print read %template_header.html ; create an HTML template for looks bbs: load %bb.db print {
Please REFRESH this page to see new messages.
} print-all: does [ print {

Posted Messages:

} foreach bb (reverse bbs) [ print rejoin [ {
Date/Time: } bb/2 { } {"Name: } bb/1 {

} bb/3 {


} ] ] ] submitted: decode-cgi system/options/cgi/query-string if submitted/2 <> none [ entry: copy [] append entry submitted/2 append entry to-string (now + 3:00) append entry submitted/4 append/only bbs entry save %bb.db bbs print {
Your message has been added:
} ] print-all print { Post A New Public Message:

Your Name:


Your Message:


} print read %template_footer.html ; Create an HTML footer template #! ./rebol -cs REBOL [title: "CGI Simple Search" filename: %search.cgi] print "content-type: text/html^/" print ["Search"] ; print read %template_header.html submitted: decode-cgi system/options/cgi/query-string if not empty? submitted [ phrase: submitted/2 start-folder: to-file submitted/4 change-dir start-folder found-list: "" recurse: func [current-folder] [ foreach item (read current-folder) [ if not dir? item [ if error? try [ if find (read to-file item) phrase [ print rejoin [{"} phrase {" found in: } what-dir item {
}] found-list: rejoin [found-list newline what-dir item] ]] [print rejoin ["error reading " item]] ] ] foreach item (read current-folder) [ if dir? item [ change-dir item recurse %.\ change-dir %..\ ] ] ] print rejoin [{SEARCHING for "} phrase {" in } start-folder {

}] recurse %.\ print "
DONE
" ; save %found.txt found-list ; print read %template_footer.html quit ] print [
] print [
] print ["Text to search for:"


] print ["Folder to search in:"


] print [] print [
] print [
] ; print read %template_footer.html quit #! ./rebol -cs REBOL [title: "CGI Event Calendar"] print "content-type: text/html^/" print {Event Calendar} bbs: load %bb.db date: now/date html: copy rejoin [ {
} ] days: ["Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"] foreach day days [ append html rejoin [ {} ] ] append html {} sdate: date sdate/day: 0 loop sdate/weekday // 7 + 1 [append html {}] while [sdate/day: sdate/day + 1 sdate/month = date/month][ event-labels: {} foreach entry bbs [ date-in-entry: 1-Jan-1001 attempt [date-in-entry: (to-date entry/2)] if (date-in-entry = sdate) [ event-labels: rejoin [ {} event-labels "

" {} entry/1 {} "
" {
} ] ] ] append html rejoin [ {} ] if sdate/weekday = 6 [append html {}] ] loop 7 - sdate/weekday [append html rejoin [{}]] append html {
} pick system/locale/months date/month { } date/year {
} day {
} sdate/day event-labels {
} print html quit { Events are stored in the file %bb.db, in the format: ["event 1" 18-Apr-2010 http://website.com/event1.html] ["event 2" 20-Apr-2010 http://website.com/event2.html] ["event 3" 20-Apr-2010 http://website.com/event3.html] } #! /home/path/public_html/rebol/rebol276 -cs REBOL [Title: "CGI Console" filename: %console.cgi] print "content-type: text/html^/" print {Console} selection: decode-cgi system/options/cgi/query-string if ((selection/2 = none) or (selection/4 = none)) [ print { W A R N I N G - Private Server, Login Required:

Username:

Password:

} quit ] qq: [ print {


} ] if selection/2 = "command-submitted" [ write %commands.txt join "REBOL[]^/" selection/4 ; The "call" function requires REBOL version 2.76: call/output/error "/home/path/public_html/rebol/rebol276 -qs commands.txt" %conso.txt %conse.txt print rejoin [ {
Output:

} {
}
            read %conso.txt
            {


} {Errors:

} read %conse.txt {
} ] do qq quit ] username: selection/2 password: selection/4 either (username = "user") and (password = "pass") [] [ print "Incorrect Username/Password." quit ] do qq #!./rebol -cs REBOL [title: "CGI Text Editor" filename: %edit.cgi] print {content-type: text/html^/} print {Edit Text Document} read-cgi: func [/local data buffer][ switch system/options/cgi/request-method [ "POST" [ data: make string! 1020 buffer: make string! 16380 while [positive? read-io system/ports/input buffer 16380][ append data buffer clear buffer ] ] "GET" [data: system/options/cgi/query-string] ] data ] submitted: decode-cgi read-cgi if submitted/2 = "save" [ ; save newly edited document: write to-file rejoin ["./" submitted/6 "/document.txt"] submitted/4 print ["Document Saved."] print rejoin [ {} ] quit ] if ((submitted/2 = none) or (submitted/4 = none)) [ print { W A R N I N G - Private Server, Login Required:

Username:

Password:

} quit ] userlist: load %userlist.txt folder: submitted/2 password: submitted/4 response: false foreach user userlist [ if ((first user) = folder) and (password = (second user)) [ response: true ] ] if response = false [print {Incorrect Username/Password.} quit] cur-time: to-string replace/all to-string now/time {:} {-} ; backup document_text: read to-file rejoin [{./} folder {/document.txt}] write to-file rejoin [ {./} folder {/} now/date {_} cur-time {.txt}] document_text prin { Be sure to SUBMIT when done:

} {<\/textarea>} print {

} print rejoin [{}] print {} print {
} print {} #! ./rebol -cs REBOL [title: "CGI Event Signup" filename: %event.cgi] print {content-type: text/html^/} print {Event Sign-Up} events: load %event.db a-line: [] loop 65 [append a-line "-"] a-line: trim to-string a-line print {
" Sign up for an event:"

Student Name:

ADD yourself to this event: "

REMOVE yourself from this event:

} print-all: does [ print [

] print " Currently scheduled events, and current attendance:" print [
] foreach event events [ print rejoin [a-line {
} event/1 {BR} a-line {
}] for person 2 (length? event) 1 [ print event/:person print {
} ] print {
} ] print {} ] submitted: decode-cgi system/options/cgi/query-string if submitted/2 <> none [ if ((submitted/4 = "") and (submitted/6 = "")) [ print { Please try again. You must choose an event. } print-all quit ] if ((submitted/4 <> "") and (submitted/6 <> "")) [ print { Please try again. Choose add OR remove. } print-all quit ] if submitted/4 = "all" [ foreach event events [append event submitted/2] save %event.db events print { Your name has been added to every event: } print-all quit ] if submitted/6 = "all" [ foreach event events [ if find event submitted/2 [ remove-each name event [name = submitted/2] save %event.db events ] ] print { Your name has been removed from all events: } print-all quit ] foreach event events [ if (find event submitted/4) [ append event submitted/2 save %event.db events print { Your name has been added to the selected event: } print-all quit ] ] found: false foreach event events [ if (find event submitted/6) [ if (find event submitted/2) [ remove-each name event [name = submitted/2] save %event.db events print { Your name has been removed from the selected event: } print-all quit found: true ] ] ] if found <> true [ print { That name is not found in the specified event!" } print-all quit ] ] print-all