[REBOL] [CGI] Re: downloading files with CGI
Carlos: How do I use REBOL to write a CGI script that builds a page with a download link? Simply version: you just need a href to the file that you want downloaded. Take a look at the source of: http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-librarian.r The click here to download the alpha version is simply a link to the file that will be downloaded. This may not be what you want, and it can cause problems with browsers have trouble with downloading files that contain HTML. (That may be because the server or browser is sending/assuming a content-type: text/html). The Script Library also uses another method (I've been experimenting with various things, and the experiments are not at an end) to download a file that may not exist until you click the link. Take a look at: http://www.rebol.org/cgi-bin/cgiwrap/rebol/documentation.r?script=patch-ftp-226-handling.r That has links to Download documentation as: [HTML] or [editable]. Those files probably don't exist until you click the link. The link is to a program. That program creates the file and then sends a HTTP redirect to point your browser at the file it has created: print join Location: http://www.rebol.org/library/docs-download/patch-ftp-226-handling.r print ^/ ;; newline to end HTTP headers Sunanda. -- To unsubscribe from this list, just send an email to [EMAIL PROTECTED] with unsubscribe as the subject.
[REBOL] CGI Re:(2)
Though, as noted on an earlier message on this list, doing so means that you will only get one value from a multi-select input. Brett. - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, October 04, 2000 8:08 PM Subject: [REBOL] CGI Re: Sharriff Aina wrote: Sorry to bother you with this newbie question: Why does one have to "make object!" after a "decode-cgi" ? just curious... Actually, one doesn't have to, but it's safer for your software if you so, as you can put arbitrary Rebol code in the cgi url. Putting the results of the decode-cgi in a object minimises the damage the Rebol code can do. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/ http://members.xoom.com/AndrewMartin/ --
[REBOL] CGI Re:
It simply makes an easy-access object out of the data: decode-cgi "foo=10bar=20" == [foo: 10 bar: 20] when you make an object out of it with: cgi: make object! decode-cgi "foo=10bar=20" you can access the form values like this: cgi/foo == 10 cgi/bar == 20 The reason you might not make an objects is if you have multiple form items on the page with the same name so your cgi query string looks like this: "foo=10bar=20bar=30" Then if you make an object, you'll only get one value for 'bar. WARNING You can also DO the decoded cgi block and it will set the words to their respective valus. This is neat but remember that any word can come in through cgi so if you do this: do decode-cgi "foo=10bar=20read=0" will stomp all over the word 'read... not a good idea. And since you do not have control over what somebody could hack pu and send in to you cgi program it is not generally a good idea to DO the decode-cgi block. WARNING Sterling Hi guys! Sorry to bother you with this newbie question: Why does one have to "make object!" after a "decode-cgi" ? just curious... Sharriff Aina med.iq information quality in healthcare AG Gutenbergstr. 42 41564 Kaarst tel.: 02131-3669-0 fax: 02131-3669-599 www.med-iq.de
[REBOL] cgi Re:(4)
Here is what I have discovered. Printing text/html output of the following... print {INPUT TYPE="hidden" name="article-reference" value="27155544"} ...passes a URL appended with "?article%2Dreference=27155544" creating a word REBOL cannot use. while... print {INPUT TYPE="hidden" name="articlereference" value="27155544"} ...passes a word REBOL can use. It seems the hyphen was causing a problem with my CGI. -Ryan INPUT TYPE="hidden" NAME="name" VALUE="value" will pass a static value with a form I need to figure out how to pass a static value with a form, one that is not generated or chosen by the submitter
[REBOL] cgi Re:(2)
Well, using... cgi-input: make object! decode-cgi system/options/cgi/query-string and then calling "comments-reference" using cgi-input/comments-reference from the url... http://www.beosjournal.com/cgi-bin/displaycomments.cgi?comments-reference= 2715121834 Worked! I can now view the comments page, although there are no comments yet and here is why: I need to send another reference value to another script which processes submitted comments. When I try to submit a comment, I get an error because the url ends up being as follows... http://www.beosjournal.com/cgi-bin/processcomments.cgi?article-reference= 2715121834?heading=First+commentbody=No+comment.name=Gemail=g%40g.mib As you can see, I try to pass an "article-reference" value by appending the url and then also try to pass form values along with the same query string, producing double "?" query string markers. I'm working on this. I need to figure out how to pass a static value with a form, one that is not generated or chosen by the submitter. -Ryan
[REBOL] cgi Re:(3)
Ryan wrote: I need to figure out how to pass a static value with a form, one that is not generated or chosen by the submitter. IIRC, hidden controls in the HTML form will provide this. Andrew Martin ICQ: 26227169 http://members.xoom.com/AndrewMartin/ --
[REBOL] CGI Re:(4)
Perhaps also related to my "Rebol on IIS not sending email when commanded to via cgi." (Although I have no problem writing to files.) TBrownell --- [EMAIL PROTECTED] wrote: - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 15, 2000 3:45 AM Subject: [REBOL] CGI Re:(2) Howdy, Daniel: Thank you for your help, everyone. This is how far I've got until now : Apparently, file access is working normally only in the first cgi script launchedby Apache, all itschild processes (subsequent calls of scripts, whether they reside in cgi-bin or elsewhere) have problems to access the local file system. That's an odd one. We'll have a closer look at that one when we can (cgi with apache for windows, right?), but unfortunately don't have a decent answer for why you're seeing that behavior right now. Is having your cgi-bin script reading and writing files outside of cgi-bin what you want to accomplish? Perhaps you could have a separate rebol process running living in the directory that you want to write files in that talks through ports to the cgi-bin program. This background REBOL process could do the writing and reading of files on the cgi-bin script's behalf. -jeff Hey Jeff, This might be related to the do/args "string" bug I found, feedback #3246. Cheers, Allen K __ Do You Yahoo!? Yahoo! Photos -- now, 100 FREE prints! http://photos.yahoo.com
[REBOL] CGI Re:(5)
Hello, You mentioned that the scripts runs another script with 'do/args - where does that other script reside? Is it in the same/lower directory, or a higher? The latter script reside in a higher directory. Regards, Rachid -- [EMAIL PROTECTED] http://perso.worldonline.fr/mutant
[REBOL] CGI Re:
Thank you for your help, everyone. This is how far I've got until now : Apparently, file access is working normally only in the first cgi script launched by Apache, all its child processes (subsequent calls of scripts, whether they reside in cgi-bin or elsewhere) have problems to access the local file system. Can someone help me with the following : Consider this : print exists %. In other words, does the current directory exists ? (which has to be always true). However, when this line is called from a CGI script (it's not part of the CGI script itself, but part of a rebol script called with "do/args" from the CGI script), it produces "false". I'm running Apache. daniel -- [EMAIL PROTECTED] http://perso.worldonline.fr/mutant -- [EMAIL PROTECTED] http://perso.worldonline.fr/mutant
[REBOL] CGI Re:(2)
Howdy, Daniel: Thank you for your help, everyone. This is how far I've got until now : Apparently, file access is working normally only in the first cgi script launchedby Apache, all itschild processes (subsequent calls of scripts, whether they reside in cgi-bin or elsewhere) have problems to access the local file system. That's an odd one. We'll have a closer look at that one when we can (cgi with apache for windows, right?), but unfortunately don't have a decent answer for why you're seeing that behavior right now. Is having your cgi-bin script reading and writing files outside of cgi-bin what you want to accomplish? Perhaps you could have a separate rebol process running living in the directory that you want to write files in that talks through ports to the cgi-bin program. This background REBOL process could do the writing and reading of files on the cgi-bin script's behalf. -jeff
[REBOL] CGI Re:(3)
- Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 15, 2000 3:45 AM Subject: [REBOL] CGI Re:(2) Howdy, Daniel: Thank you for your help, everyone. This is how far I've got until now : Apparently, file access is working normally only in the first cgi script launchedby Apache, all itschild processes (subsequent calls of scripts, whether they reside in cgi-bin or elsewhere) have problems to access the local file system. That's an odd one. We'll have a closer look at that one when we can (cgi with apache for windows, right?), but unfortunately don't have a decent answer for why you're seeing that behavior right now. Is having your cgi-bin script reading and writing files outside of cgi-bin what you want to accomplish? Perhaps you could have a separate rebol process running living in the directory that you want to write files in that talks through ports to the cgi-bin program. This background REBOL process could do the writing and reading of files on the cgi-bin script's behalf. -jeff Hey Jeff, This might be related to the do/args "string" bug I found, feedback #3246. Cheers, Allen K
[REBOL] CGI Re:(3)
So, Daniel: what do you see if you do what-dir in the other script? Can you change-dir? What are the system/options/path, and system/script/path values? Can your script write out a test file, if so, where does it show up? The exists? function actually makes this determination by attempting to open a port to the file or url your specified. If opening the port results in an error it does not exist (for all practical purposes that's true as far as REBOL's concerned there)-- otherwise it does exist. Point being that other things can make it appear to not exist. -jeff Just a guess, but does the same happen if you add a trailing slash, ie: print exists? %./ Yes it does. I guess it has to do with file permissions. I'm running NT, the script does some stuff on files but it's local. The rebol script invoked with the do/args is outside of the cgi-bin directory defined in Apache. Is this a problem ? (it runs fine, it just seems oblivious to what local files pertains). daniel
[REBOL] CGI Re:(4)
So, Daniel: what do you see if you do what-dir in the other script? Can you change-dir? What are the system/options/path, and system/script/path values? Can your script write out a test file, if so, where does it show up? Jeff, All the above works as intended when launched with the Rebol interpreter. However, when called from a cgi-script, a change-dir in the regular script yields : ** Access Error: Cannot open /c/winnt/. ** BTW, the same change-dir (change-dir %/c/winnt/) in the CGI script does not work neither and results in the same error. The external script runs in its own directory [system/script/path]. The CGI script runs in the cgi-bin as defined in httpd.conf (Apache on NT) In both scripts, if I write print system/options/path, I get ** Script Error: Invalid path value: path. ** Where: system/options/path daniel The exists? function actually makes this determination by attempting to open a port to the file or url your specified. If opening the port results in an error it does not exist (for all practical purposes that's true as far as REBOL's concerned there)-- otherwise it does exist. Point being that other things can make it appear to not exist. -jeff Just a guess, but does the same happen if you add a trailing slash, ie: print exists? %./ Yes it does. I guess it has to do with file permissions. I'm running NT, the script does some stuff on files but it's local. The rebol script invoked with the do/args is outside of the cgi-bin directory defined in Apache. Is this a problem ? (it runs fine, it just seems oblivious to what local files pertains). daniel -- [EMAIL PROTECTED] http://perso.worldonline.fr/mutant
[REBOL] CGI Re:(4)
Thank you for your answer. I don't see why this would happen, as I'm working on local files with an administrator account (NT). What user does the *web server* run as? CGI scripts will inherit the same permissions as the web server, which usually runs with minimal permissions. Regards, Kev Kevin McKinnon, Network Engineer [EMAIL PROTECTED] Sunshine Communications http://www.sunshinecable.com PGP Public Key: http://www.dockmaster.net/pgp.html PGP 6.0 www.pgp.com
[REBOL] CGI Re:(4)
Hello, You mentioned that the scripts runs another script with 'do/args - where does that other script reside? Is it in the same/lower directory, or a higher? Regards, Rachid
[REBOL] CGI Re:
Try this... you just need to write out and read in as binary to get the file read and sent properly. Sterling #!/usr/local/bin/rebol -csq REBOL [] file: read/binary %test.xls ; file is 17920 bytes long prin [ {Content-Type: application/octet-stream; name="file"} newline {Content-Disposition: attachment; filename="file"} newline newline] write-io system/ports/output file length? file Hi I wrote CGI script in REBOL, and I run it, but script doesn't work. I running this script on FreeBSD server (WWW Apache server). I write something like that ;-- begin #!/usr/local/bin/rebol -csq REBOL [] file: read %test.xls ; file is 17920 bytes long prin [ {Content-Type: application/octet-stream; name="file"} newline {Content-Disposition: attachment; filename="file"} newline newline] print file ;--end When i run this script (typing in browser http://aaa.bbb.cc/cgi-bin/examples/test) browser ask me on filename and send to me file, but saved file have only 5340 bytes :( What I can transfer file in binry mode Please help me, it's very important to me, because i can't finish my project. Grettings Mark Sorry for my "English"
[REBOL] cgi Re:(3)
I am no expert either, but I seem to have it going (at last). I added the following to access.conf Directory /home/ingo/public_html AllowOverride All Options ExecCGI FollowSymLinks order allow,deny allow from all /Directory This allows me to use CGI (ExecCGI) within the dir /home/ingo/public_html and all its sub-dirs. CGI scripts need to have the ending .cgi (this may be changed somewhere else), be runnable, and have a #!rebol -cs in the first line (if the rebol executable is in the same directory) I don't remember if I changed other settings in the apache conffiles, sorry 1. SCRIPT LANGUAGE="REBOL" RUNAT="SEREVR" This is not possible now, but wait for the rebol apache module, due to be in betatest soon. Of course then your provider needs to install it ... (unless you're your own provider) hope this helps Ingo Those were the words of [EMAIL PROTECTED]: I am not an expert on this, and I don't have rebol working under Apache (yet) but the following thoughts occur to me: 1. SCRIPT LANGUAGE="REBOL" RUNAT="SEREVR" could "SEREVR" be misspelled? 2. I use SuSE 6.1 which does a lot of the install/config of Apache for you. I have experimented with Apache only in loopback mode. The main config file is /etc/httpd/httpd.conf and it has a lot of comments in it which provide clues on which settings to fiddle with. I have included some *severely* snipped text from this file to give an idea - it is a starting point - I cannot claim to have retained all the settings you may need to fiddle with. Apache has a lot of documentation - books, web site, and stuff with the distribution. Basically, it seems that any program that Apache calls through the cgi interface must either be loaded as an Apache module, or configured via httpd.conf or both. 3. I hope this is a little help, as I would like to see the detailed instructions myself. On Sat, 27 Nov 1999, you wrote: Well ... I have been waiting for a reply to the message below. Has there been a reply and I missed it? I have been trying to use rebol for CGI scripts which is the main reason why I started to use it. People have send CGI examples to me, which work for them but they don't work for me. I have by now tried to run rebol cgi scripts on WIN95 and PWS4, WIN98 and PWS4, Windows NTWS and PWS4, Windows NT Server and even tried it on a SuSe Linux and Apache. But nothing has worked for me so far. A previous message to the list said that rebol cgi did not need any setting up on the server, it only needs to have the rebol.exe in a directory where the scripts are. - Doesn't work for me. I have also seen an example of rebol to be used as follows ... SCRIPT LANGUAGE="REBOL" RUNAT="SEREVR" etc ... I would be VERY VERY VERY interested in knowing how to set this up or in knowing where I could host my web site that supports this. Any help would be great as I just don't know what else to do. = snippings from /etc/httpd/httpd.conf which may be = relevant to getting rebol to work under SuSe 6.1/Apache # # Each directory to which Apache has access, can be configured with respect # to which services and features are allowed and/or disabled in that # directory (and its subdirectories). # # First, we configure the "default" to be a very restrictive set of # permissions. # Directory / Options FollowSymLinks AllowOverride None /Directory # # Note that from this point forward you must specifically allow # particular features to be enabled - so if something's not working as # you might expect, make sure that you have specifically enabled it # below. # # # ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the realname directory are treated as applications and # run by the server when requested rather than as documents sent to the client. # The same rules about trailing "/" apply to ScriptAlias directives as to # Alias. # ScriptAlias /cgi-bin/ "/usr/local/httpd/cgi-bin/" # # "/usr/local/httpd/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # Directory "/usr/local/httpd/cgi-bin" AllowOverride None Options None Order allow,deny Allow from all /Directory # cgi-bin for SuSE help system # using SetHandler Directory "/usr/lib/sdb/cgi-bin" AllowOverride None Options +ExecCGI -Includes SetHandler cgi-script /Directory # enable perl for cgi-bin # Location /cgi-bin AddHandler perl-script .pl PerlHandler Apache::Registry PerlSendHeader On Options +ExecCGI /Location # # To use CGI scripts: # AddHandler cgi-script .cgi Hi Rebols,
[REBOL] cgi Re:
Well ... I have been waiting for a reply to the message below. Has there been a reply and I missed it? I have been trying to use rebol for CGI scripts which is the main reason why I started to use it. People have send CGI examples to me, which work for them but they don't work for me. I have by now tried to run rebol cgi scripts on WIN95 and PWS4, WIN98 and PWS4, Windows NTWS and PWS4, Windows NT Server and even tried it on a SuSe Linux and Apache. But nothing has worked for me so far. A previous message to the list said that rebol cgi did not need any setting up on the server, it only needs to have the rebol.exe in a directory where the scripts are. - Doesn't work for me. I have also seen an example of rebol to be used as follows ... SCRIPT LANGUAGE="REBOL" RUNAT="SEREVR" etc ... I would be VERY VERY VERY interested in knowing how to set this up or in knowing where I could host my web site that supports this. Any help would be great as I just don't know what else to do. Regards, Marco Mark - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, November 26, 1999 10:39 AM Subject: [REBOL] cgi hello, I just discovered Rebol last week and have become a little obsessed with its simple beauty. Hence I want to re-write all my perl scripts and bin it for good. I've been desperately tring to get rebol cgi support set up on my macintosh and a linux box. To no avail. I've never had to tinker with the internals of Apache before, nor Webstar. Any of you rebol kings have some advice? I'm running: Rebol ppc Webstar 2.0 RedHat 5.2 Thanks, Sam Phillips -- Head of Design Multimedia Brand: Promotion, merchandising, design, licensing, sponsorship, event services. 34 St Enoch Square t: +44 (0) 141 221 0342 Glasgow G1 1DF f: +44 (0) 141 221 5456 Scotland, UK i: +44 (0) 141 221 5859