Ejemplo n.º 1
0
 /**
  * @param string $message
  * @param string $scope
  * @return void
  */
 public function write($message, $scope = Output::SCOPE_PRIVATE)
 {
     if ($scope == Output::SCOPE_PUBLIC) {
         $this->xmpp->presence(null, 'available', $this->getChatroom() . '/Git');
         $this->xmpp->message($this->getChatroom(), sprintf('[%s] %s', $this->getUser(), $message), 'groupchat');
         $this->xmpp->presence(null, 'unavailable', $this->getChatroom() . '/Git');
     }
 }
 /**
  * @param array $notification
  * @param array $overrideConfig
  * @return void
  */
 public function addNotification($notification, $overrideConfig)
 {
     $config = $this->getConfig($overrideConfig);
     $message = $this->getMessageForNotification($notification);
     /** @var tx_caretaker_AbstractNode $node */
     $node = $notification['node'];
     $contacts = $node->getContacts($config['roles']);
     /** @var tx_caretaker_Contact $contact */
     foreach ($contacts as $contact) {
         $xmppAddress = $contact->getAddressProperty('xmpp');
         if (!empty($xmppAddress)) {
             $this->connection->message($xmppAddress, $message);
         }
     }
 }
 /**
  * Processes the message (sends using jabber).
  * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
  * @return true if ok, false if error
  */
 function send_message($eventdata)
 {
     global $CFG;
     if (!empty($CFG->noemailever)) {
         // hidden setting for development sites, set in config.php if needed
         debugging('$CFG->noemailever active, no jabber message sent.', DEBUG_MINIMAL);
         return true;
     }
     //hold onto jabber id preference because /admin/cron.php sends a lot of messages at once
     static $jabberaddresses = array();
     if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) {
         $jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', null, $eventdata->userto->id);
     }
     $jabberaddress = $jabberaddresses[$eventdata->userto->id];
     //calling s() on smallmessage causes Jabber to display things like < Jabber != a browser
     $jabbermessage = fullname($eventdata->userfrom) . ': ' . $eventdata->smallmessage;
     if (!empty($eventdata->contexturl)) {
         $jabbermessage .= "\n" . get_string('view') . ': ' . $eventdata->contexturl;
     }
     $jabbermessage .= "\n(" . get_string('noreply', 'message') . ')';
     $conn = new XMPPHP_XMPP($CFG->jabberhost, $CFG->jabberport, $CFG->jabberusername, $CFG->jabberpassword, 'moodle', $CFG->jabberserver);
     try {
         //$conn->useEncryption(false);
         $conn->connect();
         $conn->processUntil('session_start');
         $conn->presence();
         $conn->message($jabberaddress, $jabbermessage);
         $conn->disconnect();
     } catch (XMPPHP_Exception $e) {
         debugging($e->getMessage());
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Sends message recipient if log entries are present.
  *
  * @return void
  */
 public function shutdown()
 {
     // If there are events to send, use them as message body.
     // Otherwise, there is no message to be sent.
     if (empty($this->_eventsToSend)) {
         return;
     }
     // Finally, send the IM, but re-throw any exceptions at the
     // proper level of abstraction.
     try {
         $jabber = new XMPPHP_XMPP($this->options['host'], $this->options['port'], $this->options['user'], $this->options['password'], $this->options['resource'], $this->options['server'], false, XMPPHP_Log::LEVEL_VERBOSE);
         try {
             $jabber->connect();
             $jabber->processUntil('session_start');
             $jabber->presence();
             $events = implode('', $this->_eventsToSend);
             $jabber->message($this->options['recipient'], $events);
             $jabber->disconnect();
         } catch (XMPPHP_Exception $e) {
             die($e->getMessage());
         }
     } catch (Exception $e) {
         throw new Zend_Log_Exception($e->getMessage(), $e->getCode());
     }
 }
Ejemplo n.º 5
0
function my_action_callback() 
{
	$cmd = $_POST['cmd'];
	
	include 'XMPPHP/XMPP.php';
	
	error_reporting(0);

	//$time_start = microtime_float();
	$conn = new XMPPHP_XMPP('talk.google.com', 5222, '*****@*****.**', 'ns171284', 'xmpphp', 'gmail.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);
	
	try {
		$conn->connect();
	    $conn->processUntil('session_start');
	    $conn->presence();
	     //			$time_end = microtime_float();
	    $conn->message('*****@*****.**', $cmd);
	    $conn->disconnect();
	} catch(XMPPHP_Exception $e) {
	    die($e->getMessage());
	}
	

	//$time = $time_end - $time_start;
	die();
	//die("TOTAL TIME = ".$time);
}
Ejemplo n.º 6
0
 /**
  * Processes the message (sends using jabber).
  * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
  * @return true if ok, false if error
  */
 function send_message($eventdata)
 {
     global $CFG;
     if (message_output_jabber::_jabber_configured()) {
         //hold onto jabber id preference because /admin/cron.php sends a lot of messages at once
         static $jabberaddresses = array();
         if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) {
             $jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', $eventdata->userto->email, $eventdata->userto->id);
         }
         $jabberaddress = $jabberaddresses[$eventdata->userto->id];
         $jabbermessage = fullname($eventdata->userfrom) . ': ' . $eventdata->smallmessage;
         if (!empty($eventdata->contexturl)) {
             $jabbermessage .= "\n" . get_string('view') . ': ' . $eventdata->contexturl;
         }
         $jabbermessage .= "\n(" . get_string('noreply', 'message') . ')';
         $conn = new XMPPHP_XMPP($CFG->jabberhost, $CFG->jabberport, $CFG->jabberusername, $CFG->jabberpassword, 'moodle', $CFG->jabberserver);
         try {
             //$conn->useEncryption(false);
             $conn->connect();
             $conn->processUntil('session_start');
             $conn->presence();
             $conn->message($jabberaddress, $jabbermessage);
             $conn->disconnect();
         } catch (XMPPHP_Exception $e) {
             debugging($e->getMessage());
             return false;
         }
     }
     //note that we're reporting success if message was sent or if Jabber simply isnt configured
     return true;
 }
Ejemplo n.º 7
0
 protected function sendGroupMessage(\XMPPHP_XMPP $client, $config)
 {
     $client->connect();
     $client->processUntil('session_start', static::TIMEOUT);
     $client->presence(NULL, static::STATUS, $config['to'] . '/Professor X');
     $client->message($config['to'], $config['message'], 'groupchat');
     $client->disconnect();
 }
Ejemplo n.º 8
0
 public function notify(Commit $commit)
 {
     $old = error_reporting(0);
     $conn = new \XMPPHP_XMPP($this->host, $this->port, $this->username, $this->password, 'sismo', $this->server);
     $conn->connect();
     $conn->processUntil('session_start');
     $conn->presence();
     foreach (explode(',', $this->recipient) as $user) {
         $conn->message($user, $this->format($this->format, $commit));
     }
     $conn->disconnect();
     error_reporting($old);
 }
Ejemplo n.º 9
0
function xs_send($to, $text)
{
    include TE_DIR . '/lib/XMPPHP/XMPP.php';
    $conn = new XMPPHP_XMPP(XS_SERVER, XS_PORT, XS_LOGIN, XS_PASS, 'xmpphp', XS_SERVIS, $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
    try {
        $conn->connect();
        $conn->processUntil('session_start');
        $conn->presence();
        $conn->message($to, $text);
        $conn->disconnect();
    } catch (XMPPHP_Exception $e) {
        die($e->getMessage());
    }
}
Ejemplo n.º 10
0
function jabber($to, $message)
{
    @(require_once DIR . '/system/lib/XMPPHP/XMPP.php');
    @($conn = new XMPPHP_XMPP($GLOBALS['config']['jabber']['host'], $GLOBALS['config']['jabber']['port'], $GLOBALS['config']['jabber']['user'], $GLOBALS['config']['jabber']['password'], $GLOBALS['config']['jabber']['resource'], $GLOBALS['config']['jabber']['server'], $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO));
    try {
        @$conn->connect();
        @$conn->processUntil('session_start');
        @$conn->presence();
        @$conn->message($to, $message);
        @$conn->disconnect();
        return true;
    } catch (XMPPHP_Exception $e) {
        return false;
    }
}
Ejemplo n.º 11
0
 public function testAuthException()
 {
     try {
         $xmpp = new XMPPHP_XMPP('jabber.wentz.it', 5222, 'invalidusername', 'invalidpassword', 'xmpphp', 'jabber.wentz.it', true, XMPPHP_Log::LEVEL_VERBOSE);
         $xmpp->useEncryption(false);
         $xmpp->connect(10);
         $xmpp->processUntil('session_start');
         $xmpp->presence();
         $xmpp->message('*****@*****.**', 'This is a test message!');
         $xmpp->disconnect();
     } catch (XMPPHP_Exception $e) {
         return;
     } catch (Exception $e) {
         $this->fail('Unexpected Exception thrown: ' . $e->getMessage());
     }
     $this->fail('Expected XMPPHP_Exception not thrown!');
 }
Ejemplo n.º 12
0
 /**
  * @param $message
  *
  * @return $this
  */
 protected function send($message)
 {
     $configCurrentProject = $this->getCurrentProjectConfig();
     $host = $configCurrentProject['host'];
     $port = $configCurrentProject['port'];
     $user = $configCurrentProject['user'];
     $password = $configCurrentProject['password'];
     $ressource = $configCurrentProject['ressource'];
     $server = $configCurrentProject['server'];
     $to = $configCurrentProject['to'];
     $type = $configCurrentProject['type'];
     $xmpp = new XMPPHP_XMPP($host, $port, $user, $password, $ressource, $server, false, 4);
     $xmpp->connect();
     $xmpp->processUntil('session_start');
     $xmpp->presence(null, 'available', $to . '/' . $user);
     $xmpp->message($to, $message, $type);
     $xmpp->presence(null, 'unavailable', $to . '/' . $user);
     $xmpp->disconnect();
     return $this;
 }
Ejemplo n.º 13
0
 public static function SendMessage($msg, $to = NULL)
 {
     if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
         $jabber_server = sfConfig::get('app_sfJabberPlugin_jabber_server');
         $port = sfConfig::get('app_sfJabberPlugin_port');
         $username = sfConfig::get('app_sfJabberPlugin_username');
         $host = sfConfig::get('app_sfJabberPlugin_host');
         $password = sfConfig::get('app_sfJabberPlugin_password');
         if ($to == NULL) {
             $to = sfConfig::get('app_sfJabberPlugin_admin');
         }
         $conn = new XMPPHP_XMPP($jabber_server, $port, $username, $password, 'xmpphp', $host, $printlog = false, $loglevel = XMPPHP_Log::LEVEL_VERBOSE);
         try {
             $conn->useSSL();
             $conn->connect();
             $conn->processUntil('session_start');
             $conn->presence();
             $conn->message($to, $msg);
             $conn->disconnect();
         } catch (XMPPHP_Exception $e) {
         }
     }
 }
Ejemplo n.º 14
0
 }
 switch ($event) {
     case 'message':
         if (!$body) {
             break;
         }
         echo str_repeat('-', 80);
         echo "Message from: {$from}";
         if (isset($subject)) {
             echo "Subject: {$subject}";
         }
         echo $body;
         echo str_repeat('-', 80);
         $cmd = explode(' ', $body);
         $body = "Mi no entender! '{$body}'";
         $conn->message($from, $body, $type);
         if (isset($cmd[0])) {
             if ($cmd[0] == 'quit') {
                 $conn->disconnect();
             }
             if ($cmd[0] == 'break') {
                 $conn->send('</end>');
             }
             if ($cmd[0] == 'vcard') {
                 if (!isset($cmd[1])) {
                     $cmd[1] = $conn->user;
                 }
                 // Take a note which user requested which vcard
                 $vcard_request[$from] = $cmd[1];
                 // Request the vcard
                 $conn->getVCard($cmd[1]);
Ejemplo n.º 15
0
<?php

// activate full error reporting
//error_reporting(E_ALL & E_STRICT);
include 'XMPPHP/XMPP.php';
#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
#If this doesn't work, are you running 64-bit PHP with < 5.2.6?
$conn = new XMPPHP_XMPP('jabber.SERVER.com.ua', 5222, '*****@*****.**', 'your_password', 'xmpphp', 'jabber.SERVER.com.ua', $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
try {
    //$conn->useEncryption(true);
    $conn->connect();
    $conn->processUntil('session_start');
    $conn->presence();
    $conn->message('*****@*****.**', 'This is a test message!');
    $conn->disconnect();
} catch (XMPPHP_Exception $e) {
    die($e->getMessage());
}
// 	mysql_query("insert into $pantiltActionTable (command, last_update) values ('s', " . microtime(true) . ");");
// }
//system ('rm -f /tmp/robot_commands.sock');
$conn = new XMPPHP_XMPP('9thsense.com', 5222, 'controller', '9thsense', 'xmpphp', '9thsense.com', true, XMPPHP_Log::LEVEL_VERBOSE);
$conn->connect();
$conn->processUntil('session_start');
$commandSocket = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($commandSocket, '127.0.0.1', '49440');
socket_listen($commandSocket, 1000000);
socket_set_nonblock($commandSocket);
echo "Done... moving to loop";
while (true) {
    if (($thisSock = @socket_accept($commandSocket)) !== false) {
        $string = socket_read($thisSock, 1400, PHP_NORMAL_READ);
        $string = "litebot@9thsense.com|" . time() . "|{$string}";
        $conn->message("*****@*****.**", "{$string}");
        echo "\nthis is it: {$string}\n";
    }
}
// $current_state = 's';
//
// // one infinite loop (ha ha, get it?)
// $count = 0;
// while (1)
// {
// 	$count ++;
// 	if ($count % 30)
// 	{
// 		//create_update_status ($createFp);
// 	}
// 	$createResult = mysql_query("select * from $createActionTable");
Ejemplo n.º 17
0
 public function sendNotification($user, $subject, $message)
 {
     if ($user->getNotificationMethod() == 'jabber') {
         $conn = new XMPPHP_XMPP(ConfigLine::configByName('jabber_server'), 5222, ConfigLine::configByName('jabber_username'), ConfigLine::configByName('jabber_password'), 'xmpphp', $server = null, $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
         try {
             $conn->connect();
             $conn->processUntil('session_start');
             $conn->presence();
             $conn->message($user->getJabber(), $message);
             $conn->disconnect();
         } catch (XMPPHP_Exception $e) {
             echo $e->getMessage();
         }
     } elseif ($user->getNotificationMethod() == 'email') {
         if ($GLOBALS['mail_sending_type'] == 'smtp') {
             $config['username'] = ConfigLine::configByName('mail_smtp_username');
             $config['password'] = ConfigLine::configByName('mail_smtp_password');
             $config['ssl'] = ConfigLine::configByName('mail_smtp_ssl');
             $config['auth'] = ConfigLine::configByName('mail_smtp_login_auth');
             $transport = new Zend_Mail_Transport_Smtp(ConfigLine::configByName('mail_smtp_server'), $config);
         }
         $mail = new Zend_Mail();
         $mail->setFrom(ConfigLine::configByName('mail_sender_adress'), ConfigLine::configByName('mail_sender_name'));
         $mail->addTo($user->getEmail());
         $mail->setSubject($subject);
         $mail->setBodyText($message);
         $mail->send($transport);
     }
 }
Ejemplo n.º 18
0
$conn = new XMPPHP_XMPP($config_jhost, $config_jport, $config_juser, $config_jpass, $config_jresource, $config_jhost, $printlog = true, $loglevel = XMPPHP_Log::LEVEL_INFO);
//$conn = new XMPPHP_XMPP('jabber.ru', 5222, 'sam-o-bot', 'koikke', 'sylwer', 'jabber.ru', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);
$conn->useSSL(false);
$conn->useEncryption(false);
$conn->autoSubscribe();
$vcard_request = array();
try {
    $conn->connect();
    echo "done\n";
    $s->jconn = $conn;
    while (!$conn->isDisconnected()) {
        //if ($conn->isSessionStarted())
        //{
        $msg = $s->update();
        if ($msg !== false) {
            $conn->message($msg['to'], $body = $msg['body']);
        }
        //}
        $payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start', 'vcard'), 5);
        foreach ($payloads as $event) {
            $pl = $event[1];
            switch ($event[0]) {
                case 'message':
                    print "---------------------------------------------------------------------------------\n";
                    print "Message from: {$pl['from']}\n";
                    if (isset($pl['subject'])) {
                        print "Subject: {$pl['subject']}\n";
                    }
                    //     				print $pl['body'] . "\n";
                    //print_r($pl);
                    print "---------------------------------------------------------------------------------\n";
Ejemplo n.º 19
0
    $conn->connect();
    $conn->processUntil('session_start');
    $conn->presence();
    output("Retrieving roster....");
    $conn->getRoster();
    $roster = $conn->roster;
    // No specific event to signify end, so use timer instead. 3s should be enough.
    $conn->processTime(3);
    // Determine status of user.
    $active = $roster->getPresence($INPUT['im']);
    output("User " . $INPUT['im'] . " state is '" . $active['show'] . "'....");
    $online = in_array($active['show'], $CONFIG['notify_status']);
    // If they're online, then we're all good.
    if ($online) {
        output("Notifying user via IM....");
        $conn->message($INPUT['im'], $INPUT['subject'] . "\n" . $INPUT['message']);
        // Wait for an acknowledgement (any message sent back)
        $payload = $conn->processUntil('message', $ACK_TIMEOUT);
        // non-zero payload array length means a message was received
        $im_sent = count($payload);
    }
    $conn->disconnect();
} catch (XMPPHP_Exception $e) {
    output("XMPP Exception");
}
// If no IM sent, trigger a mail instead.
if (!$im_sent) {
    output("IM not sent, notifying user via email to '" . $INPUT['email'] . "'....");
    $headers = 'From: nagios@' . $XMPP['domain'] . "\r\n" . 'Reply-To: do-not-reply@' . $XMPP['domain'] . "\r\n" . 'X-Mailer: NagNot';
    $result = mail($INPUT['email'], $INPUT['subject'], $INPUT['message'], $headers);
    output("Email sent status: " . ($result ? "sent" : "error"));
Ejemplo n.º 20
0
 $message = $_POST['message'];
 if ($XMPP_MESSAGE_SIGN_ENABLE) {
     $UserInfo = $ldap->getArray($_COOKIE['dn'], false, array($DISPLAY_NAME_FIELD, $LDAP_TITLE_FIELD, $LDAP_CELL_PHONE_FIELD, $LDAP_INTERNAL_PHONE_FIELD), false, false, true);
     $Sign = "\n\n" . $L->l("start_of_xmpp_sign");
     $Sign .= "\n" . $UserInfo[$DISPLAY_NAME_FIELD][0] . " (" . $UserInfo[$LDAP_TITLE_FIELD][0] . ")";
     if ($XMPP_USE_INTERNAL_PHONE_IN_SIGN_ENABLE) {
         $Sign .= "\n" . $L->l("intrenal_phone") . ": " . $UserInfo[$LDAP_INTERNAL_PHONE_FIELD][0] . "";
     }
     if ($XMPP_USE_MOBILE_PHONE_IN_SIGN_ENABLE) {
         $Sign .= "\n" . $L->l("cell_phone") . ": " . $UserInfo[$LDAP_CELL_PHONE_FIELD][0] . "";
     }
     $message .= $Sign;
 }
 if (is_array($_POST['resipients'])) {
     foreach ($_POST['resipients'] as $key => $value) {
         $conn->message(current(explode("@", $value)) . "@" . $XMPP_ACCOUNT_END, $message);
     }
 }
 if (is_array($_POST['groups'])) {
     $Filter = "(|(" . $LDAP_DISTINGUISHEDNAME_FIELD . "=" . implode(")(" . $LDAP_DISTINGUISHEDNAME_FIELD . "=", LDAP::escapeFilterValue($_POST['groups'])) . "))";
     //echo $Filter;
     $Entries = $ldap->ldap_search($OU, $Filter, array($LDAP_MEMBER_FIELD));
     for ($i = 0; $i < $Entries['count']; $i++) {
         if ($i == 0) {
             $Filter = "(|";
         }
         for ($j = 0; $j < $Entries[$i][$LDAP_MEMBER_FIELD]['count']; $j++) {
             $Filter .= "(" . $LDAP_DISTINGUISHEDNAME_FIELD . "=" . LDAP::escapeFilterValue($Entries[$i][$LDAP_MEMBER_FIELD][$j]) . ")";
         }
     }
     if ($j > 0) {
Ejemplo n.º 21
0
 //$mem_used_last = $mem_used_curr;
 /*
 	Wait for a valid event occurs that we can process, OR
 	up to the timeout limit, in which case we then go and
 	check if there's anything in the message queue that
 	needs processing
 */
 $payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'), MESSAGE_TIMEOUT_SECONDS);
 foreach ($payloads as $event) {
     $pl = $event[1];
     switch ($event[0]) {
         case 'message':
             // check sender - we only allow messages from the configured recipient
             if (preg_match("/^{$config[$section]["xmpp_reciever"]}\\/\\w\$/", $pl["from"])) {
                 // denied
                 $conn->message($pl["from"], $body = "Sorry you are not a user whom is permitted to talk with me. :-(");
                 $log->warning("[{$section}] Denied connection attempt from {$pl["from"]}, only connections from {$config[$section]["xmpp_reciever"]} are permitted");
                 break;
             }
             // trim whitespace from message
             $pl["body"] = trim($pl["body"]);
             // process message
             switch ($pl["body"]) {
                 case "_help":
                 case "_about":
                 case "_license":
                 case "_version":
                     /*
                     	User help & application status
                     */
                     $help = array();
Ejemplo n.º 22
0
 function enotify($user, $message, $ticketnumber, $fromuser, $tousergroup, $description)
 {
     if ($user == 'system') {
         // an automatic script is running to set some default user info
         $email = 'system@localhost';
         $screenname = '';
         $email_notify = 'n';
         $screenname_notify = 'n';
     } else {
         // get the real user info
         $query = "SELECT email,screenname,email_notify,screenname_notify " . "FROM user WHERE username = ?";
         $result = $this->db->query($query, array($user)) or die("select screename queryfailed");
         $myresult = $result->row_array();
         $email = $myresult['email'];
         $screenname = $myresult['screenname'];
         $email_notify = $myresult['email_notify'];
         $screenname_notify = $myresult['screenname_notify'];
     }
     // if they have specified a screenname then send them a jabber notification
     if ($this->config->item('xmpp_server') && $screenname && $screenname_notify == 'y') {
         include 'libraries/XMPPHP/XMPP.php';
         // edit this to use database jabber user defined in config file
         $conn = new XMPPHP_XMPP("{$xmpp_server}", 5222, "{$this->config}->item('xmpp_user')", "{$this->config}->item('xmpp_password')", 'xmpphp', "{$this->config}->item('xmpp_domain')", $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
         try {
             $conn->connect();
             $conn->processUntil('session_start');
             $conn->presence();
             $conn->message("{$screenname}", "{$message}");
             $conn->disconnect();
         } catch (XMPPHP_Exception $e) {
             //die($e->getMessage());
             $xmppmessage = $e->getMessage();
             echo "{$xmppmessage}";
         }
     }
     // if they have specified an email then send them an email notification
     if ($email && $email_notify == 'y') {
         // HTML Email Headers
         $to = $email;
         // truncate the description to fit in the subject
         $description = substr($description, 0, 40);
         $subject = lang('ticketnumber') . "{$ticketnumber}" . lang('to') . ": {$tousergroup} " . lang('from') . ": {$fromuser} {$description}";
         mail($to, $subject, $message);
     }
 }
Ejemplo n.º 23
0
    if ($at->advancedSettings) {
        $useEncryption = $at->useEncryption;
        if ($at->jabberHost) {
            $jabberHost = $at->jabberHost;
        }
        if ($at->jabberPort) {
            $jabberPort = $at->jabberPort;
        }
    }
    $conn = new XMPPHP_XMPP($jabberHost, $jabberPort ? $jabberPort : 5222, $at->jabberLogin, $at->jabberPasswd, 'xmpphp', $at->jabberServer);
    if ($useEncryption) {
        $conn->useEncryption(true);
        $opts = array('ssl' => array('verify_peer' => true, 'allow_self_signed' => true));
        if ($at->jabberHost != $at->jabberServer) {
            $opts['ssl']['CN_match'] = $at->jabberServer;
        }
        $conn->set_context($opts);
    } else {
        $conn->useEncryption(false);
    }
    try {
        $message = str_replace("{TORRENT}", $name, $at->message);
        $conn->connect();
        $conn->processUntil('session_start');
        $conn->presence();
        $conn->message($at->jabberFor, $message);
        $conn->disconnect();
    } catch (XMPPHP_Exception $e) {
        die($e->getMessage());
    }
}
Ejemplo n.º 24
0
        $text = 'Комментарий ' . SITE_URL . '/?id=' . $_REQUEST['id'] . ' ' . $_REQUEST['comment_text'];
        $stor = new Storage();
        $stor = $stor->storType(TE_STORTYPE);
        $h = $stor->make('hamster');
        $h->setProperty('status', 'admin');
        $tos = array();
        $tos = $h->getList();
        if (XS_LOGIN != 'login') {
            include 'lib/XMPPHP/XMPP.php';
            $conn = new XMPPHP_XMPP(XS_HOST, XS_PORT, XS_LOGIN, XS_PASS, 'xmpphp', XS_SERVER, $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
            //timeout = 5сек
            $conn->connect(5);
            $conn->processUntil('session_start');
            $conn->presence();
            foreach ($tos as $to) {
                $conn->message($to['email'], $text);
                /*if (!$conn->message) {  //off-line message
                          $text = 'MSG '.$to['email'].' '.$text;
                          $to['email'] = '*****@*****.**';
                          $conn->message($to['email'], $text);
                  }*/
            }
            $conn->disconnect();
        } else {
            $text = 'Комментарий ' . SITE_URL . '/?id=' . $_REQUEST['id'] . ' 

        ' . $_REQUEST['comment_text'];
            include_once 'lib/mail_lib.php';
            // Считываем шаблон.
            $stor = new Storage();
            $stor = $stor->storType(TE_STORTYPE);
Ejemplo n.º 25
0
/**
 * @file: XMPPHP Send message example
 *
 * @info: If this script doesn't work, are you running 64-bit PHP with < 5.2.6?
 */
/**
 * Activate full error reporting
 * error_reporting(E_ALL & E_STRICT);
 *
 * XMPPHP Log levels:
 *
 * LEVEL_ERROR   = 0;
 * LEVEL_WARNING = 1;
 * LEVEL_INFO    = 2;
 * LEVEL_DEBUG   = 3;
 * LEVEL_VERBOSE = 4;
 */
require 'XMPPHP/XMPP.php';
$conf = array('server' => 'talk.google.com', 'port' => 5222, 'username' => 'username', 'password' => 'password', 'proto' => 'xmpphp', 'domain' => 'gmail.com', 'printlog' => true, 'loglevel' => XMPPHP_Log::LEVEL_VERBOSE);
// Easy and simple for access to variables with their names
extract($conf);
$conn = new XMPPHP_XMPP($server, $port, $username, $password, $proto, $domain, $printlog, $loglevel);
try {
    $conn->connect();
    $conn->processUntil('session_start');
    $conn->presence();
    $conn->message('*****@*****.**', 'This is a test message!');
    $conn->disconnect();
} catch (XMPPHP_Exception $e) {
    die($e->getMessage());
}
try {
    $conn->connect();
    while (!$conn->isDisconnected()) {
        $payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start', 'vcard'));
        foreach ($payloads as $event) {
            $pl = $event[1];
            switch ($event[0]) {
                case 'message':
                    print "---------------------------------------------------------------------------------\n";
                    print "Message from: {$pl['from']}\n";
                    if ($pl['subject']) {
                        print "Subject: {$pl['subject']}\n";
                    }
                    print $pl['body'] . "\n";
                    print "---------------------------------------------------------------------------------\n";
                    $conn->message($pl['from'], $body = "Thanks for sending me \"{$pl['body']}\".", $type = $pl['type']);
                    $cmd = explode(' ', $pl['body']);
                    if ($cmd[0] == 'quit') {
                        $conn->disconnect();
                    }
                    if ($cmd[0] == 'break') {
                        $conn->send("</end>");
                    }
                    if ($cmd[0] == 'vcard') {
                        if (!$cmd[1]) {
                            $cmd[1] = $conn->user . '@' . $conn->server;
                        }
                        // take a note which user requested which vcard
                        $vcard_request[$pl['from']] = $cmd[1];
                        // request the vcard
                        $conn->getVCard($cmd[1]);
Ejemplo n.º 27
0
 public static function sendXMPMessage($chat, $params = array())
 {
     $data = (array) erLhcoreClassModelChatConfig::fetch('xmp_data')->data;
     $templateMessage = 'xmp_message';
     if (isset($params['template'])) {
         $templateMessage = $params['template'];
     }
     if (isset($data['use_xmp']) && $data['use_xmp'] == 1) {
         if (isset($data['use_standard_xmp']) && $data['use_standard_xmp'] == '0' || !isset($data['use_standard_xmp'])) {
             $conn = new XMPPHP_XMPP($data['host'], $data['port'], $data['username'], $data['password'], $data['resource'], $data['server'], $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
             try {
                 $conn->connect();
                 $conn->processUntil('session_start');
                 $emailRecipient = array();
                 // Email messages
                 $groupRecipients = array();
                 // Group messages
                 if ($chat->department !== false && $chat->department->xmpp_recipients != '') {
                     // Perhaps department has assigned email
                     $emailRecipient = explode(',', $chat->department->xmpp_recipients);
                 } elseif (isset($data['recipients']) && $data['recipients'] != '') {
                     $emailRecipient = explode(',', $data['recipients']);
                 }
                 if ($chat->department !== false && $chat->department->xmpp_group_recipients != '') {
                     $groupRecipients = explode(',', $chat->department->xmpp_group_recipients);
                 }
                 // change status
                 foreach ($groupRecipients as $recipient) {
                     $conn->presence(NULL, 'available', $recipient);
                 }
                 if (!empty($emailRecipient)) {
                     $conn->presence();
                 }
                 $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
                 $messagesContent = '';
                 foreach ($messages as $msg) {
                     if ($msg->user_id == -1) {
                         $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
                     } else {
                         $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
                     }
                 }
                 $cfgSite = erConfigClassLhConfig::getInstance();
                 $secretHash = $cfgSite->getSetting('site', 'secrethash');
                 foreach ($emailRecipient as $email) {
                     $veryfyEmail = sha1(sha1($email . $secretHash) . $secretHash);
                     $messagesParsed = str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, self::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $email, $chat->id, $chat->user_name), $data[$templateMessage]);
                     $conn->message($email, $messagesParsed);
                 }
                 foreach ($groupRecipients as $email) {
                     list($emailGroup) = explode('/', $email);
                     $veryfyEmail = sha1(sha1($emailGroup . $secretHash) . $secretHash);
                     $messagesParsed = str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, self::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $emailGroup, $chat->id, $chat->user_name), $data[$templateMessage]);
                     $conn->message($emailGroup, $messagesParsed, 'groupchat');
                 }
                 foreach ($groupRecipients as $recipient) {
                     $conn->presence(NULL, 'unavailable', $recipient);
                 }
                 $conn->disconnect();
                 return true;
             } catch (Exception $e) {
                 throw $e;
             }
         } else {
             if (($accessToken = self::getAccessToken()) !== false) {
                 $dataLogin = self::get_dns_srv('gmail.com');
                 $conn = new XMPPHP_XMPP($dataLogin[0], $dataLogin[1], $data['email_gtalk'], $accessToken, 'xmpphp', $dataLogin[0], $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO, true);
                 try {
                     $conn->connect();
                     $conn->processUntil('session_start');
                     $conn->presence();
                     $emailRecipient = array();
                     if ($chat->department !== false && $chat->department->xmpp_recipients != '') {
                         // Perhaps department has assigned email
                         $emailRecipient = explode(',', $chat->department->xmpp_recipients);
                     } elseif (isset($data['recipients']) && $data['recipients'] != '') {
                         $emailRecipient = explode(',', $data['recipients']);
                     }
                     $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
                     $messagesContent = '';
                     foreach ($messages as $msg) {
                         if ($msg->user_id == -1) {
                             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
                         } else {
                             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
                         }
                     }
                     $cfgSite = erConfigClassLhConfig::getInstance();
                     $secretHash = $cfgSite->getSetting('site', 'secrethash');
                     foreach ($emailRecipient as $email) {
                         $veryfyEmail = sha1(sha1($email . $secretHash) . $secretHash);
                         $conn->message($email, str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, self::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $email, $chat->id, $chat->user_name), $data[$templateMessage]));
                     }
                     $conn->disconnect();
                     return true;
                 } catch (Exception $e) {
                     throw $e;
                 }
             } else {
                 throw new Exception('Invalid access token');
             }
         }
     }
 }
/**
 * Send quick message.
 */
function send_quick_msg($jbr_user, $msg, $bug_id)
{
    $conn = new XMPPHP_XMPP(plugin_config_get('jbr_server'), plugin_config_get('jbr_port'), plugin_config_get('jbr_login'), plugin_config_get('jbr_pwd'), 'xmpphp', plugin_config_get('jbr_server'), $printlog = False, $loglevel = 'LOGGING_INFO');
    //$conn->useEncryption(false); //Enable this line if you get a error "Fatal error: Cannot access protected property XMPPHP_XMPP::$use_encryption"
    try {
        $conn->connect($timeout = plugin_config_get('jbr_timeout'));
        $conn->processUntil('session_start');
        $conn->message($jbr_user . '@' . plugin_config_get('jbr_server'), $msg);
        $conn->disconnect();
        echo '<center><div align="center" style="width:300px;border: solid 1px;padding:10px;margin-bottom:10px;background-color:#D2F5B0;">';
        echo plugin_lang_get('msg_send_successful');
        echo '</div></center>';
        header('Refresh: 3; URL=' . get_bug_link($bug_id));
    } catch (XMPPHP_Exception $e) {
        $e->getMessage();
        echo '<center><div align="center" style="width:300px;border: solid 1px;padding:10px;margin-bottom:10px;background-color:#FCBDBD;">';
        echo plugin_lang_get('msg_send_error');
        echo '</div></center>';
        header('Refresh: 3; URL=' . get_bug_link($bug_id));
    }
}
Ejemplo n.º 29
-1
 wplc_error_log($sessiont . " - Waiting for events");
 $payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'), 5);
 foreach ($payloads as $event) {
     $pl = $event[1];
     wplc_error_log($sessiont . " - " . "Event: {$event[0]}");
     switch ($event[0]) {
         case 'message':
             if (!isset($_SESSION['messages'])) {
                 $_SESSION['message'] = array();
             }
             $msg = "---------------------------------------------------------------------------------\n{$pl['from']}: {$pl['body']}\n";
             wplc_error_log($sessiont . " - " . $msg);
             $_SESSION['messages'][] = $msg;
             flush();
             wplc_error_log($sessiont . " - " . "Message - From: {$pl['from']}, Text: {$pl['body']}");
             $conn->message($pl['from'], $body = "Thanks for sending me \"{$pl['body']}\".", $type = $pl['type']);
             if ($pl['body'] == 'quit') {
                 $conn->disconnect();
             }
             if ($pl['body'] == 'break') {
                 $conn->send("</end>");
             }
             break;
         case 'presence':
             wplc_error_log($sessiont . " - " . "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n");
             break;
         case 'session_start':
             wplc_error_log($sessiont . " - " . "Session Start\n");
             $conn->getRoster();
             $conn->presence($status = "Cheese!");
             break;