[Pi3web-users] CGI hints
Brought to you by:
zimpel
|
From: <zi...@t-...> - 2002-02-05 21:11:54
|
Hi there,
I got some questions via direct mail and assume, the answers are
of general interest:
Q: I installed a Perl-CGI based application. The static HTML sites
are shown, but invocation of a CGI causes an "403 Forbidden" status
code. What goes wrong?
A: Your CGI application is probably installed in a sub-directory of
.\Pi3Web\Cgi-Bin\. You don't have directory browsing permissions here
per default, which causes the 403 error correctly.
To fix this add an additional CGI mapping to the configuration either
with the admin GUI -
Type: CGI
From: /cgi-bin/mycgiapp/
To: Cgi-Bin\MyCgiApp\
Realm: none
or edit in .\Pi3Web\Config.pi3 -
Mapping CGIMapper From="/cgi-bin/yabb" To="Cgi-Bin\yabb\"
Important (to be considered for both GUI or editor usage):
- Don't forget to add the trailing "\" to the physical path
- The conbfiguration line with this mapping has to be placed above
the 'standard' CGI mapping, which is
Mapping CGIMapper From="/cgi-bin/" To="Cgi-Bin\"
If the CGI application is deployed into more than one sub-folder, you need
accordingly additional CGI mappings.
If the location of the CGI's is arbitrary, you can also simply move the scripts
to .Pi3Web\Cgi-Bin\. Probably you've to adapt some URL-configuration of the CGI
program inside your scripts or the HTML pages for it.
Q: I want to execute CGI programs from anywhere within .\Pi3Web\WebRoot, not
only from .Pi3Web\Cgi-Bin\. How can I achieve this?
A: The solution is a bit tricky deal with the configuration:
1.) Stop server
2.) Make backup copy of .\Pi3Web\Config.pi3
3.) Open .\Pi3Web\Config.pi3 with a text editor
4.) Search in the "Default" handler for the following line:
Handle Condition="&and(¬(&dblookup(response,string,ObjectMap)),\
¬(®exp('internal/*',$c)))" SendFile
5.) Insert the following line before it:
Handle Condition="&or(&cmp($c,text/x-perl),&and(&cmp($c,application/octet-stream),\
®exp('*.exe',$z)))" CGIScripts
6.) Insert a new handler object named 'CGIScripts':
<Object>
Name CGIScripts
Class FlexibleHandlerClass
CheckPath RefuseFileByMask AllowFileMask="EFD" RefuseStatus=404
CheckPath RefuseFileByMask AllowFileMask="F" RefuseStatus=403
CheckPath ReturnCode ReturnCode=COMPLETED
CheckAccess AccessByFile RequirePermissions="X"
CheckType ReturnCode ReturnCode=COMPLETED
Handle Condition="&dbreplace(response,rfc822,Content-Type,'')" StandardCGI
</Object>
7.) Save .\Pi3Web\Config.pi3
8.) Restart server
All path mappings, which are dispatched to the "Default handler" consider
.cgi, .exe and .pl files as CGI scripts from now on.
If this configuration doesn't work as expected, check, if mime-mappings exist
for the following extensions (either in .\Pi3Web\Config.pi3 or with the admin
GUI):
AddMIMEEntry "cgi text/x-perl"
AddMIMEEntry "exe application/octet-stream"
AddMIMEEntry "pl text/x-perl"
Only for the interested: What is the meaning of:
Condition="&dbreplace(response,rfc822,Content-Type,'')"
Some lines above the default handler applies a mime-mapping. This is accordingly
to the file extension and will send back a Content-Type of e.g. "text/x-perl".
This will cause some browsers to show a download-box. The applied mime type is
reset by this expression and now taken correctly from the CGI output, which is
normally "text/html".
Have fun!
--
regards
Holger
TMTOWTDI - There's More Than One Way To Do It - Perl motto
----------------------------------------------------------
Holger 'zimpel' Zimmermann
----------------------------------------------------------
Wendishain
Germany
----------------------------------------------------------
http://home.t-online.de/home/zimpel/
http://pi3web.sourceforge.net/
mailto:zi...@t-...
----------------------------------------------------------
|