示例#1
0
class Role(admin_db.Model, RoleMixin):
    id = admin_db.Column(admin_db.Integer(), primary_key=True)
    name = admin_db.Column(admin_db.String(80), unique=True)
    description = admin_db.Column(admin_db.String(255))

    def __str__(self):
        return self.name
示例#2
0
class InformationRechercheInteret(RechercheInteret):
    __tablename__ = 'information_recherche_interet'
    id = db.Column(db.Integer, db.ForeignKey('recherche_interet.id'), primary_key=True)

    information_cible = db.Column(db.String(255), nullable=False)

    __mapper_args__ = {
        'polymorphic_identity': str(RechercheInteret).replace('RechercheInteret', 'InformationRechercheInteret'),
    }

    def __repr__(self):
        if self.focus_cle and self.focus_cle != '':
            return _('<Recherche Information Balisée \'{expr}\' DANS "{loc}">').format(expr=self.information_cible, loc=self.focus_cle)
        return _('<Recherche Information Balisée \'{expr}\' PARTOUT>').format(expr=self.information_cible)

    def transcription(self):
        """
        :rtype: hermes.detecteur.InformationRechercheInteret
        """
        from hermes.detecteur import InformationRechercheInteret as Critere
        return Critere(
            self.designation,
            self.information_cible,
            self.focus_cle,
            self.est_obligatoire,
            self.friendly_name
        )
示例#3
0
class OperationLogiqueRechercheInteret(RechercheInteret):
    __tablename__ = 'operation_logique_recherche_interet'
    id = db.Column(db.Integer, db.ForeignKey('recherche_interet.id'), primary_key=True)

    operande = db.Column(db.Enum("AND", "NOT", 'XOR', 'OR'), nullable=False)
    sous_regles = db.relationship(RechercheInteret, secondary='lien_sous_regle_operation_logique', enable_typechecks=False, cascade="save-update, delete")

    __mapper_args__ = {
        'polymorphic_identity': str(RechercheInteret).replace('RechercheInteret', 'OperationLogiqueRechercheInteret'),
    }

    def __repr__(self):
        return _('<Opération sur Critère(s) {operande} "{nom}">').format(operande=self.operande, nom=self.designation)

    def transcription(self):
        """
        :rtype: hermes.detecteur.OperationLogiqueRechercheInteret
        """
        from hermes.detecteur import OperationLogiqueRechercheInteret as Critere

        kwargs = dict()

        for sous_regle in self.sous_regles:
            kwargs['ma_cond_{}'.format(sous_regle.id)] = sous_regle.transcription()

        kwargs['friendly_name'] = self.friendly_name

        return Critere(
            self.designation,
            self.operande,
            **kwargs
        )
示例#4
0
class IdentificateurRechercheInteret(RechercheInteret):
    __tablename__ = 'identificateur_recherche_interet'

    id = db.Column(db.Integer, db.ForeignKey('recherche_interet.id'), primary_key=True)

    prefixe = db.Column(db.String(255), nullable=False)

    __mapper_args__ = {
        'polymorphic_identity': str(RechercheInteret).replace('RechercheInteret', 'IdentificateurRechercheInteret'),
    }

    def __repr__(self):
        if self.focus_cle and self.focus_cle != '':
            return _('<Recherche Identifiant Préfixé \'{identifiant_prefixe}\' DANS \'{focus_cle}\'>').format(identifiant_prefixe=self.prefixe, focus_cle=self.focus_cle)
        return _('<Recherche Identifiant Préfixé \'{identifiant_prefixe}\' PARTOUT>').format(identifiant_prefixe=self.prefixe)

    def transcription(self):
        """
        :rtype: hermes.detecteur.IdentificateurRechercheInteret
        """
        from hermes.detecteur import IdentificateurRechercheInteret as Critere
        return Critere(
            self.designation,
            self.prefixe,
            taille_stricte=None,
            focus_cle=self.focus_cle,
            est_obligatoire=self.est_obligatoire,
            friendly_name=self.friendly_name
        )
