Example #1
0
def requestImage(data):
    try:
        output = ''

        if (data != ''):
            data = utils.base64Decode(data)

            input = BytesIO(data)
            output = BytesIO()
            image.prepareImage(input, output)

            topic = config.env[config.MQTT_TOPIC_RESPONSE]
            message = json.dumps({
                'type': 'image',
                'value': utils.base64Encode(output.getvalue())
            })
            mqttPublish(topic, message)

            output.seek(0)
            input = output
            output = BytesIO()
            image.rotateImage(input, output)

            output = utils.base64Encode(output.getvalue())

        topic = config.env[config.MQTT_TOPIC_CONTROL]
        message = json.dumps({'type': 'image', 'value': output})
        mqttPublish(topic, message)

    except Exception as exception:
        logger.exception('requestImage: failed to process request: %s',
                         utils.getExceptionMessage(exception))
Example #2
0
def AuthenticationFilter(action, handler):
    keys = sorted(handler.mcontext["parameters"].keys())

    strToSign = "" + action + "\n"
    for param in keys:
        if param == "CredentialId" or param == "Signature":
            continue
        strToSign = strToSign + param + ":" + utils.base64Encode(
            handler.mcontext["parameters"][param]) + "\n"

    strToSign = utils.base64Encode(strToSign)
    credentialIdB64 = handler.mcontext["parameters"]["CredentialId"]
    info = utils.GetInfoFromCredentialId(credentialIdB64)
    secret = storage.QueryUser(info["email"])
    if secret in errors.errors:
        return secret
    secret = secret["Secret"]
    key = utils.GenerateCredentialSecret(credentialIdB64, secret)
    signature = utils.hmacsha256(strToSign, key)
    """
    print info["timeStart"]
    print int(time.time()*1000)
    print info["timeEnd"]
    print signature
    print handler.mcontext["parameters"]["Signature"]
    """
    if info["timeStart"] < int(time.time()*1000) and \
        info["timeEnd"] > int(time.time()*1000) and \
        signature == handler.mcontext["parameters"]["Signature"]:
        handler.mcontext["userInfo"] = info
        return None
    return errors.AccessForbidden
Example #3
0
def contentPhoto(update, context):
    checkUser(context.bot, update.message.from_user)
    updateChatId(update.message.chat.id)

    image = update.message.photo[-1]

    logger.info('image: from: {0}/{1}, image: {2}'.format(
        update.message.from_user.name, update.message.from_user.id,
        image.file_id))

    try:
        imageFile = context.bot.get_file(image.file_id)
        imagePath = config.outputDir + 'image.jpg'
        imageFile.download(imagePath)

        output = BytesIO()
        with open(imagePath, "rb") as image:
            shutil.copyfileobj(image, output)
            output.seek(0)

        topic = config.env[config.MQTT_TOPIC_REQUEST]
        message = json.dumps({
            'type': 'image',
            'value': utils.base64Encode(output.getvalue())
        })
        mqttPublish(topic, message)

        update.message.reply_text('ok')

    except Exception as exception:
        logger.exception('photo: failed to process photo: %s',
                         utils.getExceptionMessage(exception))

        update.message.reply_text('Something went wrong...')
Example #4
0
def build_message(blocks: list):
    msg_bytes = b''
    for block in blocks:
        for row in block:
            for byt in row:
                msg_bytes += byt
    msg_out = utils.base64Encode(msg_bytes)
    return msg_out
Example #5
0
def getDeviceId():
    canvasFingerprint = utils.md5Encode(str(time.time()))
    xl_fp_raw = utils.base64Encode(DEVICE_RAW + canvasFingerprint)
    data = {
        "xl_fp_raw": xl_fp_raw,
        "xl_fp": utils.md5Encode(xl_fp_raw),
        "xl_fp_sign": algorithm.xl_al(xl_fp_raw)
    }
    print(data)
    response = requests.post(DEVICE_REPORT_URL,
                             data=data,
                             headers=DEVICE_HEADERS)
    return response.cookies['deviceid']