Archive for November, 2009

Creating a Slave DNS Server on Bind9

Sunday, November 29th, 2009

I couldn’t find a quick and dirty list of commands for setting up a slave DNS server so I figured I would just throw it together.

Starting with a fully working primary name server, we are going to set up a slave name server. We are going to make the following assumptions:
primary – 1.2.3.4
slave – 4.5.6.7
* We want to have the domain example.com have a slave name server

On the primary (or master) name server, add the following lines to the options section.

1
2
3
4
options {
    allow-transfer { 4.5.6.7; };
    notify yes;
};

Ensure that you update the serial number in the SOA on the master. Then run:

1
# rndc reload

On the slave name server, add the following entry to the named.conf file (or whichever file houses your zone entries). Ensure that the path leading up to the zone file exists and that bind has write access to that directory.

1
 zone "example.com"  { type slave; file "/etc/bind9/zones/example.com.slave"; masters { 1.2.3.4; }; };

Then once you made the changes to the slave, you will need to reload the configuration. Do this the same way you did on the master:

1
# rndc reload

If you watch your DNS log, you should see the transfer happen as soon as you restart both named servers.

SSH Over The Web With Web Shell

Friday, November 27th, 2009

After reading a Tweet from Matt Cutts about being able to SSH from the iPhone (and the web in general), I had to give it a try. I am always looking for better ways to be able to check on systems when necessary. I have iPhone apps for SSHing around if I need as well, but like with any “new” tool, I have to try it out to see if it serves a purpose or makes my admin life easier in any way.

First go check out the Google Code repository for Web Shell. Webshell is written in Python and is based on Ajaxterm. All that’s required is SSL And Python 2.3 or greater. It works on any browser that has Javascript and can make use of AJAX.

The way Web Shell works is you start it up on a server and then can use a web browser to access only that machine over SSH. The works best if you have a gateway server to a network and use a single point of entry to access the rest of the servers. Web Shell runs on HTTPS on port 8022. Reading the README will lead you through the same set of instructions I used below. Once installed, we connect by using a web browser: https://server.com:8022/
(more…)

Adding AJAX Bookmarks to Your Rails Application (Part 2 of 2)

Wednesday, November 25th, 2009

In part 1 of this series, we discussed the base models, controller, database migrations necessary to get this project off the ground. Now we are going to continue with this functionality

Let’s take a look at what needs to go into the models to support this. If you have a model that uses a slug generated via to_param, then your code will look like the top model, If you are using the normal numeric id convention, then it will look like the bottom model. The reason for the specifically named methods get_title and get_description will become apparent when you start displaying bookmarks. The thought process is that you can use a consistent set of calls for displaying the bookmark information and put the code to grab that information in the model where it belongs rather than loading up the helper methods. What should also be noted is that the title and description fields are not always consistent across models. Therefore the method naming conventions returns the proper column with consistent method names.
(more…)

Adding AJAX Bookmarks to Your Rails Application (Part 1 of 2)

Monday, November 23rd, 2009

It you want to add the ability to bookmark pages in your Rails application, its actually a fairly straightforward thing to do. You can even do them in AJAX. There may be better ways to do this, but this way is somewhat abstract and it works for me, so hopefully it can work for you too. It is abstract in the sense that it will work for models with different URL styles and different column names.

The way this works is that you add a bookmark icon (which is initially disabled) to a show <model_name> page. When the user clicks on the bookmark icon, an AJAX query will be made in the background and update the users bookmark lists. I am approaching this from an abstract methodology. Meaning that I have “forced” these methods to work with models executed in various fashions (as I give examples of below). The AJAX call is going to be simply work as a toggle. It will actually call a toggle method in the bookmarks controller and change the current value and replace the image. The user can then view the pages they have bookmarked in their profile.

I have decided to break this into a multi-part blog entry because it ends up being quite long. Not necessarily in how long it takes, just the amount of space it takes to show all the code. I have done my best to only show relevant code and maintain brevity. Note: I will not cover how to allow for unobtrusive AJAX calls. That is beyond the scope of this set of posts.
(more…)

Modsecurity 2.5 Review Coming

Sunday, November 22nd, 2009

The folks over at Packt Publishing are kind enough to send me out an advance copy of the upcoming Modsecurity book by Magnus Mischel. I have written about mod security before, but really haven’t had a chance to look into it recently. I am anxious to see where its advanced to in version 2.5.

If you don’t know anything about mod_security, I encourage you to read up on it in the interim.

Stay tuned for the review.

File Read Write Create with IO::File

Friday, November 20th, 2009

Ran into an annoying gotchya with Perl’s IO::File. Apparently opening the file in append mode with read access if the file already exists puts the file position pointer at the end of the file. If it doesn’t exist, it creates the file. Note the +>>, that opens the file r/w/append. You can also use the more common (and more easily recognizable) form of a+.

1
2
3
4
5
    my $FH = new IO::File "$file", "+>>";
    while (my $line = $FH->getline()) {
      print "Line: $line\n";
    }
    undef $FH;

