Attachment Improvements By Xon

Attachment Improvements By Xon 1.1.3

No permission to download
Hi Xon!, found this addon whilst looking for SVG support, and it is working great! Thanks!
Cheers.

Regarding the X-Accel-Redirect functionality: am I correct in guessing that this would have the effect of freeing up resources of the webserver? I'm just a bit confused as to what the benefit actually is. And then to implement, we would just copy your 'location' directive suggestion for 'internal data in webroot', to our nginx vhost config file?

We have a ton of attachments and are running the latest nginx.
Current XenForo, a php worker stays executing code for the entire time the download of the attachment is occurring.

With X-Accel-Redirect, php sets up the download and then nginx handles it for you. This reduces the amount of time spent by the php worker serving the attachment which means it can be doing other stuff.

As for implementing it, make sure you test it :p
 
Hi

could you expand the options to restrict per usergroup not only in file size in kb, but also in pixel dimensions on the longest side?

Some users upload images with 4000 pixel length and this is breaking the width of the thread....
 
Hello! My forum works with nginx + php5.6-fpm. After I've installed plugin, attachments are accessible, but my error log file is full of warns like this:
Code:
2016/04/20 23:37:14 [warn] 26956#0: *22351804 an upstream response is buffered to a temporary file /var/lib/nginx/fastcgi_temp/9/98/0000104989 while reading upstream, client: XXX, server: XXX, request: "GET /forum/attachments/33607/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000"…

2016/04/21 01:50:18 [warn] 26956#0: *22467847 a client request body is buffered to a temporary file /var/spool/nginx_client_body_temp/0000104997, client: xxx, server: xxx, request: "POST /forum/attachments/do-upload.json?hash=XXXXX&content_type=post HTTP/1.1"…
Nginx conf for forum is here:
Code:
location /forum/ {
    try_files $uri $uri/ /talk/index.php?$uri&$args;
    index index.php index.html;
}

location /forum/internal_data/ {
    internal;
    add_header Etag $upstream_http_etag;
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
}
location /forum/library/ {
       internal;
}
Could you please help to fix these warns?
 
@Azaly Make sure you have enabled X-Accel-Redirect support, then check. The entire aspect of that feature is for nginx to avoid spooling the files which are being sent from php/fastcgi.

This feature is disabled by default, since my add-on doesn't detect if it is behind nginx dynamically.

You may have some other add-on doing something with attachments.
 
I got this error 3 times, from the same user.
Code:
Error Info
Zend_Db_Statement_Mysqli_Exception: Mysqli statement execute error : Incorrect string value: '\xF0\x9F\x98\x8D\xF0\x9F...' for column 'filename' at row 1 - library/Zend/Db/Statement/Mysqli.php:214
Generated By: user, Today at 8:47 AM
Stack Trace
#0 /library/Zend/Db/Statement.php(297): Zend_Db_Statement_Mysqli->_execute(Array)
#1 /library/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 /library/Zend/Db/Adapter/Abstract.php(574): Zend_Db_Adapter_Abstract->query('INSERT INTO `xf...', Array)
#3 /library/XenForo/DataWriter.php(1638): Zend_Db_Adapter_Abstract->insert('xf_attachment_d...', Array)
#4 /library/XenForo/DataWriter.php(1627): XenForo_DataWriter->_insert()
#5 /library/XenForo/DataWriter.php(1419): XenForo_DataWriter->_save()
#6 /library/XenForo/Model/Attachment.php(539): XenForo_DataWriter->save()
#7 /library/SV/AttachmentImprovements/XenForo/Model/Attachment.php(31): XenForo_Model_Attachment->insertUploadedAttachmentData(Object(XenForo_Upload), 555085, Array)
#8 /library/XenForo/ControllerPublic/Attachment.php(205): SV_AttachmentImprovements_XenForo_Model_Attachment->insertUploadedAttachmentData(Object(XenForo_Upload), 555085)
#9 /library/XenForo/FrontController.php(351): XenForo_ControllerPublic_Attachment->actionDoUpload()
#10 /library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#11 /index.php(13): XenForo_FrontController->run()
#12 {main}
Request State
array(3) {
  ["url"] => string(45) "http://www.domain.com/attachments/do-upload"
  ["_GET"] => array(1) {
    ["/attachments/do-upload"] => string(0) ""
  }
  ["_POST"] => array(8) {
    ["_xfToken"] => string(8) "********"
    ["hash"] => string(32) "0e80b7668d3803b6582d7d3c88b94fed"
    ["content_type"] => string(4) "post"
    ["key"] => string(0) ""
    ["content_data"] => array(1) {
      ["thread_id"] => string(6) "158061"
    }
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfResponseType"] => string(9) "json-text"
    ["_xfUploader"] => string(1) "1"
  }
}



