Ejemplo n.º 1
0
    def index(self, **kwargs):
        self.authorize()

        if "hardware_id" not in cherrypy.request.params:
            return self.returnError("Missing POST parametr - hardware_id")

        headers = {}
        headers['Content-Type'] = 'application/octet-stream'
        headers['Authorization'] = 'Bearer %s' % self.accessToken
        headers['X-WNS-Type'] = "wns/raw"

        queryResult = globalFunctions.queryApi(
            self.config,
            {"hardware_id": cherrypy.request.params["hardware_id"]},
            self.config.get("API", "GetPushToken"))

        if queryResult["success"] != True or "push_token" not in queryResult:
            return self.returnError(
                "Error in communication with API, response: " +
                str(queryResult))

        pushToken = queryResult["push_token"]

        try:
            req = urllib2.Request(pushToken, "ok", headers)
            result = urllib2.urlopen(req).read()
        except urllib2.HTTPError, err:
            return self.returnError(
                "Windows Service returned with http code %d" % err.code)
Ejemplo n.º 2
0
    def getAndSendPushToken(self, tree, namespace,
                            deviceHardwareIdWithoutPrefix):
        items = tree.findall("./{%s}SyncBody/{%s}Results/{%s}Item/." %
                             (namespace, namespace, namespace))
        pushToken = None
        for item in items:
            locUri = item.find("./{%s}Source/{%s}LocURI/." %
                               (namespace, namespace)).text
            if locUri == TOKEN_URI % self.config.get("Enrollment",
                                                     "ProviderId"):
                pushToken = item.find("./{%s}Data/." % namespace).text
                break

        if pushToken is not None:
            queryResult = globalFunctions.queryApi(
                self.config, {
                    "hardware_id": deviceHardwareIdWithoutPrefix,
                    "push_token": pushToken
                }, self.config.get("API", "AssignPushToken"))
            if queryResult["success"] != True:
                globalFunctions.printDebugLog(
                    self.config, "QUERY API FAILED",
                    self.config.get("API", "AssignPushToken") + " response: " +
                    str(result))
            return queryResult["success"] == True
        globalFunctions.printDebugLog(self.config,
                                      "Error in obtaining Push Token",
                                      "Push Token is None")
        return False
Ejemplo n.º 3
0
 def assignHardwareIdToApi(self, deviceId, deviceHardwareIdWithoutPrefix):
     result = globalFunctions.queryApi(
         self.config, {
             "device_id": deviceId,
             "hardware_id": deviceHardwareIdWithoutPrefix
         }, self.config.get("API", "AssignHardwareId"))
     if not result["success"]:
         globalFunctions.printDebugLog(
             self.config, "QUERY API FAILED",
             self.config.get("API", "AssignHardwareId") + " response: " +
             str(result))
     return result["success"]
Ejemplo n.º 4
0
 def isUnenrollmentRequest(self, tree, namespace,
                           deviceHardwareIdWithoutPrefix):
     alerts = tree.findall("./{%s}SyncBody/{%s}Alert/." %
                           (namespace, namespace))
     if alerts is not None:
         for alert in alerts:
             alertData = alert.find("./{%s}Data/." % namespace)
             if alertData is not None and int(
                     alertData.text) == UNENROLLMENT_CODE:
                 result = globalFunctions.queryApi(
                     self.config,
                     {"hardware_id": deviceHardwareIdWithoutPrefix},
                     self.config.get("API", "UnenrollmentSuccess"))
                 return True
     return False
Ejemplo n.º 5
0
    def index(self, **kwargs):
        if 'Content-Type' not in cherrypy.request.headers:
            return "Error, no content type"

        if cherrypy.request.headers['Content-Type'] == CONTENT_TYPE_SOAP:
            cherrypy.response.headers['Content-Type'] = CONTENT_TYPE_SOAP
            requestBody = cherrypy.request.body.read()
            globalFunctions.printDebugLog(self.config, "ENROLLMENT REQUEST",
                                          requestBody)
            tree = ET.fromstring(requestBody)
            xmlDoc = XmlDoc()
            messageId = tree.find("./{%s}Header/{%s}MessageID/." %
                                  (NAMESPACE_S, NAMESPACE_A)).text
            binarySecurityTokenPem = tree.find(
                "./{%s}Body/{%s}RequestSecurityToken/{%s}BinarySecurityToken/."
                % (NAMESPACE_S, NAMESPACE_WST, NAMESPACE_WSSE)).text
            binarySecurityToken = M2Crypto.X509.load_request_string(
                self.reformatRequestToken(binarySecurityTokenPem))

            usernameToken = tree.find(
                "./{%s}Header/{%s}Security/{%s}UsernameToken/." %
                (NAMESPACE_S, NAMESPACE_WSSE, NAMESPACE_WSSE))
            #username is enrollment token
            username = usernameToken.find("./{%s}Username/." %
                                          NAMESPACE_WSSE).text
            #password is parent pid
            password = usernameToken.find("./{%s}Password/." %
                                          NAMESPACE_WSSE).text

            result = globalFunctions.queryApi(
                self.config, {
                    'token': username,
                    'pin': password
                }, self.config.get("API", "CheckTokenUrl"))
            if result["success"] != True:
                globalFunctions.printDebugLog(
                    self.config, "cannot verify username and token", "")
                return

            deviceId = str(result["device_id"])

            toReturn = self.makeResponse(messageId, binarySecurityToken,
                                         deviceId)
            globalFunctions.printDebugLog(self.config, "ENROLLMENT RESPONSE",
                                          toReturn)
            return toReturn

        return "unsupported request"
Ejemplo n.º 6
0
 def checkApiIfUserShouldUnenroll(self, deviceHardwareIdWithoutPrefix):
     result = globalFunctions.queryApi(
         self.config, {"hardware_id": deviceHardwareIdWithoutPrefix},
         self.config.get("API", "CheckUnenrollment"))
     return result["unenrollment"]