|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Scan; |
|
6
|
|
|
use App\ScanResult; |
|
7
|
|
|
use Carbon\Carbon; |
|
8
|
|
|
use Illuminate\Console\Command; |
|
9
|
|
|
|
|
10
|
|
|
class ScannerTimeout extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The name and signature of the console command. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $signature = 'siwecos:timeout'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'Check for timeout'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create a new command instance. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the console command. |
|
38
|
|
|
* |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
public function handle() |
|
42
|
|
|
{ |
|
43
|
|
|
$timeout = getenv('SCANNER_TIMEOUT'); |
|
44
|
|
|
if ($timeout) { |
|
45
|
|
|
$timeout = intval($timeout, 10); |
|
46
|
|
|
} else { |
|
47
|
|
|
$timeout = 300; |
|
48
|
|
|
} |
|
49
|
|
|
$start_time = Carbon::now()->subSeconds($timeout); |
|
50
|
|
|
$notFinishedScans = Scan::whereStatus('2')->where('created_at', '<', $start_time)->get(); |
|
51
|
|
|
$this->info($start_time); |
|
52
|
|
|
/** @var Scan $pendingScan */ |
|
53
|
|
|
foreach ($notFinishedScans as $pendingScan) { |
|
54
|
|
|
/** @var ScanResult $result */ |
|
55
|
|
|
foreach ($pendingScan->results as &$result) { |
|
56
|
|
|
if ($result->result == null) { |
|
57
|
|
|
$result->result = self::getTimeOutArray($result->scanner_type, $timeout); |
|
58
|
|
|
} |
|
59
|
|
|
$result->save(); |
|
60
|
|
|
} |
|
61
|
|
|
$this->info($pendingScan->url); |
|
62
|
|
|
$pendingScan->status = 3; |
|
63
|
|
|
$pendingScan->save(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function getTimeOutArray(string $scanner, $to_val) |
|
68
|
|
|
{ |
|
69
|
|
|
$timeout = []; |
|
70
|
|
|
$timeout['name'] = 'TIMEOUT'; |
|
71
|
|
|
$timeout['hasError'] = true; |
|
72
|
|
|
$timeout['dangerlevel'] = 0; |
|
73
|
|
|
$timeout['score'] = 0; |
|
74
|
|
|
$timeout['scoreType'] = 'success'; |
|
75
|
|
|
$timeout['testDetails'] = []; |
|
76
|
|
|
$timeout['errorMessage'] = []; |
|
77
|
|
|
$timeout['errorMessage']['placeholder'] = 'SCANNER_TIMEOUT'; |
|
78
|
|
|
$timeout['errorMessage']['values'] = []; |
|
79
|
|
|
$timeout['errorMessage']['values']['scanner'] = $scanner; |
|
80
|
|
|
$timeout['errorMessage']['values']['timeoutvalue'] = $to_val; |
|
81
|
|
|
|
|
82
|
|
|
return [$timeout]; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|