Skip to content
Snippets Groups Projects
Commit 0f59a4cf authored by Jan Soukal's avatar Jan Soukal
Browse files

upravy ohledne funkce getClientsInfo vypisujici informace o vsech do wardenu zapojenych klientech.

parent 1b487ec4
No related branches found
No related tags found
No related merge requests found
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.
......
#!/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;
......@@ -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';
......
......@@ -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;
......@@ -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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment