diff --git a/web/zm.php b/web/zm.php index df8637c76..5acafb941 100644 --- a/web/zm.php +++ b/web/zm.php @@ -23,7 +23,8 @@ define( "DB_USER", "zmadmin" ); // Database login define( "DB_PASS", "zmadminzm" ); // Database password define( "MAX_EVENTS", 12 ); -define( "ZMU_PATH", "/usr/local/bin/zmu" ); +define( "ZM_PATH", "/usr/local/bin" ); +define( "ZMU_PATH", ZM_PATH."/zmu" ); define( "ZMS_PATH", "/cgi-bin/zms" ); define( "ZMS_EVENT_PATH", "/data/zm" ); define( "CAMBOZOLA_PATH", "cambozola.jar" ); @@ -101,7 +102,8 @@ if ( $action ) } elseif ( $action == "function" && $mid ) { - $result = mysql_query( "select * from Monitors where Id = '$mid'" ); + $sql = "select * from Monitors where Id = '$mid'"; + $result = mysql_query( $sql ); if ( !$result ) die( mysql_error() ); $monitor = mysql_fetch_assoc( $result ); @@ -109,75 +111,69 @@ if ( $action ) $old_function = $monitor['Function']; if ( $new_function != $old_function ) { + $sql = "update Monitors set Function = '$new_function' where Id = '$mid'"; + $result = mysql_query( $sql ); + if ( !$result ) + echo mysql_error(); + $sql = "select * from Monitors where Device = '$monitor[Device]' and Function != 'None'"; + $result = mysql_query( $sql ); + if ( !$result ) + die( mysql_error() ); + $device_monitors = mysql_num_rows( $result ); if ( $new_function == "None" ) { + if ( $device_monitors == 0 ) + { + stopDaemon( "zmc", $monitor[Device] ); + stopDaemon( "zma", $monitor[Device] ); + } + else + { + signalDaemon( "zmc", $monitor[Device], 'HUP' ); + signalDaemon( "zma", $monitor[Device], 'HUP' ); + } } - else + elseif ( $new_function == "Passive" ) { + startDaemon( "zmc", $monitor[Device] ); + if ( $device_monitors == 0 ) + { + stopDaemon( "zma", $monitor[Device] ); + } + else + { + signalDaemon( "zmc", $monitor[Device], 'HUP' ); + startDaemon( "zma", $monitor[Device] ); + signalDaemon( "zma", $monitor[Device], 'HUP' ); + } } + elseif ( $new_function == "Active" ) + { + startDaemon( "zmc", $monitor[Device] ); + signalDaemon( "zmc", $monitor[Device], 'HUP' ); + startDaemon( "zma", $monitor[Device] ); + signalDaemon( "zma", $monitor[Device], 'HUP' ); + } + $refresh_parent = true; } } elseif ( $action == "device" && isset( $did ) ) { if ( $zmc_status && !$zmc_action ) { - # Shutdown Capture daemon - $ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zmc $did' | grep -v grep" ) ); - if ( $ps_array[3] ) - { - $zmc_pid = $ps_array[3]; - exec( "kill -TERM $zmc_pid" ); - } - while( $zmc_pid ) - { - sleep( 1 ); - $ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zmc $did' | grep -v grep" ) ); - $zmc_pid = $ps_array[3]; - } + stopDaemon( "zmc", $did ); } elseif ( !$zmc_status && $zmc_action ) { - # Start Capture daemon - $command = '/usr/local/bin/zmc '.$did.' 2>/dev/null >&- <&- >/dev/null &'; - exec( $command ); - $ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zmc $did' | grep -v grep" ) ); - $zmc_pid = $ps_array[3]; - while ( !$zmc_pid ) - { - sleep( 1 ); - $ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zmc $did' | grep -v grep" ) ); - $zmc_pid = $ps_array[3]; - } + startDaemon( "zmc", $did ); } if ( $zma_status && !$zma_action ) { - # Shutdown Analysis daemon - $ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zma $did' | grep -v grep" ) ); - if ( $ps_array[3] ) - { - $zma_pid = $ps_array[3]; - exec( "kill -TERM $zma_pid" ); - } - while( $zma_pid ) - { - sleep( 1 ); - $ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zma $did' | grep -v grep" ) ); - $zma_pid = $ps_array[3]; - } + stopDaemon( "zma", $did ); } elseif ( !$zma_status && $zma_action ) { - # Start Analysis daemon - $command = '/usr/local/bin/zma '.$did.' 2>/dev/null >&- <&- >/dev/null &'; - exec( $command ); - $ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zma $did' | grep -v grep" ) ); - $zma_pid = $ps_array[3]; - while ( !$zma_pid ) - { - sleep( 1 ); - $ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zma $did' | grep -v grep" ) ); - $zma_pid = $ps_array[3]; - } + startDaemon( "zma", $did ); } } } @@ -542,7 +538,7 @@ elseif ( $view == "events" )