예제 #1
0
파일: Xmpp.php 프로젝트: ratibus/pflow
 /**
  * @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');
     }
 }
예제 #2
0
 /**
  * Override XMLStream's startXML
  *
  * @param parser $parser
  * @param string $name
  * @param array $attr
  */
 protected function startXML($parser, $name, $attr)
 {
     if ($this->xml_depth == 0 and $attr['version'] != '1.0') {
         $this->session_id = $attr['ID'];
         $this->authenticate();
     }
     parent::startXML($parser, $name, $attr);
 }
예제 #3
0
 /**
  * Override XMLStream's startXML
  *
  * @param parser $parser
  * @param string $name
  * @param array $attr
  */
 public function startXML($parser, $name, $attr)
 {
     if ($this->xml_depth == 0) {
         $this->session_id = $attr['ID'];
         $this->authenticate();
     }
     parent::startXML($parser, $name, $attr);
 }
예제 #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;
 }
예제 #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);
}
예제 #6
0
파일: Xmpp.php 프로젝트: tegansnyder/Logger
 /**
  * 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());
     }
 }
 /**
  * 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;
 }
예제 #8
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();
 }
예제 #9
0
 /**
  * Constructor
  *
  * @param string  $host
  * @param integer $port
  * @param string  $user
  * @param string  $password
  * @param string  $resource
  * @param string  $server
  * @param boolean $printlog
  * @param string  $loglevel
  */
 public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null)
 {
     parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
     // We use $host to connect, but $server to build JIDs if specified.
     // This seems to fix an upstream bug where $host was used to build
     // $this->basejid, never seen since it isn't actually used in the base
     // classes.
     if (!$server) {
         $server = $this->host;
     }
     $this->basejid = $this->user . '@' . $server;
     // Normally the fulljid is filled out by the server at resource binding
     // time, but we need to do it since we're not talking to a real server.
     $this->fulljid = "{$this->basejid}/{$this->resource}";
 }
예제 #10
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);
 }
예제 #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!');
 }
예제 #12
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());
    }
}
예제 #13
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;
    }
}
예제 #14
0
파일: jabber.php 프로젝트: Br3nda/laconica
/**
 * 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;
}
예제 #15
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());
    }
}
예제 #16
0
 public function __construct($jid, $password, $server = null)
 {
     $jidarr = split('@', $jid, 2);
     $server = $jidarr[1];
     $user = $jidarr[0];
     $host = 'xmpp.superfeedr.com';
     $this->addXPathHandler('{jabber:client}message/{http://jabber.org/protocol/pubsub#event}event/{http://superfeedr.com/xmpp-pubsub-ext}status', 'handle_superfeedr_msg');
     XMPPHP_XMPP::__construct($host, 5222, $user, $password, 'superfeedr', $server, false, XMPPHP_Log::LEVEL_INFO);
     print $jid;
     print $server;
     $this->connect();
     $payloads = $this->processUntil(array('session_start', 'end_stream'));
     foreach ($payloads as $event) {
         $pl = $event[1];
         switch ($event[0]) {
             case 'session_start':
                 break;
             case 'end_stream':
                 break;
         }
     }
 }
예제 #17
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;
 }
예제 #18
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) {
         }
     }
 }
예제 #19
0
파일: shadow.php 프로젝트: noisywiz/tractor
 define("XS_PASS", "password");
 //пароль
 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'] . ' 
예제 #20
0
$name = $argv[1];
$at = rXmpp::load();
if ($at->message !== '' && isset($at->jabberServer) && isset($at->jabberLogin) && isset($at->jabberPasswd) && isset($at->jabberFor)) {
    $useEncryption = true;
    $jabberHost = $at->jabberServer;
    $jabberPort = 5222;
    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();
예제 #21
0
 /**
  * Constructor
  *
  * Creates connection to the XMPP server, and loads all command classes.
  *
  * @return void
  */
 public function __construct()
 {
     // Load config
     $conf = parse_ini_file(dirname(__FILE__) . '/../../Config/JabberBot.ini', true);
     $this->_config = new JabberBot_Config($conf);
     $server = $this->_config->getValue('server');
     $this->rooms = array();
     $this->db = new JabberBot_Db('bot');
     $this->acl = new JabberBot_Acl();
     $botConf = $this->_config->getValue('bot');
     $this->defaultRoom = isset($botConf['defaultroom']) ? $botConf['defaultroom'] : null;
     $this->pingInverval = $botConf['pinginterval'];
     // Call parent constructor, and set variables
     parent::__construct($server['host'], $server['port'], $server['user'], $server['password'], $server['resource'], null, true, $botConf['loglevel']);
     $this->addEventHandler('reconnect', 'handleReconnect', $this);
     $this->useEncryption($server['ssl'] == 'true');
     // Set up Commands
     $commandBase = dirname(__FILE__) . '/Command/';
     foreach (scandir($commandBase) as $filename) {
         if (preg_match('/^(.*).class.php/', $filename)) {
             $this->log->log('Including ' . $commandBase . $filename, XMPPHP_Log::LEVEL_INFO);
             require_once $commandBase . $filename;
         }
     }
     $this->arrCommands = array();
     foreach (get_declared_classes() as $className) {
         if (get_parent_class($className) == 'JabberBot_Command') {
             $this->arrCommands[] = new $className($this);
             $this->log->log('Loaded Command: ' . $className, XMPPHP_Log::LEVEL_INFO);
         }
     }
     // Connect to the server
     try {
         $this->connect();
         $this->processUntil('session_start');
     } catch (Exception $e) {
         die('Failed to connect: ' . $e->getMessage());
     }
     // Connect to the default conference room, if set.
     if ($this->defaultRoom) {
         $this->enterRoom($this->defaultRoom);
     }
     // Announce our presence for private chats
     $this->presence();
     $this->resetPing();
 }
