Skip to content

Commit

Permalink
simplify the code handling the vulnerability checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzsequence committed May 24, 2023
1 parent f9637bd commit 7c8aafd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
21 changes: 10 additions & 11 deletions php/pantheon/checks/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,31 @@ public function run() {
$slug = substr($plugin_path, 0, stripos($plugin_path,'/'));
}

if ( $should_check_vulnerabilities ) {
$vulnerable = $this->is_vulnerable($slug, $data['Version']);
}

$needs_update = 0;
$available = '-';
if (isset($update[$plugin_path])) {
$needs_update = 1;
$available = $update[$plugin_path]->update->new_version;
}

if ( $should_check_vulnerabilities && $vulnerable ) {
// Todo: Replace this URL with a Patchstack URL
$vulnerable = sprintf('<a href="https://wpscan.com/plugins/%s" target="_blank" >more info</a>', $slug );
} elseif ( $should_check_vulnerabilities ) {
$vulnerable = "None";
}

$report[ $slug ] = array(
'slug' => $slug,
'installed' => (string) $data['Version'],
'available' => (string) $available,
'needs_update' => (string) $needs_update,
);

// If we're checking for vulnerabilities, do stuff.
if ( $should_check_vulnerabilities ) {
$vulnerable = $this->is_vulnerable($slug, $data['Version']);
$report[ $slug ]['vulnerable'] = $vulnerable;

if ( $vulnerable ) {
// Todo: Replace this URL with a Patchstack URL
$vulnerable = sprintf('<a href="https://wpscan.com/plugins/%s" target="_blank" >more info</a>', $slug );
} else {
$vulnerable = "None";
}
}
}
$this->alerts = $report;
Expand Down Expand Up @@ -198,6 +196,7 @@ public function message(Messenger $messenger) {
$rows = array();
$count_update = 0;
$count_vuln = 0;

foreach( $this->alerts as $alert ) {
$class = 'ok';
if ($alert['needs_update']) {
Expand Down
19 changes: 10 additions & 9 deletions php/pantheon/checks/themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,13 @@ public function run() {

$data = wp_get_theme($slug);
$version = $data->version;
if ( $should_check_vulnerabilities ) {
$vulnerable = $this->is_vulnerable($slug, $version);
}

$needs_update = 0;
$available = '-';

if (isset($update[$theme_path])) {
$needs_update = 1;
$available = $update[$slug]->update["new_version"];
}
if ( $should_check_vulnerabilities && $vulnerable ) {
$vulnerable = sprintf('<a href="https://wpscan.com/themes/%s" target="_blank" >more info</a>', $slug );
} elseif ( $should_check_vulnerabilities ) {
$vulnerable = "None";
}

$report[$slug] = array(
'slug' => $slug,
Expand All @@ -82,8 +74,17 @@ public function run() {
'needs_update' => (string) $needs_update,
);

// If we're checking for vulnerabilities, do stuff.
if ( $should_check_vulnerabilities ) {
$vulnerable = $this->is_vulnerable($slug, $version);
$report[ $slug ]['vulnerable'] = $vulnerable;

if ( $vulnerable ) {
// Todo: Replace this link with one to Patchstack.
$vulnerable = sprintf('<a href="https://wpscan.com/themes/%s" target="_blank" >more info</a>', $slug );
} else {
$vulnerable = "None";
}
}
}
$this->alerts = $report;
Expand Down

0 comments on commit 7c8aafd

Please sign in to comment.