ASNMTAP

 view release on metacpan or  search on metacpan

applications/htmlroot/cgi-bin/runCmdOnDemand.pl  view on Meta::CPAN

    # my $capture_exec = ( $RUNCMDONDEMAND eq 'probe' ) ? "$SSHCOMMAND -i '$SSHKEYPATH/$SSHLOGONNAME/.ssh/asnmtap.id' -o 'StrictHostKeyChecking=no' $SSHLOGONNAME\@$FQDN \"if [ -d /opt/monitoring/asnmtap/plugins/ ]; then cd /opt/monitoring/asnmtap/plu...
      my $capture_exec = ( $RUNCMDONDEMAND eq 'probe' ) ? "$SSHCOMMAND -i '$SSHKEYPATH/$SSHLOGONNAME/asnmtap.id' -o 'StrictHostKeyChecking=no' $SSHLOGONNAME\@$FQDN \"if [ -d /opt/monitoring/asnmtap/plugins/ ]; then cd /opt/monitoring/asnmtap/plugins/...

      if ( 1 == 1 ) {
        @capture_array = `$capture_exec`;
      } else {
        my ($stdout, $stderr, $exit_value, $signal_num, $dumped_core);

        if ($CAPTUREOUTPUT) {
          use IO::CaptureOutput qw(capture_exec);
          ($stdout, $stderr) = capture_exec("$capture_exec");
        } else {
          system ("$capture_exec"); $stdout = $stderr = '';
        }

        $exit_value  = $? >> 8;
        $signal_num  = $? & 127;
        $dumped_core = $? & 128;
        @capture_array = split (/\n/, $stdout);
        print "< $capture_exec >< $exit_value >< $signal_num >< $dumped_core >< $stdout >< $stderr >\n" if ($debug eq 'S');
      }

      for (; $capture_array < @capture_array -1; $capture_array++) {
        my $capture = $capture_array[$capture_array];
        $capture =~ s/\r$//g;
        $capture =~ s/\n$//g;

        if ( $capture =~ /^--> URL: (?:GET|POST)/ ) {
          $capture_long = $capture_html = $capture_text = $capture_debug = 0;
          print "<tr><th class=\"RunCmdOnDemandCaptureHeader\">$capture</th></tr>\n";
        } elsif ( $capture =~ /LWP::UserAgent::request: Simple response:/ ) {
          $capture_long = 1;
          print "<tr><td class=\"RunCmdOnDemandCaptureTrue\">$capture</td></tr>\n<tr><td class=\"RunCmdOnDemandCaptureLong\">";
        } elsif ( ! $capture_html and $capture =~ /<HTML|<!DOCTYPE HTML PUBLIC/i ) {
          $capture_html = 1;
          print "</td></tr><tr><td class=\"RunCmdOnDemandCaptureHtml\">$capture\n";
        } elsif ( $capture =~ /<\/HTML>/i ) {
          $capture_html = 0;
          print "$capture\n</td></tr>\n";
        } elsif ( ! $capture_text and $capture =~ /^scan_socket_info :|^<!---Start debug:-->/ ) {
          $capture_text = 1;
          print "</td></tr><tr><td class=\"RunCmdOnDemandCaptureTrue\"><pre>$capture\n";
        } elsif ( ! $capture_debug and $capture =~ /^Start time   :|^Status       :/ ) {
          $capture_debug = 1;
          print "</td></tr><tr><td class=\"RunCmdOnDemandCaptureDebug\"><pre>$capture\n";
        } elsif ($capture =~ /WebTransact::response_time: /) {
          push (@WebTransactResponses, $capture);
        } elsif ($capture =~ /WebTransact::timing_tries: /) {
          push (@WebTransactResponses, $capture);
        } elsif ($capture ne '') {
          if ($capture_debug) {
            print "$capture\n";
          } elsif ($capture_text) {
            print "$capture\n";
          } elsif ($capture_html) {
            $capture =~ s/(window.location.href)/\/\/$1/gi;

            # RFC 1738 -> [ $\/:;=?@.\-!*'()\w&+,]+
            $capture =~ s/(<META\s+HTTP-EQUIV\s*=\s*\"Refresh\"\s+CONTENT\s*=\s*\"\d+;\s*URL\s*=[^"]+\"(?:\s+\/?)?>)/<!--$1-->/img;

            # remove password from Basic Authentication URL before putting into database!
            $capture =~ s/(http[s]?)\:\/\/(\w+)\:(\w+)\@/$1\:\/\/$2\:********\@/img;

            # comment <SCRIPT></SCRIPT>
            $capture =~ s/<SCRIPT/<!--<SCRIPT/gi;
            $capture =~ s/<\/SCRIPT>/<\/SCRIPT>-->/gi;

            # replace <BODY onload="..."> with <BODY>
            $capture =~ s/<BODY\s*onload\s*=\s*.*\s*>/<BODY>/gi;

            print "$capture\n";
          } elsif ($capture_long) {
            print "$capture<br>\n";
          } else {
            print "<tr><td class=\"RunCmdOnDemandCaptureTrue\">$capture</td></tr>\n";
	      }
  	    }
      }

      foreach my $WebTransactResponses (@WebTransactResponses) {
        print "</td></tr><tr><td class=\"RunCmdOnDemandCaptureTime\">$WebTransactResponses\n";
      }

      print "<tr><td>&nbsp;</td></tr>\n" if ($capture_array == 0);
      my ($status, undef) = split(/ - /, $capture_array[$capture_array], 2);
      $status = ( $status =~ /(^OK|^WARNING|^CRITICAL|^UNKNOWN|^DEPENDENT|^OFFLINE|^NO TEST)/ ) ? $1 : 'UNKNOWN';
      print '</table><br><IMG SRC="', $IMAGESURL, '/', $ICONS{$status}, '" ALT="$status" WIDTH="16" HEIGHT="16" BORDER=0 ALIGN="middle"> ', encode_html_entities('M', $capture_array[$capture_array]), "<br>";
    } else {
      print "<br>Select application for immediate launch.<br>";
    }
  }

  print '<BR>', "\n";
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub maskPassword {
  my ($parameters) =  @_;

  # --dnPass=
  if ($parameters =~ /--dnPass=/) {
    $parameters =~ s/(--dnPass=)\w+/$1********/g;
  }

  # --proxy=user:pasword\@proxy
  if ($parameters =~ /--proxy=/) {
    $parameters =~ s/(--proxy=\w*:)\w*(\@\w+)/$1********$2/g;
  }

  # -p user:pasword\@proxy
  if ($parameters =~ /-p / and ($parameters !~ /-u / and $parameters !~ /--username=/)) {
    $parameters =~ s/(-p \w*:)\w*(\@\w+)/$1********$2/g;
  }

  # --password=
  if ($parameters =~ /--password=/) {
    $parameters =~ s/(--password=)\w+/$1********/g;
  }

  # --username= or -u and --password= or -p (database plugins)
  if ($parameters =~ /-p / and ($parameters =~ /-u / or $parameters =~ /--username=/)) {
    $parameters =~ s/(-p )\w+/$1********/g;
  }

  # --username= or -U and --password= or -P (ftp plugins)
  if ($parameters =~ /-P / and ($parameters =~ /-U / or $parameters =~ /--username=/)) {
    $parameters =~ s/(-P )\w+/$1********/g;
  }

  # j_username= or j_password= (J2EE based Applications)
  if ($parameters =~ /j_username=/ and $parameters =~ /j_password=/) {
    $parameters =~ s/(j_password=)\w+/$1********/g;
  }

  return ($parameters);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

print_legend (*STDOUT);
print '</BODY>', "\n", '</HTML>', "\n";

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



( run in 1.455 second using v1.01-cache-2.11-cpan-437f7b0c052 )