Exemplo n.º 1
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    action = ht.get_required(query, 'action')

    conn = db.connect(config.db_path)
    try:
        res = None

        if action == 'database':
            c = db.cursor(conn)
            res = db.read_database(c)
        elif action == 'integrity':
            all_local = ht.convert_bool(ht.get_required(query, 'all_local'), 'all_local')
            c1 = db.cursor(conn)
            c2 = db.cursor(conn)
            res = db.check_integrity(c1, c2, all_local)
        else:
            raise ht.BadFieldResponse('action', action)

        raise ht.ok_json({'status' : 'ok', 'res' : res})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 2
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    to_user_key = ht.get_optional(query, 'to_user_key')
    from_user = ht.get_optional(query, 'from_user')
    from_user_key = ht.get_optional(query, 'from_user_key')
    start_time = ht.convert_int(ht.get_optional(query, 'start_time'), 'start_time')
    end_time = ht.convert_int(ht.get_optional(query, 'end_time'), 'end_time')
    max_records = ht.convert_int(ht.get_optional(query, 'max_records'), 'max_records')
    order = ht.get_optional(query, 'order')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        message_list = db.read_message_list(c, timestamp, node_name, user_id,
                                            to_user_key, from_user, from_user_key,
                                            start_time, end_time, max_records, order,
                                            public_key_hash, signature)

        raise ht.ok_json({'status' : 'ok', 'message_list' : message_list})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 3
