Add proxy support to curl wrapper, provide proxy list from

http://multiproxy.org/txt_all/proxy.txt
This commit is contained in:
Pellaeon Lin 2017-02-21 17:25:34 +08:00
parent 701ea934a6
commit 8658d93ec5
4 changed files with 1544 additions and 7 deletions

View File

@ -101,7 +101,7 @@ class FacebookBridge extends BridgeAbstract {
$context = stream_context_create($http_options);
$html = getContents($captcha_action, false, $context);
*/
list($html, $info, $res_header) = curlgetContents($captcha_action, $captcha_fields, true);
list($html, $info, $res_header, $proxy) = curlgetContents($captcha_action, $captcha_fields, true);
if ( $info['http_code'] != 200 )
returnServerError('Error '.$info['http_code'].$captcha_action."\nReq:\n".$res_header."\nResp:\n".$info['request_header']);
@ -113,10 +113,11 @@ class FacebookBridge extends BridgeAbstract {
}
$res_header = '';
$proxy = '';
//Retrieve page contents
if (is_null($html)) {
if (!strpos($this->getInput('u'), "/")) {
list($html, $info, $res_header) = curlgetSimpleHTMLDOM(self::URI.urlencode($this->getInput('u')).'?_fb_noscript=1');
list($html, $info, $res_header, $proxy) = curlgetSimpleHTMLDOM(self::URI.urlencode($this->getInput('u')).'?_fb_noscript=1');
if ( $info['http_code'] != 200 )
returnServerError('Error '.$info['http_code']."\nResp:\n".$res_header."\nReq:\n".$info['request_header']);
} else {
@ -151,6 +152,7 @@ class FacebookBridge extends BridgeAbstract {
<p><b>Response:</b> <input name="captcha_response" placeholder="please fill in" />
<input type="submit" value="Submit!" /></p>
<pre>{$res_header}</pre>
<p>Proxy: <pre>{$proxy}</pre></p>
</form>
EOD;
die($message);

View File

@ -4,8 +4,16 @@ function curlgetContents( $url, $params, $post=false){
curl_setopt($ch, CURLOPT_URL, $post ? $url : $url.'?'.http_build_query($params) );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/rssbridge-fb-cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/rssbridge-fb-cookies.txt');
#curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/rssbridge-fb-cookies.txt');
#curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/rssbridge-fb-cookies.txt');
$files = array_diff(scandir(__DIR__.'/../proxylist/'), array('.', '..'));
$proxies = [];
foreach($files as $file) {
$proxies_str = file_get_contents(__DIR__.'/../proxylist/'.$file);
array_push($proxies, explode("\n", $proxies_str));
}
$proxy = array_rand($proxies);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
@ -33,7 +41,7 @@ function curlgetContents( $url, $params, $post=false){
curl_close($ch);
file_put_contents(__DIR__.'/../debug/D'.date('H-i-s').'.html', $body);
return array($body, $info, $header);
return array($body, $info, $header, $proxy);
}
function curlgetSimpleHTMLDOM($url
@ -48,7 +56,7 @@ function curlgetSimpleHTMLDOM($url
, $defaultBRText = DEFAULT_BR_TEXT
, $defaultSpanText = DEFAULT_SPAN_TEXT
){
list($body, $info, $header) = curlgetContents($url, $use_include_path, $context, $offset, $maxLen);
list($body, $info, $header, $proxy) = curlgetContents($url, $use_include_path, $context, $offset, $maxLen);
return array(str_get_html($body
, $lowercase
, $forceTagsClosed
@ -56,6 +64,6 @@ function curlgetSimpleHTMLDOM($url
, $stripRN
, $defaultBRText
, $defaultSpanText),
$info, $header);
$info, $header, $proxy);
}
?>

0
proxylist/.gitkeep Normal file
View File

1527
proxylist/proxy2.txt Normal file

File diff suppressed because it is too large Load Diff