| 1 |
<?php |
| 2 |
/** |
| 3 |
* CLI functions |
| 4 |
* |
| 5 |
* @package WPVulnerability |
| 6 |
* |
| 7 |
* @version 2.0.0 |
| 8 |
*/ |
| 9 |
defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); |
| 10 |
|
| 11 |
/** |
| 12 |
* Registers a WP-CLI command for WPVulnerability plugin. |
| 13 |
* |
| 14 |
* @since 2.0.0 |
| 15 |
* |
| 16 |
* @return void |
| 17 |
*/ |
| 18 |
if( defined( 'WP_CLI' ) && WP_CLI ) { |
| 19 |
|
| 20 |
/** |
| 21 |
* Core section in WP-CLI command |
| 22 |
* |
| 23 |
* @since 2.0.0 |
| 24 |
* |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
function wpvulnerability_cli_core() { |
| 28 |
|
| 29 |
// Get core vulnerabilities |
| 30 |
$core_vulnerabilities = wpvulnerability_core_get_vulnerabilities(); |
| 31 |
|
| 32 |
$vulnerabilities = array(); |
| 33 |
// Loop through each core vulnerability |
| 34 |
foreach ( $core_vulnerabilities as $vulnerability ) { |
| 35 |
|
| 36 |
$severity = null; |
| 37 |
if( isset( $vulnerability['impact']['cvss']['severity'] ) ) { |
| 38 |
$severity = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] ); |
| 39 |
} |
| 40 |
$exploitable = null; |
| 41 |
if( isset( $vulnerability['impact']['cvss']['exploitable'] ) ) { |
| 42 |
$exploitable = number_format( (float) $vulnerability['impact']['cvss']['exploitable'], 1, '.', '' ); |
| 43 |
} |
| 44 |
|
| 45 |
// Add the vulnerability details to the array |
| 46 |
array_push( |
| 47 |
$vulnerabilities, |
| 48 |
array( |
| 49 |
'Version' => trim( html_entity_decode( wp_kses( $vulnerability['name'], 'strip' ) ) ), |
| 50 |
'Vulnerability information' => '[*] WordPress ' . trim( html_entity_decode( wp_kses( $vulnerability['name'], 'strip' ) ) ), |
| 51 |
) |
| 52 |
); |
| 53 |
|
| 54 |
|
| 55 |
$what = array(); |
| 56 |
if( isset( $vulnerability['impact']['cwe'] ) && count( $vulnerability['impact']['cwe'] ) ) { |
| 57 |
|
| 58 |
array_push( |
| 59 |
$vulnerabilities, |
| 60 |
array( |
| 61 |
'Version' => ' ', |
| 62 |
'Vulnerability information' => ' ', |
| 63 |
) |
| 64 |
); |
| 65 |
|
| 66 |
foreach( $vulnerability['impact']['cwe'] as $vulnerability_cwe ) { |
| 67 |
|
| 68 |
array_push( |
| 69 |
$vulnerabilities, |
| 70 |
array( |
| 71 |
'Version' => ' ', |
| 72 |
'Vulnerability information' => trim( html_entity_decode( wp_kses( $vulnerability_cwe['name'], 'strip' ) ) ), |
| 73 |
) |
| 74 |
); |
| 75 |
|
| 76 |
array_push( |
| 77 |
$vulnerabilities, |
| 78 |
array( |
| 79 |
'Version' => ' ', |
| 80 |
'Vulnerability information' => trim( html_entity_decode( wp_kses( $vulnerability_cwe['description'], 'strip' ) ) ), |
| 81 |
) |
| 82 |
); |
| 83 |
|
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
$score = null; |
| 88 |
if( isset( $vulnerability['impact']['cvss']['score'] ) ) { |
| 89 |
$score = number_format( (float) $vulnerability['impact']['cvss']['score'], 1, '.', '' ); |
| 90 |
} |
| 91 |
$severity = null; |
| 92 |
if( isset( $vulnerability['impact']['cvss']['severity'] ) ) { |
| 93 |
$severity = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] ); |
| 94 |
} |
| 95 |
$exploitable = null; |
| 96 |
if( isset( $vulnerability['impact']['cvss']['exploitable'] ) ) { |
| 97 |
$exploitable = number_format( (float) $vulnerability['impact']['cvss']['exploitable'], 1, '.', '' ); |
| 98 |
} |
| 99 |
|
| 100 |
if( !is_null( $score ) || !is_null( $severity ) || !is_null( $exploitable ) ) { |
| 101 |
|
| 102 |
array_push( |
| 103 |
$vulnerabilities, |
| 104 |
array( |
| 105 |
'Version' => ' ', |
| 106 |
'Vulnerability information' => ' ', |
| 107 |
) |
| 108 |
); |
| 109 |
|
| 110 |
if( !is_null( $score ) ) { |
| 111 |
array_push( |
| 112 |
$vulnerabilities, |
| 113 |
array( |
| 114 |
'Version' => ' ', |
| 115 |
'Vulnerability information' => __( 'Global score: ', 'wpvulnerability' ) . $score . ' / 10', |
| 116 |
) |
| 117 |
); |
| 118 |
} |
| 119 |
if( !is_null( $severity ) ) { |
| 120 |
array_push( |
| 121 |
$vulnerabilities, |
| 122 |
array( |
| 123 |
'Version' => ' ', |
| 124 |
'Vulnerability information' => __( 'Severity: ', 'wpvulnerability' ) . $severity, |
| 125 |
) |
| 126 |
); |
| 127 |
} |
| 128 |
if( !is_null( $exploitable ) ) { |
| 129 |
array_push( |
| 130 |
$vulnerabilities, |
| 131 |
array( |
| 132 |
'Version' => ' ', |
| 133 |
'Vulnerability information' => __( 'Exploitability: ', 'wpvulnerability' ) . $exploitable . ' / 10', |
| 134 |
) |
| 135 |
); |
| 136 |
|
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
if( isset( $vulnerability['source'] ) && count( $vulnerability['source'] ) ) { |
| 141 |
|
| 142 |
array_push( |
| 143 |
$vulnerabilities, |
| 144 |
array( |
| 145 |
'Version' => ' ', |
| 146 |
'Vulnerability information' => ' ', |
| 147 |
) |
| 148 |
); |
| 149 |
|
| 150 |
foreach( $vulnerability['source'] as $vulnerability_source ) { |
| 151 |
|
| 152 |
array_push( |
| 153 |
$vulnerabilities, |
| 154 |
array( |
| 155 |
'Version' => ' ', |
| 156 |
'Vulnerability information' => '[+] ' . trim( html_entity_decode( wp_kses( $vulnerability_source['name'], 'strip' ) ) ), |
| 157 |
) |
| 158 |
); |
| 159 |
array_push( |
| 160 |
$vulnerabilities, |
| 161 |
array( |
| 162 |
'Version' => ' ', |
| 163 |
'Vulnerability information' => ' ' . esc_url_raw( $vulnerability_source['link'], 'strip'), |
| 164 |
) |
| 165 |
); |
| 166 |
|
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
array_push( |
| 171 |
$vulnerabilities, |
| 172 |
array( |
| 173 |
'Version' => ' ', |
| 174 |
'Vulnerability information' => ' ', |
| 175 |
) |
| 176 |
); |
| 177 |
|
| 178 |
} |
| 179 |
|
| 180 |
// Format and output the vulnerabilities in a table |
| 181 |
WP_CLI\Utils\format_items( |
| 182 |
'table', |
| 183 |
$vulnerabilities, |
| 184 |
array( 'Version', 'Vulnerability information' ) |
| 185 |
); |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Plugin section in WP-CLI command |
| 191 |
* |
| 192 |
* @since 2.0.0 |
| 193 |
* |
| 194 |
* @return void |
| 195 |
*/ |
| 196 |
function wpvulnerability_cli_plugins() { |
| 197 |
|
| 198 |
// Get plugin vulnerabilities |
| 199 |
$plugin_vulnerabilities = wpvulnerability_plugin_get_vulnerabilities(); |
| 200 |
|
| 201 |
// Loop through each plugin vulnerability |
| 202 |
foreach ( $plugin_vulnerabilities as $plugin ) { |
| 203 |
|
| 204 |
if ( 1 === $plugin['vulnerable'] ) { |
| 205 |
|
| 206 |
$name = trim( html_entity_decode( wp_kses( $plugin['Name'], 'strip' ) ) ); |
| 207 |
|
| 208 |
// Output the plugin name with red color |
| 209 |
WP_CLI::line( WP_CLI::colorize( "%r$name%n " ) ); |
| 210 |
|
| 211 |
// Prepare the vulnerabilities array for table format output |
| 212 |
$vulnerabilities = array(); |
| 213 |
foreach ( $plugin['vulnerabilities'] as $vulnerability ) { |
| 214 |
|
| 215 |
$severity = null; |
| 216 |
if( isset( $vulnerability['impact']['cvss']['severity'] ) ) { |
| 217 |
$severity = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] ); |
| 218 |
} |
| 219 |
$exploitable = null; |
| 220 |
if( isset( $vulnerability['impact']['cvss']['exploitable'] ) ) { |
| 221 |
$exploitable = number_format( (float) $vulnerability['impact']['cvss']['exploitable'], 1, '.', '' ); |
| 222 |
} |
| 223 |
|
| 224 |
// Add the vulnerability details to the array |
| 225 |
array_push( |
| 226 |
$vulnerabilities, |
| 227 |
array( |
| 228 |
'Version' => trim( html_entity_decode( wp_kses( $vulnerability['versions'], 'strip' ) ) ), |
| 229 |
'Vulnerability information' => '[*] ' . trim( html_entity_decode( wp_kses( $vulnerability['name'], 'strip' ) ) ), |
| 230 |
) |
| 231 |
); |
| 232 |
if( (int)$vulnerability['closed'] || (int)$vulnerability['unfixed'] ) { |
| 233 |
if( (int)$vulnerability['closed'] ) { |
| 234 |
|
| 235 |
array_push( |
| 236 |
$vulnerabilities, |
| 237 |
array( |
| 238 |
'Version' => ' ', |
| 239 |
'Vulnerability information' => '*** ' . __( 'This plugin is closed. Please replace it with another.', 'wpvulnerability' ) . ' ***', |
| 240 |
) |
| 241 |
); |
| 242 |
|
| 243 |
} |
| 244 |
if( (int)$vulnerability['unfixed'] ) { |
| 245 |
|
| 246 |
array_push( |
| 247 |
$vulnerabilities, |
| 248 |
array( |
| 249 |
'Version' => ' ', |
| 250 |
'Vulnerability information' => '*** ' . __( 'This vulnerability appears to be unpatched. Stay tuned for upcoming plugin updates.', 'wpvulnerability' ) . ' ***', |
| 251 |
) |
| 252 |
); |
| 253 |
|
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
$what = array(); |
| 258 |
if( isset( $vulnerability['impact']['cwe'] ) && count( $vulnerability['impact']['cwe'] ) ) { |
| 259 |
|
| 260 |
array_push( |
| 261 |
$vulnerabilities, |
| 262 |
array( |
| 263 |
'Version' => ' ', |
| 264 |
'Vulnerability information' => ' ', |
| 265 |
) |
| 266 |
); |
| 267 |
|
| 268 |
foreach( $vulnerability['impact']['cwe'] as $vulnerability_cwe ) { |
| 269 |
|
| 270 |
array_push( |
| 271 |
$vulnerabilities, |
| 272 |
array( |
| 273 |
'Version' => ' ', |
| 274 |
'Vulnerability information' => trim( html_entity_decode( wp_kses( $vulnerability_cwe['name'], 'strip' ) ) ), |
| 275 |
) |
| 276 |
); |
| 277 |
|
| 278 |
array_push( |
| 279 |
$vulnerabilities, |
| 280 |
array( |
| 281 |
'Version' => ' ', |
| 282 |
'Vulnerability information' => trim( html_entity_decode( wp_kses( $vulnerability_cwe['description'], 'strip' ) ) ), |
| 283 |
) |
| 284 |
); |
| 285 |
|
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
$score = null; |
| 290 |
if( isset( $vulnerability['impact']['cvss']['score'] ) ) { |
| 291 |
$score = number_format( (float) $vulnerability['impact']['cvss']['score'], 1, '.', '' ); |
| 292 |
} |
| 293 |
$severity = null; |
| 294 |
if( isset( $vulnerability['impact']['cvss']['severity'] ) ) { |
| 295 |
$severity = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] ); |
| 296 |
} |
| 297 |
$exploitable = null; |
| 298 |
if( isset( $vulnerability['impact']['cvss']['exploitable'] ) ) { |
| 299 |
$exploitable = number_format( (float) $vulnerability['impact']['cvss']['exploitable'], 1, '.', '' ); |
| 300 |
} |
| 301 |
|
| 302 |
if( !is_null( $score ) || !is_null( $severity ) || !is_null( $exploitable ) ) { |
| 303 |
|
| 304 |
array_push( |
| 305 |
$vulnerabilities, |
| 306 |
array( |
| 307 |
'Version' => ' ', |
| 308 |
'Vulnerability information' => ' ', |
| 309 |
) |
| 310 |
); |
| 311 |
|
| 312 |
if( !is_null( $score ) ) { |
| 313 |
array_push( |
| 314 |
$vulnerabilities, |
| 315 |
array( |
| 316 |
'Version' => ' ', |
| 317 |
'Vulnerability information' => __( 'Global score: ', 'wpvulnerability' ) . $score . ' / 10', |
| 318 |
) |
| 319 |
); |
| 320 |
} |
| 321 |
if( !is_null( $severity ) ) { |
| 322 |
array_push( |
| 323 |
$vulnerabilities, |
| 324 |
array( |
| 325 |
'Version' => ' ', |
| 326 |
'Vulnerability information' => __( 'Severity: ', 'wpvulnerability' ) . $severity, |
| 327 |
) |
| 328 |
); |
| 329 |
} |
| 330 |
if( !is_null( $exploitable ) ) { |
| 331 |
array_push( |
| 332 |
$vulnerabilities, |
| 333 |
array( |
| 334 |
'Version' => ' ', |
| 335 |
'Vulnerability information' => __( 'Exploitability: ', 'wpvulnerability' ) . $exploitable . ' / 10', |
| 336 |
) |
| 337 |
); |
| 338 |
|
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
if( isset( $vulnerability['source'] ) && count( $vulnerability['source'] ) ) { |
| 343 |
|
| 344 |
array_push( |
| 345 |
$vulnerabilities, |
| 346 |
array( |
| 347 |
'Version' => ' ', |
| 348 |
'Vulnerability information' => ' ', |
| 349 |
) |
| 350 |
); |
| 351 |
|
| 352 |
foreach( $vulnerability['source'] as $vulnerability_source ) { |
| 353 |
|
| 354 |
array_push( |
| 355 |
$vulnerabilities, |
| 356 |
array( |
| 357 |
'Version' => ' ', |
| 358 |
'Vulnerability information' => '[+] ' . trim( html_entity_decode( wp_kses( $vulnerability_source['name'], 'strip' ) ) ), |
| 359 |
) |
| 360 |
); |
| 361 |
array_push( |
| 362 |
$vulnerabilities, |
| 363 |
array( |
| 364 |
'Version' => ' ', |
| 365 |
'Vulnerability information' => ' ' . esc_url_raw( $vulnerability_source['link'], 'strip'), |
| 366 |
) |
| 367 |
); |
| 368 |
|
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
array_push( |
| 373 |
$vulnerabilities, |
| 374 |
array( |
| 375 |
'Version' => ' ', |
| 376 |
'Vulnerability information' => ' ', |
| 377 |
) |
| 378 |
); |
| 379 |
|
| 380 |
} |
| 381 |
|
| 382 |
// Format and output the vulnerabilities in a table |
| 383 |
WP_CLI\Utils\format_items( |
| 384 |
'table', |
| 385 |
$vulnerabilities, |
| 386 |
array( 'Version', 'Vulnerability information' ) |
| 387 |
); |
| 388 |
|
| 389 |
} |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
/** |
| 394 |
* Theme section in WP-CLI command |
| 395 |
* |
| 396 |
* @since 2.0.0 |
| 397 |
* |
| 398 |
* @return void |
| 399 |
*/ |
| 400 |
function wpvulnerability_cli_themes() { |
| 401 |
|
| 402 |
// Get theme vulnerabilities |
| 403 |
$theme_vulnerabilities = wpvulnerability_theme_get_vulnerabilities(); |
| 404 |
|
| 405 |
// Loop through each theme vulnerability |
| 406 |
foreach ( $theme_vulnerabilities as $theme ) { |
| 407 |
|
| 408 |
if ( 1 === $theme['wpvulnerability']['vulnerable'] ) { |
| 409 |
|
| 410 |
$name = trim( html_entity_decode( wp_kses( $theme['wpvulnerability']['name'], 'strip' ) ) ); |
| 411 |
|
| 412 |
// Output the theme name with red color |
| 413 |
WP_CLI::line( WP_CLI::colorize( "%r$name%n " ) ); |
| 414 |
|
| 415 |
// Prepare the vulnerabilities array for table format output |
| 416 |
$vulnerabilities = array(); |
| 417 |
foreach ( $theme['wpvulnerability']['vulnerabilities'] as $vulnerability ) { |
| 418 |
|
| 419 |
$severity = null; |
| 420 |
if( isset( $vulnerability['impact']['cvss']['severity'] ) ) { |
| 421 |
$severity = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] ); |
| 422 |
} |
| 423 |
$exploitable = null; |
| 424 |
if( isset( $vulnerability['impact']['cvss']['exploitable'] ) ) { |
| 425 |
$exploitable = number_format( (float) $vulnerability['impact']['cvss']['exploitable'], 1, '.', '' ); |
| 426 |
} |
| 427 |
|
| 428 |
// Add the vulnerability details to the array |
| 429 |
array_push( |
| 430 |
$vulnerabilities, |
| 431 |
array( |
| 432 |
'Version' => trim( html_entity_decode( wp_kses( $vulnerability['versions'], 'strip' ) ) ), |
| 433 |
'Vulnerability information' => '[*] ' . trim( html_entity_decode( wp_kses( $vulnerability['name'], 'strip' ) ) ), |
| 434 |
) |
| 435 |
); |
| 436 |
if( (int)$vulnerability['closed'] || (int)$vulnerability['unfixed'] ) { |
| 437 |
if( (int)$vulnerability['closed'] ) { |
| 438 |
|
| 439 |
array_push( |
| 440 |
$vulnerabilities, |
| 441 |
array( |
| 442 |
'Version' => ' ', |
| 443 |
'Vulnerability information' => '*** ' . __( 'This theme is closed. Please replace it with another.', 'wpvulnerability' ) . ' ***', |
| 444 |
) |
| 445 |
); |
| 446 |
|
| 447 |
} |
| 448 |
if( (int)$vulnerability['unfixed'] ) { |
| 449 |
|
| 450 |
array_push( |
| 451 |
$vulnerabilities, |
| 452 |
array( |
| 453 |
'Version' => ' ', |
| 454 |
'Vulnerability information' => '*** ' . __( 'This vulnerability appears to be unpatched. Stay tuned for upcoming theme updates.', 'wpvulnerability' ) . ' ***', |
| 455 |
) |
| 456 |
); |
| 457 |
|
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
$what = array(); |
| 462 |
if( isset( $vulnerability['impact']['cwe'] ) && count( $vulnerability['impact']['cwe'] ) ) { |
| 463 |
|
| 464 |
array_push( |
| 465 |
$vulnerabilities, |
| 466 |
array( |
| 467 |
'Version' => ' ', |
| 468 |
'Vulnerability information' => ' ', |
| 469 |
) |
| 470 |
); |
| 471 |
|
| 472 |
foreach( $vulnerability['impact']['cwe'] as $vulnerability_cwe ) { |
| 473 |
|
| 474 |
array_push( |
| 475 |
$vulnerabilities, |
| 476 |
array( |
| 477 |
'Version' => ' ', |
| 478 |
'Vulnerability information' => trim( html_entity_decode( wp_kses( $vulnerability_cwe['name'], 'strip' ) ) ), |
| 479 |
) |
| 480 |
); |
| 481 |
|
| 482 |
array_push( |
| 483 |
$vulnerabilities, |
| 484 |
array( |
| 485 |
'Version' => ' ', |
| 486 |
'Vulnerability information' => trim( html_entity_decode( wp_kses( $vulnerability_cwe['description'], 'strip' ) ) ), |
| 487 |
) |
| 488 |
); |
| 489 |
|
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
$score = null; |
| 494 |
if( isset( $vulnerability['impact']['cvss']['score'] ) ) { |
| 495 |
$score = number_format( (float) $vulnerability['impact']['cvss']['score'], 1, '.', '' ); |
| 496 |
} |
| 497 |
$severity = null; |
| 498 |
if( isset( $vulnerability['impact']['cvss']['severity'] ) ) { |
| 499 |
$severity = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] ); |
| 500 |
} |
| 501 |
$exploitable = null; |
| 502 |
if( isset( $vulnerability['impact']['cvss']['exploitable'] ) ) { |
| 503 |
$exploitable = number_format( (float) $vulnerability['impact']['cvss']['exploitable'], 1, '.', '' ); |
| 504 |
} |
| 505 |
|
| 506 |
if( !is_null( $score ) || !is_null( $severity ) || !is_null( $exploitable ) ) { |
| 507 |
|
| 508 |
array_push( |
| 509 |
$vulnerabilities, |
| 510 |
array( |
| 511 |
'Version' => ' ', |
| 512 |
'Vulnerability information' => ' ', |
| 513 |
) |
| 514 |
); |
| 515 |
|
| 516 |
if( !is_null( $score ) ) { |
| 517 |
array_push( |
| 518 |
$vulnerabilities, |
| 519 |
array( |
| 520 |
'Version' => ' ', |
| 521 |
'Vulnerability information' => __( 'Global score: ', 'wpvulnerability' ) . $score . ' / 10', |
| 522 |
) |
| 523 |
); |
| 524 |
} |
| 525 |
if( !is_null( $severity ) ) { |
| 526 |
array_push( |
| 527 |
$vulnerabilities, |
| 528 |
array( |
| 529 |
'Version' => ' ', |
| 530 |
'Vulnerability information' => __( 'Severity: ', 'wpvulnerability' ) . $severity, |
| 531 |
) |
| 532 |
); |
| 533 |
} |
| 534 |
if( !is_null( $exploitable ) ) { |
| 535 |
array_push( |
| 536 |
$vulnerabilities, |
| 537 |
array( |
| 538 |
'Version' => ' ', |
| 539 |
'Vulnerability information' => __( 'Exploitability: ', 'wpvulnerability' ) . $exploitable . ' / 10', |
| 540 |
) |
| 541 |
); |
| 542 |
|
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
if( isset( $vulnerability['source'] ) && count( $vulnerability['source'] ) ) { |
| 547 |
|
| 548 |
array_push( |
| 549 |
$vulnerabilities, |
| 550 |
array( |
| 551 |
'Version' => ' ', |
| 552 |
'Vulnerability information' => ' ', |
| 553 |
) |
| 554 |
); |
| 555 |
|
| 556 |
foreach( $vulnerability['source'] as $vulnerability_source ) { |
| 557 |
|
| 558 |
array_push( |
| 559 |
$vulnerabilities, |
| 560 |
array( |
| 561 |
'Version' => ' ', |
| 562 |
'Vulnerability information' => '[+] ' . trim( html_entity_decode( wp_kses( $vulnerability_source['name'], 'strip' ) ) ), |
| 563 |
) |
| 564 |
); |
| 565 |
array_push( |
| 566 |
$vulnerabilities, |
| 567 |
array( |
| 568 |
'Version' => ' ', |
| 569 |
'Vulnerability information' => ' ' . esc_url_raw( $vulnerability_source['link'], 'strip'), |
| 570 |
) |
| 571 |
); |
| 572 |
|
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
array_push( |
| 577 |
$vulnerabilities, |
| 578 |
array( |
| 579 |
'Version' => ' ', |
| 580 |
'Vulnerability information' => ' ', |
| 581 |
) |
| 582 |
); |
| 583 |
|
| 584 |
} |
| 585 |
|
| 586 |
// Format and output the vulnerabilities in a table |
| 587 |
WP_CLI\Utils\format_items( |
| 588 |
'table', |
| 589 |
$vulnerabilities, |
| 590 |
array( 'Version', 'Vulnerability information' ) |
| 591 |
); |
| 592 |
|
| 593 |
} |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
/** |
| 598 |
* Switches the command to show the list of vulnerabilities detected in the site. |
| 599 |
* |
| 600 |
* @param array $args The subcommand to execute. |
| 601 |
* @return void |
| 602 |
*/ |
| 603 |
function wpvulnerability_cli_command( $args ) { |
| 604 |
|
| 605 |
// Selects the correct function to execute based on the subcommand. |
| 606 |
switch ( $args[0] ) { |
| 607 |
case 'core': |
| 608 |
wpvulnerability_cli_core(); |
| 609 |
break; |
| 610 |
case 'plugins': |
| 611 |
wpvulnerability_cli_plugins(); |
| 612 |
break; |
| 613 |
case 'themes': |
| 614 |
wpvulnerability_cli_themes(); |
| 615 |
break; |
| 616 |
default: |
| 617 |
// Displays an error message for an invalid subcommand. |
| 618 |
WP_CLI::error( "'$args[0]' is not a registered subcommand of 'wpvulnerability'.\nAvailable subcommands: core, plugins, themes" ); |
| 619 |
break; |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
/** |
| 624 |
* Adds a WP-CLI command to show the list of vulnerabilities detected in your site. |
| 625 |
* |
| 626 |
* EXAMPLES |
| 627 |
* |
| 628 |
* - wp wpvulnerability core |
| 629 |
* - wp wpvulnerability plugins |
| 630 |
* - wp wpvulnerability themes |
| 631 |
* |
| 632 |
* @param object $args Arguments passed from the command line. |
| 633 |
* |
| 634 |
* @return void |
| 635 |
*/ |
| 636 |
WP_CLI::add_command( |
| 637 |
'wpvulnerability', |
| 638 |
'wpvulnerability_cli_command', |
| 639 |
array( |
| 640 |
'shortdesc' => 'Show the list of vulnerabilities detected in your site.', |
| 641 |
'synopsis' => array( |
| 642 |
array( |
| 643 |
'type' => 'positional', |
| 644 |
'name' => 'subcommand', |
| 645 |
'description' => 'subcommand [core|plugins|themes].', |
| 646 |
'optional' => false, |
| 647 |
), |
| 648 |
), |
| 649 |
'when' => 'after_wp_load', |
| 650 |
'longdesc' => "EXAMPLES:\n\n - wp wpvulnerability core\n - wp wpvulnerability plugins\n - wp wpvulnerability themes", |
| 651 |
) |
| 652 |
); |
| 653 |
|
| 654 |
} |
| 655 |
|