5 print "Content-type: text/json"
12 form = cgi.FieldStorage ()
13 cookies = Cookie.SimpleCookie(os.environ.get("HTTP_COOKIE",""))
16 if not (cookies.has_key("username") and cookies.has_key("pin") and form.has_key("slot")):
17 result = {"result" : "Missing information!"}
19 expr_name = re.compile ("^\w*$")
20 expr_pin = re.compile ("^\d{4}$")
21 expr_slot = re.compile ("^\d$")
22 username = cookies["username"].value.lower ()
23 pin = cookies["pin"].value
24 slot = form["slot"].value
25 if (not expr_name.match (cookies["username"].value)) or (not expr_pin.match (cookies["pin"].value)):
26 result = {"result" : "Incorrect login!"}
28 output = commands.getoutput ("sudo checkpin " + username + " " + pin)
30 result = {"result" : "Authentication failed!"}
32 if not output == "True":
33 result = {"result" : "PIN not set up."}
35 output = commands.getoutput ("dispense -u " + username + " " + slot);
36 expr_disp = re.compile ("^Dispensing a.*")
37 if expr_disp.match (output):
38 return {"result" : "success"}
39 return {"result" : "Dispense failed."}
41 print str(checkdata ())