From 825cddfb623a8cf69948e005ef5134fc678e5ccd Mon Sep 17 00:00:00 2001 From: Luis Abreu Date: Thu, 7 Feb 2013 12:57:38 +0000 Subject: [PATCH 1/2] Spoof curl user agent to avoid UA blacklist Using Chrome UA instead. Could go into config.json. --- lib/image-magick.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/image-magick.js b/lib/image-magick.js index 3d6135e..a2d843e 100644 --- a/lib/image-magick.js +++ b/lib/image-magick.js @@ -1,9 +1,10 @@ -var exec = require('child_process').exec - , path = require('path') - , fs = require('fs') - , exists = fs.exists || path.exists - , crypto = require('crypto') - , Identify = require('identify.js') +var exec = require('child_process').exec + , path = require('path') + , fs = require('fs') + , exists = fs.exists || path.exists + , crypto = require('crypto') + , Identify = require('identify.js') + , userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.30 (KHTML, like Gecko) Chrome/26.0.1405.0 Safari/537.30' var ImageMagick = module.exports = function(config, logger) { if(!config) throw new Error('Where is my config?') @@ -17,7 +18,7 @@ var ImageMagick = module.exports = function(config, logger) { ImageMagick.Templates = { tmpPath: "%{dir}/%{file}", - downloadCmd: "curl --create-dirs -sf '%{source}' -o '%{target}'", + downloadCmd: "curl -A " + userAgent + " --create-dirs -sf '%{source}' -o '%{target}'", identifyCmd: "identify -format %m '%{file}'", identifyVerboseCmd: "identify -verbose '%{file}'", createBlankImageCmd: "convert -bordercolor '#B1B1B1' -background '#eee' -border 1 -size %{size} -fill '#900' -font '/Library/Fonts/Arial Bold.ttf' -pointsize 16 label:' x' '%{tmpfile}'", From 8426d77389bede2c669155989835471b3fd13315 Mon Sep 17 00:00:00 2001 From: Luis Abreu Date: Thu, 7 Feb 2013 13:31:21 +0000 Subject: [PATCH 2/2] Simplified spoof UA, added referrer to curl command --- lib/image-magick.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/image-magick.js b/lib/image-magick.js index a2d843e..de23661 100644 --- a/lib/image-magick.js +++ b/lib/image-magick.js @@ -1,10 +1,11 @@ var exec = require('child_process').exec , path = require('path') , fs = require('fs') + , url = require('url') , exists = fs.exists || path.exists , crypto = require('crypto') , Identify = require('identify.js') - , userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.30 (KHTML, like Gecko) Chrome/26.0.1405.0 Safari/537.30' + , userAgent = 'Mozilla' var ImageMagick = module.exports = function(config, logger) { if(!config) throw new Error('Where is my config?') @@ -18,7 +19,7 @@ var ImageMagick = module.exports = function(config, logger) { ImageMagick.Templates = { tmpPath: "%{dir}/%{file}", - downloadCmd: "curl -A " + userAgent + " --create-dirs -sf '%{source}' -o '%{target}'", + downloadCmd: "curl -A " + userAgent + " -e %{sourceHost} --create-dirs -sf '%{source}' -o '%{target}'", identifyCmd: "identify -format %m '%{file}'", identifyVerboseCmd: "identify -verbose '%{file}'", createBlankImageCmd: "convert -bordercolor '#B1B1B1' -background '#eee' -border 1 -size %{size} -fill '#900' -font '/Library/Fonts/Arial Bold.ttf' -pointsize 16 label:' x' '%{tmpfile}'", @@ -165,7 +166,8 @@ ImageMagick.prototype._createTmpPath = function(rand) { ImageMagick.prototype._downloadSource = function(source, target, callback) { this.logger.log('Downloading source') - this.execute(ImageMagick.Templates.get('downloadCmd', {source: source, target: target}), { timeout: this.config.timeouts.download }, callback) + var sourceHost = url.parse( source ).host; + this.execute(ImageMagick.Templates.get('downloadCmd', {source: source, sourceHost: sourceHost, target: target}), { timeout: this.config.timeouts.download }, callback) } ImageMagick.prototype._localizeSource = function(source, tmpPath, callback) {