Exemple #1
0
        print("SQL directory does not exist {0}" "..creating".format(dirname))
        os.makedirs(dirname)
        os.chmod(dirname, 0777)
    elif not (os.path.isdir(dirname)):
        print("Error. SQL directory is a not a dir {0}" "".format(dirname))
        raise IrmaDatabaseError("Can not create Frontend database dir")

    if not os.path.exists(db_name):
        # touch like method to create a rw-rw-rw- file for db
        open(db_name, "a").close()
        os.chmod(db_name, 0666)


sql_db_connect()
Base = declarative_base()
tables_prefix = "{0}_".format(config.get_sql_db_tables_prefix())


class Scan(Base, SQLDatabaseObject):
    __tablename__ = "{0}scan".format(tables_prefix)
    # SQLite fix for auto increment on ids
    # see http://docs.sqlalchemy.org/en/latest/dialects/sqlite.html
    if config.get_sql_db_uri_params()[0] == "sqlite":
        __table_args__ = {"sqlite_autoincrement": True}

    # Fields
    id = Column(Integer, autoincrement=True, nullable=False, primary_key=True, name="id")
    scan_id = Column(String, index=True, nullable=False, name="scan_id")
    status = Column(Integer, nullable=False, name="status")
    timestamp = Column(Float(precision=2), nullable=False, name="timestamp")
    nb_files = Column(Integer, nullable=False, name="nb_files")
Exemple #2
0
#
# Copyright (c) 2013-2018 Quarkslab.
# This file is part of IRMA project.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License in the top-level directory
# of this distribution and at:
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# No part of the project, including this file, may be copied,
# modified, propagated, or distributed except according to the
# terms contained in the LICENSE file.

from sqlalchemy.ext.declarative import declarative_base
import config.parser as config

Base = declarative_base()
tables_prefix = '{0}_'.format(config.get_sql_db_tables_prefix())
from sqlalchemy.orm import relationship, backref
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from sqlalchemy.sql import func

import config.parser as config
from lib.irma.common.exceptions import IrmaDatabaseResultNotFound, \
    IrmaDatabaseError, IrmaCoreError, IrmaFileSystemError
from lib.common import compat
from lib.common.utils import UUID
from lib.irma.common.utils import IrmaScanStatus, IrmaProbeType
from lib.irma.database.sqlobjects import SQLDatabaseObject
from frontend.helpers.format import IrmaFormatter


Base = declarative_base()
tables_prefix = '{0}_'.format(config.get_sql_db_tables_prefix())

# Many to many Tag <-> File
tag_file = Table(
    '{0}tag_file'.format(tables_prefix),
    Base.metadata,
    Column(
        'id_tag',
        Integer,
        ForeignKey('{0}tag.id'.format(tables_prefix))
    ),
    Column(
        'id_file',
        Integer,
        ForeignKey('{0}file.id'.format(tables_prefix)))
)