1. Eu, CGI and file-access
- Posted by stab master <stabmaster_ at HOTMAIL.COM> Dec 03, 1999
- 448 views
I'm taking a course at school called "computer-networking", and our teacher thought that we should do a linux-project since linux is the "ultimate" networking OS (hrm). So, we all got to install a copy of linux (I chose RedHat 6.0, wich I very much regret) and set up an apache-server of our own. Then it was decided that we should learn some CGI. I took a quick look at Perl before deciding to go with Euphoria. I downloaded Irv Mullins' CGI-examples for Euphoria and started experimenting. Everything went just fine until I wanted to save the input-data to a local file. I'm trying to create and open a file using something like this: atom fn fn=open("/home/results.res","wb") But open() will return -1 every, single time (argh..). Is there something I'm doing wrong? Is there some little quirk when running Euphoria under linux? Or are there perhaps some special rules when opening files through a CGI-script? If I can't get this working, then I can't see any other way out than to use Perl instead, and that's something I really don't want. ______________________________________________________ Get Your Private, Free Email at http://www.hotmail.com
2. Re: Eu, CGI and file-access
- Posted by Brian Jackson <bjackson at 2FARGON.HYPERMART.NET> Dec 03, 1999
- 445 views
On Fri, 3 Dec 1999 05:41:32 PST, stab master <stabmaster_ at HOTMAIL.COM> wrote: >I'm taking a course at school called "computer-networking", and our teacher >thought that we should do a linux-project since linux is the "ultimate" >networking OS (hrm). Honestly, it truly is. It IS the Internet, and has been since 1965. It takes 3 windows machines to do what 1 Linux box can do. (Brian steps down from soapbox, exits stage left) >So, we all got to install a copy of linux (I chose >RedHat 6.0, wich I very much regret) and set up an apache-server of our own. >Then it was decided that we should learn some CGI. I took a quick look at >Perl before deciding to go with Euphoria. I downloaded Irv Mullins' >CGI-examples for Euphoria and started experimenting. Everything went just >fine until I wanted to save the input-data to a local file. I'm trying to >create and open a file using something like this: >atom fn >fn=open("/home/results.res","wb") > >But open() will return -1 every, single time (argh..). Is there something >I'm doing wrong? Is there some little quirk when running Euphoria under >linux? Or are there perhaps some special rules when opening files through a >CGI-script? If I can't get this working, then I can't see any other way out >than to use Perl instead, and that's something I really don't want. > **************** UNTESTED HYPOTHESIS/SOLUTION FOLLOWS ******************* I not an *expert* at Linux, but I will bet that your server is set up to run all of your CGI scripts as the user 'nobody'. Nobody has no rights to write any data to disk, unless you seriously want to compromise security (i.e, make your whole hard drive writeable to the outside world.) I suggest that you create a new user call 'cgid' (CGI-Daemon), or whatever you like, tell Apache to run all cgi scripts as this user, and then make all your file writes happen in the /home/cgid/ directory. That way, you data is still protected, but you've got write access. I've run into the same type of problems when trying to debug a cgi script (ex.err can't be created either). BTW, if I'm right, you'd be having the same problem in Perl. Good luck, Brian
3. Re: Eu, CGI and file-access
- Posted by "Lucius L. Hilley III" <lhilley at CDC.NET> Dec 03, 1999
- 436 views
> ---------------------- Information from the mail header -------- > Sender: Euphoria Programming <EUPHORIA at LISTSERV.MUOHIO.EDU> > Poster: stab master <stabmaster_ at HOTMAIL.COM> > Subject: Eu, CGI and file-access > ---------------------------------------------------------------- > <SNIP> > I'm trying to create and open a file using something like this: > atom fn > fn=open("/home/results.res","wb") > > But open() will return -1 every, single time (argh..). Is there something > I'm doing wrong? Is there some little quirk when running Euphoria under > linux? Or are there perhaps some special rules when opening files through a > CGI-script? If I can't get this working, then I can't see any other way out > than to use Perl instead, and that's something I really don't want. > What? no signature? 8^( And I so much enjoy leaving those in. Nevermind.... Okay, I'm no expert but lets cover the following common problems. 1. Directory permissions. Does the program have permission to write to that directory? 2. Spelling/Typo? Are you sure you have the directory structure correctly spelled? NOTE: this doesn't appear to be your problem. 3. I can't currently think of any more of the common mistakes. Lucius L. Hilley III lhilley at cdc.net +----------+--------------+--------------+ | Hollow | ICQ: 9638898 | AIM: LLHIII | | Horse +--------------+--------------+ | Software | http://www.cdc.net/~lhilley | +----------+-----------------------------+
4. Re: Eu, CGI and file-access
- Posted by Irv Mullins <irv at ELLIJAY.COM> Dec 03, 1999
- 458 views
On Fri, 03 Dec 1999, you wrote: > I'm taking a course at school called "computer-networking", and our teacher > thought that we should do a linux-project since linux is the "ultimate" > networking OS (hrm). So, we all got to install a copy of linux (I chose > RedHat 6.0, wich I very much regret) and set up an apache-server of our own. > Then it was decided that we should learn some CGI. I took a quick look at > Perl before deciding to go with Euphoria. I downloaded Irv Mullins' > CGI-examples for Euphoria and started experimenting. Everything went just > fine until I wanted to save the input-data to a local file. I'm trying to > create and open a file using something like this: > atom fn > fn=open("/home/results.res","wb") As it happens, I was just working with CGI's last night, and was implementing exactly the same thing: Source code pasted at end of this message. > But open() will return -1 every, single time (argh..). Is there something > I'm doing wrong? Is there some little quirk when running Euphoria under > linux? Or are there perhaps some special rules when opening files through a > CGI-script? If I can't get this working, then I can't see any other way out > than to use Perl instead, and that's something I really don't want to do.... It has to do with permissions and security. Apache is another user, and doesn't have permission to write to your directory. Instead, set up a directory under /httpd to store your files: Here's what I have: /usr/local/httpd/public is owned by wwwrun and is part of the bin group. I set full read/write/execute permissions on /public with chmod 777. You may want to narrow that down a bit. Execute wouldn't be a good idea, if you were using it in real life. Also, you will probably want to change the program to append to a file, rather than writing over the old file. Here's the source: Note that you need a copy of exu or pdexu in the cgi-bin directory to make this work as written. #!exu -------------------------------------------------- -- This script handles input from EuForm.html, and saves the output -- -- to a file "EuWeb.txt" in the directory /usr/local/httpd/public -- -------------------------------------------------- atom fn object query object now now = date() -- build html page: puts(1,"Content-type: text/HTML\n\n") puts(1,"<title>CGI-TEST.EX</title>") puts(1,"<body>") puts(1,"<H3><IMG SRC=\"/gif/suse_150.gif\" ALIGN=\"RIGHT\" >") puts(1,"Euphoria CGI Form Results:</H3>") printf(1,"Around %02d:%02d:%02d EST ",{now[4],now[5],now[6]}) printf(1,"on %02d/%02d/%4d <BR>",{now[2],now[3],now[1]+1900}) puts(1,"You submitted the following information ") puts(1,"(your answers are in <B>boldface</b>)<P><P>") -- retrieve values of environmental variables: query = getenv("QUERY_STRING") if not atom(query) then for i = 1 to length(query) do if query[i] = '&' then puts(1,"<BR></B>") elsif query[i] = '=' then puts(1,"=<B>") elsif query[i] = '+' then puts(1,' ') else puts(1,query[i]) end if end for end if -- save output to text file: if not atom(query) then fn = open("/usr/local/httpd/public/EuWeb.txt","w") if fn < 1 then puts(1,"<br>Error opening EuWeb.txt\n") else puts(1,"<br>Saving input to EuWeb.txt\n") for i = 1 to length(query) do puts(fn,query[i]) end for close(fn) end if end if -- end of html: --Irv