This file is indexed.

/usr/share/perl5/CGI/Simple/Standard.pm is in libcgi-simple-perl 1.115-1.

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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
package CGI::Simple::Standard;

use strict;
use CGI::Simple;
use Carp;
use vars qw( $VERSION $USE_CGI_PM_DEFAULTS $DISABLE_UPLOADS $POST_MAX
 $NO_UNDEF_PARAMS $USE_PARAM_SEMICOLONS $HEADERS_ONCE
 $NPH $DEBUG $NO_NULL $FATAL *in %EXPORT_TAGS $AUTOLOAD );

$VERSION = "1.114";

%EXPORT_TAGS = (
  ':html'     => [qw(:misc)],
  ':standard' => [qw(:core :access)],
  ':cgi'      => [qw(:core :access)],
  ':all'      => [
    qw(:core :misc :cookie :header :push :debug :cgi-lib
     :access :internal)
  ],
  ':core' => [
    qw(param add_param param_fetch url_param keywords
     append Delete delete_all Delete_all upload
     query_string parse_query_string  parse_keywordlist
     Vars save_parameters restore_parameters)
  ],
  ':misc'   => [qw(url_decode url_encode escapeHTML unescapeHTML put)],
  ':cookie' => [qw(cookie raw_cookie)],
  ':header' => [qw(header cache no_cache redirect)],
  ':push'   => [
    qw(multipart_init multipart_start multipart_end
     multipart_final)
  ],
  ':debug'   => [qw(Dump as_string cgi_error _cgi_object)],
  ':cgi-lib' => [
    qw(ReadParse SplitParam MethGet MethPost MyBaseUrl MyURL
     MyFullUrl PrintHeader HtmlTop HtmlBot PrintVariables
     PrintEnv CgiDie CgiError Vars)
  ],
  ':ssl'    => [qw(https)],
  ':access' => [
    qw(version nph all_parameters charset crlf globals
     auth_type content_length content_type document_root
     gateway_interface path_translated referer remote_addr
     remote_host remote_ident remote_user request_method
     script_name server_name server_port server_protocol
     server_software user_name user_agent virtual_host
     path_info Accept http https protocol url self_url
     state)
  ],
  ':internal' => [
    qw(_initialize_globals _use_cgi_pm_global_settings
     _store_globals _reset_globals)
  ]
);

# BEGIN {
#     $SIG{__DIE__} = sub { croak "Undefined Method : @_\n" }
# }

sub import {
  my ( $self, @args ) = @_;
  my $package = caller();
  my ( %exports, %pragmas );
  for my $arg ( @args ) {
    $exports{$arg}++, next if $arg =~ m/^\w+$/;
    $pragmas{$arg}++, next if $arg =~ m/^-\w+$/;
    if ( $arg =~ m/^:[-\w]+$/ ) {
      if ( exists $EXPORT_TAGS{$arg} ) {
        my @tags = @{ $EXPORT_TAGS{$arg} };
        for my $tag ( @tags ) {
          my @expanded
           = exists $EXPORT_TAGS{$tag}
           ? @{ $EXPORT_TAGS{$tag} }
           : ( $tag );
          $exports{$_}++ for @expanded;
        }
      }
      else {
        croak
         "No '$arg' tag set available for export from CGI::Simple::Standard!\n";
      }
    }
  }
  my @exports = keys %exports;
  my %valid_exports;
  for my $tag ( @{ $EXPORT_TAGS{':all'} } ) {
    $valid_exports{$_}++ for @{ $EXPORT_TAGS{$tag} };
  }
  for ( @exports ) {
    croak
     "'$_' is not an available export method from CGI::Simple::Standard!\n"
     unless exists $valid_exports{$_};
  }
  no strict 'refs';
  if ( exists $pragmas{'-autoload'} ) {

    # hack symbol table to export our AUTOLOAD sub
    *{"${package}::AUTOLOAD"} = sub {
      my ( $caller, $sub ) = $AUTOLOAD =~ m/(.*)::(\w+)$/;
      &CGI::Simple::Standard::loader( $caller, $sub, @_ );
    };
    delete $pragmas{'-autoload'};
  }
  my @pragmas = keys %pragmas;
  CGI::Simple->import( @pragmas ) if @pragmas;

  # export subroutine stubs for all the desired export functions
  # we will replace them in the symbol table with the real thing
  # if and when they are first called
  for my $i ( 0 .. $#exports ) {
    *{"${package}::$exports[$i]"} = sub {
      my $caller = caller;
      &CGI::Simple::Standard::loader( $caller, $exports[$i], @_ );
     }
  }
}

