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 | {--N|nomailok=false : True if you want send result to email only for alarm, false is default} |
||
21 | {--w|whitelist= : If you want exclude from alarm some paths, divide by ","}'; |
||
22 | |||
23 | /** |
||
24 | * The console command description. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $description = <<<EOF |
||
29 | The <info>composer-security:check</info> command looks for every composer.lock file in the given path |
||
30 | and foreach composer.lock check for security issues in the project dependencies: |
||
31 | <info>php composer-security:check</info> |
||
32 | If you omit path argument, command look into current folder. |
||
33 | You can also pass the path as an argument: |
||
34 | <info>php composer-security:check /path/to/my/repos</info> |
||
35 | You can use <info>*</info> in path argument as jolly character i.e. <info>/var/www/*/*/</info> |
||
36 | By default, the command displays the result in console, but you can also |
||
37 | send an html email by using the <info>--mail</info> option: |
||
38 | <info>php composer-security:check /path/to/my/repos [email protected]</info> |
||
39 | EOF; |
||
40 | |||
41 | |||
42 | /** |
||
43 | * @var Client an istance of GuzzleHttp\Client |
||
44 | */ |
||
45 | protected $guzzle; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $headersTableConsole = ['name', 'version', 'title', 'whitelist']; |
||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $tableVulnerabilities = []; |
||
56 | |||
57 | /** |
||
58 | * Create a new command instance. |
||
59 | * |
||
60 | * @param Client $objguzzle |
||
61 | */ |
||
62 | 18 | public function __construct(Client $objguzzle) |
|
67 | |||
68 | /** |
||
69 | * Execute the console command. |
||
70 | * |
||
71 | * @return mixed |
||
72 | */ |
||
73 | 16 | public function handle() |
|
77 | |||
78 | /** |
||
79 | * @param $argument |
||
80 | * @param $option |
||
81 | */ |
||
82 | 16 | private function hardWork($argument, $option) |
|
107 | |||
108 | /** |
||
109 | * @param $mail |
||
110 | * @param $tuttoOk |
||
111 | */ |
||
112 | 16 | private function notifyResult($mail, $nomailok, $tuttoOk) |
|
124 | |||
125 | |||
126 | 16 | private function notify($result) |
|
134 | |||
135 | 10 | private function notifyOK() |
|
140 | |||
141 | 6 | private function notifyKO() |
|
146 | |||
147 | /** |
||
148 | * @param $mail |
||
149 | * @param $tuttoOk |
||
150 | */ |
||
151 | 14 | private function sendEmail($mail, $tuttoOk) |
|
158 | |||
159 | /** |
||
160 | * |
||
161 | * @param $path |
||
162 | * @return array of composer.lock file |
||
163 | */ |
||
164 | 18 | private function findFilesComposerLock($path) |
|
179 | |||
180 | /** |
||
181 | * @param $fileLock |
||
182 | * @param $whitelist |
||
183 | * @return bool |
||
184 | */ |
||
185 | 16 | private function checkFile($fileLock, $whitelist) |
|
218 | |||
219 | } |
||
220 | |||
221 |