public
Last active

PSGI file to serving Nagios WebUI

  • Download Gist
nagios_web.psgi
Perl
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
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,
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.