Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
[nagiosplug.git] / contrib / restrict.pl
1 #!/usr/bin/perl
3 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
4     if 0;
6 # Set this to your local Nagios plugin path
7 my $pluginpath = "/usr/libexec/nagios/plugins/";
9 # Put all the legal commands (i.e. the commands that are
10 # not Nagios checks but are allowed to be executed anyway)
11 # in the following associative array.
12 my %legal_cmds = ("nc" => "/usr/sbin/nc");
14 # This will not work on OpenSSH
15 # It does work on ssh-1.2.27-1i
16 @arg = split ' ',$ENV{'SSH_ORIGINAL_COMMAND'};
18 $arg[0] =~ s/.*\///;            # strip leading path
19 $arg[0] =~ tr/-_.a-zA-Z0-9/X/c; # change atypical chars to X
21 if (!defined ($cmd = $legal_cmds{$arg[0]}))
22 {
23   $cmd = $pluginpath . $arg[0];
24 }
26 exec { $cmd } @arg or die "Can't exec $cmd: $!";