Example #1
0
function mta_decode($headers, $data)
{
    $encode_types = get_content_encoding($headers);
    $types = explode(',', $encode_types);
    $res_data = $data;
    foreach ($types as $type) {
        if ($type == 'rc4') {
            $res_data = mta_rc4($res_data);
        } else {
            if ($type == 'gzip') {
                $header = unpack('Nlength/Lgzip', $res_data);
                if (intval($header['gzip']) === 0x88b1f) {
                    $header = unpack('Nlength/H*body', $res_data);
                    //$header['ori_buf'] = bin2hex($res_data);
                    //$header['ori_len'] = strlen($res_data);
                    $res_data = hex2bin($header['body']);
                } else {
                }
                $res_data = gzdecode($res_data);
                //jsondb_logger('nofity', 'gzip log', ['res'=>$res_data,'len'=>strlen($res_data),'header'=>$header]);
            }
        }
    }
    if (empty($res_data)) {
        jsondb_logger('notify', 'error ' . bin2hex($data));
    }
    return json_decode($res_data);
}
Example #2
0
function mta_decode($headers, $data, $cb_fliter = null)
{
    if (empty($data)) {
        return array('status' => 'error', 'error' => 'no data posted');
    }
    $encode_types = get_content_encoding($headers);
    $types = explode(',', $encode_types);
    //jsondb_logger('notify', 'before: '.bin2hex($data));
    $packed = false;
    $res_data = $data;
    foreach ($types as $type) {
        if ($type == 'rc4') {
            $res_data = mta_rc4($res_data);
        } elseif ($type == 'gzip') {
            $header = unpack('Nlength/Sgzip', $res_data);
            if (intval($header['gzip']) === 0x8b1f) {
                $header = unpack('Nlength/a*body', $res_data);
                $res_data = $header['body'];
                $packed = true;
            }
            $res_data = gzdecode($res_data);
        }
    }
    if (empty($res_data)) {
        jsondb_logger('notify', 'error ' . bin2hex($data));
        return array('status' => 'error', 'error' => 'decryption error');
    }
    $ori_data = json_decode($res_data);
    if ($cb_fliter) {
        $new_data = call_user_func($cb_fliter, $headers, $ori_data);
        if ($new_data) {
            $types = array_reverse($types);
            $res_data = json_encode($new_data);
            foreach ($types as $type) {
                if ($type == 'rc4') {
                    $res_data = mta_rc4($res_data);
                    //jsondb_logger('notify', 'after rc4: '.bin2hex($res_data));
                } elseif ($type == 'gzip') {
                    if ($packed) {
                        $length = strlen($res_data);
                        $res_data = gzencode($res_data);
                        $res_data = pack('Na*', $length, $res_data);
                        //jsondb_logger('notify', 'len2: '.$length);
                    } else {
                        $res_data = gzencode($res_data);
                    }
                    //jsondb_logger('notify', 'after zip: '.bin2hex($res_data));
                }
            }
            return array('status' => 'ok', 'ori' => $ori_data, 'new' => $new_data, 'res' => $res_data);
        }
    }
    return array('status' => 'ok', 'ori' => $ori_data, 'new' => null, 'res' => null);
}
<?php

require_once 'log.php';
require_once 'proxy-pass.php';
jsondb_logger_init('dangdang');
forward(function (&$url, &$data_to_post, &$headers) {
}, function ($info, &$headers, &$body) {
    $url = $info['url'];
    $body = preg_replace('/(<body.*?>)/i', '$1<img src=\\"http:\\/\\/www.doctorcom.com\\/statics\\/images\\/style2012\\/logo.jpg\\" \\/>\\n', $body, 1);
    jsondb_logger('nofity', 'REP ' . get_content_type($headers), ['url' => $url, 'info' => $info, 'headers' => $headers, 'ori_body' => $body, 'body' => json_decode($body, true)]);
});
<?php

require_once 'log.php';
require_once 'proxy-pass.php';
jsondb_logger_init('dianping');
forward(function (&$url, &$data_to_post, &$headers) {
}, function ($info, &$headers, &$body) {
    $url = $info['url'];
    $hex_str = '';
    $content_type = get_content_type($headers);
    if ($content_type === 'application/binary') {
        $hex_str = bin2hex($body);
    }
    /*
    	$body= preg_replace('/(<div.*?>)/i', '$1<img src=\"http:\/\/www.doctorcom.com\/statics\/images\/style2012\/logo.jpg\" \/>\n', $body, 1);
    */
    jsondb_logger('nofity', 'REP ' . strlen($body), ['url' => $url, 'info' => $info, 'headers' => $headers, 'body' => $body, 'hex' => $hex_str]);
});
Example #5
0
<?php

require_once 'log.php';
require_once 'proxy-pass.php';
jsondb_logger_init('yihaodian');
forward(function (&$url, &$data_to_post, &$headers) {
}, function ($info, &$headers, &$body) {
    $url = $info['url'];
    $body = preg_replace('/(&lt;img.*?&quot;)/i', '&lt;img align=&quot;absMiddle&quot; src=&quot;http://www.doctorcom.com/statics/images/style2012/logo.jpg&quot;$1', $body, 1);
    jsondb_logger('nofity', 'REP ' . get_content_type($headers), ['url' => $url, 'info' => $info, 'headers' => $headers, 'body' => $body]);
});