0
def delete_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    post_id = ht.get_required(query, 'post_id')
    delete_signature = ht.get_optional(query, 'delete_signature')
    proof_of_work = ht.get_optional(query, 'proof_of_work')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.delete_post(c, timestamp, node_name, group_id, owner_id, post_id, proof_of_work, delete_signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 4
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    group_id = ht.get_required(query, "group_id")
    owner_id = ht.get_required(query, "owner_id")
    key_use = ht.get_required(query, "key_use")
    key_type = ht.get_optional(query, "key_type")
    pub_key = ht.get_optional(query, "pub_key")
    public_key_hash = ht.get_required(query, "public_key_hash")
    signature = ht.get_required(query, "signature")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.change_group_key(
            c, timestamp, node_name, group_id, owner_id, key_use, key_type, pub_key, public_key_hash, signature
        )
        db.commit(conn)

        raise ht.ok_json({"status": "ok"})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 5
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    new_size = ht.convert_int(ht.get_optional(query, 'new_size'), 'new_size')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        
        db.change_max_post_size(c,
                timestamp, node_name, group_id, owner_id, new_size,
                public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 6
0
def delete_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    from_user_key_hash = ht.get_required(query, 'from_user_key_hash')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')
    
    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.delete_message_access(c,
                timestamp, node_name, user_id, from_user_key_hash, public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 7
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    group_id = ht.get_required(query, "group_id")
    owner_id = ht.get_required(query, "owner_id")
    new_size = ht.convert_int(ht.get_required(query, "new_size"), "new_size")
    when_space_exhausted = ht.get_required(query, "when_space_exhausted")

    public_key_hash = ht.get_required(query, "public_key_hash")
    signature = ht.get_required(query, "signature")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.change_group_quota(
            c, timestamp, node_name, group_id, owner_id, new_size, when_space_exhausted, public_key_hash, signature
        )
        db.commit(conn)

        raise ht.ok_json({"status": "ok"})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 8
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    start_time = ht.convert_int(ht.get_optional(query, 'start_time'), 'start_time')
    end_time = ht.convert_int(ht.get_optional(query, 'end_time'), 'end_time')
    max_records = ht.convert_int(ht.get_optional(query, 'max_records'), 'max_records')
    order = ht.get_optional(query, 'order')
    read_signature = ht.get_optional(query, 'read_signature')
    proof_of_work = ht.get_optional(query, 'proof_of_work')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        post_list = db.read_post_list(
                c, timestamp, node_name, group_id, owner_id,
                start_time, end_time, max_records,
                order, read_signature, proof_of_work)

        raise ht.ok_json({'status' : 'ok', 'post_list' : post_list})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 9
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    to_user = ht.get_required(query, "to_user")
    from_user = ht.get_optional(query, "from_user")
    from_user_key_hash = ht.get_optional(query, "from_user_key_hash")
    from_user_key_sig = ht.get_optional(query, "from_user_key_sig")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        max_message_size = db.read_max_message_size(
            c, timestamp, node_name, to_user, from_user, from_user_key_hash, from_user_key_sig
        )

        raise ht.ok_json({"status": "ok", "max_message_size": max_message_size})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 10
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    new_size = ht.convert_int(ht.get_required(query, 'new_size'), 'new_size')
    when_space_exhausted = ht.get_required(query, 'when_space_exhausted')

    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.change_message_quota(c,
                timestamp, node_name, user_id, new_size, when_space_exhausted,
                public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 11
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    post_access = ht.get_required(query, 'post_access')
    read_access = ht.get_required(query, 'read_access')
    delete_access = ht.get_required(query, 'delete_access')
    posting_key_type = ht.get_optional(query, 'posting_key_type')
    posting_pub_key = ht.get_optional(query, 'posting_pub_key')
    reading_key_type = ht.get_optional(query, 'reading_key_type')
    reading_pub_key = ht.get_optional(query, 'reading_pub_key')
    delete_key_type = ht.get_optional(query, 'delete_key_type')
    delete_pub_key = ht.get_optional(query, 'delete_pub_key')
    quota_allocated = ht.convert_int(ht.get_required(query, 'quota_allocated'), 'quota_allocated')
    when_space_exhausted = ht.get_required(query, 'when_space_exhausted')
    max_post_size = ht.convert_int(ht.get_optional(query, 'max_post_size'), 'max_post_size')

    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        row = (timestamp, group_id, owner_id,
               post_access, read_access, delete_access,
               posting_key_type, posting_pub_key,
               reading_key_type, reading_pub_key,
               delete_key_type, delete_pub_key,
               quota_allocated, when_space_exhausted,
               max_post_size)
        db.create_group(c, row, node_name, public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 12
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        user_exists = db.query_user(c, node_name, user_id)

        raise ht.ok_json({'status' : 'ok', 'user_exists' : user_exists})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 13
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        quota_obj = db.read_user_quota(c, timestamp, node_name, user_id, public_key_hash, signature)

        raise ht.ok_json({'status' : 'ok', 'user_quota' : quota_obj})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 14
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    read_signature = ht.get_optional(query, 'read_signature')
    proof_of_work = ht.get_optional(query, 'proof_of_work')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        last_post_time = db.read_last_post_time(c, timestamp, node_name, group_id, owner_id, read_signature, proof_of_work)

        raise ht.ok_json({'status' : 'ok', 'last_post_time' : last_post_time})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 15
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    group_id = ht.get_required(query, "group_id")
    owner_id = ht.get_required(query, "owner_id")
    read_signature = ht.get_optional(query, "read_signature")
    proof_of_work = ht.get_optional(query, "proof_of_work")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        group_quota = db.read_group_quota(c, timestamp, node_name, group_id, owner_id, read_signature, proof_of_work)

        raise ht.ok_json({"status": "ok", "group_quota": group_quota})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 16
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    use = ht.get_required(query, 'use')
    signature = ht.get_optional(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        access = db.read_group_access(c, timestamp, node_name, group_id, owner_id, use, signature)

        raise ht.ok_json({'status' : 'ok', 'access' : access})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 17
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    post_signature = ht.get_required(query, 'post_signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        max_post_size = db.read_max_post_size(c,
                timestamp, node_name, group_id, owner_id, post_signature)

        raise ht.ok_json({'status' : 'ok', 'max_post_size' : max_post_size})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 18
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    key_type = ht.get_required(query, 'key_type')
    public_key = ht.get_required(query, 'public_key')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    revoke_date = ht.convert_int(ht.get_optional(query, 'revoke_date'), 'revoke_date')
    default_message_access = ht.get_required(query, 'default_message_access')
    when_mail_exhausted = ht.get_required(query, 'when_mail_exhausted')
    quota_size = ht.convert_int(ht.get_required(query, 'quota_size'), 'quota_size')
    mail_quota_size = ht.convert_int(ht.get_required(query, 'mail_quota_size'), 'mail_quota_size')
    max_message_size = ht.convert_int(ht.get_optional(query, 'max_message_size'), 'max_message_size')

    # TODO: figure these out
    user_class = ht.get_optional(query, 'user_class')
    auth_token = ht.get_optional(query, 'auth_token')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.create_user(c, node_name,
                       user_id, key_type, public_key, public_key_hash, revoke_date,
                       default_message_access, when_mail_exhausted,
                       db.root_quota_id, quota_size, mail_quota_size,
                       max_message_size)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 19
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    to_user = ht.get_required(query, 'to_user')
    to_user_key_hash = ht.get_optional(query, 'to_user_key_hash')
    from_user = ht.get_optional(query, 'from_user')
    from_user_key_hash = ht.get_optional(query, 'from_user_key_hash')
    message_hash = ht.get_required(query, 'message_hash')

    message = ht.get_required(query, 'message')
    message_id = ht.get_required(query, 'message_id')

    from_signature = ht.get_optional(query, 'from_signature')
    proof_of_work = ht.get_optional(query, 'proof_of_work')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.add_message(c,
                       (message_id, timestamp, 
                        to_user, to_user_key_hash,
                        from_user, from_user_key_hash,
                        message, message_hash,
                        from_signature, proof_of_work, None),
                       node_name)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 20
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    user_id = ht.get_required(query, "user_id")
    new_size = ht.convert_int(ht.get_optional(query, "new_size"), "new_size")
    public_key_hash = ht.get_required(query, "public_key_hash")
    signature = ht.get_required(query, "signature")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.change_max_message_size(c, timestamp, node_name, user_id, new_size, public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({"status": "ok"})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 21
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    to_user = ht.get_required(query, 'to_user')
    from_user = ht.get_required(query, 'from_user')
    from_user_key_hash = ht.get_optional(query, 'from_user_key_hash')
    from_user_key_sig = ht.get_optional(query, 'from_user_key_sig')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        message_access = db.query_message_access(c,
                timestamp, node_name, to_user, from_user, from_user_key_hash, from_user_key_sig)

        raise ht.ok_json({'status' : 'ok', 'message_access' : message_access})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Exemplo n.º 22
0
#!/usr/bin/python
# Run this script as user: www-data

import os
import server_path
import squeakspace.server.db_sqlite3 as db
import config

try:
    os.remove(config.db_path)
except OSError:
    pass

conn = db.connect(config.db_path)
c = db.cursor(conn)
db.make_db(c, config.total_quota)
db.commit(conn)
db.close(conn)