From: Mark Tearle Date: Sat, 8 Nov 2014 14:07:56 +0000 (+0800) Subject: Remove virtualvend due to bitrot. X-Git-Tag: HACK-SLAH-BURN-ENDS^0 X-Git-Url: https://git.ucc.asn.au/?p=uccvend-vendserver.git;a=commitdiff_plain;h=b9a135236fde9954fa83e6fb771bf043f1248fd3 Remove virtualvend due to bitrot. Can always resurrect later. In the interim, use virtualsnack --- diff --git a/virtualvend/vvend.glade b/virtualvend/vvend.glade deleted file mode 100644 index 73fb04e..0000000 --- a/virtualvend/vvend.glade +++ /dev/null @@ -1,591 +0,0 @@ - - - - - - - True - Virtual Vend - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_UTILITY - GDK_GRAVITY_NORTH_WEST - - - - - - True - False - 0 - - - - True - True - False - - - - True - label1 - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 40 - 0 - - - - - 0 - True - True - - - - - - True - 3 - 4 - False - 0 - 0 - - - - True - True - 1 - True - GTK_RELIEF_NORMAL - True - - - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - True - 3 - True - GTK_RELIEF_NORMAL - True - - - - - 2 - 3 - 0 - 1 - fill - - - - - - - True - True - 4 - True - GTK_RELIEF_NORMAL - True - - - - - 3 - 4 - 0 - 1 - fill - - - - - - - True - True - 5 - True - GTK_RELIEF_NORMAL - True - - - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - True - 6 - True - GTK_RELIEF_NORMAL - True - - - - - 1 - 2 - 1 - 2 - fill - - - - - - - True - True - 7 - True - GTK_RELIEF_NORMAL - True - - - - - 2 - 3 - 1 - 2 - fill - - - - - - - True - True - 8 - True - GTK_RELIEF_NORMAL - True - - - - - 3 - 4 - 1 - 2 - fill - - - - - - - True - True - RESET - True - GTK_RELIEF_NORMAL - True - - - - - - 2 - 4 - 2 - 3 - - - - - - - True - True - 0 - True - GTK_RELIEF_NORMAL - True - - - - - 1 - 2 - 2 - 3 - - - - - - - True - True - 9 - True - GTK_RELIEF_NORMAL - True - - - - - 0 - 1 - 2 - 3 - - - - - - - True - True - 2 - True - GTK_RELIEF_NORMAL - True - - - - - 1 - 2 - 0 - 1 - fill - - - - - - 0 - True - True - - - - - - True - False - 0 - - - - True - True - 0.05 - True - GTK_RELIEF_NORMAL - True - - - - 0 - True - True - - - - - - True - True - 0.10 - True - GTK_RELIEF_NORMAL - True - - - - 0 - True - True - - - - - - True - True - 0.25 - True - GTK_RELIEF_NORMAL - True - - - - 0 - True - True - - - - - - True - True - $1 - True - GTK_RELIEF_NORMAL - True - - - - 0 - True - True - - - - - - True - True - MODE - True - GTK_RELIEF_NORMAL - True - - - - 0 - True - True - - - - - 0 - True - True - - - - - - True - False - 0 - - - - True - True - DIP1 - True - GTK_RELIEF_NORMAL - True - False - False - - - 0 - True - True - - - - - - True - True - DIP2 - True - GTK_RELIEF_NORMAL - True - False - False - - - 0 - True - True - - - - - - True - True - DIP3 - True - GTK_RELIEF_NORMAL - True - False - False - - - 0 - True - True - - - - - - True - True - DIP4 - True - GTK_RELIEF_NORMAL - True - False - False - - - 0 - True - True - - - - - - True - True - DIP5 - True - GTK_RELIEF_NORMAL - True - False - False - - - 0 - True - True - - - - - - True - True - DIP6 - True - GTK_RELIEF_NORMAL - True - False - False - - - 0 - True - True - - - - - - True - True - DIP7 - True - GTK_RELIEF_NORMAL - True - False - False - - - 0 - True - True - - - - - - True - True - DIP8 - True - GTK_RELIEF_NORMAL - True - False - False - - - 0 - True - True - - - - - 0 - True - True - - - - - - True - True - DOOR - True - GTK_RELIEF_NORMAL - True - True - False - - - - 0 - False - False - - - - - - True - True - - - 0 - False - False - - - - - - - diff --git a/virtualvend/vvend.py b/virtualvend/vvend.py deleted file mode 100644 index eff3205..0000000 --- a/virtualvend/vvend.py +++ /dev/null @@ -1,347 +0,0 @@ -#!/usr/bin/env python - -import sys -import socket -import string - -try: - import pygtk - #tell pyGTK, if possible, that we want GTKv2 - pygtk.require("2.0") -except: - #Some distributions come with GTK2, but not pyGTK - pass - -try: - import gtk - import gtk.glade -except: - print "You need to install pyGTK or GTKv2 ", - print "or set your PYTHONPATH correctly." - print "try: export PYTHONPATH=", - print "/usr/local/lib/python2.2/site-packages/" - sys.exit(1) - -import pango - -class Switches: - def __init__(self): - self.misc_input = 0xff - self.switch_input = 0x3f - def door_open(self): - return self.switch_input & 0x20 - def set_door_open(self, open = True): - if open: - self.switch_input |= 0x20 - else: - self.switch_input &= ~0x20 - -#now we have both gtk and gtk.glade imported -#Also, we know we are running GTK v2 - -class appgui: - def __init__(self): - """ - In this init we are going to display the main - serverinfo window - """ - gladefile="vvend.glade" - windowname="vvend" - self.wTree=gtk.glade.XML (gladefile,windowname) - # we only have two callbacks to register, but - # you could register any number, or use a - # special class that automatically - # registers all callbacks. If you wanted to pass - # an argument, you would use a tuple like this: - # dic = { "on button1_clicked" : - # (self.button1_clicked, arg1,arg2) , ... - - dic = { - "on_button1_clicked" : self.keypad_clicked, - "on_button2_clicked" : self.keypad_clicked, - "on_button3_clicked" : self.keypad_clicked, - "on_button4_clicked" : self.keypad_clicked, - "on_button5_clicked" : self.keypad_clicked, - "on_button6_clicked" : self.keypad_clicked, - "on_button7_clicked" : self.keypad_clicked, - "on_button8_clicked" : self.keypad_clicked, - "on_button9_clicked" : self.keypad_clicked, - "on_button10_clicked" : self.keypad_clicked, - "on_button11_clicked" : self.keypad_clicked, - "on_button11_clicked" : self.keypad_clicked, - "on_door_toggled" : self.door_changed, - "on_vvend_destroy_event" : self.quit, - "on_vvend_delete_event" : self.quit } - self.wTree.signal_autoconnect (dic) - display = self.wTree.get_widget("label1") - label_font = pango.FontDescription('monospace 28') - display.modify_font(label_font) - - label_style = display.get_style().copy() - fg_color = display.get_colormap().alloc_color('lightgreen') - label_style.fg[gtk.STATE_NORMAL] = fg_color - display.set_style(label_style) - - w = self.wTree.get_widget("eventbox1") - wstyle = w.get_style().copy() - bg_color = w.get_colormap().alloc_color('black') - wstyle.bg[gtk.STATE_NORMAL] = bg_color - w.set_style(wstyle) - - display.set_text("*5N4CK0RZ*") - - # vending machine password set here - self.vendpw = "AAAAAAAAAAAAAAAA" - - self.messageid = None - self.switches = Switches() - - #s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - #s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) -# -# listenhost="" -# listenport=5150 -# s.bind((listenhost, listenport)) -# # only one connection -# s.listen(1) -# s.setblocking(1) -# #GDK->gtk.gdk in GTK V 2.0 -# id=gtk.input_add(s, gtk.gdk.INPUT_READ, self.handleNewConnection) - - self.server() - - - return - - def __del__(self): - try: - self.sock.close() - self.sock.shutdown() - except: - pass - -#####CALLBACKS - def keypad_clicked(self,widget): - key = widget.get_label() - if key == 'RESET': - key = '11' - else: - key = '0'+key - self.do_send('2'+key+' keypress\n') - - def door_changed(self, widget): - self.switches.set_door_open(not widget.get_active()) - if widget.get_active(): - self.do_send('401 door closed\n') - else: - self.do_send('400 door open\n') - - def handleNewConnection(self,source,condition): - #source is a socket in GTK v 1 and a fd in version 2 - conn, addr = source.accept() - sys.stdout.write(conn.recv(1)) - conn.send("bing\n") - return gtk.TRUE - -# from http://www.pythonbrasil.com.br/moin.cgi/MonitorandoSocketsComPygtk - - - def send(self, data=None, widget=None): - text = self.entry.get_text() - self.do_send(text) - self.entry.set_text('') - - # - - def do_send(self, data): - - # envia ''data'' para todos os clientes conectados - - for addr, (conn, tag) in self.clients.iteritems(): - conn.send(data) - - def server(self): - - # inicializa o servidor - port = 5150 - - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.sock.bind(('localhost', port)) - self.sock.listen(0) - print "listening on ", port - - # - # - - self.server_tag = gtk.input_add(self.sock, gtk.gdk.INPUT_READ, self.accept) - - # mantemos uma lista dos clientes conectados - - self.clients = {} - - def accept(self, source, condition): - - # - # esperando para ser aceito - - conn, addr = source.accept() - self.insert("%s:%s conectado\n" % addr) - - # insere o cliente na lista e registra o método self.write como - # callback para quando existirem dados esperando para serem lidos - - self.do_prompt() - self.clients[addr] = (conn, gtk.input_add(conn, gtk.gdk.INPUT_READ, self.write)) - - def write(self, source, condition): - - # método chamado quando um cliente envia dados - - data = source.recv(1024) - if data.strip() == 'bye' or not len(data): - - # se o cliente enviar um ''bye'', desconecte-o :) - - source.close() - for addr, (conn, tag) in self.clients.iteritems(): - if source is conn: - gtk.input_remove(tag) - self.insert('%s:%s desconectado\n' % addr) - del self.clients[addr] - - self.server_tag = gtk.input_add(self.sock, gtk.gdk.INPUT_READ, self.accept) - break - elif data.strip() == 'quit': - self.quit() - else: - for (addr, port), (conn, tag) in self.clients.iteritems(): - if source is conn: - self.insert('%s:%s >>> %s\n'%(addr, port, data.strip())) - self.handle_command(data.strip()) - break - - return gtk.TRUE - - def insert(self, data): - statusbar = self.wTree.get_widget("statusbar1") - if self.messageid: - statusbar.remove(1, self.messageid) - self.messageid=statusbar.push(1,data) - - def quit(self, *args): - sys.stdout.write("quiting...\n") - gtk.input_remove(self.server_tag) - for addr, (conn, tag) in self.clients.iteritems(): - gtk.input_remove(tag) - conn.close() - self.sock.close() - self.sock.shutdown() - - gtk.mainquit() - sys.stdout.write("quit!\n") - - def do_prompt(self): - self.do_send("# ") - - def do_help(self): - help = """ - -Valid commands are: - ABOUT ROM information - B[S][nn] beep [synchronously] for a duration nn (optional) - C[S][nn] silence [synchronously] for a duration nn (optional) - Dxxxxxxxxxx show a message on the display - ECHO {ON|OFF} turn echo on or off - GETROM download the ROM source code using xmodem - H[...] this help screen -*JUMPxxxx jumps to a subroutine at location xxxx -*PEEKxxxx returns the value of the byte at location xxxx -*POKExxxxyy sets the value of location xxxx to yy - PING pongs - S[...] query all internal switch states -+Vnn vend an item -+VALL vend all items -*Wxxxxxxxxxxxx set a new password for authenticated vends. xxx=16 chars - password will be converted to uppercase - -Very few functions are available when the machine is in standalone -mode (DIP SW 1 is set) -+ denotes that this item requires authentication if DIP SW 2 is set -* denotes that DIP SW 3 must be set to use these -Commands starting with # are ignored (comments) -""" - self.do_send(help) - - def do_about(self): - about = """ - -The Virtual Vending Machine Company - -Mark Tearle, June 2004 -""" - self.do_send(about) - - def do_vend_all(self): - for i in range(11,99): - self.do_send("101 Vending "+str(i)+"\n") - self.do_send("153 Home sensors failing\n") - self.do_send("102 Vend all motors complete\n") - - def do_vend(self,command): - fail = None - if fail: - self.do_send("153 Home sensors failing\n") - else: - self.insert("Vending "+command) - self.do_send("100 Vend successful\n") - - def do_display(self,string): - display = self.wTree.get_widget("label1") - display.set_text("%-10.10s" % (string)) - self.do_send('300 Written\n') - - def do_beep(self,command): - sys.stdout.write("\a") - self.do_send('500 Beeped\n') - - def do_silence(self,command): - pass - - def do_switches(self): - self.do_send("600 3F 3F\n") - - def do_pong(self): - self.do_send("000 PONG!\n") - - def handle_command(self, command): - command = string.upper(command) - print command - if string.find(command, "HELP",0) == 0: - self.do_help() - elif string.find(command, "ABOUT",0) == 0: - self.do_about() - elif string.find(command, "PING",0) == 0: - self.do_pong() - elif string.find(command, "VALL",0) == 0: - self.do_vend_all() - elif string.find(command, "V",0) == 0: - self.do_vend(command) - elif string.find(command, "B",0) == 0: - self.do_beep(command) - elif string.find(command, "C",0) == 0: - self.do_silence(command) - elif string.find(command, "S",0) == 0: - self.do_switches() - elif string.find(command, "D",0) == 0: - self.do_display(command[1:]) - self.do_prompt() - - -# we start the app like this... -app=appgui() -gtk.main() - - -# notes -# http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq20.011.htp