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