[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 12 require_once ('include/database/PearDatabase.php'); 13 require_once ('include/utils/utils.php'); 14 require_once ('include/logging.php'); 15 global $log; 16 global $current_user; 17 $vtigerpath = $_SERVER['REQUEST_URI']; 18 $vtigerpath = str_replace("/index.php?module=uploads&action=add2db", "", $vtigerpath); 19 20 $crmid = $_REQUEST['return_id']; 21 $log->debug("DGDEBUG In add2db.php"); 22 23 // Arbitrary File Upload Vulnerability fix - Philip 24 $binFile = $_FILES['filename']['name']; 25 26 $ext_pos = strrpos($binFile, "."); 27 28 $ext = substr($binFile, $ext_pos + 1); 29 30 if (in_array($ext, $upload_badext)) 31 { 32 $binFile .= ".txt"; 33 } 34 35 $_FILES["filename"]["name"] = $binFile; 36 // Vulnerability fix ends 37 38 //decide the file path where we should upload the file in the server 39 $upload_filepath = decideFilePath(); 40 41 $current_id = $adb->getUniqueID("vtiger_crmentity"); 42 43 if(move_uploaded_file($_FILES["filename"]["tmp_name"],$upload_filepath.$current_id."_".$_FILES["filename"]["name"])) 44 { 45 $filename = basename($binFile); 46 $filetype= $_FILES['filename']['type']; 47 $filesize = $_FILES['filename']['size']; 48 49 if($filesize != 0) 50 { 51 $desc = $_REQUEST['txtDescription']; 52 $description = addslashes($desc); 53 $date_var = $adb->formatDate(date('YmdHis')); 54 55 $query = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime) values('"; 56 $query .= $current_id."','".$current_user->id."','".$current_user->id."','".$_REQUEST['return_module'].' Attachment'."','".$description."',".$date_var.")"; 57 $result = $adb->query($query); 58 59 # Added by DG 26 Oct 2005 60 # Attachments added to contacts are also added to their accounts 61 $log->debug("DGDEBUG Here's the test:"); 62 $log->debug("DGDEBUG return_module: ".$_REQUEST['return_module']); 63 if ($_REQUEST['return_module'] == 'Contacts') 64 { 65 $log->debug("DGDEBUG Passed the test."); 66 $crmid = $_REQUEST['return_id']; 67 $query = 'select accountid from vtiger_contactdetails where contactid='.$crmid; 68 $log->debug("DGDEBUG Running query: ".$query); 69 $result = $adb->query($query); 70 if($adb->num_rows($result) != 0) 71 { 72 $log->debug("DGDEBUG Returned a row"); 73 $associated_account = $adb->query_result($result,0,"accountid"); 74 # Now make sure that we haven't already got this attachment associated to this account 75 # Hmmm... if this works, should we NOT upload the attachment again, and just set the relation for the contact too? 76 $log->debug("DGDEBUG Associated Account: ".$associated_account); 77 $query = "select name,attachmentsize from vtiger_attachments where name= '".$filename."'"; 78 $result = $adb->query($query); 79 if($adb->num_rows($result) != 0) 80 { 81 $log->debug("DGDEBUG Matched a row"); 82 # Whoops! We matched the name. Is it the same size? 83 $dg_size = $adb->query_result($result,0,"attachmentsize"); 84 $log->debug("DGDEBUG: These should be the same size: ".$dg_size." ".$filesize); 85 if ($dg_size == $filesize) 86 { 87 # Yup, it is probably the same file 88 $associated_account = ''; 89 } 90 } 91 } 92 else 93 { 94 $associated_account = ''; 95 } 96 } 97 # DG 19 June 2006 98 # Strip out single quotes from filenames 99 $filename = preg_replace('/\'/', '', $filename); 100 101 $sql = "insert into vtiger_attachments values("; 102 $sql .= $current_id.",'".$filename."','".$description."','".$filetype."','".$upload_filepath."')"; 103 $result = $adb->query($sql); 104 105 106 $sql1 = "insert into vtiger_seattachmentsrel values('"; 107 $sql1 .= $crmid."','".$current_id."')"; 108 $result = $adb->query($sql1); 109 110 # Added by DG 26 Oct 2005 111 # Attachments added to contacts are also added to their accounts 112 if ($associated_account) 113 { 114 $log->debug("DGDEBUG: inserting into vtiger_seattachmentsrel from add2db 2"); 115 $sql1 = "insert into vtiger_seattachmentsrel values('"; 116 $sql1 .= $associated_account."','".$current_id."')"; 117 $log->debug("DGDEBUG: Here's the query: ".$sql1); 118 $result = $adb->query($sql1); 119 } 120 121 echo '<script>window.opener.location.href = window.opener.location.href;self.close();</script>'; 122 } 123 else 124 { 125 $errormessage = "<font color='red'><B>Error Message<ul> 126 <li><font color='red'>Invalid file OR</font> 127 <li><font color='red'>File has no data</font> 128 </ul></B></font> <br>" ; 129 echo $errormessage; 130 include "upload.php"; 131 } 132 } 133 else 134 { 135 $errorCode = $_FILES['binFile']['error']; 136 137 if($errorCode == 4) 138 { 139 $errormessage = "<B><font color='red'>Kindly give a valid file for upload!</font></B> <br>" ; 140 echo $errormessage; 141 include "upload.php"; 142 } 143 else if($errorCode == 2) 144 { 145 $errormessage = "<B><font color='red'>Sorry, the uploaded file exceeds the maximum filesize limit. Please try a file smaller than 1000000 bytes</font></B> <br>"; 146 echo $errormessage; 147 include "upload.php"; 148 //echo $errorCode; 149 } 150 else if($errorCode == 3 || $errorcode == '') 151 { 152 echo "<b><font color='red'>Problems in file upload. Please try again!</font></b><br>"; 153 include "upload.php"; 154 } 155 156 } 157 158 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |