|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Jobs; |
|
4
|
|
|
|
|
5
|
|
|
use App\Scan; |
|
6
|
|
|
use Exception; |
|
7
|
|
|
use GuzzleHttp\Client; |
|
8
|
|
|
use GuzzleHttp\Psr7\Request; |
|
9
|
|
|
use Illuminate\Bus\Queueable; |
|
10
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
11
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
|
12
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
|
13
|
|
|
use Illuminate\Queue\SerializesModels; |
|
14
|
|
|
use Log; |
|
15
|
|
|
|
|
16
|
|
|
class ScanInisJob implements ShouldQueue |
|
17
|
|
|
{ |
|
18
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected $scan; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Create a new job instance. |
|
24
|
|
|
* |
|
25
|
|
|
* @param Scan $scan |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(Scan $scan) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->scan = $scan; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Execute the job. |
|
34
|
|
|
* |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
|
|
public function handle() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->scan->update([ |
|
40
|
|
|
'status' => 2, |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
$scanResult = $this->scan->results()->create([ |
|
44
|
|
|
'scanner_type' => 'ini-s', |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
$callbackUrl = route('callback', ['scanId' => $scanResult->id]); |
|
48
|
|
|
|
|
49
|
|
|
$client = new Client(); |
|
50
|
|
|
$request = new Request('POST', env('INI_S_SCANNER_URL'), ['timeout' => 0.5], \GuzzleHttp\json_encode([ |
|
51
|
|
|
'url' => $this->scan->url, |
|
52
|
|
|
'callbackurls' => [$callbackUrl], |
|
53
|
|
|
])); |
|
54
|
|
|
|
|
55
|
|
|
try { |
|
56
|
|
|
Log::info('Calling '.$request->getUri()); |
|
57
|
|
|
Log::info('Payload '.$request->getBody()); |
|
58
|
|
|
$response = $client->sendAsync($request, ['timeout' => 0.5]); |
|
59
|
|
|
$response->wait(); |
|
60
|
|
|
} catch (Exception $ex) { |
|
61
|
|
|
// only way to make it async |
|
62
|
|
|
// promise running against timeout |
|
63
|
|
|
Log::info('ini-s has started'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|