#!/usr/bin/env python # TODO: better way to refresh rc.fire (setuid C program is a hack!) # TODO: better way to deal with redirect? import cgi import cgitb import os import sys import time import string import ssh mac_file = "/tmp/known_macs" refresh_cmd = "/usr/local/bin/fw_refresh" host = 'stargate.cs.usfca.edu' html = """ Network Registration Thank you. You will be re-directed automatically back to our web site. Or you can just click here.

""" sys.stderr = sys.stdout cgitb.enable() form = cgi.FieldStorage() print "Content-Type: text/html" print print html #cgi.print_environ() #print "Username: ", form["user"].value, "
" #print "Password: ", form["pass"].value, "
" if not form.has_key("user") or not form.has_key("pass"): print 'ERROR: You must enter your username and your password.

' print '' sys.exit(1) # verify username and password if not ssh.verify_account(form["user"].value, form["pass"].value, host): print 'ERROR: Verification failed. Try again.

' print '' sys.exit(1) ipaddr = os.environ["REMOTE_ADDR"] browser = os.environ["HTTP_USER_AGENT"] command = "arp -n | grep " + ipaddr + " | awk '{ print $3 }'" f = os.popen(command) output = f.readlines() f.close() f = open(mac_file, 'r') macs = [string.strip(l) for l in f.readlines()] f.close() macs = [string.split(m, "\t")[0] for m in macs] hash = {} for m in macs: hash[m] = 1 if not output: print "You are not on the local subnet, stupid. Why are you here?
" else: hwaddr = string.strip(output[0]) result = hwaddr + "\t# " + ipaddr + " " + form["user"].value + " " +\ browser + time.strftime(' [%d/%b/%Y %X]') if hash.has_key(hwaddr): print "This device is already registered.
" else: f = open(mac_file, 'a') print >> f, result f.close() os.system(refresh_cmd) print "All done. You do NOT need to reboot your computer.
" print ""