Moodling!

Moodle Logo
Moodle

Last year, I built a framework for a training site for my company in an effort to save some money.  This framework was highly restrictive because I was keeping it on the company network.  Still, I was able to build a training site on the local intranet that embedded flash classes, wrote to a database and was something that could be adapted with time all with html, javascript and using Microsoft Access as a database.

I found a much better and more practical solution, with the thought I will not be there to write the test in html and maintain the database forever.  Along comes moodle, an open source course management system.  This is much better than anything I’d dreamt of doing with html and javascript and it’s really amazing in it’s ability to adapt to several situations.  I’m sure with this application, there will not be any problem handing off the on-line training for the company.

Linux bash script for wifi.

When starting with Backtrack4, I compiled and installed the Broadcom wl driver for my laptop’s wifi. The unfortunate thing was that I got very frustrated because the default connection manager, wicd was getting confused when I would go to a network other than the one I initially connected to after boot-up. Shortly after that, Ubuntu 9.10 was experiencing the same difficulty after upgrading the kernel. So to work around using a network manager, I created a quick script to use.

In this script, you can see that you can pass a variable for your network name and key in the same format as you would normally. This was a fun script as it could easily be adapted as it’s own network manager, even with a little more work, you could have it in the tray, it’s own gui, etc. It’s nothing more than the commands typically used to connect on wifi but it just automated the process. I then went and created a child script for my most used networks, and after placing these in my bin, I actually have started to prefer this method.

Here’s the script:

#!/bin/bash

# die with honor
function usage() {
	echo "usage: ./connectWifi \"<essid>\" [key]"
	echo "       *key in ascii prefaces s:[key]"
	echo
	exit 1
}

# killed in disgrace
function die() {
	echo
	echo "   [*] ERROR: $1..."
	echo
	exit 1
}

# check for essid
if [[ $1 ]]; then
	# setup
	echo "Starting..."
	ifconfig eth1 down
	dhclient -r eth1 -q
	echo " -Previous connection dropped."
	ifconfig eth1 up
	iwconfig eth1 essid "$1"
	echo " -ESSID Set to $1."
	# check for key
	if [[ $2 ]]; then
		iwconfig eth1 key $2
		echo " -Key set to $2."
	fi
	# connect
	iwconfig eth1 mode Managed
	echo " -Connecting..."
	echo
	dhclient eth1
	# announce success
	if [[ $? -eq 0 ]]; then
		echo
		echo "Successfully connected to $1!"
		echo
		exit 0
	fi

else
	# no variables
	usage
fi

# declare failure
die "Failed to connect to $1."

This can serve as a good example of both the commands in connecting to wifi and an introduction to bash scripting. Please comment on the code and offer any suggestions you may have!

A quick Python MySQLdb fix…

Okay, so I enjoy writing code in python a lot more than I ever would in php.  So when I came across the MySQLdb module, I was thrilled.  Now I could do anything that php could do and more, in my opinion.  Well, except php’s python comes with all sort of proctections such as mysql_real_escape()… hmm, what to do now.  Well, better come to a solution.  Here’s that solution in all of it’s glory:

#!/usr/bin/env python
## FILENAME: sql.py

def clean(unclean):
	cleaned = ""
	badchrs = "\\\/\"\'"
	temp    = ""
	for ch in unclean:
		temp = ch
		if temp in badchrs:
			temp = "\\" + temp
		cleaned += temp
	return cleaned

As for usage, just place this with your script (most likely in cgi-bin) and import it:

import sql
name    = sql.clean(form.getvalue('name'))

Obviously, there can be more escapes added but for the initial framework, this is the start of a simple fix! for discussion, what vulnerabilities are in this code? What are other ways to extend the MySQLdb module? Please comment…

Just a starter…

So, to start off, hello and thanks for visiting!  This blog has a purpose to demonstrate code examples that refers primarily to the languages of python, c/c++ and others.  Just a quick introduction, I’m a hobby programmer from Ames, Iowa.  Recently, I’ve attempted to start offering computer services to the local community and have created this site: http://www.skeltonnetworks.com/ which is in it’s intial stages but is functional.  My interests in programming relate mostly to computer security and linux.  For any comments, please feel free to write through either this blog or the contact form on my home page.