mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-26 15:57:16 +00:00
chg: [chats] add UI shortcut + networks list + show chats/subchannels info
This commit is contained in:
parent
789210bcba
commit
b1d5399607
10 changed files with 155 additions and 3 deletions
|
@ -128,6 +128,9 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
|
|||
if meta.get('name'):
|
||||
chat.set_name(meta['name'])
|
||||
|
||||
if meta.get('info'):
|
||||
chat.set_info(meta['info'])
|
||||
|
||||
if meta.get('date'): # TODO check if already exists
|
||||
chat.set_created_at(int(meta['date']['timestamp']))
|
||||
|
||||
|
@ -160,6 +163,9 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
|
|||
subchannel.set_name(meta['name'])
|
||||
# subchannel.update_name(meta['name'], timestamp) # TODO #################
|
||||
|
||||
if meta.get('info'):
|
||||
subchannel.set_info(meta['info'])
|
||||
|
||||
subchannel.add_message(message.get_global_id(), message.id, timestamp, reply_id=reply_id)
|
||||
return subchannel
|
||||
|
||||
|
|
|
@ -185,6 +185,15 @@ class ChatServiceInstance:
|
|||
def get_chat_service_instances():
|
||||
return r_obj.smembers(f'chatSerIns:all')
|
||||
|
||||
def get_chat_service_instances_by_protocol(protocol):
|
||||
instance_uuids = {}
|
||||
for network in r_obj.smembers(f'chat:protocol:networks:{protocol}'):
|
||||
inst_uuids = r_obj.hvals(f'map:chatSerIns:{protocol}:{network}')
|
||||
if not network:
|
||||
network = 'default'
|
||||
instance_uuids[network] = inst_uuids
|
||||
return instance_uuids
|
||||
|
||||
def get_chat_service_instance_uuid(protocol, network, address):
|
||||
if not network:
|
||||
network = ''
|
||||
|
@ -192,6 +201,14 @@ def get_chat_service_instance_uuid(protocol, network, address):
|
|||
address = ''
|
||||
return r_obj.hget(f'map:chatSerIns:{protocol}:{network}', address)
|
||||
|
||||
def get_chat_service_instance_uuid_meta_from_network_dict(instance_uuids):
|
||||
for network in instance_uuids:
|
||||
metas = []
|
||||
for instance_uuid in instance_uuids[network]:
|
||||
metas.append(ChatServiceInstance(instance_uuid).get_meta())
|
||||
instance_uuids[network] = metas
|
||||
return instance_uuids
|
||||
|
||||
def get_chat_service_instance(protocol, network, address):
|
||||
instance_uuid = get_chat_service_instance_uuid(protocol, network, address)
|
||||
if instance_uuid:
|
||||
|
@ -280,7 +297,7 @@ def api_get_chat(chat_id, chat_instance_uuid):
|
|||
chat = Chats.Chat(chat_id, chat_instance_uuid)
|
||||
if not chat.exists():
|
||||
return {"status": "error", "reason": "Unknown chat"}, 404
|
||||
meta = chat.get_meta({'img', 'subchannels', 'username'})
|
||||
meta = chat.get_meta({'img', 'info', 'subchannels', 'username'})
|
||||
if meta['subchannels']:
|
||||
meta['subchannels'] = get_subchannels_meta_from_global_id(meta['subchannels'])
|
||||
else:
|
||||
|
|
|
@ -76,6 +76,8 @@ class Chat(AbstractChatObject):
|
|||
meta['tags'] = self.get_tags(r_list=True)
|
||||
if 'img':
|
||||
meta['icon'] = self.get_img()
|
||||
if 'info':
|
||||
meta['info'] = self.get_info()
|
||||
if 'username' in options:
|
||||
meta['username'] = self.get_username()
|
||||
if 'subchannels' in options:
|
||||
|
|
|
@ -115,6 +115,12 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
|
|||
def set_img(self, icon):
|
||||
self._set_field('img', icon)
|
||||
|
||||
def get_info(self):
|
||||
return self._get_field('info')
|
||||
|
||||
def set_info(self, info):
|
||||
self._set_field('info', info)
|
||||
|
||||
def get_nb_messages(self):
|
||||
return r_object.zcard(f'messages:{self.type}:{self.subtype}:{self.id}')
|
||||
|
||||
|
|
|
@ -57,6 +57,19 @@ def chats_explorer_protocols():
|
|||
protocols = chats_viewer.get_chat_protocols_meta()
|
||||
return render_template('chats_protocols.html', protocols=protocols)
|
||||
|
||||
@chats_explorer.route("chats/explorer/networks", methods=['GET'])
|
||||
@login_required
|
||||
@login_read_only
|
||||
def chats_explorer_networks():
|
||||
protocol = request.args.get('protocol')
|
||||
networks = chats_viewer.get_chat_service_instances_by_protocol(protocol)
|
||||
if len(networks) == 1:
|
||||
instance_uuid = list(networks.values())[0]
|
||||
return redirect(url_for('chats_explorer.chats_explorer_instance', uuid=instance_uuid))
|
||||
else:
|
||||
return render_template('chats_networks.html', protocol=protocol, networks=networks)
|
||||
|
||||
|
||||
@chats_explorer.route("chats/explorer/instance", methods=['GET'])
|
||||
@login_required
|
||||
@login_read_only
|
||||
|
@ -93,7 +106,7 @@ def objects_subchannel_messages():
|
|||
return create_json_response(subchannel[0], subchannel[1])
|
||||
else:
|
||||
subchannel = subchannel[0]
|
||||
return render_template('SubChannelMessages.html', subchannel=subchannel)
|
||||
return render_template('SubChannelMessages.html', subchannel=subchannel, bootstrap_label=bootstrap_label)
|
||||
|
||||
#############################################################################################
|
||||
#############################################################################################
|
||||
|
|
|
@ -98,6 +98,11 @@
|
|||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{% if subchannel['info'] %}
|
||||
<li class="list-group-item py-0">
|
||||
<pre class="my-0">{{ subchannel['info'] }}</pre>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="list-group-item py-0">
|
||||
<br>
|
||||
<div class="mb-3">
|
||||
|
|
|
@ -84,6 +84,11 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% if chat['info'] %}
|
||||
<li class="list-group-item py-0">
|
||||
<pre class="my-0">{{ chat['info'] }}</pre>
|
||||
</li>
|
||||
{% endif %}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
|
78
var/www/templates/chats_explorer/chats_networks.html
Normal file
78
var/www/templates/chats_explorer/chats_networks.html
Normal file
|
@ -0,0 +1,78 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Chats Protocols - AIL</title>
|
||||
<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">
|
||||
|
||||
<!-- Core CSS -->
|
||||
<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
|
||||
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
|
||||
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
|
||||
|
||||
<!-- JS -->
|
||||
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
|
||||
<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
|
||||
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
|
||||
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
|
||||
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{% include 'nav_bar.html' %}
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
||||
{% include 'sidebars/sidebar_objects.html' %}
|
||||
|
||||
<div class="col-12 col-lg-10" id="core_content">
|
||||
|
||||
<h1 class="m-4">{{ protocol }} Networks:</h1>
|
||||
|
||||
{% for network in networks %}
|
||||
<ul class="list-group flex-md-column flex-row justify-content-between w-100 mb-4">
|
||||
<li class="list-group-item active">
|
||||
<h3>{{ network }}:</h3>
|
||||
</li>
|
||||
|
||||
{% for instance_uuid in networks[network] %}
|
||||
<li class="list-group-item">
|
||||
<a class="nav-link" href="{{url_for('chats_explorer.chats_explorer_instance')}}?uuid={{ instance_uuid }}">
|
||||
<span>{{ instance_uuid }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("#page-Decoded").addClass("active");
|
||||
$("#nav_explorer_chat").addClass("active");
|
||||
});
|
||||
|
||||
function toggle_sidebar(){
|
||||
if($('#nav_menu').is(':visible')){
|
||||
$('#nav_menu').hide();
|
||||
$('#side_menu').removeClass('border-right')
|
||||
$('#side_menu').removeClass('col-lg-2')
|
||||
$('#core_content').removeClass('col-lg-10')
|
||||
}else{
|
||||
$('#nav_menu').show();
|
||||
$('#side_menu').addClass('border-right')
|
||||
$('#side_menu').addClass('col-lg-2')
|
||||
$('#core_content').addClass('col-lg-10')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -29,10 +29,12 @@
|
|||
|
||||
<div class="col-12 col-lg-10" id="core_content">
|
||||
|
||||
<h1 class="m-2"><i class="fas fa-comments"></i> Chats Protocols:</h1>
|
||||
|
||||
{% if protocols %}
|
||||
<div class="d-flex justify-content-around my-2">
|
||||
{% for meta in protocols %}
|
||||
<a class="btn btn-light border-secondary" style="" href="#">
|
||||
<a class="btn btn-light border-secondary" style="" href="{{ url_for('chats_explorer.chats_explorer_networks') }}?protocol={{ meta['id'] }}">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">
|
||||
{% if meta['icon'] %}
|
||||
|
|
|
@ -24,10 +24,28 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<h5 class="d-flex text-muted w-100">
|
||||
<span>Explorers</span>
|
||||
</h5>
|
||||
<ul class="nav flex-md-column flex-row navbar-nav justify-content-between w-100 mb-4">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{url_for('chats_explorer.chats_explorer_protocols')}}" id="nav_explorer_chat">
|
||||
<i class="far fa-comments"></i>
|
||||
<span>Chats Explorer</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h5 class="d-flex text-muted w-100">
|
||||
<span>Objects</span>
|
||||
</h5>
|
||||
<ul class="nav flex-md-column flex-row navbar-nav justify-content-between w-100 mb-4">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{url_for('objects_subtypes.objects_dashboard_chat')}}" id="nav_dashboard_chat">
|
||||
<i class="fas fa-comments"></i>
|
||||
<span>Chat</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{url_for('objects_cve.objects_cves')}}" id="nav_cve">
|
||||
<i class="fas fa-bug"></i>
|
||||
|
|
Loading…
Reference in a new issue