-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclamav.admin.inc
146 lines (132 loc) · 6.57 KB
/
clamav.admin.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
// $Id$
/**
* @file
* Admin-pages for managing the ClamAV module.
*/
/**
* Admin settings page for ClamAV
*/
function clamav_admin_settings() {
// Load the include helper so that the form can test connectivity to ClamAV
// and report success/failure.
module_load_include('inc', 'clamav');
$form = array();
$form['antivirus'] = array(
'#type' => 'fieldset',
'#title' => t('ClamAV'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['antivirus']['clamav_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable ClamAV anti-virus scans'),
'#default_value' => variable_get('clamav_enabled', TRUE),
);
$form['antivirus']['clamav_mode'] = array(
'#type' => 'radios',
'#title' => t('Select scan method'),
'#options' => array(CLAMAV_USE_DAEMON => t('Daemon mode'),
CLAMAV_USE_EXECUTABLE => t('Executable')),
'#default_value' => variable_get('clamav_mode', CLAMAV_DEFAULT_MODE),
'#description' => t("Set the scan-method according to how the ClamAV software is configured on the server.<br /><strong>Daemon-mode is recommended</strong>, because it is usually quicker than running as an executable. The Daemon will require read-access to the web server's temporary files in order to scan them."),
);
$form['antivirus']['clamav_unchecked_files'] = array(
'#type' => 'radios',
'#title' => t('Action when ClamAV is not available'),
//Allow file uploads if the daemon is not running or program is not found'),
'#options' => array(CLAMAV_BLOCK_UNCHECKED => t('Block unchecked files'),
CLAMAV_ALLOW_UNCHECKED => t('Allow unchecked files')),
'#default_value' => variable_get('clamav_unchecked_files', CLAMAV_DEFAULT_UNCHECKED),
'#description' => t('Scans may fail - for example: if ClamAV is not running, or the path to the executable is invalid. Choose whether files should be blocked or allowed when a scan cannot be completed.'),
);
// Deamon-mode.
// Check for a daemon on the current settings.
$daemon_config = array('host' => variable_get('clamav_daemon_host', CLAMAV_DEFAULT_HOST),
'port' => variable_get('clamav_daemon_port', CLAMAV_DEFAULT_PORT),
);
$clamav_daemon_version = clamav_get_version($daemon_config);
$clamav_daemon_version = preg_match('/ClamAV/', $clamav_daemon_version) ? $clamav_daemon_version : NULL;
$message = isset($clamav_daemon_version)
? t("The clamav-daemon at %host:%port gives the version:<br />@version_string.", array('%host' => $daemon_config['host'], '%port' => $daemon_config['port'], '@version_string' => $clamav_daemon_version))
: t('The clamav-daemon was not found at %host:%port.', array('%host' => $daemon_config['host'], '%port' => $daemon_config['port']));
$form['daemon'] = array(
'#type' => 'fieldset',
'#title' => t('ClamAV daemon'),
'#description' => t("Configure the connection settings when using Daemon-mode.") . '<br />' . $message,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['daemon']['clamav_daemon_host'] = array(
'#type' => 'textfield',
'#title' => t('Hostname'),
'#default_value' => variable_get('clamav_daemon_host', CLAMAV_DEFAULT_HOST),
'#maxlength' => 255,
'#description' => t('The hostname for the Clam-AV daemon. Defaults to localhost.'),
);
$form['daemon']['clamav_daemon_port'] = array(
'#type' => 'textfield',
'#title' => t('Port'),
'#default_value' => variable_get('clamav_daemon_port', CLAMAV_DEFAULT_PORT),
'#size' => 6,
'#maxlength' => 8,
'#description' => t('The port for the Clam-AV daemon. Defaults to port 3310. Must be between 0 and 65535.'),
);
// Executable.
// Check that the executable-path matches the default clamscan
$msg = '';
$executable = variable_get('clamav_executable_path', CLAMAV_DEFAULT_PATH);
$version_string = clamav_get_version($executable);
if($version_string) {
$msg .= t("The clamscan at %executable_filepath gives the version:<br />@version_string.", array('%executable_filepath' => $executable, '@version_string' => $version_string));
}
else {
$msg .= t("The clamscan at %executable_filepath did not respond.", array('%executable_filepath' => $executable));
}
$default_executable_path = exec('which clamscan 2>/dev/null');
if($default_executable_path && $default_executable_path != variable_get('clamav_executable_path', CLAMAV_DEFAULT_PATH)) {
$version_string = clamav_get_version($default_executable_path);
if($default_executable_version_string) {
$msg .= "<br />";
$msg .= t("The clamscan at %executable_filepath gives the version:<br />@version_string.", array('%executable_filepath' => $default_executable_path, '@version_string' => $version_string));
}
}
$form['executable'] = array(
'#type' => 'fieldset',
'#title' => t('ClamAV executable'),
'#description' => t('These settings will be used if you have chosen "Executable" as the scan-method.') . '<br />' . $msg,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['executable']['clamav_executable_path'] = array(
'#type' => 'textfield',
'#title' => t('Executable path'),
'#default_value' => variable_get('clamav_executable_path', CLAMAV_DEFAULT_PATH),
'#maxlength' => 255,
'#description' => t("Full path to the 'clamscan' utility."),
);
$form['integration'] = array(
'#type' => 'fieldset',
'#title' => t('Integration'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['integration']['clamav_enable_element_file'] = array(
'#type' => 'checkbox',
'#title' => t('Scan normal file uploads'),
'#default_value' => variable_get('clamav_enable_element_file', TRUE),
);
$form['integration']['clamav_enable_element_filefield_widget'] = array(
'#type' => 'checkbox',
'#title' => t('Scan CCK filefield widget uploads'),
'#default_value' => module_exists('filefield') && variable_get('clamav_enable_element_filefield_widget', TRUE),
'#disabled' => !module_exists('filefield'),
);
$form['integration']['clamav_enable_element_imagefield_widget'] = array(
'#type' => 'checkbox',
'#title' => t('Scan CCK imagefield widget uploads'),
'#default_value' => module_exists('imagefield') && variable_get('clamav_enable_element_imagefield_widget', TRUE),
'#disabled' => !module_exists('imagefield'),
);
return system_settings_form($form);
}