mirror of https://github.com/MISP/misp-modules
chg: [website] rename glob_query to modules_list
parent
0b73052ebc
commit
4d0672ffdd
|
@ -21,7 +21,7 @@ class Module(db.Model):
|
||||||
class Session_db(db.Model):
|
class Session_db(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
uuid = db.Column(db.String(36), index=True, unique=True)
|
uuid = db.Column(db.String(36), index=True, unique=True)
|
||||||
glob_query = db.Column(db.String)
|
modules_list = db.Column(db.String)
|
||||||
query_enter = db.Column(db.String)
|
query_enter = db.Column(db.String)
|
||||||
input_query = db.Column(db.String)
|
input_query = db.Column(db.String)
|
||||||
config_module=db.Column(db.String)
|
config_module=db.Column(db.String)
|
||||||
|
|
|
@ -29,7 +29,7 @@ def query(sid):
|
||||||
query_loc = s.query
|
query_loc = s.query
|
||||||
session=s
|
session=s
|
||||||
if flag:
|
if flag:
|
||||||
return render_template("query.html", query=query_loc, sid=sid, input_query=session.input_query, modules=json.loads(session.glob_query))
|
return render_template("query.html", query=query_loc, sid=sid, input_query=session.input_query, modules=json.loads(session.modules_list))
|
||||||
return render_template("404.html")
|
return render_template("404.html")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -116,13 +116,13 @@ def change_status_core(module_id):
|
||||||
##############
|
##############
|
||||||
|
|
||||||
def get_status_db(session):
|
def get_status_db(session):
|
||||||
glob_query = json.loads(session.glob_query)
|
|
||||||
"""Return status of a session"""
|
"""Return status of a session"""
|
||||||
|
modules_list = json.loads(session.modules_list)
|
||||||
result = json.loads(session.result)
|
result = json.loads(session.result)
|
||||||
return{
|
return{
|
||||||
'id': session.uuid,
|
'id': session.uuid,
|
||||||
'total': len(glob_query),
|
'total': len(modules_list),
|
||||||
'complete': len(glob_query),
|
'complete': len(modules_list),
|
||||||
'remaining': 0,
|
'remaining': 0,
|
||||||
'registered': len(result),
|
'registered': len(result),
|
||||||
'stopped' : True,
|
'stopped' : True,
|
||||||
|
@ -139,5 +139,5 @@ def get_history():
|
||||||
histories = History.query.all()
|
histories = History.query.all()
|
||||||
for history in histories:
|
for history in histories:
|
||||||
session = Session_db.query.get(history.session_id)
|
session = Session_db.query.get(history.session_id)
|
||||||
histories_list.append({"uuid": session.uuid, "query": session.query_enter, "modules": json.loads(session.glob_query), "input": session.input_query})
|
histories_list.append({"uuid": session.uuid, "query": session.query_enter, "modules": json.loads(session.modules_list), "input": session.input_query})
|
||||||
return histories_list
|
return histories_list
|
||||||
|
|
|
@ -22,13 +22,13 @@ class Session_class:
|
||||||
self.result = dict()
|
self.result = dict()
|
||||||
self.query = request_json["query"]
|
self.query = request_json["query"]
|
||||||
self.input_query = request_json["input"]
|
self.input_query = request_json["input"]
|
||||||
self.glob_query = self.expansion + self.hover
|
self.modules_list = request_json["modules"]
|
||||||
self.nb_errors = 0
|
self.nb_errors = 0
|
||||||
self.config_module = self.config_module_setter(request_json)
|
self.config_module = self.config_module_setter(request_json)
|
||||||
|
|
||||||
def config_module_setter(self, request_json):
|
def config_module_setter(self, request_json):
|
||||||
if request_json["config"]:
|
if request_json["config"]:
|
||||||
for query in self.glob_query:
|
for query in self.modules_list:
|
||||||
if not query in request_json["config"]:
|
if not query in request_json["config"]:
|
||||||
request_json["config"][query] = {}
|
request_json["config"][query] = {}
|
||||||
module = HomeModel.get_module_by_name(query)
|
module = HomeModel.get_module_by_name(query)
|
||||||
|
@ -41,9 +41,9 @@ class Session_class:
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start all worker"""
|
"""Start all worker"""
|
||||||
for i in range(len(self.glob_query)):
|
for i in range(len(self.modules_list)):
|
||||||
#need the index and the url in each queue item.
|
#need the index and the url in each queue item.
|
||||||
self.jobs.put((i, self.glob_query[i]))
|
self.jobs.put((i, self.modules_list[i]))
|
||||||
for _ in range(self.thread_count):
|
for _ in range(self.thread_count):
|
||||||
worker = Thread(target=self.process)
|
worker = Thread(target=self.process)
|
||||||
worker.daemon = True
|
worker.daemon = True
|
||||||
|
@ -55,7 +55,7 @@ class Session_class:
|
||||||
if self.jobs.empty():
|
if self.jobs.empty():
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
total = len(self.glob_query)
|
total = len(self.modules_list)
|
||||||
remaining = max(self.jobs.qsize(), len(self.threads))
|
remaining = max(self.jobs.qsize(), len(self.threads))
|
||||||
complete = total - remaining
|
complete = total - remaining
|
||||||
registered = len(self.result)
|
registered = len(self.result)
|
||||||
|
@ -123,7 +123,7 @@ class Session_class:
|
||||||
def save_info(self):
|
def save_info(self):
|
||||||
s = Session_db(
|
s = Session_db(
|
||||||
uuid=str(self.id),
|
uuid=str(self.id),
|
||||||
glob_query=json.dumps(self.glob_query),
|
modules_list=json.dumps(self.modules_list),
|
||||||
query_enter=self.query,
|
query_enter=self.query,
|
||||||
input_query=self.input_query,
|
input_query=self.input_query,
|
||||||
config_module=json.dumps(self.config_module),
|
config_module=json.dumps(self.config_module),
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: d6f8bfc9d454
|
||||||
|
Revises: c0e243696052
|
||||||
|
Create Date: 2024-02-08 15:23:46.714541
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'd6f8bfc9d454'
|
||||||
|
down_revision = 'c0e243696052'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('session_db', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('modules_list', sa.String(), nullable=True))
|
||||||
|
batch_op.drop_column('glob_query')
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('session_db', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('glob_query', sa.VARCHAR(), nullable=True))
|
||||||
|
batch_op.drop_column('modules_list')
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in New Issue