Querying MSSQL database from LAP (not LAMP!)

My current task is to use a policy compliance tool to check all of our systems. Find the guessed passwords, Missing OS patches etc… Not to go into the details… The program I am using uses its own database. Therefore it is a pain to make user specific queries to the program…Thank god, for this, they came up with a database converter which dumps the datas to a MSSQL database of anykind. (Thank god for a readable DB, SHAME ON YOU for not being able to dump it on a MYSQL or POSTGRESQL DB server… That`s another story…)

Well… Since I have a lot of data spilling out from each conversion, I had to come up with a DB querying and displaying mechanism to sort/analyse all these junk. First I tried the “reports tool” coming with the converter tool, but two words: IT SUCKS!

I decided to write my own piece of code. For this I had options. (who hates options?) I have to have a Windows user readable output (read: Excel, html, pdf…) I have to use any tool I want for this… I have NO IDEA about MSSQL, I have never used a tool to query it… I have knowledge of perl, php, python and made DB connections using them before.

I first decided to use python and create also a GUI. But I wasted too much time (Since it must be completed ASAP 😛 ) Anyway… I turned to perl and tried to find a MSSQL libs and I was amazed by the choices of libs for DB connections. I had to choose one and eliminate others (i had no time for this 🙂 So I made my decision on using php. 🙂

I had a redhat 8.0 laptop on my hand and I wanted to go on with that. FYI the version of apache coming with RH 8.0 is 2.0.40. Of course, RH was not shipped with php with MSSQL support, so i had to compile my own. I downloaded FreeTDS and installed it to my box. I downloaded PHP v4.3.4 and compiled it. I realized that I didn`t have httpd-devel packages installed on my RH machine. So I downloaded them I `rpm -Uvh`ed them, and tried to recompile php with Apache SO mod support. It didn`t work. Because php 4.3.4 requires apache version >= 2.0.44 (remember RH 8.0 is shipped with 2.0.40, i am 4 versions missing 🙁 )

So the decision is made. “rpm -e `Put here anything related to httpd packages`” Go to hell with RH rpms for apache, php, etc… And than I went to Apache for downloading the http server, and installed it. And than recompile the php with appropriate supports (aka ./configure –with-mssql –with-mysql –with-apxs2=/usr/local/apache2/bin/apxs)
make
make install (as root)
et voilà! I have a running apache server with php supporting MSSQL connections.

Run the scripts I tried earlier.. and BANG! I cannot connect to the database! 🙂 Since i`m a dumbass sometimes and I don`t read the documentations (RTFM Emre!) I realized after reading them (everything post-factum…) that I need to create some DB connection handlers for FreeTDS (checked /usr/local/etc/freetds.conf and edited the lines needed for MSSQL connections.)

[MyServer70]
host = your.host.here
port = 1433
tds version = 8.0

Run the scripts again and TADAAA! My stupid users and their guessed passwords 🙂

Next step is now to create a nice reporting mechanism and modular sytem for compliance queries.

Well long to read, even longer to live it and implement. Ok.. I`m off now, I`m going home….