Skip to content

Commit

Permalink
chg: [website] parser view for result
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCruciani committed Feb 12, 2024
1 parent ad6397b commit 67a0110
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 29 deletions.
4 changes: 4 additions & 0 deletions website/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import CSRFProtect
from flask_migrate import Migrate
from flask_session import Session

from config import config as Config
import os
Expand All @@ -10,6 +11,7 @@
db = SQLAlchemy()
csrf = CSRFProtect()
migrate = Migrate()
sess = Session()

def create_app():
app = Flask(__name__)
Expand All @@ -22,6 +24,8 @@ def create_app():
db.init_app(app)
csrf.init_app(app)
migrate.init_app(app, db, render_as_batch=True)
app.config["SESSION_SQLALCHEMY"] = db
sess.init_app(app)

from .home import home_blueprint
app.register_blueprint(home_blueprint, url_prefix="/")
Expand Down
123 changes: 94 additions & 29 deletions website/app/templates/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,49 +49,96 @@ <h4>Modules:</h4>
<br/>

<!-- Results Part -->
<hr>
<div class="row" v-if="Object.keys(modules_res).length">
<div class="col-10">
<h3 id="results_part">Results</h3>
<div class="accordion">
<div class="accordion-item" v-for="result, key in modules_res">
<template v-if="!('error' in result)">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" :data-bs-target="'#panelsStayOpen-'+key" aria-expanded="true" :aria-controls="'panelsStayOpen-'+key">
[[key]]
</button>
</h2>
<div :id="'panelsStayOpen-'+key" class="accordion-collapse collapse show">
<div class="accordion-body" v-html="generateCoreFormatUI(result)[0].outerHTML"></div>
</div>
</template>
<hr>
<ul class="nav nav-tabs" style="margin-bottom: 10px;">
<li class="nav-item">
<button class="nav-link active" id="tab-json" aria-current="page" @click="active_tab(true)">Json</button>
</li>
<li class="nav-item">
<button class="nav-link" id="tab-parser" @click="active_tab(false)">Parser</button>
</li>
</ul>

<template v-if="json_tab">
<div class="row" v-if="Object.keys(modules_res).length">
<div class="col-10">
<h3 id="results_part">Results</h3>
<div class="accordion">
<div class="accordion-item" v-for="result, key in modules_res">
<template v-if="!('error' in result)">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" :data-bs-target="'#panelsStayOpen-'+key" aria-expanded="true" :aria-controls="'panelsStayOpen-'+key">
[[key]]
</button>
</h2>
<div :id="'panelsStayOpen-'+key" class="accordion-collapse collapse show">
<div class="accordion-body" v-html="generateCoreFormatUI(result)[0].outerHTML"></div>
</div>
</template>
</div>
</div>

<!-- Errors Part -->
<hr style="margin-top: 50px">
<h3 id="errors_part">Errors</h3>
<div class="accordion">
<div class="accordion-item" v-for="result, key in modules_res">
<template v-if="'error' in result">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" :data-bs-target="'#panelsStayOpen-'+key" aria-expanded="true" :aria-controls="'panelsStayOpen-'+key">
[[key]]
<span style="margin-left: 5px;" title="Error"></span>
</button>
</h2>
<div :id="'panelsStayOpen-'+key" class="accordion-collapse collapse show">
<div class="accordion-body" v-html="generateCoreFormatUI(result)[0].outerHTML"></div>
</div>
</template>
</div>
</div>
</div>
<div class="col-1" style="position: fixed; right: 0px; box-shadow: 0 2px 5px 0 rgb(0 0 0 / 5%), 0 2px 10px 0 rgb(0 0 0 / 5%);">
<div style="padding: 10px;"><a style="text-decoration: none;" href="#results_part">Results</a></div>
<div style="padding: 10px;"><a style="text-decoration: none;" href="#errors_part">Errors</a></div>
</div>
</div>
</template>

<!-- Errors Part -->
<hr style="margin-top: 50px">
<h3 id="errors_part">Errors</h3>
<template v-else>
<div v-if="Object.keys(modules_res).length">
<div class="accordion">
<div class="accordion-item" v-for="result, key in modules_res">
<template v-if="'error' in result">
<template v-if="!('error' in result)">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" :data-bs-target="'#panelsStayOpen-'+key" aria-expanded="true" :aria-controls="'panelsStayOpen-'+key">
[[key]]
<span style="margin-left: 5px;" title="Error"></span>
</button>
</h2>
<div :id="'panelsStayOpen-'+key" class="accordion-collapse collapse show">
<div class="accordion-body" v-html="generateCoreFormatUI(result)[0].outerHTML"></div>
<div class="accordion-body row">
<template v-for="obj, key_obj in result.results.Object">
<h4>Object #[[key_obj+1]] - <small>[[obj.name]]</small></h4>
<div class="row" style="margin: 5px; padding: 5px;">
<div class="col-4 mb-3" style="border: 1px solid #939393; border-radius: 10px;" v-for="attr, key_attr in obj.Attribute">
<h6>Attributes #[[key_attr+1]]</h6>
<div>
Type: [[attr.type]]
</div>
<div>
Value: [[attr.value]]
</div>
</div>
</div>
<hr>
</template>
</div>
</div>
</template>
</div>
</div>
</div>
<div class="col-1" style="position: fixed; right: 0px; box-shadow: 0 2px 5px 0 rgb(0 0 0 / 5%), 0 2px 10px 0 rgb(0 0 0 / 5%);">
<div style="padding: 10px;"><a style="text-decoration: none;" href="#results_part">Results</a></div>
<div style="padding: 10px;"><a style="text-decoration: none;" href="#errors_part">Errors</a></div>
</div>
</div>
</template>

<span id="goTop">[<a href="#top">Go Back Top</a>]</span>
{% endblock %}

Expand All @@ -109,6 +156,7 @@ <h2 class="accordion-header">
const modules_res = ref({})
const progress = ref(0)
const status_site = ref()
const json_tab = ref(true)


function actionQuery(){
Expand Down Expand Up @@ -148,18 +196,35 @@ <h2 class="accordion-header">
modules_res.value = loc
}

function active_tab(is_json){
if(is_json){
json_tab.value = true
if ( !document.getElementById("tab-json").classList.contains("active") ){
document.getElementById("tab-json").classList.add("active")
document.getElementById("tab-parser").classList.remove("active")
}
}else{
json_tab.value = false
if ( !document.getElementById("tab-parser").classList.contains("active") ){
document.getElementById("tab-parser").classList.add("active")
document.getElementById("tab-json").classList.remove("active")
}
}
}

onMounted(() => {
actionQuery()
})


return {
message_list,
progress,
status_site,
is_searching,
modules_res,
generateCoreFormatUI
json_tab,
generateCoreFormatUI,
active_tab
}
}
}).mount('.container')
Expand Down
2 changes: 2 additions & 0 deletions website/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Config:
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = "sqlite:///misp-module.sqlite"
SESSION_TYPE = "sqlalchemy"
SESSION_SQLALCHEMY_TABLE = "flask_sessions"

@classmethod
def init_app(cls, app):
Expand Down

0 comments on commit 67a0110

Please sign in to comment.