Esempio n. 1
0
 public static function init($jaxl)
 {
     // initialize working parameters for this jaxl instance
     $jaxl->bosh = array('host' => 'localhost', 'port' => 5280, 'suffix' => 'http-bind', 'out' => true, 'outheaders' => 'Content-type: application/json', 'cookie' => array('ttl' => 3600, 'path' => '/', 'domain' => false, 'https' => false, 'httponly' => true), 'hold' => '1', 'wait' => '30', 'polling' => '0', 'version' => '1.6', 'xmppversion' => '1.0', 'secure' => true, 'content' => 'text/xml; charset=utf-8', 'headers' => array('Accept-Encoding: gzip, deflate', 'Content-Type: text/xml; charset=utf-8'), 'xmlns' => 'http://jabber.org/protocol/httpbind', 'xmlnsxmpp' => 'urn:xmpp:xbosh', 'url' => 'http://localhost:5280/http-bind');
     // parse user options
     $jaxl->bosh['host'] = $jaxl->getConfigByPriority($jaxl->config['boshHost'], "JAXL_BOSH_HOST", $jaxl->bosh['host']);
     $jaxl->bosh['port'] = $jaxl->getConfigByPriority($jaxl->config['boshPort'], "JAXL_BOSH_PORT", $jaxl->bosh['port']);
     $jaxl->bosh['suffix'] = $jaxl->getConfigByPriority($jaxl->config['boshSuffix'], "JAXL_BOSH_SUFFIX", $jaxl->bosh['suffix']);
     $jaxl->bosh['out'] = $jaxl->getConfigByPriority($jaxl->config['boshOut'], "JAXL_BOSH_OUT", $jaxl->bosh['out']);
     $jaxl->bosh['url'] = "http://" . $jaxl->bosh['host'] . ":" . $jaxl->bosh['port'] . "/" . $jaxl->bosh['suffix'] . "/";
     // cookie params
     $jaxl->bosh['cookie']['ttl'] = $jaxl->getConfigByPriority($jaxl->config['boshCookieTTL'], "JAXL_BOSH_COOKIE_TTL", $jaxl->bosh['cookie']['ttl']);
     $jaxl->bosh['cookie']['path'] = $jaxl->getConfigByPriority($jaxl->config['boshCookiePath'], "JAXL_BOSH_COOKIE_PATH", $jaxl->bosh['cookie']['path']);
     $jaxl->bosh['cookie']['domain'] = $jaxl->getConfigByPriority($jaxl->config['boshCookieDomain'], "JAXL_BOSH_COOKIE_DOMAIN", $jaxl->bosh['cookie']['domain']);
     $jaxl->bosh['cookie']['https'] = $jaxl->getConfigByPriority($jaxl->config['boshCookieHTTPS'], "JAXL_BOSH_COOKIE_HTTPS", $jaxl->bosh['cookie']['https']);
     $jaxl->bosh['cookie']['httponly'] = $jaxl->getConfigByPriority($jaxl->config['boshCookieHTTPOnly'], "JAXL_BOSH_COOKIE_HTTP_ONLY", $jaxl->bosh['cookie']['httponly']);
     session_set_cookie_params($jaxl->bosh['cookie']['ttl'], $jaxl->bosh['cookie']['path'], $jaxl->bosh['cookie']['domain'], $jaxl->bosh['cookie']['https'], $jaxl->bosh['cookie']['httponly']);
     session_start();
     JAXLPlugin::add('jaxl_post_bind', array('JAXL0124', 'postBind'));
     JAXLPlugin::add('jaxl_send_xml', array('JAXL0124', 'wrapBody'));
     JAXLPlugin::add('jaxl_pre_handler', array('JAXL0124', 'preHandler'));
     JAXLPlugin::add('jaxl_post_handler', array('JAXL0124', 'postHandler'));
     JAXLPlugin::add('jaxl_send_body', array('JAXL0124', 'sendBody'));
     self::loadSession($jaxl);
 }