Error Info
Zend_Db_Statement_Mysqli_Exception: Mysqli statement execute error : Incorrect string value: '\xF0\x9F\x98\x8D\xF0\x9F...' for column 'filename' at row 1 - library/Zend/Db/Statement/Mysqli.php:214
Generated By: user, Today at 8:44 AM
Stack Trace
#0 /library/Zend/Db/Statement.php(297): Zend_Db_Statement_Mysqli->_execute(Array)
#1 /library/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 /library/Zend/Db/Adapter/Abstract.php(574): Zend_Db_Adapter_Abstract->query('INSERT INTO `xf...', Array)
#3 /library/XenForo/DataWriter.php(1638): Zend_Db_Adapter_Abstract->insert('xf_attachment_d...', Array)
#4 /library/XenForo/DataWriter.php(1627): XenForo_DataWriter->_insert()
#5 /library/XenForo/DataWriter.php(1419): XenForo_DataWriter->_save()
#6 /library/XenForo/Model/Attachment.php(539): XenForo_DataWriter->save()
#7 /library/SV/AttachmentImprovements/XenForo/Model/Attachment.php(31): XenForo_Model_Attachment->insertUploadedAttachmentData(Object(XenForo_Upload), 555085, Array)
#8 /library/XenForo/ControllerPublic/Attachment.php(205): SV_AttachmentImprovements_XenForo_Model_Attachment->insertUploadedAttachmentData(Object(XenForo_Upload), 555085)
#9 /library/XenForo/FrontController.php(351): XenForo_ControllerPublic_Attachment->actionDoUpload()
#10 /library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#11 /index.php(13): XenForo_FrontController->run()
#12 {main}
Request State
array(3) {
  ["url"] => string(45) "http://www.domain.com/attachments/do-upload"
  ["_GET"] => array(1) {
    ["/attachments/do-upload"] => string(0) ""
  }
  ["_POST"] => array(8) {
    ["_xfToken"] => string(8) "********"
    ["hash"] => string(32) "39a2eb2464a5d561fc8d6afcd71029bc"
    ["content_type"] => string(4) "post"
    ["key"] => string(0) ""
    ["content_data"] => array(1) {
      ["thread_id"] => string(6) "158061"
    }
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfResponseType"] => string(9) "json-text"
    ["_xfUploader"] => string(1) "1"
  }
}




Error Info
Zend_Db_Statement_Mysqli_Exception: Mysqli statement execute error : Incorrect string value: '\xF0\x9F\x98\x8D\xF0\x9F...' for column 'filename' at row 1 - library/Zend/Db/Statement/Mysqli.php:214
Generated By: user, Today at 8:43 AM
Stack Trace
#0 /library/Zend/Db/Statement.php(297): Zend_Db_Statement_Mysqli->_execute(Array)
#1 /library/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 /library/Zend/Db/Adapter/Abstract.php(574): Zend_Db_Adapter_Abstract->query('INSERT INTO `xf...', Array)
#3 /library/XenForo/DataWriter.php(1638): Zend_Db_Adapter_Abstract->insert('xf_attachment_d...', Array)
#4 /library/XenForo/DataWriter.php(1627): XenForo_DataWriter->_insert()
#5 /library/XenForo/DataWriter.php(1419): XenForo_DataWriter->_save()
#6 /library/XenForo/Model/Attachment.php(539): XenForo_DataWriter->save()
#7 /library/SV/AttachmentImprovements/XenForo/Model/Attachment.php(31): XenForo_Model_Attachment->insertUploadedAttachmentData(Object(XenForo_Upload), 555085, Array)
#8 /library/XenForo/ControllerPublic/Attachment.php(205): SV_AttachmentImprovements_XenForo_Model_Attachment->insertUploadedAttachmentData(Object(XenForo_Upload), 555085)
#9 /library/XenForo/FrontController.php(351): XenForo_ControllerPublic_Attachment->actionDoUpload()
#10 /library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#11 /index.php(13): XenForo_FrontController->run()
#12 {main}
Request State
array(3) {
  ["url"] => string(45) "http://www.domain.com/attachments/do-upload"
  ["_GET"] => array(1) {
    ["/attachments/do-upload"] => string(0) ""
  }
  ["_POST"] => array(8) {
    ["_xfToken"] => string(8) "********"
    ["hash"] => string(32) "39a2eb2464a5d561fc8d6afcd71029bc"
    ["content_type"] => string(4) "post"
    ["key"] => string(0) ""
    ["content_data"] => array(1) {
      ["thread_id"] => string(6) "158061"
    }
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfResponseType"] => string(9) "json-text"
    ["_xfUploader"] => string(1) "1"
  }
}
 
