Skip to content
Snippets Groups Projects
Forked from 713 / Warden / Warden
855 commits behind the upstream repository.
Warden.pm 27.70 KiB
#!/usr/bin/perl -w
#
# Warden.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 Warden;

use strict;
use DBI;
use DBD::mysql;
use Format::Human::Bytes;
use Sys::Syslog qw(:DEFAULT setlogsock);
Sys::Syslog::setlogsock('unix');
use File::Basename;
use Net::CIDR::Lite;
use DateTime;
use MIME::Base64;
use Crypt::X509;

our $VERSION = "2.1";


################################################################################
#			READING OF CONFIGURATION VARIABLES
################################################################################

my $conf_file = "/opt/warden-server/etc/warden-server.conf"; # path is updated by install.sh
our $FACILITY	= undef;
our $DB_NAME	= undef;
our $DB_USER	= undef;
our $DB_PASS	= undef;
our $DB_HOST	= undef;
our $MAX_EVENTS_LIMIT	= undef;
our %VALID_STRINGS	= undef;

# load set variables by user
unless (do $conf_file) {
  errMsg("Errors in config file '$conf_file': $@") if $@;
  errMsg("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
}


################################################################################
#				VARIABLES
################################################################################

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: $DBI::errstr";


################################################################################
#				LOCAL FUNCTIONS
################################################################################

#-------------------------------------------------------------------------------
# errMsg - print error message and die
#-------------------------------------------------------------------------------
sub errMsg
{
  my $msg = shift;
  $msg = trim($msg);
  print $msg . "\n";
  exit 1;
} # End of errMsg


#-------------------------------------------------------------------------------