예제 #22
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());
}
예제 #23
0
 	Establish connection to the XMPP server
 */
 if (empty($config[$section]["xmpp_server"])) {
     $log->error_fatal("An XMPP server must be configured");
 }
 if (empty($config[$section]["xmpp_port"])) {
     // default protocol port
     $config[$section]["xmpp_port"] = "5222";
 }
 if (empty($config[$section]["xmpp_username"])) {
     $log->error_fatal("An XMPP user must be configured");
 }
 if (empty($config[$section]["xmpp_reciever"])) {
     $log->error_fatal("An XMPP reciever must be configured!");
 }
 $conn = new XMPPHP_XMPP($config[$section]["xmpp_server"], $config[$section]["xmpp_port"], $config[$section]["xmpp_username"], $config[$section]["xmpp_password"], $section, $config[$section]["xmpp_domain"], $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
 try {
     $conn->connect();
 } catch (XMPPHP_Exception $e) {
     die($e->getMessage());
 }
 /*
 	Launch gateway/device logic
 
 	All the gateway/device logic is broken into include files that are only loaded into
 	the particular worker fork which is using that gateway. If we can't load it for some
 	reason we should fail with an error to all the apps.
 */
 if (!$config[$section]["gw_type"]) {
     $log->error_fatal("There is no gateway set! Unable to proceed!");
 }
<?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('talk.google.com', 5222, 'spottersu', 'spotGSP11', 'xmpphp', 'gmail.com', $printlog = true, $loglevel = XMPPHP_Log::LEVEL_INFO);
$conn->autoSubscribe();
$vcard_request = array();
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') {
예제 #25
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');
             }
         }
     }
 }
예제 #26
0
파일: BOSH.php 프로젝트: Wordi/xmpphp
 public function disconnect()
 {
     parent::disconnect();
     unset($_SESSION['XMPPHP_BOSH_RID']);
     unset($_SESSION['XMPPHP_BOSH_SID']);
     unset($_SESSION['XMPPHP_BOSH_authed']);
     unset($_SESSION['XMPPHP_BOSH_basejid']);
     unset($_SESSION['XMPPHP_BOSH_fulljid']);
     unset($_SESSION['XMPPHP_BOSH_inactivity']);
     unset($_SESSION['XMPPHP_BOSH_lat']);
 }
예제 #27
0
 * 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);
$conn->autoSubscribe();
$vcard_request = array();
try {
    $conn->connect();
    while (!$conn->isDisconnected()) {
        $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) {
예제 #28
0
파일: nagnot.php 프로젝트: richadams/nagnot
////////////////////////////////////////////////////////////////////////////////////////////////////
// Functions
// Outputs a message
function output($m)
{
    echo "[" . date("Y-m-d h:i:s", mktime()) . "] " . $m . "\n";
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Do the work
include_once "xmpphp/XMPP.php";
output("Received instruction - (im:" . $INPUT['im'] . ",email:" . $INPUT['email'] . ",subject:" . $INPUT['subject'] . ",message:" . $INPUT['message'] . ")");
$im_sent = false;
// Try an IM
try {
    // Attempt to connect and get user roster.
    $conn = new XMPPHP_XMPP($XMPP['server'], $XMPP['port'], $XMPP['username'], $XMPP['password'], $XMPP['resource'], $XMPP['domain']);
    output("Connecting to IM server....");
    $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) {
예제 #29
0
$check = 1;
if ($check == 1) {
    if ($_POST['action'] == 'wplc_call_to_xmp_server_visitor') {
        wplc_error_log("[" . __LINE__ . "] NEW XMP REQUEST");
        if (defined('WPLC_TIMEOUT')) {
            set_time_limit(WPLC_TIMEOUT);
        } else {
            set_time_limit(120);
        }
        $i = 1;
        $array = array("check" => false);
        /* must record the session ID */
        include '/includes/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('server', 5222, 'user', 'pass', 'xmpphp', 'gmail.com', $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
        wplc_error_log("[" . __LINE__ . "] Connecting to XMP server");
        $conn->connect();
        $conn->processUntil('session_start');
        $conn->presence($status = 'Controller available.');
        // Enter the chatroom
        $conn->presence(NULL, "available", "chatroom@server/NickName");
        //$conn->message("chatroom@server", "Test!", "groupchat");
        while ($i < $iterations) {
            session_write_close();
            try {
                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]}");
/**
 * 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));
    }
}