Is this addon useful for a LSWS configuration?
It does 3 things;
  • Extra permissions.
  • (optional) SVG as images support.
  • Add nginx X-Accel-Redirect support.
    • Which LiteSpeed Web Server doesn't support with the same header, but has the same concept with "X-LiteSpeed-Location".
    • If you are interested; shoot me a PM about adding this. It should be very simple.
 
If I add the following to my config.php then my site fails:
config['internalDataUrl'] = '/internal_data';

But internal_data is in the domain root.
 
Did you mean?:
Code:
$config['internalDataUrl'] = '/internal_data';

Because that starting $ is important :p (I typo'ed the instructions sorry)
 
I installed this on my test forum and checked "Nginx X-Accel-Redirect Support". How can I tell if it is working?
 
I installed this on my test forum and checked "Nginx X-Accel-Redirect Support". How can I tell if it is working?
Well if you can still view attachments it is still working! In debug mode, there is a 'Log Attachment Redirection URLs' setting if you want a log of what it does when implementing XAR support
 
I will try to install this addon for second time.
@Xon would you please help me

My forum is in webroot so internal_data folder exists within the webroot too.

My web nginx conf look like this:

Code:
location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$uri&$args;
       include /usr/local/nginx/conf/blockbots.conf;
    }

    location /internal_data/ {
        internal;
        allow 127.0.0.1;
        allow MY IP;
        deny all;
    }
    
    location /library/ {
        internal;
        allow 127.0.0.1;
        allow MY IP;
        deny all;
    }

I have to add your part so is this correct?

Code:
  location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$uri&$args;
       include /usr/local/nginx/conf/blockbots.conf;
    }

    location ^~ /internal_data/ {
        add_header Etag $upstream_http_etag;
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-Content-Type-Options nosniff;
        internal;
        allow 127.0.0.1;
        allow MY IP;
    }
    
    location /library/ {
        internal;
        allow 127.0.0.1;
        allow MY IP;
        deny all;
    }


And this I have to add into config.php in xenforo library folder?

Code:
location ^~ /internal_data/ {
  add_header Etag $upstream_http_etag;
  add_header X-Frame-Options SAMEORIGIN;
  add_header X-Content-Type-Options nosniff;
  internal;
}
 
I will try to install this addon for second time.
@Xon would you please help me

My forum is in webroot so internal_data folder exists within the webroot too.

My web nginx conf look like this:

Code:
location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$uri&$args;
       include /usr/local/nginx/conf/blockbots.conf;
    }

    location /internal_data/ {
        internal;
        allow 127.0.0.1;
        allow MY IP;
        deny all;
    }
   
    location /library/ {
        internal;
        allow 127.0.0.1;
        allow MY IP;
        deny all;
    }

I have to add your part so is this correct?

Code:
  location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$uri&$args;
       include /usr/local/nginx/conf/blockbots.conf;
    }

    location ^~ /internal_data/ {
        add_header Etag $upstream_http_etag;
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-Content-Type-Options nosniff;
        internal;
        allow 127.0.0.1;
        allow MY IP;
    }
   
    location /library/ {
        internal;
        allow 127.0.0.1;
        allow MY IP;
        deny all;
    }
This looks ok.

And this I have to add into config.php in xenforo library folder?

Code:
location ^~ /internal_data/ {
  add_header Etag $upstream_http_etag;
  add_header X-Frame-Options SAMEORIGIN;
  add_header X-Content-Type-Options nosniff;
  internal;
}
I've updated it so this is less confusing, this is about adding the headers. Which you've done.
 
So into config.php in xenforo library folder I have to add just this or nothing?
Code:
add_header Etag $upstream_http_etag;
  add_header X-Frame-Options SAMEORIGIN;
  add_header X-Content-Type-Options nosniff;
 
So into config.php in xenforo library folder I have to add just this or nothing?
Code:
add_header Etag $upstream_http_etag;
  add_header X-Frame-Options SAMEORIGIN;
  add_header X-Content-Type-Options nosniff;
Not XenForo config, webserver config. Which the previous post had added.
 
Aha, so just have to edit website nginx conf file than.
I have nothing to do/edit in xenforo config.php
 
Top Bottom