Commit 2622aeb4 authored by Luca Lamorte's avatar Luca Lamorte

First release of the UI developed for the privacy Module

parents
[submodule "testing_tool_gui/utils"]
path = testing_tool_gui/utils
url = https://llamorte@gitlab.distantaccess.com/f-interop-contributors/utils.git
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
#!/usr/bin/env bash
python3 -m testing_tool_gui.gui
\ No newline at end of file
/**
* Created by luca.lamorte on 21/04/2017.
*/
var express = require("express");
var amqp = require('amqplib/callback_api');
var app = express();
// Web Socket
var server = require('http').Server(app);
server.listen(3001);
var ws_amqp = null;
var channel = null;
var ex = 'default';
var io = require('socket.io')(server);
io.on('connection', function (socket) {
ws_amqp = socket
channel.publish(ex, "bootstrap", new Buffer("WebSocket open on port 3001"));
socket.on('server_evt', function (data) {
console.log(data);
});
});
// AMQP Connection
amqp.connect('amqp://luca:luca@finterop1/session1', function(err, conn) {
conn.createChannel(function(err, ch) {
channel = ch
ch.assertExchange(ex, 'topic', {durable: true});
ch.assertQueue('', {exclusive: true}, function(err, q) {
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q.queue);
ch.bindQueue(q.queue, ex, '#');
ch.consume(q.queue, function(msg) {
// to read all field JSON.stringify(msg)
msg.content = msg.content.toString()
console.log(" [x] %s", JSON.stringify(msg));
if (ws_amqp!=null)
ws_amqp.emit('amqp_msg', JSON.stringify(msg));
}, {noAck: true});
console.log("SEND AMQP MESSAGE")
ch.publish(ex, "bootstrap", new Buffer("Node.js is up!!!!"));
});
});
});
app.use(express.static('public'));
var router = express.Router();
var path = __dirname + '/views/';
router.use(function (req,res,next) {
//console.log("/" + req.method);
next();
});
router.get("/",function(req,res){
res.sendFile(path + "index.html");
});
router.get("/about",function(req,res){
res.sendFile(path + "about.html");
});
router.get("/contact",function(req,res){
res.sendFile(path + "contact.html");
});
router.get("/demo",function(req,res){
res.sendFile(path + "demo.html");
})
app.use("/",router);
app.use("*",function(req,res){
res.sendFile(path + "404.html");
});
app.listen(3000,function(){
console.log("Live at Port 3000");
});
import osimport pikaimport traceback VERSION = '0.0.1'COMPONENT_ID = "gui_tt" UPLOAD_FOLDER = './tmp'ALLOWED_EXTENSIONS = set(['json', 'pcap']) RABBIT_MQ_CONNECTED = False try: AMQP_EXCHANGE = str(os.environ['AMQP_EXCHANGE'])except KeyError as e: print('couldnt import AMQP_EXCHANGE from environment') AMQP_EXCHANGE = "default" try: AMQP_URL = str(os.environ['AMQP_URL'])except KeyError as e: print('couldnt import AMQP_URL from environment') # TODO: REMOVE PERSONAL CONFIGURATION ## AMQP_URL = "amqp://guest:guest@localhost/" AMQP_URL = str(os.getenv('AMQP_URL', 'amqp://luca:luca@finterop1/session1')) def get_connection(AMQP_URL): try: print('Setting up AMQP connection... %s' % AMQP_URL) # setup AMQP connection return pika.BlockingConnection(pika.URLParameters(AMQP_URL)) except pika.exceptions.ConnectionClosed as cc: print(' AMQP cannot be established, is message broker up? \n More: %s' % traceback.format_exc()) return None def get_configuration(status = None): global RABBIT_MQ_CONNECTED if status: RABBIT_MQ_CONNECTED = status cfg = dict() cfg["url"] = AMQP_URL cfg["exchange"] = AMQP_EXCHANGE cfg["version"] = VERSION cfg["component"] = COMPONENT_ID cfg["connected"] = RABBIT_MQ_CONNECTED return cfg
\ No newline at end of file
from flask import Flask
from flask import render_template
from flask import request, redirect
from flask_socketio import SocketIO
from testing_tool_gui.utils.amqp_synch_call import publish_message
from testing_tool_gui.utils.messages import *
from testing_tool_gui.gui.amqp_sniffer import *
from testing_tool_gui.gui import *
amqp_connection = get_connection(AMQP_URL)
if amqp_connection:
my_channel = amqp_connection.channel()
get_configuration(status=True)
# WEB SOCKET
NAMESPACE = "/ws"
async_modes = ['threading', 'eventlet', 'gevent','gevent_uwsgi']
async_mode = async_modes[0]
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, async_mode=async_mode)
thread = None
def start_amqp_sniffer():
amqp_listener = AmqpSniffer(amqp_connection, socketio)
amqp_listener.start()
# ================= WEB SOCKET EVENTS ===================== #
@socketio.on('send_amqp_msg', namespace=NAMESPACE)
def test_message(message):
print("SEND MESSAGE %s" % message["msg"])
if my_channel:
try:
msg = message_types_dict[message["msg"]]()
publish_message(my_channel, msg)
except Exception as ex:
print("EXCEPTION %s!"%ex)
else:
print("Channel is not available")
@socketio.on('change_config', namespace=NAMESPACE)
def test_message(config):
print(" Change configuration: %s"+json.dumps(config))
# global AMQP_EXCHANGE
# global AMQP_URL
# global amqp_connection
#
# AMQP_URL = config["url"]
# AMQP_EXCHANGE = config["exchange"]
# amqp_connection = get_connection(AMQP_URL)
# socketio.start_background_task(target=start_amqp_sniffer)
@socketio.on('connect', namespace=NAMESPACE)
def test_connect():
print("WS Connected")
global thread
if thread is None:
thread = socketio.start_background_task(target=start_amqp_sniffer)