/dev/null >&- <&- >/dev/null"; exec( $string ); } function packageControl( $command ) { $string = ZM_PATH_BIN."/zmpkg.pl $command"; $string .= " 2>/dev/null >&- <&- >/dev/null"; exec( $string ); } function daemonControl( $command, $daemon=false, $args=false ) { $string = ZM_PATH_BIN."/zmdc.pl $command"; if ( $daemon ) { $string .= " $daemon"; if ( $args ) { $string .= " $args"; } } $string .= " 2>/dev/null >&- <&- >/dev/null"; exec( $string ); } function zmcControl( $monitor, $restart=false ) { print_r( $monitor ); if ( $monitor[Type] == "Local" ) { $sql = "select count(if(Function='Passive',1,NULL)) as PassiveCount, count(if(Function='Active',1,NULL)) as ActiveCount, count(if(Function='X10',1,NULL)) as X10Count from Monitors where Device = '$monitor[Device]'"; $zmc_args = "-d $monitor[Device]"; } else { $sql = "select count(if(Function='Passive',1,NULL)) as PassiveCount, count(if(Function='Active',1,NULL)) as ActiveCount, count(if(Function='X10',1,NULL)) as X10Count from Monitors where Host = '$monitor[Host]' and Port = '$monitor[Port]' and Path = '$monitor[Path]'"; $zmc_args = "-H $monitor[Host] -P $monitor[Port] -p '$monitor[Path]'"; } $result = mysql_query( $sql ); if ( !$result ) echo mysql_error(); $row = mysql_fetch_assoc( $result ); $passive_count = $row[PassiveCount]; $active_count = $row[ActiveCount]; $x10_count = $row[X10Count]; if ( !$passive_count && !$active_count && !$x10_count ) { daemonControl( "stop", "zmc", $zmc_args ); } else { if ( $restart ) { daemonControl( "stop", "zmc", $zmc_args ); } daemonControl( "start", "zmc", $zmc_args ); } } function zmaControl( $monitor, $restart=false ) { if ( !is_array( $monitor ) ) { $sql = "select Id,Function from Monitors where Id = '$monitor'"; $result = mysql_query( $sql ); if ( !$result ) echo mysql_error(); $monitor = mysql_fetch_assoc( $result ); } if ( $monitor['Function'] == 'Active' ) { if ( $restart ) { daemonControl( "stop", "zmfilter.pl", "-m $monitor[Id] -e -1" ); daemonControl( "stop", "zma", "-m $monitor[Id]" ); } daemonControl( "start", "zma", "-m $monitor[Id]" ); daemonControl( "start", "zmfilter.pl", "-m $monitor[Id] -e -1" ); } else { daemonControl( "stop", "zmfilter.pl", "-m $monitor[Id] -e -1" ); daemonControl( "stop", "zma", "-m $monitor[Id]" ); } } function daemonCheck( $daemon=false, $args=false ) { $string = ZM_PATH_BIN."/zmdc.pl check"; if ( $daemon ) { $string .= " $daemon"; if ( $args ) $string .= " $args"; } $result = exec( $string ); return( preg_match( '/running/', $result ) ); } function zmcCheck( $monitor ) { if ( $monitor[Type] == 'Local' ) { $zmc_args = "-d $monitor[Device]"; } else { $zmc_args = "-H $monitor[Host] -P $monitor[Port] -p '$monitor[Path]'"; } return( daemonCheck( "zmc", $zmc_args ) ); } function zmaCheck( $monitor ) { if ( is_array( $monitor ) ) { $monitor = $monitor[Id]; } return( daemonCheck( "zma", "-m $monitor" ) ); } function createVideo( $event ) { $command = ZM_PATH_BIN."/zmvideo.pl -e $event[Id]"; $result = exec( $command, $output, $status ); return( $status?"":rtrim($result) ); } ?>