1 | <?php |
||
18 | class ComposerSecurityCheck extends Command |
||
19 | { |
||
20 | /** |
||
21 | * The name and signature of the console command. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $signature = 'composer-security:check |
||
26 | {path? : path where find composer.lock, you can use * as jolly character i.e. "/var/www/*/*/", use quotation marks} |
||
27 | {--M|mail= : If you want send result to email} |
||
28 | {--w|whitelist= : If you want exclude from alarm some paths, divide by ","}' |
||
29 | ; |
||
30 | |||
31 | /** |
||
32 | * The console command description. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $description = <<<EOF |
||
37 | The <info>composer-security:check</info> command looks for every composer.lock file in the given path |
||
38 | and foreach composer.lock check for security issues in the project dependencies: |
||
39 | <info>php composer-security:check</info> |
||
40 | If you omit path argument, command look into current folder. |
||
41 | You can also pass the path as an argument: |
||
42 | <info>php composer-security:check /path/to/my/repos</info> |
||
43 | You can use <info>*</info> in path argument as jolly character i.e. <info>/var/www/*/*/</info> |
||
44 | By default, the command displays the result in console, but you can also |
||
45 | send an html email by using the <info>--mail</info> option: |
||
46 | <info>php composer-security:check /path/to/my/repos [email protected]</info> |
||
47 | EOF; |
||
48 | |||
49 | |||
50 | /** |
||
51 | * @var Client an istance of GuzzleHttp\Client |
||
52 | */ |
||
53 | protected $guzzle; |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $headersTableConsole = ['name', 'version', 'title', 'whitelist']; |
||
59 | |||
60 | /** |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $tableVulnerabilities = []; |
||
64 | |||
65 | /** |
||
66 | * Create a new command instance. |
||
67 | * |
||
68 | * @param Client $objguzzle |
||
69 | */ |
||
70 | 2 | public function __construct(Client $objguzzle) |
|
75 | |||
76 | /** |
||
77 | * Execute the console command. |
||
78 | * |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 2 | public function handle() |
|
85 | |||
86 | /** |
||
87 | * @param $argument |
||
88 | * @param $option |
||
89 | */ |
||
90 | 2 | private function hardWork($argument,$option) |
|
138 | |||
139 | 2 | private function adjustWhiteList($white) |
|
150 | |||
151 | 2 | private function notifyResult($mail,$tuttoOk) |
|
152 | { |
||
153 | 2 | $esito=Config::get('composer-security-check.mailSubjectSuccess'); |
|
154 | |||
155 | 2 | if (!$tuttoOk) { |
|
156 | 2 | $esito=Config::get('composer-security-check.mailSubjetcAlarm'); |
|
157 | 2 | $this->error($esito); |
|
158 | 2 | } |
|
159 | else { |
||
160 | $this->line($esito); |
||
161 | } |
||
162 | |||
163 | //print to console |
||
164 | 2 | $this->table($this->headersTableConsole, $this->tableVulnerabilities); |
|
193 |