/** * Execute the console command. * * @return mixed */ public function fire() { $proxies = Proxy::all(); $this->info("Checking existing proxies...\n"); Telegram::sendMessage(env("TELEGRAM_CHANNEL"), "A iniciar os teste de segurança para " . count($proxies) . " proxies."); foreach ($proxies as $proxy) { $this->info("\n # Checking security on " . $proxy->host . ":" . $proxy->port . "..."); //Check for proxy security $this->checkProxySecurity($proxy); } Telegram::sendMessage(env("TELEGRAM_CHANNEL"), "Testes de segurança finalizados! De " . count($proxies) . " proxies, ficaram " . count(Proxy::all()) . "."); $this->info("Done."); }
/** * Execute the console command. * * @return mixed */ public function fire() { define('HTTP_GATE', 'http://revolucaodosbytes.pt/gate.php'); // Gate for check HTTP,SOCKS proxy define('HTTPS_GATE', 'https://revolucaodosbytes.pt/gate.php'); // Gate for check HTTPS proxy define('CHECK_TIMEOUT', 10); // Curl timeout request // Store the proxies on this array $proxy_array = []; // First proxy site $proxy_list_url = "http://www.google-proxy.net"; $curl = curl_init($proxy_list_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $output = curl_exec($curl); curl_close($curl); if (!$output) { $this->error("Failed fetching {$proxy_list_url}"); return; } $this->info("\nFetched {$proxy_list_url}... Parsing HTML"); $dom = new \DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($output); libxml_use_internal_errors(false); $xpath = new \DOMXPath($dom); $entries = $xpath->query('//*[@id="proxylisttable"]/tbody/tr'); foreach ($entries as $entry) { $host = $entry->childNodes->item(0)->textContent; $port = $entry->childNodes->item(1)->textContent; $this->info(" * FOUND " . $host . ":" . $port); $proxy_array[] = [$host, $port]; } $this->info(" All done!! "); // Second proxy site $proxy_list_url = "http://proxy-list.org/english/index.php?p="; for ($page = 1; $page <= 10; $page++) { $curl = curl_init($proxy_list_url . $page); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $output = curl_exec($curl); curl_close($curl); if (!$output) { $this->error("Failed fetching page {$page}"); continue; } $this->info("\nFetched page {$page}... Parsing HTML"); $dom = new \DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($output); libxml_use_internal_errors(false); $xpath = new \DOMXPath($dom); $entries = $xpath->query('//*[@id="proxy-table"]//li[@class="proxy"]//script'); foreach ($entries as $entry) { preg_match('/\'(.*)\'/i', $entry->textContent, $proxy_address); $proxy_address = base64_decode($proxy_address[1]); if (strpos($proxy_address, ":") === false) { continue; } list($host, $port) = explode(":", $proxy_address); $this->info(" * FOUND " . $host . ":" . $port); $proxy_array[] = [$host, $port]; } } /** * NOW TEST THE PROXY AND ADD TO DATABASE */ $this->info("\n#############################################"); $this->info("#### STARTED TESTING PROXIES ####"); $this->info("#############################################"); $this->info("There are " . count($proxy_array) . " proxy entries to test.\n"); Telegram::sendMessage(env("TELEGRAM_CHANNEL"), "Procura de novos proxies iniciada. Vou iniciar o teste de " . count($proxy_array) . " proxies."); $counter = 0; foreach ($proxy_array as $proxy) { list($host, $port) = $proxy; if (!Proxy::whereRaw('host = ? and port = ?', array($host, $port))->get()->isEmpty()) { $this->info(" * Skipping " . $host . ":" . $port . "... Already on the database"); continue; } $this->info(" * Testing " . $host . ":" . $port . "..."); $resultQuery = PHPProxyChecker::checkProxy($host . ":" . $port); if (isset($resultQuery['NOT_WORKING']) && $resultQuery['NOT_WORKING'] == 'Y') { $this->error("\t * Proxy not responding... "); continue; } if (isset($resultQuery['SUPPORT_SSL']) && $resultQuery['SUPPORT_SSL'] != 'Y') { $this->error("\t * Proxy does not support SSL. Skipping."); continue; } $this->info("\t * Success! "); $this->table(["Type", "Type Name", "Query Time", "SSL"], [[$resultQuery['TYPE'], $resultQuery['TYPE_NAME'], $resultQuery['QUERY_TIME'], $resultQuery['SUPPORT_SSL']]]); $proxy = new Proxy(); $proxy->host = $host; $proxy->port = $port; $proxy->speed = $resultQuery['QUERY_TIME']; $proxy->working = true; $proxy->latest_report = json_encode($resultQuery); $proxy->save(); $counter++; } $this->info("\n * All done! Added {$counter} new proxies"); //Notify on telegram Telegram::sendMessage(env("TELEGRAM_CHANNEL"), "Terminei agora de ir buscar novos proxies. De um total de " . count($proxy_array) . " proxies, aproveitei apenas {$counter}."); }
/** * When a Ahoy! user gets into a blocked site that isn't on the whitelist, * the application will report back notifying us that a new site should be blocked. * * @TODO store this information in the database, and add some algorithm to data treatment * * @param Request $request */ public function autoReportBlockedSite(Request $request) { $site = $request->input('site'); $site = str_replace('www.', "", parse_url($site, PHP_URL_HOST)); $site = rtrim($site, '.'); // Sometimes there are URL's with a extra dot in the end. Strip all the dots. if (empty($site)) { return new Response(['error' => 'no site provided'], Response::HTTP_BAD_REQUEST); } // Validate if site is already on the list foreach (SitesController::getAllSites() as $site_in_list) { if ($site == $site_in_list) { return new Response(['error' => 'site already in the list'], Response::HTTP_ALREADY_REPORTED); } } if (Cache::has('site-ignore-' . $site)) { return new Response(['error' => 'site in the ignore list'], Response::HTTP_UNPROCESSABLE_ENTITY); } // @todo use this for rate limit // Test if site was reported in the last 5 minutes if (Cache::has('ip-reported-' . $site)) { $response = Response(['error' => 'site reported in less than 5 minutes']); $response->setStatusCode('420', "Enhance Your Calm"); return $response; } // Add a cache key for when a given host is reported. This key has 5 minutes duration $site_reported = Cache::remember('ip-reported-' . $site, 5, function () { return true; }); // Get the IP details $user_ip = $request->ip(); $ip_details = Cache::remember('ip-details-' . $user_ip, 3600, function () use($user_ip) { return $this->getIPDetails($user_ip); }); // Fallback if ($ip_details == null) { $ip_details = new \stdClass(); $ip_details->org = "Unknown"; } // Store the site host in cache, without www $site_id = $this->generateUniqueID(); Cache::put('site-' . $site_id, $site, 3600); // Store it for a day // @todo instead of sending to telegram, store in a database Telegram::sendMessage(env("TELEGRAM_CHANNEL"), "Foi detectado um novo site bloqueado.\n\t\t\t\tURL: {$site}\n\t\t\t\tIP: {$user_ip}\n\t\t\t\tProvider: {$ip_details->org}", true); Telegram::sendMessage(env("TELEGRAM_CHANNEL"), "Para incluir este site, utiliza o comando /adicionar {$site_id}\nPara ignorar este site, utiliza o comando /ignorar {$site_id}"); return ['success' => 'true']; }