Esempio n. 2
0
 public static function init($jaxl)
 {
     $jaxl->features[] = self::$ns;
     JAXLXml::addTag('iq', 'time', '//iq/time/@xmlns');
     JAXLXml::addTag('iq', 'timeTZO', '//iq/time/tzo');
     JAXLXml::addTag('iq', 'timeUTC', '//iq/time/utc');
     JAXLPlugin::add('jaxl_get_iq_get', array('JAXL0202', 'handleIq'));
 }
Esempio n. 3
0
 public static function init($jaxl)
 {
     $jaxl->features[] = self::$ns;
     JAXLXml::addTag('iq', 'softwareName', '//iq/query[@xmlns="' . self::$ns . '"]/name');
     JAXLXml::addTag('iq', 'softwareVersion', '//iq/query[@xmlns="' . self::$ns . '"]/version');
     JAXLXml::addTag('iq', 'softwareOS', '//iq/query[@xmlns="' . self::$ns . '"]/os');
     JAXLPlugin::add('jaxl_get_iq_get', array('JAXL0092', 'getIq'));
 }
Esempio n. 4
0
 public static function init($jaxl)
 {
     $jaxl->features[] = self::$ns;
     JAXLXml::addTag('message', 'request', '//message/request/@xmlns');
     JAXLXml::addTag('message', 'received', '//message/received/@xmlns');
     JAXLXml::addTag('message', 'receivedId', '//message/received/@id');
     JAXLPlugin::add('jaxl_get_message', array('JAXL0184', 'handleMessage'));
 }
Esempio n. 5
0
 public static function init($jaxl)
 {
     $jaxl->features[] = self::$ns;
     JAXLXml::addTag('message', 'composing', '//message/composing/@xmlns');
     JAXLXml::addTag('message', 'active', '//message/active/@xmlns');
     JAXLXml::addTag('message', 'inactive', '//message/inactive/@xmlns');
     JAXLXml::addTag('message', 'paused', '//message/paused/@xmlns');
     JAXLXml::addTag('message', 'gone', '//message/gone/@xmlns');
     JAXLPlugin::add('jaxl_get_message', array('JAXL0085', 'getMessage'));
 }
Esempio n. 6
0
 public static function init($jaxl, $config = array())
 {
     $jaxl->features[] = self::$ns['info'];
     $jaxl->features[] = self::$ns['item'];
     self::$category = isset($config['category']) ? $config['category'] : 'client';
     self::$type = isset($config['type']) ? $config['type'] : 'bot';
     self::$name = isset($config['name']) ? $config['name'] : 'Jaxl';
     self::$lang = isset($config['lang']) ? $config['lang'] : 'en';
     // register callbacks
     JAXLPlugin::add('jaxl_get_iq_get', array('JAXL0030', 'handleIq'));
 }
Esempio n. 7
0
 public static function init($jaxl)
 {
     $jaxl->features[] = self::$ns;
     $jaxl->pingInterval = 0;
     $jaxl->pingInterval = $jaxl->getConfigByPriority($jaxl->config['pingInterval'], "JAXL_PING_INTERVAL", $jaxl->pingInterval);
     if ($jaxl->pingInterval > 0) {
         JAXLCron::add(array('JAXL0199', 'ping'), $jaxl->pingInterval, $jaxl->domain, $jaxl->jid, array('JAXL0199', 'pinged'));
     }
     JAXLXml::addTag('iq', 'ping', '//iq/ping/@xmlns');
     JAXLPlugin::add('jaxl_get_iq_get', array('JAXL0199', 'handleIq'));
 }
Esempio n. 8
0
 public static function init($jaxl)
 {
     // initialize working parameter for this jaxl instance
     $jaxl->comp = array('host' => false, 'pass' => false);
     // parse user options
     $jaxl->comp['host'] = isset($jaxl->config['compHost']) ? $jaxl->config['compHost'] : (@constant("JAXL_COMPONENT_HOST") == null ? $jaxl->comp['host'] : JAXL_COMPONENT_HOST);
     $jaxl->comp['pass'] = isset($jaxl->config['compPass']) ? $jaxl->config['compPass'] : (@constant("JAXL_COMPONENT_PASS") == null ? $jaxl->comp['pass'] : JAXL_COMPONENT_PASS);
     // register required callbacks
     JAXLPlugin::add('jaxl_post_start', array('JAXL0114', 'handshake'));
     JAXLPlugin::add('jaxl_pre_handler', array('JAXL0114', 'preHandler'));
 }
