-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunyatt.cgi
executable file
·69 lines (62 loc) · 1.93 KB
/
runyatt.cgi
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
#!/usr/bin/perl -T
#!/usr/bin/perl -w
package main; # For do 'runyatt.cgi'.
use strict;
use warnings qw(FATAL all NONFATAL misc);
use sigtrap die => qw(normal-signals);
use FindBin;
#----------------------------------------
# Ensure ENV, for mod_fastcgi+FCGI.pm and Taint check.
$ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin";
#----------------------------------------
# To allow do 'runyatt.cgi', we should avoid using FindBin.
my $untaint_any; BEGIN { $untaint_any = sub { $_[0] =~ m{.*}s; $& } }
# To avoid redefinition of sub rootname.
my ($get_rootname, $get_extname);
BEGIN {
$get_rootname = sub { my $fn = shift; $fn =~ s/\.\w+$//; join "", $fn, @_ };
$get_extname = sub { my $fn = shift; $fn =~ s/\.(\w+)$// and $1 };
}
use Cwd qw(realpath);
use File::Spec;
my $app_root;
my $rootname;
my @libdir;
BEGIN {
$app_root = $untaint_any->(File::Spec->rel2abs(__FILE__));
$app_root =~ s{/html/cgi-bin/.*}{};
$rootname = $get_rootname->($untaint_any->(realpath(__FILE__)));
if (-d "$app_root/lib/YATT") {
push @libdir, "$app_root/lib";
}
if (defined $rootname and -d $rootname) {
push @libdir, "$rootname.lib";
} elsif (my ($found) = $FindBin::Bin =~ m{^(.*?)/YATT/}) {
push @libdir, $found;
}
unless (@libdir) {
warn "Can't find libdir".(defined $app_root ? ", app_root=$app_root" : "");
}
if (-d (my $dn = "$app_root/extlib")) {
push @libdir, $dn;
}
}
use lib @libdir;
#
use YATT::Lite::Breakpoint;
use YATT::Lite::WebMVC0::SiteApp -as_base;
#----------------------------------------
my @opts;
for (; @ARGV and $ARGV[0] =~ /^--(\w+)(?:=(.*))?/s; shift @ARGV) {
push @opts, $1, defined $2 ? $2 : 1;
}
#----------------------------------------
# To customize, edit app.psgi or app.yml.
my $dispatcher = MY->load_psgi_script("$app_root/app.psgi");
if (caller) {
# For do 'runyatt.cgi'.
return $dispatcher;
} else {
$dispatcher->runas($get_extname->($0), \*STDOUT, \%ENV, \@ARGV
, progname => __FILE__);
}