Skip to content

Commit

Permalink
Merge pull request #272 from InQuest/issue/243-filter-by-tags-on-arti…
Browse files Browse the repository at this point in the history
…facts

#243 : adding tags to ui-grid for c2dns/c2ip.
  • Loading branch information
danny248 committed Dec 26, 2018
2 parents 737413c + d282852 commit 7018605
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 9 deletions.
12 changes: 10 additions & 2 deletions app/routes/c2dns.py
Expand Up @@ -5,6 +5,8 @@
from dateutil import parser
from sqlalchemy import exc, and_

from app.models.tags_mapping import Tags_mapping
from app.models.tags import Tags
from app.models.users import KBUser
from app.models.metadata import Metadata, MetadataMapping
from app.models.cfg_states import verify_state
Expand Down Expand Up @@ -39,8 +41,7 @@ def get_all_c2dns():

searches = json.loads(searches)

if searches and any(
[search_key not in c2dns.C2dns.__table__.columns.keys() for search_key, val in searches.items()]):
if searches and any([search_key not in c2dns.C2dns.__table__.columns.keys() and search_key != "tags" for search_key, val in searches.items()]):
entities = c2dns.C2dns.query.outerjoin(Metadata, Metadata.artifact_type == ENTITY_MAPPING["DNS"]).join(
MetadataMapping,
and_(
Expand All @@ -61,6 +62,13 @@ def get_all_c2dns():
KBUser.email.like("%" + str(value) + "%"))
continue

if column == "tags":
entities = entities.outerjoin(Tags_mapping, c2dns.C2dns.id == Tags_mapping.source_id)\
.filter(Tags_mapping.source_table == c2dns.C2dns.__tablename__)\
.join(Tags, Tags_mapping.tag_id == Tags.id)\
.filter(Tags.text.like("%" + str(value) + "%"))
continue

try:
column = getattr(c2dns.C2dns, column)
entities = entities.filter(column.like("%" + str(value) + "%"))
Expand Down
11 changes: 10 additions & 1 deletion app/routes/c2ips.py
Expand Up @@ -5,6 +5,8 @@
from dateutil import parser
from sqlalchemy import exc, and_

from app.models.tags_mapping import Tags_mapping
from app.models.tags import Tags
from app.models.users import KBUser
from app.models.metadata import Metadata, MetadataMapping
from app.models.cfg_states import verify_state
Expand Down Expand Up @@ -38,7 +40,7 @@ def get_all_c2ips():

searches = json.loads(searches)

if searches and any([search_key not in c2ip.C2ip.__table__.columns.keys() for search_key, val in searches.items()]):
if searches and any([search_key not in c2ip.C2ip.__table__.columns.keys() and search_key != "tags" for search_key, val in searches.items()]):
entities = c2ip.C2ip.query.outerjoin(Metadata, Metadata.artifact_type == ENTITY_MAPPING["IP"]).join(
MetadataMapping,
and_(
Expand All @@ -59,6 +61,13 @@ def get_all_c2ips():
KBUser.email.like("%" + str(value) + "%"))
continue

if column == "tags":
entities = entities.outerjoin(Tags_mapping, c2ip.C2ip.id == Tags_mapping.source_id)\
.filter(Tags_mapping.source_table == c2ip.C2ip.__tablename__)\
.join(Tags, Tags_mapping.tag_id == Tags.id)\
.filter(Tags.text.like("%" + str(value) + "%"))
continue

try:
column = getattr(c2ip.C2ip, column)
entities = entities.filter(column.like("%" + str(value) + "%"))
Expand Down
19 changes: 16 additions & 3 deletions app/static/js/c2dns/c2dns-controller.js
Expand Up @@ -96,13 +96,13 @@ angular.module('ThreatKB')
[
{
field: 'domain_name',
width: '320',
width: '300'
},
{
field: 'date_created',
displayName: "Created Date",
enableSorting: true,
width: '180',
width: '150',
cellFilter: 'date:\'yyyy-MM-dd HH:mm:ss\''
},
{
Expand All @@ -112,6 +112,7 @@ angular.module('ThreatKB')
{
field: 'state',
displayName: 'State',
width: '130',
enableSorting: true,
cellTemplate: '<ui-select append-to-body="true" ng-model="row.entity.state"'
+ ' on-select="grid.appScope.save(row.entity)">'
Expand All @@ -128,7 +129,7 @@ angular.module('ThreatKB')
{
field: 'owner_user.email',
displayName: 'Owner',
width: '180',
width: '170',
enableSorting: false,
cellTemplate: '<ui-select append-to-body="true" ng-model="row.entity.owner_user"'
+ ' on-select="grid.appScope.save(row.entity)">'
Expand All @@ -142,6 +143,18 @@ angular.module('ThreatKB')
+ '</ui-select>'
+ '</div>'
},
{
field: 'tags',
displayName: 'Tags',
width: '180',
enableSorting: false,
cellTemplate: '<ul class="gridTags" append-to-body="true" ng-model="row.entity.tags">'
+ '<li ng-repeat="tag in (row.entity.tags | filter: $select.search) track by tag.id">'
+ '<small>{{tag.text}}</small>'
+ '</li>'
+ '</ul>'
+ '</div>'
},
{
name: 'Actions',
width: '120',
Expand Down
18 changes: 15 additions & 3 deletions app/static/js/c2ip/c2ip-controller.js
Expand Up @@ -104,7 +104,7 @@ angular.module('ThreatKB')
field: 'date_created',
displayName: "Created Date",
enableSorting: true,
width: '180',
width: '150',
cellFilter: 'date:\'yyyy-MM-dd HH:mm:ss\''
},
{
Expand All @@ -114,7 +114,7 @@ angular.module('ThreatKB')
{
field: 'state',
displayName: 'State',
width: '180',
width: '130',
enableSorting: true,
cellTemplate: '<ui-select append-to-body="true" ng-model="row.entity.state"'
+ ' on-select="grid.appScope.save(row.entity)">'
Expand All @@ -131,7 +131,7 @@ angular.module('ThreatKB')
{
field: 'owner_user.email',
displayName: 'Owner',
width: '180',
width: '170',
enableSorting: false,
cellTemplate: '<ui-select append-to-body="true" ng-model="row.entity.owner_user"'
+ ' on-select="grid.appScope.save(row.entity)">'
Expand All @@ -145,6 +145,18 @@ angular.module('ThreatKB')
+ '</ui-select>'
+ '</div>'
},
{
field: 'tags',
displayName: 'Tags',
width: '180',
enableSorting: false,
cellTemplate: '<ul class="gridTags" append-to-body="true" ng-model="row.entity.tags">'
+ '<li ng-repeat="tag in (row.entity.tags | filter: $select.search) track by tag.id">'
+ '<small>{{tag.text}}</small>'
+ '</li>'
+ '</ul>'
+ '</div>'
},
{
name: 'Actions',
width: '120',
Expand Down
20 changes: 20 additions & 0 deletions app/static/views/c2dns/c2dns.html
Expand Up @@ -287,6 +287,26 @@ <h4 class="modal-title" id="myC2dnsLabel">
</button>
</div>
<br>
<style type="text/css">
.gridTags {
padding: 0;
width:180px;
height: 2em;
line-height: 1em;
text-overflow: ellipsis;
word-break: break-all;
overflow:hidden;
white-space: nowrap;
}
.gridTags:hover{
overflow: visible;
white-space: normal;
height:auto;
}
.gridTags li:not(:last-child):after {
content: ", ";
}
</style>
<div ui-if="gridOptions.data.length > 0" ui-grid="gridOptions" ng-style="getTableHeight()"
ui-grid-pagination ui-grid-auto-resize>
</div>
Expand Down
20 changes: 20 additions & 0 deletions app/static/views/c2ip/c2ips.html
Expand Up @@ -292,6 +292,26 @@ <h4 class="modal-title" id="myC2ipLabel">
</button>
</div>
<br>
<style type="text/css">
.gridTags {
padding: 0;
width:180px;
height: 2em;
line-height: 1em;
text-overflow: ellipsis;
word-break: break-all;
overflow:hidden;
white-space: nowrap;
}
.gridTags:hover{
overflow: visible;
white-space: normal;
height:auto;
}
.gridTags li:not(:last-child):after {
content: ", ";
}
</style>
<div ui-if="gridOptions.data.length > 0" ui-grid="gridOptions" ng-style="getTableHeight()"
ui-grid-pagination ui-grid-auto-resize>
</div>
Expand Down

0 comments on commit 7018605

Please sign in to comment.