/**
  * 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.");
 }
Ejemplo n.º 2
0
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
use Telegram\Bot\Laravel\Facades\Telegram;
$app->get('/', function () use($app) {
    try {
        Telegram::setWebhook('https://ahoy-api.revolucaodosbytes.pt/' . env('TELEGRAM_BOT_TOKEN') . '/webhook');
    } catch (\Telegram\Bot\Exceptions\TelegramResponseException $exception) {
        error_log("Telegram exception: " . $exception->getMessage());
    }
    return ['version' => 1];
});
$app->post('/' . env("TELEGRAM_BOT_TOKEN") . '/webhook', function () {
    Telegram::commandsHandler(true);
    return 'ok';
});
$app->group(['prefix' => 'api', 'namespace' => 'App\\Http\\Controllers'], function () use($app) {
    $app->post('auth/login', 'Auth\\AuthController@login');
    $app->post('auth/register', 'Auth\\AuthController@register');
    $app->post('auth/renew', 'Auth\\AuthController@renewToken');
    $app->get('pac', 'ProxyController@generatePAC');
    $app->post('pac', 'ProxyController@generatePAC');
    $app->get('proxies', 'ProxyController@getProxyList');
    $app->get('sites', 'SitesController@getSiteList');
    $app->get('hosts', 'SitesController@getHostsList');
    $app->get('getProxy', 'ProxyController@getProxy');
    $app->get('stats/host/{hostname}', 'StatsController@hostname');
    $app->post('report/blocked', 'ReportController@autoReportBlockedSite');
    $app->get('vpn/certs/version', 'VPNController@getClientCAVersion');
Ejemplo n.º 3
0
 /**
  * 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}.");
 }
Ejemplo n.º 4
0
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register(App\Providers\CommandServiceProvider::class);
$app->register(Vluzrmos\Tinker\TinkerServiceProvider::class);
$app->register(\Telegram\Bot\Laravel\TelegramServiceProvider::class);
$app->register(\Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class);
$app->register(\GrahamCampbell\Throttle\ThrottleServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
$app->group(['namespace' => 'App\\Http\\Controllers'], function ($app) {
    require __DIR__ . '/../app/Http/routes.php';
});
Telegram::addCommands([\App\Console\Commands\Telegram\StartCommand::class, \App\Console\Commands\Telegram\TopCommand::class, \App\Console\Commands\Telegram\StatsCommand::class, \App\Console\Commands\Telegram\FunCommand::class, \App\Console\Commands\Telegram\AddNewSiteCommand::class, \App\Console\Commands\Telegram\IgnoreSiteCommand::class]);
/*
 * Register Facades
 */
class_alias('Tymon\\JWTAuth\\Facades\\JWTAuth', 'JWTAuth');
class_alias('GrahamCampbell\\Throttle\\Facades\\Throttle', 'Throttle');
return $app;
Ejemplo n.º 5
-1
 /**
  * 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'];
 }
Ejemplo n.º 6
-1
 public function getUpdates()
 {
     $updates = Telegram::getUpdates();
     // Telegram::sendMessage('24560074', 'Ich lebe');
     return Response::json($updates);
 }