Skip to content

Commit

Permalink
nightly build
Browse files Browse the repository at this point in the history
  • Loading branch information
alienhunter3010 committed Jul 4, 2013
1 parent a6eed37 commit 8548815
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 26 deletions.
2 changes: 1 addition & 1 deletion GPIO/GPIOClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def sendCommand(self, command):
a.update(t)
payload.append(t)
else:
a.update(pma)
a.update(self.pma)
a.update(command)
payload.insert(0, a.digest())
self.service.send('::'.join(payload))
Expand Down
Binary file modified GPIO/GPIOClient.pyc
Binary file not shown.
61 changes: 41 additions & 20 deletions GPIO/GPIODaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
binpath=os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, binpath + '/../lib')

from myGPIO import mnemonic
#from myGPIO import mnemonic
import RPi.GPIO as GPIO
import Daemon

Expand All @@ -23,11 +23,43 @@ class GPIODaemon(Daemon.Daemon):
setupMap = {}
eventsMap = {}
persistence=False
serversocket=False

def init(self):
def reload(self):
# Take it easy and send a client command to the running daemon
# (please remember that resident daemon and service request are two distinct processes!)
import GPIOClient
c = GPIOClient.GPIOClient()
c.sendCommand('system.reload')

def setup(self):
self.config = ConfigParser.ConfigParser()
self.config.read([binpath + '/../etc/GPIO.conf'])

self.tokenMode=not self.config.get('auth', 'token') in ('0', 'False')
if not self.tokenMode:
# Poor Man Secret (copy it on your client script, too!)
self.pma=self.config.get('auth', 'pma')

if self.serversocket:
self.serversocket.shutdown(socket.SHUT_RDWR)
self.serversocket.close()
else: # First run
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
#create an INET, STREAMing socket
self.serversocket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
#bind the socket to a public host,
# and the daemon port
self.serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.serversocket.bind(('', int(self.config.get('common', 'port'))))
#become a server socket, GPIO is ONE, so we accept only 1 connection at a time!
self.serversocket.listen(1)

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

def checkToken(self, token):
#create an INET, STREAMing socket
s = socket.socket(
Expand All @@ -53,42 +85,32 @@ def eventTrigger(self, channel):
print 'Error Triggering event, eventMap entry does not exists!?'

def run(self):
self.tokenMode=not self.config.get('auth', 'token') in ('0', 'False')
if not self.tokenMode:
# Poor Man Secret (copy it on your client script, too!)
self.pma=self.config.get('auth', 'pma')

o=mnemonic()

#create an INET, STREAMing socket
serversocket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
#bind the socket to a public host,
# and the daemon port
serversocket.bind(('', int(self.config.get('common', 'port'))))
#become a server socket, GPIO is ONE, so we accept only 1 connection at a time!
serversocket.listen(1)
self.setup()

while 1:
if not self.persistence:
#accept connections from outside
(clientsocket, address) = serversocket.accept()
(clientsocket, address) = self.serversocket.accept()
#now do something with the clientsocket
(auth, input, token) = clientsocket.recv(4096).split('::')
a = md5.new()
if self.tokenMode:
(auth, input, token) = clientsocket.recv(4096).split('::')
if self.checkToken(token) == False:
clientsocket.send('-4')
continue
a.update(token)
else:
(auth, input) = clientsocket.recv(4096).split('::')
a.update(self.pma)
a.update(input)
if (a.digest() != auth):
clientsocket.send('-4')
continue
if input=='system.quit':
exit()
elif input=='system.reload':
self.setup()
continue
elif input=='system.persistence.on':
self.persistence=True
clientsocket.send('0')
Expand Down Expand Up @@ -196,5 +218,4 @@ def autoSetup(self, port, type):

if __name__ == "__main__":
daemon = GPIODaemon('/tmp/gpiod.pid')
daemon.init()
Daemon.Daemon.manage(daemon)
2 changes: 1 addition & 1 deletion auth/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run(self):
self.activeTokens[r] = time.time()
continue
elif query=='debug':
if config.get('server', 'debug') == '1'
if config.get('server', 'debug') == '1':
print "On stack: %d" % len(self.activeTokens)
continue
(cmd, arg) = query.split(':', 2)
Expand Down
7 changes: 4 additions & 3 deletions etc/GPIO.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[auth]
token:False
token:True
host:localhost
port:9898

pma:SomethingThatYouCanCustomizeAsYouLike
;host:localhost
;port:9898

[common]
port=5050
Expand Down
12 changes: 11 additions & 1 deletion lib/Daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def manage(d):
d.stop()
elif 'restart' == sys.argv[1]:
d.restart()
elif 'reload' == sys.argv[1]:
d.reload()
else:
print "Unknown command"
sys.exit(2)
Expand Down Expand Up @@ -86,7 +88,11 @@ def daemonize(self):
def delpid(self):
if self.enableAtExit:
os.remove(self.pidfile)


def init(self):
# Override me!
return

def start(self):
"""
Start the daemon
Expand All @@ -108,6 +114,10 @@ def start(self):
self.daemonize()
self.run()

def reload(self):
# Override me
return

def stop(self):
"""
Stop the daemon
Expand Down
Binary file modified lib/Daemon.pyc
Binary file not shown.

0 comments on commit 8548815

Please sign in to comment.