# loader() may be called either via our exported AUTOLOAD sub or by the
# subroutine stubs we exported on request. It has three functions:
# 1) to initialize and store (via a closure) our CGI::Simple object
# 2) to overwrite the exported subroutine stubs with calls to the real ones
# 3) to provide two 'virtual' methods - _cgi_object() and restore_parameters()
# restore_parameters effectively functions like new() for the OO interface.
{
  my $q;

  sub loader {
    my $package = shift;
    my $sub     = shift;
    if ( $sub eq '_cgi_object' ) {    # for debugging get at the object
      $q = CGI::Simple->new( @_ ) unless $q;
      return $q;
    }
    if ( !$q or $sub eq 'restore_parameters' ) {
      if ( $sub eq 'restore_parameters' ) {
        $q = CGI::Simple->new( @_ );
        return;
      }
      else {
        $q = CGI::Simple->new;
      }
    }

   # hack the symbol table and insert the sub so we only use loader once
   # get strict to look the other way while we use sym refs
    no strict 'refs';

    # stop warnings screaming about redefined subs
    local $^W = 0;

   # hack to ensure %in ends in right package when exported by ReadParse
    @_ = ( *{"${package}::in"} ) if $sub eq 'ReadParse' and !@_;

    # write the required sub to the callers symbol table
    *{"${package}::$sub"} = sub { $q->$sub( @_ ) };

 # now we have inserted the sub let's call it and return the results :-)
    return &{"${package}::$sub"};
  }
}

1;

=head1 NAME

CGI::Simple::Standard - a wrapper module for CGI::Simple that provides a
function style interface

=head1 SYNOPSIS

    use CGI::Simple::Standard qw( -autoload );
    use CGI::Simple::Standard qw( :core :cookie :header :misc );
    use CGI::Simple::Standard qw( param upload );

    $CGI::Simple::Standard::POST_MAX = 1024;       # max upload via post 1kB
    $CGI::Simple::Standard::DISABLE_UPLOADS = 0;   # enable uploads

    @params = param();        # return all param names as a list
    $value =  param('foo');   # return the first value supplied for 'foo'
    @values = param('foo');   # return all values supplied for foo

    %fields   = Vars();       # returns untied key value pair hash
    $hash_ref = Vars();       # or as a hash ref
    %fields   = Vars("|");    # packs multiple values with "|" rather than "\0";

    @keywords = keywords();   # return all keywords as a list

    param( 'foo', 'some', 'new', 'values' );        # set new 'foo' values
    param( -name=>'foo', -value=>'bar' );
    param( -name=>'foo', -value=>['bar','baz'] );

    append( -name=>'foo', -value=>'bar' );          # append values to 'foo'
    append( -name=>'foo', -value=>['some', 'new', 'values'] );

    Delete('foo');   # delete param 'foo' and all its values
    Delete_all();    # delete everything

    <INPUT TYPE="file" NAME="upload_file" SIZE="42">

    $files    = upload()                   # number of files uploaded
    @files    = upload();                  # names of all uploaded files
    $filename = param('upload_file')       # filename of 'upload_file' field
    $mime     = upload_info($filename,'mime'); # MIME type of uploaded file
    $size     = upload_info($filename,'size'); # size of uploaded file

    my $fh = $q->upload($filename);     # open filehandle to read from
    while ( read( $fh, $buffer, 1024 ) ) { ... }

    # short and sweet upload
    $ok = upload( param('upload_file'), '/path/to/write/file.name' );
    print "Uploaded ".param('upload_file')." and wrote it OK!" if $ok;

    $decoded    = url_decode($encoded);
    $encoded    = url_encode($unencoded);
    $escaped    = escapeHTML('<>"&');
    $unescaped  = unescapeHTML('&lt;&gt;&quot;&amp;');

    $qs = query_string();   # get all data in $q as a query string OK for GET

    no_cache(1);            # set Pragma: no-cache + expires
    print header();         # print a simple header
    # get a complex header
    $header = header(   -type       => 'image/gif'
                        -nph        => 1,
                        -status     => '402 Payment required',
                        -expires    =>'+24h',
                        -cookie     => $cookie,
                        -charset    => 'utf-7',
                        -attachment => 'foo.gif',
                        -Cost       => '$2.00');

    @cookies = cookie();        # get names of all available cookies
    $value   = cookie('foo')    # get first value of cookie 'foo'
    @value   = cookie('foo')    # get all values of cookie 'foo'
    # get a cookie formatted for header() method
    $cookie  = cookie(  -name    => 'Password',
                        -values  => ['superuser','god','my dog woofie'],
                        -expires => '+3d',
                        -domain  => '.nowhere.com',
                        -path    => '/cgi-bin/database',
                        -secure  => 1 );
    print header( -cookie=>$cookie );       # set cookie

    print redirect('http://go.away.now');   # print a redirect header

    dienice( cgi_error() ) if cgi_error();

