diff --git a/src/warden-client/doc/CHANGELOG b/src/warden-client/doc/CHANGELOG index fd48a8fd68c4187ce34f0f2333e5fbc1e82e5e4c..d0c17ef9c2eca6444fb0be6392da39b32c0f8260 100644 --- a/src/warden-client/doc/CHANGELOG +++ b/src/warden-client/doc/CHANGELOG @@ -1,5 +1,7 @@ 2012-12-?? v.2.2-beta version -------------------------------------------------------------------------------- +- Added new getClientInfo() function allowing the client to see (#609) + information regarding other involved clients - Enhanced handling of errors. Die() functions are removed from (#599) the code, errors are handled using return values. diff --git a/src/warden-client/doc/example-info.pl.txt b/src/warden-client/doc/example-info.pl.txt new file mode 100755 index 0000000000000000000000000000000000000000..a4c1adaeca06018383cc0f4c1c5252362b742392 --- /dev/null +++ b/src/warden-client/doc/example-info.pl.txt @@ -0,0 +1,47 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +use strict; + +#------------------------------------------------------------------------------ +# Warden 2.2 Client, Info, Example +# +# Simple use of warden-client Info functionality to receive information about +# client registered to Warden server. This code illustrates how to integrate +# warden-client info functionality into local applications. +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# This code should developer add into his/her application. + +# Path to warden-client directory +my $warden_path = '/home/soukal/pokus/warden/warden-client/'; + +# Inclusion of warden-client receiving functionality +require $warden_path . '/lib/WardenClientCommon.pm'; + +my @clients = WardenClientCommon::getClientInfo($warden_path); + +print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n"; +print "| Client ID | Hostname | Registered | Requestor | Service | CT | Type | ROE | Description tags | IP Net Client |\n"; +print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n"; +foreach (@clients) { + printf("| %-10s ", @$_[0] || "unknown"); + printf("| %-30s ", @$_[1] || "unknown"); + printf("| %19s ", @$_[2] || "unknown"); + printf("| %-23s ", @$_[3] || "unknown"); + printf("| %-25s ", @$_[4] || "unknown"); + printf("| %-2s ", @$_[5] || "unknown"); + printf("| %-15s ", @$_[6] || "unknown"); + printf("| %-4s ", @$_[7] || "unknown"); + printf("| %-50s ", @$_[8] || "unknown"); + printf("| %-18s |\n", @$_[9] || "unknown"); +} +print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n"; +print "\n"; +print "Current registered clients in: " . scalar localtime(time) . "\n"; + +exit 0; diff --git a/src/warden-client/doc/example-receiver.pl.txt b/src/warden-client/doc/example-receiver.pl.txt index 090e9a9d4d9fb5289814f12d708eed811bd475ee..55076103b0b847098d5e26450cfffb22e97d149a 100755 --- a/src/warden-client/doc/example-receiver.pl.txt +++ b/src/warden-client/doc/example-receiver.pl.txt @@ -7,7 +7,7 @@ use strict; #------------------------------------------------------------------------------ -# Warden 2.1 Client, Receiver, Example +# Warden 2.2 Client, Receiver, Example # # Simple use of warden-client receiver functionality to download new events # from # Warden server. This code illustrates how to integrate warden-client @@ -18,7 +18,7 @@ use strict; # This code should developer add into his/her application. # Path to warden-client directory -my $warden_path = '/opt/warden-client/'; +my $warden_path = '/home/soukal/pokus/warden/warden-client/'; # Inclusion of warden-client receiving functionality require $warden_path . '/lib/WardenClientReceive.pm'; diff --git a/src/warden-client/doc/example-sender.pl.txt b/src/warden-client/doc/example-sender.pl.txt index 40af31a0b048fb37204e076a8e64c59c7a514fd4..e123eaf1a41fe8791f07ae9bf73eeb23b872aa17 100755 --- a/src/warden-client/doc/example-sender.pl.txt +++ b/src/warden-client/doc/example-sender.pl.txt @@ -8,7 +8,7 @@ use strict; use DateTime; #------------------------------------------------------------------------------- -# Warden 2.1. Client, Sender, Example +# Warden 2.2. Client, Sender, Example # # Sample script using warden-client sending functionality. This example is not # intended to be a standalone script. It only shows how to use warden-client @@ -23,7 +23,7 @@ use DateTime; my $local_detected = DateTime->from_epoch(epoch => time()); -my $service = "ScanDetector"; +my $service = "test"; my $detected = "$local_detected"; my $type = "portscan"; my $source_type = "IP"; @@ -32,8 +32,8 @@ my $target_proto = "TCP"; my $target_port = "22"; my $attack_scale = "1234567890"; my $note = "important note or comment"; -my $priority = undef; -my $timeout = "20"; +my $priority = 1; +my $timeout = 20; my @event = ($service, $detected, $type, $source_type, $source, $target_proto, $target_port, $attack_scale, $note, @@ -45,12 +45,15 @@ my @event = ($service, $detected, $type, $source_type, $source, # (with corresponding paths appropriately changed). # Path to warden-client folder -my $warden_path = '/opt/warden-client'; +my $warden_path = '/home/soukal/pokus/warden/warden-client'; # Inclusion of warden-client sender module require $warden_path . '/lib/WardenClientSend.pm'; # Sending event to Warden server -WardenClientSend::saveNewEvent($warden_path, \@event); +for (my $i = 0; $i < 10; $i++) { + print "Sending $i-st event on server\n"; + WardenClientSend::saveNewEvent($warden_path, \@event); + } exit 0; diff --git a/src/warden-client/lib/WardenClientCommon.pm b/src/warden-client/lib/WardenClientCommon.pm index ef5ba39897082f1a5dc0a446e22177af1f0e04cd..efda17a69798244f7b277b2d1d18e35dc3a12f69 100755 --- a/src/warden-client/lib/WardenClientCommon.pm +++ b/src/warden-client/lib/WardenClientCommon.pm @@ -139,3 +139,53 @@ sub c2s } } +#------------------------------------------------------------------------------- +# getClientInfo - retrieve information about other clients from Warden server +#------------------------------------------------------------------------------- +sub getClientInfo +{ + my $warden_path = shift; + + my $etcdir = $warden_path . "/etc/"; + my $libdir = $warden_path . "/lib/"; + + require $libdir . "WardenClientConf.pm"; + + # read the config file + my $conf_file = $etcdir . "warden-client.conf"; + WardenClientConf::loadConf($conf_file); + + # c2s() returns undef on fail + my $response = c2s($WardenClientConf::URI, $WardenClientConf::SSL_KEY_FILE, $WardenClientConf::SSL_CERT_FILE, $WardenClientConf::SSL_CA_FILE, "getClients"); + + defined $response or return; # receive data or return undef + + # parse returned SOAP data object with clients + my @clients; + my ($client_id, $hostname, $registered, $requestor, $service, $client_type, $type, $receive_own_events, $description_tags, $ip_net_client); + my @response_list = $response->valueof('/Envelope/Body/getClientsResponse/client/'); + + while (scalar @response_list) { + my $response_data = shift(@response_list); + my @client; + + $client_id = $response_data->{'CLIENT_ID'} ; + $hostname = $response_data->{'HOSTNAME'}; + $registered = $response_data->{'REGISTERED'}; + $requestor = $response_data->{'REQUESTOR'}; + $service = defined $response_data->{'SERVICE'} ? $response_data->{'SERVICE'} : "-"; + $client_type = $response_data->{'CLIENT_TYPE'}; + $type = defined $response_data->{'TYPE'} ? $response_data->{'TYPE'} : "-"; + $receive_own_events = defined $response_data->{'RECEIVE_OWN_EVENTS'} ? $response_data->{'RECEIVE_OWN_EVENTS'} : "-"; + $description_tags = defined $response_data->{'DESCRIPTION_TAGS'} ? $response_data->{'DESCRIPTION_TAGS'} : "-"; + $ip_net_client = $response_data->{'IP_NET_CLIENT'}; + + # push received clients from warden server into @clients which is returned + @client = ($client_id, $hostname, $registered, $requestor, $service, $client_type, $type, $receive_own_events, $description_tags, $ip_net_client); + push (@clients,\@client); + } + + return @clients; +} + +1;