Esempio n. 1
0
"""

from understory import mf, web

app = web.application(
    __name__,
    prefix="subscriptions",
    args={"subscription_id": r".+"},
    model={
        "received_subscriptions": {  # others following you
            "received_subscription_id": "TEXT UNIQUE",
            "subscribed": "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
            "topic_url": "TEXT UNIQUE",
            "callback_url": "TEXT",
        },
        "sent_subscriptions": {  # you following others
            "sent_subscription_id": "TEXT UNIQUE",
            "subscribed": "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
            "topic_url": "TEXT UNIQUE",
            "callback_url": "TEXT UNIQUE",
            "verified": "INTEGER NOT NULL",
        },
        "incoming_posts": {"sent_subscription_id": "TEXT", "permalink": "TEXT"},
    },
)

subscription_lease = 60 * 60 * 24 * 90


def publish(hub_url, topic_url, resource):
Esempio n. 2
0
""""""

import lxml
import pkg_resources
import requests
import semver
from understory import web
from understory.web import tx

app = web.application(
    __name__,
    prefix="system",
    model={
        "config": {
            "theme": "INTEGER",
        },
    },
)


@app.wrap
def config_theme(handler, app):
    try:
        tx.host.theme = bool(tx.db.select("config")[0]["theme"])
    except IndexError:
        tx.db.insert("config", theme=True)
        tx.host.theme = True
    yield


def get_versions(package):
Esempio n. 3
0
# TODO https://indieweb.org/Salmention
# TODO https://indieweb.org/Vouch

from understory import web

app = web.application(
    __name__,
    prefix="mentions",
    args={"mention_id": r"\w+"},
    model={
        "received_mentions": {  # others mentioning you
            "mention_id": "TEXT",
            "mentioned": "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
            "source": "TEXT",
            "target": "TEXT",
            "data": "JSON",
        },
        "sent_mentions": {  # you mentioning others
            "mention_id": "TEXT",
            "mentioned": "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
            "source": "TEXT",
            "target": "TEXT",
            "response": "JSON",
        },
    },
)


def receive(source, target) -> None:
    """
    Receive a webmention for `target` on behalf of `source`.
Esempio n. 4
0
""""""

from understory import web
from understory.web import tx

app = web.application(__name__, prefix="search")


@app.control(r"")
class Search:
    """Search locally and globally."""
    def get(self):
        """Return a search box or search results."""
        try:
            query = web.form("q").q
        except web.BadRequest:
            return app.view.search()
        results = tx.cache.search(query)
        return app.view.results(query, results)
Esempio n. 5
0
"""A web app for the site owner."""

from Crypto.Random import random
from understory import host, web

app = web.application(
    __name__,
    prefix="owner",
    model={
        "identities": {
            "created": "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
            "card": "JSON",
        },
        "passphrases": {
            "created": "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
            "passphrase_salt": "BLOB",
            "passphrase_hash": "BLOB",
        },
    },
)


@app.wrap
def connect_model(handler, main_app):
    """Connect the model to this transaction's database."""
    web.tx.identities = app.model(web.tx.db)
    yield


@app.wrap
def wrap(handler, main_app):
Esempio n. 6
0
[0]: https://indieweb.org/Microsub

"""

from understory import web

app = web.application(
    __name__,
    prefix="people",
    args={"nickname": r"[A-Za-z0-9-]+"},
    model={
        "channels": {
            "uid": "TEXT UNIQUE",
            "name": "TEXT UNIQUE",
            "unread": "INTEGER"
        },
        "following": {
            "person_id": "TEXT UNIQUE",
            "url": "TEXT UNIQUE",
            "added": "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
        },
    },
)


@app.wrap
def connect_model(handler, main_app):
    """Connect the model to this transaction's database."""
    web.tx.sub = app.model(web.tx.db)
    yield
Esempio n. 7
0
""""""

from understory import web

