ASNMTAP

 view release on metacpan or  search on metacpan

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

#!/usr/bin/env perl
# ---------------------------------------------------------------------------------------------------------
# © Copyright 2003-2011 Alex Peeters [alex.peeters@citap.be]
# ---------------------------------------------------------------------------------------------------------
# 2011/mm/dd, v3.002.003, generateConfig.pl for ASNMTAP::Asnmtap::Applications::CGI
# ---------------------------------------------------------------------------------------------------------

use strict;
use warnings;           # Must be used in test mode only. This reduces a little process speed
#use diagnostics;       # Must be used in test mode only. This reduces a lot of process speed

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

BEGIN { if ( $ENV{ASNMTAP_PERL5LIB} ) { eval 'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'; } }

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

use DBI;
use CGI;
use File::stat;

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

use ASNMTAP::Time v3.002.003;
use ASNMTAP::Time qw(&get_csvfiledate &get_csvfiletime);

use ASNMTAP::Asnmtap::Applications::CGI v3.002.003;
use ASNMTAP::Asnmtap::Applications::CGI qw(:APPLICATIONS :CGI :SADMIN :DBREADWRITE :DBTABLES $DIFFCOMMAND $RSYNCCOMMAND $SCPCOMMAND $SSHCOMMAND );

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

use vars qw($PROGNAME);

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

$PROGNAME       = "generateConfig.pl";
my $prgtext     = "Generate Config";
my $version     = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; # must be all on one line or MakeMaker will get confused.

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

# URL Access Parameters
my $cgi = new CGI;
my $pagedir = (defined $cgi->param('pagedir')) ? $cgi->param('pagedir') : '<NIHIL>'; $pagedir =~ s/\+/ /g;
my $pageset = (defined $cgi->param('pageset')) ? $cgi->param('pageset') : 'admin';   $pageset =~ s/\+/ /g;
my $debug   = (defined $cgi->param('debug'))   ? $cgi->param('debug')   : 'F';
my $action  = (defined $cgi->param('action'))  ? $cgi->param('action')  : 'menuView';
my $Cauto   = (defined $cgi->param('auto'))    ? $cgi->param('auto')    : 0;

my ($Cplugin, $ChelpPluginFilename, $Ctodo);

if ($action eq 'updateView' or $action eq 'update') {
  $Cplugin             = (defined $cgi->param('plugin'))             ? $cgi->param('plugin')             : '';
  $ChelpPluginFilename = (defined $cgi->param('helpPluginFilename')) ? $cgi->param('helpPluginFilename') : '';
  $Ctodo               = (defined $cgi->param('todo'))               ? $cgi->param('todo')               : '';
}

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

my $htmlTitle = $APPLICATION;

# Init parameters
my ($rv, $dbh, $sth, $sql, $numberCentralServers, $nextAction, $formDisabledAll, $formDisabledPrimaryKey, $submitButton);
my (@matchingAsnmtapCollectorCTscript, @matchingAsnmtapDisplayCTscript, %ASNMTAP_PATH);

