This file is indexed.

/usr/lib/x86_64-linux-gnu/perl5/5.22/Embperl/Syntax/SSI.pm is in libembperl-perl 2.5.0-6.

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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
###################################################################################
#
#   Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh  www.ecos.de
#   Embperl - Copyright (c) 2008-2014 Gerald Richter
#
#   You may distribute under the terms of either the GNU General Public
#   License or the Artistic License, as specified in the Perl README file.
#
#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
#   $Id: SSI.pm 1578075 2014-03-16 14:01:14Z richter $
#
###################################################################################
 
package Embperl::Syntax::SSI ;

use Embperl::Syntax qw{:types} ;
use Embperl::Syntax::HTML ;
use File::Basename;

BEGIN { 
    local $^W = 0 ;
    require POSIX ;

    eval "use Apache::Constants qw(:common OPT_INCNOEXEC);" ;
    } ;

use strict ;
use vars qw{@ISA} ;

@ISA = qw(Embperl::Syntax::HTML) ;


###################################################################################
#
#   Methods
#
###################################################################################

# ---------------------------------------------------------------------------------
#
#   Create new Syntax Object
#
# ---------------------------------------------------------------------------------


sub new

    {
    my $class = shift ;

    my $self = Embperl::Syntax::HTML::new ($class) ;

    if (!$self -> {-ssiInit})
        {
        $self -> {-ssiInit} = 1 ;    
        Init ($self) ;
        }

    return $self ;
    }



###################################################################################
#
#   Definitions for SSI HTML tags
#
###################################################################################

sub Init

    {
    my ($self) = @_ ;

    $self -> AddInitCode (undef, 'Embperl::Syntax::SSI::InitSSI($_[0], $req_rec);', undef) ;

    $self -> AddComment ('#echo', ['var', 'encoding'], undef, undef, { perlcode => '_ep_rp(%$x%, $ENV{%&*\'var%}) ;' } ) ;
    $self -> AddComment ('#printenv', undef, undef, undef, { perlcode => '_ep_rp(%$x%, join ("\\\\<br\\\\>\n", map { "$_ = $ENV{$_}" } keys %ENV)) ;' } ) ;
    $self -> AddComment ('#config', ['errmsg', 'sizefmt', 'timefmt'], undef, undef,  
                            {   perlcode => [
                                            '$_ep_ssi_errmsg  = %&*\'errmsg% ;',
                                            '$_ep_ssi_sizefmt = %&*\'sizefmt% ;',
                                            '$_ep_ssi_timefmt = %&*\'timefmt% ;',
                                            ],
                              removenode => 1 
                                             } ) ;

    $self -> AddComment ('#exec', ['cgi', 'cmd'], undef, undef, 
                            { perlcode => [
                                        '_ep_rp(%$x%, Embperl::Syntax::SSI::exec (%&\'cmd%, %&\'cgi%)) ;',
                                        ] } ) ;

    $self -> AddComment ('#fsize', ['file', 'virtual'], undef, undef, 
                            { perlcode => [
                                        '_ep_rp(%$x%, Embperl::Syntax::SSI::fsize ($_ep_ssi_sizefmt, %&\'file%, %&\'virtual%)) ;',
                                        ] } ) ;
    $self -> AddComment ('#flastmod', ['file', 'virtual'], undef, undef, 
                            { perlcode => [
                                        '_ep_rp(%$x%, Embperl::Syntax::SSI::flastmod ($_ep_ssi_timefmt, %&\'file%, %&\'virtual%)) ;',
                                        ] } ) ;

    $self -> AddComment ('#include', ['file', 'virtual'], undef, undef, 
                            { perlcode => [
                                        '_ep_rp(%$x%, Embperl::Syntax::SSI::include (%&\'file%, %&\'virtual%)) ;',
                                        ] } ) ;
    $self -> AddComment ('#set', ['var', 'value'], undef, undef, 
                            { perlcode   => '%&value%',
                              compiletimeperlcode => '$Embperl::req -> component -> code (q{$ENV{%&*\'var%} = "} . Embperl::Syntax::SSI::InterpretVars (%&\'value%) . \'";\') ;',
                              removenode => 1 
                                         } ) ;
    $self -> AddComment ('#if', ['expr'], undef, undef, 
                            { perlcode   => '%&\'expr%',
                              compiletimeperlcode => '$Embperl::req -> component -> code (q{if (} . Embperl::Syntax::SSI::InterpretVars (%&\'expr%) . \') {\') ;',
                                removenode  => 10,
                                mayjump     => 1,
                                stackname   => 'ssicmd',
                                'push'      => 'if',
                            } ) ;
    $self -> AddComment ('#elif', ['expr'], undef, undef, 
                            { perlcode   => '%&\'expr%',
                              compiletimeperlcode => '$Embperl::req -> component -> code (\'} elsif (\' . Embperl::Syntax::SSI::InterpretVars (%&\'expr%) . \') {\') ;',
                            removenode => 10,
                            mayjump     => 1,
                            stackname   => 'ssicmd',
                            stackmatch  => 'if',
                            'push'      => 'if',
                            } ) ;
    $self -> AddComment ('#else', undef, undef, undef, 
                            { perlcode   => '} else {',
                            removenode => 10,
                            mayjump     => 1,
                            stackname   => 'ssicmd',
                            stackmatch  => 'if',
                            'push'      => 'if',
                            } ) ;
    $self -> AddComment ('#endif', undef, undef, undef, 
                            { perlcode   => '} ;',
                            removenode => 10,
                            mayjump     => 1,
                            stackname   => 'ssicmd',
                            stackmatch  => 'if',
                            } ) ;
    my $tag = $self -> AddComment ('#syntax', ['type'], undef, undef, 
                { 
                compiletimeperlcode => '$Embperl::req -> component -> syntax  (Embperl::Syntax::GetSyntax(%&\'type%, $Embperl::req -> component -> syntax -> name));', 
                removenode => 3,
                },
                 ) ;
    my $ptcode = '$Embperl::req -> component -> syntax (Embperl::Syntax::GetSyntax(\'%%\', $Embperl::req -> component -> syntax -> name)) ;' ;
    
    if (!$self -> {-ssiAssignAttrType})
        {
        $self -> {-ssiAssignAttrType}     = $self -> CloneHash ($self -> {-htmlAssignAttr}) ;
        }
    $tag -> {inside}{type}{'follow'} = $self -> {-ssiAssignAttrType} ;
    $self -> {-ssiAssignAttrType}{Assign}{follow}{'Attribut ""'}{parsetimeperlcode} = $ptcode ;
    $self -> {-ssiAssignAttrType}{Assign}{follow}{'Attribut \'\''}{parsetimeperlcode} = $ptcode ;
    $self -> {-ssiAssignAttrType}{Assign}{follow}{'Attribut alphanum'}{parsetimeperlcode} = $ptcode ;
 

    }


