/usr/share/perl5/RefDB/CGI.pm is in librefdb-perlmod-perl 1.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | ## package RefDB::CGI
## RefDB CGI support module
## markus@mhoenicka.de 2002-12-27
## $Id: CGI.pm,v 1.1 2002/12/29 23:06:44 mhoenicka Exp $
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## Package main documentation
=head1 NAME
RefDB::CGI - CGI support for RefDB Perl scripts
=head1 SYNOPSIS
use RefDB::CGI;
if (RefDB::CGI::check_cgi("GET") == 0) {
$template = RefDB::CGI::load_html("/usr/local/share/myapp/template.html");
}
=head1 DESCRIPTION
Provides functions important to run RefDB scripts as CGI applications.
=head1 FEEDBACK
Send bug reports, questions, and comments to the refdb-users mailing list at:
refdb-users@lists.sourceforge.net
For list information and archives, please visit:
http://lists.sourceforge.net/lists/listinfo/refdb-users
=head1 AUTHOR
Markus Hoenicka, markus@mhoenicka.de
=head1 SEE ALSO
This module is part of the RefDB package, a reference manager and bibliography tool for markup languages. Please visit http://refdb.sourceforge.net for further information.
=cut
package RefDB::CGI;
use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
$VERSION = "1.2";
=head1 package functions
=head2 check_cgi
Title : check_cgi
Usage : $cgi = check_cgi($mode);
Function: Checks whether app runs as a CGI app accepting GET or POST data
Argument: mode: either "GET" or "POST"
Returns : 0 if CGI app called properly
1 if incorrect mode
2 if missing content length of POST data
3 if not CGI at all
=cut
##********************************************************************
## check_cgi(): checks whether we run as CGI app
## Argument: mode, either "GET" or "POST"
## Returns: 0 if CGI app called appropriately, >0 if not
##********************************************************************
sub check_cgi {
my $mode = shift;
my $retcode;
my $request_method = $ENV{'REQUEST_METHOD'};
## A web server will set the environment variable REQUEST_METHOD
## (among others) for CGI processes. If this envar is not set,
## we're not a CGI app
if (defined($request_method)) {
if ($request_method eq "GET") {
if ($mode eq "GET") {
$retcode = 0;
}
else {
$retcode = 1;
}
}
elsif ($request_method eq "POST") {
if ($mode eq "GET") {
$retcode = 1;
}
else {
my $content_length = $ENV{'CONTENT_LENGTH'};
if (!defined($content_length)) {
$retcode = 2;
}
else {
$retcode = 0;
}
}
}
else {
$retcode = 3; # no CGI
}
}
else {
$retcode = 3;
}
if ($retcode == 0) {
## all fine, proper mode detected
return 0;
}
elsif ($retcode == 1) {
print "Content-type: text/plain\n\nIncorrect request method: $request_method<<\n";
return 1;
}
elsif ($retcode == 2) {
## this is a web server error, should never happen
print "Content-type: text/plain\n\nUnknown request size\n";
return 2;
}
else { ## retcode == 3
# print "Not running as a CGI application\n";
return 3;
}
} ## end of check_cgi
=head2 load_html
Title : load_html
Usage : $template = load_html("full/path/to/template.html")
Function: Reads a HTML template into a string
Returns : string if file was found, undef if not
=cut
##********************************************************************
## load_html(): reads html template into a string
## Arguments: path of template file
## Return value: template string if ok, undef if failed
##********************************************************************
sub load_html {
my $frag = shift;
my $fragstring;
if (open FRAG, "<$frag") {
while (<FRAG>) {
$fragstring = $fragstring . $_;
}
return $fragstring;
}
else {
return undef;
}
} ## end of load_html
1;
__END__
|