ASNMTAP

 view release on metacpan or  search on metacpan

lib/ASNMTAP/Asnmtap/Plugins/Modem.pm  view on Meta::CPAN

  %ASNMTAP::Asnmtap::Plugins::Modem::EXPORT_TAGS = ( ALL => [ qw(&get_modem_request) ] );

  @ASNMTAP::Asnmtap::Plugins::Modem::EXPORT_OK   = ( @{ $ASNMTAP::Asnmtap::Plugins::Modem::EXPORT_TAGS{ALL} } );

  $ASNMTAP::Asnmtap::Plugins::Modem::VERSION     = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
}

# Utility methods - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub get_modem_request {
  my %defaults = ( asnmtapInherited => undef,
                   custom           => undef,
                   customArguments  => undef,
                   windows          => undef,
                   phonenumber      => undef,
                   port             => '/dev/ttyS0',
                   baudrate         => 19200,
                   databits         => 8,
                   initString       => 'H0 Z S7=45 S0=0 Q0 V1 E0 &C0 X4',
                   parity           => 'none',
                   stopbits         => 1,
                   timeout          => 30,
                   phonebook        => undef,
                   username         => undef,
                   password         => undef,
                   defaultGateway   => undef,
                   defaultInterface => undef,
                   defaultDelete    => 1,
                   pppInterface     => 'ppp0',
                   pppTimeout       => 60,
                   pppPath          => '/etc/ppp',
                   logtype          => 'syslog',
                   loglevel         => 'emerg'
                 );

  my %parms = (%defaults, @_);

  my $asnmtapInherited = $parms{asnmtapInherited};
  unless ( defined $asnmtapInherited ) { cluck ( 'ASNMTAP::Asnmtap::Plugins::XML: asnmtapInherited missing' ); exit $ERRORS{UNKNOWN} }

  my $debug = $$asnmtapInherited->getOptionsValue ( 'debug' ) || 0;

  unless ( defined $parms{phonenumber} ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Missing phonenumber' }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  unless ( $parms{phonenumber} =~ /^[.0-9]+$/ ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid phonenumber: '. $parms{phonenumber} }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  if ( $^O eq 'MSWin32' or ( defined $parms{windows} and $parms{windows} ) ) {
    eval "use Win32::RASE";
    $parms{windows} = 1;

    unless ( $parms{port} =~ /^com[1-4]$/ ) {
      $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid Windows port: '. $parms{port} }, $TYPE{APPEND} );
      return ( $ERRORS{UNKNOWN} );
    }
  } else {                                             # running on Linix
    eval "use Net::Ifconfig::Wrapper";
    $parms{windows} = 0;

    unless ( $parms{port} =~ /^\/dev\/ttyS[0-3]$/ ) {
      $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid Linux port: '. $parms{port} }, $TYPE{APPEND} );
      return ( $ERRORS{UNKNOWN} );
    }
  }

  unless ( $parms{baudrate} =~ /^(?:300|1200|2400|4800|9600|19200|38400|57600|115200)$/ ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid baudrate: '. $parms{baudrate} }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  unless ( $parms{databits} =~ /^[5-8]$/ ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid databits: '. $parms{databits} }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  unless ( $parms{parity} =~ /^(?:none|odd|even)$/ ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid : parity'. $parms{parity} }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  unless ( $parms{stopbits} =~ /^[12]$/ ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid stopbits: '. $parms{stopbits} }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  unless ( $parms{timeout} =~ /^\d+$/ ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid timeout: '. $parms{timeout} }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  my $modem_not_ras = ( defined $parms{phonebook} ) ? 0 : 1;

  unless ( $modem_not_ras ) {
    unless ( defined $parms{phonebook} and defined $parms{username} ) {
      $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Missing phonebook' }, $TYPE{APPEND} ) unless ( defined $parms{phonebook} );
      $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Missing username' },  $TYPE{APPEND} ) unless ( defined $parms{username} );
      return ( $ERRORS{UNKNOWN} );
    }

    if ( $parms{windows} and ! defined $parms{password} ) {
      $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Missing password' },  $TYPE{APPEND} );
      return ( $ERRORS{UNKNOWN} );
    }
  }

  unless ( $parms{defaultDelete} =~ /^(?:[01])$/ ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid defaultDelete: '. $parms{defaultDelete} }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  unless ( $parms{pppInterface} =~ /^(?:ppp[0-3])$/ ) {
    $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Invalid pppInterface: '. $parms{pppInterface} }, $TYPE{APPEND} );
    return ( $ERRORS{UNKNOWN} );
  }

  unless ( $parms{pppTimeout} =~ /^(?:[1-9]\d*)$/ ) {



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