Hi Guys,
I've installed osTicket a few days ago and everything works fine, except the attachments. I've read lot of tickets about this, but havent' found a solution. So I've made a debug session and found a solution that works for me. Maybe this is all stupid, maybe it could help someone...
My problem: Mail attachments gone lost between my qmail pipe and osTicket without an error or something else.
My debug Session:
1. Make the pipe more chatty:
temporarily added the following onto the beginning of /var/www/..../api/pipe.php:
$fp = fopen("/var/www/..../attachments/0210/test1.pdf", "w");
echo "result: $fp\n";
fclose($fp);
2. get an answer
send a mail with an allowed attachment and wait for response
...
/Warning: fopen(): SAFE MODE Restriction in effect. The script whose uid is 110 is not allowed to access /var/www/.../attachments owned by uid 10004 in /var/www/.../api/pipe.php on line 19
...
3. Changing php-cli configuration
changed /etc/php5/cli/php.ini:
;safe_mode = On
safe_mode = Off
at this point I've seen the first tickets with attachments - but they weren't readable
4. get an overview
cd /var/www/.../attachments/; ls -l
drwx------ 2 popuser popuser 4096 2010-02-23 20 0210
cd 0210; ls -l
-rw------- 1 popuser popuser 97686 2010-02-23 20 2FB11347BA2A4_test.pdf
so qmail runs with user 'popuser' and apache with user 'www-data'. i wonder why osTicket didn't set file mask 777....
5. pimping source code of include/class.ticket.php
//incoming email or json/xml bases attachments.
function saveAttachment($name,$data,$refid,$type){
...
//try creating the directory if it doesn't exists.
if(!file_exists(rtrim($dir,'/').'/'.$month)) { //CHANGED BY ZEAQ (trailing {)
<USERMENTION username="mkdir">@mkdir</USERMENTION>(rtrim($dir,'/').'/'.$month,0777);
chmod(rtrim($dir,'/').'/'.$month,0777); //ADDED BY ZEAQ
} //ADDED BY ZEAQ
....
if(($fp=fopen($filename,'w'))) {
fwrite($fp,$data);
fclose($fp);
chmod($filename,0777); //ADDED BY ZEAQ
$size=@filesize($filename);
new files and directories now get file mask 777... but I'm still wondering why mkdir didn't work as it should
-zeaq-
PS: My System: debian, plesk, qmail, apache2, php5, mysql5, osticket 1.6.0 / mail piping
PPS: For completeness I also changed the web upload function
//online based attached files.
function uploadAttachment($file,$refid,$type){
...
//try creating the directory if it doesn't exists.
if(!file_exists(rtrim($dir,'/').'/'.$month)) { //CHANGED BY PICHLO
<USERMENTION username="mkdir">@mkdir</USERMENTION>(rtrim($dir,'/').'/'.$month,0777);
chmod(rtrim($dir,'/').'/'.$month,0777); //ADDED BY PICHLO
} //ADDED BY PICHLO
...
if(move_uploaded_file($file,$filename)){
chmod($filename,0777); //ADDED BY PICHLO
$sql ='INSERT INTO '.TICKET_ATTACHMENT_TABLE.' SET created=NOW() '.
PPPS: don't forget to clean up /var/www/..../api/pipe.php if you changed it.