Quantcast

how do I enable CGI scripts in Tomcat 6?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how do I enable CGI scripts in Tomcat 6?

Grossman, Robert B
We have a web application running in Tomcat 6 on Ubuntu, and we want to run CGI scripts in Perl via the browser.  The descriptions of the CGI enabling process that we have found on the Web, e.g. http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html and http://www.wellho.net/solutions/java-running-cgi-scripts-in-apache-tomcat.html , seem simple enough, but they have not worked for us.

We already had set <context privileged="true"> in Tomcat's context.xml.  We created a WEB-INF/cgi directory in our web app's hierarchy.  In $CATALINA_BASE/conf/web.xml, we uncommented the CGI servlet description and servlet matching, and we set the cgiPathPrefix to WEB-INF/cgi/ and the servlet matching pattern to /cgi/*.  (We also tried cgi/* and cgi-bin/* , with no better results.)

We downloaded servlets-cgi.renametojar from a Tomcat 5 distribution, copied it into $CATALINA_BASE/lib/, renamed it to servlets-cgi.jar, and put a symlink to it in usr/share/tomcat6/lib/.  (Tomcat 6 did not come with this file.  Nor, for that matter, can we find a preexisting cgi-bin directory anywhere.)

After each step we restarted Tomcat, but when we browse to a CGI script in WEB-INF/cgi/ (we actually access it through a symlink in a different, publicly accessible directory), the browser displays it simply as text instead of running it as a Perl script.  The first line of the file says #!/usr/bin/perl, and we have confirmed that we have a working Perl installation at that location.  Shortly thereafter, the file tells us we haven't configured our Web server to run CGI scripts.

We also tried modifying our web app's WEB-INF/web.xml instead of the $CATALINA_BASE/conf/web.xml, but no joy.

I'm sure we're missing something obvious to those in the know, but it's not obvious to us.  Any suggestions would be welcome.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: how do I enable CGI scripts in Tomcat 6?

Caldarale, Charles R
> From: Grossman, Robert B [mailto:[hidden email]]
> Subject: how do I enable CGI scripts in Tomcat 6?
>
> The descriptions of the CGI enabling process that we have found on
> the Web, e.g. http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html

That's the right one.

> and http://www.wellho.net/solutions/java-running-cgi-scripts-in-apache-tomcat.html 

Sadly out of date and seriously broken.  Use the real doc.

> We already had set <context privileged="true"> in Tomcat's context.xml.

That's wrong.  First, it's <Context>, not <context> - case matters.  Second, you shouldn't be setting this attribute globally, but rather in just the webapps that need it.

> We created a WEB-INF/cgi directory in our web app's hierarchy.  In
> $CATALINA_BASE/conf/web.xml, we uncommented the CGI servlet description
> and servlet matching, and we set the cgiPathPrefix to WEB-INF/cgi/ and
> the servlet matching pattern to /cgi/*.

Please post (via copy and paste) those sections of conf/web.xml so we can see what you actually did.  Too often people see what they expect, not what's there.

> We downloaded servlets-cgi.renametojar from a Tomcat 5 distribution,

Bad move.  Where in the Tomcat 6 doc does it say to do that?  You just broke your Tomcat 6 installation.

> Tomcat 6 did not come with this file.

Because it doesn't need it.

> Nor, for that matter, can we find a preexisting cgi-bin directory anywhere.

Nor should you.  That's simply a part of the URL that triggers the CGI servlet, not an actual directory.  The script path is specified by the cgiPathPrefix parameter.

> when we browse to a CGI script in WEB-INF/cgi/ (we actually access
> it through a symlink in a different, publicly accessible directory)

Don't muck with symlinks until you've got it working.  No point in introducing extra trouble spots until the basics are functional.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how do I enable CGI scripts in Tomcat 6?

Grossman, Robert B
Thanks for your reply, Chuck.

(1) We do indeed have <Context privileged="true">.  The lower-case C was my typo.  I'm not sure why my collaborator decided to set the value here rather in the web app, but we have only one web app running on this machine anyway.
(2) We only copied servlets-cgi.renametojar after the steps in http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html failed to work.  Per your advice, I have now removed it.
(3) Here's what we currently have in $CATALINA_BASE/conf/web.xml:

    <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>1</param-value>
        </init-param>
        <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi-bin</param-value>
        </init-param>
         <load-on-startup>5</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>/cgi-bin/*</url-pattern>
    </servlet-mapping>

(4) Our web app is in /home/aceorg/aceorg/DEV-2.2/.  It has two branches, epoch-plugin/ and courseware/.  epoch-plugin/web/WEB-INF/ now contains cgi-bin/, which contains many cgi scripts, including login.cgi.  Most of our web app requires a login, so we are unable to point our browser to WEB-INF/cgi-bin/login.cgi directly.  However, we do have a public access folder at epoch-plugin/web/public/, which a Web browser can access at http://domain/epoch-plugin/public/, so I made a symlink public/webmo/cgi-bin to point to WEB-INF/cgi-bin.  When we point a browser to http://domain/epoch-plugin/public/webmo/cgi-bin/login.cgi, we see the text for WEB-INF/cgi-bin/login.cgi.

I have tried various other arrangements and names of the files, to no avail.  I also tried putting the above XML in WEB-INF/web.xml instead of $CATALINA_BASE/conf/web.xml, again to no avail.  I am ready to try anything you suggest.

________________________________
From: "Caldarale, Charles R" <[hidden email]>
Reply-To: Tomcat Users List <[hidden email]>
Date: Tue, 12 Jan 2010 23:09:14 -0500
To: Tomcat Users List <[hidden email]>
Conversation: how do I enable CGI scripts in Tomcat 6?
Subject: RE: how do I enable CGI scripts in Tomcat 6?

> From: Grossman, Robert B [mailto:[hidden email]]
> Subject: how do I enable CGI scripts in Tomcat 6?
>
> The descriptions of the CGI enabling process that we have found on
> the Web, e.g. http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html

That's the right one.

> and http://www.wellho.net/solutions/java-running-cgi-scripts-in-apache-tomcat.html

Sadly out of date and seriously broken.  Use the real doc.

> We already had set <context privileged="true"> in Tomcat's context.xml.

That's wrong.  First, it's <Context>, not <context> - case matters.  Second, you shouldn't be setting this attribute globally, but rather in just the webapps that need it.

> We created a WEB-INF/cgi directory in our web app's hierarchy.  In
> $CATALINA_BASE/conf/web.xml, we uncommented the CGI servlet description
> and servlet matching, and we set the cgiPathPrefix to WEB-INF/cgi/ and
> the servlet matching pattern to /cgi/*.

Please post (via copy and paste) those sections of conf/web.xml so we can see what you actually did.  Too often people see what they expect, not what's there.

> We downloaded servlets-cgi.renametojar from a Tomcat 5 distribution,

Bad move.  Where in the Tomcat 6 doc does it say to do that?  You just broke your Tomcat 6 installation.

> Tomcat 6 did not come with this file.

Because it doesn't need it.

> Nor, for that matter, can we find a preexisting cgi-bin directory anywhere.

Nor should you.  That's simply a part of the URL that triggers the CGI servlet, not an actual directory.  The script path is specified by the cgiPathPrefix parameter.

> when we browse to a CGI script in WEB-INF/cgi/ (we actually access
> it through a symlink in a different, publicly accessible directory)

Don't muck with symlinks until you've got it working.  No point in introducing extra trouble spots until the basics are functional.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how do I enable CGI scripts in Tomcat 6?

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert,

On 1/13/2010 9:25 AM, Grossman, Robert B wrote:

>     <servlet>
>         <servlet-name>cgi</servlet-name>
>         <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
>         <init-param>
>           <param-name>debug</param-name>
>           <param-value>1</param-value>
>         </init-param>
>         <init-param>
>           <param-name>cgiPathPrefix</param-name>
>           <param-value>WEB-INF/cgi-bin</param-value>
>         </init-param>
>          <load-on-startup>5</load-on-startup>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>cgi</servlet-name>
>         <url-pattern>/cgi-bin/*</url-pattern>
>     </servlet-mapping>
>
> (4) Our web app is in /home/aceorg/aceorg/DEV-2.2/. It has two
> branches, epoch-plugin/ and courseware/. epoch-plugin/web/WEB-INF/ now
> contains cgi-bin/, which contains many cgi scripts, including login.cgi.

Just to get some nomenclature straight: the term "branch" is meaningless
to the servlet specification. If that term has some internal meaning to
you, it does not to us. The directory /home/aceorg/DEV-2.2 is more
likely the appBase for a <Host> defined in Tomcat's conf/server.xml.
That means it's the directory used for auto-deployed WAR files and
directory-based webapps. The epoch-plugin and courseware "branches", as
you call them, are really independent webapps. You can tell because each
one of them has a separate WEB-INF/web.xml file.

> Most of our web app requires a login, so we are unable to point our
> browser to WEB-INF/cgi-bin/login.cgi directly.

If you have an executable file in WEB-INF/cgi-bin/login.cgi, then you
should be accessing it using this URL:

http://host/epoch-plugin/cgi-bin/login.cgi
and not
http://host/epoch-plugin/WEB-INF/cgi-bin/login.cgi

Note that you configured this explicitly in the CGIServlet (see above)
using the url-pattern of "/cgi-bin/*". There's no "WEB-INF" in that path.

> However, we do have a public access folder at
> epoch-plugin/web/public/, which a Web browser can access at
> http://domain/epoch-plugin/public/, so I made a symlink
> public/webmo/cgi-bin to point to WEB-INF/cgi-bin. When we point a
> browser to
> http://domain/epoch-plugin/public/webmo/cgi-bin/login.cgi, we see the
> text for WEB-INF/cgi-bin/login.cgi.

Your URL path for the CGIServlet is "/cgi-bin/*" not
"/public/webmo/cgi-bin/*", so the CGIServlet isn't being invoked. By
adding that symlink, you have allowed the DefaultServlet to serve the
raw bytes of the .cgi file, so you see the source code of your perl
script (or whatever).

Try removing the symlink and hitting this URL:

http://host/epoch-plugin/cgi-bin/login.cgi

What happens?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktN6NQACgkQ9CaO5/Lv0PBv7wCgv16UkUZM2edmPV5i9jvFQ6aV
o5EAn144Hb9S+ccbTUz7wSfNYkhRnibh
=gcZp
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how do I enable CGI scripts in Tomcat 6?

Grossman, Robert B
Well, butter my butt and call me a biscuit.  Accessing that URL works!

I think I can handle it from here.  Thanks again.

P.S.  Sorry for the nomenclature confusion, I'm really a chemist, not a computer programmer.


________________________________
From: Christopher Schultz <[hidden email]>
Reply-To: Tomcat Users List <[hidden email]>
Date: Wed, 13 Jan 2010 10:37:56 -0500
To: Tomcat Users List <[hidden email]>
Conversation: how do I enable CGI scripts in Tomcat 6?
Subject: Re: how do I enable CGI scripts in Tomcat 6?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert,

On 1/13/2010 9:25 AM, Grossman, Robert B wrote:

>     <servlet>
>         <servlet-name>cgi</servlet-name>
>         <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
>         <init-param>
>           <param-name>debug</param-name>
>           <param-value>1</param-value>
>         </init-param>
>         <init-param>
>           <param-name>cgiPathPrefix</param-name>
>           <param-value>WEB-INF/cgi-bin</param-value>
>         </init-param>
>          <load-on-startup>5</load-on-startup>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>cgi</servlet-name>
>         <url-pattern>/cgi-bin/*</url-pattern>
>     </servlet-mapping>
>
> (4) Our web app is in /home/aceorg/aceorg/DEV-2.2/. It has two
> branches, epoch-plugin/ and courseware/. epoch-plugin/web/WEB-INF/ now
> contains cgi-bin/, which contains many cgi scripts, including login.cgi.

Just to get some nomenclature straight: the term "branch" is meaningless
to the servlet specification. If that term has some internal meaning to
you, it does not to us. The directory /home/aceorg/DEV-2.2 is more
likely the appBase for a <Host> defined in Tomcat's conf/server.xml.
That means it's the directory used for auto-deployed WAR files and
directory-based webapps. The epoch-plugin and courseware "branches", as
you call them, are really independent webapps. You can tell because each
one of them has a separate WEB-INF/web.xml file.

> Most of our web app requires a login, so we are unable to point our
> browser to WEB-INF/cgi-bin/login.cgi directly.

If you have an executable file in WEB-INF/cgi-bin/login.cgi, then you
should be accessing it using this URL:

http://host/epoch-plugin/cgi-bin/login.cgi
and not
http://host/epoch-plugin/WEB-INF/cgi-bin/login.cgi

Note that you configured this explicitly in the CGIServlet (see above)
using the url-pattern of "/cgi-bin/*". There's no "WEB-INF" in that path.

> However, we do have a public access folder at
> epoch-plugin/web/public/, which a Web browser can access at
> http://domain/epoch-plugin/public/, so I made a symlink
> public/webmo/cgi-bin to point to WEB-INF/cgi-bin. When we point a
> browser to
> http://domain/epoch-plugin/public/webmo/cgi-bin/login.cgi, we see the
> text for WEB-INF/cgi-bin/login.cgi.

Your URL path for the CGIServlet is "/cgi-bin/*" not
"/public/webmo/cgi-bin/*", so the CGIServlet isn't being invoked. By
adding that symlink, you have allowed the DefaultServlet to serve the
raw bytes of the .cgi file, so you see the source code of your perl
script (or whatever).

Try removing the symlink and hitting this URL:

http://host/epoch-plugin/cgi-bin/login.cgi

What happens?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktN6NQACgkQ9CaO5/Lv0PBv7wCgv16UkUZM2edmPV5i9jvFQ6aV
o5EAn144Hb9S+ccbTUz7wSfNYkhRnibh
=gcZp
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: how do I enable CGI scripts in Tomcat 6?

Holger Rieß-2
In reply to this post by Christopher Schultz-2
The context elements are defined in /%CATALINA_HOME%/conf/server.xml:
<Server ...>
        <Service ...>
                <Engine ...>
                        <Host ...>
                                <Context docBase= ...>
                                <Context docBase= ...>
                                ...
                        </Host>
                </Engine>
        </Service>
</Server>

There are two web applications that have access to these resources. The servlets main task is to calculate picture dimensions with java.awt.Toolkit. The request.getResource methods don't find these 'extern' paths.

Holger

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how do I enable CGI scripts in Tomcat 6?

neelesh86
This post has NOT been accepted by the mailing list yet.
In reply to this post by Christopher Schultz-2
Hi ,

I am using apache-tomcat7 installed on one of the Linux box.

I am learning cgi scripting and have made a simple html file and a .cgi file where in the html the .cgi script is invoked.

Below are the contents of web.xml
    <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi</param-value>
        </init-param>
        <init-param>
         <param-name>passShellEnvironment</param-name>
         <param-value>true</param-value>
        </init-param>
         <load-on-startup>5</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>/cgi-bin/*</url-pattern>
    </servlet-mapping>

hotel_post.html
<form action="post.cgi" method="POST">
Your Name: <input type="text" name="name"><br>
Email Address: <input type="text" name="email"><br>
Comments:<br>
<textarea name="comments" rows="5"
   cols="60"></textarea><br>
<input type="submit" value="Send">
</form>


post.cgi :
#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;

print header;
print start_html("Thank You");
print h2("Thank You");

my %form;
foreach my $p (param()) {
    $form{$p} = param($p);
    print "$p = $form{$p}<br>\n";
}
print end_html;


The 'webapps' folder is at the location : /data/nonprod/Tomcat/apache-tomcat-7.0.26/webapps

The html file and the .cgi file is kept @ /data/nonprod/Tomcat/apache-tomcat-7.0.26/webapps/cgi-bin/hotel

When I hit the url : http://server.name.com:8080/cgi-bin/hotel/hotel_post.html    the html page is rendered on the browser but after clicking the send button the content of the cgi script is printed instead of the output of the script.

Please let me know what mistake i am doing.

Many thanks!
Loading...