Esempio n. 9
0
 public static function init($jaxl)
 {
     $jaxl->features[] = self::$ns['info'];
     $jaxl->features[] = self::$ns['items'];
     JAXLXml::addTag('iq', 'identityCategory', '//iq/query/identity/@category');
     JAXLXml::addTag('iq', 'identityText', '//iq/query/identity/@text');
     JAXLXml::addTag('iq', 'identityName', '//iq/query/identity/@name');
     JAXLXml::addTag('iq', 'identityLang', '//iq/query/identity/@xml:lang');
     JAXLXml::addTag('iq', 'featureVar', '//iq/query/feature/@var');
     // register callbacks
     JAXLPlugin::add('jaxl_get_iq_get', array('JAXL0030', 'handleIq'));
 }
Esempio n. 10
0
 public static function init($jaxl)
 {
     JAXLPlugin::add('jaxl_post_bind', array('JAXL0124', 'postBind'));
     JAXLPlugin::add('jaxl_send_xml', array('JAXL0124', 'wrapBody'));
     JAXLPlugin::add('jaxl_pre_handler', array('JAXL0124', 'preHandler'));
     JAXLPlugin::add('jaxl_post_handler', array('JAXL0124', 'postHandler'));
     JAXLPlugin::add('jaxl_get_body', array('JAXL0124', 'processBody'));
     JAXLPlugin::add('jaxl_pre_curl', array('JAXL0124', 'saveSession'));
     JAXLPlugin::add('jaxl_send_body', array('JAXL0124', 'sendBody'));
     self::setEnv($jaxl);
     self::loadSession($jaxl);
 }
Esempio n. 11
0
// Demo requires VCard XEP
$xmpp->requires('JAXL0054');
function postConnect($payload, $xmpp)
{
    $xmpp->startStream();
}
function doAuth($mechanism, $xmpp)
{
    $xmpp->auth('DIGEST-MD5');
}
function postAuth($payload, $xmpp)
{
    $xmpp->JAXL0054('getVCard', false, $xmpp->jid, 'handleVCard');
}
function handleVCard($payload, $xmpp)
{
    echo "<b>Successfully fetched VCard</b><br/>";
    print_r($payload);
    $xmpp->shutdown();
}
function postAuthFailure($payload, $xmpp)
{
    echo "OOPS! Auth failed";
}
// Register callbacks for required events
JAXLPlugin::add('jaxl_post_connect', 'postConnect');
JAXLPlugin::add('jaxl_get_auth_mech', 'doAuth');
JAXLPlugin::add('jaxl_post_auth', 'postAuth');
JAXLPlugin::add('jaxl_post_auth_failure', 'postAuthFailure');
// Fire start JAXL Core
$xmpp->startCore();
Esempio n. 12
0
 public static function iq($type, $payload = false, $to = false, $from = false, $callback = false, $jaxl, $id = false, $ns = 'jabber:client')
 {
     if ($type == 'get' || $type == 'set') {
         $id = $jaxl->getId();
         if ($callback) {
             JAXLPlugin::add('jaxl_get_iq_' . $id, $callback);
         }
     }
     $types = array('get', 'set', 'result', 'error');
     $xml = '';
     $xml .= '<iq';
     $xml .= ' type="' . $type . '"';
     $xml .= ' id="' . $id . '"';
     if ($to) {
         $xml .= ' to="' . $to . '"';
     }
     if ($from) {
         $xml .= ' from="' . $from . '"';
     }
     $xml .= '>';
     if ($payload) {
         $xml .= $payload;
     }
     $xml .= '</iq>';
     self::xml($xml, $jaxl);
     if ($type == 'get' || $type == 'set') {
         return $id;
     } else {
         return true;
     }
 }
Esempio n. 13
0
 public static function init()
 {
     JAXLPlugin::add('jaxl_get_xml', array('JAXLCron', 'ticker'));
 }