示例#5
0
class ExpressionDansCleRechercheInteret(RechercheInteret):
    __tablename__ = 'expression_dans_cle_recherche_interet'

    id = db.Column(db.Integer(), db.ForeignKey('recherche_interet.id'), primary_key=True)

    cle_recherchee = db.Column(db.String(255), nullable=False)
    expression_recherchee = db.Column(db.String(255), nullable=False)

    __mapper_args__ = {
        'polymorphic_identity': str(RechercheInteret).replace('RechercheInteret', 'ExpressionDansCleRechercheInteret'),
    }

    def __repr__(self):
        return _('<Recherche Exactement \'{expr}\' DANS Clé Auto-Découverte "{loc}">').format(expr=self.expression_recherchee, loc=self.cle_recherchee)

    def transcription(self):
        """
        :rtype: hermes.detecteur.ExpressionDansCleRechercheInteret
        """
        from hermes.detecteur import ExpressionDansCleRechercheInteret as Critere
        return Critere(
            self.designation,
            self.cle_recherchee,
            self.expression_recherchee,
            self.est_obligatoire,
            self.friendly_name
        )
示例#6
0
class ExpressionXPathRechercheInteret(RechercheInteret):

    __tablename__ = 'expression_xpath_recherche_interet'

    id = db.Column(db.Integer, db.ForeignKey('recherche_interet.id'), primary_key=True)

    expression_xpath = db.Column(db.String(255), nullable=False)

    __mapper_args__ = {
        'polymorphic_identity': str(RechercheInteret).replace('RechercheInteret',
                                                              'ExpressionXPathRechercheInteret'),
    }

    def __repr__(self):
        return _('<Recherche XPath \'{expr_xpath}\' DANS CORPS HTML>').format(expr_xpath=self.expression_xpath)

    def transcription(self):
        """
        :rtype: hermes.detecteur.ExpressionXPathRechercheInteret
        """
        from hermes.detecteur import ExpressionXPathRechercheInteret as Critere
        return Critere(
            self.designation,
            self.expression_xpath,
            self.est_obligatoire,
            self.friendly_name
        )
示例#7
0
class LocalisationExpressionRechercheInteret(RechercheInteret):

    __tablename__ = 'localisation_expression_recherche_interet'

    id = db.Column(db.Integer,
                   db.ForeignKey('recherche_interet.id'),
                   primary_key=True)

    expression_gauche = db.Column(db.String(255), nullable=True)
    expression_droite = db.Column(db.String(255), nullable=True)

    __mapper_args__ = {
        'polymorphic_identity':
        str(RechercheInteret).replace(
            'RechercheInteret', 'LocalisationExpressionRechercheInteret'),
    }

    def __repr__(self):
        if self.expression_gauche and self.expression_droite and self.expression_gauche != '' and self.expression_droite != '':
            return _(
                '<Recherche Expression ENTRE \'{expr_gauche}\' ET \'{expr_droite}\' {loc}>'
            ).format(
                expr_gauche=self.expression_gauche,
                expr_droite=self.expression_droite,
                loc=_('PARTOUT') if self.focus_cle and self.focus_cle != ''
                else _('DANS \'{}\'').format(self.focus_cle))
        if self.expression_gauche and self.expression_gauche != '':
            return _(
                '<Recherche Expression À DROITE DE \'{expr_gauche}\' {loc}>'
            ).format(
                expr_gauche=self.expression_gauche,
                loc=_('PARTOUT') if self.focus_cle and self.focus_cle != ''
                else _('DANS \'{}\'').format(self.focus_cle))
        if self.expression_droite and self.expression_droite != '':
            return _(
                '<Recherche Expression À GAUCHE DE \'{expr_droite}\' {loc}>'
            ).format(
                expr_droite=self.expression_droite,
                loc=_('PARTOUT') if self.focus_cle and self.focus_cle != ''
                else _('DANS \'{}\'').format(self.focus_cle))

        return _(
            '<Recherche Expression ENTRE \'{expr_gauche}\' ET \'{expr_droite}\' {loc}>'
        ).format(expr_gauche=self.expression_gauche,
                 expr_droite=self.expression_droite,
                 loc=_('PARTOUT') if self.focus_cle and self.focus_cle != ''
                 else _('DANS \'{}\'').format(self.focus_cle))

    def transcription(self):
        """
        :rtype: hermes.detecteur.LocalisationExpressionRechercheInteret
        """
        from hermes.detecteur import LocalisationExpressionRechercheInteret as Critere
        return Critere(self.designation, self.expression_droite,
                       self.expression_gauche, self.focus_cle,
                       self.est_obligatoire, self.friendly_name)
