Fri, 6 Dec 2013

Another SELinux Lesson

— SjG @ 6:17 pm

So there’s this project that requires a ridiculously complicated communication protocol involving lots of byte-wrangling and formatting and weird transports. For the sake of brevity, I’ll only mention one of the endpoints, which requires decoding an email attachment.

Of course, this means a procmail script sending the email to PHP for processing and much ceremonious mucking about. On first go, it was failing. In debug mode, procmail was telling me that permission was denied. But it wasn’t user permissions: the file was owned by the same user as receiving the email and running the procmail script.

Naturally, when faced with cryptic permission failures, the first thing I did was look at /var/log/audit/audit.log and /var/log/messages for SELinux denials. There I found nothing at all. No errors, no warnings, no ugly “avc: denied” splatters.

Finally, this page here explained it to me. Rebuilding the policies with semodule -DB quickly revealed that my problem was, in fact, SELinux (as it all so often is). Once I could see the policies that were marked “dontaudit,” it was just an hour of building more and more complicated policies for procmail before stuff started working.

Once everything was good, happy, and shiny, a simple semodule -B returned the SELinux logging to the previous state, and I could once again spend my time fighting the convoluted bit-twiddling of the communication protocol.

Sat, 2 Nov 2013

Hallowe’en

— SjG @ 10:43 am

We had a Hack o’ Lantern this year, who responded to tweets, tweeted jokes, and “accidentally” revealed it’s plans for world domination.

Pure pumpkin cyber evil
Pure pumpkin cyber evil

For the World Domination Plan, I needed some artwork, which I hereby inflict upon the world.

They’re remixes. Tux is courtesy of Larry Ewing, Simon Budig, and Anja Gerwinski.

broadcast2

vamp-tux

Mon, 2 Sep 2013

Legacy-labeler.com

— SjG @ 5:29 pm

Consider this the soft-launch announcement for Legacy Labeler, an experimental web site for adding metadata and labels to your family pictures.

Samuel

In Ye Olden Days, family pictures would be physical photo prints all stuffed in a drawer somewhere. It’s possible that they were neatly labeled and put in albums, or mayhaps someone wrote names on the backs.

Today, however, we are deluged in JPEGs straight out of our digital cameras. Some people have discipline and create digital galleries, but more often they’re just accumulated on hard-drives somewhere.

Legacy-labeler.com is an approach for labeling these JPEG images, and adding or updating the relevant metadata in the file. Future generations deserve to know more about the pictures than when it was taken. “DSCN1012.jpg” probably won’t mean a whole lot to them.

I welcome feedback on the site: suggestions, bug reports, comments, flattery, invective, snark, or what-have-you.

Wed, 12 Jun 2013

Smart fixtures for testing

— SjG @ 1:28 pm

Because we’re not completely insane, we run automated testing of the web sites and web-based applications we develop. Because we are busy, we probably don’t do as much testing as we’d like. While there’s always room for improvement, though, having both unit tests and functional tests is a huge, huge win.

For enterprise intranet sites, there are a lot of things which are time-based. There are documents that get published or expired on given dates, users who receive notifications on a schedule, financial tables that depend on the fiscal year, and so on. If you test these functions (and, of course, you do), you may discover your automated tests suddenly fail on the first day of the quarter or some other threshold. This will likely be due to hard-coded dates in your test fixtures (and surely not because of boundary-condition bugs in your code).

There is an easy solution. Where it’s appropriate, you can make your fixtures “smart” by using adaptive logic. Messy, beautiful functions like PHP’s strtotime make this easy.

For example, here’s a snippet from a fixture for a Yii-based project. It’s for a message data table, and I want to be able to guarantee that there’s at least one valid message and one expired message no matter when I’m testing:


"message_1"=>array(
"Id"=>1,
"Subject"=>"Meeting",
"Content"=>"There will be an important announcement on ".date('m/d/Y',strtotime('first day of next month')),
"PublicationDate"=>date('Y-m-d H:i:s',strtotime('midnight first day of last month')),
"ExpirationDate"=>date('Y-m-d H:i:s',strtotime('midnight first day of next month -1 second')),
),
"message_2"=>array(
"Id"=>2,
"Subject"=>"Monthly Results",
"Content"=>"This message is never current",
"PublicationDate"=>date('Y-m-d H:i:s',strtotime('midnight first day of last month -2 month')),
"ExpirationDate"=>date('Y-m-d H:i:s',strtotime('midnight first day of this month -1 day')),
),

With a fixture like that, I can make safe assumptions about time-related displays no matter what the current date is.

Filed in:General, Technology

Fri, 24 May 2013

Javascript approximation for Pi

— SjG @ 11:01 am

Based on this tweet, I now have the ultimate JavaScript approximation for Pi (Π), which I think we can all agree is preferable in every way to the outmoded Math.PI:

var pi=((++[+[]][+[]]+[]+ ++[+[]][+[]]+[])* ++[+[]][+[]])*(++[+[]][+[]]+ ++[+[]][+[]])/((+[+[]]+'x'+(![]+[])[[+!+[]+!+[]]*[+!+[]+!+[]]])/(++[+[]][+[]]+ ++[+[]][+[]]));