[3019] | 1 | <?php |
---|
[5509] | 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 | |
---|
[3019] | 12 | require_once '../../header.session.inc.php'; |
---|
[3610] | 13 | |
---|
[3889] | 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 | ) ); |
---|
[3896] | 22 | |
---|
[3889] | 23 | exit; |
---|
| 24 | } |
---|
| 25 | |
---|
[3019] | 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'); |
---|
[3879] | 37 | $c = CreateObject('phpgwapi.config','filemanager'); |
---|
[3019] | 38 | $c->read_repository(); |
---|
| 39 | |
---|
[3879] | 40 | $current_config = $c->config_data; |
---|
| 41 | $upload_max_size = $current_config['filemanager_Max_file_size']; |
---|
| 42 | $path = $_POST['path']; |
---|
| 43 | $notifUser = $_POST['notifTo']; |
---|
[5327] | 44 | $show_upload_boxes = count($_FILES['upload_file']['name']); |
---|
| 45 | $filesUpload = $_FILES['upload_file']; |
---|
[3879] | 46 | |
---|
[3610] | 47 | function create_summaryImage($file) |
---|
| 48 | { |
---|
[3019] | 49 | list($width, $height,$image_type) = getimagesize($file); |
---|
[3610] | 50 | |
---|
[3019] | 51 | switch($image_type) |
---|
| 52 | { |
---|
[3610] | 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; |
---|
[3019] | 64 | } |
---|
[3610] | 65 | |
---|
[3019] | 66 | $max_resolution = 48; |
---|
[3610] | 67 | |
---|
| 68 | if ($width > $height) |
---|
| 69 | { |
---|
[3019] | 70 | $new_width = $max_resolution; |
---|
| 71 | $new_height = $height*($new_width/$width); |
---|
| 72 | } |
---|
[3610] | 73 | else |
---|
| 74 | { |
---|
[3019] | 75 | $new_height = $max_resolution; |
---|
| 76 | $new_width = $width*($new_height/$height); |
---|
| 77 | } |
---|
[3610] | 78 | |
---|
[3019] | 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++) |
---|
[3610] | 92 | { |
---|
[3019] | 93 | $command .= " ".$_FILES['upload_file']['tmp_name'][$i]; |
---|
[3610] | 94 | } |
---|
| 95 | |
---|
| 96 | $return = 0; |
---|
| 97 | |
---|
[3019] | 98 | exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return); |
---|
[3610] | 99 | |
---|
[3019] | 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 | |
---|
[3879] | 107 | if( $path != '/' ) |
---|
[3610] | 108 | { |
---|
[3889] | 109 | $return = array( ); |
---|
[3879] | 110 | for( $i = 0; $i != $show_upload_boxes; $i++) |
---|
[3019] | 111 | { |
---|
[3889] | 112 | if ( $_FILES['upload_file']['error'][$i] !== 0 ) |
---|
[3019] | 113 | { |
---|
[3879] | 114 | $return[] = array( |
---|
[3889] | 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( |
---|
[3879] | 123 | "file" => $_FILES['upload_file']['name'][$i] , |
---|
| 124 | "size" => $_FILES['upload_file']['size'][$i] , |
---|
| 125 | "size_max" => ($upload_max_size*1024*1024) |
---|
| 126 | ); |
---|
[3019] | 127 | continue; |
---|
| 128 | } |
---|
[3879] | 129 | elseif( $_FILES['upload_file']['size'][$i] > 0 ) |
---|
| 130 | { |
---|
[3881] | 131 | $badchar = $bo->bad_chars( $_FILES['upload_file']['name'][$i], True, True ); |
---|
[5327] | 132 | |
---|
[3881] | 133 | if( $badchar ) |
---|
[3879] | 134 | { |
---|
| 135 | $return[] = array( |
---|
| 136 | "file" => $_FILES['upload_file']['name'][$i], |
---|
| 137 | "badchar" => lang('File names cannot contain "%1"', $badchar) |
---|
| 138 | ); |
---|
| 139 | continue; |
---|
| 140 | } |
---|
[3019] | 141 | |
---|
[3879] | 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 | )); |
---|
[3019] | 149 | |
---|
[3879] | 150 | $fileinfo = $ls_array[0]; |
---|
[3019] | 151 | |
---|
[3879] | 152 | if( $fileinfo['name'] ) |
---|
[3019] | 153 | { |
---|
[3879] | 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 | } |
---|
[3019] | 162 | } |
---|
| 163 | |
---|
| 164 | if($fileinfo['name'] && $fileinfo['deleteable'] != 'N') |
---|
| 165 | { |
---|
[3896] | 166 | $FILE_ORIGINAL = $_FILES['upload_file']['name'][$i]; |
---|
[3019] | 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( |
---|
[5327] | 176 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
| 177 | 'relatives' => array(RELATIVE_ALL), |
---|
[3879] | 178 | 'attributes' => array( |
---|
[5327] | 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]) |
---|
[3019] | 185 | ) |
---|
| 186 | ); |
---|
| 187 | $bo->vfs->set_attributes($tmp_arr); |
---|
| 188 | |
---|
[3879] | 189 | $return[] = array( |
---|
[3897] | 190 | "file" => $FILE_ORIGINAL, |
---|
[3896] | 191 | "undefined" => lang( "There is a file %1, that was not replaced", $FILE_ORIGINAL ) |
---|
[3879] | 192 | ); |
---|
[3019] | 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( |
---|
[3879] | 203 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
| 204 | 'relatives' => array(RELATIVE_ALL), |
---|
| 205 | 'attributes' => array( |
---|
[5327] | 206 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
| 207 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
[3879] | 208 | ) |
---|
[3019] | 209 | )); |
---|
| 210 | } |
---|
[3879] | 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 | ); |
---|
[3019] | 217 | } |
---|
| 218 | } |
---|
| 219 | } |
---|
[3879] | 220 | elseif( $_FILES['upload_file']['name'][$i] ) |
---|
[3019] | 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( |
---|
[3879] | 228 | 'string' => $_FILES['upload_file']['name'][$i], |
---|
[5327] | 229 | 'relatives' => array(RELATIVE_ALL), |
---|
[3879] | 230 | 'attributes' => array( |
---|
[5327] | 231 | 'mime_type' => $_FILES['upload_file']['type'][$i], |
---|
| 232 | 'comment' => stripslashes($_POST['upload_comment'][$i]) |
---|
[3879] | 233 | ) |
---|
[3019] | 234 | )); |
---|
| 235 | } |
---|
| 236 | |
---|
[3879] | 237 | if ( !(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE ) ) |
---|
[3019] | 238 | { |
---|
| 239 | $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]); |
---|
[3879] | 240 | if ($content) |
---|
| 241 | { |
---|
[3019] | 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 | } |
---|
[3610] | 251 | } |
---|
[3415] | 252 | |
---|
[3610] | 253 | if( count($notifUser) > 0 ) |
---|
[3415] | 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); |
---|
[3610] | 268 | |
---|
| 269 | foreach( $notifUser as $userMail ) |
---|
[3415] | 270 | { |
---|
| 271 | $mail->AddAddress($userMail); |
---|
| 272 | $mail->Subject = lang("Filemanager notification"); |
---|
[3610] | 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 | { |
---|
[3415] | 287 | $return[] = $mail->ErrorInfo; |
---|
| 288 | } |
---|
| 289 | } |
---|
[3610] | 290 | |
---|
| 291 | unset( $filesUpload ); |
---|
| 292 | |
---|
[3415] | 293 | } |
---|
| 294 | |
---|
[3610] | 295 | $_SESSION['response'] = ( count($return) > 0 ) ? serialize($return) : serialize( array( 0 => 'Ok' ) ); |
---|
| 296 | |
---|
| 297 | ?> |
---|