示例#8
0
class LienDetecteurRechercheInteret(db.Model):

    __tablename__ = 'lien_detecteur_recherche_interet'

    detecteur_id = db.Column(db.Integer(),
                             db.ForeignKey('detecteur.id', ondelete='CASCADE'),
                             primary_key=True)
    recherche_interet_id = db.Column(db.Integer(),
                                     db.ForeignKey('recherche_interet.id',
                                                   ondelete='CASCADE'),
                                     primary_key=True)
示例#9
0
class RechercheInteret(db.Model):
    __tablename__ = 'recherche_interet'

    id = db.Column(db.Integer(), primary_key=True)
    designation = db.Column(db.String(255), nullable=False)

    detecteurs = db.relationship(Detecteur,
                                 secondary='lien_detecteur_recherche_interet')

    est_obligatoire = db.Column(db.Boolean(), nullable=False)

    focus_cle = db.Column(db.String(255), nullable=True)

    createur_id = db.Column(db.ForeignKey('user.id'), nullable=True)
    createur = db.relationship(
        User, primaryjoin="User.id==RechercheInteret.createur_id")

    date_creation = db.Column(db.DateTime(timezone=True),
                              nullable=False,
                              default=datetime.datetime.utcnow())
    date_modification = db.Column(db.DateTime(timezone=True),
                                  nullable=False,
                                  default=datetime.datetime.utcnow())

    responsable_derniere_modification_id = db.Column(db.ForeignKey('user.id'),
                                                     nullable=True)
    responsable_derniere_modification = db.relationship(
        User,
        primaryjoin=
        "User.id==RechercheInteret.responsable_derniere_modification_id")

    mapped_class_child = db.Column(db.String(128), nullable=True)

    friendly_name = db.Column(db.String(255), nullable=True)

    __mapper_args__ = {
        'polymorphic_on':
        mapped_class_child,
        'polymorphic_identity':
        str(Detecteur).replace('.Detecteur', '.RechercheInteret'),
    }

    def __repr__(self):
        return _('<Recherche DE \'{nom}\'>').format(nom=self.designation)

    def transcription(self):
        """
        Transforme un critère "RechercheInteret < db.Model" en objet "RechercheInteret < hermes"
        :rtype: hermes.detecteur.RechercheInteret
        """
        raise NotImplemented
示例#10
0
class LienSousRegleOperationLogique(db.Model):

    __tablename__ = 'lien_sous_regle_operation_logique'

    operation_logique_recherche_interet_id = db.Column(
        db.Integer(),
        db.ForeignKey('operation_logique_recherche_interet.id',
                      ondelete='CASCADE'),
        primary_key=True)

    recherche_interet_id = db.Column(db.Integer(),
                                     db.ForeignKey('recherche_interet.id',
                                                   ondelete='CASCADE'),
                                     primary_key=True)
示例#11
0
class RechercheInteretExecution(db.Model):

    id = db.Column(db.BigInteger(), primary_key=True, autoincrement=True)

    automate_execution_id = db.Column(db.BigInteger(),
                                      db.ForeignKey(AutomateExecution.id),
                                      nullable=False)
    automate_execution = db.relationship(AutomateExecution)

    recherche_interet_id = db.Column(db.Integer(),
                                     db.ForeignKey(RechercheInteret.id))
    recherche_interet = db.relationship(RechercheInteret)

    validation_recherche_interet = db.Column(db.Boolean(),
                                             default=False,
                                             nullable=False)

    payload = db.Column(db.Text(), nullable=True)
