-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.inc
98 lines (80 loc) · 2.65 KB
/
scan.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
require_once('helpers.inc');
function vulnscan_scan_form($form, &$form_state) {
global $user;
$groups = user_scannable_groups($user);
$servers = array();
$sites = get_all_sites_assoc();
if (count($groups) == 0) {
$form['vulnscan_nogroups'] = array(
'#type' => 'markup',
'#prefix' => '<div>',
'#markup' => t('No scannable groups'),
'#suffix' => '</div>',
);
return $form;
}
if (count($sites) == 0) {
$form['vulnscan_nosites'] = array(
'#type' => 'markup',
'#prefix' => '<div>',
'#markup' => t('No scannable sites'),
'#suffix' => '</div>',
);
return $form;
}
foreach ($groups as $group)
foreach (get_all_servers_in_server_group_assoc($group) as $key => $value)
$servers[$key] = $value;
$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['vulnscan_scan_host'] = array(
'#type' => 'select',
'#title' => t('Site to Scan'),
'#options' => $sites,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Run Scan',
);
return $form;
}
function vulnscan_scan_form_submit($form, &$form_state) {
global $user;
$site = $form_state['values']['vulnscan_scan_host'];
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 (run_scan_on_server_group($site, $group) == false)
return;
}
}
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;
}
run_scan_on_server($site, $server);
}
}
}