Project

General

Profile

Newbie using cgi-bin: how passing parameters?

Added by elberto about 5 years ago

Hi to all,
I'm newbie about lighttpd and cgi-bin and I'm starting to create my custom webpage.

In several pages I've seen this code:


<a href="cgi-bin/simple.cgi?John" target="Frame5" style="text-decoration:none">Comandi</a><br>

And on simple.cgi code I find:

#!/bin/bash

echo "Content-type: text/html" 
echo "" 
echo "<html><head><title>Welcome</title></head>" 
echo "<body>" 
echo "parameter is <$1>" 
echo "<br>" 
echo "<br>" 
if [ "$1" = "John" ]
then
        echo "Name is John" 

else
        echo "unknown" 
fi

echo "</body></html>" 

It doesn't work.

I can also try:

<a href="cgi-bin/simple.cgi?name=John" target="Frame5" style="text-decoration:none">Comandi</a><br>

and

echo "name is $name" 

with same result.

Here my configuration:


pi@raspberrypi:/var/www/html/cgi-bin $ cat /etc/lighttpd/lighttpd.conf
server.modules = (
        "mod_access",
        "mod_alias",
        "mod_compress",
        "mod_redirect",
# aggiunto io per cgi-bin
        "mod_cgi",

# per test favicon
        "mod_rewrite" 

)

server.document-root        = "/var/www/html" 
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log" 
server.pid-file             = "/var/run/lighttpd.pid" 
server.username             = "www-data" 
server.groupname            = "www-data" 
server.port                 = 80

# provo, per debug
# no, non mi riconosce il modulo
#fastcgi.debug = 1

#index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
index-file.names            = ("index.html")
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/" 
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl" 
include_shell "/usr/share/lighttpd/include-conf-enabled.pl" 

# aggiunto io per cgi-bin
$HTTP["url"] =~ "^/cgi-bin/" {
        alias.url += ( "/cgi-bin/" => "/var/www/html/cgi-bin/" )
        cgi.assign = (
                ".py"  => "/usr/bin/python",
        ".pl"  => "/usr/bin/perl",
        ".sh"  => "/bin/sh",
        "" => "",
        )
}

# prova per problemi favicon

url.rewrite-once = (
    "^/favicon.ico$" => "./favicon.ico" 
)

Where is the problem?
Thanks.


Replies (1)

RE: Newbie using cgi-bin: how passing parameters? - Added by gstrauss about 5 years ago

That's not how CGI works.

The Common Gateway Interface (CGI) Version 1.1
https://tools.ietf.org/html/rfc3875

The query string parameters are found in the QUERY_STRING environment variable, and you have to split and decode it.
https://tools.ietf.org/html/rfc3875#section-4.1.7
If something else were to decode it for you, there may be security risks depending on how your shell script performed command line parsing, and the allowed contents of the decoded query string parameters. The encoding might preserve information that might be lost if decoded and passed to another program as decoded.

The problem must be that you found a poor example of someone's CGI.

    (1-1/1)