# Path: config.py
# CERTITUDE_DATABASE = "sqlite:///data.db"
# 
# LISTEN_ADDRESS = '127.0.0.1'
# 
# LISTEN_PORT = 5000
# 
# Path: helpers/results_models.py
# class Result(Base):
#     __tablename__ = 'resultats'
# 
#     id = Column(Integer, primary_key=True)
#     tache_id = Column(Integer, ForeignKey('queue.id'))
#     finished = Column(DateTime, default=datetime.now)
# 
#     up = Column(Boolean)
#     blocked = Column(Boolean)
#     ip = Column(String)
#     hostname = Column(String)
#     smbreachable = Column(Boolean)
# 
# class IOCDetection(Base):
#     __tablename__ = 'iocdetections'
# 
#     id = Column(Integer, primary_key=True)
#     result_id = Column(Integer, ForeignKey('resultats.id'))
#     resultat = relationship(Result,
#         backref='iocdetections',)
#     xmlioc_id = Column(Integer)
#     indicator_id = Column(String) # Length should be 62
#     indicator_data = Column(String)
# 
# Path: helpers/misc_models.py
# class ConfigurationProfile(Base):
#     __tablename__ = 'configuration_profiles'
# 
#     id = Column(Integer, primary_key=True)
#     name = Column(String)
#     host_confidential = Column(Boolean, default=False)
#     ioc_list = Column(String)
#     yara_list = Column(String)
# 
# class XMLIOC(Base):
#     __tablename__ = 'xmliocs'
# 
#     id = Column(Integer, primary_key=True)
#     name = Column(String)
#     date_added = Column(DateTime, default=datetime.now)
#     xml_content = Column(String)
# 
# class Batch(Base):
#     __tablename__ = 'batches'
# 
#     id = Column(Integer, primary_key = True)
#     name = Column(String)
#     configuration_profile_id = Column(Integer)
#     windows_credential_id = Column(Integer)


import pandas as pd
import io
import base64
import components.scanner.openioc.openiocparser as openiocparser
import xml.etree.ElementTree as ET
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config import CERTITUDE_DATABASE, LISTEN_ADDRESS, LISTEN_PORT
from helpers.queue_models import Task
from helpers.results_models import Result, IOCDetection
from helpers.misc_models import ConfigurationProfile, XMLIOC, Batch
from bokeh.layouts import row, widgetbox, layout
from bokeh.models import Select, Slider, DataTable, TableColumn, ColumnDataSource
from bokeh.models import ColumnDataSource, BoxSelectTool, ResetTool, Div, HTMLTemplateFormatter
from bokeh.plotting import curdoc, figure
        context = indic.findall('Context')[0]
        search = context.attrib['search']

        content = indic.findall('Content')[0]
        value = content.text

        r['guids'][guid] = {'search': search, 'value': value}
        r['totalguids'] += 1

    return r

def getDataframeFromBatchid(batchid):
    engine = create_engine(CERTITUDE_DATABASE, echo=False)
    dbsession = sessionmaker(bind=engine)()

    columns = ['HostId','HostnameIP' , 'Lookup:Success' , 'Lookup:IOCScanned' , 'Lookup:HashScanned', 'Lookup:Subnet' , 'Malware', 'Compromise']
    coldata = []

    batch = dbsession.query(Batch).filter_by(id=batchid).first()
    if batch is None:
        raise Exception('No batch found')

    # Get all IOCs
    cp = dbsession.query(ConfigurationProfile).filter_by(id=batch.configuration_profile_id).first()

    if cp.ioc_list == '':
        ioc_list = []
    else:
        ioc_list = [int(e) for e in cp.ioc_list.split(',')]


# Path: config.py
# CERTITUDE_DATABASE = "sqlite:///data.db"
# 
# LISTEN_ADDRESS = '127.0.0.1'
# 
# LISTEN_PORT = 5000
# 
# Path: helpers/results_models.py
# class Result(Base):
#     __tablename__ = 'resultats'
# 
#     id = Column(Integer, primary_key=True)
#     tache_id = Column(Integer, ForeignKey('queue.id'))
#     finished = Column(DateTime, default=datetime.now)
# 
#     up = Column(Boolean)
#     blocked = Column(Boolean)
#     ip = Column(String)
#     hostname = Column(String)
#     smbreachable = Column(Boolean)
# 
# class IOCDetection(Base):
#     __tablename__ = 'iocdetections'
# 
#     id = Column(Integer, primary_key=True)
#     result_id = Column(Integer, ForeignKey('resultats.id'))
#     resultat = relationship(Result,
#         backref='iocdetections',)
#     xmlioc_id = Column(Integer)
#     indicator_id = Column(String) # Length should be 62
#     indicator_data = Column(String)
# 
# Path: helpers/misc_models.py
# class ConfigurationProfile(Base):
#     __tablename__ = 'configuration_profiles'
# 
#     id = Column(Integer, primary_key=True)
#     name = Column(String)
#     host_confidential = Column(Boolean, default=False)
#     ioc_list = Column(String)
#     yara_list = Column(String)
# 
# class XMLIOC(Base):
#     __tablename__ = 'xmliocs'
# 
#     id = Column(Integer, primary_key=True)
#     name = Column(String)
#     date_added = Column(DateTime, default=datetime.now)
#     xml_content = Column(String)
# 
# class Batch(Base):
#     __tablename__ = 'batches'
# 
#     id = Column(Integer, primary_key = True)
#     name = Column(String)
#     configuration_profile_id = Column(Integer)
#     windows_credential_id = Column(Integer)


# Path: crossbokeh.py
import pandas as pd
import io
import base64
import components.scanner.openioc.openiocparser as openiocparser
import xml.etree.ElementTree as ET
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config import CERTITUDE_DATABASE, LISTEN_ADDRESS, LISTEN_PORT
from helpers.queue_models import Task
from helpers.results_models import Result, IOCDetection
from helpers.misc_models import ConfigurationProfile, XMLIOC, Batch
from bokeh.layouts import row, widgetbox, layout
from bokeh.models import Select, Slider, DataTable, TableColumn, ColumnDataSource
from bokeh.models import ColumnDataSource, BoxSelectTool, ResetTool, Div, HTMLTemplateFormatter
from bokeh.plotting import curdoc, figure

        context = indic.findall('Context')[0]
        search = context.attrib['search']

        content = indic.findall('Content')[0]
        value = content.text

        r['guids'][guid] = {'search': search, 'value': value}
        r['totalguids'] += 1

    return r

def getDataframeFromBatchid(batchid):
    engine = create_engine(CERTITUDE_DATABASE, echo=False)
    dbsession = sessionmaker(bind=engine)()

    columns = ['HostId','HostnameIP' , 'Lookup:Success' , 'Lookup:IOCScanned' , 'Lookup:HashScanned', 'Lookup:Subnet' , 'Malware', 'Compromise']
    coldata = []

    batch = dbsession.query(Batch).filter_by(id=batchid).first()
    if batch is None:
        raise Exception('No batch found')

    # Get all IOCs
    cp = dbsession.query(ConfigurationProfile).filter_by(id=batch.configuration_profile_id).first()

    if cp.ioc_list == '':
        ioc_list = []
    else:
        ioc_list = [int(e) for e in cp.ioc_list.split(',')]


    iocs = dbsession.query(XMLIOC).filter(XMLIOC.id.in_(ioc_list)).all()