Skip to content

Commit 7785610

Browse files
committed
Merge branch 'hotfix-1.0.1-beta1' into develop
Conflicts: os2web_cp_service.module
2 parents f3507b0 + 550d1d5 commit 7785610

11 files changed

+65
-28
lines changed

.gitignore

100644100755
File mode changed.

LICENSE.txt

100644100755
File mode changed.

README.md

100644100755
File mode changed.

os2web_cp_service.context.inc

100644100755
File mode changed.

os2web_cp_service.features.field.inc

100644100755
File mode changed.

os2web_cp_service.features.inc

100644100755
File mode changed.

os2web_cp_service.features.taxonomy.inc

100644100755
File mode changed.

os2web_cp_service.features.user_permission.inc

100644100755
File mode changed.

os2web_cp_service.module

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ function os2web_cp_service_handler() {
7272
* Callback for the file provider service.
7373
*/
7474
function os2web_gf_service_handler($file_id) {
75+
// Mime Types which are disallowed to be downloaded.
76+
// People shouldn't be able to download special files.
77+
$disallowed_mimes = array(
78+
// Disallow .msg files.
79+
'application/vnd.ms-outlook',
80+
);
81+
7582
if ($url = variable_get('os2web_cp_service_cp_document_fileurl')) {
7683

7784
$username = variable_get('os2web_cp_service_endpoint_user');
@@ -86,38 +93,60 @@ function os2web_gf_service_handler($file_id) {
8693
$header = curl_getinfo($ch);
8794
curl_close($ch);
8895
if ($header['http_code'] === 200) {
89-
drupal_add_http_header('Content-Type', $header['content_type']);
90-
drupal_add_http_header('Content-Length', $header['download_content_length']);
91-
drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
92-
drupal_add_http_header('Cache-Control', 'private', FALSE);
93-
drupal_add_http_header('Connection', 'close');
94-
drupal_add_http_header('Expires', '0');
95-
96-
// Check for IE only headers.
97-
if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)) {
98-
drupal_add_http_header('Pragma', 'public');
96+
if (!in_array($header['content_type'], $disallowed_mimes)) {
97+
drupal_add_http_header('Content-Type', $header['content_type']);
98+
drupal_add_http_header('Content-Length', $header['download_content_length']);
99+
drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
100+
drupal_add_http_header('Cache-Control', 'private', FALSE);
101+
drupal_add_http_header('Connection', 'close');
102+
drupal_add_http_header('Expires', '0');
103+
104+
// Check for IE only headers.
105+
if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)) {
106+
drupal_add_http_header('Pragma', 'public');
107+
}
108+
else {
109+
drupal_add_http_header('Pragma', 'no-cache');
110+
}
111+
112+
// Load the title to use it as the filename.
113+
$query = new EntityFieldQuery();
114+
$result = $query
115+
->entityCondition('entity_type', 'node')
116+
->propertyCondition('type', 'os2web_cp_service_cp_document')
117+
->propertyCondition('status', 1)
118+
->fieldCondition('field_os2web_cp_service_file_id', 'value', $file_id, '=')
119+
->execute();
120+
$nids = (isset($result['node']))?array_keys($result['node']) : NULL;
121+
122+
$node = node_load(array_pop($nids));
123+
124+
if ($node) {
125+
$filename = str_replace('/', '_', $node->field_os2web_cp_service_doc_id[LANGUAGE_NONE][0]['value'] . '.' . os2web_cp_service_get_extension_from_mime($header['content_type']));
126+
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $filename);
127+
}
128+
echo $data;
129+
drupal_exit();
99130
}
100131
else {
101-
drupal_add_http_header('Pragma', 'no-cache');
102-
}
103132

104-
// Load the title to use it as the filename.
105-
$query = new EntityFieldQuery();
106-
$result = $query
107-
->entityCondition('entity_type', 'node')
108-
->propertyCondition('type', 'os2web_cp_service_cp_document')
109-
->propertyCondition('status', 1)
110-
->fieldCondition('field_os2web_cp_service_file_id', 'value', $file_id, '=')
111-
->execute();
112-
$nids = (isset($result['node']))?array_keys($result['node']) : NULL;
113-
114-
$node = node_load(array_pop($nids));
115-
if ($node) {
116-
$filename = str_replace('/', '_', $node->field_os2web_cp_service_doc_id[LANGUAGE_NONE][0]['value'] . '.' . os2web_cp_service_get_extension_from_mime($header['content_type']));
117-
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $filename);
133+
// Show a polite message if the file cant be downloaded.
134+
// If the message isnt set in config, deliver a access denied page.
135+
if ($error_message = variable_get('os2web_cp_service_access_denied_message')) {
136+
$markup = '<div class="messages error"><ul><li>';
137+
$markup .= $error_message;
138+
$markup .= '</li></ul></div>';
139+
140+
$page['region'] = array(
141+
'#type' => 'markup',
142+
'#markup' => $markup,
143+
);
144+
return $page;
145+
}
146+
else {
147+
drupal_access_denied();
148+
}
118149
}
119-
echo $data;
120-
drupal_exit();
121150
}
122151
else {
123152
error_log(basename(__FILE__) . ':' . __LINE__ . ' HTTP header recieved = ' . print_r($header, 1));
@@ -835,6 +864,12 @@ function os2web_cp_service_form_os2web_settings_settings_form_alter(&$form, &$fo
835864
'#description' => 'Komma separeret liste af ip-addresser der kan tilgå <em>webservicen</em>.',
836865
'#default_value' => variable_get('os2web_cp_service_cp_access_ip', ip_address()),
837866
);
867+
$form['os2web_cp_service_config_group']['os2web_cp_service_access_denied_message'] = array(
868+
'#type' => 'textfield',
869+
'#title' => 'Besked til brugeren, hvis fil ikke er tilgængelig.',
870+
'#description' => 'Vises når den modtagede filtype ikke er godkendt til Download.',
871+
'#default_value' => variable_get('os2web_cp_service_access_denied_message'),
872+
);
838873
}
839874

840875
/**
@@ -870,6 +905,8 @@ function os2web_cp_service_date_format_types() {
870905
* The file ext without the dot.
871906
*/
872907
function os2web_cp_service_get_extension_from_mime($mime) {
908+
909+
// Todo: use file_mimetype_mapping().
873910
$map = array(
874911
'application/pdf' => 'pdf',
875912
'application/zip' => 'zip',

os2web_cp_service.pages_default.inc

100644100755
File mode changed.

0 commit comments

Comments
 (0)