Esempio n. 14
0
 /**
  * Use this method instead of JAXLPlugin::add to register a callback for connected instance only
  */
 function addPlugin($hook, $callback, $priority = 10)
 {
     JAXLPlugin::add($hook, $callback, $priority, $this->uid);
 }
Esempio n. 15
0
 public static function init($jaxl)
 {
     $jaxl->features[] = self::$ns;
     JAXLXml::addTag('iq', 'ping', '//iq/ping/@xmlns');
     JAXLPlugin::add('jaxl_get_iq_get', array('JAXL0199', 'handleIq'));
 }
Esempio n. 16
0
 /**
  * Starts Jaxl Core
  *
  * This method should be called after Jaxl initialization and hook registration inside your application code
  * Optionally, you can pass 'jaxl_post_connect' and 'jaxl_get_auth_mech' response type directly to this method
  * In that case application code SHOULD NOT register callbacks to above mentioned hooks
  *
  * @param string $arg[0] Optionally application code can pre-choose what Jaxl core should do after establishing socket connection.
  *                            Following are the valid options:
  *                            a) startStream
  *                            b) startComponent
  *                            c) startBosh
  */
 function startCore($mode = false)
 {
     if ($mode) {
         switch ($mode) {
             case 'stream':
                 JAXLPlugin::add('jaxl_post_connect', array($this, 'startStream'));
                 break;
             case 'component':
                 JAXLPlugin::add('jaxl_post_connect', array($this, 'startComponent'));
                 break;
             case 'bosh':
                 $this->startBosh();
                 break;
             default:
                 break;
         }
     }
     if ($this->mode == 'cli') {
         try {
             if ($this->connect()) {
                 while ($this->stream) {
                     $this->getXML();
                 }
             }
         } catch (Exception $e) {
             die($e->getMessage);
         }
         /* Exit Jaxl after end of loop */
         exit;
     }
 }
Esempio n. 17
0
 * Usage: php componentbot.php
 * Read more: http://bit.ly/aGpYf8
 */
// Initialize Jaxl Library
require_once '../core/jaxl.class.php';
$jaxl = new JAXL(array('port' => 5559, 'compHost' => 'component.localhost', 'compPass' => '', 'logLevel' => 5));
// Include required XEP's
$jaxl->requires('JAXL0114');
// Jabber Component Protocol
// Sample Component class
class componentbot
{
    function postAuth($payload, $jaxl)
    {
        $jaxl->log("Component handshake completed ...");
    }
    function getMessage($payloads, $jaxl)
    {
        foreach ($payloads as $payload) {
            if (strlen($payload['body']) > 0) {
                $jaxl->sendMessage($payload['from'], $payload['body'], $payload['to']);
            }
        }
    }
}
// Add callbacks on various event handlers
$componentbot = new componentbot();
JAXLPlugin::add('jaxl_post_handshake', array($componentbot, 'postAuth'));
JAXLPlugin::add('jaxl_get_message', array($componentbot, 'getMessage'));
// Fire start Jaxl core
$jaxl->startCore("component");
Esempio n. 18
0
            }
        }
    }
    function getPresence($payloads)
    {
        global $jaxl;
        foreach ($payloads as $payload) {
            if ($payload['type'] == "subscribe") {
                // accept subscription
                $jaxl->subscribed($payload['from']);
                // go for mutual subscription
                $jaxl->subscribe($payload['from']);
            } else {
                if ($payload['type'] == "unsubscribe") {
                    // accept subscription
                    $jaxl->unsubscribed($payload['from']);
                    // go for mutual subscription
                    $jaxl->unsubscribe($payload['from']);
                }
            }
        }
    }
}
// Add callbacks on various event handlers
$echobot = new echobot();
JAXLPlugin::add('jaxl_post_connect', array($echobot, 'startStream'));
JAXLPlugin::add('jaxl_get_auth_mech', array($echobot, 'doAuth'));
JAXLPlugin::add('jaxl_post_auth', array($echobot, 'postAuth'));
JAXLPlugin::add('jaxl_get_message', array($echobot, 'getMessage'));
JAXLPlugin::add('jaxl_get_presence', array($echobot, 'getPresence'));
Esempio n. 19
0
 public static function init()
 {
     JAXLPlugin::add('jaxl_post_connect', array('JAXL0114', 'startStream'));
     JAXLPlugin::add('jaxl_post_start', array('JAXL0114', 'handshake'));
     JAXLPlugin::add('jaxl_pre_handler', array('JAXL0114', 'preHandler'));
 }
