1 | <?php |
||
10 | class ComposerSecurityCheck extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'composer-security:check |
||
18 | {path? : path where find composer.lock, you can use * as jolly character i.e. "/var/www/*/*/", use quotation marks} |
||
19 | {--M|mail= : If you want send result to email} |
||
20 | {--w|whitelist= : If you want exclude from alarm some paths, divide by ","}'; |
||
21 | |||
22 | /** |
||
23 | * The console command description. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = <<<EOF |
||
28 | The <info>composer-security:check</info> command looks for every composer.lock file in the given path |
||
29 | and foreach composer.lock check for security issues in the project dependencies: |
||
30 | <info>php composer-security:check</info> |
||
31 | If you omit path argument, command look into current folder. |
||
32 | You can also pass the path as an argument: |
||
33 | <info>php composer-security:check /path/to/my/repos</info> |
||
34 | You can use <info>*</info> in path argument as jolly character i.e. <info>/var/www/*/*/</info> |
||
35 | By default, the command displays the result in console, but you can also |
||
36 | send an html email by using the <info>--mail</info> option: |
||
37 | <info>php composer-security:check /path/to/my/repos [email protected]</info> |
||
38 | EOF; |
||
39 | |||
40 | |||
41 | /** |
||
42 | * @var Client an istance of GuzzleHttp\Client |
||
43 | */ |
||
44 | protected $guzzle; |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $headersTableConsole = ['name', 'version', 'title', 'whitelist']; |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $tableVulnerabilities = []; |
||
55 | |||
56 | /** |
||
57 | * Create a new command instance. |
||
58 | * |
||
59 | * @param Client $objguzzle |
||
60 | */ |
||
61 | public function __construct(Client $objguzzle) |
||
66 | 2 | ||
67 | /** |
||
68 | * Execute the console command. |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | public function handle() |
||
76 | 2 | ||
77 | /** |
||
78 | * @param $argument |
||
79 | * @param $option |
||
80 | */ |
||
81 | private function hardWork($argument, $option) |
||
107 | 2 | ||
108 | /** |
||
109 | 2 | * @param $mail |
|
110 | * @param $tuttoOk |
||
111 | */ |
||
112 | private function notifyResult($mail, $tuttoOk) |
||
126 | |||
127 | 2 | ||
128 | private function notifyOK() |
||
133 | |||
134 | private function notifyKO() |
||
139 | 2 | ||
140 | 2 | /** |
|
141 | 2 | * @param $mail |
|
142 | 2 | * @param $tuttoOk |
|
143 | 2 | */ |
|
144 | 2 | private function sendEmail($mail, $tuttoOk) |
|
151 | 2 | ||
152 | /** |
||
153 | 2 | * |
|
154 | * @param $path |
||
155 | 2 | * @return array of composer.lock file |
|
156 | 2 | */ |
|
157 | 2 | private function findFilesComposerLock($path) |
|
168 | 2 | ||
169 | /** |
||
170 | * @param $fileLock |
||
171 | * @param $whitelist |
||
172 | * @return bool |
||
173 | */ |
||
174 | 2 | private function checkFile($fileLock, $whitelist) |
|
205 | |||
206 | } |
||
207 | |||
208 |