From 22e198b44af7f38af34e07b8df6320a397cc0cfa Mon Sep 17 00:00:00 2001 From: Jan Soukal <soukal@ics.muni.cz> Date: Thu, 27 Sep 2012 14:54:52 +0200 Subject: [PATCH] dokoncena separace fci c2s a errMsg do WardenClientConf. Viditelnost promennych z requirovanych modulu vyresena explicitnim volanim. --- src/warden-client/lib/WardenClientCommon.pm | 12 ++++----- src/warden-client/lib/WardenClientConf.pm | 6 +---- src/warden-client/lib/WardenClientReceive.pm | 28 +++++++++----------- src/warden-client/lib/WardenClientSend.pm | 28 +++++++------------- 4 files changed, 28 insertions(+), 46 deletions(-) diff --git a/src/warden-client/lib/WardenClientCommon.pm b/src/warden-client/lib/WardenClientCommon.pm index a5f6b16..4349241 100644 --- a/src/warden-client/lib/WardenClientCommon.pm +++ b/src/warden-client/lib/WardenClientCommon.pm @@ -2,15 +2,13 @@ package WardenClientCommon; -require Exporter; - use strict; use Carp; +use SOAP::Lite; +use IO::Socket::SSL qw(debug1); +use SOAP::Transport::HTTP; -use WardenClientConf qw($LOG_VERBOSE); - -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(errMsg c2s); +our $VERSION = "2.1"; #------------------------------------------------------------------------------- # errMsg - print error message and die @@ -19,7 +17,7 @@ sub errMsg { my $msg = "Error message: " . shift; - if ($LOG_VERBOSE) { # user wants to log debug information + if ($WardenClientConf::LOG_VERBOSE) { # user wants to log debug information $msg .= "\nStack info: " . Carp::longmess(); } diff --git a/src/warden-client/lib/WardenClientConf.pm b/src/warden-client/lib/WardenClientConf.pm index 3872339..034ad9e 100755 --- a/src/warden-client/lib/WardenClientConf.pm +++ b/src/warden-client/lib/WardenClientConf.pm @@ -9,10 +9,6 @@ package WardenClientConf; use strict; -require Exporter; - -our @ISA = qw(Exporter); -our @EXPORT_OK = qw($URI $SSL_KEY_FILE $SSL_CERT_FILE $SSL_CA_FILE $MAX_RCV_EVENTS_LIMIT $LOG_STDERR $LOG_SYSLOG $LOG_SYSLOG_FACILITY $LOG_VERBOSE); # preset of default variables our $URI = undef; @@ -26,7 +22,7 @@ our $LOG_SYSLOG_FACILITY = "local7"; our $LOG_VERBOSE = 0; -our $VERSION = "2.0"; +our $VERSION = "2.1"; sub loadConf { diff --git a/src/warden-client/lib/WardenClientReceive.pm b/src/warden-client/lib/WardenClientReceive.pm index 20a139a..a326222 100755 --- a/src/warden-client/lib/WardenClientReceive.pm +++ b/src/warden-client/lib/WardenClientReceive.pm @@ -15,8 +15,7 @@ use SOAP::Transport::HTTP; use FindBin; use Sys::Syslog; - -our $VERSION = "2.0"; +our $VERSION = "2.1"; #------------------------------------------------------------------------------- # getNewEvents - get new events from warden server greater than last received ID @@ -34,11 +33,8 @@ sub getNewEvents my $etcdir = $warden_path . "/etc/"; my $libdir = $warden_path . "/lib/"; - # use lib "/asdf/aasdf"; # cesta do lib/ adresare wardenu - # use WardenClientConf qw($URI $SSL_KEY_FILE $SSL_CERT_FILE $SSL_CA_FILE $MAX_RCV_EVENTS_LIMIT $LOG_STDERR $LOG_SYSLOG $LOG_SYSLOG_FACILITY $LOG_VERBOSE); require $libdir . "WardenClientConf.pm"; - # use WardenClientCommon qw (errMsg c2s); - require $libdir . "WardenClientCommon.pm" + require $libdir . "WardenClientCommon.pm"; # read the config file my $conf_file = $etcdir . "warden-client.conf"; @@ -53,15 +49,15 @@ sub getNewEvents # get last ID from warden server DB and save it into ID file my $last_id; if (-e $id_file) { - open(ID, "< $id_file") || errMsg("Cannot open ID file $id_file: $!"); + open(ID, "< $id_file") || WardenClientCommon::errMsg("Cannot open ID file $id_file: $!"); foreach(<ID>) { $last_id = $_; } close ID; } else { - my $response = c2s($URI, $SSL_KEY_FILE, $SSL_CERT_FILE, $SSL_CA_FILE, "getLastId"); + my $response = WardenClientCommon::c2s($WardenClientConf::URI, $WardenClientConf::SSL_KEY_FILE, $WardenClientConf::SSL_CERT_FILE, $WardenClientConf::SSL_CA_FILE, "getLastId"); $last_id = $response->result; - open(ID, "> $id_file") || errMsg("Cannot open ID file $id_file: $!"); + open(ID, "> $id_file") || WardenClientCommon::errMsg("Cannot open ID file $id_file: $!"); print ID $last_id; close ID; } @@ -74,12 +70,12 @@ sub getNewEvents request => \SOAP::Data->value( SOAP::Data->name(REQUESTED_TYPE => $requested_type), SOAP::Data->name(LAST_ID => $last_id), - SOAP::Data->name(MAX_RCV_EVENTS_LIMIT => $MAX_RCV_EVENTS_LIMIT) + SOAP::Data->name(MAX_RCV_EVENTS_LIMIT => $WardenClientConf::MAX_RCV_EVENTS_LIMIT) ) ); # call server method getNewEvents - my $response = c2s($URI, $SSL_KEY_FILE, $SSL_CERT_FILE, $SSL_CA_FILE, "getNewEvents", $request_data); + my $response = WardenClientCommon::c2s($WardenClientConf::URI, $WardenClientConf::SSL_KEY_FILE, $WardenClientConf::SSL_CERT_FILE, $WardenClientConf::SSL_CA_FILE, "getNewEvents", $request_data); # parse returned SOAP data object my ($id, $hostname, $service, $detected, $type, $source_type, $source, $target_proto, $target_port, $attack_scale, $note, $priority, $timeout); @@ -115,20 +111,20 @@ sub getNewEvents # write last return ID if (defined $last_id) { # must be defined for first check ID - open(ID, "> $id_file") || errMsg("Cannot open ID file $id_file: $!"); + open(ID, "> $id_file") || WardenClientCommon::errMsg("Cannot open ID file $id_file: $!"); print ID $last_id; close ID; } } # End of eval block or do { - if ($LOG_STDERR) { + if ($WardenClientConf::LOG_STDERR) { print STDERR "Warden-client unexpected end in eval block.\n" . $@ . "\n"; } - if ($LOG_SYSLOG) { - openlog("Warden:", "pid", "$LOG_SYSLOG_FACILITY"); - syslog("err|$LOG_SYSLOG_FACILITY", "Warden-client unexpected end in eval block.\n" . $@ . "\n"); + if ($WardenClientConf::LOG_SYSLOG) { + openlog("Warden:", "pid", "WardenClientConf::LOG_SYSLOG_FACILITY"); + syslog("err|WardenClientConf::LOG_SYSLOG_FACILITY", "Warden-client unexpected end in eval block.\n" . $@ . "\n"); closelog(); } return; diff --git a/src/warden-client/lib/WardenClientSend.pm b/src/warden-client/lib/WardenClientSend.pm index c903807..c838818 100755 --- a/src/warden-client/lib/WardenClientSend.pm +++ b/src/warden-client/lib/WardenClientSend.pm @@ -14,16 +14,7 @@ use IO::Socket::SSL qw(debug1); use SOAP::Transport::HTTP; use Sys::Syslog; -our $VERSION = "2.0"; #first iteration after 'port to Apache' - -#----- global configuration variables - default initialization ----------------- -our $LOG_STDERR = 1; - -our $LOG_SYSLOG = 0; -our $LOG_SYSLOG_FACILITY; - -our $LOG_VERBOSE = 0; -#----- end of configuration variables ------------------------------------------ +our $VERSION = "2.1"; #------------------------------------------------------------------------------- # saveNewEvent - send new event from detection scripts to warden server @@ -39,11 +30,12 @@ sub saveNewEvent my $etcdir = $warden_path . "/etc/"; my $libdir = $warden_path . "/lib/"; + require $libdir . "WardenClientConf.pm"; + require $libdir . "WardenClientCommon.pm"; + # read the config file - require $libdir . "WardenClientConf.pm"; my $conf_file = $etcdir . "warden-client.conf"; - my ($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file, $max_rcv_events_limit); - ($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file, $max_rcv_events_limit, $LOG_STDERR, $LOG_SYSLOG, $LOG_SYSLOG_FACILITY) = WardenClientConf::loadConf($conf_file); + WardenClientConf::loadConf($conf_file); # prepare variables of event my @event = @{$event_ref}; @@ -76,17 +68,17 @@ sub saveNewEvent ) ); - $result = WardenClientConf::c2s($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file, "saveNewEvent", $event); + $result = WardenClientCommon::c2s($WardenClientConf::URI, $WardenClientConf::SSL_KEY_FILE, $WardenClientConf::SSL_CERT_FILE, $WardenClientConf::SSL_CA_FILE, "saveNewEvent", $event); } # End of eval block or do { - if ($LOG_STDERR) { + if ($WardenClientConf::LOG_STDERR) { print STDERR "Warden-client unexpected end in eval block.\n" . $@ . "\n"; } - if ($LOG_SYSLOG) { - openlog("Warden-client:", "pid", "$LOG_SYSLOG_FACILITY"); - syslog("err|$LOG_SYSLOG_FACILITY", "Warden-client unexpected end in eval block.\n" . $@ . "\n"); + if ($WardenClientConf::LOG_SYSLOG) { + openlog("Warden-client:", "pid", "$WardenClientConf::LOG_SYSLOG_FACILITY"); + syslog("err|$WardenClientConf::LOG_SYSLOG_FACILITY", "Warden-client unexpected end in eval block.\n" . $@ . "\n"); closelog(); } -- GitLab