示例#12
0
class Detecteur(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    designation = db.Column(db.String(255), nullable=False)

    regles = db.relationship("RechercheInteret", secondary='lien_detecteur_recherche_interet', lazy='joined', enable_typechecks=False, cascade="save-update, merge")  # type: list[RechercheInteret]

    createur_id = db.Column(db.ForeignKey('user.id'), nullable=True)
    createur = db.relationship(User, primaryjoin="User.id==Detecteur.createur_id")

    date_creation = db.Column(db.DateTime(timezone=True), nullable=False, default=datetime.datetime.utcnow())
    date_modification = db.Column(db.DateTime(timezone=True), nullable=False, default=datetime.datetime.utcnow())

    responsable_derniere_modification_id = db.Column(db.ForeignKey('user.id'), nullable=True)
    responsable_derniere_modification = db.relationship(User,
                                                        primaryjoin="User.id==Detecteur.responsable_derniere_modification_id")

    def __repr__(self):
        return _('<Détection DE \'{detecteur_nom}\'>').format(detecteur_nom=self.designation)

    def transcription(self):
        """
        :rtype: hermes.detecteur.Detecteur
        """
        from hermes.detecteur import Detecteur as HermesDetecteur

        mon_detecteur = HermesDetecteur(
            self.designation
        )

        for regle in self.regles:
            mon_detecteur.je_veux(
                get_child_polymorphic(regle).transcription()
            )

        return mon_detecteur
示例#13
0
class Configuration(db.Model):

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    designation = db.Column(db.String(255), nullable=False, unique=True)
    valeur = db.Column(db.Text(), nullable=False)

    createur_id = db.Column(db.ForeignKey('user.id', ondelete='SET NULL'),
                            nullable=True)
    createur = db.relationship(
        User, primaryjoin="User.id==Configuration.createur_id")

    date_creation = db.Column(db.DateTime(timezone=True), nullable=False)
    date_modification = db.Column(db.DateTime(timezone=True), nullable=False)

    responsable_derniere_modification_id = db.Column(db.ForeignKey(
        'user.id', ondelete='SET NULL'),
                                                     nullable=True)
    responsable_derniere_modification = db.relationship(
        User,
        primaryjoin=
        "User.id==Configuration.responsable_derniere_modification_id")

    format = db.Column(db.Enum("JSON", 'YAML', 'AUTRE'), nullable=False)

    def __repr__(self):
        return '<Configuration \'{}\'>'.format(self.designation)

    def on_model_change(self, form, model, is_created):
        """

        :param form:
        :param Configuration model:
        :param bool is_created:
        :return:
        """
        if is_created is True:
            model.createur = current_user
            model.date_creation = datetime.now()

        model.date_modification = datetime.now()
        model.responsable_derniere_modification = current_user

        Session.charger_input(model.designation, model.valeur, model.format)
示例#14
0
class User(admin_db.Model, UserMixin):
    id = admin_db.Column(admin_db.Integer, primary_key=True)
    first_name = admin_db.Column(admin_db.String(255))
    last_name = admin_db.Column(admin_db.String(255))
    email = admin_db.Column(admin_db.String(255), unique=True, nullable=False)
    password = admin_db.Column(admin_db.String(255), nullable=False)
    active = admin_db.Column(admin_db.Boolean(), nullable=False)
    roles = admin_db.relationship('Role',
                                  secondary=roles_users,
                                  backref='users')

    def __str__(self):
        return self.first_name + " " + self.last_name + " <" + self.email + ">"
示例#15
0
class ActionNoeudExecution(db.Model):

    id = db.Column(db.BigInteger(), primary_key=True, autoincrement=True)

    automate_execution_id = db.Column(db.BigInteger(),
                                      db.ForeignKey(AutomateExecution.id,
                                                    ondelete='CASCADE'),
                                      nullable=False)
    automate_execution = db.relationship(
        AutomateExecution, cascade='all, save-update, delete, merge')

    action_noeud_id = db.Column(
        db.Integer(), db.ForeignKey(ActionNoeud.id, ondelete='CASCADE'))
    action_noeud = db.relationship(ActionNoeud)

    validation_action_noeud = db.Column(db.Boolean(),
                                        default=False,
                                        nullable=False)

    args_payload = db.Column(db.Text(), nullable=True)
    payload = db.Column(db.Text(), nullable=True)
示例#16
0
from flask_security import RoleMixin, UserMixin
from hermes_ui.db import db as admin_db

roles_users = admin_db.Table(
    'roles_users',
    admin_db.Column('user_id', admin_db.Integer(),
                    admin_db.ForeignKey('user.id')),
    admin_db.Column('role_id', admin_db.Integer(),
                    admin_db.ForeignKey('role.id')))


class Role(admin_db.Model, RoleMixin):
    id = admin_db.Column(admin_db.Integer(), primary_key=True)
    name = admin_db.Column(admin_db.String(80), unique=True)
    description = admin_db.Column(admin_db.String(255))

    def __str__(self):
        return self.name


class User(admin_db.Model, UserMixin):
    id = admin_db.Column(admin_db.Integer, primary_key=True)
    first_name = admin_db.Column(admin_db.String(255))
    last_name = admin_db.Column(admin_db.String(255))
    email = admin_db.Column(admin_db.String(255), unique=True, nullable=False)
    password = admin_db.Column(admin_db.String(255), nullable=False)
    active = admin_db.Column(admin_db.Boolean(), nullable=False)
    roles = admin_db.relationship('Role',
                                  secondary=roles_users,
                                  backref='users')
示例#17
0
class AutomateExecution(db.Model):

    id = db.Column(db.BigInteger(), primary_key=True, autoincrement=True)

    automate_id = db.Column(db.Integer(),
                            db.ForeignKey(Automate.id, ondelete='CASCADE'),
                            nullable=False)
    automate = db.relationship(Automate,
                               cascade='all, save-update, delete, merge')

    sujet = db.Column(db.String(255), nullable=False)
    corps = db.Column(db.Text(), nullable=False)

    date_creation = db.Column(db.DateTime(timezone=True), nullable=False)

    detecteur_id = db.Column(db.Integer(),
                             db.ForeignKey(Detecteur.id, ondelete='CASCADE'),
                             nullable=False)
    detecteur = db.relationship(Detecteur, cascade='all, save-update, merge')

    validation_detecteur = db.Column(db.Boolean(),
                                     default=False,
                                     nullable=False)
    validation_automate = db.Column(db.Boolean(),
                                    default=False,
                                    nullable=False)

    explications_detecteur = db.Column(db.Text(), nullable=True)

    logs = db.Column(db.Text(), nullable=True)

    date_finalisation = db.Column(db.DateTime(timezone=True), nullable=False)

    actions_noeuds_executions = db.relationship('ActionNoeudExecution')
    recherches_interets_executions = db.relationship(
        'RechercheInteretExecution')
示例#18
0
class BoiteAuxLettresImap(db.Model):

    id = db.Column(db.Integer(), primary_key=True)
    designation = db.Column(db.String(255), nullable=False)

    activation = db.Column(db.Boolean(), default=False)

    hote_distante = db.Column(db.String(255), nullable=False)
    nom_utilisateur = db.Column(db.String(255), nullable=False)
    mot_de_passe = db.Column(db.String(255), nullable=False)
    dossier_cible = db.Column(db.String(255), nullable=False, default='INBOX')

    enable_tls = db.Column(db.Boolean(), nullable=False, default=True)
    verification_certificat = db.Column(db.Boolean(),
                                        nullable=False,
                                        default=True)
    legacy_tls_support = db.Column(db.Boolean(), nullable=False, default=False)

    createur_id = db.Column(db.ForeignKey('user.id', ondelete='SET NULL'),
                            nullable=True)
    createur = db.relationship(
        User, primaryjoin="User.id==BoiteAuxLettresImap.createur_id")

    date_creation = db.Column(db.DateTime(timezone=True), nullable=False)
    date_modification = db.Column(db.DateTime(timezone=True), nullable=False)

    responsable_derniere_modification_id = db.Column(db.ForeignKey(
        'user.id', ondelete='SET NULL'),
                                                     nullable=True)
    responsable_derniere_modification = db.relationship(
        User,
        primaryjoin=
        "User.id==BoiteAuxLettresImap.responsable_derniere_modification_id")

    def get_mailtoolbox(self):
        """
        :return:
        :rtype: MailToolbox
        """
        existant = MailToolbox.fetch_instance(self.hote_distante,
                                              self.nom_utilisateur)
        if existant is None:
            return MailToolbox(self.hote_distante,
                               self.nom_utilisateur,
                               self.mot_de_passe,
                               dossier_cible=self.dossier_cible,
                               verify_peer=self.verification_certificat,
                               use_secure_socket=self.enable_tls,
                               legacy_secure_protocol=self.legacy_tls_support)
        return existant