/**
  * Scans file for viruses.
  *
  * @param $data
  * @internal param FileScanRequest $request
  * @return array|bool|float|int|string
  */
 private function fileScan($data)
 {
     $file = $data->file('file');
     //$file_to_scan = $file->getRealPath();
     //$file_size_mb = filesize($file_to_scan) / 1024 / 1024;
     $scan = new \VirusTotal\File(getenv('VIRUSTOTAL_API_KEY'));
     $resp = $scan->scan($file->getRealPath());
     //$resp = $scan->rescan($file->getRealPath());
     if (isset($resp['resource'])) {
         $resp['Resource']['result'] = $scan->getReport($resp['resource']);
     }
     return $resp;
 }
Example #2
0
 /**
  * Scan a file via VirusTotal by providing its url
  * @param  string  $url  The filename to scan, provided as publicly available url
  * @param  boolean $rescan    Wether or not to force a rescan
  * @return array              Thee information returned by VirusTotal.
  */
 public static function scanFileViaUrl($url)
 {
     $scanResults = self::scanUrl($url);
     if ($scanResults['success'] && isset($scanResults['filescan_id'])) {
         // The api key must be set!
         $apikey = config("virus-total-api.api_key");
         if (!$apikey) {
             throw new \Exception("Please setup your VirusTotal api key to use the api.", 1);
         }
         // Prepare the file report
         $filereport = new \VirusTotal\File($apikey);
         // Try/Catch to get rate limit exceptions thrown by the api wrapper
         try {
             $fileReport = $filereport->getReport($scanResults['filescan_id']);
         } catch (\Exception $e) {
             if ($e instanceof \VirusTotal\Exceptions\RateLimitException) {
                 return ['success' => false, 'error' => 'rate limit exceeded'];
             } else {
                 throw new \Exception("Please setup a valid VirusTotal api key to use the api.", 1);
             }
         }
         return array_merge(['success' => true], $fileReport);
     }
     return $scanResults;
 }