Skip to content

Commit 74a2943

Browse files
committed
fix version compare
fix: using to_inclusive to adjust version compare, fix: add all vulnerable versions in the clean data file, added: jellix version compare
1 parent 61d7938 commit 74a2943

File tree

101 files changed

+1684
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1684
-20
lines changed

.gitattributes

100644100755
File mode changed.

LICENSE

100644100755
File mode changed.

README.md

100644100755
File mode changed.

composer.json

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"require": {
3-
"halaxa/json-machine": "^1.1"
3+
"halaxa/json-machine": "^1.1",
4+
"jelix/version": "^2.0"
45
}
56
}

composer.lock

100644100755
Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hhdev-mwp-check-plugins-vulnerability.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Check Plugins Vulnerability
44
* Plugin URI: https://haha.nl
55
* Description: Check the installed website plugins for vulnerability use the wordfence vulnerability data feed api.
6-
* Version: 1.0.5
6+
* Version: 1.0.6
77
* Author: herbert hoekstra - haha!
88
* Author URI: https://haha.nl
99
* Documentation URI: https://haha.nl/wordpress-plug-in-op-maat/
@@ -100,6 +100,8 @@ function settings() {
100100
// ------------------------
101101
function activate_this_plugin() {
102102

103+
require_once __DIR__.'/vendor/autoload.php';
104+
103105
//Checking if the MainWP plugin is enabled. This filter will return true if the main plugin is activated.
104106
$this->mainwpMainActivated = apply_filters('mainwp_activated_check', $this->mainwpMainActivated);
105107

@@ -169,11 +171,16 @@ public function hhdev_get_file_date(){
169171
}
170172

171173
// check version compare
174+
// if A < B -> -1
175+
// if A == B -> 0
176+
// if A > B -> 1
172177
// ----------------------
173-
// By default, version_compare() returns -1 if the first version is lower than the second, 0 if they are equal, and 1 if the second is lower.
174-
public function hhdev_plugin_needs_update($plugin_version, $data_version){
178+
public function hhdev_plugin_needs_update($plugin_version, $data_version, $compare){
179+
180+
$result = \Jelix\Version\VersionComparator::compareVersion($plugin_version, $data_version);
175181

176-
if( version_compare($plugin_version,$data_version) <= 0) return true;
182+
if($compare == '<' && $result == -1) return true;
183+
if($compare == '<=' && $result == 0) return true;
177184

178185
return false;
179186
}
@@ -202,10 +209,6 @@ public function hhdev_get_version_from_array($array) {
202209
// -----------------------------
203210
public function hhdev_make_adapted_file() {
204211

205-
require_once __DIR__.'/vendor/autoload.php';
206-
207-
// get updated last month
208-
209212
// get the current date
210213
date_default_timezone_set(get_option( 'timezone_string' ));
211214
$cur_date = date('Y-m-d');
@@ -228,7 +231,8 @@ public function hhdev_make_adapted_file() {
228231
if($plugin->updated > $date) {
229232
// write to new array
230233
// check if type is plugin
231-
if($plugin->software[0]->type === 'plugin' && !array_key_exists($plugin->software[0]->slug, $file)) $file[$plugin->software[0]->slug] = array(
234+
if($plugin->software[0]->type === 'plugin') $file[] = array(
235+
'slug' => $plugin->software[0]->slug,
232236
'title' => $plugin->title,
233237
'name' => $plugin->software[0]->name,
234238
'affected_versions' => json_decode(json_encode($plugin->software[0]->affected_versions),true),
@@ -241,7 +245,7 @@ public function hhdev_make_adapted_file() {
241245

242246
}
243247

244-
//print_r($file['litespeed-cache']);
248+
// print_r($file);
245249

246250
//echo wp_sprintf( '<p>', __('Records saved: %s','hhdev-mwpcpv'), count($file),'</p>');
247251

@@ -252,7 +256,6 @@ public function hhdev_make_adapted_file() {
252256

253257
}
254258

255-
256259
}
257260

258261
global $MainWPCheckPluginVulnerabilityActivator;
@@ -358,8 +361,9 @@ public function hhdev_make_adapted_file() {
358361

359362
/*
360363
change log:
361-
- 1.0.5 fixed missing entries in cleaned data file
362-
- 1.0.4 removed gitignore from /vendor/
364+
- 1.0.6 fix: using to_inclusive to adjust version compare, fix: add all vulnerable versions in the clean data file, added: jellix version compare
365+
- 1.0.5 fix: missing entries in cleaned data file
366+
- 1.0.4 removed: gitignore from /vendor/
363367
- 1.0.3 changed adapted file to hold only plugin data
364368
- 1.0.2 split the file up into 2 files, plugin and dashboard
365369
- 1.0.1 initial set up

hhdev-mwpcpv-dashboard.php

100644100755
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,29 @@ public static function hhdev_mwpcpv_render_page() {
151151
$plugin_slug = explode('/', $plugin['slug']);
152152
$slug = $plugin_slug[0];
153153

154-
// load file data before foreach loops
155-
156154
foreach ( $file as $key => $plugin_data) {
157155

158-
if($key === $slug) {
156+
if($plugin_data['slug'] == $slug) {
157+
158+
$vuln_notice = false;
159159

160160
// is patched?
161161
$patched = wp_sprintf( __('No','hhdev-mwpcpv'));
162162
if($plugin_data['patched']) $patched = wp_sprintf( __('Yes','hhdev-mwpcpv'));
163163

164164
// get the vuln version
165+
$vuln_version = '';
165166
$vuln_version = $MainWPCheckPluginVulnerabilityActivator->hhdev_get_version_from_array($plugin_data['affected_versions'])['to_version'];
166167

167-
if($MainWPCheckPluginVulnerabilityActivator->hhdev_plugin_needs_update($plugin['version'],$vuln_version)) {
168+
// get the compare operator
169+
$to_inclusive = $MainWPCheckPluginVulnerabilityActivator->hhdev_get_version_from_array($plugin_data['affected_versions'])['to_inclusive'];
170+
171+
$compare = '<';
172+
if($to_inclusive) $compare = '<=';
173+
174+
// if ($slug == 'wp-mail-logging') echo '<p>vuln version: '.$vuln_version.' -> plugin: '.$plugin['version'].'-> '.$plugin_data['title'].'</p>';
175+
176+
if($MainWPCheckPluginVulnerabilityActivator->hhdev_plugin_needs_update($plugin['version'],$vuln_version,$compare)) {
168177

169178
echo '<h3>'.$plugin['name'].'</h3>';
170179
echo wp_sprintf( __('Website plugin version: %s','hhdev-mwpcpv'), $plugin['version']);
@@ -181,7 +190,6 @@ public static function hhdev_mwpcpv_render_page() {
181190

182191
// set vuln plugin notice to true
183192
$vuln_notice = true;
184-
185193
}
186194

187195
} // end if

languages/hhdev-mwpcpv-nl_NL.mo

100644100755
File mode changed.

languages/hhdev-mwpcpv-nl_NL.po

100644100755
File mode changed.

languages/hhdev-mwpcpv.pot

100644100755
File mode changed.

0 commit comments

Comments
 (0)