コード例 #1
0
ファイル: fetion.php プロジェクト: rfyiamcool/solrex
/**
 * register to server directly, wopwhite
 * 
 * @ssic user identification
 * @sid fetion id
 * @domain domain
 * @password real password
 */
function fetion_register($ssic, $sid, $domain, $password, $tunnel)
{
    $arg = '<args><device type="PC" version="44" client-version="3.2.0540" />';
    $arg .= '<caps value="simple-im;im-session;temp-group;personal-group" />';
    $arg .= '<events value="contact;permission;system-message;personal-group" />';
    $arg .= '<user-info attributes="all" /><presence><basic value="400" desc="" /></presence></args>';
    $nonce_regex = '/nonce="(\\w+)"/s';
    $ok_regex = '/OK/s';
    fetion_debug("wop begin register");
    $call = fetion_next_call();
    // First Register to get nonce
    $msg = fetion_sip_create('R fetion.com.cn SIP-C/2.0', array('F' => $sid, 'I' => $call, 'Q' => '1 R'), $arg);
    fetion_debug("wopwhite register");
    socket_write($tunnel, $msg, strlen($msg));
    // need IMPROVE, should use socket select, but hardcoded as 15 seconds for convenience
    sleep(15);
    $msg = socket_read($tunnel, 1024);
    fetion_debug("recv nonce...");
    $matches = array();
    if (!preg_match($nonce_regex, $msg, $matches)) {
        error_log('Fetion Error: no nonce found');
        return false;
    }
    $nonce = $matches[1];
    $salt = fetion_calc_salt($password);
    $cnonce = fetion_calc_cnonce();
    $response = fetion_calc_response($sid, $domain, $password, $nonce, $cnonce);
    fetion_debug("nonce: {$nonce}");
    fetion_debug("salt: {$salt}");
    fetion_debug("cnonce: {$cnonce}");
    fetion_debug("response: {$response}");
    // Second Register with response
    $msg = fetion_sip_create('R fetion.com.cn SIP-C/2.0', array('F' => $sid, 'I' => $call, 'Q' => '2 R', 'A' => "Digest algorithm=\"SHA1-sess\",response=\"{$response}\",cnonce=\"{$cnonce}\",salt=\"{$salt}\",ssic=\"{$ssic}\""), $arg);
    fetion_debug("send response...");
    socket_write($tunnel, $msg, strlen($msg));
    // need IMPROVE, should use socket select, but hardcoded as 5 seconds for convenience
    sleep(5);
    $msg = socket_read($tunnel, 1024);
    return preg_match($ok_regex, $msg);
}
コード例 #2
0
ファイル: fetion.php プロジェクト: babaloveyou1/uims
/**
 * register to server
 * 
 * @ssic user identification
 * @sid fetion id
 * @domain domain
 * @password real password
 */
function fetion_http_register($ssic, $sid, $domain, $password)
{
    $nonce_regex = '/nonce="(\\w+)"/s';
    $ok_regex = '/OK/s';
    $arg = '<args><device type="PC" version="44" client-version="3.2.0540" />';
    $arg .= '<caps value="simple-im;im-session;temp-group;personal-group" />';
    $arg .= '<events value="contact;permission;system-message;personal-group" />';
    $arg .= '<user-info attributes="all" /><presence><basic value="400" desc="" /></presence></args>';
    fetion_debug("begin register");
    $call = fetion_next_call();
    fetion_curl_exec(fetion_next_url(), $ssic, FETION_SIPP);
    $msg = fetion_sip_create('R fetion.com.cn SIP-C/2.0', array('F' => $sid, 'I' => $call, 'Q' => '1 R'), $arg) . FETION_SIPP;
    fetion_curl_exec(fetion_next_url('i'), $ssic, $msg);
    $msg = fetion_curl_exec(fetion_next_url(), $ssic, FETION_SIPP);
    fetion_debug("recv nonce...");
    $matches = array();
    if (!preg_match($nonce_regex, $msg, $matches)) {
        error_log('Fetion Error: no nonce found');
        return false;
    }
    $nonce = $matches[1];
    $salt = fetion_calc_salt($password);
    $cnonce = fetion_calc_cnonce();
    $response = fetion_calc_response($sid, $domain, $password, $nonce, $cnonce);
    fetion_debug("nonce: {$nonce}");
    fetion_debug("salt: {$salt}");
    fetion_debug("cnonce: {$cnonce}");
    fetion_debug("response: {$response}");
    $msg = fetion_sip_create('R fetion.com.cn SIP-C/2.0', array('F' => $sid, 'I' => $call, 'Q' => '2 R', 'A' => "Digest algorithm=\"SHA1-sess\",response=\"{$response}\",cnonce=\"{$cnonce}\",salt=\"{$salt}\""), $arg) . FETION_SIPP;
    fetion_debug("send response...");
    fetion_curl_exec(fetion_next_url(), $ssic, $msg);
    $msg = fetion_curl_exec(fetion_next_url(), $ssic, FETION_SIPP);
    return preg_match($ok_regex, $msg);
}