###################################################################################
#
#   SSI Implementation
#
###################################################################################

# ---------------------------------------------------------------------------------
#
#   Init SSI
#
# ---------------------------------------------------------------------------------

sub InitSSI
    {
    my $fn ;

    $ENV{DATE_GMT}      = gmtime ;
    $ENV{DATE_LOCAL}    = localtime ;
    $ENV{DOCUMENT_NAME} = basename ($fn = $Embperl::req -> component -> sourcefile) ;
    $ENV{DOCUMENT_URI}  = $Embperl::req -> apache_req?$Embperl::req -> apache_req -> uri:$ENV{REQUEST_URI} ;
    $ENV{LAST_MODIFIED} = format_time('', (stat ($fn))[9]) ;
    }
     

# ---------------------------------------------------------------------------------
#
#   Interpolate vars inside string
#
# ---------------------------------------------------------------------------------

sub map_ssi_ops_to_perl
    {
    my $val = shift ;

    $val =~ s/\$(\w)([a-zA-Z0-9_]*)/\$ENV{'$1$2'}/g ;
    $val =~ s/\$\{(\w)([a-zA-Z0-9_]*?)\}/\$ENV{'$1$2'}/g ;
    $val =~ s,!=\s*/,!~ /,;
    $val =~ s,=\s*/,=~ /,;
    $val =~ s/!=/ne/;
    $val =~ s/=([^~])/eq$1/;    

    return $val ;
    }

