remove extra quotes, google code style, update pod docs
parent
4107082845
commit
0e3eb0df17
|
@ -1,27 +1,3 @@
|
|||
# ==========================================================================
|
||||
#
|
||||
# ZoneMinder General Utility Module, $Date$, $Revision$
|
||||
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# ==========================================================================
|
||||
#
|
||||
# This module contains the common definitions and functions used by the rest
|
||||
# of the ZoneMinder scripts
|
||||
#
|
||||
package ZoneMinder::General;
|
||||
|
||||
use 5.006;
|
||||
|
@ -42,7 +18,7 @@ our @ISA = qw(Exporter ZoneMinder::Base);
|
|||
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
||||
# will save memory.
|
||||
our %EXPORT_TAGS = (
|
||||
'functions' => [ qw(
|
||||
functions => [ qw(
|
||||
executeShellCommand
|
||||
getCmdFormat
|
||||
runCommand
|
||||
|
@ -56,7 +32,7 @@ our %EXPORT_TAGS = (
|
|||
);
|
||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } );
|
||||
|
||||
our @EXPORT = qw();
|
||||
|
||||
|
@ -80,74 +56,74 @@ sub executeShellCommand {
|
|||
my $output = qx( $command );
|
||||
my $status = $? >> 8;
|
||||
if ( $status || logDebugging() ) {
|
||||
Debug( "Command: $command\n" );
|
||||
Debug("Command: $command");
|
||||
chomp( $output );
|
||||
Debug( "Output: $output\n" );
|
||||
Debug("Output: $output");
|
||||
}
|
||||
return( $status );
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub getCmdFormat {
|
||||
Debug( "Testing valid shell syntax\n" );
|
||||
Debug("Testing valid shell syntax");
|
||||
|
||||
my ( $name ) = getpwuid( $> );
|
||||
if ( $name eq $Config{ZM_WEB_USER} ) {
|
||||
Debug( "Running as '$name', su commands not needed\n" );
|
||||
return( "" );
|
||||
Debug("Running as '$name', su commands not needed");
|
||||
return '';
|
||||
}
|
||||
|
||||
my $null_command = "true";
|
||||
my $null_command = 'true';
|
||||
|
||||
my $prefix = "sudo -u ".$Config{ZM_WEB_USER}." ";
|
||||
my $suffix = "";
|
||||
my $prefix = 'sudo -u '.$Config{ZM_WEB_USER}.' ';
|
||||
my $suffix = '';
|
||||
my $command = $prefix.$null_command.$suffix;
|
||||
Debug( "Testing \"$command\"\n" );
|
||||
Debug("Testing \"$command\"");
|
||||
my $output = qx($command 2>&1);
|
||||
my $status = $? >> 8;
|
||||
$output //= $!;
|
||||
|
||||
if ( !$status ) {
|
||||
Debug( "Test ok, using format \"$prefix<command>$suffix\"\n" );
|
||||
Debug("Test ok, using format \"$prefix<command>$suffix\"");
|
||||
return( $prefix, $suffix );
|
||||
} else {
|
||||
chomp( $output );
|
||||
Debug( "Test failed, '$output'\n" );
|
||||
Debug("Test failed, '$output'");
|
||||
|
||||
$prefix = "su ".$Config{ZM_WEB_USER}." --shell=/bin/sh --command='";
|
||||
$suffix = "'";
|
||||
$prefix = 'su '.$Config{ZM_WEB_USER}.q` --shell=/bin/sh --command='`;
|
||||
$suffix = q`'`;
|
||||
$command = $prefix.$null_command.$suffix;
|
||||
Debug( "Testing \"$command\"\n" );
|
||||
Debug("Testing \"$command\"");
|
||||
my $output = qx($command 2>&1);
|
||||
my $status = $? >> 8;
|
||||
$output //= $!;
|
||||
|
||||
if ( !$status ) {
|
||||
Debug( "Test ok, using format \"$prefix<command>$suffix\"\n" );
|
||||
Debug("Test ok, using format \"$prefix<command>$suffix\"");
|
||||
return( $prefix, $suffix );
|
||||
} else {
|
||||
chomp( $output );
|
||||
Debug( "Test failed, '$output'\n" );
|
||||
chomp($output);
|
||||
Debug("Test failed, '$output'");
|
||||
|
||||
$prefix = "su ".$Config{ZM_WEB_USER}." -c '";
|
||||
$suffix = "'";
|
||||
$command = $prefix.$null_command.$suffix;
|
||||
Debug( "Testing \"$command\"\n" );
|
||||
Debug("Testing \"$command\"");
|
||||
$output = qx($command 2>&1);
|
||||
$status = $? >> 8;
|
||||
$output //= $!;
|
||||
|
||||
if ( !$status ) {
|
||||
Debug( "Test ok, using format \"$prefix<command>$suffix\"\n" );
|
||||
Debug("Test ok, using format \"$prefix<command>$suffix\"");
|
||||
return( $prefix, $suffix );
|
||||
} else {
|
||||
chomp( $output );
|
||||
Debug( "Test failed, '$output'\n" );
|
||||
chomp($output);
|
||||
Debug("Test failed, '$output'");
|
||||
}
|
||||
}
|
||||
}
|
||||
Error( "Unable to find valid 'su' syntax\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
Error("Unable to find valid 'su' syntax");
|
||||
exit -1;
|
||||
} # end sub getCmdFormat
|
||||
|
||||
our $testedShellSyntax = 0;
|
||||
our ( $cmdPrefix, $cmdSuffix );
|
||||
|
@ -161,23 +137,23 @@ sub runCommand {
|
|||
}
|
||||
|
||||
my $command = shift;
|
||||
$command = $Config{ZM_PATH_BIN}."/".$command;
|
||||
$command = $Config{ZM_PATH_BIN}.'/'.$command;
|
||||
if ( $cmdPrefix ) {
|
||||
$command = $cmdPrefix.$command.$cmdSuffix;
|
||||
}
|
||||
Debug( "Command: $command\n" );
|
||||
Debug("Command: $command");
|
||||
my $output = qx($command);
|
||||
my $status = $? >> 8;
|
||||
chomp( $output );
|
||||
chomp($output);
|
||||
if ( $status || logDebugging() ) {
|
||||
if ( $status ) {
|
||||
Error( "Unable to run \"$command\", output is \"$output\", status is $status\n" );
|
||||
Error("Unable to run \"$command\", output is \"$output\", status is $status");
|
||||
} else {
|
||||
Debug( "Output: $output\n" );
|
||||
Debug("Output: $output");
|
||||
}
|
||||
}
|
||||
return( $output );
|
||||
}
|
||||
return $output;
|
||||
} # end sub runCommand
|
||||
|
||||
sub createEventPath {
|
||||
my $event = shift;
|
||||
|
@ -210,7 +186,7 @@ sub _checkProcessOwner {
|
|||
$_setFileOwner = 0;
|
||||
}
|
||||
}
|
||||
return( $_setFileOwner );
|
||||
return $_setFileOwner;
|
||||
}
|
||||
|
||||
sub setFileOwner {
|
||||
|
@ -219,7 +195,7 @@ sub setFileOwner {
|
|||
if ( _checkProcessOwner() ) {
|
||||
chown( $_ownerUid, $_ownerGid, $file )
|
||||
or Fatal( "Can't change ownership of file '$file' to '"
|
||||
.$Config{ZM_WEB_USER}.":".$Config{ZM_WEB_GROUP}."': $!"
|
||||
.$Config{ZM_WEB_USER}.':'.$Config{ZM_WEB_GROUP}."': $!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -234,13 +210,13 @@ sub _checkForImageInfo {
|
|||
};
|
||||
$_hasImageInfo = $@?0:1;
|
||||
}
|
||||
return( $_hasImageInfo );
|
||||
return $_hasImageInfo;
|
||||
}
|
||||
|
||||
sub createEvent {
|
||||
my $event = shift;
|
||||
|
||||
Debug( "Creating event" );
|
||||
Debug('Creating event');
|
||||
#print( Dumper( $event )."\n" );
|
||||
|
||||
_checkForImageInfo();
|
||||
|
@ -561,38 +537,33 @@ __END__
|
|||
|
||||
=head1 NAME
|
||||
|
||||
ZoneMinder::Database - Perl extension for blah blah blah
|
||||
ZoneMinder::General - Utility Functions for ZoneMinder
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use ZoneMinder::Database;
|
||||
use ZoneMinder::General;
|
||||
blah blah blah
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Stub documentation for ZoneMinder, created by h2xs. It looks like the
|
||||
author of the extension was negligent enough to leave the stub
|
||||
unedited.
|
||||
|
||||
Blah blah blah.
|
||||
This module contains the common definitions and functions used by the rest
|
||||
of the ZoneMinder scripts
|
||||
|
||||
=head2 EXPORT
|
||||
|
||||
None by default.
|
||||
functions => [ qw(
|
||||
executeShellCommand
|
||||
getCmdFormat
|
||||
runCommand
|
||||
setFileOwner
|
||||
createEventPath
|
||||
createEvent
|
||||
makePath
|
||||
jsonEncode
|
||||
jsonDecode
|
||||
) ]
|
||||
|
||||
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
Mention other useful documentation such as the documentation of
|
||||
related modules or operating system documentation (such as man pages
|
||||
in UNIX), or any relevant external documentation such as RFCs or
|
||||
standards.
|
||||
|
||||
If you have a mailing list set up for your module, mention it here.
|
||||
|
||||
If you have a web site set up for your module, mention it here.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Philip Coombes, E<lt>philip.coombes@zoneminder.comE<gt>
|
||||
|
@ -601,9 +572,18 @@ Philip Coombes, E<lt>philip.coombes@zoneminder.comE<gt>
|
|||
|
||||
Copyright (C) 2001-2008 Philip Coombes
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the same terms as Perl itself, either Perl version 5.8.3 or,
|
||||
at your option, any later version of Perl 5 you may have available.
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
=cut
|
||||
|
|
Loading…
Reference in New Issue