This file is indexed.

/usr/share/perl5/Apache/Ocsinventory/Server/Capacities/Update.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
###############################################################################
## OCSINVENTORY-NG 
## Copyleft Pascal DANEK 2005
## 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::Capacities::Update;

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();
	}
}

require Exporter;

our @ISA = qw /Exporter/;

our @EXPORT = qw //;

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' => 'UPDATE',
	'HANDLER_PROLOG_READ' => undef,
	'HANDLER_PROLOG_RESP' => undef,
	'HANDLER_PRE_INVENTORY' => undef,
	'HANDLER_POST_INVENTORY' => undef,
	'REQUEST_NAME' => 'UPDATE',
	'HANDLER_REQUEST' => \&_update_handler,
	'HANDLER_DUPLICATE' => undef,
	'TYPE' => undef,
	'XML_PARSER_OPT' => {
		'ForceArray' => []
	}
};

# Default
$Apache::Ocsinventory::{OPTIONS}{'OCS_OPT_UPDATE'} = 0;

# To manage the update request
sub _update_handler{
	my $current_context = shift;
	my $dbh = $current_context->{'DBI_HANDLE'};
	my $query = $current_context->{'XML_ENTRY'};

	my %resp;
	my @agent;
	my @dmi;
	my @ipdiscover;
	my $Acurrent;
	my $Dcurrent;
	my $Icurrent;
	my $Iversion;
	my $agent;
	my $dmi;
	my $ip;
	my $platform;
	my $Dversion;
	my $Aversion;
	my $request;
	my $row;

	#Looking for option status
	unless($ENV{'OCS_OPT_UPDATE'}){
		&_send_response({'RESPONSE',['NO_UPDATE']});
		return APACHE_OK;
	}

	# OS type
	$platform = $query->{PLATFORM};
	# Version of the agent
	$Aversion = $query->{AGENT};

	# Eventually, the DMI version
	if(defined($query->{DMI})){$Dversion = $query->{DMI}};
	if(defined($query->{IPDISCOVER})){$Iversion = $query->{IPDISCOVER}};
	if(!defined($Aversion) || !($platform=~/^WINDOWS$|^MAC$|^LINUX$/)){
			&_log(508,'update','') if $ENV{'OCS_OPT_LOGLEVEL'};
			return APACHE_BAD_REQUEST;
	}
	
	# What are the available versions in the database
	$request = $dbh->prepare('SELECT * FROM files WHERE OS=?');
	$request->execute($platform);
	
	# If no file available, tell to the client not to update
	unless($request->rows){
		&_send_response({ 'RESPONSE' => ['NO_UPDATE'] });
		$request->finish;
		return APACHE_OK;
	}else{
		# Files are available, does the client have to download and install it ?
		# Get versions number
		while($row=$request->fetchrow_hashref()){
			# Version of the agent in the database
			if($row->{'NAME'}=~/agent/i){
				push @agent, $row->{'VERSION'};
			}
			# Maybe a dmi reader version(on a linux computer)
			if(defined($Dversion)){
				# Version of the dmi in the database
				if($row->{'NAME'}=~/dmi/i){
					push @dmi, $row->{'VERSION'};
				}
			}
			if(defined($Iversion)){
				# Version of ipdiscover in the database
				if($row->{'NAME'}=~/ipdiscover/i){
					push @ipdiscover, $row->{'VERSION'};
				}
			}
		}
		# Determine the upper agent version available	
		if(@agent){
			# Looking for the latest version
			$Acurrent = 0;
			for(@agent){
				if($_>$Acurrent){$Acurrent = $_;}
			}
			# Compare to the client version. If different, we tell you to update
			$agent = ($Aversion==$Acurrent)?0:1;
		}else{
			$agent = 0;
		}
		
		# DMI
		$Dcurrent = 0;
		if(defined($Dversion) and @dmi){
			for(@dmi){
				if($_>$Dcurrent){$Dcurrent = $_;}
			}
			# Compare to the client version. If different, we tell you to update
			$dmi = ($Dversion==$Dcurrent)?0:1;
		}
		# IPDISCOVER
		if(defined($Iversion) and @ipdiscover){
			for(@ipdiscover){
				if($_>$Icurrent){$Icurrent = $_;}
			}
			# Compare to the client version. If different, we tell you to update
			$ip = ($Iversion==$Icurrent)?0:1;
		}
	}
	$request->finish;
	
	# Generate the response
	unless(($agent) or ($dmi) or $ip){
		&_send_response({'RESPONSE',['NO_UPDATE']});
		return APACHE_OK;
	}
	$resp{'RESPONSE'} = ['UPDATE'];
	if( $agent ){ $resp{'AGENT'} = [ $Acurrent ] }
	if( $dmi ){ $resp{'DMI'} = [ $Dcurrent ] }
	if( $ip ){ $resp{'IPDISCOVER'} = [ $Icurrent ] }
	
	# Send it
	&_send_response(\%resp);
	return APACHE_OK;

}
1;