示例#1
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());
    }
}
示例#2
0
                     }
                     // end of actual message
                     break;
             }
             break;
         case 'presence':
             $log->debug("[{$section}] Presence notification from " . $pl["from"] . " with status of " . $pl["status"] . "");
             break;
         case 'session_start':
             $log->debug("[{$section}] Established XMPP connection & listening for inbound requests");
             // Online and Ready
             $conn->getRoster();
             // Clear current healthcheck status to trigger presence notification
             $current_status = null;
             // allow any user to subscribe - but we validate that only certain users can message us
             $conn->autoSubscribe(true);
             // send user a welcome
             $conn->message($config[$section]["xmpp_reciever"], $body = "" . APP_NAME . " (" . APP_VERSION . ") started", $type = "chat");
             $conn->message($config[$section]["xmpp_reciever"], $body = "Type \"_help\" for usage and option information", $type = "chat");
             // note about dynamic/auto GW?
             if ($config[$section]["gw_path"] == "auto" || $config[$section]["gw_path"] == "dynamic") {
                 $conn->message($config[$section]["xmpp_reciever"], $body = "Note: This gateway is configured to be discovered automatically - you will be unable to send SMS via XMPP until the gateway first sends a message through to XMPP and reveals it's address. You can avoid this behaviour by statically assigning the device IP and adding it to the configuration.");
             }
             // ready
             $log->info("[{$section}] Ready to process messages");
             break;
         case 'end_stream':
             $log->debug("[{$section}] User closed our XMPP session");
             break;
     }
 }
<?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') {
示例#4
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;
}