Skip to main content.
May 9th, 2007

QuickDNS – Change DNS TTLs with AppleScript

A client of ours is moving his servers to a new colo soon and like us, uses QuickDNS from Men and Mice to manage his BIND installations. He needed an AppleScript that would go through all his zones and reduce all the TTL values so that when he moved his servers, the transition would happen as smoothly as possible. So I whipped up this AppleScript:

set setDirection to "low"
--set setDirection to "normal"

tell application "QuickDNS Manager"
  repeat with theZone in zones
    set curZoneName to name of theZone
    set theDoc to (open theZone)
    tell theDoc
      if ("low" is setDirection) then
        set default time to live to 7200
        try
          set expire of first SOA record to "1400"
        end try
        try
          set refresh of first SOA record to "7200"
        end try
        try
          set negative caching of first SOA record to "7200"
        end try
        try
          set retry of first SOA record to "3600"
        end try
        try
          set time to live of first SOA record to "7200"
        end try
      end if
      if ("normal" is setDirection) then
        set default time to live to 7200
        try
          set expire of first SOA record to "604800"
        end try
        try
          set refresh of first SOA record to "28800"
        end try
        try
          set negative caching of first SOA record to "43200"
        end try
        try
          set retry of first SOA record to "7200"
        end try
        try
          set time to live of first SOA record to "86400"
        end try
      end if

      save with comment ""
    end tell

  end repeat
end tell

Posted by Brian Blood as Colocation, Servers at 5:39 PM UTC

No Comments »

May 4th, 2007

PHP coding – fixing old code for new standards with BBEdit

We are trying very hard to move all our systems to PHP 5. This means going through lots of old code and correcting some bad habits.

The biggest offender is the not quoting of references to keys in an associative array like so:

$Data[FirstName]

which should be:

$Data['FirstName']

so, I pulled out my favorite text munger, BBEdit and it’s excellent grep functionality and the ability to do searching over a directory. I ended up using this pattern:

\[([a-zA-Z]+[_a-zA-Z0-9]+)\]([^"'}])

This is looking for a left bracket, then any string that must start with an alpha character, then a right bracket. It’s also making sure there is NOT a quote or tick or right brace after that. The replacement pattern of:

['\1']\2

Now, this search picks up more than one would want, so it does take some effort to manually go through the results and do the replacement one by one. But I was able to take a medium to large code base and clean it up in about an hour.

Posted by Brian Blood as Text Munging, Web App Development at 5:12 PM UTC

No Comments »