Last active
January 30, 2017 01:38
-
-
Save kazeburo/4480122 to your computer and use it in GitHub Desktop.
PSGI file to serving Nagios WebUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Plack::App::CGIBin; | |
use Plack::App::PHPCGIFile; | |
use Plack::Builder; | |
use Plack::Builder::Conditionals; | |
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 $htdocs = Plack::App::PHPCGIFile->new( | |
root => '/usr/local/nagios/share' | |
)->to_app; | |
builder { | |
enable match_if addr([qw!127.0.0.1!]), 'ReverseProxy'; | |
enable sub { | |
my $apps = shift; | |
sub { | |
my $env = shift; | |
return [302,[Location=>'http://'.$env->{HTTP_HOST}.'/nagios/'],['moved']] if $env->{PATH_INFO} =~ m!^/(nagios)?$!; | |
$env->{REMOTE_USER} = 'nagiosadmin'; | |
$env->{PATH_INFO} .= 'index.php' | |
if $env->{PATH_INFO} =~ m!^/nagios/([^\.]+/)*$!; | |
$apps->($env); | |
}; | |
}; | |
mount '/nagios/cgi-bin' => $cgibin, | |
mount '/nagios' => $htdocs, | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment