/usr/share/perl5/Apache/Ocsinventory/Server/Capacities/Notify.pm is in ocsinventory-server 2.0.5-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | ################################################################################
## OCSINVENTORY-NG
## Copyleft Pascal DANEK 2008
## Web : http://www.ocsinventory-ng.org
##
## This code is open source and may be copied and modified as long as the source
## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################
package Apache::Ocsinventory::Server::Capacities::Notify;
use strict;
BEGIN{
if($ENV{'OCS_MODPERL_VERSION'} == 1){
require Apache::Ocsinventory::Server::Modperl1;
Apache::Ocsinventory::Server::Modperl1->import();
}elsif($ENV{'OCS_MODPERL_VERSION'} == 2){
require Apache::Ocsinventory::Server::Modperl2;
Apache::Ocsinventory::Server::Modperl2->import();
}
}
use Apache::Ocsinventory::Server::System;
use Apache::Ocsinventory::Server::Communication;
use Apache::Ocsinventory::Server::Constants;
# Initialize option
push @{$Apache::Ocsinventory::OPTIONS_STRUCTURE},{
'NAME' => 'NOTIFY',
'HANDLER_PROLOG_READ' => undef,
'HANDLER_PROLOG_RESP' => undef,
'HANDLER_PRE_INVENTORY' => undef,
'HANDLER_POST_INVENTORY' => undef,
'REQUEST_NAME' => 'NOTIFY',
'HANDLER_REQUEST' => \¬ify_handler,
'HANDLER_DUPLICATE' => undef,
'TYPE' => OPTION_TYPE_ASYNC,
'XML_PARSER_OPT' => {
'ForceArray' => ['IFACE']
}
};
sub notify_handler{
my $current_context = shift;
if( !$current_context->{EXIST_FL} ){
&_log(322, 'notify', 'no_device');
return APACHE_OK;
}
&_log(322, 'notify', $current_context->{'XML_ENTRY'}->{TYPE});
if( $current_context->{'XML_ENTRY'}->{TYPE} eq 'IP' ){
&update_ip( $current_context );
}
else{
&_log(529, 'notify', 'not_supported');
}
return APACHE_OK;
}
sub update_ip{
# Initialize data
my $current_context = shift;
my $dbh = $current_context->{'DBI_HANDLE'};
my $result = $current_context->{'XML_ENTRY'};
my $hardwareId = $current_context->{'DATABASE_ID'};
my $select_h_sql = 'SELECT IPADDR,MACADDR FROM hardware h,networks n WHERE IPADDR=IPADDRESS AND h.ID=?';
my $updateMainIp_sql = 'UPDATE hardware SET IPADDR=? WHERE ID=?';
# Get default IP
my $sth = $dbh->prepare( $select_h_sql );
$sth->execute( $hardwareId );
my $row = $sth->fetchrow_hashref;
my $defaultIface = $row->{MACADDR};
my $defaultIp = $row->{IPADDR};
$sth->finish;
if( exists $result->{IFACE} ){
for my $newIface ( @{$result->{IFACE}} ){
next if !$newIface->{IP} or !$newIface->{MASK} or !$newIface->{MAC};
my (@update_fields, @update_values);
#We create update request using existing values only
if ($newIface->{GW}) { push @update_fields,'IPGATEWAY=?'; push @update_values,$newIface->{GW}; }
if ($newIface->{DHCP}) { push @update_fields,'IPDHCP=?'; push @update_values,$newIface->{DHCP}; }
if ($newIface->{SUBNET}) { push @update_fields,'IPSUBNET=?'; push @update_values,$newIface->{SUBNET}; }
if ($newIface->{IP}) { push @update_fields,'IPADDRESS=?'; push @update_values,$newIface->{IP}; }
if ($newIface->{MASK}) { push @update_fields,'IPMASK=?'; push @update_values,$newIface->{MASK}; }
push @update_values,$newIface->{MAC};
push @update_values,$hardwareId;
my $updateIp_sql= 'UPDATE networks SET '.(join ',', @update_fields).' WHERE MACADDR=? AND HARDWARE_ID=?';
my $err = $dbh->do( $updateIp_sql, {}, @update_values );
if( !$err ){
&_log(530, 'notify', 'error');
}
elsif( $err==0E0 ){
&_log(324, 'notify', $newIface->{MAC});
}
else{
&_log(323, 'notify', "$newIface->{MAC}<$newIface->{IP}>");
if (exists $result->{HARDWARE}) { #New behaviour with additional <HARDWARE> tag
$dbh->do( $updateMainIp_sql, {}, $result->{HARDWARE}->{IPADDR}, $hardwareId);
} else {
$dbh->do( $updateMainIp_sql, {}, $newIface->{IP}, $hardwareId);
}
}
}
}
}
1;
|