* * Works with Win2000, XP * * place this file in miranda_dir\mbot\scripts\autoload * * * * allows to execute shell commands by sending messages with commands * * sends command output back to command sender * * * \*****************************************************************************/ /********************** [ configuration - edit this to fit your needs ] **********************************************/ $saveIncoming=1; // save outgoing messages in history $saveOutgoing=1; // save incoming messages in history $initialDir='C:\tmp'; // initial directory for executing commands $knownOnly=1; // 1 - only users from contact list may execute commands. 0 - everyone. (this parameter is ignored if $whiteListOnly is 1) $whiteListOnly=1; // 1 - only contacts in whitelist are allowed to execute commands. 0 - depends on $knownOnly value. $cmdPrefix='!exec'; // if not blank, only messages starting with $cmdPrefix value will be considered commands, can be used instead of password $whiteList=array('340514396'); // list of contact UINs in whitelist, separated by commas, like $whiteList=array('123456','759223'); $maxlen=5000; // maximum length of message, larger text will be split to multiple messages $notAuthorizedMsg="Not Authorized"; // message that unauthorized users will get $warnNotAuthorized=1; // 1 - send notAuthorizedMsg if contact is not authorized. 0 - be silent /********************** [ end of configuration ] ********************************************************************/ function mbot_load(){mb_SelfRegister(MB_EVENT_MSG_IN,1);} function mbe_MsgIn($cid,$body,$timestamp,$known) { global $saveIncoming, $saveOutgoing, $initialDir,$knownOnly,$cmdPrefix,$whiteList,$whiteListOnly,$maxlen,$notAuthorizedMsg,$warnNotAuthorized; $saveIncoming=($saveIncoming==1?0:'drop'); $uin=mb_CGetUIN($cid); $isWhite=in_array($uin,$whiteList); if($whiteListOnly && !$isWhite){ if($warnNotAuthorized) mb_MsgSend($cid, $notAuthorizedMsg, $saveOutgoing); return $saveIncoming; } if (!$known && $knownOnly && !$isWhite){ if($warnNotAuthorized) mb_MsgSend($cid, $notAuthorizedMsg, $saveOutgoing); return $saveIncoming; } if(strlen($cmdPrefix)>0) { if(substr($body,0,strlen($cmdPrefix))==$cmdPrefix) $cmd=substr($body,strlen($cmdPrefix)); else return $saveIncoming; } else $cmd=$body; $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"),2 => array("pipe", "w")); $process = proc_open("cmd.exe /k \"$initialDir\"", $descriptorspec, $pipes); if (is_resource($process)) { fwrite($pipes[0], "$cmd\n"); fclose($pipes[0]); while (!feof($pipes[1])) $out .= fgets($pipes[1], 1024); fclose($pipes[1]); while (!feof($pipes[2])) $err .= fgets($pipes[2], 1024); fclose($pipes[2]); $return_value = proc_close($process); } $reply=$out; if(strlen($err)>1) $reply.="\n\nerror:".$err; if(strlen($reply) > $maxlen){ $sent=0; while($sent