=head1 DESCRIPTION

This module is a wrapper for the completely object oriented CGI::Simple
module and provides a simple functional style interface. It provides two
different methods to import function names into your namespace.

=head2 Autoloading

If you specify the '-autoload' pragma like this:

    use CGI::Simple::Standard qw( -autoload );

Then it will use AUTOLOAD and a symbol table trick to export only those subs
you actually call into your namespace. When you specify the '-autoload' pragma
this module exports a single AUTOLOAD subroutine into you namespace. This will
clash with any AUTOLOAD sub that exists in the calling namespace so if you are
using AUTOLOAD for something else don't use this pragma.

Anyway, when you call a subroutine that is not defined in your script this
AUTOLOAD sub will be called. The first time this happens it
will initialize a CGI::Simple object and then apply the requested method
(if it exists) to it. A fatal exception will be thrown if you try to use an
undefined method (function).

=head2 Specified Export

Alternatively you can specify the functions you wish to import. You can do
this on a per function basis like this:

    use CGI::Simple::Standard qw( param upload query_string Dump );

or utilize the %EXPORT_TAGS that group functions into related groups.
Here are the groupings:

  %EXPORT_TAGS = (
    ':html'     => [ qw(:misc) ],
    ':standard' => [ qw(:core :access) ],
    ':cgi'      => [ qw(:core :access) ],
    ':all'      => [ qw(:core :misc :cookie :header :push :debug :cgi-lib
                        :access :internal) ],
    ':core'     => [ qw(param add_param param_fetch url_param keywords
                        append Delete delete_all Delete_all upload
                        query_string parse_query_string  parse_keywordlist
                        Vars save_parameters restore_parameters) ],
    ':misc'     => [ qw(url_decode url_encode escapeHTML unescapeHTML put) ],
    ':cookie'   => [ qw(cookie raw_cookie) ],
    ':header'   => [ qw(header cache no_cache redirect) ],
    ':push'     => [ qw(multipart_init multipart_start multipart_end
                        multipart_final) ],
    ':debug'    => [ qw(Dump as_string cgi_error _cgi_object) ],
    ':cgi-lib'  => [ qw(ReadParse SplitParam MethGet MethPost MyBaseUrl MyURL
                        MyFullUrl PrintHeader HtmlTop HtmlBot PrintVariables
                        PrintEnv CgiDie CgiError Vars) ],
    ':ssl'      => [ qw(https) ],
    ':access'   => [ qw(version nph all_parameters charset crlf globals
                        auth_type content_length content_type document_root
                        gateway_interface path_translated referer remote_addr
                        remote_host remote_ident remote_user request_method
                        script_name server_name server_port server_protocol
                        server_software user_name user_agent virtual_host
                        path_info Accept http https protocol url self_url
                        state) ],
    ':internal' => [ qw(_initialize_globals _use_cgi_pm_global_settings
                        _store_globals _reset_globals) ]
    );


