1. Euphoria and CGI scripts

Hello all.

I don't know anything about writing CGI scripts, but I know it can be done
in Euphoria.  Does a program have to be bound in order to be used as a CGI
script, or could an interpreted program be used?  I was also wondering how
much I'd have to learn in order to write CGI scripts in Euphoria.  Would I
have to learn anything about programming for networks, etc.?

Regards,

Ben

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » topic index » view message » categorize

2. Re: Euphoria and CGI scripts

On Thu, 02 Sep 1999, Ben wrote:
> Hello all.
>
> I don't know anything about writing CGI scripts, but I know it can be done
> in Euphoria.  Does a program have to be bound in order to be used as a CGI
> script, or could an interpreted program be used?  I was also wondering how
> much I'd have to learn in order to write CGI scripts in Euphoria.  Would I
> have to learn anything about programming for networks, etc.?
>

Hi:

No, it is not necessary to bind. You can run a cgi by including the shell path
#!/home/user/euphoria/bin/exu line at the top (in Linux) or via a batch file
(in Windows).  This might raise some security issues, however, so eventually
you may prefer to bind the cgi's.

You won't need to know much at all about networks, just a couple of things
about how html forms and actions work.  It's pretty simple.

Unfortunately, I removed my cgi tutorial from my web site, and have lost the
source. It's possible that Rob has a copy (?)

Below is a simple cgi to return the environmental variables:

Regards,
Irv Mullins

#!/home/irv/euphoria/bin/exu

constant envars =
"AUTH_TYPE","CONTENT_TYPE","CONTENT_LENGTH",
"HTTP_USER_AGENT","HTTP_HOST","HTTP_CONNECTION",
"REMOTE_PORT","SERVER_ADMIN"}

-- build html page:
   puts(1,"Content-type: text/HTML\n\n") -- most important!
   puts(1,"<title>CGI2.EX</title>\n")
   puts(1,"<body>\n")
   puts(1,"<H3>Euphoria CGI environmental variables found:</H3>\n")

-- retrieve values of environmental variables listed above:
   for i = 1 to length(envars) do
       if not atom (getenv(envars[i])) then -- show only initialized vars
          printf(1, "<LI>%s = %s </LI>", {envars[i], getenv(envars[i])} )
       end if
   end for

-- end html page:

new topic     » goto parent     » topic index » view message » categorize

3. Re: Euphoria and CGI scripts

Ben,

On my website is a cgi.e program which my help get you started. The URL is
http://2fargon.hypermart.net/ and it is under the downloads section.  This
include file was written for EuLinux, but with a couple of minor changes, it
should work just fine on windows as well.  An important thing to note is
that unless you have your own web server, you'll have to get the sysop to
agree to install the Euphoria interpreter in order for your scripts to
work.  Let me know how it goes and if you need any help!

Brian

new topic     » goto parent     » topic index » view message » categorize

4. Re: Euphoria and CGI scripts

Thanks!

Brian, I looked at your CGI.E.  It doesn't look like it would be too
complicated, but I'll have to do some reading on using CGI scripts from the
HTML end in order to get some perspective.

I have a homepage at Geocities, and I don't know what their policy on CGI
scripts is.  If there are some security issues, they might have a problem
with it.  I'll have to look into it.

Ben

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » goto parent     » topic index » view message » categorize

5. Re: Euphoria and CGI scripts

On Thu, 02 Sep 1999, you wrote:
> Thanks!
>
> I have a homepage at Geocities, and I don't know what their policy on CGI
> scripts is.  If there are some security issues, they might have a problem
> with it.  I'll have to look into it.

I don't know about Geocities, but most ISP's would - understandably - refuse to
run Euphoria or anything other than perl scripts, for fear of locking up a
server. Even then, they usually limit CGI's to commercial accounts.

Options: 1.locate a very small ISP who will cooperate,  2. get a static IP
address and use your home pc to serve the web, or 3. just run on a local loop.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

6. Re: Euphoria and CGI scripts

>I have a homepage at Geocities, and I don't know what their policy on CGI
>scripts is.  If there are some security issues, they might have a problem
>with it.

I can tell you that it's very doubtful that Geocities will let you run cgi
scripts, especially one that's not written in Perl.  My advice would be to
explain what you want to do to your ISP, and if that doesn't work, call the
computer lab at your local college or university and see if they would be
willing to give you a shell account.

You might also try setting up a webserver on your own PC. There is a very
good one called ALIBABA which I have used for Euphoria CGI before, and it's
really easy to set up.  The best part is, if you a running the server and
you have a web browser, you don't even need to be connected to the internet
to run your cgi programs.  This is very good if you're like me and can't
afford to have a dedicated high-speed internet connection.

Hope this helps,
Brian

new topic     » goto parent     » topic index » view message » categorize

7. Re: Euphoria and CGI scripts

For Ben and whoever:

I have posted a set of Euphoria CGI scripts demonstrating the use of the CGI
environment and CGI forms. They run on Linux, and should work on Windows as
well. Download cgi.zip from http://www.mindspring.com/~mountains

Also, there are some updates there to GraphApp.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

8. Re: Euphoria and CGI scripts

Este es un mensaje multipartes en formato MIME.
--------------1682FED3043CF3CAC8A67873

Hi:

A question for all the cgi gurus

When I call a cgi from a link without parameters in my web page (not a
form), there is not any data to cgiparse.

I'm doing a guest book.  I want call the cgi from a link to view the all
the messages and a form to add a new one.

When the same cgi is called from the form, add the message to the
database before do the 'normal' operation.

