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 | 10 | */ |
|
62 | public function __construct(Client $objguzzle) |
||
67 | |||
68 | /** |
||
69 | * Execute the console command. |
||
70 | * |
||
71 | * @return mixed |
||
72 | 8 | */ |
|
73 | public function handle() |
||
77 | |||
78 | /** |
||
79 | * @param $argument |
||
80 | * @param $option |
||
81 | 8 | */ |
|
82 | private function hardWork($argument, $option) |
||
107 | |||
108 | /** |
||
109 | * @param $mail |
||
110 | * @param $tuttoOk |
||
111 | 8 | */ |
|
112 | private function notifyResult($mail, $nomailok, $tuttoOk) |
||
129 | 6 | ||
130 | 6 | ||
131 | 6 | private function notifyOK() |
|
136 | 2 | ||
137 | 2 | private function notifyKO() |
|
142 | |||
143 | 8 | /** |
|
144 | * @param $mail |
||
145 | 8 | * @param $tuttoOk |
|
146 | 8 | */ |
|
147 | 8 | private function sendEmail($mail, $tuttoOk) |
|
154 | |||
155 | /** |
||
156 | 10 | * |
|
157 | * @param $path |
||
158 | 10 | * @return array of composer.lock file |
|
159 | 10 | */ |
|
160 | 10 | private function findFilesComposerLock($path) |
|
175 | |||
176 | /** |
||
177 | 8 | * @param $fileLock |
|
178 | * @param $whitelist |
||
179 | 8 | * @return bool |
|
180 | */ |
||
181 | 8 | private function checkFile($fileLock, $whitelist) |
|
213 | |||
214 | } |
||
215 | |||
216 |