Skip to content

Commit

Permalink
multiple updates to modules, class
Browse files Browse the repository at this point in the history
sucrose committed Aug 11, 2019
1 parent 7a6397d commit be6460b
Showing 3 changed files with 178 additions and 13 deletions.
112 changes: 112 additions & 0 deletions src/modules/proxyhttp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
class proxyhttp {
function __construct() {
}

function __destruct() {
}

private function curl_get($url, $user_agent) {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HEADER => false,
CURLINFO_HEADER_OUT => false,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_POSTFIELDS => '',
CURLOPT_USERAGENT => $user_agent,
));
$resp = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
echo "cURL Error #: $err";
}
return $resp;
}

public function get_proxies($user_agent) {
$arr = [];
$resp = [];
$resp[] = $this->curl_get('https://proxyhttp.net/free-list/proxy-anonymous-hide-ip-address/', $user_agent);
$resp[] = $this->curl_get('https://proxyhttp.net/free-list/proxy-high-anonymous-hide-ip-address/', $user_agent);
$resp[] = $this->curl_get('https://proxyhttp.net/free-list/proxy-https-security-anonymous-proxy/', $user_agent);
for ($i = 1; $i < 9; $i++) { // # of pages to rake [max: 9]
$resp[] = $this->curl_get("https://proxyhttp.net/free-list/anonymous-server-hide-ip-address/$page#proxylist", $user_agent);
}
/*for ($page = 1; $page <= $pages; $page++) {
$resp = $this->curl_get("https://proxyhttp.net/free-list/anonymous-server-hide-ip-address/$page#proxylist", $user_agent);
$re = '/chash = \'(?<chash>.*)\'/mU';
if (preg_match($re, $resp, $matches)) {
$chash = $matches['chash'];
preg_match_all('/title="(?<ip>.+)"(.|\n)*data-port="(?<encodedport>.+)"/Ui', $resp, $matches, PREG_PATTERN_ORDER);
if (0 < count($matches)) {
foreach ($matches['ip'] as $idx => $val) {
$arr[] = $matches['ip'][$idx] . ':' . $this->decode_port($matches['encodedport'][$idx], $chash);
}
} else {
return [];
}
} else {
return [];
}
}*/
//return array_unique($arr); // Remove duplicates
}

private function decode_port($encoded_port, $chash)
{
for ($n = [], $i = 0, $r = 0; $i < strlen($encoded_port) - 1; $i += 2, $r++) {
$n[$r] = intval(substr($encoded_port, $i, 2), 16);
}
for ($a = [], $i = 0; $i < strlen($chash); $i++) {
$a[$i] = $this->charCodeAt($chash, $i);
}
for ($i = 0; $i < count($n); $i++) {
$n[$i] = $n[$i] ^ $a[$i % count($a)];
}
for ($i = 0; $i < count($n); $i++) {
$n[$i] = chr($n[$i]);
}
return $n = implode('', $n);
}

private function charCodeAt($str, $num) {
return $this->utf8_ord($this->utf8_charAt($str, $num));
}

private function utf8_ord($ch) {
$len = strlen($ch);
if ($len <= 0) {
return false;
}
$h = ord($ch{0});
if ($h <= 0x7F) {
return $h;
}
if ($h < 0xC2) {
return false;
}
if ($h <= 0xDF && $len>1) {
return ($h & 0x1F) << 6 | (ord($ch{1}) & 0x3F);
}
if ($h <= 0xEF && $len>2) {
return ($h & 0x0F) << 12 | (ord($ch{1}) & 0x3F) << 6 | (ord($ch{2}) & 0x3F);
}
if ($h <= 0xF4 && $len>3) {
return ($h & 0x0F) << 18 | (ord($ch{1}) & 0x3F) << 12 | (ord($ch{2}) & 0x3F) << 6 | (ord($ch{3}) & 0x3F);
}
return false;
}

