def postflight(self, runtype=None, mac=None, name=None, serial=None, manifest=None, base64bz2report=None): """Log postflight.""" # Decode report # FIXME: there has to be a better way to submit a binary blob try: base64bz2report = base64bz2report.replace(" ", "+") bz2report = base64.b64decode(base64bz2report) report = bz2.decompress(bz2report) except BaseException as e: print "Can't decode report from %s (%s): %s" % (request.environ['REMOTE_ADDR'], mac, str(e)) abort(403) # Parse plist with plistlib, as Objective-C objects can't be pickled. try: plist = plistlib.readPlistFromString(report) except BaseException as e: print "Received invalid plist from %s (%s): %s" % (request.environ['REMOTE_ADDR'], mac, str(e)) abort(403) #plist, format, error = \ # NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_( # buffer(report), # NSPropertyListMutableContainers, # None, # None # ) #if error: # print "error:", error # abort(401) # Create client if needed. client = Client.by_serial(serial) if not client: print "postflight running without preflight for %s" % mac client = Client() client.serial = serial DBSession.add(client) # Update client attributes. client.runtype = runtype if name: client.name = name else: client.name = "<NO NAME>" # Get manifest id from plist client.mac = mac client.manifest = manifest client.runstate = u"done" client.timestamp = datetime.now() client.remote_ip = unicode(request.environ['REMOTE_ADDR']) # Save report, updating activity, errors, warnings, and console_user. client.update_report(plist) DBSession.flush() return "postflight logged for %s\n" % name
def report_broken_client(self, runtype=None, mac=None, name=None): """Log report_broken_client.""" client = Client.by_mac(mac) if not client: client = Client() client.mac = mac DBSession.add(client) client.runtype = runtype client.name = name client.runstate = u"broken client" client.timestamp = datetime.now() client.remote_ip = unicode(request.environ['REMOTE_ADDR']) client.report_plist = None client.errors = 1 client.warnings = 0 DBSession.flush() return "report_broken_client logged for %s\n" % name
def preflight(self, runtype=None, mac=None, name=None): """Log preflight.""" client = Client.by_mac(mac) if not client: client = Client() client.mac = mac DBSession.add(client) client.runtype = runtype if name: client.name = name else: client.name = "<NO NAME>" client.runstate = u"in progress" client.timestamp = datetime.now() client.remote_ip = unicode(request.environ['REMOTE_ADDR']) client.activity = {"Updating": "preflight"} DBSession.flush() return "preflight logged for %s\n" % name