This repository was archived by the owner on Jan 20, 2022. It is now read-only.
forked from wnoisephx/TaskFreak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.php
199 lines (193 loc) · 8.33 KB
/
files.php
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?PHP
/****************************************************************************\
* File Attachments Plugin 4 TaskFreak! *
* Version: 0.1.2 *
* Authors: Searcher <[email protected]> *
******************************************************************************
* For: TaskFreak! Multi User *
* Version: 0.6.1 *
* Authors: Stan Ozier <[email protected]> *
* License: http://www.gnu.org/licenses/gpl.txt (GPL) *
\****************************************************************************/
$pPageIsPublic = false;
include '_common.php';
set_time_limit(0);
ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '11M');
if ($pUser = intval($_REQUEST['sUser'])) {
$objItemList->addWhere('ii.memberId = \''.$pUser.'\'');
$pLink=Tzn::concatUrl($pLink,'sUser='.$pUser);
$_SESSION['selUser'] = $pUser;
$pDefaultUserId = $pUser;
} else {
unset($_SESSION['selUser']);
// session_unregister('selUser');
$pDefaultUserId = $objUser->id;
}
# Feed The File
if ($_SESSION['fp_fileId']) {
$fileId = $_SESSION['fp_fileId'];
$_SESSION['fp_fileId'] = '';
$objFile = new ItemFile();
$objFile->setUid($fileId);
$objFile->load();
// Check if file exists
if (file_exists(FRK_ATTACHMENT_FOLDER.$fileId.".frk")) {
# Header Magic
header("Pragma: public");
header("Expires: Fri, 23 Jul 1999 01:00:00 GMT"); // cache control
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.$objFile->filename.'"');
header("Content-Transfer-Encoding: binary");
header('Content-Length: '.filesize(FRK_ATTACHMENT_FOLDER.$fileId.".frk"));
// Get File
readfile(FRK_ATTACHMENT_FOLDER.$fileId.".frk");
exit;
}
else {
echo "Sorry, file not found - ".$fileId.".frk";
exit;
}
}
# Exclusion Security
$exclude_List = explode(",", FRK_ATTACHMENT_LIST);
$exclude_ListLength = count($exclude_List);
if (FRK_ATTACHMENT_EXCLUSION == "allow") {
// allowed only these
if (FRK_ATTACHMENT_NOTIFY) {
$exclude_Msg ='<span style="color:#666"> You are <strong>allowed</strong> to upload <strong>only</strong> these extensions: <strong style="color:#0000FF">';
for ($i=0; $i<$exclude_ListLength; $i++) {
$exclude_Msg .= $exclude_List[$i];
if ($i<$exclude_ListLength-1) $exclude_Msg .= ', ';
else $exclude_Msg .= '</strong></span><br />';
}
}
}
else if (FRK_ATTACHMENT_EXCLUSION == "disallow") {
// allowed all but these
if (FRK_ATTACHMENT_NOTIFY) {
$exclude_Msg = '<span style="color:#666">You are <strong>not allowed</strong> to upload these extensions: <strong style="color:#0066FF">';
for ($i=0; $i<$exclude_ListLength; $i++) {
$exclude_Msg .= $exclude_List[$i];
if ($i<$exclude_ListLength-1) $exclude_Msg .= ', ';
else $exclude_Msg .= '</strong></span><br />';
}
}
}
else {
// config error
$exclude_Msg = '<span style="color:#FF0000">Please check your <strong>config</strong> file, there seems to be an <strong>error</strong> with <strong style="color:#0066FF">FRK_ATTACHMENT_EXCLUSION</strong></span><br />';
$exclude_Error = true;
}
# Storage Folder Permissions
if (@is_dir(FRK_ATTACHMENT_FOLDER)) { // check if exists
@rmdir(FRK_ATTACHMENT_FOLDER."tmp"); // just in case it was left there accidentally
if (@mkdir(FRK_ATTACHMENT_FOLDER."tmp")) {
@rmdir(FRK_ATTACHMENT_FOLDER."tmp");
}
else {
$exclude_Msg = '<span style="color:#FF0000">Your file storage folder does <strong>not</strong> have <strong>write</strong> permissions, <br />please check <strong style="color:#0066FF">FRK_ATTACHMENT_FOLDER</strong> in the <strong>config</strong> file</span><br />';
$exclude_Error = true;
}
}
else {
$exclude_Msg = '<span style="color:#FF0000">Your file storage folder does <strong>not</strong> exist, <br />please check <strong style="color:#0066FF">FRK_ATTACHMENT_FOLDER</strong> in the <strong>config</strong> file</span><br />';
$exclude_Error = true;
}
# Upload
if ($_POST) {
$file = $_FILES['fileupload']['name'];
$desc = $_POST['filedesc'];
$desc = preg_replace("/\r|\n/", "<br>", $desc);
$desc = preg_replace("/(<br>)+/", "<br>", $desc);
# Exclusion Security
$ext = substr($file,strrpos($file,".")+1);
if (FRK_ATTACHMENT_EXCLUSION == "allow") { // allowed only these
if (!in_array($ext, $exclude_List)) {
$exclude_Msg = '<span style="color:#FF0000">Sorry, you uploaded a <strong>disallowed</strong> file type: <strong style="color:#0066FF">'.$ext.'</strong></span><br />';
$exclude_Error = true;
}
}
else if (FRK_ATTACHMENT_EXCLUSION == "disallow") { // allowed all but these
if (in_array($ext, $exclude_List)) {
$exclude_Msg = '<span style="color:#FF0000">Sorry, you uploaded a <strong>disallowed</strong> file type: <strong style="color:#0066FF">'.$ext.'</strong></span><br />';
$exclude_Error = true;
}
}
if (!$exclude_Error) { // upload allowed
// check transfer success
$tempfile = "temp_".rand(1111,9999).".frk"; // no insert id yet
if (@is_uploaded_file($_FILES['fileupload']['tmp_name']) && @move_uploaded_file($_FILES['fileupload']['tmp_name'], FRK_ATTACHMENT_FOLDER.$tempfile)) {
// call xajax to update db
echo '<script type="text/javascript">';
echo 'parent.freak_start();';
echo 'parent.xajax_task_file_upload(parent.ff.elements[\'id\'].value,\''.$file.'\',\''.$desc.'\',\''.$tempfile.'\');';
echo '</script>';
}
else {
// error messages
$file_Error = array(
0=>"There is no error, the file uploaded with success",
1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini",
2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
3=>"The uploaded file was only partially uploaded",
4=>"No file was uploaded",
6=>"Missing a temporary folder"
);
$exclude_Msg = '<span style="color:#0066FF">'.$file_Error[$_FILES["fileupload"]["error"]].'</span><br /><br />';
$exclude_Msg .= '<span style="color:#FF0000">Sorry, the file transfer was <strong>unsuccessful</strong>, please try again</span><br /><br />';
$exclude_Error = true;
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TaskFreak!<?php if ($pPageTitle) { echo ' '.$pPageTitle; } ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo FRK_CHARSET; ?>" />
<link rel="stylesheet" type="text/css" href="skins/<?php echo FRK_SKIN_FOLDER; ?>/css/freak.css" />
<script type="text/javascript">
function freak_file_upload() {
if (!document.getElementById('fileupload').value) {
alert('please select a file!');
return false;
}
else {
document.forms[0].submit();
document.getElementById('file_transfer_body').innerHTML =
'<div align="center" style="font-size:10px">'
+ '<br><br><strong>Please wait while the file is being uploaded</strong><br><br>'
+ '<img src="<?php echo FRK_SKIN_FOLDER; ?>/images/working.gif">'
+ '</div>';
}
}
</script>
</head>
<body style="font-family:tahoma; topmargin:0">
<div id="file_transfer_body" align="center" style="font-size:10px">
<?php
if ($exclude_Error) {
echo '<br /><br />'.$exclude_Msg.'<br /><br />';
echo '<a href="javascript:this.location = \''.PRJ_WWW_URL.'files.php\'" style="font-size:12px">'
.'try again'
.'</a>';
exit;
}
?>
<form method="post" enctype="multipart/form-data" style="margin:0; padding:0">
<input type="hidden" name="MAX_FILE_SIZE" value="15000000" />
<?php echo $exclude_Msg; ?>
<br />
Choose a file to upload (max <?php echo ini_get('upload_max_filesize'); ?>): <br /><input id="fileupload" name="fileupload" type="file" style="width:200px" /><br />
<br />
File description (optional):<br />
<textarea id="filedesc" name="filedesc" style="font-family:tahoma; font-size:10px; width:200px"></textarea><br /><br />
<input type="button" value=" <?php echo $GLOBALS['langForm']['save']; ?> " onClick="freak_file_upload()">
<input type="button" value=" <?php echo $GLOBALS['langForm']['cancel']; ?> " onClick="parent.freak_body_edit(); parent.hD(parent.gE('vfedit'))">
</form>
</div>
</body>
</html>