/**
  * @return void
  */
 protected function connectXmpp()
 {
     $this->connection = new XMPPHP_XMPP($this->config['host'], $this->config['port'], $this->config['user'], $this->config['password'], $this->config['resource'], $this->config['server']);
     // TODO configurable: $this->connection->useEncryption(FALSE);
     $this->connection->connect();
     $this->connection->processUntil('session_start');
 }
Esempio n. 2
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);
}
 /**
  * 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;
 }
Esempio n. 4
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;
 }
Esempio n. 5
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());
     }
 }
Esempio n. 6
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();
 }
Esempio n. 7
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);
 }
Esempio n. 8
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());
    }
}
Esempio n. 9
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;
    }
}
Esempio n. 10
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!');
 }
Esempio n. 11
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;
 }
Esempio n. 12
0
function snapRegisterNewXmppUser($emailaddress)
{
    global $APPCONFIG;
    include_once '../extensions/XMPPHP/XMPPHP_XMPP.php';
    $conf = $APPCONFIG['XMPP'];
    $passwd = $conf['userpasswd'];
    $userJID = cleanString($emailaddress) . time() . '@' . $conf['server'];
    $conn = new XMPPHP_XMPP($conf['server'], $conf['port'], $conf['adminuser'], $conf['adminpasswd'], $conf['resource'], $conf['domain']);
    $conn->autoSubscribe(true);
    $conn->useEncryption(false);
    $resp = array();
    try {
        $conn->connect();
        $conn->processUntil('session_start');
        $conn->registerNewUser($userJID, $emailaddress, $passwd);
        $conn->processUntil('done');
        $conn->disconnect();
        return array('xmppuserid' => $userJID, 'xmpppasswd' => $passwd);
    } catch (XMPPHP_Exception $e) {
        return 0;
        //die($e->getMessage());
    }
}
Esempio 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) {
         }
     }
 }
Esempio n. 14
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);
     }
 }
Esempio n. 15
0
    define("XS_SERVER", "gmail.com");
    $reg = Registry::instance();
    if ($reg->get('new_comment') != false) {
        flush();
        $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'];
Esempio n. 16
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());
    }
}
 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));
    }
}
Esempio n. 19
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);
     }
 }
Esempio n. 20
0
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);
$conn->autoSubscribe();
try {
    if (isset($_SESSION['messages'])) {
        foreach ($_SESSION['messages'] as $message) {
            echo $message;
            flush();
        }
    } else {
        $_SESSION['messages'] = array();
    }
    $conn->connect('http://server.tld:5280/xmpp-httpbind', 1, true);
    $events = array('message', 'presence', 'end_stream', 'session_start', 'vcard');
    $payloads = $conn->processUntil($events);
    foreach ($payloads as $result) {
        list($event, $data) = $result;
        if (isset($data)) {
            extract($data);
        }
        switch ($event) {
            case 'message':
                if (!$body) {
                    break;
                }
                $cmd = explode(' ', $body);
                $msg = str_repeat('-', 80);
                $msg .= "\nMessage from: {$from}\n";
Esempio n. 21
0
/**
 * connect the configured Jabber account to the configured server
 *
 * @param string $resource Resource to connect (defaults to configured resource)
 *
 * @return XMPPHP connection to the configured server
 */
function jabber_connect($resource = null)
{
    static $conn = null;
    if (!$conn) {
        $conn = new XMPPHP_XMPP(common_config('xmpp', 'host') ? common_config('xmpp', 'host') : common_config('xmpp', 'server'), common_config('xmpp', 'port'), common_config('xmpp', 'user'), common_config('xmpp', 'password'), $resource ? $resource : common_config('xmpp', 'resource'), common_config('xmpp', 'server'), common_config('xmpp', 'debug') ? true : false, common_config('xmpp', 'debug') ? XMPPHP_Log::LEVEL_VERBOSE : null);
        if (!$conn) {
            return false;
        }
        $conn->autoSubscribe();
        $conn->useEncryption(common_config('xmpp', 'encryption'));
        try {
            $conn->connect(true);
            // true = persistent connection
        } catch (XMPPHP_Exception $e) {
            common_log(LOG_ERR, $e->getMessage());
            return false;
        }
        $conn->processUntil('session_start');
    }
    return $conn;
}
 /**
  * Custom connection function which also stores our connected state.
  * 
  * {@inheritdoc}
  */
 public function connect($timeout = 30, $persistent = false, $sendinit = true)
 {
     $return = parent::connect($timeout, $persistent, $sendinit);
     $this->connected = !$this->isDisconnected();
     return $return;
 }
Esempio n. 23
0
 /**
  * Checking if the given username exists and the given text password 
  * is correct by trying to connect to and authenticate on xmpp server.
  * @author del Rosario Ernesto <*****@*****.**>
  * @return bool
  */
 public static function check_username_and_password($user = "", $password = "", $conf = array())
 {
     if (empty($user) || empty($password) || !isset($conf["host"]) || !isset($conf["port"])) {
         return null;
     }
     $xmpp = new XMPPHP_XMPP($conf["host"], $conf["port"], $user, $password, $conf["resource"], $conf["server"], $conf["printlog"], $conf["loglevel"]);
     try {
         $xmpp->connect();
         $xmpp->processUntil('session_start');
         $xmpp->disconnect();
         return true;
     } catch (XMPPHP_Exception $e) {
         return false;
     }
 }