From 96f09b6525cc7a37cf17e473b2ffa2cb6dc5f643 Mon Sep 17 00:00:00 2001
From: Tomas Plesnik <plesnik@ics.muni.cz>
Date: Mon, 21 Jan 2013 15:30:08 +0100
Subject: [PATCH] odstranen SOAP z unregisterClient, registerSender,
 registerReceiver; vylepseno vytahovani dat z DB v getStatus.pl; odstraneny
 managmentovaci SOAP funkce z Warden.pm; odstranen WardenReg.pm a
 warden-client.conf

---
 src/warden-server/bin/getStatus.pl        |  20 +--
 src/warden-server/bin/registerReceiver.pl | 106 +++++++++--
 src/warden-server/bin/registerSender.pl   | 105 +++++++++--
 src/warden-server/bin/unregisterClient.pl | 114 +++++++++++-
 src/warden-server/etc/warden-client.conf  |  23 ---
 src/warden-server/lib/Warden.pm           | 207 ----------------------
 src/warden-server/lib/WardenReg.pm        | 170 ------------------
 7 files changed, 305 insertions(+), 440 deletions(-)
 delete mode 100644 src/warden-server/etc/warden-client.conf
 delete mode 100755 src/warden-server/lib/WardenReg.pm

diff --git a/src/warden-server/bin/getStatus.pl b/src/warden-server/bin/getStatus.pl
index 6f5c0b6..2637a62 100755
--- a/src/warden-server/bin/getStatus.pl
+++ b/src/warden-server/bin/getStatus.pl
@@ -12,7 +12,8 @@ use File::Basename;
 use DBI;
 use DBD::mysql;
 use Format::Human::Bytes;
-use Data::Dumper;
+
+
 
 ################################################################################
 #				GLOBAL VARIABLES