# User Session and Access Control
my ($sessionID, $iconAdd, $iconDelete, $iconDetails, $iconEdit, $iconQuery, $iconTable, $errorUserAccessControl, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $subTitle) = user_session_and_access_control (1, 'admin', $c...

# Serialize the URL Access Parameters into a string
my $urlAccessParameters = "pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&action=$action&auto=$Cauto";

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

      next if ( $exitCurrentServer );
      $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td>$type</td></tr>";
      my $_type = $_server->{$type};

      foreach my $_id ( keys %$_type ) {
        next if ( $exitCurrentServer );
        my $auto    = ( ( exists $_type->{$_id}{auto} and $_type->{$_id}{auto} ) ? $_type->{$_id}{auto} : 0 );
        my $label   = ( ( exists $_type->{$_id}{label} and $_type->{$_id}{label} ) ? $_type->{$_id}{label} : '??' );
        my $active  = ( ( exists $_type->{$_id}{active} and $_type->{$_id}{active} ) ? $_type->{$_id}{active} : 0 );
        my $command = ( ( exists $_type->{$_id}{command} and $_type->{$_id}{command} ) ? $_type->{$_id}{command} : '' );

        unless ( defined $command ) {
          my $prefix = ( ( $debug eq 'T' ) ? "E) '$label' [$_id] " : '' );
          $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{ENDBLOCK}\"><td><FONT COLOR=\"red\">${prefix}${command}</FONT></td></tr>";
        } elsif ( $type !~ /^(?:RELOAD|STOP|START)$/ or ( $type =~ /^(?:RELOAD|STOP|START)$/ and $active ) ) {
          if ( $Cauto == 1 and $auto == 1 ) {
            my $color = 'red';

            my @capture = `$command 2>&1`;
            my $exit_value  = $? >> 8;
            my $signal_num  = $? & 127;
            my $dumped_core = $? & 128;
            $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td><FONT COLOR=\"white\">$exit_value - $signal_num - $dumped_core - ". join('<br>', @capture) ."</FONT></td></tr>" if ( $debug eq 'T' );

            if ( $exit_value == 0 && $signal_num == 0 && $dumped_core == 0 ) {
              my ($lineNumber, $proccessNextLine) = (0, 0);

              foreach my $capture ( @capture ) {
                $capture =~ s/\r$//g;
                $capture =~ s/\n$//g;
                next unless ( defined $capture and ! $exitCurrentServer );

                $lineNumber++;
                $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td><FONT COLOR=\"cyaan\">$capture</FONT></td></tr>";

                if ( $lineNumber == 1 ) {
                  for ( $type ) {
                    /^SCP$/     && do { last; };
                    /^CHMOD$/   && do { last; };
                    /^RELOAD$/  && do {
                      $exitCurrentServer = ( ( $capture =~ /^Reload:(?:\s)*'(Collector|Display)(?:\s)*(.)*'(?:\s)*...$/ ) ? 0 : 1 );
                      last; };
                    /^STOP$/    && do {
                      $exitCurrentServer = ( ( $capture =~ /^(Stop:(?:\s)*'(Collector|Display)(?:\s)*(.)*'(?:\s)*...|'(Collector|Display)(?:\s)*(.)*'(?:\s)*already stopped)$/ ) ? 0 : 1 );
                      last; };
                    /^START$/   && do {
                      $exitCurrentServer = ( ( $capture =~ /^Start:(?:\s)*'(Collector|Display)(?:\s)*(.)*'(?:\s)*...$/ ) ? 0 : 1 );
                      $proccessNextLine++ unless ( $exitCurrentServer );
                      last; };
                    /^CRONTAB$/ && do { last; };
                    /^REMOVE$/  && do { last; };
                    $exitCurrentServer = 1;
                  }
                } elsif ( $proccessNextLine ) {
                  $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td><FONT COLOR=\"cyaan\">proccess next line: $proccessNextLine - $capture</FONT></td></tr>";
                } else {
                  my $match = 0;

                  if ( $debug eq 'T' ) {
                    for ( $capture ) {
                      /kill:(?:\s)*\((?:\d)*\)(?:\s)*-(?:\s)*No such process$/ && do { $match = 1; $exitCurrentServer = 1; last; };
                      /^cat:(?:\s)*cannot(?:\s)*open(?:\s)*(.)*\.pid$/         && do { $match = 2; $exitCurrentServer = 1; last; };
                    }
                  } else {
                    $exitCurrentServer = 1;
                  }

                  $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td><FONT COLOR=\"cyaan\">match rule: $match - $capture</FONT></td></tr>";
                }
              }

              $color = '#99CC99' unless ( $exitCurrentServer );
            } else {
              $exitCurrentServer = 1;

              foreach my $capture ( @capture ) {
                $capture =~ s/\r$//g;
                $capture =~ s/\n$//g;
                next unless ( defined $capture );

                my $match = '0';

                if ( $debug eq 'T' ) {
                  for ( $capture ) {
                    /^ksh:(?:\s)*(.)*:(?:\s)*not found$/                  && do { $match = 127; last; }; # exit_value = 127
                    /^ksh:(?:\s)*(.)*:(?:\s)*cannot execute$/             && do { $match = 126; last; }; # exit_value = 126
                    /^scp:(?:\s)*(.)*:(?:\s)*No such file or directory$/  && do { $match = 1;   last; }; # exit_value = 1
                    $match = '?';
                  }
                }

                $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{STARTBLOCK}\"><td><FONT COLOR=\"cyaan\">match rule: $match = exit_value: $exit_value - $capture</FONT></td></tr>";
              }
            }

            my $prefix = ( ( $debug eq 'T' ) ? "A) '$label' [$_id] " : '' );
            $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{ENDBLOCK}\"><td><b><FONT COLOR=\"$color\">${prefix}${command}</FONT></b></td></tr>";
          } else { # implementatie moet nog gebeuren
            my $color = ( ( $auto == 1 ) ? '#99CC99' : 'white');
            my $prefix = ( ( $debug eq 'T' ) ? "I) '$label' [$_id] " : '' );
            $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{ENDBLOCK}\"><td><b><FONT COLOR=\"$color\">${prefix}${command}</FONT></b></td></tr>";
          }
        } else { # no action required
          my $prefix = ( ( $debug eq 'T' ) ? "N) '$label' [$_id] " : '' );
          $commandsTODO .= "\n        <tr bgcolor=\"$COLORSTABLE{ENDBLOCK}\"><td><FONT COLOR=\"#99CC99\">${prefix}${command}</FONT></td></tr>";
        }

        $commandsExecuted++ unless ( $exitCurrentServer );
      }
    }
  }

  $statusMessage .= $commandsTODO if (defined $commandsTODO);

# APE #
# unless ($details)
#   $action = 'errorView' unless ( $commandsToExecute eq $commandsExecuted );
# }

  return ($statusMessage);
}



( run in 0.444 second using v1.01-cache-2.11-cpan-39bf76dae61 )