add sendControlCommand function to do the heavy work of sending zmcontrol a command
parent
e9fc7cf33a
commit
2e48c2ba3d
|
@ -963,3 +963,30 @@ function buildControlCommand( $monitor )
|
|||
$ctrlCommand .= " --command=".$_REQUEST['control'];
|
||||
return( $ctrlCommand );
|
||||
}
|
||||
|
||||
function sendControlCommand($mid,$command) {
|
||||
// Either connects to running zmcontrol.pl or runs zmcontrol.pl to send the command.
|
||||
$socket = socket_create( AF_UNIX, SOCK_STREAM, 0 );
|
||||
if ( $socket < 0 ) {
|
||||
Fatal( "socket_create() failed: ".socket_strerror($socket) );
|
||||
}
|
||||
$sockFile = ZM_PATH_SOCKS.'/zmcontrol-'.$mid.'.sock';
|
||||
if ( @socket_connect( $socket, $sockFile ) ) {
|
||||
$options = array();
|
||||
foreach ( explode( " ", $command ) as $option ) {
|
||||
if ( preg_match( '/--([^=]+)(?:=(.+))?/', $option, $matches ) ) {
|
||||
$options[$matches[1]] = $matches[2]?$matches[2]:1;
|
||||
}
|
||||
}
|
||||
$optionString = jsonEncode( $options );
|
||||
if ( !socket_write( $socket, $optionString ) ) {
|
||||
Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) );
|
||||
}
|
||||
socket_close( $socket );
|
||||
} else if ( $command != 'quit' ) {
|
||||
$command .= ' --id='.$mid;
|
||||
|
||||
// Can't connect so use script
|
||||
$ctrlOutput = exec( escapeshellcmd( $command ) );
|
||||
}
|
||||
} // end function sendControlCommand( $mid, $command )
|
||||
|
|
Loading…
Reference in New Issue