This file is indexed.

/usr/bin/zmtrack.pl is in zoneminder 1.26.5-1ubuntu3.

This file is owned by root:root, with mode 0o755.

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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/perl -wT
#
# ==========================================================================
#
# ZoneMinder Experimental PTZ Tracking Script, $Date: 2009-06-08 10:11:56 +0100 (Mon, 08 Jun 2009) $, $Revision: 2908 $
# Copyright (C) 2001-2008 Philip Coombes
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ==========================================================================
#
# This script is used to trigger and cancel alarms from external sources
# using an arbitrary text based format
#
use strict;
use bytes;

# ==========================================================================
#
# User config
#
# ==========================================================================

use constant SLEEP_TIME => 10000; # In microseconds

# ==========================================================================
#
# Don't change anything from here on down
#
# ==========================================================================

# Include from system perl paths only
use ZoneMinder;
use DBI;
use POSIX;
use Data::Dumper;
use Getopt::Long;
use Time::HiRes qw( usleep );

$| = 1;

$ENV{PATH}  = '/bin:/usr/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};

my $mid = 0;

sub Usage
{
	print( "
		Usage: zmtrack.pl -m <monitor>,--monitor=<monitor>]
		Parameters are :-
		-m<monitor>, --monitor=<monitor>   - Id of the monitor to track
		");
	exit( -1 );
}   

if ( !GetOptions( 'monitor=s'=>\$mid ) )
{
	Usage();
}

logInit();
logSetSignal();

my ( $detaint_mid ) = $mid =~ /^(\d+)$/;
$mid = $detaint_mid;

print( "Tracker daemon $mid (experimental) starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );

my $dbh = zmDbConnect();

my $sql = "select C.*,M.* from Monitors as M left join Controls as C on M.ControlId = C.Id where M.Id = ?";
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );

my $res = $sth->execute( $mid ) or Fatal( "Can't execute '$sql': ".$sth->errstr() );
my $monitor = $sth->fetchrow_hashref();

if ( !$monitor )
{
	print( "Can't find monitor '$mid'\n" );
	exit( -1 );
}
if ( !$monitor->{Controllable} )
{
	print( "Monitor '$mid' is not controllable\n" );
	exit( -1 );
}
if ( !$monitor->{TrackMotion} )
{
	print( "Monitor '$mid' is not configured to track motion\n" );
	exit( -1 );
}

if ( !$monitor->{CanMoveMap} )
{
	print( "Monitor '$mid' cannot move in map mode" );
	if ( $monitor->{CanMoveRel} )
	{
		print( ", falling back to pseudo map mode\n" );
	}
	else
	{
		print( "\n" );
		exit( -1 );
	}
}

Debug( "Found monitor for id '$monitor'\n" );
exit( -1 ) if ( !zmMemVerify( $monitor ) );

sub Suspend
{
	my $monitor = shift;
	zmMonitorSuspend( $monitor );
}

sub Resume
{
	my $monitor = shift;
	sleep( $monitor->{TrackDelay} );
	zmMonitorResume( $monitor );
}

sub Track
{
	my $monitor = shift;
	my ( $x, $y ) = @_;
	my ( $detaint_x ) = $x =~ /^(\d+)$/; $x = $detaint_x;
	my ( $detaint_y ) = $y =~ /^(\d+)$/; $y = $detaint_y;

    my $ctrlCommand = ZM_PATH_BIN."/zmcontrol.pl -i ".$monitor->{Id};
	$ctrlCommand .= " --command=".($monitor->{CanMoveMap}?"moveMap":"movePseudoMap")." --xcoord=$x --ycoord=$y";
	executeShellCommand( $ctrlCommand );
}

sub Return
{
	my $monitor = shift;

    my $ctrlCommand = ZM_PATH_BIN."/zmcontrol.pl -i ".$monitor->{Id};
	if ( $monitor->{ReturnLocation} > 0 )
	{
		$ctrlCommand .= " --command=presetGoto --preset=".$monitor->{ReturnLocation};
	}
	else
	{
		$ctrlCommand .= " --command=presetHome";
	}
	executeShellCommand( $ctrlCommand );
}

my $last_alarm = 0;
if ( ($monitor->{ReturnLocation} >= 0) )
{
	Suspend( $monitor );
	Return( $monitor );
	Resume( $monitor );
}

my $alarmed = undef;
while( 1 )
{
	if ( zmIsAlarmed( $monitor ) )
	{
		my ( $alarm_x, $alarm_y ) = zmGetAlarmLocation( $monitor );
		if ( $alarm_x >= 0 && $alarm_y >= 0 )
		{
			Debug( "Got alarm at $alarm_x, $alarm_y\n" );
			Suspend( $monitor );
			Track( $monitor, $alarm_x, $alarm_y );
			Resume( $monitor );
			$last_alarm = time();
			$alarmed = !undef;
		}
	}
	else
	{
		if ( logDebugging() && $alarmed )
		{
			print( "Left alarm state\n" );
			$alarmed = undef;
		}
		if ( ($monitor->{ReturnLocation} >= 0) && ($last_alarm > 0) && ((time()-$last_alarm) > $monitor->{ReturnDelay}) )
		{
			Debug( "Returning to location ".$monitor->{ReturnLocation}."\n" );
			Suspend( $monitor );
			Return( $monitor );
			Resume( $monitor );
			$last_alarm = 0;
		}
	}
	usleep( SLEEP_TIME );
}