[REBOL] Re: html post
From: al:bri:xtra at: 8-Aug-2002 7:47
Javier, you might be interested in looking at my Rebol/Wiki. It's a CGI
script, that reads POST-ed form data, as well as GET urls. It's attached.
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
-><-
----- Original Message -----
From: "Javier Delgado" <[javierd--paralax--com--mx]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, August 08, 2002 4:42 AM
Subject: [REBOL] Re: html post
> At 12:11 p.m. 07/08/2002 +0200, you wrote:
>
> >Are you sending the files in text/www-form-urlencoded format? If
> >you're getting your data as multipart/form-data as I think you
> >are, DECODE-CGI isn't able to process it AFAIK...
>
> mmmh.. i am using:
>
> <form action="/cgi-bin/dump-post.cgi" method="post"
> enctype="multipart/form-data" name="upload">
>
> I could not send files with other options....
>
> it seems I need to read more what going on.... :-/
>
> Javier Delgado
>
> Paralax Multimedia
> www.paralax.com.mx
> Interactivos, kioscos, sites, web hosting, video 3d, animacion 3d,
anaglifos
> tel 5373 3620 y 5363 4953
> Naucalpan de Juarez, Edo. Mex.
>
> tambien visite:
> http://www.kaliman.com.mx
> http://www.paralax.com.mx/javier
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
>
-- Attached file included as plaintext by Listar --
-- File: Wiki.r
#! C:\Rebol\View\rebol.exe -cs
Rebol [
Name: 'Wiki
Title: "Wiki"
File: %Wiki.r
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Web: http://valley.150m.com
Date: 6/August/2002
Version: 1.3.3
Purpose: {Wiki. Creates a Wiki using Rebol and the Xitami web server.}
Category: [util net markup 5]
Comments: {
In %/Xitami/xitami.cfg -- the Xitami configuration file,
in the [Mime] section, add:
htc=text/plain
to allow the %Calender.htc hypertext component to be sent.
Caution: Hypertext components only work with MSIE!
Also, change:
js=application/x-javascript
to:
js=text/javascript
so as to correctly set the MIME for JavaScript files.
}
Defects: {
Need to fix up dates.
Decide on Active Rebol Content:
- Parrallel to Wiki?
- Inside Wiki?
- Part of Wiki?
- Something else?
}
]
if not value? 'Values [
do %/C/Rebol/Values/Values.r
]
Remote: %/C/Xitami/cgi-bin/ ; Change to suit Colenso IIS!
Wiki_Folder: %/C/Rebol/Wiki/Files/ ; Where all the Wiki's .txt files are stored.
Stylesheet: %Wiki.css
if none? system/options/cgi/script-name [
foreach File read %. [
if found? find [
%.r
%.jpg %.png %.gif
%.css
%.htc
%.js
] extension? File [
write/binary Remote/:File read/binary File
]
]
]
if none? Rebol/options/cgi/script-name [
browse http://localhost/cgi-bin/Wiki.r?
quit
]
See-Other: func [URL [url!]] [
print rejoin [
Rebol/options/cgi/server-protocol " Status: 303 See Other" newline
"Location: " URL newline
]
quit
]
Envelope: func [Title [string!] Body [block!]] [
content-type 'text/html
print newline
print ML compose/deep [
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
html [
head [
title (Title)
link/rel/type/href "stylesheet" "text/css" (Stylesheet)
script/type/language/src "text/javascript" "JavaScript" %Wiki.js ""
]
body/onload/id "SetColumnHeight (HtmlElement)" "HtmlElement" [(Body)]
]
]
quit
]
Log: func [Value] [
write/append %Log.txt reform [now/time mold Value newline]
Value
]
Inspect: func [Value] [
Envelope "Inspect" compose/deep [
div/id "Center_Column" [
h1 "Inspect"
p ["As of: " (now/time) ", the value is: "]
pre [(mold Value)]
]
]
]
Mime-Data: func [Mime [path!] Data [binary!]] [
print ["Content-Type:" :Mime newline]
write-io system/ports/output Data length? Data
quit
]
Forbidden: {:*?"<>|/\.} ; A Wiki file name cannot contain any of these characters.
Permitted: complement charset Forbidden
Magic: #"*"
Wiki: make object! [
Name: [some Permitted]
set 'Wiki_Filename_Rule Filename: [Name opt [#"." Name]]
Relative_Folder: [some [Name #"/"]]
Absolute_Folder: [#"/" opt Relative_Folder]
set 'Wiki_Folder_Rule Folder: [Absolute_Folder | Relative_Folder]
set 'Wiki_File_Rule File: [opt Folder Filename | Folder]
Files: sort recursive-read Wiki_Folder
Rebols: make block! 10
use [Folder File] [
forall Files [
if all [
(%.r = extension? File: first Files)
Folder: pick Files 2
(#"/" = last Folder)
(= filename? File filename? Folder)
] [
remove/part Files 2
]
]
Files: head Files
]
Folders: make block! length? Files
foreach File Files [
if #"/" = last File [
append Folders File
]
]
sort/compare Folders func [File1 [file!] File2 [file!]] [> length? File1 length? File2]
]
Separator: charset "/-"
Month_Rule: [1 2 digit | 3 12 alpha]
Date_Rule: [
[1 2 digit Separator Month_Rule Separator [4 digit | 2 digit]]
| [4 digit Separator Month_Rule Separator 1 2 digit]
]
Deplus: func [String [string!]] [
replace/all dehex replace/all copy String #"+" #" " CRLF newline
]
CGI: make object! [
Post?: "POST" = Rebol/options/cgi/request-method
Get?: "GET" = Rebol/options/cgi/request-method
Script-File: to-file Rebol/options/cgi/script-name
Script-URL: join make url! compose [
http (join Rebol/options/cgi/server-name Rebol/options/cgi/script-name)
] #"?"
Query: Rebol/options/cgi/query-string
SubFolder_Rule: #" " ; A space will never arrive from browser as it's encoded to " ".
if not empty? Wiki/Folders [
SubFolder_Rule: make block! 2 * length? Wiki/Folders
foreach Folder Wiki/Folders [
repend SubFolder_Rule [
replace/all form Folder #" " " " '|
]
]
remove back tail SubFolder_Rule
]
Tuple_Rule: [
some [some Permitted #"|"]
]
Decode: function [Args [any-string! none!]] [Block Folder Name Value Error] [
Block: make block! 10
either all [
string? Args
not empty? Args
parse/all Args [
[
some [
[[Magic | "%2A"] copy Name [Alpha some [AlphaDigit | #"-" | #"_"]]]
[
(Value: none)
#"="
[[copy Value to #"&" skip] | [copy Value to end]]
] (
append Block compose [
(to-set-word Name) (all [Value Deplus Value])
]
)
]
end
]
| [
opt [
copy Folder [opt #"/" SubFolder_Rule] (
Folder: to-file deplus Folder
)
]
opt [
copy Value Date_Rule (
Error: error? try [
Name: 'Date
Value: load Value
]
)
| copy Value Tuple_Rule (
Name: 'Tuple
)
| copy Value Wiki_File_Rule (
Name: 'File
Value: to-file deplus Value
)
]
opt [#"?" (Name: 'Search)]
end (
if all [
none? Value
Folder
] [
Value: Folder
Folder: none
]
if none? Name [
Name: 'File
]
if Folder [
append Block compose [
Folder: (Folder)
]
]
append Block compose [
(to-set-word Name) (Value)
]
)
]
]
not Error
not empty? Block
] [
make object! Block
] [
none
]
]
Object: Decode any [
if Get? [Query]
if Post? [
use [Length] [ ; Extra length for use by Rebol's 'read-io.
Query: make string! 2 + Length: to-integer Rebol/options/cgi/content-length
read-io Rebol/ports/input Query Length
Query
]
]
]
all [
string? Query
Query: Deplus Query
]
]
Folder_Buttons: function [File [file! none!]] [Folders Stack Folder] [
if none? File [
return ""
]
if all [
not empty? File
#"/" != first File
] [
File: head insert File #"/"
]
compose/deep [
div/id "Left_Column" [
form [
(
Folders: parse/all File "/"
if all [
1 = length? Folders
empty? Folders/1
] [
clear Folders
]
Stack: make block! 6 * length? Folders
for Index 1 -1 + length? Folders 1 [
Folder: Folders/:Index
push Stack compose/deep [
input/type/value/onclick/title/class "button" (join Folder #"/") (
rejoin [
"window.location='"
CGI/Script-URL
copy/part File find/tail File join Folder #"/"
{'}
]
) "Click to change Folder" "Folders"
br
]
]
Stack
)
]
]
]
]
Command: CGI/Object
if all [
none? Command
string? CGI/Query
not empty? CGI/Query
] [
See-Other CGI/Script-URL
]
if none? Command [
Command: make object! [
File: %/
]
]
if in Command 'Date [
Command: make Command [
File: join to-file Command/Date %.txt
]
]
Random_Page: make object! [
random/seed now
Title: "Random"
Command?: function [Command [object!]] [File] [
if all [
in Command 'Random
Title = Command/Random
not empty? Wiki/Files
] [
File: first random Wiki/Files
See-Other rejoin [CGI/Script-URL File]
]
]
GUI: does [
if not empty? Wiki/Files [
compose/deep [
form/id/name/method/action (Title) (Title) "GET" (CGI/Script-File) [
input/type/name/value "hidden" (join Magic Title) (Title)
input/type/value/title "submit" (Title) "Click for a random page"
]
]
]
]
]
Search: make object! [
Title: "Search"
Command?: function [Command [object!]] [Query Results Text Index Heading] [
if in Command 'Search [
if none? Query: Command/Search [
See-Other CGI/Script-URL
]
Query: to-string Query
Results: make block! 100
append Results [
tr [
th "Results"
th "Document"
]
]
foreach File Wiki/Files [
if %.txt = Extension? File [
Text: read Wiki_Folder/:File
if found? Index: find Text Query [
File: head clear Extension? File
append Results compose/deep [
tr [
td [
(rejoin ["..." copy/part Index -35])
span/class "Hilight" (copy/part Index length? Query)
(append copy/part at Index 1 + length? Query 35 "...")
]
td [
a/href (
rejoin [CGI/Script-File #"?" #"/" File]
) (File)
]
]
]
]
]
]
Envelope Heading: rejoin ["Search: " Query] compose/deep [
(Folder_Buttons %/.)
div/id "Center_Column" [
h1 (Heading)
table [(Results)]
]
div/id "Commands" [
(Random_Page/GUI)
(Search/GUI Query)
]
]
]
]
GUI: func [Default [string!]] [
compose/deep [
form/id/name/method/action (Title) (Title) "GET" (CGI/Script-File) [
label [
(rejoin [Title #" " Rebol/script/header/title ": "])
input/type/name/value/title "text" (join Magic Title) (Default)
"Enter your search phrase here."
]
input/type/value/title "submit" (Title)
"Click button to search for your phrase in every page."
]
]
]
]
Save_Page: make object! [
Title: "Save"
Command?: function [Command [object!]] [Folder Name File] [
if all [
in Command 'Folder
Folder: Command/Folder
in Command 'Name
Name: Command/Name
Name: to-file deplus Name
in Command 'Text
] [
if not file? Folder [
Folder: to-file deplus Folder
]
File: Folder/:Name
any [
Extension? File
File: Extension File %.txt
]
See-Other rejoin [
CGI/Script-URL
either none? Command/Text [
if exists? Wiki_Folder/:File [
delete Wiki_Folder/:File
]
any [Folder? File %/]
] [
make-dir/deep Folder? Wiki_Folder/:File
write Wiki_Folder/:File Command/Text
head clear Extension? File
]
]
]
]
GUI: func [Heading [string!] File [file!] Text [string!]] [
compose/deep [
form/id/name/method/action (Title) (Title) "POST" (CGI/Script-File) [
div/id "Center_Column" [
h1 (Heading)
label [
"Folder: " input/type/name/value/title "text" (join Magic "Folder")
(any [Folder? File %/]) "Folder where File is stored."
]
label [
"Name: " input/type/name/value/title "text" (join Magic "Name")
(form Filename? File) "Name of File."
]
textarea/name/rows/cols/wrap/style (join Magic "Text") 25 80
"virtual" "width:100%;" (Text)
]
div/id "Commands" [
input/type/value/title "submit" "Save" "Saves your changes"
]
]
]
]
]
Edit_Page: make object! [
Title: "Edit"
Command?: function [Command [object!]] [File Folder Heading] [
if all [
in Command 'Edit
File: Command/Edit
File: to-file deplus File
exists? Wiki_Folder/:File
] [
Envelope Heading: rejoin [Title ": " Filename? File] compose/deep [
(Folder_Buttons File)
(Save_Page/GUI Heading File read Wiki_Folder/:File)
]
]
]
GUI: func [File [file!]] [
compose/deep [
form/id/name/method/action (Title) (Title) "GET" (CGI/Script-File) [
input/type/name/value "hidden" (join Magic Title) (File)
input/type/value/title "submit" "Edit" "Click to edit this page"
]
]
]
]
Hunt: function [File [file!]] [Bag Filename Extension] [
Bag: File
if none? Folder? File [
Bag: none
Filename: Filename? File
Extension: Extension? File
foreach WF Wiki/Files [
if all [
Filename = Filename? WF
Extension = Extension? WF
] [
either none? Bag [
Bag: WF
][
either file? Bag [
Bag: reduce [Bag WF]
] [
append Bag WF
]
]
]
]
]
Bag
]
View_Page?: function [Command [object!]] [File Folder Page Title EditText] [
if all [
in Command 'File
File: Command/File
#"/" != last File
] [
all [
in Command 'Folder
Folder: Command/Folder
File: Folder/:File
]
Page: File
any [
Extension? Page
Page: Extension Page %.txt
]
if all [
%.txt = Extension? Page
either Folder? Page [
exists? Wiki_Folder/:Page
] [
File: Hunt Page
if all [
file? File
Folder? File
] [
clear extension? File
See-Other rejoin [CGI/Script-URL #"/" File]
]
Page: File
]
] [
Title: form Filename? either file? Page [Page] [first Page]
Envelope Title compose/deep either file? Page [
[
(Folder_Buttons Page)
div/id "Center_Column" [
(
eText/Wiki/Base read Wiki_Folder/:Page rejoin [
CGI/Script-File #"?"
]
)
]
div/id "Commands" [
(Random_Page/GUI)
(Search/GUI Title)
(Edit_Page/GUI Page)
]
]
] [
[
(Folder_Buttons %/.)
div/id "Center_Column" [
h1 (Title)
p/class "Initial" [
{The document named: "} (Title)
{" is in several places. Please choose one:}
]
ul [
(
Links: make block! 100
foreach Wiki_File Page [
if %.txt = Extension? Wiki_File [
Wiki_File: copy/part Wiki_File
Extension? Wiki_File
]
append Links compose/deep [
li [
a/href (
rejoin [
CGI/Script-File #"?" #"/" Wiki_File
]
) (join #"/" Wiki_File)
]
]
]
Links
)
]
]
div/id "Commands" [
(Random_Page/GUI)
(Search/GUI Title)
]
]
]
]
]
]
New_Page?: function [Command [object!]] [File Folder Title Heading] [
if all [
in Command 'File
File: Command/File
#"/" != last File
] [
all [
in Command 'Folder
Folder: Command/Folder
File: Folder/:File
]
if not exists? Wiki_Folder/:File [
Title: form Filename? File
Envelope Heading: join "New: " Title compose/deep [
(Folder_Buttons File)
(
Save_Page/GUI Heading File rejoin [
Title newline
head insert/dup copy "" #"*" length? Title newline
;either date? Name [weekday Name] [""] ; Fix Me!
]
)
]
]
]
]
Delete_Folder: make object! [
Title: "Delete"
Command?: function [Command [object!]] [Folder] [
if all [
in Command 'Delete
Folder: Command/Delete
Folder: to-file deplus Folder
#"/" = last Folder
exists? Wiki_Folder/:Folder
empty? read Wiki_Folder/:Folder
] [
delete Wiki_Folder/:Folder
See-Other rejoin [CGI/Script-URL any [Folder? Folder ""]]
]
]
GUI: func [Folder [file!]] [
compose/deep [
form/id/name/method/action (Title) (Title) "GET" (CGI/Script-File) [