Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
use Plack::App::CGIBin;
use Plack::App::PHPCGI;
use Plack::Builder;
use File::Zglob;
my $cgibin = Plack::App::CGIBin->new(
root => "/usr/local/nagios/sbin",
exec_cb => sub { my $file = shift; $file =~ m!\.cgi$! and -x $file },
)->to_app;
my $static = Plack::App::File->new(root => "/usr/local/nagios/share")->to_app;
my @php;
for my $php ( zglob("/usr/local/nagios/share/**/*.php") ) {
my $mount = $php;
$mount =~ s!^/usr/local/nagios/share!/nagios!;
my $app = Plack::App::PHPCGI->new(
script => $php,
php_cgi => '/usr/local/php/bin/php-cgi',
);
push @php, [$mount,$app];
}
builder {
enable 'ReverseProxy';
enable sub {
my $apps = shift;
sub {
my $env = shift;
return [302,[Location=>'http://'.$env->{HTTP_HOST}.'/nagios/'],['moved']] if $env->{PATH_INFO} eq '/';
$env->{REMOTE_USER} = 'nagios';
$env->{PATH_INFO} .= 'index.php'
if $env->{PATH_INFO} =~ m!^/nagios/([^\.]+/)*$!;
$apps->($env);
};
};
for my $php ( @php ) {
mount $php->[0], $php->[1];
}
mount '/nagios/cgi-bin' => $cgibin,
mount '/nagios' => $static,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment