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
Changes from 7 commits
a4dd7ba
44ea3cb
355bf2b
ca26dd3
bfbe3b6
4e2b83d
1938aba
99b42f9
d356895
83b120a
5b5bd2f
75747c4
917209a
3cbde77
cde769e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
flask_app/__pycache__/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
There was a problem hiding this comment.
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)