Re: Eu, CGI and file-access

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu