コード例 #1
0
ファイル: insenz.func.php プロジェクト: jonycookie/projectm2
function insenz_request($data, $return = TRUE, $fp = '')
{
    global $insenz, $timestamp, $msglang;
    @(include_once DISCUZ_ROOT . './discuz_version.php');
    $authkey = !empty($insenz['authkey']) ? $insenz['authkey'] : 'Discuz!INSENZ';
    $t_hex = sprintf("%08x", $timestamp);
    $postdata = '<?xml version="1.0" encoding="UTF' . '-8"?><request insenz_version="' . INSENZ_VERSION . '" discuz_version="' . DISCUZ_VERSION . ' - ' . DISCUZ_RELEASE . '">' . $data . '</request>';
    $postdata = insenz_authcode($t_hex . md5($authkey . $postdata . $t_hex) . $postdata, 'ENCODE', $authkey);
    if (!$fp && !($fp = @fsockopen($insenz['host'], 80))) {
        if (!$return) {
            return;
        } else {
            return array('status' => 1, 'data' => $msglang['insenz_connect_failed']);
        }
    }
    $insenz['siteid'] = intval($insenz['siteid']);
    @fwrite($fp, "POST http://{$insenz['url']}/discuz.php?s_id={$insenz['siteid']} HTTP/1.0\r\n");
    @fwrite($fp, "Host: {$insenz['host']}\r\n");
    @fwrite($fp, "Content-Type: file\r\n");
    @fwrite($fp, "Content-Length: " . strlen($postdata) . "\r\n\r\n");
    @fwrite($fp, $postdata);
    if (!$return) {
        @fclose($fp);
        return;
    }
    $res = '';
    $isheader = 1;
    while (!feof($fp)) {
        $buffer = @fgets($fp, 1024);
        if (!$isheader) {
            $res .= $buffer;
        } elseif (trim($buffer) == '') {
            $isheader = 0;
        }
    }
    @fclose($fp);
    if (empty($res)) {
        return array('status' => 1, 'data' => $msglang['insenz_connect_failed']);
    }
    if (!($response = insenz_authcode($res, 'DECODE', $authkey))) {
        return array('status' => 1, 'data' => $msglang['insenz_transport_failed']);
    }
    $checkKey = substr($response, 0, 40);
    $response = substr($response, 40);
    $t_hex = substr($checkKey, 0, 8);
    $t = base_convert($t_hex, 16, 10);
    if (abs($timestamp - $t) > 1200) {
        return array('status' => 1, 'data' => $msglang['insenz_connect_timeout']);
    } elseif ($checkKey != $t_hex . md5($authkey . $response . $t_hex)) {
        return array('status' => 1, 'data' => 'Invalid Key or Data');
    }
    require_once DISCUZ_ROOT . './include/xmlparser.class.php';
    $xmlparse = new XMLParser();
    $xmlparseddata = $xmlparse->getXMLTree($response);
    if (!is_array($xmlparseddata) || !is_array($xmlparseddata['response'])) {
        return array('status' => 1, 'data' => $msglang['insenz_transport_failed']);
    }
    return array('status' => 0, 'data' => $xmlparseddata);
}
コード例 #2
0
function insenz_request($script, $data)
{
    global $timestamp, $insenz;
    @(include_once DISCUZ_ROOT . './discuz_version.php');
    $authkey = $insenz['authkey'];
    $t_hex = sprintf("%08x", $timestamp);
    $postdata = '<?xml version="1.0" encoding="UTF' . '-8"?><request insenz_version="' . INSENZ_VERSION . '" discuz_version="' . DISCUZ_VERSION . ' - ' . DISCUZ_RELEASE . '">' . $data . '</request>';
    $postdata = insenz_authcode($t_hex . md5($authkey . $postdata . $t_hex) . $postdata, 'ENCODE', $authkey);
    if (!($fp = @fsockopen($insenz['host'], 80))) {
        exit;
    }
    @fwrite($fp, "POST http://{$insenz['url']}/{$script}?s_id={$insenz['siteid']} HTTP/1.0\r\n");
    @fwrite($fp, "Host: {$insenz['host']}\r\n");
    @fwrite($fp, "Content-Type: file\r\n");
    @fwrite($fp, "Content-Length: " . strlen($postdata) . "\r\n\r\n");
    @fwrite($fp, $postdata);
    $res = '';
    $isheader = 1;
    while (!feof($fp)) {
        $buffer = @fgets($fp, 1024);
        if (!$isheader) {
            $res .= $buffer;
        } elseif (trim($buffer) == '') {
            $isheader = 0;
        }
    }
    @fclose($fp);
    if (empty($res)) {
        exit;
    }
    if (!($response = insenz_authcode($res, 'DECODE', $authkey))) {
        exit;
    }
    $checkKey = substr($response, 0, 40);
    $response = substr($response, 40);
    $t_hex = substr($checkKey, 0, 8);
    $t = base_convert($t_hex, 16, 10);
    if (abs($timestamp - $t) > 1200) {
        exit;
    } elseif ($checkKey != $t_hex . md5($authkey . $response . $t_hex)) {
        exit;
    }
    require_once DISCUZ_ROOT . './include/xmlparser.class.php';
    $xmlparse = new XMLParser();
    $xmlparseddata = $xmlparse->getXMLTree($response);
    unset($response);
    if (!is_array($xmlparseddata) || !is_array($xmlparseddata['response'])) {
        exit;
    }
    return $xmlparseddata['response'];
}