private function utf8_charAt($str, $num) {
return mb_substr($str, $num, 1, 'UTF-8');
}
}
2 changes: 1 addition & 1 deletion src/modules/proxz.php
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ private function curl_get($url, $user_agent) {
public function get_proxies($user_agent) {
$arr = [];
$resp = [];
for ($i = 0; $i < 26; $i++) {
for ($i = 0; $i < 24; $i++) {
$resp[] = $this->curl_get("http://www.proxz.com/proxy_list_high_anonymous_$i.html", $user_agent);
}
$resp_merged = implode(',', $resp);
77 changes: 65 additions & 12 deletions src/prake.class.php
Original file line number Diff line number Diff line change
@@ -11,12 +11,15 @@

namespace sucrose;

use Campo\UserAgent;

require __DIR__ . '/vendor/autoload.php';

class Prake {
private $arr_proxies = [];
private $debug_mode = false;
private $module_dir = '';
private $whitelisted_mods = [];

/**
* initiation
@@ -30,14 +33,32 @@ function __construct() {
}

/**
* initiation -> debug mode
* init -> debug mode
*
* @param dbg boolean for debug mode
* @return string debug mode state
*/
function __construct1($dbg) {
$this->debug_mode = $dbg;
return ($this->debug_mode) ? '<pre>[ + ] prake: initiated | debug mode</pre>' : '';
echo $this->debug_output('<pre>[ + ] prake: init | debug mode enabled</pre>');
return;
}

/**
* init -> debug mode, whitelisted modules
*
* @param dbg boolean for debug mode
* @param mods array for whitelisted mods
*/
function __construct2($dbg, $mods) {
$this->debug_mode = $dbg;
$this->whitelisted_mods = $mods;
$tmp = '';
$tmp .= ($this->debug_mode) ? '<pre>[ + ] prake: init | debug mode enabled</pre>' : '';
$tmp .= ($this->debug_mode && !empty($this->whitelisted_mods)) ? '<pre>[ + ] prake: init | whitelisted modules: [' . implode(', ', $this->whitelisted_mods) . ']</pre>' : '';
if (0 < strlen($tmp)) {
echo $this->debug_output($tmp);
}
return;
}

/**
@@ -46,7 +67,8 @@ function __construct1($dbg) {
* @return string debug mode state
*/
function __destruct() {
return ($this->debug_mode) ? '<pre>[ + ] prake: terminated</pre>' : true;
echo $this->debug_output('<pre>[ + ] prake: terminated</pre>');
return true;
}

/**
@@ -77,25 +99,56 @@ public function get_proxy_count() {
return count($this->arr_proxies);
}

/**
* @param str debug output string
* @return string
*/
private function debug_output($str) {
return ($this->debug_mode) ? $str : '';
}

/**
* @return string
*/
private function get_useragent() {
$ua = UserAgent::random();
echo $this->debug_output("<pre>[ + ] prake: rake() -> get_useragent() | user-agent: $ua</pre>");
return $ua;
}

/**
* @return array
*/
public function rake() {
spl_autoload_register(function ($class_name) {
$filepath = $this->get_module_dir() . $class_name . '.php';
$filepath = $this->get_module_dir() . "$class_name.php";
if (file_exists($filepath)) {
require $filepath;
echo $this->debug_output("<pre>[ + ] prake: rake() | module loaded: $class_name</pre>");
return false;
}
return true;
});
$user_agent = \Campo\UserAgent::random();
$ua = $this->get_useragent();
$dir = new \DirectoryIterator($this->get_module_dir());
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$basename = $fileinfo->getBasename('.php');
$basenameClass = new $basename();
$arr = $basenameClass->get_proxies($user_agent);
$this->arr_proxies[$basename] = $arr;
foreach ($dir as $file_info) {
if (!$file_info->isDot()) {
$basename = $file_info->getBasename('.php');
if (empty($this->whitelisted_mods)) {
$basenameClass = new $basename();
$arr = $basenameClass->get_proxies($ua);
echo $this->debug_output("<pre>[ + ] prake: rake() -> get_proxies() | $basename: " . count($arr) . '</pre>');
$this->arr_proxies[$basename] = $arr;
} else {
if (isset($this->whitelisted_mods[$basename])) {
$basenameClass = new $basename();
$arr = $basenameClass->get_proxies($ua);
echo $this->debug_output("<pre>[ + ] prake: rake() -> get_proxies() | $basename: " . count($arr) . '</pre>');
$this->arr_proxies[$basename] = $arr;
} else {
echo $this->debug_output("<pre>[ + ] prake: rake() | module ignored: $basename</pre>");
}
}
}
}
return $this->arr_proxies;

0 comments on commit be6460b

Please sign in to comment.