-
-def scroll_options(username, mk, welcome = False):
- if welcome:
- # Balance checking
- acct, unused = Popen(['dispense', 'acct', username], close_fds=True, stdout=PIPE).communicate()
- # this is fucking appalling
- balance = acct[acct.find("$")+1:acct.find("(")].strip()
-
- msg = [(center('WELCOME'), False, TEXT_SPEED),
- (center(username), False, TEXT_SPEED),
- (center(balance), False, TEXT_SPEED),]
- else:
- msg = []
- choices = ' '*10+'CHOICES: '
-
- # Get coke contents
- cokes = []
- for i in range(0, 7):
- args = ('dispense', 'iteminfo', 'coke:%i' % i)
- info, unused = Popen(args, close_fds=True, stdout=PIPE).communicate()
- m = re.match("\s*[a-z]+:\d+\s+(\d+)\.(\d\d)\s+([^\n]+)", info)
- cents = int(m.group(1))*100 + int(m.group(2))
- cokes.append('%i %i %s' % (i, cents, m.group(3)));
-
- for c in cokes:
- c = c.strip()
- (slot_num, price, slot_name) = c.split(' ', 2)
- if slot_name == 'dead': continue
- choices += '%s-(%sc)-%s8 '%(slot_name, price, slot_num)
-
-# we don't want to print snacks for now since it'll be too large
-# and there's physical bits of paper in the machine anyway - matt
-# try:
-# snacks = get_snacks()
-# except:
-# snacks = {}
-#
-# for slot, ( name, price ) in snacks.items():
-# choices += '%s8-%s (%sc) ' % ( slot, name, price )
-
- choices += '55-DOOR '
- choices += 'OR ANOTHER SNACK. '
- choices += '99 TO READ AGAIN. '
- choices += 'CHOICE? '
- msg.append((choices, False, None))
- mk.set_messages(msg)
-
-_pin_uid = 0
-_pin_uname = 'root'
-_pin_pin = '----'
-
-def _check_pin(uid, pin):
- global _pin_uid
- global _pin_uname
- global _pin_pin
- print "_check_pin('",uid,"',---)"
- if uid != _pin_uid:
- try:
- info = pwd.getpwuid(uid)
- except KeyError:
- logging.info('getting pin for uid %d: user not in password file'%uid)
- return None
- if info.pw_dir == None: return False
- pinfile = os.path.join(info.pw_dir, '.pin')
- try:
- s = os.stat(pinfile)
- except OSError:
- logging.info('getting pin for uid %d: .pin not found in home directory'%uid)
- return None
- if s.st_mode & 077:
- logging.info('getting pin for uid %d: .pin has wrong permissions. Fixing.'%uid)
- os.chmod(pinfile, 0600)
- try:
- f = file(pinfile)
- except IOError:
- logging.info('getting pin for uid %d: I cannot read pin file'%uid)
- return None
- pinstr = f.readline()
- f.close()
- if not re.search('^'+'[0-9]'*PIN_LENGTH+'$', pinstr):
- logging.info('getting pin for uid %d: %s not a good pin'%(uid,repr(pinstr)))
- return None
- _pin_uid = uid
- _pin_pin = pinstr
- _pin_uname = info.pw_name
- else:
- pinstr = _pin_pin
- if pin == int(pinstr):
- logging.info("Pin correct for %d",uid)
- else:
- logging.info("Pin incorrect for %d",uid)
- return pin == int(pinstr)
-
-def acct_is_disabled(name=None):
- global _pin_uname
- if name == None:
- name = _pin_uname
- acct, unused = Popen(['dispense', 'acct', _pin_uname], close_fds=True, stdout=PIPE).communicate()
- # this is fucking appalling
- flags = acct[acct.find("(")+1:acct.find(")")].strip()
- if 'disabled' in flags:
- return True
- if 'internal' in flags:
- return True
- return False
-
-def has_good_pin(uid):
- return _check_pin(uid, None) != None
-
-def verify_user_pin(uid, pin, skip_pin_check=False):
- if skip_pin_check or _check_pin(uid, pin) == True:
- info = pwd.getpwuid(uid)
- if skip_pin_check:
- if acct_is_disabled(info.pw_name):
- logging.info('refused mifare for disabled acct uid %d (%s)'%(uid,info.pw_name))
- return '-disabled-'
- logging.info('accepted mifare for uid %d (%s)'%(uid,info.pw_name))
- else:
- logging.info('accepted pin for uid %d (%s)'%(uid,info.pw_name))
- return info.pw_name
- else:
- logging.info('refused pin for uid %d'%(uid))
- return None
-
-
-def cookie(v):
- seed(time())
- messages = [' WASSUP! ', 'PINK FISH ', ' SECRETS ', ' ESKIMO ', ' FORTUNES ', 'MORE MONEY']
- choice = int(random()*len(messages))
- msg = messages[choice]
- left = range(len(msg))
- for i in range(len(msg)):
- if msg[i] == ' ': left.remove(i)
- reveal = 1
- while left:
- s = ''
- for i in range(0, len(msg)):
- if i in left:
- if reveal == 0:
- left.remove(i)
- s += msg[i]
- else:
- s += chr(int(random()*26)+ord('A'))
- reveal += 1
- reveal %= 17
- else:
- s += msg[i]
- v.display(s)
-
-def center(str):
- LEN = 10
- return ' '*((LEN-len(str))/2)+str
-
-
-
-idlers = []
-idler = None
-
-def setup_idlers(v):
- global idlers, idler
- idlers = [
- GrayIdler(v),
- StringIdler(v, text="Kill 'em all", repeat=False),
- GrayIdler(v,one="*",zero="-"),
- StringIdler(v, text=CREDITS),
- GrayIdler(v,one="/",zero="\\"),
- ClockIdler(v),
- GrayIdler(v,one="X",zero="O"),
- FileIdler(v, '/usr/share/common-licenses/GPL-2',affinity=2),
- GrayIdler(v,one="*",zero="-",reorder=1),
- StringIdler(v, text=str(math.pi) + " "),
- ClockIdler(v),
- GrayIdler(v,one="/",zero="\\",reorder=1),
- StringIdler(v, text=str(math.e) + " "),
- GrayIdler(v,one="X",zero="O",reorder=1),
- StringIdler(v, text=" I want some pizza - please call Pizza Hut Shenton Park on +61 8 9381 9979 [now closed? - MSH] - and order as Quinn - I am getting really hungry", repeat=False),
- PipeIdler(v, "/usr/bin/getent", "passwd"),
- FortuneIdler(v),
- ClockIdler(v),
- StringIdler(v),
- TrainIdler(v),
- # "Hello World" in brainfuck
- StringIdler(v, text=">+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++."),
- ]
- disabled = [
- ]
-
-def reset_idler(v, vstatus, t = None):
- global idlers, idler
- idler = GreetingIdler(v, t)
- vstatus.time_of_next_idlestep = time()+idler.next()
- vstatus.time_of_next_idler = None
- vstatus.time_to_autologout = None
- vstatus.change_state(STATE_IDLE, 1)
-
-def choose_idler():
- global idlers, idler
- iiindex = 0
- average_affinity = 10 # guessing here...
-
- if idler and idler.__class__ != GreetingIdler:
- iiindex = idlers.index(idler)
-
- iilen = len(idlers)
-
- move = int(random()*len(idlers)*average_affinity) + 1
-
- while move >= 0:
- iiindex += 1
- iiindex %= iilen
- idler = idlers[iiindex]
- move -= idler.affinity()
-
- idler.reset()
-
-def idle_step(vstatus):
- global idler
- if idler.finished():
- choose_idler()
- vstatus.time_of_next_idler = time() + 30
- nextidle = idler.next()
- if nextidle is None:
- nextidle = IDLE_SPEED
- vstatus.time_of_next_idlestep = time()+nextidle
-