Esempio n. 1
0
 public function testAddCheckUrls()
 {
     $start_urls = ['http://yahoo.com', 'http://google.com'];
     Safebrowsing::addCheckUrls($start_urls);
     $add_urls = ['http://snipe.net', 'http://ianfette.org'];
     Safebrowsing::addCheckUrls($add_urls);
     $this->assertEquals(4, count(Safebrowsing::getUrls()));
     $this->assertEquals($add_urls[1], Safebrowsing::getUrls()[3]);
     $this->assertEquals($start_urls[0], Safebrowsing::getUrls()[0]);
 }
Esempio n. 2
0
 /**
  * Invokes the Safebrowing API
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param $url string|array
  * @since [v0.1.0]
  * @return String JSON
  */
 public static function checkSafeBrowsing($urls)
 {
     $postUrl = 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=' . config('safebrowsing.google.api_key');
     $payload = ['client' => ['clientId' => config('safebrowsing.google.clientId'), 'clientVersion' => config('safebrowsing.google.clientVersion')], 'threatInfo' => ["threatTypes" => config('safebrowsing.google.threat_types'), "platformTypes" => config('safebrowsing.google.threat_platforms'), "threatEntryTypes" => ["URL"], "threatEntries" => Safebrowsing::formatUrls($urls)]];
     $ch = curl_init();
     $timeout = config('safebrowsing.google.timeout');
     curl_setopt($ch, CURLOPT_URL, $postUrl);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Connection: Keep-Alive'));
     $data = curl_exec($ch);
     $responseDecoded = json_decode($data, true);
     $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     if ($responseCode != 200) {
         return $responseDecoded;
     }
     return $data;
 }