The familiar CGI.pm tags are available but do not include the HTML
functionality. You specify the import of some function groups like this:

use CGI::Simple::Standard qw( :core :cookie :header );

Note that the function groups all start with a : char.

=head2 Mix and Match

You can use the '-autoload' pragma, specifically named function imports and
tag group imports together if you desire.

=head1 $POST_MAX and $DISABLE_UPLOADS

If you wish to set $POST_MAX or $DISABLE_UPLOADS you must do this *after* the
use statement and *before* the first function call as shown in the synopsis.

Unlike CGI.pm uploads are disabled by default and the maximum acceptable
data via post is capped at 102_400kB rather than infinity. This is specifically
to avoid denial of service attacks by default. To enable uploads and to
allow them to be of infinite size you simply:

    $CGI::Simple::Standard::POST_MAX = -1;         # infinite size upload
    $CGI::Simple::Standard::$DISABLE_UPLOADS = 0;  # enable uploads

Alternatively you can specify the CGI.pm default values as shown above by
specifying the '-default' pragma in your use statement.

    use CGI::Simple::Standard qw( -default ..... );

=head1 EXPORT

Nothing by default.

Under the '-autoload' pragma the AUTOLOAD subroutine is
exported into the calling namespace. Additional subroutines are only imported
into this namespace if you physically call them. They are installed in the
symbol table the first time you use them to save repeated calls to AUTOLOAD.

If you specifically request a function or group of functions via an EXPORT_TAG
then stubs of these functions are exported into the calling namespace. These
stub functions will be replaced with the real functions only if you actually
call them saving wasted compilation effort.

=head1 FUNCTION DETAILS

This is a wrapper module for CGI::Simple. Virtually all the methods available
in the OO interface are available via the functional interface. Several
method names are aliased to prevent namespace conflicts:

    $q->delete('foo')   =>  Delete('foo')
    $q->delete_all      =>  Delete_all() or delete_all()
    $q->save(\*FH)      =>  save_parameters(\*FH)
    $q->accept()        =>  Accept()

Although you could use the new() function to genrate new OO CGI::Simple
objects the restore_parameters() function is a better choice as it operates
like new but on the correct underlying CGI::Simple object for the functional
interface.

restore_parameters() can be used exactly as you might use new() in that
you can supply arguments to it such as query strings, hashes and file handles
to re-initialize your underlying object.

    $q->new CGI::Simple()                => restore_parameters()
    $q->new CGI::Simple({foo=>'bar'})    => restore_parameters({foo=>'bar'})
    $q->new CGI::Simple($query_string)   => restore_parameters($query_string)
    $q->new CGI::Simple(\*FH)            => restore_parameters(\*FH)

For full details of the available functions see the CGI::Simple docs. Just
remove the $q-> part and use the method name directly.

=head1 BUGS

As this is 0.01 there are almost bound to be some.

=head1 AUTHOR

Dr James Freeman E<lt>jfreeman@tassie.net.auE<gt>
This release by Andy Armstrong <andy@hexten.net>

This package is free software and is provided "as is" without express or
implied warranty. It may be used, redistributed and/or modified under the terms
of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html)

Address bug reports and comments to: andy@hexten.net

=head1 CREDITS

The interface and key sections of the CGI::Simple code come from
CGI.pm by Lincoln Stein.

=head1 SEE ALSO

L<CGI::Simple> which is the back end for this module,
B<CGI.pm by Lincoln Stein>

=cut