Esempio n. 1
0
 def do_getcerts(self, inp):
     '''Get certs'''
     t = Texttable()
     for cert in session.query(CERT).all():
         t.add_rows([['ID', 'Desc', 'CommonName', 'CA-ID'],
                     str(cert).split(", ")])
     print(t.draw())
Esempio n. 2
0
 def _print_cas(self):
     '''Print existing CAs'''
     t = Texttable()
     ca_list = session.query(CA).all()
     for ca in ca_list:
         t.add_rows([['ID', 'Desc', 'CommonName'], str(ca).split(", ")])
     print(t.draw())
     return len(ca_list)
Esempio n. 3
0
def studiji():
    studiji = session.query(Studiji).all()
    return jsonify([{
        "id": studij.id,
        "naziv": studij.naziv,
        "godina": studij.godina,
        "url": studij.url
    } for studij in studiji])
Esempio n. 4
0
 def _print_certs(self):
     '''Print existing certs'''
     t = Texttable()
     cert_list = session.query(CERT).all()
     for cert in cert_list:
         t.add_rows([['ID', 'Desc', 'CommonName', 'CA-ID'],
                     str(cert).split(", ")])
     print(t.draw())
     return len(cert_list)
Esempio n. 5
0
def termini(studij_id):
    termini = session.query(Termin).filter_by(studiji_id=studij_id).all()
    return jsonify([{
        "id": termin.id,
        "naslov": termin.title,
        "datum": termin.date,
        "trajanje": termin.duration,
        "pocetak": termin.startTime
    } for termin in termini])
Esempio n. 6
0
def exists(user: User, post: Post) -> bool:
    """
    Checks whether a post exists for a given user

    :param user: the user
    :param post: the post
    :return: True if the post exists, False if not
    """
    db_post = session.query(DBPost).get(
        (user.id, post.post_id, post.board_url.short_url))

    return db_post is not None
Esempio n. 7
0
    def do_getcertsforca(self, inp):
        '''Get all certs for an ca'''
        # Print existing CAs
        self._print_cas()

        # Let the user select the CA
        ca_id = input("Choose an CA by ID: ")

        # Print all CERTs for CA
        t = Texttable()
        for cert in session.query(CERT).filter(CERT.ca_id == ca_id).all():
            t.add_rows([['ID', 'Desc', 'CommonName', 'CA-ID'],
                        str(cert).split(", ")])
        print(t.draw())
Esempio n. 8
0
    def do_exportca(self, inp):
        '''Export an key or cert of the ca'''
        num_cas = self._print_cas()
        ca_id = self._get_san_input_int("Choose an CA to export: ", num_cas)
        ca = session.query(CA).filter(CA.id == ca_id).one()

        # Ask user what to export
        t = Texttable()
        t.add_rows([['ID', 'Target'], ['1', 'private key (PEM)'],
                    ['2', 'certificate (CRT)'], ['3', 'public key (PEM)']])
        print(t.draw())
        what_to_export = self._get_san_input_int("What to export :", 3)
        val = self._get_cert_info_as_string(ca, what_to_export)

        self._export_val(val)
Esempio n. 9
0
    def do_importcert(self, inp):
        '''Import an Cert'''

        # Get ca_id to export by user and extract from db
        self._print_cas()
        ca_id = input("CA to use for signing: ")
        ca = session.query(CA).filter(CA.id == ca_id).one()

        # Get the key and cert from file
        key, cert = self._load_key_and_cert_from_file()

        # Creat DB-Object and commit
        desc = input("Please enter an description: ")
        cert = CERT(desc, cert, key, ca)
        session.add(cert)
        session.commit()
Esempio n. 10
0
def get_favorites(user: User) -> List[PostEntry]:
    """
    Returns all favorites for a user

    :param user: the user
    :return: the favorites for the specified user
    """
    posts = session.query(DBPost).filter(DBPost.user_id == user.id).order_by(
        DBPost.saved_at.asc())

    logging.info(f'Fetched favorites, user={user}')

    return [
        PostEntry(URL.find(db_post.url), db_post.post_id, db_post.saved_at)
        for db_post in posts
    ]
Esempio n. 11
0
    def do_gencert(self, inp):
        '''Add an CERT to an CA'''
        # Print existing CAs
        self._print_cas()

        # Get ca_id to export by user
        ca_id = input("CA to use for signing: ")

        # Extract from the DB
        ca = session.query(CA).filter(CA.id == ca_id).one()

        # Generate CERT, create an DB-Obj and add to session
        cert, key = gen_cert(ca=ca)
        desc = input("Please enter an description: ")
        cert = CERT(desc, cert, key, ca)
        session.add(cert)
        session.commit()
Esempio n. 12
0
def remove_favorite(user: User, post: Post):
    """
    Removes a favorite from a user
    This will not succeed if the user is not stored in the database
    Or if the user did not have the favorite

    :param user: the user
    :param post: the post
    :return: True if removing succeeds, False if not
    """
    db_post = session.query(DBPost).get(
        (user.id, post.post_id, post.board_url.short_url))

    session.delete(db_post)
    session.commit()
    logging.info(
        f'Removed favorite, user={user}, post_id={post.post_id}, url={post.board_url}'
    )
Esempio n. 13
0
def father():
    if request.method == 'POST':
        data = request.json
        logging.debug('Received data on /father: {}'.format(data))
        father = Father(data['name'], data['last_name'])
        session.add(father)
        session.commit()
        return Response(status=200)

    else:
        ret = []
        for elem in session.query(Father).all():
            tmp = {}
            tmp['name'] = elem.name
            tmp['last_name'] = elem.last_name
            ret.append(tmp)

        # ret = "{}; {}".format(ret, entry.name)
        return json.dumps(ret)
Esempio n. 14
0
    def do_exportcert(self, inp):
        '''Export an key or cert of an client-cert'''
        num_certs = self._print_certs()
        cert_id = self._get_san_input_int("Choose an certificate to export: ",
                                          num_certs)
        cert = session.query(CERT).filter(CERT.id == cert_id).one()

        # Ask user what to export
        t = Texttable()
        t.add_rows([
            ['ID', 'Target'],
            ['1', 'private key (PEM)'],
            ['2', 'certificate (CRT)'],
            ['3', 'public key (PEM)'],
            ['4', 'packed and pw-protected (PKCS12)'],
        ])
        print(t.draw())

        what_to_export = self._get_san_input_int("What to export :", 4)
        val = self._get_cert_info_as_string(cert, what_to_export)

        self._export_val(val)