Esempio n. 20
0
 public static function init()
 {
     global $jaxl;
     $jaxl->features[] = self::$ns;
     JAXLPlugin::add('jaxl_get_iq_get', array('JAXL0012', 'getIq'));
 }
Esempio n. 21
0
         $response = array('jaxl' => 'pinged');
         $jaxl->JAXL0206('out', $response);
     }
     public static function postAuthFailure($payload, $jaxl)
     {
         $response = array('jaxl' => 'authFailed');
         $jaxl->JAXL0206('out', $response);
     }
 }
 // Add callbacks on various event handlers
 JAXLPlugin::add('jaxl_post_auth_failure', array('boshchat', 'postAuthFailure'));
 JAXLPlugin::add('jaxl_post_auth', array('boshchat', 'postAuth'));
 JAXLPlugin::add('jaxl_post_disconnect', array('boshchat', 'postDisconnect'));
 JAXLPlugin::add('jaxl_get_empty_body', array('boshchat', 'postEmptyBody'));
 JAXLPlugin::add('jaxl_get_message', array('boshchat', 'getMessage'));
 JAXLPlugin::add('jaxl_get_presence', array('boshchat', 'getPresence'));
 // Handle incoming bosh request
 switch ($_REQUEST['jaxl']) {
     case 'connect':
         $jaxl->user = $_POST['user'];
         $jaxl->pass = $_POST['pass'];
         $jaxl->startCore('bosh');
         break;
     case 'disconnect':
         $jaxl->JAXL0206('endStream');
         break;
     case 'getRosterList':
         $jaxl->getRosterList(array('boshchat', 'handleRosterList'));
         break;
     case 'setStatus':
         $jaxl->setStatus(FALSE, FALSE, FALSE, TRUE);
Esempio n. 22
0
// Include required XEP's
$xmpp->requires(array('JAXL0054', 'JAXL0206'));
function doAuth($mechanism, $xmpp)
{
    $xmpp->auth('DIGEST-MD5');
}
function postAuth($payload, $xmpp)
{
    $xmpp->JAXL0054('getVCard', false, $xmpp->jid, 'handleVCard');
}
function handleVCard($payload, $xmpp)
{
    echo "<b>Successfully fetched VCard</b><br/>";
    print_r($payload);
    $xmpp->JAXL0206('endStream');
}
function postDisconnect($payload, $xmpp)
{
    exit;
}
function postAuthFailure($payload, $xmpp)
{
    echo "OOPS! Auth failed";
}
// Register callbacks for required events
JAXLPlugin::add('jaxl_get_auth_mech', 'doAuth');
JAXLPlugin::add('jaxl_post_auth', 'postAuth');
JAXLPlugin::add('jaxl_post_auth_failure', 'postAuthFailure');
JAXLPlugin::add('jaxl_post_disconnect', 'postDisconnect');
// Fire start Jaxl in bosh mode
$xmpp->startCore('bosh');
Esempio n. 23
0
<?php

/**
 * Sample command line bot for sending a message
 * Usage: php sendMessage.php "*****@*****.**" "Your message"
 */
// Initialize Jaxl Library
require_once '../core/jaxl.class.php';
// Values passed to the constructor can also be defined as constants
// List of constants can be found inside "../../env/jaxl.ini"
// Note: Values passed to the constructor always overwrite defined constants
$jaxl = new JAXL(array('user' => '', 'pass' => '', 'host' => 'talk.google.com', 'domain' => 'gmail.com', 'authType' => 'PLAIN', 'logLevel' => 5));
// Post successful auth send desired message
function postAuth($payload, $jaxl)
{
    global $argv;
    $jaxl->sendMessage($argv[1], $argv[2]);
    $jaxl->shutdown();
}
// Register callback on required hooks
JAXLPlugin::add('jaxl_post_auth', 'postAuth');
// Fire start Jaxl core
$jaxl->startCore("stream");