sub InterpretVars

    {
    my $val = shift ;
    my $esc = shift ;
    my @fields = ($val =~ m/\s* ("(?:(?!(?<!\\)").)*" | '(?:(?!(?<!\\)').)*' | \S+)/gx);
    $val = join(' ', map {m/^[\"\']/ ? $_ : map_ssi_ops_to_perl($_)} @fields );
    $val =~ s/\'/\\\'/g if ($esc) ;
    return $val ;
    }

# ---------------------------------------------------------------------------------
#
#   Find a file
#
# ---------------------------------------------------------------------------------

sub find_file 
    {
    my ($fn, $virt) = @_;
    my $req;

    if (!defined ($Embperl::req -> apache_req))
        {
        if ($fn)
            {
            if ($fn !~ m#/|\\#)
                {
                return $Embperl::req -> component -> cwd . '/' . $fn ;
                }
            else
                {
                return $fn ;
                }
            }
        return $Embperl::req -> component -> sourcefile if (!$virt) ;

	my $filename = $virt;
        
	#die "Cannot use 'virtual' without mod_perl" if ($virt) ;

	if ($filename && ($filename =~ /^\//)) {
		$filename = $ENV{DOCUMENT_ROOT} . $filename;
	}
	return $filename;
        }

    if ($fn) 
        {
        my $req = $Embperl::req -> apache_req -> lookup_file (InterpretVars ($fn)) ;
        return $req -> filename ;
        }
    if ($virt) 
        {
        my $req = $Embperl::req -> apache_req -> lookup_uri (InterpretVars ($virt)) ;
        return $req -> filename ;
        }
    else
        {
        return $Embperl::req -> component -> sourcefile ;
        }
    }


# ---------------------------------------------------------------------------------
#
#   Format time
#
# ---------------------------------------------------------------------------------

sub time_args 

    {
    # This routine must respect the caller's wantarray() context.
    my ($time, $zone) = @_;
    return $zone =~ /GMT/ ? gmtime($time) : localtime($time);
    }


sub format_time 
  {
  my ($format, $time, $tzone) = @_;
  return ($format ? 
	  POSIX::strftime($format, time_args($time, $tzone)) :
	  scalar time_args($time, $tzone));
  }




# ---------------------------------------------------------------------------------
#
#   Output fsize
#
# ---------------------------------------------------------------------------------



sub fsize
   
    { 
    my ($fmt, $fn, $virt) = @_;
    
    my $size = -s find_file($fn, $virt) ;
    
    $fmt ||= 'abbrev' ;

    if ($fmt eq 'bytes')
         {
         return $size;
         }
    elsif ($fmt eq 'abbrev') 
        {
        return "   0k" unless $size;
        return "   1k" if $size < 1024;
        return sprintf("%4dk", ($size + 512)/1024) if $size < 1048576;
        return sprintf("%4.1fM", $size/1048576.0)  if $size < 103809024;
        return sprintf("%4dM", ($size + 524288)/1048576);
        } 
    else 
        {
        die "Unrecognized size format '$fmt'" ;
        }
    }

# ---------------------------------------------------------------------------------
#
#   Output flastmod
#
# ---------------------------------------------------------------------------------

sub flastmod 
    {
    my($fmt, $fn, $virt) = @_;
    
    return format_time($fmt, (stat (find_file($fn, $virt)))[9])
    }

# ---------------------------------------------------------------------------------
#
#   Include
#
# ---------------------------------------------------------------------------------

sub include {
	my($fn, $virt) = @_;
				
	local $/ = undef ;

	my $type = "SSI"; # adding Embperl to syntax results in errors I can't figure out...
	my $filename = $virt;

	if ($fn) {
		$type = "Text";
		$filename = $fn;
	}
	elsif ($virt) {
		if ($filename && ($filename =~ /^\//)) {
			$filename = $ENV{DOCUMENT_ROOT} . "/$filename";
		}
	}
	else {
		warn "Nothing to #include... need file or virtual";
		return "";
	}

	my $output = "";
	Embperl::Req::ExecuteComponent({inputfile=>$filename, output=>\$output, syntax=>$type});

        local $Embperl::escmode = 0 ;
	return $output;
}

# ---------------------------------------------------------------------------------
#
#   Exec
#
# ---------------------------------------------------------------------------------


sub exec 
    {
    my($cmd, $cgi) = @_;

    if (!defined (&Apache::request))
        {
        return scalar `$cmd` if ($cmd) ;
        die "Cannot use 'cgi' without mod_perl" ;
        }

    my $r = $Embperl::req -> apache_req ;
    my $filename = $r->filename;
    
    die ("httpd: exec used but not allowed in $filename") if ($r->allow_options & &OPT_INCNOEXEC) ;
    
    return scalar `$cmd` if ($cmd) ;
    
    die ("No 'cmd' or 'cgi' argument given to #exec") if (!$cgi) ;

    die ("'cgi' as argument to #exec not implemented yet") ;

    # Okay, we're doing <!--#exec cgi=...>
    my $rr = $r->lookup_uri($cgi);
    die("Error including cgi: subrequest returned status '" . $rr->status . "', not 200") if ($rr->status != 200);
    
    # Pass through our own path_info and query_string (does this work?)
    $rr->path_info( $r->path_info );
    $rr->args( scalar $r->args );
    $rr->content_type("application/x-httpd-cgi");
    &_set_VAR($rr, 'DOCUMENT_URI', $r->uri);
    
    my $status = $rr->run;
    return '';
    }


1; 

__END__

=pod

=head1 NAME

Embperl::Syntax::SSI - define SSI syntax for Embperl 

=head1 SYNOPSIS

 [$ syntax SSI $]
 
 DATE_GMT:       <!-- #echo  var='DATE_GMT' -->
 DATE_LOCAL:	<!-- #echo  var='DATE_LOCAL' --> 
 DOCUMENT_NAME:	<!-- #echo  var='DOCUMENT_NAME' -->
 DOCUMENT_URI:	<!-- #echo  var='DOCUMENT_URI' -->
 LAST_MODIFIED:	<!-- #echo  var='LAST_MODIFIED' -->


=head1 DESCRIPTION

The module make Embperl understand the following SSI tags. See
Apaches mod_include (or Apache::SSI) for a description, what they
do.

=over 4

=item * config

=item * echo

=item * exec

=item * fsize

=item * flastmod

=item * include

=item * printenv

=item * set

=item * if

=item * elif

=item * else

=item * endif

=item * syntax

The syntax SSI is non standard and is used to change the syntax once you are
in SSI syntax. It looks like

  <!--#syntax type="Embperl" -->

=back


=head1 Author

Gerald Richter <richter at embperl dot org>

Some ideas and parts of the code are taken from Apache::SSI by Ken Williams. 

=head1 See Also

Embperl::Syntax, Embperl::Syntax::HTML

=cut



# ---------------------------------------------------------------------------------
#
#   Perl
#
# ---------------------------------------------------------------------------------



sub perl 
    {
    my($self, $args, $margs) = @_;

    my ($pass_r, @arg1, @arg2, $sub) = (1);
    {
        my @a;
        while (@a = splice(@$margs, 0, 2)) {
            $a[1] =~ s/\\(.)/$1/gs;
            if (lc $a[0] eq 'sub') {
                $sub = $a[1];
            } elsif (lc $a[0] eq 'arg') {
                push @arg1, $a[1];
            } elsif (lc $a[0] eq 'args') {
                push @arg1, split(/,/, $a[1]);
            } elsif (lc $a[0] eq 'pass_request') {
                $pass_r = 0 if lc $a[1] eq 'no';
            } elsif ($a[0] =~ s/^-//) {
                push @arg2, @a;
            } else { # Any unknown get passed as key-value pairs
                push @arg2, @a;
            }
        }
    }

    warn "sub is $sub, args are @arg1 & @arg2" if $debug;
    my $subref;
    if ( $sub =~ /^\s*sub\s/ ) {     # for <!--#perl sub="sub {print ++$Access::Cnt }" -->
        $subref = eval($sub);
        if ($@) {
            $self->error("Perl eval of '$sub' failed: $@") if $self->{_r};
            warn("Perl eval of '$sub' failed: $@") unless $self->{_r};  # For offline mode
        }
        return $self->error("sub=\"sub ...\" didn't return a reference") unless ref $subref;
    } else {             # for <!--#perl sub="package::subr" -->
        no strict('refs');
	$subref = (defined &{$sub} ? \&{$sub} :
		   defined &{"${sub}::handler"} ? \&{"${sub}::handler"} : 
		   \&{"main::$sub"});
    }
    
    $pass_r = 0 if $self->{_r} and lc $self->{_r}->dir_config('SSIPerlPass_Request') eq 'no';
    unshift @arg1, $self->{_r} if $pass_r;
    warn "sub is $subref, args are @arg1 & @arg2" if $debug;
    return scalar &{ $subref }(@arg1, @arg2);
}


1 ;