Skip to content

Commit 85531f7

Browse files
committed
scan websites based on tags
added option to scan sites based on tags (groups), some style changes
1 parent dc46245 commit 85531f7

File tree

4 files changed

+118
-50
lines changed

4 files changed

+118
-50
lines changed

hhdev-mwpcpv-dashboard.php

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
// mwpcpv dashboard
3-
// version: 1.0.11
3+
// version: 1.1.0
44
// ---------------------
55

66

@@ -64,10 +64,12 @@ public static function hhdev_mwpcpv_render_page() {
6464
?>
6565
<div id="mainwp_custom_dashboard_extension">
6666

67+
6768
<div class='ui segment'>
69+
6870
<h2><?php echo wp_sprintf( __('Check Plugins Vulnerability','hhdev-mwpcpv')); ?></h2>
6971

70-
<p><?php echo sprintf( __( 'Here you can check if there are plugins that need updating for security reasons.', 'hhdev-mwpcpv' )); ?></p>
72+
<div class="sub header"><?php echo sprintf( __( 'Here you can check if there are plugins that need updating for security reasons.', 'hhdev-mwpcpv' )); ?></div>
7173

7274
<ul>
7375
<li><?php echo sprintf( __( 'Data from %s is used to check plugins for each childsite.', 'hhdev-mwpcpv' ),
@@ -127,24 +129,37 @@ public static function hhdev_mwpcpv_render_page() {
127129
$('#toggle-novuln').removeClass('active').css("background-color","#7FB100");
128130
}
129131
});
132+
$('.mainwp-page-title').text('Security');
130133
});
131134
</script>
132135
<style>
133136
<!--
134-
#toggle-novuln { max-width: 320px; border: 1px solid #ccc; border-radius: 3px; -moz-border-radius: 3px; padding: 3px; text-align: center; background-color: none; cursor:pointer;}
135-
.ui.info.message {max-width: 480px;}
136-
.mainwp-page-title {display: none;}
137+
#toggle-novuln { max-width: 320px; border: 1px solid #ccc; border-radius: 0.28571429rem; -moz-border-radius: 0.28571429rem; padding: 3px; text-align: center; background-color: none; cursor:pointer;}
138+
.ui.info.message, .ui.segment {max-width: 680px;}
139+
/*.mainwp-page-title {display: none;}*/
140+
#mainwp-page-navigation-wrapper, .mainwp-page-navigation {display: none !important;min-width: 0px;}
141+
.mainwp-individual-site-view #mainwp-site-mode-wrap { width: 100%; float: none;}
142+
#mainwp_custom_dashboard_extension .ui.segment.website { margin-bottom: 10px; max-width: 680px; margin-left: 10px; border: 1px solid #ccc; border-radius: 0.28571429rem;}
137143
-->
138144
</style>
139145
<div class='ui segment'>
140-
<p><?php _e('Please make sure you do a "sync dashboard with sites" before you run a scan!','hhdev-mwpcpv'); ?></p>
146+
<div class="sub header"><?php _e('Please make sure you do a "sync dashboard with sites" before you run a scan!','hhdev-mwpcpv'); ?></div>
141147
<form id="run-scan" name="run-scan" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>" method="post">
142148
<p><input name="mwpcpv-run-scan" type="hidden" value="1" /></p>
143149
<?php
144150
// hide button is there is no file yet
145151
if($MainWPCheckPluginVulnerabilityActivator->hhdev_data_file_exists()) {
152+
153+
// get a groups dropmenu
154+
// posts: value= mwpcpv-groups -> show_all or group ID
155+
// ------------------
156+
if(isset($_POST['mwpcpv-run-scan']) && $_POST['mwpcpv-groups']) $selected_group = $_POST['mwpcpv-groups']; // selected option
157+
echo '<div class="sub header">';
158+
_e('Choose a site group to scan:','hhdev-mwpcpv');
159+
echo '&nbsp;'.$MainWPCheckPluginVulnerabilityActivator->hhdev_get_groups_dropdown($selected_group);
160+
echo '</div>';
146161
?>
147-
<p><a class="ui button green" href="#" onclick="javascript:document.getElementById('run-scan').submit();"><?php _e('Run the scan!','hhdev-mwpcpv'); ?></a></p>
162+
<div class="sub header"><a class="ui button green" href="#" onclick="javascript:document.getElementById('run-scan').submit();"><?php _e('Run the scan!','hhdev-mwpcpv'); ?></a></div>
148163
<?php } // end if file exist ?>
149164