I have problems with some '0' that appear in the database between the
registers.
What is the problem?
--
+-+-+-+-+-+-+-+-+-+
Marco A. Achury P.
http://members.xoom.com/achury
mailto:achury at eldish.net
ICQ: 19390207
Caracas, Venezuela
--------------1682FED3043CF3CAC8A67873
 name="Mensajes.exu"
Content-Disposition: inline;
 filename="Mensajes.exu"

#!/usr/euphoria/bin/exu

global integer ArchDatos
constant archivo="../mensajes/mensajes.db"

global atom dump --Archivo al que se volcan variables

include get.e

-- Interpreta la entrada estandar proveniente de un formulario
function cgi_parse(sequence entrada)
sequence hex
sequence val
atom car -- Caracter a calculado con hexagesimal
-- atom dig -- Digito hexagesimal
integer i -- Caracter siendo analizado
integer j -- Indica numero de "registro", consecutivo de parametros
integer k -- Indica numero de "campo" del registro: 1->Nombre 2->Valor
sequence parametros
hex={"0123456789abcdefABCDEF"}
    if equal(entrada, {}) then
        return {}
    end if
    i=1     j=1     k=1
    parametros={{{},{}}}
    while i<length(entrada) do
        if entrada[i]='+' then
            parametros[j][k]=append(parametros[j][k], ' ')
        elsif entrada[i]='=' then
            k=2
        elsif entrada[i]='&' then
            k=1
            j=j+1
            parametros = append(parametros, {{},{}})
        elsif entrada[i]='%' then
            --trace(1)
            car=0
            car=val[find(entrada[i+1],hex[1])]*16+val[find(entrada[i+2],hex[1])]
            parametros[j][k]=append(parametros[j][k], car)
            i=i+2
            trace(0)
        else
            parametros[j][k]=append(parametros[j][k], entrada[i])
        end if
        i=i+1
    end while
    puts(dump, "Salida de cgi-parse")
    print(dump, parametros)
    return parametros
end function

procedure NuevoMensaje(sequence entrada)  --Pone un nuevo mensaje en la base de
datos
sequence mensajes
sequence Nombre --Remitente del mensaje
sequence Texto --Contiene el texto del mensaje
    if sequence(entrada[1][2]) and sequence( entrada[2][2]) then
        Nombre = entrada[1][2]
        Texto = entrada[2][2]
        --Abrir base de datos...
        ArchDatos=open(archivo,"r")
        if ArchDatos!=-1 then --Si existe el archivo
            --Lee la estructura de datos
            mensajes=get(ArchDatos)
            close(ArchDatos)
        else --Si no existe, tendremos que crear una nueva...
            mensajes={}
        end if
        if equal(mensajes,{}) then
            mensajes ={Nombre, Texto}
            -- Poner la entrada al final de la hilera de mensajes
        else
            mensajes=prepend(mensajes, {Nombre, Texto})
        end if
        -- Si hay muchos mensajes elimina los mas viejos
        if length(mensajes)>20  then
            mensajes=mensajes[1..20]
        end if
        -- Grabar nuestra estructura en la base de datos
        ArchDatos=open(archivo,"w")
        print(ArchDatos, mensajes)
        close(ArchDatos)
    end if
end procedure

procedure encabezados()
    puts (1,"Content-type: text/html\n\n")
    puts (1,"<html><body>\n")
    puts (1,"<a href=\"/index.html\">Volver a nuestra pagina principal</a>\n")
    puts (1,"<h1>Tablero de mensajes</h1>\n")
    puts (1,"Bienvenido a nuestro sistema de mensajes<br>\n")
end procedure

procedure formulario()
    -- Abrir archivo html, y volcarlo en el formulario
    puts(1,"<h2>Enviar Mensajes</h2>\n" &
    "<form action=\"/cgi-bin/mensajes.exu\" method=\"POST\">\n"&
    "Nombre: <input type=\"text\" name=\"nombre\"><BR>\n"&
    "Comentario:<textarea name=comentario rows=3 cols=60></textarea>\n"&
    "<input type=submit value=\"ENVIAR\"><input type=reset value=\"BORRAR\">\n"&
    "<hr><p>Marco Antonio Achury<br>Agosto de 1999")
end procedure

procedure MostrarMensajes()
sequence mensajes
sequence nombre
object contenido
    mensajes=get(ArchDatos)
    if mensajes[1] = GET_SUCCESS then
        mensajes=mensajes[2..length(mensajes)]
        puts (1,"Encontrados mensajes <br>")
        for r=1  to length(mensajes)  do
--          ? mensajes
            nombre=mensajes[r][1]
            contenido=mensajes[r][2]
            puts(1, "<p>Mensaje de: <b>")
            puts(1, nombre)
            puts(1, "</b><p>")
            puts(1, contenido)
            puts(1, "<hr>")
        end for
    end if
    close(ArchDatos)
end procedure

procedure pagina()
    -- Probar si existe la base de datos
    encabezados()
    ArchDatos=open(archivo,"r")
    if ArchDatos=-1 then  --Si la base de datos no existe
        puts(1, "En este momento no hay mensajes.<br>")
    else
        MostrarMensajes()
    end if
    formulario()
end procedure

-- procedure @ProgramaPrincipal()
object entrada
    entrada = gets (0)
    -- Si la llamada trae datos (hecha desde formulario)
    dump =open("../mensajes/dump", "w")
    if sequence(entrada) then
        -- Poner nuevo mensaje en la base de datos
        NuevoMensaje(cgi_parse(entrada))
    end if
    --Presentar la pagina actualizada
    pagina()

--------------1682FED3043CF3CAC8A67873--

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu