Doorboy proxy exports door access information from MongoDB to door Raspberry Pi controllers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.1 KiB

from datetime import datetime
from flask import Flask, request, redirect, render_template, Blueprint, make_response, jsonify
from pymongo import MongoClient
import flask
import hashlib
import jinja2
import json
import os
import pymongo
import smtplib
app = Flask(__name__)
mongodb = MongoClient('mongodb://,,', replicaSet="kspace-mongo-set").kspace_accounting
mongodb.authenticate("kspace_accounting", os.environ["MONGO_PASSWORD"])
assert len(DOORBOY_SECRET) > 10
def view_doorboy_uids():
if request.headers.get('KEY') != DOORBOY_SECRET:
return "how about no"
allowed_names = [o["_id"] for o in mongodb.member.find({"enabled": True})]
allowed_uids = []
for obj in mongodb.inventory.find({"token.uid_hash": {"$exists":True}, "inventory.owner_id": {"$exists":True}, "token.enabled": True}, {"inventory.owner_id": True, "token.uid_hash": True }):
if obj["inventory"].pop("owner_id") in allowed_names:
return jsonify(allowed_uids=allowed_uids)
def view_longpoll():
if request.headers.get('KEY') != DOORBOY_SECRET:
return "how about no"
def g():
yield "data: response-generator-started\n\n"
pipeline = [
'$match': {
'operationType': "insert",
# 'component': 'doorboy',
# 'type': 'open-door'
with as stream:
yield "data: watch-stream-opened\n\n"
for event in stream:
if event["fullDocument"].get("type") == "open-door":
yield "data: %s\n\n" % event["fullDocument"]["door"]
except pymongo.errors.PyMongoError:
return "urror"
return flask.Response(g(),
if __name__ == '__main__':, host='::')