150165
</form>
@@ -158,18 +173,35 @@ public static function hhdev_mwpcpv_render_page() {
158173
// hit the button to run the scan
159174
if (isset($_POST['mwpcpv-run-scan'])) {
160175

161-
// Fetch all child-sites
162-
$websites = apply_filters('mainwp_getsites', $MainWPCheckPluginVulnerabilityActivator->getChildFile(), $MainWPCheckPluginVulnerabilityActivator->getChildKey(), null);
176+
// print_r($groups);
177+
178+
/*Array ( [11] => stdClass Object ( [id] => 11 [userid] => 2 [name] => alleen-monitoren [color] => [nrsites] => 3 ) [12] => stdClass Object ( [id] => 12 [userid] => 2 [name] => Bedrock-setup [color] => #6435c9 [nrsites] => 24 ) [3] => stdClass Object ( [id] => 3 [userid] => 2 [name] => contract-combell [color] => [nrsites] => 7 ) [10] => stdClass Object ( [id] => 10 [userid] => 2 [name] => contract-extern [color] => [nrsites] => 4 ) [2] => stdClass Object ( [id] => 2 [userid] => 2 [name] => contract-shop [color] => [nrsites] => 1 ) [5] => stdClass Object ( [id] => 5 [userid] => 2 [name] => contract-uniek [color] => [nrsites] => 4 ) [9] => stdClass Object ( [id] => 9 [userid] => 2 [name] => contract-xynta [color] => [nrsites] => 9 ) [1] => stdClass Object ( [id] => 1 [userid] => 1 [name] => eigen [color] => [nrsites] => 6 ) [4] => stdClass Object ( [id] => 4 [userid] => 2 [name] => urenkaart [color] => [nrsites] => 7 ) [6] => stdClass Object ( [id] => 6 [userid] => 2 [name] => xynta-dev [color] => [nrsites] => 2 ) ) */
179+
180+
$group_id = $_POST['mwpcpv-groups'];
181+
182+
// get site ids for certain group ID (tag)
183+
// -------------------
184+
$websites = \MainWP\Dashboard\MainWP_DB::instance()->get_websites_by_group_id( $group_id );
185+
// print_r($websites);
186+
187+
// Fetch all child-sites if on show_all dropmenu option
188+
// -------------------
189+
if($group_id == 'show_all') $websites = apply_filters('mainwp_getsites', $MainWPCheckPluginVulnerabilityActivator->getChildFile(), $MainWPCheckPluginVulnerabilityActivator->getChildKey(), null);
163190

164191
$sites_ids = array();
165-
if ( is_array( $websites ) ) {
192+
if ( is_array( $websites ) ) {
166193
foreach ( $websites as $website ) {
194+
// switch for group sites or all sites
195+
if($group_id == 'show_all') {
167196
$sites_ids[] = $website['id'];
197+
} else {
198+
$sites_ids[] = $website->id;
199+
}
168200
}
169201
}
170202

171203
//$sites_ids = array( 20,39,45 ); // test site
172-
$option = array('plugins'=> true,);
204+
$option = array('plugins'=> true);
173205

174206
// get all plugins for single website
175207
$websites = apply_filters( 'mainwp_getdbsites', $MainWPCheckPluginVulnerabilityActivator->getChildFile(), $MainWPCheckPluginVulnerabilityActivator->getChildKey(), $sites_ids, array(), $option );
@@ -180,6 +212,8 @@ public static function hhdev_mwpcpv_render_page() {
180212

181213
foreach ( $websites as $website ) {
182214

215+
// print_r($website);
216+
183217
if ( $website->plugins != '' ) {
184218

185219
$plugins = json_decode( $website->plugins, 1 );

hhdev-mwpcpv.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Check Plugins Vulnerability Extension
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.11
6+
* Version: 1.1.0
77
* Author: herbert hoekstra - haha!
88
* Author URI: https://haha.nl
99
* Documentation URI: https://haha.nl/wordpress-plug-in-op-maat/
@@ -35,7 +35,7 @@ class MainWPCheckPluginVulnerabilityActivator
3535
protected $childFile;
3636
protected $plugin_handle = 'hhdev-mwp-check-plugins-vulnerability';
3737
protected $product_id = 'MainWP Check Plugins Vulnerability Extension';
38-
protected $software_version = '1.0.11';
38+
protected $software_version = '1.1.0';
3939

4040
// set custom plugin vars
4141
// -------------------
@@ -152,8 +152,33 @@ public function getChildFile()
152152

153153
// plugin functions
154154
// -----------------------
155+
156+
// get a groups dropdown menu
157+
// posts: 'show_all' or group ID
158+
// group id as selected
159+
// ------------------------
160+
public function hhdev_get_groups_dropdown($selected_option) {
161+
162+
// get groups (tags)
163+
$groups = \MainWP\Dashboard\MainWP_DB_Common::instance()->get_groups_and_count();
164+
$selected = ''; // selected default
165+
166+
$dropmenu = '<select class="ui selection dropdown" name="mwpcpv-groups" id="groups">';
167+
$dropmenu .= '<option value="show_all" '.$selected.'>'.__('Show all','hhdev-mwpcpv').'</option>';
168+
foreach ( $groups as $group ) {
169+
if($selected_option == $group->id) $selected = 'selected';
170+
$dropmenu .= '<option value="'.$group->id.'"'.$selected.'>'.$group->name.'</option>';
171+
$selected = ''; // reset selected
172+
}
173+
$dropmenu .= '</select>';
174+
175+
return $dropmenu;
176+
177+
}
178+
155179
// save api data file to directory
156180
// fires on scan start
181+
// -----------------------------
157182
public function hhdev_save_api_data_file(){
158183

159184
if (!is_dir($this->dir_path)) { mkdir($this->dir_path, 0777, true); }
@@ -392,6 +417,7 @@ public function hhdev_make_adapted_file() {
392417

393418
/*
394419
change log:
420+
- 1.1.0 added optio to scan sites based on tags (groups), some style changes
395421
- 1.0.11 added: custom icon, changed: menu setup only from extensions menu, added show/hide toggle state, added: menu under sites -> security menu.
396422
- 1.0.10 fix: double header on link to check from extensions page
397423
- 1.0.9 added: some styling on the show hide button, some file names changed, use mainwp sidebar and header

languages/hhdev-mwpcpv-nl_NL.mo

119 Bytes
Binary file not shown.

languages/hhdev-mwpcpv-nl_NL.po

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
msgid ""
44
msgstr ""
55
"Project-Id-Version: undefined\n"
6-
"POT-Creation-Date: 2024-03-22 10:27+0100\n"
6+
"POT-Creation-Date: 2024-03-27 13:05+0100\n"
77
"PO-Revision-Date: \n"
88
"Last-Translator: \n"
99
"Language-Team: haha.nl\n"
@@ -21,119 +21,127 @@ msgstr ""
2121
"X-Poedit-SearchPath-0: .\n"
2222
"X-Poedit-SearchPathExcluded-0: *.js\n"
2323

24-
#: hhdev-mwp-check-plugins-vulnerability.php:94
25-
msgid "The Extension has to be enabled to change the settings."
26-
msgstr "De extensie moet worden geactiveerd om instellingen te wijzigen."
27-
28-
#: hhdev-mwp-check-plugins-vulnerability.php:124
29-
msgid "requires "
30-
msgstr "noodzakelijk"
31-
32-
#: hhdev-mwp-check-plugins-vulnerability.php:124
33-
msgid " Plugin to be activated in order to work. Please install and activate"
34-
msgstr "Plugin is nodig om te werken. Activeer de plugin"
35-
36-
#: hhdev-mwp-check-plugins-vulnerability.php:124
37-
msgid "first."
38-
msgstr "eerst."
39-
40-
#: hhdev-mwpcpv-dashboard.php:48
24+
#: hhdev-mwpcpv-dashboard.php:68
4125
msgid "Check Plugins Vulnerability"
4226
msgstr ""
4327

44-
#: hhdev-mwpcpv-dashboard.php:50
28+
#: hhdev-mwpcpv-dashboard.php:70
4529
msgid ""
4630
"Here you can check if there are plugins that need updating for security "
4731
"reasons."
4832
msgstr ""
4933
"Hier kun je de controleren of er plugins zijn die, om veiligheids "
5034
"overwegingen, geupdated moeten worden. "
5135

52-
#: hhdev-mwpcpv-dashboard.php:53
36+
#: hhdev-mwpcpv-dashboard.php:73
5337
#, php-format
5438
msgid "Data from %s is used to check plugins for each childsite."
5539
msgstr ""
5640
"Data van %s wordt gebruikt om voor elke website de plugins te controleren. "
5741

58-
#: hhdev-mwpcpv-dashboard.php:57
42+
#: hhdev-mwpcpv-dashboard.php:77
5943
msgid "The scan only shows plugins that need to be updated per site."
6044
msgstr "De scan toont alleen plugins die een update nodig hebben."
6145

62-
#: hhdev-mwpcpv-dashboard.php:59
46+
#: hhdev-mwpcpv-dashboard.php:79
6347
msgid ""
6448
"An adapted data file is created for scanning with vulnarability data only 24 "
6549
"month in the past based on when it was updated."
6650
msgstr ""
6751
"Een aangepast bestand wordt aangemaakt met veiligheidsdata tot 24 maanden "
6852
"terug in de tijd, gebasseeerd op de aanpassings datum."
6953

70-
#: hhdev-mwpcpv-dashboard.php:69
54+
#: hhdev-mwpcpv-dashboard.php:89
7155
msgid "File updated!"
7256
msgstr "Bestand aangepast!"
7357

74-
#: hhdev-mwpcpv-dashboard.php:70
58+
#: hhdev-mwpcpv-dashboard.php:90
7559
msgid "Not updated!"
7660
msgstr "Niet aangepast!"
7761

78-
#: hhdev-mwpcpv-dashboard.php:71
62+
#: hhdev-mwpcpv-dashboard.php:91
7963
msgid "Adapted file created!!"
8064
msgstr "Aangepast bestand gemaakt!"
8165

82-
#: hhdev-mwpcpv-dashboard.php:75
66+
#: hhdev-mwpcpv-dashboard.php:95
8367
msgid "No base file found. Please click the \"Update data file\" button."
8468
msgstr ""
8569
"Geen basis bestand gevonden. Klik op de \"Pas data bestand aan\" knop. "
8670

87-
#: hhdev-mwpcpv-dashboard.php:79
71+
#: hhdev-mwpcpv-dashboard.php:99
8872
msgid "Local WordFence api data file: "
8973
msgstr "Lokaal WordFence api data bestand:"
9074

91-
#: hhdev-mwpcpv-dashboard.php:84
75+
#: hhdev-mwpcpv-dashboard.php:104
9276
msgid "Update data file"
9377
msgstr "Pas data bestand aan"
9478

95-
#: hhdev-mwpcpv-dashboard.php:108
79+
#: hhdev-mwpcpv-dashboard.php:140
9680
msgid ""
9781
"Please make sure you do a \"sync dashboard with sites\" before you run a "
9882
"scan!"
9983
msgstr ""
10084
"Zorg dat je altijd eerst een \"sync dashboard with sites\" doet voordat je "
10185
"een scan draait!"
10286

103-
#: hhdev-mwpcpv-dashboard.php:115
87+
#: hhdev-mwpcpv-dashboard.php:152
88+
msgid "Choose a site group to scan:"
89+
msgstr "Kies een website groep om te scannen:"
90+
91+
#: hhdev-mwpcpv-dashboard.php:156
10492
msgid "Run the scan!"
10593
msgstr "Doe een scan!"
10694

107-
#: hhdev-mwpcpv-dashboard.php:120
95+
#: hhdev-mwpcpv-dashboard.php:162
10896
msgid "Hide/show websites with no vulnerabilities."
10997
msgstr "Verberg/toon websites zonder kwetsbaarheden."
11098

111-
#: hhdev-mwpcpv-dashboard.php:172
99+
#: hhdev-mwpcpv-dashboard.php:234
112100
msgid "No"
113101
msgstr "Nee"
114102

115-
#: hhdev-mwpcpv-dashboard.php:173
103+
#: hhdev-mwpcpv-dashboard.php:235
116104
msgid "Yes"
117105
msgstr "Ja"
118106

119-
#: hhdev-mwpcpv-dashboard.php:190
107+
#: hhdev-mwpcpv-dashboard.php:252
120108
#, php-format
121109
msgid "Website plugin version: %s"
122110
msgstr "Website plugin versie: %s"
123111

124-
#: hhdev-mwpcpv-dashboard.php:194
112+
#: hhdev-mwpcpv-dashboard.php:256
125113
#, php-format
126114
msgid "Has patch: %s"
127115
msgstr "Heeft een oplossing: %s"
128116

129-
#: hhdev-mwpcpv-dashboard.php:198
117+
#: hhdev-mwpcpv-dashboard.php:260
130118
msgid "Reference:"
131119
msgstr "Referentie:"
132120

133-
#: hhdev-mwpcpv-dashboard.php:212
121+
#: hhdev-mwpcpv-dashboard.php:274
134122
msgid "No vulnerabilities found!"
135123
msgstr "Geen kwetsbaarheden gevonden!"
136124

125+
#: hhdev-mwpcpv.php:108
126+
msgid "The Extension has to be enabled to change the settings."
127+
msgstr "De extensie moet worden geactiveerd om instellingen te wijzigen."
128+
129+
#: hhdev-mwpcpv.php:139
130+
msgid "requires "
131+
msgstr "noodzakelijk"
132+
133+
#: hhdev-mwpcpv.php:139
134+
msgid " Plugin to be activated in order to work. Please install and activate"
135+
msgstr "Plugin is nodig om te werken. Activeer de plugin"
136+
137+
#: hhdev-mwpcpv.php:139
138+
msgid "first."
139+
msgstr "eerst."
140+
141+
#: hhdev-mwpcpv.php:167
142+
msgid "Show all"
143+
msgstr "Toon alles"
144+
137145
#~ msgid "You will be redirected to the page immediately."
138146
#~ msgstr "Je wordt direct doorgestuurd naar de juiste pagina."
139147

0 commit comments

Comments
 (0)