I noticed that when I tried to read the file (if it already existed), then nothing would be read. I neglected to realize that you must seek to position 0 in the file if you want to read it. Therefore the following code will work:

1
2
3
4
5
6
    my $FH = new IO::File "$file", "+>>";
    $FH->seek(0,0);
    while (my $line = $FH->getline()) {
      print "Line: $line\n";
    }
    undef $FH;

Although it might seem obvious that you need to be at the beginning of the file to read it forward (and it is), I didn’t realize the file pointer opened a file in append mode to the last position in the file (in hind sight, it does appear to be a bit more obvious).

Thoughts on Blog Posting

Thursday, November 19th, 2009

During a conversation I was having with Nirvdrum about blog posts, we got to discussing the validity and credibility of blog posting along with how and why people do it. I have a few thoughts on this topic.

The first and foremost reason that I write blog posts is that engineers who spend a lot of time figuring things out on the fly could use a helping hand. A lot of that figuring is done piecing together parts of other people’s solutions to problems from various blogs and papers. Every time I run into an issue or fix a problem, I try to write a blog post about it. I don’t do this because I feel that I have more to offer than anyone else, I just feel like my work should be able to benefit others (there is no use in reinventing the wheel). And to top it off, if I do something and someone has a better way, I like hearing about it in the comments or from an email.
(more…)

Converting From Subversion To Git

Monday, November 16th, 2009

Now that I have basically fallen for Git, I decided to finally move my Subversion repository over to Git (this way I can finally have a remote backup of it that I am comfortable with on Codaset).

The method for this was a lot more straightforward than I expected it to be. For the conversion tool, I used Nirvdrums fork of svn2git. It a feature complete version of the svn2git portion though the rest of it is still is development. Since it is a Ruby gem, getting it installed was a breeze. Just make sure that you have Ruby and rubygems installed.
(more…)

Remote Code Storage

Monday, November 9th, 2009

I was chatting with a friend of mine the other day about version control and why it’s necessary. So I decided to throw together a few options and a little explanation about why its important.

I have been using version control in some form or another for many years. I started with CVS, then moved to Subversion (which I still use quite a bit), and now, as my latest post about Git GUI’s on the Mac suggests, I have moved to Git. The one thing that has been consistent across every single transition has been that I had some sort of remote code storage every time. During the CVS days, I used a CVS pserver and stored my code locally and remotely for safety (and ease of checkout/deployment). For subversion, I always stored my code locally and used an apache install somewhere with a WebDAV module to get at and deploy whatever code is necessary.

Ultimately I use remote code storage for 2 reasons, back up my existing code base (so I have it in more than one place) and to have a visualization of what is going on in your project. That visualization is handy to be used as a central consistent view for multiple people (unlike a personal client which can be different per user).
(more…)

Git GUI on Mac OS X

Friday, November 6th, 2009

I have been using Git a lot lately and have found a lot of things I like better in Git than in Subversion. The one major item that was really bothering me was that there wasn’t really too many Git clients that could help you visualize the repository. I mean show merges, commits, branching, blame, etc. Seeing that CVS and Subversion have been around for a lot longer, there are many clients for them and now that I have been using Git for a while on the command line, I decided to take a look again.

What I am looking for is simple. I want 2 things:

  1. In the typical Mac style, I want a great looking interface. I want to be able to see who did what, when, and why (assuming good commit messages from the developers).
  2. Easy navigation through all the features. I am not planning on using any of the commands visually, I am still an archaic command line junkie.

One of my favorite features of git coming from Subversion is the ease of branching. I branch for everything now that I am using git. So in order to best track my changes, I was hoping for something to help me visualize my branches. I didn’t count this specifically in my desires because it wasn’t a requirement to be acceptable, but it definitely would have helped to tip the scales.
(more…)

One Time Modal Windows With Rails and Fancybox

Tuesday, November 3rd, 2009

Let’s say that you have a situation that you want to have a modal window show up only once for each user. It’s actually not that difficult although lots of Googling around got me nowhere. I am choosing to use FancyBox for my modal window, but feel free to use your modal framework of choice. So let’s get down to business.

First thing you’ll need to do is download FancyBox and copy the stylesheets, images, and Javascript files to their proper/desired location in your Rails app. Style the window according to your likings.

Whether it is right or wrong, I did this entirely in the view, without even pulling the Javascript out into the application.js (or even another Javascript file for that matter). My reason was that I only want the modal window showing up on this page. If you want your modal window to show up somewhere else (or on every page), then put the code in your layout. But remember that this call will be executed every time the page loads. I put mine in a profile page which doesn’t get accessed that often so the conditional is not checked quite as frequently.

My application uses Facebook Connect and grabs the users Facebook Proxy email address (FB app developers will know what this is). So I check if that’s the email I have for the user. If yes, then I pop up a modal window on page load only once to get their regular email address and possibly a password so they can login to their account without Facebook Connect if they want. When the modal window is shown, a variable is set in the cookie (note that this cookie is shared with authlogic for sessions) to ensure that the modal window isn’t shown again.
(more…)