mike ward content follows

Archive for November, 2008

paperclip just worked

Posted in rails, GEM/plugins on November 21st, 2008

OK for a current project I needed to have attached photos for stores. I could have chosen to use attachment_fu, but after seeing the excellent Railscast, I was eager to try paperclip. My opinion - a bit disappointing really, as it was so effortless I didn’t actually learn much at all. No looking through lots of plugin code, no spending hours of googling - no pain!
I grabbed the plugin code since the GEM seems to be out of date? How easy was it? Keep reading.

First I installed the plugin then I ran the migration. Four columns added to my stores table for filename, size, type and timestamp. Frankly I could live without all four, but some projects are gonna use these I suppose.

Next I added a line to the model to which I wanted to have an attachment:

has_attached_file :exterior,

:url => “/images/stores/:attachment/:id.:extension”,
:path => “:rails_root/public/images/stores/:attachment/:id.:extension

I could have also specified multiple different file sizes to save, like 150×200, 400×300, etc.like this:

:styles => { :thumb => “200×150″, :regular => “640×480>” }

Then I added a couple lines to validate the things I cared about:

validates_attachment_size :exterior, :less_than => 100.kilobytes
validates_attachment_content_type :exterior,

:content_type => [’image/jpeg’,'image/png’,'image/gif’]

There’s one “gotcha” in here, in that to change your new and edit forms to work with binary attachments you’re gonna have to change the form action to be mixed/multipart

<% form_for(@store, :html => { :multipart => true }) do |f| %>

Next I went to the view and just refer to the attachment as @store.exterior.url (my stores controller serves up @store), and if I had saved thumbnails and large versions I could have specified which one I wanted to display.

Now I am saving these store images in a shared directory. So when I deploy, I have a task defined in capistrano that runs right after the deploy:symlink that also puts symlink in the public/images/stores directory pointing to this shared store photo store (pun intended) But I need to run a background task to back up those images periodically, or I’ll forget about them until one day…..

Long story short, I decided to see how easy it was to tell Paperclip to save them in my Amazon s3 account instead of the filesystem. Yeah you guess it - pretty tame. Here’s the revised store.rb snippet:

has_attached_file :exterior,

:storage => :s3,
:bucket => “pizza.pro.stores.exteriors”,
:s3_credentials => “#{RAILS_ROOT}/config/s3.yml”,
:path => “:id.:extension”

Don’t ask why I am using such a ridiculously named bucket, but I am. Anyway the 2 keys for s3 are kept in a YAML file as you can see. I treat it just like my database.yml file, and don’t version it, but simply keep in :rails_root/shared/config/ and create a symlink to it on every deploy.
Now you may ask, how can this be such a happy plugin experience. Well if I have to criticize, it would be that I see it added 4 columns to my stores table. In my case I could get by with less. But I think the main point is if I had a half dozen attachments per model, like for a real estate app with exteriors, kitchens, family rooms, etc. then this table could not be allowed to grow that wide.

But hey, if the app is featuring photos as a central item, shouldn’t you have a model just for your attachments? Add one column to refer back to the model it belongs_to and you’re golden. That’s really not so terrible.

storm worm, DDNS attacks and more

Posted in DNS, security on November 11th, 2008

Such an interesting story this week all over the web: researchers at UC Berkley and UC San Diego spent some time this spring infiltrating a giant botnet called Storm Worm. This botnet has been estimated to send up to 20% of the spam on the Internet. So the researchers substituted their own faux phishing sites as the link targets in the spam in order to gather metrics.

The results: hundreds of millions of emails, an estimated three quarters of which were intercepted and only 28 would-be sales. On the other hand, when they tried to estimate malware-installing effectiveness it turns out that fully 10 percent of people following the link actually click on to install the payload! Conclusions: First, it takes such a low number of sales to make spam campaigns profitable that it will surely continue unabated; second, malware distribution can be accomplished effectively using the services of botnet operators. Both of these phenomena will evolve and flourish.

In other newsnetwork attacks would seem to be increasing at a faster rate than last year, according to Arbor Networks’ annual survey of ISP’s. Not only that but there is a broadening out of attack types. The main focus for concern is attacksĀ  on DNS and network infrastructure systems. DNS cache poisoning has jumped up to be the second largest threat in the eyes of respondents, exceeded only by botnets and followed closely by route hijacking. Some of the things the public usually worries about rank significantly lower: worms, identity theft, etc. And the bad news: attacks are getting more specific to networks, regions, and applications!Purchase Brahmi

Scary Halloween Story

Posted in security on November 1st, 2008

Why diversity of computer systems is good.

http://www.rsa.com/blog/blog_entry.aspx?id=1378