1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * Expresso Livre * |
---|
4 | * http://www.expressolivre.org * |
---|
5 | * -------------------------------------------- * |
---|
6 | * This program is free software; you can redistribute it and/or modify it * |
---|
7 | * under the terms of the GNU General Public License as published by the * |
---|
8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
9 | * option) any later version. * |
---|
10 | \**************************************************************************/ |
---|
11 | |
---|
12 | require_once '../../header.session.inc.php'; |
---|
13 | |
---|
14 | $post_limit = error_get_last( ); |
---|
15 | |
---|
16 | if ( preg_match( '/POST Content-Length of (\d+) bytes exceeds the limit of \d+ bytes/i', $post_limit[ 'message' ], $matches ) ) |
---|
17 | { |
---|
18 | $_SESSION['response'] = serialize( array( |
---|
19 | 'postsize' => $matches[ 1 ], |
---|
20 | 'max_postsize' => ini_get( 'post_max_size' ) |
---|
21 | ) ); |
---|
22 | |
---|
23 | exit; |
---|
24 | } |
---|
25 | |
---|
26 | /* This single file is used to increase upload_max_filesize and post_max_size using .htaccess*/ |
---|
27 | if(!isset($GLOBALS['phpgw_info'])){ |
---|
28 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
29 | 'currentapp' => 'filemanager', |
---|
30 | 'nonavbar' => true, |
---|
31 | 'noheader' => true |
---|
32 | ); |
---|
33 | } |
---|
34 | require_once '../../header.inc.php'; |
---|
35 | |
---|
36 | $bo = CreateObject('filemanager.bofilemanager'); |
---|
37 | $c = CreateObject('phpgwapi.config','filemanager'); |
---|
38 | $c->read_repository(); |
---|
39 | |
---|
40 | $current_config = $c->config_data; |
---|
41 | $upload_max_size = $current_config['filemanager_Max_file_size']; |
---|
42 | $path = $_POST['path']; |
---|
43 | $notifUser = $_POST['notifTo']; |
---|
44 | $show_upload_boxes = count($_FILES['upload_file']['name']); |
---|
45 | $filesUpload = $_FILES['upload_file']; |
---|
46 | |
---|
47 | function create_summaryImage($file) |
---|
48 | { |
---|
49 | list($width, $height,$image_type) = getimagesize($file); |
---|
50 | |
---|
51 | switch($image_type) |
---|
52 | { |
---|
53 | case 1: |
---|
54 | $image_big = imagecreatefromgif($file); |
---|
55 | break; |
---|
56 | case 2: |
---|
57 | $image_big = imagecreatefromjpeg($file); |
---|
58 | break; |
---|
59 | case 3: |
---|
60 | $image_big = imagecreatefrompng($file); |
---|
61 | break; |
---|
62 | default: |
---|
63 | return false; |
---|
64 | } |
---|
65 | |
---|
66 | $max_resolution = 48; |
---|
67 | |
---|
68 | if ($width > $height) |
---|
69 | { |
---|
70 | $new_width = $max_resolution; |
---|
71 | $new_height = $height*($new_width/$width); |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | $new_height = $max_resolution; |
---|
76 | $new_width = $width*($new_height/$height); |
---|
77 | } |
---|
78 | |
---|
79 | $image_new = imagecreatetruecolor($new_width, $new_height); |
---|
80 | imagecopyresampled($image_new, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
---|
81 | ob_start(); |
---|
82 | imagepng($image_new); |
---|
83 | $content = ob_get_clean(); |
---|
84 | return $content; |
---|
85 | } |
---|
86 | |
---|
87 | /* Its much faster test all files only one time */ |
---|
88 | if(strlen($current_config['filemanager_antivirus_command']) > 0) |
---|
89 | { |
---|
90 | $command = "nice -n19 ".$current_config['filemanager_antivirus_command']; |
---|
91 | for($i = 0; $i != $show_upload_boxes; ++$i) |
---|
92 | { |
---|
93 | $command .= " ".$_FILES['upload_file']['tmp_name'][$i]; |
---|
94 | } |
---|
95 | |
---|
96 | $return = 0; |
---|
97 | |
---|
98 | exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return); |
---|
99 | |
---|
100 | if ($return == 1) |
---|
101 | { |
---|
102 | $_SESSION['response'] = serialize(array(0 => lang('Error:').lang('One of the files sent was considered infected'))); |
---|
103 | return; |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | if( $path != '/' ) |
---|
108 | { |
---|
109 | $return = array( ); |
---|
110 | for( $i = 0; $i != $show_upload_boxes; ++$i) |
---|
111 | { |
---|
112 | if ( $_FILES['upload_file']['error'][$i] !== 0 ) |
---|
113 | { |
---|
114 | $return[] = array( |
---|
115 | "file" => $_FILES['upload_file']['name'][$i] , |
---|
116 | "filesize" => 'filesize #' . $_FILES['upload_file']['error'][$i] |
---|
117 | ); |
---|
118 | continue; |
---|
119 | } |
---|
120 | elseif ( $_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024) ) |
---|
121 | { |
---|
122 | $return[] = array( |
---|
123 | "file" => $_FILES['upload_file']['name'][$i] , |
---|
124 | "size" => $_FILES['upload_file']['size'][$i] , |
---|
125 | "size_max" => ($upload_max_size*1024*1024) |
---|
126 | ); |
---|
127 | continue; |
---|
128 | } |
---|
129 | elseif( $_FILES['upload_file']['size'][$i] > 0 ) |
---|
130 | { |
---|
131 | $badchar = $bo->bad_chars( $_FILES['upload_file']['name'][$i], True, True ); |
---|
132 | |
---|
133 | if( $badchar ) |
---|
134 | { |
---|
135 | $return[] = array( |
---|
136 | "file" => $_FILES['upload_file']['name'][$i], |
---|
137 | "badchar" => lang('File names cannot contain "%1"', $badchar) |
---|
138 | ); |
---|
139 | continue; |
---|
140 | } |
---|
141 | |
---|
142 | # Check to see if the file exists in the database, and get its info at the same time |
---|
143 | $ls_array = $bo->vfs->ls(array( |
---|
144 | 'string'=> $path . '/' . $_FILES['upload_file']['name'][$i], |
---|
145 | 'relatives' => array(RELATIVE_NONE), |
---|
146 | 'checksubdirs' => False, |
---|
147 | 'nofiles' => True |
---|
148 | )); |
---|
149 | |
---|
150 | $fileinfo = $ls_array[0]; |
---|
151 | |
---|
152 | if( $fileinfo['name'] ) |
---|
153 | { |
---|
154 | if( $fileinfo['mime_type'] == 'Directory' ) |
---|
155 | { |
---|
156 | $return[] = array( |
---|
157 | "file" => $_FILES['upload_file']['name'][$i], |
---|
158 | "directory" => lang('Cannot replace %1 because it is a directory', $fileinfo['name'] ) |
---|
159 | ); |
---|
160 | continue; |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | if($fileinfo['name'] && $fileinfo['deleteable'] != 'N') |
---|
165 | { |
---|
166 | $FILE_ORIGINAL = $_FILES['upload_file']['name'][$i]; |
---|
167 | $_FILES['upload_file']['name'][$i] = date('Ymd-H:i')."-".$_FILES['upload_file']['name'][$i]; |
---|
168 | $tmp_arr=array( |
---|
169 | 'from' => $_FILES['upload_file']['tmp_name'][$i], |
---|
170 | 'to' => $_FILES['upload_file']['name'][$i], |
---|
171 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
172 | |
---|
173 | ); |
---|
174 | $bo->vfs->cp($tmp_arr); |
---|
175 | $tmp_arr=array( |
---|
176 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
177 | 'relatives' => array(RELATIVE_ALL), |
---|
178 | 'attributes' => array( |
---|
179 | 'owner_id' => $bo->userinfo['username'], |
---|
180 | 'modifiedby_id' => $bo->userinfo['username'], |
---|
181 | 'size' => $_FILES['upload_file']['size'][$i], |
---|
182 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
183 | 'deleteable' => 'Y', |
---|
184 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
185 | ) |
---|
186 | ); |
---|
187 | $bo->vfs->set_attributes($tmp_arr); |
---|
188 | |
---|
189 | $return[] = array( |
---|
190 | "file" => $FILE_ORIGINAL, |
---|
191 | "undefined" => lang( "There is a file %1, that was not replaced", $FILE_ORIGINAL ) |
---|
192 | ); |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | if ($bo->vfs->cp(array( |
---|
197 | 'from'=> $_FILES['upload_file']['tmp_name'][$i], |
---|
198 | 'to'=> $_FILES['upload_file']['name'][$i], |
---|
199 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
200 | ))) |
---|
201 | { |
---|
202 | $bo->vfs->set_attributes(array( |
---|
203 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
204 | 'relatives' => array(RELATIVE_ALL), |
---|
205 | 'attributes' => array( |
---|
206 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
207 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
208 | ) |
---|
209 | )); |
---|
210 | } |
---|
211 | else |
---|
212 | { |
---|
213 | $return[] = array ( |
---|
214 | "file" => $_FILES['upload_file']['name'][$i], |
---|
215 | "sendFile" => lang('It was not possible to send your file') |
---|
216 | ); |
---|
217 | } |
---|
218 | } |
---|
219 | } |
---|
220 | elseif( $_FILES['upload_file']['name'][$i] ) |
---|
221 | { |
---|
222 | $bo->vfs->touch(array( |
---|
223 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
224 | 'relatives' => array(RELATIVE_ALL) |
---|
225 | )); |
---|
226 | |
---|
227 | $bo->vfs->set_attributes(array( |
---|
228 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
229 | 'relatives' => array(RELATIVE_ALL), |
---|
230 | 'attributes' => array( |
---|
231 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
232 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
233 | ) |
---|
234 | )); |
---|
235 | } |
---|
236 | |
---|
237 | if ( !(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE ) ) |
---|
238 | { |
---|
239 | $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]); |
---|
240 | if ($content) |
---|
241 | { |
---|
242 | $bo->vfs->set_summary(array( |
---|
243 | 'string'=> $_FILES['upload_file']['name'][$i], |
---|
244 | 'relatives' => array(RELATIVE_ALL), |
---|
245 | 'summary'=> $content |
---|
246 | )); |
---|
247 | } |
---|
248 | |
---|
249 | } |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | if( count($notifUser) > 0 ) |
---|
254 | { |
---|
255 | define('PHPGW_INCLUDE_ROOT','../../'); |
---|
256 | define('PHPGW_API_INC','../../phpgwapi/inc'); |
---|
257 | include_once(PHPGW_API_INC.'/class.phpmailer.inc.php'); |
---|
258 | $mail = new PHPMailer(); |
---|
259 | $mail->IsSMTP(); |
---|
260 | $boemailadmin = CreateObject('emailadmin.bo'); |
---|
261 | $emailadmin_profile = $boemailadmin->getProfileList(); |
---|
262 | $emailadmin = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']); |
---|
263 | $mail->Host = $emailadmin['smtpServer']; |
---|
264 | $mail->Port = $emailadmin['smtpPort']; |
---|
265 | $mail->From = $GLOBALS['phpgw']->preferences->values['email']; |
---|
266 | $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname']; |
---|
267 | $mail->IsHTML(true); |
---|
268 | |
---|
269 | foreach( $notifUser as $userMail ) |
---|
270 | { |
---|
271 | $mail->AddAddress($userMail); |
---|
272 | $mail->Subject = lang("Filemanager notification"); |
---|
273 | |
---|
274 | $body = "<div style='font-size: 9pt !important;'>"; |
---|
275 | $body .= lang("The user %1 sent the following files", "<span style='font-weight: bold;'>" . $GLOBALS['phpgw_info']['user']['fullname'] . "</span>") . "<br/><br/>"; |
---|
276 | |
---|
277 | foreach( $filesUpload['name'] as $key => $name ) |
---|
278 | $body .= "<div style='font-weight: bold;'> - " . $name ." ( " . $filesUpload['type'][$key] . " )</div>"; |
---|
279 | |
---|
280 | $body .= "<div style='margin-top:25px;'>".lang("To view the files %1", "<a href='../filemanager/index.php'>".lang("Click here")."</a>")."</div>"; |
---|
281 | $body .= "</div>"; |
---|
282 | |
---|
283 | $mail->Body = $body; |
---|
284 | |
---|
285 | if( !$mail->Send() ) |
---|
286 | { |
---|
287 | $return[] = $mail->ErrorInfo; |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | unset( $filesUpload ); |
---|
292 | |
---|
293 | } |
---|
294 | |
---|
295 | $_SESSION['response'] = ( count($return) > 0 ) ? serialize($return) : serialize( array( 0 => 'Ok' ) ); |
---|
296 | |
---|
297 | ?> |
---|