forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownload.php
More file actions
124 lines (102 loc) · 3.57 KB
/
download.php
File metadata and controls
124 lines (102 loc) · 3.57 KB
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
<?php
/**
* Serves the public downloads.
*
* @package ProjectSend
*
*/
use ProjectSend\Classes\Download;
$allowed_levels = array(9,8,7,0);
require_once 'bootstrap.php';
$page_title = __('File information','cftp_admin');
$dont_redirect_if_logged = 1;
include_once ADMIN_VIEWS_DIR . DS . 'header-unlogged.php';
if (!empty($_GET['token']) && !empty($_GET['id'])) {
$token = htmlentities($_GET['token']);
$file_id = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
if (!is_numeric($_GET['id'])) {
exit;
}
$can_download = false;
$can_view = false; // Can only view information about the file, not download it
$file = new \ProjectSend\Classes\Files;
$file->get($file_id);
if ($file->public_token != $token || $file->expired == true) {
header("Location: ".PAGE_STATUS_CODE_403);
exit;
}
if ($file->public == 1 && $file->public_token == $token) {
$can_download = true;
$can_view = true;
}
if (get_option('enable_landing_for_all_files') == '1') {
$can_view = true;
} else {
if ($file->public == 0) {
header("Location: ".PAGE_STATUS_CODE_403);
exit;
}
}
if ($can_download == true) {
if (isset($_GET['download'])) {
recordNewDownload(0, $file->id);
/** Record the action log */
$logger = new \ProjectSend\Classes\ActionsLog;
$new_record_action = $logger->addEntry([
'action' => 37,
'owner_user' => null,
'owner_id' => 0,
'affected_file' => $file->id,
'affected_file_name' => $file->filename_original,
]);
// DOWNLOAD
$process = new Download;
$alias=$process->getAlias($file);
$process->serveFile($file->full_path, $file->filename_unfiltered,$alias);
exit;
}
}
} else {
header("Location: ".PAGE_STATUS_CODE_403);
exit;
}
?>
<div class="col-xs-12 col-sm-12 col-lg-8 col-lg-offset-2">
<?php echo get_branding_layout(true); ?>
<div class="white-box">
<div class="white-box-interior">
<?php
if ($can_view) {
?>
<div class="text-center">
<h2 class="file_title">
<span class="label label-default">
<?php echo $file->filename_original; ?>
</span>
</h2>
<h3><?php echo $file->title; ?></h3>
<div class="description">
<?php echo $file->description; ?>
</div>
<div class="size">
<?php echo $file->size_formatted; ?>
</div>
<?php if ($can_download == true) { ?>
<div class="actions">
<a href="<?php echo $file->public_url . '&download'; ?>" class="btn btn-primary">
<?php _e('Download file','cftp_admin'); ?>
</a>
</div>
<?php } ?>
</div>
<?php
}
?>
</div>
</div>
<div class="login_form_links">
<p><a href="<?php echo BASE_URI; ?>" target="_self"><?php _e('Go back to the homepage.','cftp_admin'); ?></a></p>
</div>
</div>
<?php
include_once ADMIN_VIEWS_DIR . DS . 'footer.php';