Пример #1
0
$bldcyn = chr(0x1b) . '[1;36m';
$bldwht = chr(0x1b) . '[1;37m';
$txtrst = chr(0x1b) . '[0m';
$XBOPTS['host'] = "127.0.0.1";
$XBOPTS['port'] = 8000;
$XBOPTS['usermd5'] = md5("user:password");
$XBOPTS['realm'] = "";
//$XBOPTS['profile'] = true;
global $XBAR;
$XBAR = new CrossBar($XBOPTS);
// See if we can make a connection
$USER_ID = '';
$ACCOUNT_ID = '';
$DEVICE_ID = '';
printf("{$bldblu}TEST: Authentication{$txtrst}\n");
if ($XBAR->is_authenticated()) {
    printf("{$bldgrn}PASS: Authentication Success.{$txtrst}\n\n");
    $TEMPLATE['name'] = 'supermegamega';
    $TEMPLATE['realm'] = 'supermega.example.com';
    $TEMPLATE['owner_id'] = $XBAR->auth_account_id;
    //Which ever user authed we will use that account is attached to
    $realm_id = $XBAR->get_account_id_by_realm($TEMPLATE['realm']);
    if (strlen($realm_id)) {
        printf("{$bldylw}WARN: {$bldred}Existing Account SKIPPING CREATION!{$txtrst}\n");
    } else {
        printf("{$bldblu}TEST: Create Account{$txtrst}\n");
        $resp = $XBAR->put_account($TEMPLATE);
        if ($resp['status'] == 'success') {
            printf("{$bldgrn}PASS: Account Creation Successful.{$txtrst}\n");
            $realm_id = $XBAR->get_account_id_by_realm($TEMPLATE['realm']);
        } else {