@@ -116,10 +117,9 @@ if ($SYSLOG_VERBOSE == 1) {
 
 #-------------------------------------------------------------------------------
 # Warden server status
-my $sth;
 
 # size of database events
-$sth = $DBH->prepare("SELECT data_length + index_length FROM information_schema.TABLES WHERE table_schema = ? AND TABLE_NAME = ?") or die "Cannot prepare statement: " . $DBH->errstr;
+my $sth = $DBH->prepare("SELECT data_length + index_length FROM information_schema.TABLES WHERE table_schema = ? AND TABLE_NAME = ?") or die "Cannot prepare statement: " . $DBH->errstr;
 $sth->execute('warden', 'events') or die "Cannot execute statement: " . $sth->errstr;
 my $size = $sth->fetchrow();
 my $db_size = defined $size ? Format::Human::Bytes::base10($size) : "none";
@@ -199,13 +199,13 @@ if ($clients_sum != 0) {
   print "+----------------------------------------------------------------------------------------------------------------+\n";
   print "| Client ID  | Hostname                       | Service                   | Stored events | Last insertion (UTC) |\n";
   print "+----------------------------------------------------------------------------------------------------------------+\n";
-    foreach my $key (sort {$a<=>$b} keys %$hash_ref) {
-      printf("| %-10s ", $hash_ref->{$key}->{client_id} || "unknown");
-      printf("| %-30s ", $hash_ref->{$key}->{hostname}|| "unknown");
-      printf("| %-25s ", $hash_ref->{$key}->{service} || "unknown");
-      printf("| %-13s ", $hash_ref->{$key}->{"count(*)"} || "unknown");
-      printf("| %-20s |\n", $hash_ref->{$key}->{"max(received)"} || "unknown");
-    }
+  foreach my $key (sort {$a<=>$b} keys %$hash_ref) {
+    printf("| %-10s ", $hash_ref->{$key}->{client_id} || "unknown");
+    printf("| %-30s ", $hash_ref->{$key}->{hostname}|| "unknown");
+    printf("| %-25s ", $hash_ref->{$key}->{service} || "unknown");
+    printf("| %-13s ", $hash_ref->{$key}->{"count(*)"} || "unknown");
+    printf("| %-20s |\n", $hash_ref->{$key}->{"max(received)"} || "unknown");
+  }
   print "+----------------------------------------------------------------------------------------------------------------+\n";
   print "\n";
 }
diff --git a/src/warden-server/bin/registerReceiver.pl b/src/warden-server/bin/registerReceiver.pl
index cada6e2..3c95297 100755
--- a/src/warden-server/bin/registerReceiver.pl
+++ b/src/warden-server/bin/registerReceiver.pl
@@ -2,7 +2,7 @@
 #
 # registerReceiver.pl
 #
-# Copyright (C) 2011-2012 Cesnet z.s.p.o
+# Copyright (C) 2011-2013 Cesnet z.s.p.o
 #
 # Use of this source is governed by a BSD-style license, see LICENSE file.
 
@@ -10,16 +10,26 @@ use strict;
 use Getopt::Std;
 use Switch;
 use File::Basename;
+use DBI;
+use DBD::mysql;
+use DateTime;
+use Sys::Syslog qw(:DEFAULT setlogsock);
+Sys::Syslog::setlogsock('unix');
+use Carp;
 
-our $VERSION = "2.0";
 
-my $warden_path = '/opt/warden-server';
-require $warden_path . '/lib/WardenReg.pm';
+
+################################################################################
+#				GLOBAL VARIABLES
+################################################################################
+our $VERSION = "2.2";
 my $filename = basename($0);
 
-#-------------------------------------------------------------------------------
+
+
+################################################################################
 #                               Functions
-#-------------------------------------------------------------------------------
+################################################################################
 sub usage {
   print "Usage: $filename [-h -o -n <hostname> -r <requestor> -t <type> -i <ip_net_client>]\n";
   exit 1;
@@ -63,8 +73,33 @@ sub trim
 
 
 #-------------------------------------------------------------------------------
-#                               MAIN
+# sendMsg - sent message to syslog (SYS::Syslog)
 #-------------------------------------------------------------------------------
+sub sendMsg
+{
+  my $syslog		= shift;
+  my $syslog_verbose	= shift;
+  my $syslog_facility	= shift;
+  my $severity          = shift;
+  my $syslog_msg        = shift;
+  my $filename          = File::Basename::basename($0);
+
+  if ($syslog_verbose == 1 && ($severity eq "err" || $severity eq "debug")) {
+    $syslog_msg .= "\nStack info: " . Carp::longmess();
+  }
+
+  if ($syslog == 1 && defined $severity && defined $syslog_msg) {
+    Sys::Syslog::openlog($filename, "cons,pid", $syslog_facility);
+    Sys::Syslog::syslog("$severity", "$syslog_msg");
+    Sys::Syslog::closelog();
+  }
+} # End of sendMsg
+
+
+
+################################################################################
+#                               MAIN
+################################################################################
 our ($opt_n, $opt_r, $opt_t, $opt_o, $opt_i, $opt_h);
 
 if ($#ARGV == -1) {usage}
@@ -87,7 +122,7 @@ if ($help) {
 }
 
 if ($ip_net_client !~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(\d|[1-2]\d|3[0-2]))$/) {
-    die errMsg("Enter correct IP in CIDR format!");
+    die "Enter correct IP address in CIDR format!";
 }
 
 # superuser controle
@@ -103,7 +138,56 @@ switch () {
   case {!defined $ip_net_client} { print "ERROR: Parameter 'ip_net_client' is not defined!\n"; exit 1; }
 }
 
-my $return = WardenReg::registerReceiver($warden_path, $hostname, $requestor, $type, $receive_own_events, $ip_net_client);
-$return ? print "Registration of $hostname was SUCCESSFUL...\n" : print "Registration of $hostname FAILED!\n";
+# defined variables by script
+my $client_type             = "r";
+my $registered              = DateTime->now;
+my $service                 = undef;
+my $description_tags        = undef;
+
+
+# read config file
+my $conf_file = "/opt/warden-server/etc/warden-server.conf"; # path is updated by install.sh
+our $SYSLOG             = undef;
+our $SYSLOG_VERBOSE     = undef;
+our $SYSLOG_FACILITY    = undef;
+our $DB_NAME            = undef;
+our $DB_USER            = undef;
+our $DB_PASS            = undef;
+our $DB_HOST            = undef;
+unless (do $conf_file) {
+  die("Errors in config file '$conf_file': $@") if $@;
+  die("Can't read config file '$conf_file': $!") unless defined $_;
+  # if $_ defined, it's retvalue of last statement of conf, for which we don't care
+}
 
-exit 0;
+# connect to DB
+our $DBH = DBI->connect("DBI:mysql:database=$DB_NAME;host=$DB_HOST", $DB_USER, $DB_PASS, {RaiseError => 1, mysql_auto_reconnect => 1}) || die "Could not connect to database: $DBH->errstr";
+
+# check if receiver has been already registered or register it
+my $sth = $DBH->prepare("SELECT registered FROM clients WHERE hostname = ? AND client_type = ? AND type = ? AND ip_net_client = ? LIMIT 1;") or die "Cannot prepare statement: " . $DBH->errstr;
+$sth->execute($hostname, $client_type, $type, $ip_net_client) or die "Cannot execute statement: " . $sth->errstr;
+my $result = $sth->fetchrow();
+my $warden_server = trim(`hostname -f`);
+if (defined $result) {
+  sendMsg($SYSLOG,
+          $SYSLOG_VERBOSE,
+          $SYSLOG_FACILITY,
+          "info",
+          "Attempt to re-register the receiver [hostname: '$hostname', type: '$type', cidr: '$ip_net_client']");
+  errMsg("Receiver has already been registered at $warden_server in '$result'");
+} else {
+  $sth = $DBH->prepare("INSERT INTO clients VALUES (?,?,?,?,?,?,?,?,?,?);") or die "Cannot prepare statement: " . $DBH->errstr;
+  my $ret_val = $sth->execute(undef, $hostname, $registered, $requestor, $service, $client_type, $type, $receive_own_events, $description_tags, $ip_net_client) or die "Cannot execute statement: " . $sth->errstr;
+  if ($ret_val == 1) {
+    sendMsg($SYSLOG,
+	    $SYSLOG_VERBOSE,
+	    $SYSLOG_FACILITY,
+            "info",
+            "New receiver [hostname: '$hostname', type: '$type', cidr: '$ip_net_client'] was registered");
+    print "Registration of receiver from $hostname was SUCCESSFUL!!!\n";
+    exit 0;
+  } else {
+    print "Registration of receiver from $hostname FAILED!!!\n";
+    exit 1;
+  }
+}
diff --git a/src/warden-server/bin/registerSender.pl b/src/warden-server/bin/registerSender.pl
index da34a2d..03a2660 100755
--- a/src/warden-server/bin/registerSender.pl
+++ b/src/warden-server/bin/registerSender.pl
@@ -10,21 +10,32 @@ use strict;
 use Getopt::Std;
 use Switch;
 use File::Basename;
+use DBI;
+use DBD::mysql;
+use DateTime;
+use Sys::Syslog qw(:DEFAULT setlogsock);
+Sys::Syslog::setlogsock('unix');
+use Carp;
 
-our $VERSION = "2.0";
 
-my $warden_path = '/opt/warden-server';
-require $warden_path . '/lib/WardenReg.pm';
+
+################################################################################
+#				GLOBAL VARIABLES
+################################################################################
+our $VERSION = "2.2";
 my $filename = basename($0);
 
-#-------------------------------------------------------------------------------
-#				Functions
-#-------------------------------------------------------------------------------
+
+
+################################################################################
+#                               Functions
+################################################################################
 sub usage {
   print "Usage: $filename [-h -n <hostname> -r <requestor> -s <service> -d <description_tags> -i <ip_net_client>]\n";
   exit 1;
 }
 
+
 sub help {
   print "$filename [-h -n <hostname> -r <requestor> -s <service> -d <description_tags> -i <ip_net_client>]\n";
   print "-h 	print this text and exit\n";
@@ -62,8 +73,33 @@ sub trim
 
 
 #-------------------------------------------------------------------------------
-#				MAIN
+# sendMsg - sent message to syslog (SYS::Syslog)
 #-------------------------------------------------------------------------------
+sub sendMsg
+{
+  my $syslog		= shift;
+  my $syslog_verbose	= shift;
+  my $syslog_facility	= shift;
+  my $severity          = shift;
+  my $syslog_msg        = shift;
+  my $filename          = File::Basename::basename($0);
+
+  if ($syslog_verbose == 1 && ($severity eq "err" || $severity eq "debug")) {
+    $syslog_msg .= "\nStack info: " . Carp::longmess();
+  }
+
+  if ($syslog == 1 && defined $severity && defined $syslog_msg) {
+    Sys::Syslog::openlog($filename, "cons,pid", $syslog_facility);
+    Sys::Syslog::syslog("$severity", "$syslog_msg");
+    Sys::Syslog::closelog();
+  }
+} # End of sendMsg
+
+
+
+################################################################################
+#                               MAIN
+################################################################################
 our ($opt_n, $opt_r, $opt_s, $opt_d, $opt_i, $opt_h);
 
 if ($#ARGV == -1) {usage}
@@ -98,8 +134,55 @@ switch () {
   case {!defined $ip_net_client} { print "ERROR: Parameter 'ip_net_client' is not defined!\n"; exit 1; }
 }
 
-# register sender at warden server
-my $return = WardenReg::registerSender($warden_path, $hostname, $requestor, $service, $description_tags, $ip_net_client);
-$return ? print "Registration of $hostname was SUCCESSFUL...\n" : print "Registration of $hostname FAILED!\n";
+# defined variables by method
+my $client_type             = "s";
+my $registered              = DateTime->now;
+my $type                    = undef;
+my $receive_own_events      = undef;
+
+# read config file
+my $conf_file = "/opt/warden-server/etc/warden-server.conf"; # path is updated by install.sh
+our $SYSLOG             = undef;
+our $SYSLOG_VERBOSE     = undef;
+our $SYSLOG_FACILITY    = undef;
+our $DB_NAME            = undef;
+our $DB_USER            = undef;
+our $DB_PASS            = undef;
+our $DB_HOST            = undef;
+unless (do $conf_file) {
+  die("Errors in config file '$conf_file': $@") if $@;
+  die("Can't read config file '$conf_file': $!") unless defined $_;
+  # if $_ defined, it's retvalue of last statement of conf, for which we don't care
+}
 
-exit 0;
+# connect to DB
+our $DBH = DBI->connect("DBI:mysql:database=$DB_NAME;host=$DB_HOST", $DB_USER, $DB_PASS, {RaiseError => 1, mysql_auto_reconnect => 1}) || die "Could not connect to database: $DBH->errstr";
+
+# check if receiver has been already registered or register it
+my $sth = $DBH->prepare("SELECT registered FROM clients WHERE hostname = ? AND service = ? AND client_type = ? AND ip_net_client = ? LIMIT 1;") or die "Cannot prepare statement: " . $DBH->errstr;
+$sth->execute($hostname, $service, $client_type, $ip_net_client) or die "Cannot execute statement: " . $sth->errstr;
+my $result = $sth->fetchrow();
+my $warden_server = trim(`hostname -f`);
+if (defined $result) {
+  sendMsg($SYSLOG,
+          $SYSLOG_VERBOSE,
+          $SYSLOG_FACILITY,
+          "info",
+          "Attempt to re-register the sender [hostname: '$hostname', service: '$service', cidr: '$ip_net_client']");
+  errMsg("Sender has already been registered at $warden_server in '$result'");
+} else {
+  $sth = $DBH->prepare("INSERT INTO clients VALUES (?,?,?,?,?,?,?,?,?,?);") or die "Cannot prepare statement: " . $DBH->errstr;
+  my $ret_val = $sth->execute(undef, $hostname, $registered, $requestor, $service, $client_type, $type, $receive_own_events, $description_tags, $ip_net_client) or die "Cannot execute statement: " . $sth->errstr;
+  if ($ret_val == 1) {
+    sendMsg($SYSLOG,
+	    $SYSLOG_VERBOSE,
+	    $SYSLOG_FACILITY,
+            "info",
+            "New sender [hostname: '$hostname', service: '$service', cidr: '$ip_net_client'] was registered");
+    print "Registration of sender from $hostname was SUCCESSFUL!!!\n";
+    exit 0;
+  } else {
+    print "Registration of sender from $hostname FAILED!!!\n";
+    exit 1;
+  }
+}
diff --git a/src/warden-server/bin/unregisterClient.pl b/src/warden-server/bin/unregisterClient.pl
index f054b40..323ce7d 100755
--- a/src/warden-server/bin/unregisterClient.pl
+++ b/src/warden-server/bin/unregisterClient.pl
@@ -10,16 +10,26 @@ use strict;
 use Getopt::Std;
 use Switch;
 use File::Basename;
+use DBI;
+use DBD::mysql;
+use DateTime;
+use Sys::Syslog qw(:DEFAULT setlogsock);
+Sys::Syslog::setlogsock('unix');
+use Carp;
 
-our $VERSION = "2.0";
 
-my $warden_path = '/opt/warden-server';
-require $warden_path . '/lib/WardenReg.pm';
+
+################################################################################
+#				GLOBAL VARIABLES
+################################################################################
+our $VERSION = "2.2";
 my $filename = basename($0);
 
-#-------------------------------------------------------------------------------
+
+
+################################################################################
 #                               Functions
-#-------------------------------------------------------------------------------
+################################################################################
 sub usage {
   print "Usage: $filename [-h -i <client_id>]\n";
   exit 1;
@@ -57,6 +67,31 @@ sub trim
 } # End of trim
 
 
+#-------------------------------------------------------------------------------
+# sendMsg - sent message to syslog (SYS::Syslog)
+#-------------------------------------------------------------------------------
+sub sendMsg
+{
+  my $syslog		= shift;
+  my $syslog_verbose	= shift;
+  my $syslog_facility	= shift;
+  my $severity          = shift;
+  my $syslog_msg        = shift;
+  my $filename          = File::Basename::basename($0);
+
+  if ($syslog_verbose == 1 && ($severity eq "err" || $severity eq "debug")) {
+    $syslog_msg .= "\nStack info: " . Carp::longmess();
+  }
+
+  if ($syslog == 1 && defined $severity && defined $syslog_msg) {
+    Sys::Syslog::openlog($filename, "cons,pid", $syslog_facility);
+    Sys::Syslog::syslog("$severity", "$syslog_msg");
+    Sys::Syslog::closelog();
+  }
+} # End of sendMsg
+
+
+
 #-------------------------------------------------------------------------------
 #                               MAIN
 #-------------------------------------------------------------------------------
@@ -83,7 +118,70 @@ if (!defined $client_id) {
   exit 1;
 }
 
-my $return = WardenReg::unregisterClient($warden_path, $client_id);
-$return ? print "Unregistration of client (#$client_id) was SUCCESSFUL...\n" : print "Unregistration of client (# $client_id) FAILED!\n";
+# read config file
+my $conf_file = "/opt/warden-server/etc/warden-server.conf"; # path is updated by install.sh
+our $SYSLOG             = undef;
+our $SYSLOG_VERBOSE     = undef;
+our $SYSLOG_FACILITY    = undef;
+our $DB_NAME            = undef;
+our $DB_USER            = undef;
+our $DB_PASS            = undef;
+our $DB_HOST            = undef;
+unless (do $conf_file) {
+  die("Errors in config file '$conf_file': $@") if $@;
+  die("Can't read config file '$conf_file': $!") unless defined $_;
+  # if $_ defined, it's retvalue of last statement of conf, for which we don't care
+}
 
-exit 0;
+# connect to DB
+our $DBH = DBI->connect("DBI:mysql:database=$DB_NAME;host=$DB_HOST", $DB_USER, $DB_PASS, {RaiseError => 1, mysql_auto_reconnect => 1}) || die "Could not connect to database: $DBH->errstr";
+
+# check if receiver has been already registered
+my $sth = $DBH->prepare("SELECT client_id, hostname, service, client_type, type FROM clients WHERE client_id = ? LIMIT 1;") or die "Cannot prepare statement: " . $DBH->errstr;
+$sth->execute($client_id) or die "Cannot execute statement: " . $sth->errstr;
+my ($id, $hostname, $service, $client_type, $type) = $sth->fetchrow();
+my $warden_server = trim(`hostname -f`);
+
+# delete registered client
+if (!defined $id) {
+  sendMsg($SYSLOG,
+          $SYSLOG_VERBOSE,
+          $SYSLOG_FACILITY,
+          "err",
+          "Attempt to delete unregister client (client_id: #$client_id)");
+  errMsg("Client (#$client_id) is not registered at $warden_server");
+} else {
+  if ($client_type eq 's') {
+    $sth = $DBH->prepare("DELETE FROM clients WHERE client_id = ?;") or die "Cannot prepare statement: " . $DBH->errstr;
+    my $ret_val = $sth->execute($client_id) or die "Cannot execute statement: " . $sth->errstr;
+    if ($ret_val == 1) {
+      $sth = $DBH->prepare("UPDATE events SET valid = 'f' where hostname = ? AND service = ?;") or die "Cannot prepare statement: " . $DBH->errstr;
+      $sth->execute($hostname, $service) or die "Cannot execute statement: " . $sth->errstr;
+      sendMsg($SYSLOG,
+              $SYSLOG_VERBOSE,
+              $SYSLOG_FACILITY,
+              "info",
+              "Sender '$hostname' [client_id: '$client_id', service: '$service'] was deleted and its data were invalidated from $warden_server");
+      print "Unregistration of sender client (client_id: #$client_id) was SUCCESSFUL!!!\n";
+      exit 0;
+    } else {
+      print "Unregistration of sender client (client_id: #$client_id) FAILED!!!\n";
+      exit 1;
+    }
+  } else {
+    $sth = $DBH->prepare("DELETE FROM clients WHERE client_id = ?;") or die "Cannot prepare statement: " . $DBH->errstr;
+    my $ret_val = $sth->execute($client_id) or die "Cannot execute statement: " . $sth->errstr;
+    if ($ret_val == 1) {
+      sendMsg($SYSLOG,
+              $SYSLOG_VERBOSE,
+              $SYSLOG_FACILITY,
+              "info",
+              "Receiver '$hostname' [client_id: '$client_id', type: '$type'] was deleted from $warden_server");
+      print "Unregistration of receiver client (client_id: #$client_id) was SUCCESSFUL!!!\n";
+      exit 0;
+    } else {
+      print "Unregistration of receiver client (client_id: #$client_id) FAILED!!!\n";
+      exit 1;
+    }
+  }
+}
diff --git a/src/warden-server/etc/warden-client.conf b/src/warden-server/etc/warden-client.conf
deleted file mode 100644
index 9992d58..0000000
--- a/src/warden-server/etc/warden-client.conf
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-# warden-client.conf - configuration file for the warden sender/receiver client
-#
-
-#-------------------------------------------------------------------------------
-# URI - URI address of Warden server
-#-------------------------------------------------------------------------------
-$URI = "https://warden-c.cesnet.cz:443/Warden";
-
-#-------------------------------------------------------------------------------
-# SSL_KEY_FILE - path to client SSL certificate key file
-#-------------------------------------------------------------------------------
-$SSL_KEY_FILE = "/etc/ssl/private/warden-c.cesnet.cz.key";
-
-#-------------------------------------------------------------------------------
-# SSL_CERT_FILE - path to client SSL certificate file
-#-------------------------------------------------------------------------------
-$SSL_CERT_FILE = "/etc/ssl/certs/warden-c.cesnet.cz.pem";
-
-#-------------------------------------------------------------------------------
-# SSL_CA_FILE - path to CA certificate file
-#-------------------------------------------------------------------------------
-$SSL_CA_FILE = "/etc/ssl/certs/tcs-ca-bundle.pem";
diff --git a/src/warden-server/lib/Warden.pm b/src/warden-server/lib/Warden.pm
index 2b064d3..6ac8aec 100755
--- a/src/warden-server/lib/Warden.pm
+++ b/src/warden-server/lib/Warden.pm
@@ -423,213 +423,6 @@ sub getLastId
 } # END of getLastID
 
 
-#-----------------------------------------------------------------------------
-# registerSender - register new sender
-#-----------------------------------------------------------------------------
-sub registerSender
-{
-  my ($class, $data) = @_;
-  my $sth;
-
-  # client network information
-  my $cn = $ENV{'SSL_CLIENT_S_DN_CN'};
-  my $ip = $ENV{'REMOTE_ADDR'};
-  my $local_ip = $ENV{'SERVER_ADDR'};
-
-  my $function_name = 'registerSender';
-
-  if ($local_ip ne $ip) {
-    sendMsg("err",
-           "Unauthorized access to function '$function_name' from: '$ip' ('$cn') - access allowed only from localhost",
-           "Access denied - access allowed only from localhost");
-  } else {
-    # defined variables by method
-    my $client_type 		= "s";
-    my $registered 		= DateTime->now;
-    my $type			= undef;
-    my $receive_own_events	= undef;
-
-    # parse SOAP data oject
-    my $hostname		= $data->{'HOSTNAME'};
-    my $requestor		= $data->{'REQUESTOR'};
-    my $service			= $data->{'SERVICE'};
-    my $description_tags	= $data->{'DESCRIPTION_TAGS'};
-    my $ip_net_client		= $data->{'IP_NET_CLIENT'};
-
-    # check if sender has been already registered
-    $sth = $DBH->prepare("SELECT registered FROM clients WHERE hostname = ? AND service = ? AND client_type = ? AND ip_net_client = ? LIMIT 1;");
-    if (!defined $sth) {
-      sendMsg("err",
-             "Cannot prepare statement in function '$function_name': $DBH->errstr",
-             "Internal 'prepare' server error");
-    }
-    $sth->execute($hostname, $service, $client_type, $ip_net_client);
-    my $result = $sth->fetchrow();
-
-    # register new sender
-    if (defined $result) {
-      sendMsg("err",
-             "Attempt to re-register the sender: {hostname: '$hostname', service: '$service', cidr: '$ip_net_client'}",
-             "Sender has been already registered at $ENV{'SERVER_NAME'} in '$result'");
-    } else {
-      $sth = $DBH->prepare("INSERT INTO clients VALUES (?,?,?,?,?,?,?,?,?,?);");
-      if (!defined $sth) {
-        sendMsg("err",
-	       "Cannot prepare statement in function '$function_name': $DBH->errstr",
-	       "Internal 'prepare' server error");
-      }
-      $sth->execute(undef, $hostname, $registered, $requestor, $service, $client_type, $type, $receive_own_events, $description_tags, $ip_net_client);
-        sendMsg("info",
-	       "New sender '$hostname' {service: '$service', cidr: '$ip_net_client'} was registered at $ENV{'SERVER_NAME'}",
-	        undef);
-      return 1;
-    }
-  }
-} # END of registerSender
-
-
-#-----------------------------------------------------------------------------
-# registerReceiver - register new receiver
-#-----------------------------------------------------------------------------
-sub registerReceiver
-{
-  my ($class, $data) = @_;
-  my $sth;
-
-  # client network information 
-  my $cn = $ENV{'SSL_CLIENT_S_DN_CN'};
-  my $ip = $ENV{'REMOTE_ADDR'};
-  my $local_ip = $ENV{'SERVER_ADDR'};
-
-  my $function_name = 'registerReceiver';
-
-  if ($local_ip ne $ip) {
-    sendMsg("err",
-           "Unauthorized access to function '$function_name' from: '$ip' ('$cn') - access allowed only from localhost",
-           "Access denied - access allowed only from localhost");
-  } else {
-    # variables defined by method
-    my $client_type		= "r";
-    my $registered 		= DateTime->now;
-    my $service			= undef;
-    my $description_tags	= undef;
-
-    # parse SOAP data oject
-    my $hostname		= $data->{'HOSTNAME'};
-    my $requestor		= $data->{'REQUESTOR'};
-    my $type			= $data->{'TYPE'};
-    my $receive_own_events	= $data->{'RECEIVE_OWN_EVENTS'};
-    my $ip_net_client		= $data->{'IP_NET_CLIENT'};
-
-    # check if receiver has been already registered
-    $sth = $DBH->prepare("SELECT registered FROM clients WHERE hostname = ? AND client_type = ? AND type = ? AND ip_net_client = ? LIMIT 1;");
-    if (!defined $sth) {
-      sendMsg("err",
-             "Cannot prepare statement in function '$function_name': $DBH->errstr",
-	     "Internal 'prepare' server error");
-    }
-    $sth->execute($hostname, $client_type, $type, $ip_net_client);
-    my $result = $sth->fetchrow();
-
-    # register new receiver
-    if (defined $result) {
-      sendMsg("err",
-             "Attempt to re-register the receiver: {hostname: '$hostname', type: '$type', cidr: '$ip_net_client'}",
-             "Receiver has already been registered at $ENV{'SERVER_NAME'} in '$result'");
-    } else {
-      $sth = $DBH->prepare("INSERT INTO clients VALUES (?,?,?,?,?,?,?,?,?,?);");
-      if (!defined($sth)) {
-        sendMsg("err",
-	       "Cannot prepare statement in function '$function_name': $DBH->errstr",
-	       "Internal 'prepare' server error");
-      }
-      $sth->execute(undef, $hostname, $registered, $requestor, $service, $client_type, $type, $receive_own_events, $description_tags, $ip_net_client);
-      sendMsg("info",
-             "New receiver '$hostname' {type: '$type', cidr: '$ip_net_client'} was registered at $ENV{'SERVER_NAME'}",
-	      undef);
-      return 1;
-    }
-  }
-} # END of registerReceiver
-
-
-#-----------------------------------------------------------------------------
-# unregisterClient - unregister client
-#-----------------------------------------------------------------------------
-sub unregisterClient
-{
-  my ($class, $data) = @_;
-  my $sth;
-
-  # client network information
-  my $cn = $ENV{'SSL_CLIENT_S_DN_CN'};
-  my $ip = $ENV{'REMOTE_ADDR'};
-  my $local_ip = $ENV{'SERVER_ADDR'};
-
-  my $function_name = 'unregisterClient';
-
-  if ($local_ip ne $ip) {
-    sendMsg("err",
-           "Unauthorized access to function '$function_name' from: '$ip' ('$cn') - access allowed only from localhost",
-           "Access denied - access allowed only from localhost");
-  } else {
-    # parse SOAP data oject
-    my $client_id	= $data->{'CLIENT_ID'};
-
-    # check if receiver has been already registered
-    $sth = $DBH->prepare("SELECT client_id, hostname, service, client_type FROM clients WHERE client_id = ? LIMIT 1;");
-    if (!defined $sth) {
-      sendMsg("err",
-             "Cannot prepare statement in function '$function_name': $DBH->errstr",
-	     "Internal 'prepare' server error");
-    }
-    $sth->execute($client_id);
-    my ($id, $hostname, $service, $client_type) = $sth->fetchrow();
-
-    # delete registered client
-    if (!defined $id) {
-      sendMsg("err",
-             "Attempt to delete unregister client '$id', '$hostname', '$service', '$client_type'",
-             "Client (#$client_id) is not registered at $ENV{'SERVER_NAME'}");
-    } else {
-      if ($client_type eq 's') {
-        $sth = $DBH->prepare("DELETE FROM clients WHERE client_id = ?;");
-        if (!defined $sth) {
-          sendMsg("err",
-	         "Cannot prepare statement in function '$function_name': $DBH->errstr",
-		 "Internal 'prepare' server error");
-	}
-        $sth->execute($client_id);
-
-        $sth = $DBH->prepare("UPDATE events SET valid = 'f' where hostname = ? AND service = ?;");
-        if (!defined $sth) {
-          sendMsg("err",
-	         "Cannot prepare statement in function '$function_name': $DBH->errstr",
-		 "Internal 'prepare' server error");
-	}
-	$sth->execute($hostname, $service);
-        sendMsg("info",
-	       "Sender '$hostname' (client_id: '$client_id', service: '$service') was deleted and its data were invalidated",
-	       undef);
-        return 1;
-      } else {
-        $sth = $DBH->prepare("DELETE FROM clients WHERE client_id = ?;");
-        if (!defined $sth) {
-	  sendMsg("err",
-	         "Cannot prepare statement in function '$function_name': $DBH->errstr",
-		 "Internal 'prepare' server error");
-	}
-	$sth->execute($client_id);
-        sendMsg("info",
-	       "Receiver '$hostname' (client_id: '$client_id') was deleted from $ENV{'SERVER_NAME'}",
-	        undef);
-        return 1;
-      }
-    }
-  }
-} # END of unregisterClient
-
-
 #-------------------------------------------------------------------------------
 # getClientInfo - get list of registered clients on Warden server
 #		  by Warden client
diff --git a/src/warden-server/lib/WardenReg.pm b/src/warden-server/lib/WardenReg.pm
deleted file mode 100755
index 39aa743..0000000
--- a/src/warden-server/lib/WardenReg.pm
+++ /dev/null
@@ -1,170 +0,0 @@
-#!/usr/bin/perl -w
-#
-# WardenReg.pm
-#
-# Copyright (C) 2011-2012 Cesnet z.s.p.o
-#
-# Use of this source is governed by a BSD-style license, see LICENSE file.
-
-package WardenReg;
-
-use strict;
-use SOAP::Lite;
-use IO::Socket::SSL qw(debug1);
-use SOAP::Transport::HTTP;
-
-our $VERSION = "2.0";
-
-
-#-------------------------------------------------------------------------------
-# errMsg - print error message and die
-#-------------------------------------------------------------------------------
-sub errMsg
-{
-  my $msg = shift;
-  die($msg . "\n");
-} # End of errMsg
-
-
-#-------------------------------------------------------------------------------
-# c2s - connect to server, send request and receive response
-#-------------------------------------------------------------------------------
-sub c2s 
-{
-  my $uri               = shift;
-  my $ssl_key_file      = shift;
-  my $ssl_cert_file     = shift;
-  my $ssl_ca_file       = shift;
-  my $method            = shift;
-  my $data              = shift;
-  my $client;
-
-  my ($server, $port, $service) = $uri =~ /https:\/\/(.+)\:(\d+)\/(.+)/;
-  if (!($client = SOAP::Transport::HTTP::Client->new())) {
-    errMsg("Sorry, unable to create socket: " . &SOAP::Transport::HTTP::Client::errstr)
-  }
-  $client->timeout(10);
-  $client->ssl_opts(    verify_hostname     => 1,
-                        SSL_use_cert        => 1,
-                        SSL_verify_mode     => 0x02,
-                        SSL_key_file        => $ssl_key_file,
-                        SSL_cert_file       => $ssl_cert_file,
-                        SSL_ca_file         => $ssl_ca_file);
-
-  # set URI and serialize SOAP envelope and data object
-  my $soap     = SOAP::Lite->uri($service)->proxy($uri);
-  my $envelope = $soap->serializer->envelope(method => $method, $data);
-
-  # set URI and send serialized SOAP envelope and data
-  my $server_uri = "https://$server:$port/$service";
-  my $result = $client->send_receive(envelope => $envelope, endpoint => $server_uri);
-
-  # check server response
-  if (!defined $result) {
-    errMsg("Error: server returned empty response." . "\n" . "Problem with used SSL ceritificates or Warden server at $server:$port is down.");
-  } else {
-    # deserialized response from server -> create SOAP envelope and data object
-    my $response = $soap->deserializer->deserialize($result);
-    # check SOAP fault status
-    $response->fault ? errMsg("Server sent error message:: " . $response->faultstring) : return 1;
-  }
-}
-
-
-#-------------------------------------------------------------------------------
-# registerSender - register new warden sender
-#-------------------------------------------------------------------------------
-sub registerSender
-{
-  my $warden_path	= shift;
-  my $hostname		= shift;
-  my $requestor		= shift;
-  my $service		= shift;
-  my $description_tags	= shift;
-  my $ip_net_client	= shift;
-
-  my $etcdir = $warden_path . "/etc/";
-  my $libdir = $warden_path . "/lib/";
-
-  # read the config file
-  require $libdir .  "WardenConf.pm";
-  my $conf_file = $etcdir . "warden-client.conf";
-  my ($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file) = WardenConf::loadConf($conf_file);
-
-  # create SOAP data obejct
-  my $request_data = SOAP::Data->name(client => \SOAP::Data->value(
-    SOAP::Data->name(HOSTNAME 		=> $hostname),
-    SOAP::Data->name(REQUESTOR		=> $requestor),
-    SOAP::Data->name(SERVICE		=> $service),
-    SOAP::Data->name(DESCRIPTION_TAGS	=> $description_tags),
-    SOAP::Data->name(IP_NET_CLIENT	=> $ip_net_client)
-  ));
-
-  my $result = c2s($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file, "registerSender", $request_data);
-  $result ? return 1 : return 0;
-
-} # End of registerSender
-
-
-#-------------------------------------------------------------------------------
-# registerReceiver - register new warden receiver
-#-------------------------------------------------------------------------------
-sub registerReceiver
-{
-  my $warden_path		= shift;
-  my $hostname			= shift;
-  my $requestor			= shift;
-  my $type			= shift;
-  my $receive_own_events	= shift;
-  my $ip_net_client		= shift;
-
-  my $etcdir = $warden_path . "/etc/";
-  my $libdir = $warden_path . "/lib/";
-
-  # read the config file
-  require $libdir .  "WardenConf.pm";
-  my $conf_file = $etcdir . "warden-client.conf";
-  my ($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file) = WardenConf::loadConf($conf_file);
-
-  # create SOAP data obejct
-  my $request_data = SOAP::Data->name(client => \SOAP::Data->value(
-    SOAP::Data->name(HOSTNAME 		=> $hostname),
-    SOAP::Data->name(REQUESTOR		=> $requestor),
-    SOAP::Data->name(TYPE		=> $type),
-    SOAP::Data->name(RECEIVE_OWN_EVENTS	=> $receive_own_events),
-    SOAP::Data->name(IP_NET_CLIENT	=> $ip_net_client)
-  ));
-
-  my $result = c2s($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file, "registerReceiver", $request_data);
-  $result ? return 1 : return 0;
-
-} # End of registerReceiver
-
-
-#-------------------------------------------------------------------------------
-# unregisterClient - unregister client from warden server
-#-------------------------------------------------------------------------------
-sub unregisterClient
-{
-  my $warden_path	= shift;
-  my $client_id		= shift;
-
-  my $etcdir = $warden_path . "/etc/";
-  my $libdir = $warden_path . "/lib/";
-
-  # read the config file
-  require $libdir .  "WardenConf.pm";
-  my $conf_file = $etcdir . "warden-client.conf";
-  my ($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file) = WardenConf::loadConf($conf_file);
-
-  # create SOAP data obejct
-  my $request_data = SOAP::Data->name(client => \SOAP::Data->value(
-    SOAP::Data->name(CLIENT_ID => $client_id)
-  ));
-
-  my $result = c2s($uri, $ssl_key_file, $ssl_cert_file, $ssl_ca_file, "unregisterClient", $request_data);
-  $result ? return 1 : return 0;
-
-} # End of unregisterClient
-
-1;
-- 
GitLab