New phone, New Development, New Instructions

I recently won a Motorola Droid phone in the “claw event” promotion held by Verizon.  That being said I wanted to take a stab at some development on it.  I was trying to use the SimpleCursorAdaptor method to bind results from sqlite to a listview.. and it just wasn’t happening.

To create the database I had a line like this:

private static final String DATABASE_CREATE =
             "create table decks (id integer primary key autoincrement, "
             + "name text not null);";

My application would throw an exception and I had no idea why until I wrote  a simple debug method.  It’s the equivalent of  “alert();” in javascript.

public void createAlert(String message){
      AlertDialog alertDialog = new AlertDialog.Builder(this).create();
      alertDialog.setTitle("Message");
      alertDialog.setMessage(message);
      alertDialog.setButton("OK", new DialogInterface.OnClickListener(){
      public void onClick(DialogInterface dialog, int which){
                    return; }
      });
      alertDialog.show();
}

I simply threw my code in a java try-catch and received the error: “column _id does not exist.”  Did you catch that?  I didn’t declare my column name with an underscore.

I guess it is always good to read the documentation.

Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named “_id” or this class will not work.

Now why would I post this lame crap? Because after googling the problem… it seems that a lot of beginners are running into this issue.

Continue reading » · Written on: 12-01-09 · 1 Comment »

Searching Your Corporate LDAP/AD with python

There are a ton of examples out there on how to utilize ldap in python. I recently worked on a simple project which required active directory authentication using ldap. The following is simple script I’ve used hundreds of times.


#!/usr/bin/env python
#binds to ldap, queries for a specific AD account

import ldap

def Search(server,port, auth_user, auth_pass, ldap_user,attrs):

#base_dn should reflect your domain
base_dn="dc=yourcompanydomain,dc=com"
found_results=""

l = ldap.initialize('ldap://%s:%s' % (server, port) )
l.simple_bind_s(auth_user, auth_pass)
try:
search_result= l.search(base_dn,ldap.SCOPE_SUBTREE,'sAMAccountName='+ldap_user,attrs)
result_set =[]
while 1:
result_type, result_data = l.result(search_result,0)
if (result_data ==[]):
break
else:
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)

print len(result_set)
for line in result_set:
print line
except ldap.LDAPError, e:
print e

results = Search("192.168.5.10",3268,"akonkol@yourcompanydomain.com","mysecretpassword","akonkol",['givenName','sn','mail'])

This will return the attributes you supplied (givenName, sn, mail)

Continue reading » · Written on: 11-18-09 · No Comments »

Useful Commands for Proxy Migration

Recently I took on a project to migrate “difficult” users from our proxy-based firewalls to use default route towards packet filters.  Since we do not force users to authenticate for dhcp / keep track of IP assignments to users, it was very difficult to contact the remaining users going through our proxies.  The first step to identify hosts going through our proxy firewalls is to get a list of IP addresses, which I did with the following command  on the proxy firewalls:

tcpdump -qni em1 not src host 192.168.5.2 | awk ‘{print $2}’ | awk -F. ‘{print $1″.”$2″.”$3″.”$4}’ >> ~/hosts-through-proxy.txt

Explanation:

tcpdump -qni tells tcpdump to operate in “quiet” mode which really strips off a lot of extraneous info for our purposes.   The n flag also tells tcpdump to not resolve hostnames.

em1 This is your inside (internal) interface

192.168.5.2 This is the IP address on your internal interface, and tells tcpdump to ignore traffic coming from this IP address.

awk ‘{print $2}’ This prints the source ip field

awk -F. ‘{print $1″.”$2″.”$3″.”$4}’ This breaks up the souce ip text by periods, then prints the all the octets minus the port that tcpdump adds on

>> ~/hosts-through-proxy.txt This obviously writes the output to a file

After letting this run for a decent amount of time (a few days) I was able to run the file through uniq and produce a list of hosts using the firewall.

I will continue to post commands/workflows I find useful in this project.

Continue reading » · Written on: 11-10-09 · No Comments »

Maintaining Sanity Through Insanity

Last month was a spirit crusher due to an increased workload. Every once in a while I decide to run into the woods and get lost in something that I’ve never done. It’s been a while since I’ve had the chance to develop something selfishly.

Last year I wrote an intranet site using ruby on rails for what I call “personal enrichment.” Rails went OK, but whenever I wanted to achieve something that wasn’t textbook I found myself writing code that was like a trick/hack… needless to say it didn’t give me a good feeling.

About 6 months ago i started to force myself to use Python for all shell script tasks that were thrown my way. I love python. If you are used to scripting or actually enjoy scripting python is great. Now one of my pet peeves is when people say things like “lightweight, efficient, clean, easy to read.” Now all of those things are great.. but what does it really mean? Visual Basic is almost like writing english and developers think its the fisher-price of languages (including me). I have no answer to why I like python except a few little things:

  • whitespace is used to terminate directives, which forces everyone to use similar formatting
  • smtplib is the best email library I’ve ever worked with
  • django doesn’t assume as much as rails does, you still have some tedious work but I find it the perfect balance.

So I built my first site in django it’s currently running in my dev enviornment. What does the app do? It’s an app that uses the power of expect (one of my favorites), diff (another favorite), and a repository model. Simply put, the app connects to a device (via ssh/telnet) logs in and issues a command, stores the output in a database, does a diff between the last retrieved output and does a diff, if there is a diff it emails the system owner.

What does this achieve? Automatic change control and a configuration repository. I’ve used RANCID to do this before and I love the concept. RANCID doesn’t have a front end, but it also uses cvs/svn so you can install cvs/svn frontends.

I re-invented the wheel, but I like this wheel… it’s dead simple… and it helps out those admins that suck at cli.

Like I said, I haven’t deployed it yet… but I think I may want to release it. So my next problem I’m thinking about is how to package up and release a distribution. I’ve never used/installed a django driven web app… how do people usually release their django projects to the public? VMs?

tratto-screenshot

Continue reading » · Written on: 08-08-09 · No Comments »

Powerline Fishing

I’ve been fishing on Chicago’s lakefront since I was a very young child.  There is a certain culture that arises from people that like to fish but don’t have boats.  I never picked up on this culture until I lurked several chicago fishing messageboards.  Like any hobby, hobbyists are nerds which can’t wait to tell you about something they built… and help you along in your own projects.

I’ve always heard the rumor or urban legend about powerlining rigs.  Powerlining is essentially launching a high test fishing line out with an anchor and several baited hooks.  Pitching a line out with several other smaller lines allows you to achieve distances (and in turn depths) that would be hard to achieve using the traditional rod and reel.

powerline

There are three main ways to pitch this monster line out into the water:

  1. Throwing the anchor/weight by hand
  2. Using a water balloon sling shot
  3. Using the pressure of a CO2 tank (think potato gun)

Guess which one I’m interested in…. you guessed it… CO2 tank.

there_she_blows

After perusing several messaging boards I’ve come up with the following bill of materials:

  1. CO2 Fire extinguisher
  2. 5ft of 1″ pipe
  3. some sort of pipe adapter (I’ll figure that out once at home depot)
  4. 12 oz 1″ x 2.5″ weight
  5. 70′ of rubber band/cord
  6. A couple hundred yards of 10-12 lb test
  7. Reel
  8. two large swivels
  9. 10 smaller swivels
  10. hooks
  11. beads

Then my additonail ideas:

  1. Door stopper spring
  2. Dowel rod
  3. Bell
  4. Screweyes

The plan I’m working on… still need to add snelled hooks.

powerline-rig1

Continue reading » · Written on: 06-18-09 · 5 Comments »