Skip to content
Snippets Groups Projects
Commit 0e0982f1 authored by Tomáš Plesník's avatar Tomáš Plesník
Browse files

pridana nova funkce getClientInfo, pridana autorizace v getLastId, autorizacni...

pridana nova funkce getClientInfo, pridana autorizace v getLastId, autorizacni proces vraci i client_id
parent 960cd361
No related branches found
No related tags found
No related merge requests found
...@@ -123,26 +123,39 @@ sub authorizeClient ...@@ -123,26 +123,39 @@ sub authorizeClient
# obtain cidr based on rigth common name and alternate names, service and client_type # obtain cidr based on rigth common name and alternate names, service and client_type
if($function_name eq 'saveNewEvent') { if($function_name eq 'saveNewEvent') {
$sth = $DBH->prepare("SELECT hostname, ip_net_client, receive_own_events FROM clients WHERE hostname IN ($alt_names) AND service = ? AND client_type = ? ORDER BY SUBSTRING_INDEX(ip_net_client,'/', -1) DESC;"); $sth = $DBH->prepare("SELECT client_id, hostname, ip_net_client, receive_own_events FROM clients WHERE hostname IN ($alt_names) AND service = ? AND client_type = ? ORDER BY SUBSTRING_INDEX(ip_net_client,'/', -1) DESC;");
} elsif($function_name eq 'getNewEvents') { } elsif($function_name eq 'getNewEvents') {
$sth = $DBH->prepare("SELECT hostname, ip_net_client, receive_own_events FROM clients WHERE hostname IN ($alt_names) AND (type = ? OR type = '_any_') AND client_type = ? ORDER BY SUBSTRING_INDEX(ip_net_client,'/', -1) DESC;"); $sth = $DBH->prepare("SELECT client_id, hostname, ip_net_client, receive_own_events FROM clients WHERE hostname IN ($alt_names) AND (type = ? OR type = '_any_') AND client_type = ? ORDER BY SUBSTRING_INDEX(ip_net_client,'/', -1) DESC;");
} } elsif($function_name eq 'getClientInfo') {
$sth = $DBH->prepare("SELECT client_id, hostname, ip_net_client, receive_own_events FROM clients WHERE hostname IN ($alt_names) ORDER BY SUBSTRING_INDEX(ip_net_client,'/', -1) DESC;");
} elsif($function_name eq 'getLastId') {
$sth = $DBH->prepare("SELECT client_id, hostname, ip_net_client, receive_own_events FROM clients WHERE hostname IN ($alt_names) AND client_type = 'r' ORDER BY SUBSTRING_INDEX(ip_net_client,'/', -1) DESC;");
}
# check db handler
if (!defined $sth) { if (!defined $sth) {
sendMsg("err", sendMsg("err",
"Cannot prepare authorization statement in $function_name: $DBH->errstr", "Cannot prepare authorization statement in $function_name: $DBH->errstr",
"Internal 'prepare' server error") "Internal 'prepare' server error")
} }
$sth->execute($service_type, $client_type);
my ($an, $cidr, $receive_own, $cidr_list); # execute query for two or none params functions
if ($function_name eq 'saveNewEvent' || $function_name eq 'getNewEvents') {
$sth->execute($service_type, $client_type);
} else {
$sth->execute;
}
# obtain registration info about clients
my ($client_id, $an, $cidr, $receive_own, $cidr_list);
my $correct_ip_source = 0; my $correct_ip_source = 0;
my %ret; my %ret;
while(($an, $cidr, $receive_own) = $sth->fetchrow()) { while(($client_id, $an, $cidr, $receive_own) = $sth->fetchrow()) {
my $cidr_list = Net::CIDR::Lite-> new -> add($cidr); my $cidr_list = Net::CIDR::Lite-> new -> add($cidr);
$ret{'dns'} = $an; $ret{'client_id'} = $client_id;
$ret{'cidr'} = $cidr; $ret{'dns'} = $an;
$ret{'cidr'} = $cidr;
$ret{'receive_own'} = $receive_own; $ret{'receive_own'} = $receive_own;
if ($cidr_list->bin_find($ip)) { if ($cidr_list->bin_find($ip)) {
...@@ -385,18 +398,29 @@ sub getNewEvents ...@@ -385,18 +398,29 @@ sub getNewEvents
sub getLastId sub getLastId
{ {
my ($class, $arg) = @_; my ($class, $arg) = @_;
# client network information
my $cn = $ENV{'SSL_CLIENT_S_DN_CN'};
my $alt_names = getAltNames(undef);
my $ip = $ENV{'REMOTE_ADDR'};
my $service = undef;
my $client_type = undef;
my $function_name = 'getLastId'; my $function_name = 'getLastId';
my $sth = $DBH->prepare("SELECT max(id) FROM events;"); my %client = authorizeClient($alt_names, $ip, $service, $client_type, $function_name);
if ( !defined $sth ) { if (defined %client) {
sendMsg("err", my $sth = $DBH->prepare("SELECT max(id) FROM events;");
"Cannot prepare statement in function '$function_name': $DBH->errstr", if (!defined $sth) {
"Internal 'prepare' server error"); sendMsg("err",
"Cannot prepare statement in function '$function_name': $DBH->errstr",
"Internal 'prepare' server error");
}
$sth->execute;
my $result = $sth->fetchrow();
return $result;
} }
$sth->execute;
my $result = $sth->fetchrow();
return $result;
} # END of getLastID } # END of getLastID
...@@ -816,4 +840,68 @@ sub getStatus ...@@ -816,4 +840,68 @@ sub getStatus
} }
} # END of getStatus } # END of getStatus
#-------------------------------------------------------------------------------
# getClientInfo
#-------------------------------------------------------------------------------
sub getClientInfo
{
my ($class, $data) = @_;
my (@clients, $client);
my ($client_id, $hostname, $registered, $requestor, $service, $client_type, $type, $receive_own_events, $description_tags, $ip_net_client);
# client network information
my $cn = $ENV{'SSL_CLIENT_S_DN_CN'};
my $alt_names = getAltNames(undef);
my $ip = $ENV{'REMOTE_ADDR'};
my $service = undef;
my $client_type = undef;
my $function_name = 'getClientInfo';
my %client = authorizeClient($alt_names, $ip, $service, $client_type, $function_name);
if (defined %client) {
my $sth = $DBH->prepare("SELECT * FROM clients ORDER BY client_id ASC;");
if (!defined $sth) {
sendMsg("err",
"Cannot prepare statement in function '$function_name': $DBH->errstr",
"Internal 'prepare' server error");
}
$sth->execute;
while ( my @result = $sth->fetchrow() ) {
$client_id = $result[0];
$hostname = $result[1];
$registered = $result[2];
$requestor = $result[3];
$service = $result[4];
$client_type = $result[5];
$type = $result[6];
$receive_own_events = $result[7];
$description_tags = $result[8];
$ip_net_client = $result[9];
$client = SOAP::Data->name(client => \SOAP::Data->value(
SOAP::Data->name(CLIENT_ID => $client_id),
SOAP::Data->name(HOSTNAME => $hostname),
SOAP::Data->name(REGISTERED => $registered),
SOAP::Data->name(REQUESTOR => $requestor),
SOAP::Data->name(SERVICE => $service),
SOAP::Data->name(CLIENT_TYPE => $client_type),
SOAP::Data->name(TYPE => $type),
SOAP::Data->name(RECEIVE_OWN_EVENTS => $receive_own_events),
SOAP::Data->name(DESCRIPTION_TAGS => $description_tags),
SOAP::Data->name(IP_NET_CLIENT => $ip_net_client),
));
push(@clients, $client);
}
my $sum = scalar @clients;
sendMsg("info",
"Sending information about '$sum' registered clients from $ENV{'SERVER_NAME'}",
undef);
return @clients;
}
} # END of getClientInfo
1; 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