Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment of basic features #1

Merged
merged 15 commits into from Apr 17, 2024
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@

flask_app/__pycache__/
10 changes: 9 additions & 1 deletion README.md
@@ -1,2 +1,10 @@
# mptcp-check
a website to check the validity of a mptcp connection
A website to check the validity of a mptcp connection

The website is designed with [Flask](https://flask.palletsprojects.com/en/3.0.x/), it can be installed with `pip install Flask`.
For test purposses, the app can be started with `flask run` from `/flask_app`.
For production, one of the [recommended](https://flask.palletsprojects.com/en/3.0.x/deploying/) app should be used instead.

For convegnance, `uwsgi` can be used with the provided `app.ini` config file.
simply run => `mptcpize run uwsgi --ini app.ini` preferably as root.

8 changes: 8 additions & 0 deletions app.ini
@@ -0,0 +1,8 @@
[uwsgi]
module = flask_app.app:app
master = true
processes = 3
socket = socket.sock
chmod-socket = 660
vacuum = true
die-on-term = true
52 changes: 52 additions & 0 deletions flask_app/app.py
@@ -0,0 +1,52 @@
from flask import Flask, request, render_template, Response
from subprocess import check_output

app = Flask(__name__)

@app.route("/")
def mptcp_status_page():
"""
Flask route to display MPTCP connection status.

Retrieves the visitor's IP and port, checks for MPTCP data in the connections dictionary,
and renders the webpage with the connection status.

Returns:
Rendered webpage with connection status and MPTCP version if established.
"""

addr = request.remote_addr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does it display a v6 address? In ss, it surrounds it with [], you might need to handle that.

(to check if it is a v6 address, simply look for : in the address)

port = request.environ.get('REMOTE_PORT')

try:
conn = check_output(["ss", "-MtnH", "src", f"{addr}", "sport", f"{port}"]).decode("ascii")
if (conn == ""):
pass
mux99 marked this conversation as resolved.
Show resolved Hide resolved

if list(filter(None, conn.split(' ')))[0] == "mptcp":
state_message = 'Established'
state_class = 'success'
else:
state_message = 'Not Established'
state_class = 'fail'
except:
state_message = 'Established'
state_class = 'error'

return render_template('index.html', state_message=state_message, state_class=state_class)

@app.route('/stream_audio')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this? Just to have a file to download?

You will need to put the license and the source somewhere to avoid troubles... (even if we can use it)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the download of a file usefull? can the same effect be achieved with a large binary file or something similar?

Copy link

@matttbe matttbe May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the same can be achieved with large binary files generated with 'dd' with random data (not just zeros). So flask should not be needed for that part. Probably best to disable compression support in lighttpd like GZip.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe easier to add files in a dedicated directory: 1M, 10M, 100M, 1G?

def stream_audio():
def generate_audio():
# Your audio streaming logic goes here
# You can read audio data from a file or generate it dynamically
# Example: Streaming a static audio file
with open('sounds/joyful-whistle-186300.mp3', 'rb') as f:
while True:
audio_chunk = f.read(1024)
if not audio_chunk:
break
yield audio_chunk

return Response(generate_audio(), mimetype='audio/mpeg')

Binary file added flask_app/sounds/joyful-whistle-186300.mp3
Binary file not shown.
45 changes: 45 additions & 0 deletions flask_app/static/styles.css
@@ -0,0 +1,45 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}

.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h1 {
text-align: center;
}

#connection-status {
text-align: center;
margin-top: 30px;
font-size: 18px;
padding: 20px;
border-radius: 5px;
}

.error {
background-color: #f0ad4e;
}

.success {
background-color: #5cb85c;
color: white;
}

.fail {
background-color: #d9534f;
color: white;
}

p {
margin: 0;
}
17 changes: 17 additions & 0 deletions flask_app/templates/index.html
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MPTCP Connection Status</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
<div class="container">
<h1>MPTCP Connection Status</h1>
<div id="connection-status" class="{{ state_class }}">
<p>MPTCP Connection is <strong>{{ state_message }}</strong></p>
</div>
</div>
</body>
</html>