app = web.application(
    __name__,
    prefix="providers",
    model={"providers": {
        "service": "TEXT UNIQUE",
        "token": "TEXT UNIQUE"
    }},
)


@app.wrap
def connect_model(handler, main_app):
    """Connect the model to this transaction's database."""
    web.tx.providers = app.model(web.tx.db)
    yield


@app.control("")
class Providers:
    """Manage your third-party service providers."""
    def get(self):
        try:
            host = web.tx.db.select("providers",
                                    where="service = ?",
                                    vals=["digitalocean.com"])[0]
        except IndexError:
            host = None
Esempio n. 8
0
Track your web movement: webpage visits (eg. Liana)

"""

from understory import web

app = web.application(
    __name__,
    prefix="tracker",
    args={"start": r".*"},
    model={
        "locations": {
            "location": "JSON"
        },
        "trips": {
            "start": "DATETIME",
            "distance": "TEXT",
            "location": "JSON"
        },
        "web": {
            "location": "JSON"
        },
    },
)


@app.wrap
def connect_model(handler, main_app):
    """Connect the model to this transaction's database."""
    web.tx.tracker = app.model(web.tx.db)
    yield
Esempio n. 9
0
from understory.web import tx

from ..util import generate_challenge

__all__ = ["app"]

app = web.application(
    __name__,
    prefix="auth",
    args={"client_id": r"[\w/.]+"},
    model={
        "auths": {
            "auth_id": "TEXT",
            "initiated": "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
            "revoked": "DATETIME",
            "code": "TEXT",
            "client_id": "TEXT",
            "client_name": "TEXT",
            "code_challenge": "TEXT",
            "code_challenge_method": "TEXT",
            "redirect_uri": "TEXT",
            "response": "JSON",
            "token": "TEXT",
        },
    },
)

supported_scopes = (
    "create",
    "draft",
    "update",
    "delete",
Esempio n. 10
0
app = web.application(
    __name__,
    prefix="jobs",
    args={
        "job_module": r"[\w.]+",
        "job_object": r"\w+",
        "job_arghash": r"\w+",
        "job_run_id": r"\!+",
    },
    model={
        "job_signatures": {
            "module": "TEXT",
            "object": "TEXT",
            "args": "BLOB",
            "kwargs": "BLOB",
            "arghash": "TEXT",
            "unique": ("module", "object", "arghash"),
        },
        "job_runs": {
            "job_signature_id": "INTEGER",
            "job_id": "TEXT UNIQUE",
            "created": """DATETIME NOT NULL
                          DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW'))""",
            "started": "DATETIME",
            "finished": "DATETIME",
            "start_time": "REAL",
            "run_time": "REAL",
            "status": "INTEGER",
            "output": "TEXT",
        },
        "job_schedules": {
            "job_signature_id":
            "INTEGER",
            "minute":
            "TEXT",
            "hour":
            "TEXT",
            "day_of_month":
            "TEXT",
            "month":
            "TEXT",
            "day_of_week":
            "TEXT",
            "unique": (
                "job_signature_id",
                "minute",
                "hour",
                "day_of_month",
                "month",
                "day_of_week",
            ),
        },
    },
)
Esempio n. 11
0
    machines={
        "name": "TEXT UNIQUE",
        "ip_address": "TEXT UNIQUE",
        "details": "JSON",
    },
    domains={
        "name": "TEXT UNIQUE",
        "nameserver": "TEXT UNIQUE",
        "details": "JSON",
    },
)
app = web.application(
    __name__,
    prefix="sites",
    args={
        "machine": r"\w+",
        "domain_name": r"\w+"
    },
    model=model.schemas,
)


def spawn_machine(name, token):
    """Spin up a VPS and setup a machine."""
    ip_address = host.spawn_machine(name, token)
    tx.db.insert("machines", name=name, ip_address=ip_address, details={})


def build(ip_address, program):
    details = tx.db.select("machines",
                           where="ip_address = ?",