Skip to content

Commit

Permalink
Merge branch 'fix_hardcoded'
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Sep 29, 2023
2 parents faaed69 + 2d46fc3 commit db390a4
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 49 deletions.
60 changes: 60 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ mark_as_advanced(
ZM_PATH_MAP
ZM_PATH_ARP
ZM_PATH_ARP_SCAN
ZM_PATH_RM
ZM_PATH_UNAME
ZM_PATH_IP
ZM_PATH_IFCONFIG
ZM_CONFIG_DIR
ZM_CONFIG_SUBDIR
ZM_DETECT_SYSTEMD
Expand Down Expand Up @@ -155,6 +159,14 @@ set(ZM_PATH_ARP "" CACHE PATH
"Full path to compatible arp binary. Leave empty for automatic detection.")
set(ZM_PATH_ARP_SCAN "" CACHE PATH
"Full path to compatible scan_arp binary. Leave empty for automatic detection.")
set(ZM_PATH_RM "" CACHE PATH
"Full path to compatible rm binary. Leave empty for automatic detection.")
set(ZM_PATH_UNAME "" CACHE PATH
"Full path to compatible uname binary. Leave empty for automatic detection.")
set(ZM_PATH_IP "" CACHE PATH
"Full path to compatible ip binary. Leave empty for automatic detection.")
set(ZM_PATH_IFCONFIG "" CACHE PATH
"Full path to compatible ifconfig binary. Leave empty for automatic detection.")
set(ZM_CONFIG_DIR "/${CMAKE_INSTALL_SYSCONFDIR}" CACHE PATH
"Location of ZoneMinder configuration, default system config directory")
set(ZM_CONFIG_SUBDIR "${ZM_CONFIG_DIR}/conf.d" CACHE PATH
Expand Down Expand Up @@ -671,6 +683,54 @@ if(ZM_PATH_ARP_SCAN STREQUAL "")
endif()
endif()

# Find the path to an rm compatible executable
if(ZM_PATH_RM STREQUAL "")
find_program(RM_EXECUTABLE rm)
if(RM_EXECUTABLE)
set(ZM_PATH_RM "${RM_EXECUTABLE}")
mark_as_advanced(RM_EXECUTABLE)
endif()
if(RM_EXECUTABLE-NOTFOUND)
message(WARNING "Unable to find a compatible rm binary.")
endif()
endif()

# Find the path to a uname compatible executable
if(ZM_PATH_UNAME STREQUAL "")
find_program(UNAME_EXECUTABLE uname)
if(UNAME_EXECUTABLE)
set(ZM_PATH_UNAME "${UNAME_EXECUTABLE}")
mark_as_advanced(UNAME_EXECUTABLE)
endif()
if(UNAME_EXECUTABLE-NOTFOUND)
message(WARNING "Unable to find a compatible uname binary.")
endif()
endif()

# Find the path to a uname compatible executable
if(ZM_PATH_IP STREQUAL "")
find_program(IP_EXECUTABLE ip)
if(IP_EXECUTABLE)
set(ZM_PATH_IP "${IP_EXECUTABLE}")
mark_as_advanced(IP_EXECUTABLE)
endif()
if(IP_EXECUTABLE-NOTFOUND)
message(WARNING "Unable to find a compatible ip binary.")
endif()
endif()

# Find the path to a ifconfig compatible executable
if(ZM_PATH_IFCONFIG STREQUAL "")
find_program(IFCONFIG_EXECUTABLE ifconfig)
if(IFCONFIG_EXECUTABLE)
set(ZM_PATH_IFCONFIG "${IFCONFIG_EXECUTABLE}")
mark_as_advanced(IFCONFIG_EXECUTABLE)
endif()
if(IFCONFIG_EXECUTABLE-NOTFOUND)
message(WARNING "Unable to find a compatible ifconfig binary.")
endif()
endif()

# Some variables that zm expects
set(ZM_PID "${ZM_RUNDIR}/zm.pid")
set(ZM_CONFIG "${ZM_CONFIG_DIR}/zm.conf")
Expand Down
16 changes: 16 additions & 0 deletions conf.d/01-system-paths.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ ZM_PATH_ARP="@ZM_PATH_ARP@"
# ZoneMinder will find the arp-scan binary automatically on most systems
ZM_PATH_ARP_SCAN="@ZM_PATH_ARP_SCAN@"

# Full path to optional rm binary or just rm to use PATH
# ZoneMinder will find the rm binary automatically on most systems
ZM_PATH_RM="@ZM_PATH_RM@"

# Full path to optional uname binary or just uname to use PATH
# ZoneMinder will find the rm binary automatically on most systems
ZM_PATH_UNAME="@ZM_PATH_UNAME@"

# Full path to optional ip binary or just ip to use PATH
# ZoneMinder will find the ip binary automatically on most systems
ZM_PATH_IP="@ZM_PATH_IP@"

# Full path to optional ifconfig binary or just ifconfig to use PATH
# ZoneMinder will find the ifconfig binary automatically on most systems
ZM_PATH_IFCONFIG="@ZM_PATH_IFCONFIG@"

#Full path to shutdown binary
ZM_PATH_SHUTDOWN="@ZM_PATH_SHUTDOWN@"

Expand Down
2 changes: 1 addition & 1 deletion scripts/ZoneMinder/lib/ZoneMinder/Memory.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
#our $arch = int(3.2*length(~0));

# New method for determining the bitness
our $arch = 32 + 32*( qx(uname -m) =~ /64/ );
our $arch = 32 + 32*( qx($Config{ZM_PATH_UNAME} -m) =~ /64/ );

our $native = $arch/8;
our $mem_seq = 0;
Expand Down
2 changes: 1 addition & 1 deletion scripts/ZoneMinder/lib/ZoneMinder/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ sub delete_path {
my $storage_path = $self->Path();
($storage_path) = ($storage_path =~ /^(.*)$/); # De-taint
($path) = ($path =~ /^(.*)$/); # De-taint
my $command = "/bin/rm -rf $storage_path/$path 2>&1";
my $command = "$Config{ZM_PATH_RM} -rf $storage_path/$path 2>&1";
if (ZoneMinder::General::executeShellCommand($command)) {
Error("Error deleting event directory at $storage_path/$path");
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/zmaudit.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ MAIN: while( $loop ) {
}
aud_print("Deleting event directories with no event id information at $day_dir/$event_dir");
if ( confirm() ) {
executeShellCommand("rm -rf $event_dir");
executeShellCommand($Config{ZM_PATH_RM}.' -rf '.$event_dir);
$cleaned = 1;
}
} # end if able to find id
Expand Down Expand Up @@ -515,7 +515,7 @@ MAIN: while( $loop ) {
aud_print("Filesystem monitor '$monitor_id' in $$Storage{Path} does not exist in database");

if ( confirm() ) {
executeShellCommand("rm -rf $monitor_id");
executeShellCommand($Config{ZM_PATH_RM}.' -rf '.$monitor_id);
$cleaned = 1;
}
}
Expand All @@ -529,7 +529,7 @@ MAIN: while( $loop ) {
aud_print("Filesystem monitor link '$link' does not point to valid monitor directory");
if ( confirm() ) {
( $link ) = ( $link =~ /^(.*)$/ ); # De-taint
executeShellCommand(qq`rm "$link"`);
executeShellCommand($Config{ZM_PATH_RM}.qq` "$link"`);
$cleaned = 1;
}
} # end foreach monitor link
Expand Down
2 changes: 1 addition & 1 deletion scripts/zmtelemetry.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ sub collectData {
$telemetry->{timestamp} = strftime('%Y-%m-%dT%H:%M:%S%z', localtime());
$telemetry->{monitor_count} = countQuery($dbh, 'Monitors');
$telemetry->{event_count} = countQuery($dbh, 'Events');
$telemetry->{architecture} = runSysCmd('uname -p');
$telemetry->{architecture} = runSysCmd($Config{ZM_PATH_UNAME}.' -p');
@$telemetry{qw(kernel distro version)} = getDistro();
$telemetry->{zm_version} = ZoneMinder::Base::ZM_VERSION;
$telemetry->{system_memory} = totalmem();
Expand Down
3 changes: 0 additions & 3 deletions web/ajax/shutdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@

if ( $command == 'shutdown' ) {
exec('sudo -n '.ZM_PATH_SHUTDOWN." -P $when 2>&1", $data['output'], $data['rc']);
#exec('sudo -n /bin/systemctl poweroff -i 2>&1', $data['output'], $data['rc']);
ZM\Debug('Shutdown output ' .$data['rc'].' '.implode("\n",$data['output']));
#ZM\Debug("Shutdown output " . shell_exec('/bin/systemctl poweroff -i 2>&1'));
} else if ( $command == 'restart' ) {
$data['output'] = array();
exec('sudo -n '.ZM_PATH_SHUTDOWN." -r $when 2>&1", $data['output'], $data['rc']);
#exec('sudo -n /bin/systemctl reboot -i 2>&1', $data['output'], $data['rc']);
ZM\Debug("Shutdown output " . implode("\n",$data['output']));
} else if ( $command == 'cancel' ) {
$data['output'] = array();
Expand Down
80 changes: 40 additions & 40 deletions web/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2303,43 +2303,42 @@ function i18n() {
function get_networks() {
$interfaces = array();

if (file_exists('/usr/sbin/ip')) {
exec('ip link', $output, $status);
if (defined('ZM_PATH_IP') and ZM_PATH_IP and file_exists(ZM_PATH_IP)) {
exec(ZM_PATH_IP.' link', $output, $status);
if ( $status ) {
$html_output = implode('<br/>', $output);
ZM\Error("Unable to list network interfaces, status is '$status'. Output was:<br/><br/>$html_output");
} else {
foreach ( $output as $line ) {
if ( preg_match('/^\d+: ([[:alnum:]]+):/', $line, $matches ) ) {
if ( $matches[1] != 'lo' ) {
$interfaces[$matches[1]] = $matches[1];
} else {
ZM\Debug("No match for $line");
}
}
if ( $matches[1] != 'lo' ) {
$interfaces[$matches[1]] = $matches[1];
} else {
ZM\Debug("No match for $line");
}
}
}
}
$routes = array();
exec('ip route', $output, $status);
if ( $status ) {
exec(ZM_PATH_IP.' route', $output, $status);
if ($status) {
$html_output = implode('<br/>', $output);
ZM\Error("Unable to list network interfaces, status is '$status'. Output was:<br/><br/>$html_output");
} else {
foreach ( $output as $line ) {
foreach ($output as $line) {
if ( preg_match('/^default via [.[:digit:]]+ dev ([[:alnum:]]+)/', $line, $matches) ) {
$interfaces['default'] = $matches[1];
$interfaces['default'] = $matches[1];
} else if ( preg_match('/^([.[:digit:]]+\/[[:digit:]]+) dev ([[:alnum:]]+)/', $line, $matches) ) {
$interfaces[$matches[2]] .= ' ' . $matches[1];
ZM\Debug("Matched $line: $matches[2] .= $matches[1]");
} else {
ZM\Debug("Didn't match $line");
}
} # end foreach line of output
$interfaces[$matches[2]] .= ' ' . $matches[1];
ZM\Debug("Matched $line: $matches[2] .= $matches[1]");
} else {
ZM\Debug("Didn't match $line");
}
} # end foreach line of output
}
} else if (file_exists('/sbin/ifconfig')) {
ZM\Debug("Executing ifconfig");
exec('ifconfig', $output, $status);
if ( $status ) {
} else if (defined('ZM_PATH_IFCONFIG') and ZM_PATH_IFCONFIG and file_exists(ZM_PATH_IFCONFIG)) {
exec(ZM_PATH_IFCONFIG, $output, $status);
if ($status) {
$html_output = implode("\n", $output);
ZM\Error("Unable to list network interfaces, status is '$status'. Output was:$html_output");
} else {
Expand All @@ -2353,7 +2352,6 @@ function get_networks() {

ZM\Debug(print_r( $regex,true));
}

}
return $interfaces;
}
Expand All @@ -2363,27 +2361,29 @@ function get_networks() {

function get_subnets($interface) {
$subnets = array();
exec('ip route', $output, $status);
if ( $status ) {
$html_output = implode('<br/>', $output);
ZM\Error("Unable to list network interfaces, status is '$status'. Output was:<br/><br/>$html_output");
} else {
foreach ($output as $line) {
if (preg_match('/^([.[:digit:]]+\/[[:digit:]]+) dev ([[:alnum:]]+)/', $line, $matches)) {
if ($matches[1] == '169.254.0.0/16') {
# Ignore mdns
} else if ($matches[2] == $interface) {
$subnets[] = $matches[1];
if (defined('ZM_PATH_IP') and ZM_PATH_IP and file_exists(ZM_PATH_IP)) {
exec(ZM_PATH_IP.' route', $output, $status);
if ( $status ) {
$html_output = implode('<br/>', $output);
ZM\Error("Unable to list network interfaces, status is '$status'. Output was:<br/><br/>$html_output");
} else {
foreach ($output as $line) {
if (preg_match('/^([.[:digit:]]+\/[[:digit:]]+) dev ([[:alnum:]]+)/', $line, $matches)) {
if ($matches[1] == '169.254.0.0/16') {
# Ignore mdns
} else if ($matches[2] == $interface) {
$subnets[] = $matches[1];
} else {
ZM\Debug("Wrong interface $matches[1] != $interface");
}
} else {
ZM\Debug("Wrong interface $matches[1] != $interface");
ZM\Debug("Didn't match $line");
}
} else {
ZM\Debug("Didn't match $line");
}
} # end foreach line of output
} # end foreach line of output
}
}
return $subnets;
}
} # end function get_subnets($interface)

function extract_auth_values_from_url($url) {
$protocolPrefixPos = strpos($url, '://');
Expand Down

0 comments on commit db390a4

Please sign in to comment.