Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add basic framework for scanning

  • Loading branch information...
commit 7bce6e71fdf197f2e2c9fd3ba9cc35de39894d55 1 parent 930f959
@lattera lattera authored
View
38 sites/all/modules/wayfair/vulnscan/helpers.inc
@@ -122,3 +122,41 @@ function add_servers_in_server_group($groupname, $servers=array()) {
return true;
}
+
+/* User accesses */
+function user_can_scan_group($user, $groupname) {
+ foreach (user_role_permissions($user->roles) as $perms) {
+ foreach ($perms as $key => $value) {
+ if (strpos($key, $groupname) !== FALSE)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+function user_can_scan_server($user, $servername) {
+ $groups = get_all_server_groups();
+
+ foreach ($groups as $group) {
+ $servers = get_all_servers_in_server_group($group->groupname);
+
+ foreach ($servers as $server)
+ if (!strcmp($server->servername, $servername))
+ if (user_can_scan_group($user, $group->groupname))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+function user_scannable_groups($user) {
+ $ret = array();
+ $groups = get_all_server_groups_assoc();
+
+ foreach ($groups as $key => $value)
+ if (user_can_scan_group($user, $key))
+ $ret[$key] = $value;
+
+ return $ret;
+}
View
71 sites/all/modules/wayfair/vulnscan/scan.inc
@@ -1,12 +1,73 @@
<?php
function vulnscan_scan_form($form, &$form_state) {
- $form['vulnscan_scan'] = array(
- '#type' => 'markup',
- '#prefix' => '<div>',
- '#markup' => t('Under Construction. Good news - you can run scans!'),
- '#suffix' => '</div>',
+ global $user;
+ $groups = user_scannable_groups($user);
+ $servers = array();
+
+ foreach ($groups as $group)
+ foreach (get_all_servers_in_server_group_assoc($group) as $key => $value)
+ $servers[$key] = $value;
+
+ if (count($groups) == 0) {
+ $form['vulnscan_nogroups'] = array(
+ '#type' => 'markup',
+ '#prefix' => '<div>',
+ '#markup' => t('No scannable groups'),
+ '#suffix' => '</div>',
+ );
+
+ return $form;
+ }
+
+ $form['vulnscan_scan_server_groups'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Scan Server Groups'),
+ );
+
+ $form['vulnscan_scan_server_groups']['groups'] = array(
+ '#type' => 'select',
+ '#multiple' => TRUE,
+ '#options' => $groups,
+ );
+
+ $form['vulnscan_scan_servers'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Scan Individual Servers'),
+ );
+
+ $form['vulnscan_scan_servers']['servers'] = array(
+ '#type' => 'select',
+ '#multiple' => TRUE,
+ '#options' => $servers,
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => 'Run Scan',
);
return $form;
}
+
+function vulnscan_scan_form_submit($form, &$form_state) {
+ global $user;
+
+ if (isset($form_state['values']['groups'])) {
+ foreach (array_filter($form_state['values']['groups']) as $group) {
+ if (user_can_scan_group($user, $group) == false) {
+ drupal_set_message(t('Invalid group: @group', array('@group' => $group)), 'error');
+ continue;
+ }
+ }
+ }
+
+ if (isset($form_state['values']['servers'])) {
+ foreach (array_filter($form_state['values']['servers']) as $server) {
+ if (user_can_scan_server($user, $server) == false) {
+ drupal_set_message(t('Invalid server: @server', array('@server' => $server)), 'error');
+ continue;
+ }
+ }
+ }
+}
View
26 sites/all/modules/wayfair/vulnscan/vulnscan.admin.inc
@@ -117,18 +117,20 @@ function vulnscan_admin_settings_servergroup($form, &$form_state) {
);
}
- $form['vulnscan_new_servers'] = array(
- '#type' => 'fieldset',
- '#title' => t('Add New Servers'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
-
- $form['vulnscan_new_servers']['new_server'] = array(
- '#type' => 'select',
- '#multiple' => TRUE,
- '#options' => $new_servers,
- );
+ if (count($new_servers)) {
+ $form['vulnscan_new_servers'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Add New Servers'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
+
+ $form['vulnscan_new_servers']['new_server'] = array(
+ '#type' => 'select',
+ '#multiple' => TRUE,
+ '#options' => $new_servers,
+ );
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.