Skip to content

Commit

Permalink
Merge pull request #3 from thrasr/master
Browse files Browse the repository at this point in the history
Thrasher pull request with new web frontend and major changes to server.
  • Loading branch information
gavin-black committed May 20, 2014
2 parents ae8cb54 + 1aa287c commit ac123b6
Show file tree
Hide file tree
Showing 20 changed files with 9,031 additions and 153 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ You must have the following installed on the server:
* Recommend downloading and compiling yourself
* Some Debian-based distros disable features needed by M2Crypto
* Source available at [http://www.openssl.org/source/](http://www.openssl.org/source/)
* Python, with the following libraries
* Python 2.7, with the following libraries
* [web.py](http://webpy.org/)
* [M2Crypto](http://chandlerproject.org/bin/view/Projects/MeTooCrypto)
* [PyOpenSSL](https://pypi.python.org/pypi/pyOpenSSL)

Network Settings
* Outbound access to gateway.push.apple.com:2195
Expand Down
3 changes: 2 additions & 1 deletion server/README
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ whitepaper elsewhere in this repository.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

software:
* python
* python 2.7
* python libraries:
* web.py: http://webpy.org/
* M2Crypto: http://chandlerproject.org/bin/view/Projects/MeTooCrypto
* PyOpenSSL: https://pypi.python.org/pypi/pyOpenSSL
* OpenSSL (to create certs)
* Iphone Configuration Utility (free from Apple)

Expand Down
1 change: 0 additions & 1 deletion server/creds.py

This file was deleted.

115 changes: 115 additions & 0 deletions server/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from collections import deque
from plistlib import *
from operator import itemgetter

class device:
def __init__(self, newUDID, tuple):
self.UDID = newUDID
self.IP = tuple[0]
self.pushMagic = tuple[1]
self.deviceToken = tuple[2]
self.unlockToken = tuple[3]

# Hard coded information to show possible feature
self.GEO = "42*21'29''N 71*03'49''W"
self.owner = 'John Snow'
self.location = 'Winterfell'
self.status = 0# 0=ready for command (green? gray?)
# 1=command in queue (yellow)
# 2=error/timeout (red)
# maybe have green (last command successful?)


# Possible additional parameters
#self.availableCapacity
#self.totalCapacity
#self.installedApps

self.name = ''
self.model = ''
self.OS = ''

# Dictionary to hold commands and responses that HAVE been sent
# Keys are Command UUID, value is an array [command, response]
# Possibly change to {'command', 'response', 'result', 'order'}
self.cmdList = {}

# Queue to hold commands that HAVE NOT been sent
self.queue = deque()


def getUDID(self):
return self.UDID

def getQueueInfo(self):
# Returns information needed by queue function
return self.pushMagic, self.deviceToken

def getResponse(self, cmdUUID):
return self.cmdList[cmdUUID]['response']

def populate(self):
# Returns info as a dictionary for use as JSON with mustache
d = {}
d['UDID'] = self.UDID
d['name'] = self.name
d['ip'] = self.IP
d['owner'] = self.owner
d['location'] = self.location
d['geo'] = self.GEO
d['status'] = ['success', 'warning', 'danger'][self.status]
#d['icon'] = ['ok', 'refresh', 'remove'][self.status] # possible glyphicon functionality

d['commands'] = []
for key in self.cmdList:
d['commands'].append(self.cmdList[key])

return d

def customInfo(self, newOwner, newLocation, newName):
pass

def updateInfo(self, newName, newModel, newOS):
# Update class variables with data from DeviceInformation
self.name = newName
self.model = newModel
self.OS = newOS

def reenroll(self, newIP, newPush, newUnlock):
self.IP = newIP
self.pushMagic = newPush
self.unlockToken = newUnlock

def addCommand(self, cmd):
# Add a new command to the queue

# Update command with unlockToken if necessary
if cmd['Command']['RequestType'] == 'ClearPasscode':
cmd['Command']['UnlockToken'] = Data(self.unlockToken)

print "ADDED COMMAND TO QUEUE:", cmd['CommandUUID']
self.queue.append(cmd)

def sendCommand(self):
# Pop command off queue to be sent to the device
if len(self.queue) == 0:
print "**No commands left in queue"
return ''

cmd = self.queue.popleft()
self.cmdList[cmd['CommandUUID']] = {}
self.cmdList[cmd['CommandUUID']]['cmd'] = cmd
self.cmdList[cmd['CommandUUID']]['response'] = ''
self.cmdList[cmd['CommandUUID']]['status'] = 'warning'
self.cmdList[cmd['CommandUUID']]['order'] = len(self.cmdList.keys())
print "**Sending command", cmd['CommandUUID'], "and moving it from queue**"
return cmd


def addResponse(self, cmdUUID, response):
# Add a response to correspond with a previous command
print "**ADDING RESPONSE TO CMD:", cmdUUID
print self.cmdList.keys()
self.cmdList[cmdUUID]['response'] = response
# Check response to see if error? if so, status=3
self.cmdList[cmdUUID]['status'] = 'success'
Loading

0 comments on commit ac123b6

Please sign in to comment.