From be6460bd76b78e91a8b59fc7a9c3e8dc93a79510 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 11 Aug 2019 04:37:35 -0400 Subject: [PATCH] multiple updates to modules, class --- src/modules/proxyhttp.php | 112 ++++++++++++++++++++++++++++++++++++++ src/modules/proxz.php | 2 +- src/prake.class.php | 77 ++++++++++++++++++++++---- 3 files changed, 178 insertions(+), 13 deletions(-) create mode 100644 src/modules/proxyhttp.php diff --git a/src/modules/proxyhttp.php b/src/modules/proxyhttp.php new file mode 100644 index 0000000..6a23d75 --- /dev/null +++ b/src/modules/proxyhttp.php @@ -0,0 +1,112 @@ + $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 = \'(?.*)\'/mU'; + if (preg_match($re, $resp, $matches)) { + $chash = $matches['chash']; + preg_match_all('/title="(?.+)"(.|\n)*data-port="(?.+)"/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'); + } + } diff --git a/src/modules/proxz.php b/src/modules/proxz.php index f65bfc6..0f65b12 100644 --- a/src/modules/proxz.php +++ b/src/modules/proxz.php @@ -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); diff --git a/src/prake.class.php b/src/prake.class.php index 616c3a7..eaa1bf7 100644 --- a/src/prake.class.php +++ b/src/prake.class.php @@ -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) ? '
[ + ] prake: initiated | debug mode
' : ''; + echo $this->debug_output('
[ + ] prake: init | debug mode enabled
'); + 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) ? '
[ + ] prake: init | debug mode enabled
' : ''; + $tmp .= ($this->debug_mode && !empty($this->whitelisted_mods)) ? '
[ + ] prake: init | whitelisted modules: [' . implode(', ', $this->whitelisted_mods) . ']
' : ''; + 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) ? '
[ + ] prake: terminated
' : true; + echo $this->debug_output('
[ + ] prake: terminated
'); + 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("
[ + ] prake: rake() -> get_useragent() | user-agent: $ua
"); + 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("
[ + ] prake: rake() | module loaded: $class_name
"); 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("
[ + ] prake: rake() -> get_proxies() | $basename: " . count($arr) . '
'); + $this->arr_proxies[$basename] = $arr; + } else { + if (isset($this->whitelisted_mods[$basename])) { + $basenameClass = new $basename(); + $arr = $basenameClass->get_proxies($ua); + echo $this->debug_output("
[ + ] prake: rake() -> get_proxies() | $basename: " . count($arr) . '
'); + $this->arr_proxies[$basename] = $arr; + } else { + echo $this->debug_output("
[ + ] prake: rake() | module ignored: $basename
"); + } + } } } return $this->arr_proxies;